bin-prettier.js 1.3 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858
  1. #!/usr/bin/env node
  2. 'use strict';
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var fs = _interopDefault(require('fs'));
  5. var os = _interopDefault(require('os'));
  6. var path = _interopDefault(require('path'));
  7. var assert = _interopDefault(require('assert'));
  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.18.2";
  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. "@angular/compiler": "7.2.9",
  29. "@babel/code-frame": "7.0.0",
  30. "@babel/parser": "7.2.0",
  31. "@glimmer/syntax": "0.38.4",
  32. "@iarna/toml": "2.2.3",
  33. "@typescript-eslint/typescript-estree": "1.6.0",
  34. "angular-estree-parser": "1.1.5",
  35. "angular-html-parser": "1.2.0",
  36. "camelcase": "4.1.0",
  37. "chalk": "2.1.0",
  38. "cjk-regex": "2.0.0",
  39. "cosmiconfig": "5.0.7",
  40. "dashify": "0.2.2",
  41. "dedent": "0.7.0",
  42. "diff": "3.2.0",
  43. "editorconfig": "0.15.2",
  44. "editorconfig-to-prettier": "0.1.1",
  45. "escape-string-regexp": "1.0.5",
  46. "esutils": "2.0.2",
  47. "find-parent-dir": "0.3.0",
  48. "find-project-root": "1.1.1",
  49. "flow-parser": "0.84.0",
  50. "get-stream": "3.0.0",
  51. "globby": "6.1.0",
  52. "graphql": "14.2.0",
  53. "html-element-attributes": "2.0.0",
  54. "html-styles": "1.0.0",
  55. "html-tag-names": "1.1.2",
  56. "ignore": "4.0.6",
  57. "is-ci": "2.0.0",
  58. "jest-docblock": "23.2.0",
  59. "json-stable-stringify": "1.0.1",
  60. "leven": "2.1.0",
  61. "lines-and-columns": "1.1.6",
  62. "linguist-languages": "6.2.1-dev.20180706",
  63. "lodash.uniqby": "4.7.0",
  64. "mem": "1.1.0",
  65. "minimatch": "3.0.4",
  66. "minimist": "1.2.0",
  67. "n-readlines": "1.0.0",
  68. "normalize-path": "3.0.0",
  69. "parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
  70. "postcss-less": "1.1.5",
  71. "postcss-media-query-parser": "0.2.3",
  72. "postcss-scss": "2.0.0",
  73. "postcss-selector-parser": "2.2.3",
  74. "postcss-values-parser": "1.5.0",
  75. "regexp-util": "1.2.2",
  76. "remark-math": "1.0.4",
  77. "remark-parse": "5.0.0",
  78. "resolve": "1.5.0",
  79. "semver": "5.4.1",
  80. "string-width": "3.0.0",
  81. "typescript": "3.4.1",
  82. "unicode-regex": "2.0.0",
  83. "unified": "6.1.6",
  84. "vnopts": "1.0.2",
  85. "yaml": "1.0.2",
  86. "yaml-unist-parser": "1.0.0"
  87. };
  88. var devDependencies = {
  89. "@babel/cli": "7.2.0",
  90. "@babel/core": "7.2.0",
  91. "@babel/preset-env": "7.2.0",
  92. "babel-loader": "8.0.4",
  93. "benchmark": "2.1.4",
  94. "builtin-modules": "2.0.0",
  95. "codecov": "codecov/codecov-node#e427d900309adb50746a39a50aa7d80071a5ddd0",
  96. "cross-env": "5.0.5",
  97. "eslint": "4.18.2",
  98. "eslint-config-prettier": "2.9.0",
  99. "eslint-friendly-formatter": "3.0.0",
  100. "eslint-plugin-import": "2.9.0",
  101. "eslint-plugin-prettier": "2.6.0",
  102. "eslint-plugin-react": "7.7.0",
  103. "execa": "0.10.0",
  104. "jest": "23.3.0",
  105. "jest-junit": "5.0.0",
  106. "jest-snapshot-serializer-ansi": "1.0.0",
  107. "jest-snapshot-serializer-raw": "1.1.0",
  108. "jest-watch-typeahead": "0.1.0",
  109. "mkdirp": "0.5.1",
  110. "prettier": "1.18.0",
  111. "prettylint": "1.0.0",
  112. "rimraf": "2.6.2",
  113. "rollup": "0.47.6",
  114. "rollup-plugin-alias": "1.4.0",
  115. "rollup-plugin-babel": "4.0.0-beta.4",
  116. "rollup-plugin-commonjs": "8.2.6",
  117. "rollup-plugin-json": "2.1.1",
  118. "rollup-plugin-node-builtins": "2.0.0",
  119. "rollup-plugin-node-globals": "1.1.0",
  120. "rollup-plugin-node-resolve": "2.0.0",
  121. "rollup-plugin-replace": "1.2.1",
  122. "rollup-plugin-uglify": "3.0.0",
  123. "shelljs": "0.8.1",
  124. "snapshot-diff": "0.4.0",
  125. "strip-ansi": "4.0.0",
  126. "tempy": "0.2.1",
  127. "webpack": "3.12.0"
  128. };
  129. var scripts = {
  130. "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
  131. "prepare-release": "yarn && yarn build && yarn test:dist",
  132. "test": "jest",
  133. "test:dist": "node ./scripts/test-dist.js",
  134. "test-integration": "jest tests_integration",
  135. "perf-repeat": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  136. "perf-repeat-inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  137. "perf-benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  138. "lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
  139. "lint-docs": "prettylint {.,docs,website,website/blog}/*.md",
  140. "lint-dist": "eslint --no-eslintrc --no-ignore --env=browser \"dist/!(bin-prettier|index|third-party).js\"",
  141. "build": "node --max-old-space-size=2048 ./scripts/build/build.js",
  142. "build-docs": "node ./scripts/build-docs.js",
  143. "check-deps": "node ./scripts/check-deps.js"
  144. };
  145. var _package = {
  146. name: name,
  147. version: version$1,
  148. description: description,
  149. bin: bin,
  150. repository: repository,
  151. homepage: homepage,
  152. author: author,
  153. license: license,
  154. main: main,
  155. engines: engines,
  156. dependencies: dependencies,
  157. devDependencies: devDependencies,
  158. scripts: scripts
  159. };
  160. var _package$1 = Object.freeze({
  161. name: name,
  162. version: version$1,
  163. description: description,
  164. bin: bin,
  165. repository: repository,
  166. homepage: homepage,
  167. author: author,
  168. license: license,
  169. main: main,
  170. engines: engines,
  171. dependencies: dependencies,
  172. devDependencies: devDependencies,
  173. scripts: scripts,
  174. default: _package
  175. });
  176. function unwrapExports (x) {
  177. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  178. }
  179. function createCommonjsModule(fn, module) {
  180. return module = { exports: {} }, fn(module, module.exports), module.exports;
  181. }
  182. var base = createCommonjsModule(function (module, exports) {
  183. /*istanbul ignore start*/
  184. 'use strict';
  185. exports.__esModule = true;
  186. exports['default'] =
  187. /*istanbul ignore end*/
  188. Diff;
  189. function Diff() {}
  190. Diff.prototype = {
  191. /*istanbul ignore start*/
  192. /*istanbul ignore end*/
  193. diff: function diff(oldString, newString) {
  194. /*istanbul ignore start*/
  195. var
  196. /*istanbul ignore end*/
  197. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  198. var callback = options.callback;
  199. if (typeof options === 'function') {
  200. callback = options;
  201. options = {};
  202. }
  203. this.options = options;
  204. var self = this;
  205. function done(value) {
  206. if (callback) {
  207. setTimeout(function () {
  208. callback(undefined, value);
  209. }, 0);
  210. return true;
  211. } else {
  212. return value;
  213. }
  214. } // Allow subclasses to massage the input prior to running
  215. oldString = this.castInput(oldString);
  216. newString = this.castInput(newString);
  217. oldString = this.removeEmpty(this.tokenize(oldString));
  218. newString = this.removeEmpty(this.tokenize(newString));
  219. var newLen = newString.length,
  220. oldLen = oldString.length;
  221. var editLength = 1;
  222. var maxEditLength = newLen + oldLen;
  223. var bestPath = [{
  224. newPos: -1,
  225. components: []
  226. }]; // Seed editLength = 0, i.e. the content starts with the same values
  227. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  228. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  229. // Identity per the equality and tokenizer
  230. return done([{
  231. value: this.join(newString),
  232. count: newString.length
  233. }]);
  234. } // Main worker method. checks all permutations of a given edit length for acceptance.
  235. function execEditLength() {
  236. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  237. var basePath =
  238. /*istanbul ignore start*/
  239. void 0;
  240. var addPath = bestPath[diagonalPath - 1],
  241. removePath = bestPath[diagonalPath + 1],
  242. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  243. if (addPath) {
  244. // No one else is going to attempt to use this value, clear it
  245. bestPath[diagonalPath - 1] = undefined;
  246. }
  247. var canAdd = addPath && addPath.newPos + 1 < newLen,
  248. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  249. if (!canAdd && !canRemove) {
  250. // If this path is a terminal then prune
  251. bestPath[diagonalPath] = undefined;
  252. continue;
  253. } // Select the diagonal that we want to branch from. We select the prior
  254. // path whose position in the new string is the farthest from the origin
  255. // and does not pass the bounds of the diff graph
  256. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  257. basePath = clonePath(removePath);
  258. self.pushComponent(basePath.components, undefined, true);
  259. } else {
  260. basePath = addPath; // No need to clone, we've pulled it from the list
  261. basePath.newPos++;
  262. self.pushComponent(basePath.components, true, undefined);
  263. }
  264. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  265. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  266. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  267. } else {
  268. // Otherwise track this path as a potential candidate and continue.
  269. bestPath[diagonalPath] = basePath;
  270. }
  271. }
  272. editLength++;
  273. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  274. // sync and async mode which is never fun. Loops over execEditLength until a value
  275. // is produced.
  276. if (callback) {
  277. (function exec() {
  278. setTimeout(function () {
  279. // This should not happen, but we want to be safe.
  280. /* istanbul ignore next */
  281. if (editLength > maxEditLength) {
  282. return callback();
  283. }
  284. if (!execEditLength()) {
  285. exec();
  286. }
  287. }, 0);
  288. })();
  289. } else {
  290. while (editLength <= maxEditLength) {
  291. var ret = execEditLength();
  292. if (ret) {
  293. return ret;
  294. }
  295. }
  296. }
  297. },
  298. /*istanbul ignore start*/
  299. /*istanbul ignore end*/
  300. pushComponent: function pushComponent(components, added, removed) {
  301. var last = components[components.length - 1];
  302. if (last && last.added === added && last.removed === removed) {
  303. // We need to clone here as the component clone operation is just
  304. // as shallow array clone
  305. components[components.length - 1] = {
  306. count: last.count + 1,
  307. added: added,
  308. removed: removed
  309. };
  310. } else {
  311. components.push({
  312. count: 1,
  313. added: added,
  314. removed: removed
  315. });
  316. }
  317. },
  318. /*istanbul ignore start*/
  319. /*istanbul ignore end*/
  320. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  321. var newLen = newString.length,
  322. oldLen = oldString.length,
  323. newPos = basePath.newPos,
  324. oldPos = newPos - diagonalPath,
  325. commonCount = 0;
  326. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  327. newPos++;
  328. oldPos++;
  329. commonCount++;
  330. }
  331. if (commonCount) {
  332. basePath.components.push({
  333. count: commonCount
  334. });
  335. }
  336. basePath.newPos = newPos;
  337. return oldPos;
  338. },
  339. /*istanbul ignore start*/
  340. /*istanbul ignore end*/
  341. equals: function equals(left, right) {
  342. return left === right;
  343. },
  344. /*istanbul ignore start*/
  345. /*istanbul ignore end*/
  346. removeEmpty: function removeEmpty(array) {
  347. var ret = [];
  348. for (var i = 0; i < array.length; i++) {
  349. if (array[i]) {
  350. ret.push(array[i]);
  351. }
  352. }
  353. return ret;
  354. },
  355. /*istanbul ignore start*/
  356. /*istanbul ignore end*/
  357. castInput: function castInput(value) {
  358. return value;
  359. },
  360. /*istanbul ignore start*/
  361. /*istanbul ignore end*/
  362. tokenize: function tokenize(value) {
  363. return value.split('');
  364. },
  365. /*istanbul ignore start*/
  366. /*istanbul ignore end*/
  367. join: function join(chars) {
  368. return chars.join('');
  369. }
  370. };
  371. function buildValues(diff, components, newString, oldString, useLongestToken) {
  372. var componentPos = 0,
  373. componentLen = components.length,
  374. newPos = 0,
  375. oldPos = 0;
  376. for (; componentPos < componentLen; componentPos++) {
  377. var component = components[componentPos];
  378. if (!component.removed) {
  379. if (!component.added && useLongestToken) {
  380. var value = newString.slice(newPos, newPos + component.count);
  381. value = value.map(function (value, i) {
  382. var oldValue = oldString[oldPos + i];
  383. return oldValue.length > value.length ? oldValue : value;
  384. });
  385. component.value = diff.join(value);
  386. } else {
  387. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  388. }
  389. newPos += component.count; // Common case
  390. if (!component.added) {
  391. oldPos += component.count;
  392. }
  393. } else {
  394. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  395. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  396. // The diffing algorithm is tied to add then remove output and this is the simplest
  397. // route to get the desired output with minimal overhead.
  398. if (componentPos && components[componentPos - 1].added) {
  399. var tmp = components[componentPos - 1];
  400. components[componentPos - 1] = components[componentPos];
  401. components[componentPos] = tmp;
  402. }
  403. }
  404. } // Special case handle for when one terminal is ignored. For this case we merge the
  405. // terminal into the prior string and drop the change.
  406. var lastComponent = components[componentLen - 1];
  407. if (componentLen > 1 && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  408. components[componentLen - 2].value += lastComponent.value;
  409. components.pop();
  410. }
  411. return components;
  412. }
  413. function clonePath(path$$1) {
  414. return {
  415. newPos: path$$1.newPos,
  416. components: path$$1.components.slice(0)
  417. };
  418. }
  419. });
  420. unwrapExports(base);
  421. var character = createCommonjsModule(function (module, exports) {
  422. /*istanbul ignore start*/
  423. 'use strict';
  424. exports.__esModule = true;
  425. exports.characterDiff = undefined;
  426. exports.
  427. /*istanbul ignore end*/
  428. diffChars = diffChars;
  429. /*istanbul ignore start*/
  430. var _base2 = _interopRequireDefault(base);
  431. function _interopRequireDefault(obj) {
  432. return obj && obj.__esModule ? obj : {
  433. 'default': obj
  434. };
  435. }
  436. /*istanbul ignore end*/
  437. var characterDiff =
  438. /*istanbul ignore start*/
  439. exports.
  440. /*istanbul ignore end*/
  441. characterDiff = new
  442. /*istanbul ignore start*/
  443. _base2['default']();
  444. function diffChars(oldStr, newStr, callback) {
  445. return characterDiff.diff(oldStr, newStr, callback);
  446. }
  447. });
  448. unwrapExports(character);
  449. var params = createCommonjsModule(function (module, exports) {
  450. /*istanbul ignore start*/
  451. 'use strict';
  452. exports.__esModule = true;
  453. exports.
  454. /*istanbul ignore end*/
  455. generateOptions = generateOptions;
  456. function generateOptions(options, defaults) {
  457. if (typeof options === 'function') {
  458. defaults.callback = options;
  459. } else if (options) {
  460. for (var name in options) {
  461. /* istanbul ignore else */
  462. if (options.hasOwnProperty(name)) {
  463. defaults[name] = options[name];
  464. }
  465. }
  466. }
  467. return defaults;
  468. }
  469. });
  470. unwrapExports(params);
  471. var word = createCommonjsModule(function (module, exports) {
  472. /*istanbul ignore start*/
  473. 'use strict';
  474. exports.__esModule = true;
  475. exports.wordDiff = undefined;
  476. exports.
  477. /*istanbul ignore end*/
  478. diffWords = diffWords;
  479. /*istanbul ignore start*/
  480. exports.
  481. /*istanbul ignore end*/
  482. diffWordsWithSpace = diffWordsWithSpace;
  483. /*istanbul ignore start*/
  484. var _base2 = _interopRequireDefault(base);
  485. /*istanbul ignore end*/
  486. /*istanbul ignore start*/
  487. function _interopRequireDefault(obj) {
  488. return obj && obj.__esModule ? obj : {
  489. 'default': obj
  490. };
  491. }
  492. /*istanbul ignore end*/
  493. // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
  494. //
  495. // Ranges and exceptions:
  496. // Latin-1 Supplement, 0080–00FF
  497. // - U+00D7 × Multiplication sign
  498. // - U+00F7 ÷ Division sign
  499. // Latin Extended-A, 0100–017F
  500. // Latin Extended-B, 0180–024F
  501. // IPA Extensions, 0250–02AF
  502. // Spacing Modifier Letters, 02B0–02FF
  503. // - U+02C7 ˇ &#711; Caron
  504. // - U+02D8 ˘ &#728; Breve
  505. // - U+02D9 ˙ &#729; Dot Above
  506. // - U+02DA ˚ &#730; Ring Above
  507. // - U+02DB ˛ &#731; Ogonek
  508. // - U+02DC ˜ &#732; Small Tilde
  509. // - U+02DD ˝ &#733; Double Acute Accent
  510. // Latin Extended Additional, 1E00–1EFF
  511. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  512. var reWhitespace = /\S/;
  513. var wordDiff =
  514. /*istanbul ignore start*/
  515. exports.
  516. /*istanbul ignore end*/
  517. wordDiff = new
  518. /*istanbul ignore start*/
  519. _base2['default']();
  520. wordDiff.equals = function (left, right) {
  521. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  522. };
  523. wordDiff.tokenize = function (value) {
  524. 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.
  525. for (var i = 0; i < tokens.length - 1; i++) {
  526. // If we have an empty string in the next field and we have only word chars before and after, merge
  527. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  528. tokens[i] += tokens[i + 2];
  529. tokens.splice(i + 1, 2);
  530. i--;
  531. }
  532. }
  533. return tokens;
  534. };
  535. function diffWords(oldStr, newStr, callback) {
  536. var options =
  537. /*istanbul ignore start*/
  538. (0, params.generateOptions
  539. /*istanbul ignore end*/
  540. )(callback, {
  541. ignoreWhitespace: true
  542. });
  543. return wordDiff.diff(oldStr, newStr, options);
  544. }
  545. function diffWordsWithSpace(oldStr, newStr, callback) {
  546. return wordDiff.diff(oldStr, newStr, callback);
  547. }
  548. });
  549. unwrapExports(word);
  550. var line = createCommonjsModule(function (module, exports) {
  551. /*istanbul ignore start*/
  552. 'use strict';
  553. exports.__esModule = true;
  554. exports.lineDiff = undefined;
  555. exports.
  556. /*istanbul ignore end*/
  557. diffLines = diffLines;
  558. /*istanbul ignore start*/
  559. exports.
  560. /*istanbul ignore end*/
  561. diffTrimmedLines = diffTrimmedLines;
  562. /*istanbul ignore start*/
  563. var _base2 = _interopRequireDefault(base);
  564. /*istanbul ignore end*/
  565. /*istanbul ignore start*/
  566. function _interopRequireDefault(obj) {
  567. return obj && obj.__esModule ? obj : {
  568. 'default': obj
  569. };
  570. }
  571. /*istanbul ignore end*/
  572. var lineDiff =
  573. /*istanbul ignore start*/
  574. exports.
  575. /*istanbul ignore end*/
  576. lineDiff = new
  577. /*istanbul ignore start*/
  578. _base2['default']();
  579. lineDiff.tokenize = function (value) {
  580. var retLines = [],
  581. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  582. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  583. linesAndNewlines.pop();
  584. } // Merge the content and line separators into single tokens
  585. for (var i = 0; i < linesAndNewlines.length; i++) {
  586. var line = linesAndNewlines[i];
  587. if (i % 2 && !this.options.newlineIsToken) {
  588. retLines[retLines.length - 1] += line;
  589. } else {
  590. if (this.options.ignoreWhitespace) {
  591. line = line.trim();
  592. }
  593. retLines.push(line);
  594. }
  595. }
  596. return retLines;
  597. };
  598. function diffLines(oldStr, newStr, callback) {
  599. return lineDiff.diff(oldStr, newStr, callback);
  600. }
  601. function diffTrimmedLines(oldStr, newStr, callback) {
  602. var options =
  603. /*istanbul ignore start*/
  604. (0, params.generateOptions
  605. /*istanbul ignore end*/
  606. )(callback, {
  607. ignoreWhitespace: true
  608. });
  609. return lineDiff.diff(oldStr, newStr, options);
  610. }
  611. });
  612. unwrapExports(line);
  613. var sentence = createCommonjsModule(function (module, exports) {
  614. /*istanbul ignore start*/
  615. 'use strict';
  616. exports.__esModule = true;
  617. exports.sentenceDiff = undefined;
  618. exports.
  619. /*istanbul ignore end*/
  620. diffSentences = diffSentences;
  621. /*istanbul ignore start*/
  622. var _base2 = _interopRequireDefault(base);
  623. function _interopRequireDefault(obj) {
  624. return obj && obj.__esModule ? obj : {
  625. 'default': obj
  626. };
  627. }
  628. /*istanbul ignore end*/
  629. var sentenceDiff =
  630. /*istanbul ignore start*/
  631. exports.
  632. /*istanbul ignore end*/
  633. sentenceDiff = new
  634. /*istanbul ignore start*/
  635. _base2['default']();
  636. sentenceDiff.tokenize = function (value) {
  637. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  638. };
  639. function diffSentences(oldStr, newStr, callback) {
  640. return sentenceDiff.diff(oldStr, newStr, callback);
  641. }
  642. });
  643. unwrapExports(sentence);
  644. var css = createCommonjsModule(function (module, exports) {
  645. /*istanbul ignore start*/
  646. 'use strict';
  647. exports.__esModule = true;
  648. exports.cssDiff = undefined;
  649. exports.
  650. /*istanbul ignore end*/
  651. diffCss = diffCss;
  652. /*istanbul ignore start*/
  653. var _base2 = _interopRequireDefault(base);
  654. function _interopRequireDefault(obj) {
  655. return obj && obj.__esModule ? obj : {
  656. 'default': obj
  657. };
  658. }
  659. /*istanbul ignore end*/
  660. var cssDiff =
  661. /*istanbul ignore start*/
  662. exports.
  663. /*istanbul ignore end*/
  664. cssDiff = new
  665. /*istanbul ignore start*/
  666. _base2['default']();
  667. cssDiff.tokenize = function (value) {
  668. return value.split(/([{}:;,]|\s+)/);
  669. };
  670. function diffCss(oldStr, newStr, callback) {
  671. return cssDiff.diff(oldStr, newStr, callback);
  672. }
  673. });
  674. unwrapExports(css);
  675. var json = createCommonjsModule(function (module, exports) {
  676. /*istanbul ignore start*/
  677. 'use strict';
  678. exports.__esModule = true;
  679. exports.jsonDiff = undefined;
  680. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  681. return typeof obj;
  682. } : function (obj) {
  683. return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
  684. };
  685. exports.
  686. /*istanbul ignore end*/
  687. diffJson = diffJson;
  688. /*istanbul ignore start*/
  689. exports.
  690. /*istanbul ignore end*/
  691. canonicalize = canonicalize;
  692. /*istanbul ignore start*/
  693. var _base2 = _interopRequireDefault(base);
  694. /*istanbul ignore end*/
  695. /*istanbul ignore start*/
  696. function _interopRequireDefault(obj) {
  697. return obj && obj.__esModule ? obj : {
  698. 'default': obj
  699. };
  700. }
  701. /*istanbul ignore end*/
  702. var objectPrototypeToString = Object.prototype.toString;
  703. var jsonDiff =
  704. /*istanbul ignore start*/
  705. exports.
  706. /*istanbul ignore end*/
  707. jsonDiff = new
  708. /*istanbul ignore start*/
  709. _base2['default'](); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  710. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  711. jsonDiff.useLongestToken = true;
  712. jsonDiff.tokenize =
  713. /*istanbul ignore start*/
  714. line.lineDiff.
  715. /*istanbul ignore end*/
  716. tokenize;
  717. jsonDiff.castInput = function (value) {
  718. /*istanbul ignore start*/
  719. var
  720. /*istanbul ignore end*/
  721. undefinedReplacement = this.options.undefinedReplacement;
  722. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), function (k, v) {
  723. if (typeof v === 'undefined') {
  724. return undefinedReplacement;
  725. }
  726. return v;
  727. }, ' ');
  728. };
  729. jsonDiff.equals = function (left, right) {
  730. return (
  731. /*istanbul ignore start*/
  732. _base2['default'].
  733. /*istanbul ignore end*/
  734. prototype.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
  735. );
  736. };
  737. function diffJson(oldObj, newObj, options) {
  738. return jsonDiff.diff(oldObj, newObj, options);
  739. } // This function handles the presence of circular references by bailing out when encountering an
  740. // object that is already on the "stack" of items being processed.
  741. function canonicalize(obj, stack, replacementStack) {
  742. stack = stack || [];
  743. replacementStack = replacementStack || [];
  744. var i =
  745. /*istanbul ignore start*/
  746. void 0;
  747. for (i = 0; i < stack.length; i += 1) {
  748. if (stack[i] === obj) {
  749. return replacementStack[i];
  750. }
  751. }
  752. var canonicalizedObj =
  753. /*istanbul ignore start*/
  754. void 0;
  755. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  756. stack.push(obj);
  757. canonicalizedObj = new Array(obj.length);
  758. replacementStack.push(canonicalizedObj);
  759. for (i = 0; i < obj.length; i += 1) {
  760. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  761. }
  762. stack.pop();
  763. replacementStack.pop();
  764. return canonicalizedObj;
  765. }
  766. if (obj && obj.toJSON) {
  767. obj = obj.toJSON();
  768. }
  769. if (
  770. /*istanbul ignore start*/
  771. (typeof
  772. /*istanbul ignore end*/
  773. obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
  774. stack.push(obj);
  775. canonicalizedObj = {};
  776. replacementStack.push(canonicalizedObj);
  777. var sortedKeys = [],
  778. key =
  779. /*istanbul ignore start*/
  780. void 0;
  781. for (key in obj) {
  782. /* istanbul ignore else */
  783. if (obj.hasOwnProperty(key)) {
  784. sortedKeys.push(key);
  785. }
  786. }
  787. sortedKeys.sort();
  788. for (i = 0; i < sortedKeys.length; i += 1) {
  789. key = sortedKeys[i];
  790. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  791. }
  792. stack.pop();
  793. replacementStack.pop();
  794. } else {
  795. canonicalizedObj = obj;
  796. }
  797. return canonicalizedObj;
  798. }
  799. });
  800. unwrapExports(json);
  801. var array = createCommonjsModule(function (module, exports) {
  802. /*istanbul ignore start*/
  803. 'use strict';
  804. exports.__esModule = true;
  805. exports.arrayDiff = undefined;
  806. exports.
  807. /*istanbul ignore end*/
  808. diffArrays = diffArrays;
  809. /*istanbul ignore start*/
  810. var _base2 = _interopRequireDefault(base);
  811. function _interopRequireDefault(obj) {
  812. return obj && obj.__esModule ? obj : {
  813. 'default': obj
  814. };
  815. }
  816. /*istanbul ignore end*/
  817. var arrayDiff =
  818. /*istanbul ignore start*/
  819. exports.
  820. /*istanbul ignore end*/
  821. arrayDiff = new
  822. /*istanbul ignore start*/
  823. _base2['default']();
  824. arrayDiff.tokenize = arrayDiff.join = function (value) {
  825. return value.slice();
  826. };
  827. function diffArrays(oldArr, newArr, callback) {
  828. return arrayDiff.diff(oldArr, newArr, callback);
  829. }
  830. });
  831. unwrapExports(array);
  832. var parse = createCommonjsModule(function (module, exports) {
  833. /*istanbul ignore start*/
  834. 'use strict';
  835. exports.__esModule = true;
  836. exports.
  837. /*istanbul ignore end*/
  838. parsePatch = parsePatch;
  839. function parsePatch(uniDiff) {
  840. /*istanbul ignore start*/
  841. var
  842. /*istanbul ignore end*/
  843. options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  844. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  845. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  846. list = [],
  847. i = 0;
  848. function parseIndex() {
  849. var index = {};
  850. list.push(index); // Parse diff metadata
  851. while (i < diffstr.length) {
  852. var line = diffstr[i]; // File header found, end parsing diff metadata
  853. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  854. break;
  855. } // Diff index
  856. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  857. if (header) {
  858. index.index = header[1];
  859. }
  860. i++;
  861. } // Parse file headers if they are defined. Unified diff requires them, but
  862. // there's no technical issues to have an isolated hunk without file header
  863. parseFileHeader(index);
  864. parseFileHeader(index); // Parse hunks
  865. index.hunks = [];
  866. while (i < diffstr.length) {
  867. var _line = diffstr[i];
  868. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  869. break;
  870. } else if (/^@@/.test(_line)) {
  871. index.hunks.push(parseHunk());
  872. } else if (_line && options.strict) {
  873. // Ignore unexpected content unless in strict mode
  874. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  875. } else {
  876. i++;
  877. }
  878. }
  879. } // Parses the --- and +++ headers, if none are found, no lines
  880. // are consumed.
  881. function parseFileHeader(index) {
  882. var headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
  883. var fileHeader = headerPattern.exec(diffstr[i]);
  884. if (fileHeader) {
  885. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  886. index[keyPrefix + 'FileName'] = fileHeader[2];
  887. index[keyPrefix + 'Header'] = fileHeader[3];
  888. i++;
  889. }
  890. } // Parses a hunk
  891. // This assumes that we are at the start of a hunk.
  892. function parseHunk() {
  893. var chunkHeaderIndex = i,
  894. chunkHeaderLine = diffstr[i++],
  895. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  896. var hunk = {
  897. oldStart: +chunkHeader[1],
  898. oldLines: +chunkHeader[2] || 1,
  899. newStart: +chunkHeader[3],
  900. newLines: +chunkHeader[4] || 1,
  901. lines: [],
  902. linedelimiters: []
  903. };
  904. var addCount = 0,
  905. removeCount = 0;
  906. for (; i < diffstr.length; i++) {
  907. // Lines starting with '---' could be mistaken for the "remove line" operation
  908. // But they could be the header for the next file. Therefore prune such cases out.
  909. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  910. break;
  911. }
  912. var operation = diffstr[i][0];
  913. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  914. hunk.lines.push(diffstr[i]);
  915. hunk.linedelimiters.push(delimiters[i] || '\n');
  916. if (operation === '+') {
  917. addCount++;
  918. } else if (operation === '-') {
  919. removeCount++;
  920. } else if (operation === ' ') {
  921. addCount++;
  922. removeCount++;
  923. }
  924. } else {
  925. break;
  926. }
  927. } // Handle the empty block count case
  928. if (!addCount && hunk.newLines === 1) {
  929. hunk.newLines = 0;
  930. }
  931. if (!removeCount && hunk.oldLines === 1) {
  932. hunk.oldLines = 0;
  933. } // Perform optional sanity checking
  934. if (options.strict) {
  935. if (addCount !== hunk.newLines) {
  936. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  937. }
  938. if (removeCount !== hunk.oldLines) {
  939. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  940. }
  941. }
  942. return hunk;
  943. }
  944. while (i < diffstr.length) {
  945. parseIndex();
  946. }
  947. return list;
  948. }
  949. });
  950. unwrapExports(parse);
  951. var distanceIterator = createCommonjsModule(function (module, exports) {
  952. /*istanbul ignore start*/
  953. "use strict";
  954. exports.__esModule = true;
  955. exports["default"] =
  956. /*istanbul ignore end*/
  957. function (start, minLine, maxLine) {
  958. var wantForward = true,
  959. backwardExhausted = false,
  960. forwardExhausted = false,
  961. localOffset = 1;
  962. return function iterator() {
  963. if (wantForward && !forwardExhausted) {
  964. if (backwardExhausted) {
  965. localOffset++;
  966. } else {
  967. wantForward = false;
  968. } // Check if trying to fit beyond text length, and if not, check it fits
  969. // after offset location (or desired location on first iteration)
  970. if (start + localOffset <= maxLine) {
  971. return localOffset;
  972. }
  973. forwardExhausted = true;
  974. }
  975. if (!backwardExhausted) {
  976. if (!forwardExhausted) {
  977. wantForward = true;
  978. } // Check if trying to fit before text beginning, and if not, check it fits
  979. // before offset location
  980. if (minLine <= start - localOffset) {
  981. return -localOffset++;
  982. }
  983. backwardExhausted = true;
  984. return iterator();
  985. } // We tried to fit hunk before text beginning and beyond text lenght, then
  986. // hunk can't fit on the text. Return undefined
  987. };
  988. };
  989. });
  990. unwrapExports(distanceIterator);
  991. var apply = createCommonjsModule(function (module, exports) {
  992. /*istanbul ignore start*/
  993. 'use strict';
  994. exports.__esModule = true;
  995. exports.
  996. /*istanbul ignore end*/
  997. applyPatch = applyPatch;
  998. /*istanbul ignore start*/
  999. exports.
  1000. /*istanbul ignore end*/
  1001. applyPatches = applyPatches;
  1002. /*istanbul ignore start*/
  1003. var _distanceIterator2 = _interopRequireDefault(distanceIterator);
  1004. function _interopRequireDefault(obj) {
  1005. return obj && obj.__esModule ? obj : {
  1006. 'default': obj
  1007. };
  1008. }
  1009. /*istanbul ignore end*/
  1010. function applyPatch(source, uniDiff) {
  1011. /*istanbul ignore start*/
  1012. var
  1013. /*istanbul ignore end*/
  1014. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  1015. if (typeof uniDiff === 'string') {
  1016. uniDiff =
  1017. /*istanbul ignore start*/
  1018. (0, parse.parsePatch
  1019. /*istanbul ignore end*/
  1020. )(uniDiff);
  1021. }
  1022. if (Array.isArray(uniDiff)) {
  1023. if (uniDiff.length > 1) {
  1024. throw new Error('applyPatch only works with a single input.');
  1025. }
  1026. uniDiff = uniDiff[0];
  1027. } // Apply the diff to the input
  1028. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  1029. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  1030. hunks = uniDiff.hunks,
  1031. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent)
  1032. /*istanbul ignore start*/
  1033. {
  1034. return (
  1035. /*istanbul ignore end*/
  1036. line === patchContent
  1037. );
  1038. },
  1039. errorCount = 0,
  1040. fuzzFactor = options.fuzzFactor || 0,
  1041. minLine = 0,
  1042. offset = 0,
  1043. removeEOFNL =
  1044. /*istanbul ignore start*/
  1045. void 0
  1046. /*istanbul ignore end*/
  1047. ,
  1048. addEOFNL =
  1049. /*istanbul ignore start*/
  1050. void 0;
  1051. /**
  1052. * Checks if the hunk exactly fits on the provided location
  1053. */
  1054. function hunkFits(hunk, toPos) {
  1055. for (var j = 0; j < hunk.lines.length; j++) {
  1056. var line = hunk.lines[j],
  1057. operation = line[0],
  1058. content = line.substr(1);
  1059. if (operation === ' ' || operation === '-') {
  1060. // Context sanity check
  1061. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  1062. errorCount++;
  1063. if (errorCount > fuzzFactor) {
  1064. return false;
  1065. }
  1066. }
  1067. toPos++;
  1068. }
  1069. }
  1070. return true;
  1071. } // Search best fit offsets for each hunk based on the previous ones
  1072. for (var i = 0; i < hunks.length; i++) {
  1073. var hunk = hunks[i],
  1074. maxLine = lines.length - hunk.oldLines,
  1075. localOffset = 0,
  1076. toPos = offset + hunk.oldStart - 1;
  1077. var iterator =
  1078. /*istanbul ignore start*/
  1079. (0, _distanceIterator2['default']
  1080. /*istanbul ignore end*/
  1081. )(toPos, minLine, maxLine);
  1082. for (; localOffset !== undefined; localOffset = iterator()) {
  1083. if (hunkFits(hunk, toPos + localOffset)) {
  1084. hunk.offset = offset += localOffset;
  1085. break;
  1086. }
  1087. }
  1088. if (localOffset === undefined) {
  1089. return false;
  1090. } // Set lower text limit to end of the current hunk, so next ones don't try
  1091. // to fit over already patched text
  1092. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  1093. } // Apply patch hunks
  1094. for (var _i = 0; _i < hunks.length; _i++) {
  1095. var _hunk = hunks[_i],
  1096. _toPos = _hunk.offset + _hunk.newStart - 1;
  1097. if (_hunk.newLines == 0) {
  1098. _toPos++;
  1099. }
  1100. for (var j = 0; j < _hunk.lines.length; j++) {
  1101. var line = _hunk.lines[j],
  1102. operation = line[0],
  1103. content = line.substr(1),
  1104. delimiter = _hunk.linedelimiters[j];
  1105. if (operation === ' ') {
  1106. _toPos++;
  1107. } else if (operation === '-') {
  1108. lines.splice(_toPos, 1);
  1109. delimiters.splice(_toPos, 1);
  1110. /* istanbul ignore else */
  1111. } else if (operation === '+') {
  1112. lines.splice(_toPos, 0, content);
  1113. delimiters.splice(_toPos, 0, delimiter);
  1114. _toPos++;
  1115. } else if (operation === '\\') {
  1116. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  1117. if (previousOperation === '+') {
  1118. removeEOFNL = true;
  1119. } else if (previousOperation === '-') {
  1120. addEOFNL = true;
  1121. }
  1122. }
  1123. }
  1124. } // Handle EOFNL insertion/removal
  1125. if (removeEOFNL) {
  1126. while (!lines[lines.length - 1]) {
  1127. lines.pop();
  1128. delimiters.pop();
  1129. }
  1130. } else if (addEOFNL) {
  1131. lines.push('');
  1132. delimiters.push('\n');
  1133. }
  1134. for (var _k = 0; _k < lines.length - 1; _k++) {
  1135. lines[_k] = lines[_k] + delimiters[_k];
  1136. }
  1137. return lines.join('');
  1138. } // Wrapper that supports multiple file patches via callbacks.
  1139. function applyPatches(uniDiff, options) {
  1140. if (typeof uniDiff === 'string') {
  1141. uniDiff =
  1142. /*istanbul ignore start*/
  1143. (0, parse.parsePatch
  1144. /*istanbul ignore end*/
  1145. )(uniDiff);
  1146. }
  1147. var currentIndex = 0;
  1148. function processIndex() {
  1149. var index = uniDiff[currentIndex++];
  1150. if (!index) {
  1151. return options.complete();
  1152. }
  1153. options.loadFile(index, function (err, data) {
  1154. if (err) {
  1155. return options.complete(err);
  1156. }
  1157. var updatedContent = applyPatch(data, index, options);
  1158. options.patched(index, updatedContent, function (err) {
  1159. if (err) {
  1160. return options.complete(err);
  1161. }
  1162. processIndex();
  1163. });
  1164. });
  1165. }
  1166. processIndex();
  1167. }
  1168. });
  1169. unwrapExports(apply);
  1170. var create = createCommonjsModule(function (module, exports) {
  1171. /*istanbul ignore start*/
  1172. 'use strict';
  1173. exports.__esModule = true;
  1174. exports.
  1175. /*istanbul ignore end*/
  1176. structuredPatch = structuredPatch;
  1177. /*istanbul ignore start*/
  1178. exports.
  1179. /*istanbul ignore end*/
  1180. createTwoFilesPatch = createTwoFilesPatch;
  1181. /*istanbul ignore start*/
  1182. exports.
  1183. /*istanbul ignore end*/
  1184. createPatch = createPatch;
  1185. /*istanbul ignore start*/
  1186. function _toConsumableArray(arr) {
  1187. if (Array.isArray(arr)) {
  1188. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
  1189. arr2[i] = arr[i];
  1190. }
  1191. return arr2;
  1192. } else {
  1193. return Array.from(arr);
  1194. }
  1195. }
  1196. /*istanbul ignore end*/
  1197. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1198. if (!options) {
  1199. options = {};
  1200. }
  1201. if (typeof options.context === 'undefined') {
  1202. options.context = 4;
  1203. }
  1204. var diff =
  1205. /*istanbul ignore start*/
  1206. (0, line.diffLines
  1207. /*istanbul ignore end*/
  1208. )(oldStr, newStr, options);
  1209. diff.push({
  1210. value: '',
  1211. lines: []
  1212. }); // Append an empty value to make cleanup easier
  1213. function contextLines(lines) {
  1214. return lines.map(function (entry) {
  1215. return ' ' + entry;
  1216. });
  1217. }
  1218. var hunks = [];
  1219. var oldRangeStart = 0,
  1220. newRangeStart = 0,
  1221. curRange = [],
  1222. oldLine = 1,
  1223. newLine = 1;
  1224. /*istanbul ignore start*/
  1225. var _loop = function _loop(
  1226. /*istanbul ignore end*/
  1227. i) {
  1228. var current = diff[i],
  1229. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  1230. current.lines = lines;
  1231. if (current.added || current.removed) {
  1232. /*istanbul ignore start*/
  1233. var _curRange;
  1234. /*istanbul ignore end*/
  1235. // If we have previous context, start with that
  1236. if (!oldRangeStart) {
  1237. var prev = diff[i - 1];
  1238. oldRangeStart = oldLine;
  1239. newRangeStart = newLine;
  1240. if (prev) {
  1241. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  1242. oldRangeStart -= curRange.length;
  1243. newRangeStart -= curRange.length;
  1244. }
  1245. } // Output our changes
  1246. /*istanbul ignore start*/
  1247. (_curRange =
  1248. /*istanbul ignore end*/
  1249. curRange).push.
  1250. /*istanbul ignore start*/
  1251. apply
  1252. /*istanbul ignore end*/
  1253. (
  1254. /*istanbul ignore start*/
  1255. _curRange
  1256. /*istanbul ignore end*/
  1257. ,
  1258. /*istanbul ignore start*/
  1259. _toConsumableArray(
  1260. /*istanbul ignore end*/
  1261. lines.map(function (entry) {
  1262. return (current.added ? '+' : '-') + entry;
  1263. }))); // Track the updated file position
  1264. if (current.added) {
  1265. newLine += lines.length;
  1266. } else {
  1267. oldLine += lines.length;
  1268. }
  1269. } else {
  1270. // Identical context lines. Track line changes
  1271. if (oldRangeStart) {
  1272. // Close out any changes that have been output (or join overlapping)
  1273. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  1274. /*istanbul ignore start*/
  1275. var _curRange2;
  1276. /*istanbul ignore end*/
  1277. // Overlapping
  1278. /*istanbul ignore start*/
  1279. (_curRange2 =
  1280. /*istanbul ignore end*/
  1281. curRange).push.
  1282. /*istanbul ignore start*/
  1283. apply
  1284. /*istanbul ignore end*/
  1285. (
  1286. /*istanbul ignore start*/
  1287. _curRange2
  1288. /*istanbul ignore end*/
  1289. ,
  1290. /*istanbul ignore start*/
  1291. _toConsumableArray(
  1292. /*istanbul ignore end*/
  1293. contextLines(lines)));
  1294. } else {
  1295. /*istanbul ignore start*/
  1296. var _curRange3;
  1297. /*istanbul ignore end*/
  1298. // end the range and output
  1299. var contextSize = Math.min(lines.length, options.context);
  1300. /*istanbul ignore start*/
  1301. (_curRange3 =
  1302. /*istanbul ignore end*/
  1303. curRange).push.
  1304. /*istanbul ignore start*/
  1305. apply
  1306. /*istanbul ignore end*/
  1307. (
  1308. /*istanbul ignore start*/
  1309. _curRange3
  1310. /*istanbul ignore end*/
  1311. ,
  1312. /*istanbul ignore start*/
  1313. _toConsumableArray(
  1314. /*istanbul ignore end*/
  1315. contextLines(lines.slice(0, contextSize))));
  1316. var hunk = {
  1317. oldStart: oldRangeStart,
  1318. oldLines: oldLine - oldRangeStart + contextSize,
  1319. newStart: newRangeStart,
  1320. newLines: newLine - newRangeStart + contextSize,
  1321. lines: curRange
  1322. };
  1323. if (i >= diff.length - 2 && lines.length <= options.context) {
  1324. // EOF is inside this hunk
  1325. var oldEOFNewline = /\n$/.test(oldStr);
  1326. var newEOFNewline = /\n$/.test(newStr);
  1327. if (lines.length == 0 && !oldEOFNewline) {
  1328. // special case: old has no eol and no trailing context; no-nl can end up before adds
  1329. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  1330. } else if (!oldEOFNewline || !newEOFNewline) {
  1331. curRange.push('\\ No newline at end of file');
  1332. }
  1333. }
  1334. hunks.push(hunk);
  1335. oldRangeStart = 0;
  1336. newRangeStart = 0;
  1337. curRange = [];
  1338. }
  1339. }
  1340. oldLine += lines.length;
  1341. newLine += lines.length;
  1342. }
  1343. };
  1344. for (var i = 0; i < diff.length; i++) {
  1345. /*istanbul ignore start*/
  1346. _loop(
  1347. /*istanbul ignore end*/
  1348. i);
  1349. }
  1350. return {
  1351. oldFileName: oldFileName,
  1352. newFileName: newFileName,
  1353. oldHeader: oldHeader,
  1354. newHeader: newHeader,
  1355. hunks: hunks
  1356. };
  1357. }
  1358. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1359. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  1360. var ret = [];
  1361. if (oldFileName == newFileName) {
  1362. ret.push('Index: ' + oldFileName);
  1363. }
  1364. ret.push('===================================================================');
  1365. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  1366. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  1367. for (var i = 0; i < diff.hunks.length; i++) {
  1368. var hunk = diff.hunks[i];
  1369. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  1370. ret.push.apply(ret, hunk.lines);
  1371. }
  1372. return ret.join('\n') + '\n';
  1373. }
  1374. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  1375. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  1376. }
  1377. });
  1378. unwrapExports(create);
  1379. var dmp = createCommonjsModule(function (module, exports) {
  1380. /*istanbul ignore start*/
  1381. "use strict";
  1382. exports.__esModule = true;
  1383. exports.
  1384. /*istanbul ignore end*/
  1385. convertChangesToDMP = convertChangesToDMP; // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  1386. function convertChangesToDMP(changes) {
  1387. var ret = [],
  1388. change =
  1389. /*istanbul ignore start*/
  1390. void 0
  1391. /*istanbul ignore end*/
  1392. ,
  1393. operation =
  1394. /*istanbul ignore start*/
  1395. void 0;
  1396. for (var i = 0; i < changes.length; i++) {
  1397. change = changes[i];
  1398. if (change.added) {
  1399. operation = 1;
  1400. } else if (change.removed) {
  1401. operation = -1;
  1402. } else {
  1403. operation = 0;
  1404. }
  1405. ret.push([operation, change.value]);
  1406. }
  1407. return ret;
  1408. }
  1409. });
  1410. unwrapExports(dmp);
  1411. var xml = createCommonjsModule(function (module, exports) {
  1412. /*istanbul ignore start*/
  1413. 'use strict';
  1414. exports.__esModule = true;
  1415. exports.
  1416. /*istanbul ignore end*/
  1417. convertChangesToXML = convertChangesToXML;
  1418. function convertChangesToXML(changes) {
  1419. var ret = [];
  1420. for (var i = 0; i < changes.length; i++) {
  1421. var change = changes[i];
  1422. if (change.added) {
  1423. ret.push('<ins>');
  1424. } else if (change.removed) {
  1425. ret.push('<del>');
  1426. }
  1427. ret.push(escapeHTML(change.value));
  1428. if (change.added) {
  1429. ret.push('</ins>');
  1430. } else if (change.removed) {
  1431. ret.push('</del>');
  1432. }
  1433. }
  1434. return ret.join('');
  1435. }
  1436. function escapeHTML(s) {
  1437. var n = s;
  1438. n = n.replace(/&/g, '&amp;');
  1439. n = n.replace(/</g, '&lt;');
  1440. n = n.replace(/>/g, '&gt;');
  1441. n = n.replace(/"/g, '&quot;');
  1442. return n;
  1443. }
  1444. });
  1445. unwrapExports(xml);
  1446. var lib = createCommonjsModule(function (module, exports) {
  1447. /*istanbul ignore start*/
  1448. 'use strict';
  1449. exports.__esModule = true;
  1450. 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;
  1451. /*istanbul ignore end*/
  1452. /*istanbul ignore start*/
  1453. var _base2 = _interopRequireDefault(base);
  1454. /*istanbul ignore end*/
  1455. /*istanbul ignore start*/
  1456. function _interopRequireDefault(obj) {
  1457. return obj && obj.__esModule ? obj : {
  1458. 'default': obj
  1459. };
  1460. }
  1461. exports.
  1462. /*istanbul ignore end*/
  1463. Diff = _base2['default'];
  1464. /*istanbul ignore start*/
  1465. exports.
  1466. /*istanbul ignore end*/
  1467. diffChars = character.diffChars;
  1468. /*istanbul ignore start*/
  1469. exports.
  1470. /*istanbul ignore end*/
  1471. diffWords = word.diffWords;
  1472. /*istanbul ignore start*/
  1473. exports.
  1474. /*istanbul ignore end*/
  1475. diffWordsWithSpace = word.diffWordsWithSpace;
  1476. /*istanbul ignore start*/
  1477. exports.
  1478. /*istanbul ignore end*/
  1479. diffLines = line.diffLines;
  1480. /*istanbul ignore start*/
  1481. exports.
  1482. /*istanbul ignore end*/
  1483. diffTrimmedLines = line.diffTrimmedLines;
  1484. /*istanbul ignore start*/
  1485. exports.
  1486. /*istanbul ignore end*/
  1487. diffSentences = sentence.diffSentences;
  1488. /*istanbul ignore start*/
  1489. exports.
  1490. /*istanbul ignore end*/
  1491. diffCss = css.diffCss;
  1492. /*istanbul ignore start*/
  1493. exports.
  1494. /*istanbul ignore end*/
  1495. diffJson = json.diffJson;
  1496. /*istanbul ignore start*/
  1497. exports.
  1498. /*istanbul ignore end*/
  1499. diffArrays = array.diffArrays;
  1500. /*istanbul ignore start*/
  1501. exports.
  1502. /*istanbul ignore end*/
  1503. structuredPatch = create.structuredPatch;
  1504. /*istanbul ignore start*/
  1505. exports.
  1506. /*istanbul ignore end*/
  1507. createTwoFilesPatch = create.createTwoFilesPatch;
  1508. /*istanbul ignore start*/
  1509. exports.
  1510. /*istanbul ignore end*/
  1511. createPatch = create.createPatch;
  1512. /*istanbul ignore start*/
  1513. exports.
  1514. /*istanbul ignore end*/
  1515. applyPatch = apply.applyPatch;
  1516. /*istanbul ignore start*/
  1517. exports.
  1518. /*istanbul ignore end*/
  1519. applyPatches = apply.applyPatches;
  1520. /*istanbul ignore start*/
  1521. exports.
  1522. /*istanbul ignore end*/
  1523. parsePatch = parse.parsePatch;
  1524. /*istanbul ignore start*/
  1525. exports.
  1526. /*istanbul ignore end*/
  1527. convertChangesToDMP = dmp.convertChangesToDMP;
  1528. /*istanbul ignore start*/
  1529. exports.
  1530. /*istanbul ignore end*/
  1531. convertChangesToXML = xml.convertChangesToXML;
  1532. /*istanbul ignore start*/
  1533. exports.
  1534. /*istanbul ignore end*/
  1535. canonicalize = json.canonicalize;
  1536. /* See LICENSE file for terms of use */
  1537. /*
  1538. * Text diff implementation.
  1539. *
  1540. * This library supports the following APIS:
  1541. * JsDiff.diffChars: Character by character diff
  1542. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  1543. * JsDiff.diffLines: Line based diff
  1544. *
  1545. * JsDiff.diffCss: Diff targeted at CSS content
  1546. *
  1547. * These methods are based on the implementation proposed in
  1548. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  1549. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  1550. */
  1551. });
  1552. unwrapExports(lib);
  1553. /*!
  1554. * normalize-path <https://github.com/jonschlinkert/normalize-path>
  1555. *
  1556. * Copyright (c) 2014-2018, Jon Schlinkert.
  1557. * Released under the MIT License.
  1558. */
  1559. var normalizePath = function normalizePath(path$$1, stripTrailing) {
  1560. if (typeof path$$1 !== 'string') {
  1561. throw new TypeError('expected path to be a string');
  1562. }
  1563. if (path$$1 === '\\' || path$$1 === '/') return '/';
  1564. var len = path$$1.length;
  1565. if (len <= 1) return path$$1; // ensure that win32 namespaces has two leading slashes, so that the path is
  1566. // handled properly by the win32 version of path.parse() after being normalized
  1567. // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
  1568. var prefix = '';
  1569. if (len > 4 && path$$1[3] === '\\') {
  1570. var ch = path$$1[2];
  1571. if ((ch === '?' || ch === '.') && path$$1.slice(0, 2) === '\\\\') {
  1572. path$$1 = path$$1.slice(2);
  1573. prefix = '//';
  1574. }
  1575. }
  1576. var segs = path$$1.split(/[/\\]+/);
  1577. if (stripTrailing !== false && segs[segs.length - 1] === '') {
  1578. segs.pop();
  1579. }
  1580. return prefix + segs.join('/');
  1581. };
  1582. function _classCallCheck(instance, Constructor) {
  1583. if (!(instance instanceof Constructor)) {
  1584. throw new TypeError("Cannot call a class as a function");
  1585. }
  1586. }
  1587. function _defineProperties(target, props) {
  1588. for (var i = 0; i < props.length; i++) {
  1589. var descriptor = props[i];
  1590. descriptor.enumerable = descriptor.enumerable || false;
  1591. descriptor.configurable = true;
  1592. if ("value" in descriptor) descriptor.writable = true;
  1593. Object.defineProperty(target, descriptor.key, descriptor);
  1594. }
  1595. }
  1596. function _createClass(Constructor, protoProps, staticProps) {
  1597. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1598. if (staticProps) _defineProperties(Constructor, staticProps);
  1599. return Constructor;
  1600. }
  1601. function _inherits(subClass, superClass) {
  1602. if (typeof superClass !== "function" && superClass !== null) {
  1603. throw new TypeError("Super expression must either be null or a function");
  1604. }
  1605. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1606. constructor: {
  1607. value: subClass,
  1608. writable: true,
  1609. configurable: true
  1610. }
  1611. });
  1612. if (superClass) _setPrototypeOf(subClass, superClass);
  1613. }
  1614. function _getPrototypeOf(o) {
  1615. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  1616. return o.__proto__ || Object.getPrototypeOf(o);
  1617. };
  1618. return _getPrototypeOf(o);
  1619. }
  1620. function _setPrototypeOf(o, p) {
  1621. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1622. o.__proto__ = p;
  1623. return o;
  1624. };
  1625. return _setPrototypeOf(o, p);
  1626. }
  1627. function isNativeReflectConstruct() {
  1628. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1629. if (Reflect.construct.sham) return false;
  1630. if (typeof Proxy === "function") return true;
  1631. try {
  1632. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  1633. return true;
  1634. } catch (e) {
  1635. return false;
  1636. }
  1637. }
  1638. function _construct(Parent, args, Class) {
  1639. if (isNativeReflectConstruct()) {
  1640. _construct = Reflect.construct;
  1641. } else {
  1642. _construct = function _construct(Parent, args, Class) {
  1643. var a = [null];
  1644. a.push.apply(a, args);
  1645. var Constructor = Function.bind.apply(Parent, a);
  1646. var instance = new Constructor();
  1647. if (Class) _setPrototypeOf(instance, Class.prototype);
  1648. return instance;
  1649. };
  1650. }
  1651. return _construct.apply(null, arguments);
  1652. }
  1653. function _isNativeFunction(fn) {
  1654. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  1655. }
  1656. function _wrapNativeSuper(Class) {
  1657. var _cache = typeof Map === "function" ? new Map() : undefined;
  1658. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1659. if (Class === null || !_isNativeFunction(Class)) return Class;
  1660. if (typeof Class !== "function") {
  1661. throw new TypeError("Super expression must either be null or a function");
  1662. }
  1663. if (typeof _cache !== "undefined") {
  1664. if (_cache.has(Class)) return _cache.get(Class);
  1665. _cache.set(Class, Wrapper);
  1666. }
  1667. function Wrapper() {
  1668. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1669. }
  1670. Wrapper.prototype = Object.create(Class.prototype, {
  1671. constructor: {
  1672. value: Wrapper,
  1673. enumerable: false,
  1674. writable: true,
  1675. configurable: true
  1676. }
  1677. });
  1678. return _setPrototypeOf(Wrapper, Class);
  1679. };
  1680. return _wrapNativeSuper(Class);
  1681. }
  1682. function _assertThisInitialized(self) {
  1683. if (self === void 0) {
  1684. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1685. }
  1686. return self;
  1687. }
  1688. function _possibleConstructorReturn(self, call) {
  1689. if (call && (typeof call === "object" || typeof call === "function")) {
  1690. return call;
  1691. }
  1692. return _assertThisInitialized(self);
  1693. }
  1694. function _superPropBase(object, property) {
  1695. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  1696. object = _getPrototypeOf(object);
  1697. if (object === null) break;
  1698. }
  1699. return object;
  1700. }
  1701. function _get(target, property, receiver) {
  1702. if (typeof Reflect !== "undefined" && Reflect.get) {
  1703. _get = Reflect.get;
  1704. } else {
  1705. _get = function _get(target, property, receiver) {
  1706. var base = _superPropBase(target, property);
  1707. if (!base) return;
  1708. var desc = Object.getOwnPropertyDescriptor(base, property);
  1709. if (desc.get) {
  1710. return desc.get.call(receiver);
  1711. }
  1712. return desc.value;
  1713. };
  1714. }
  1715. return _get(target, property, receiver || target);
  1716. }
  1717. function _slicedToArray(arr, i) {
  1718. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  1719. }
  1720. function _toArray(arr) {
  1721. return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
  1722. }
  1723. function _toConsumableArray(arr) {
  1724. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  1725. }
  1726. function _arrayWithoutHoles(arr) {
  1727. if (Array.isArray(arr)) {
  1728. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  1729. return arr2;
  1730. }
  1731. }
  1732. function _arrayWithHoles(arr) {
  1733. if (Array.isArray(arr)) return arr;
  1734. }
  1735. function _iterableToArray(iter) {
  1736. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  1737. }
  1738. function _iterableToArrayLimit(arr, i) {
  1739. var _arr = [];
  1740. var _n = true;
  1741. var _d = false;
  1742. var _e = undefined;
  1743. try {
  1744. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  1745. _arr.push(_s.value);
  1746. if (i && _arr.length === i) break;
  1747. }
  1748. } catch (err) {
  1749. _d = true;
  1750. _e = err;
  1751. } finally {
  1752. try {
  1753. if (!_n && _i["return"] != null) _i["return"]();
  1754. } finally {
  1755. if (_d) throw _e;
  1756. }
  1757. }
  1758. return _arr;
  1759. }
  1760. function _nonIterableSpread() {
  1761. throw new TypeError("Invalid attempt to spread non-iterable instance");
  1762. }
  1763. function _nonIterableRest() {
  1764. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  1765. }
  1766. function _toPrimitive(input, hint) {
  1767. if (typeof input !== "object" || input === null) return input;
  1768. var prim = input[Symbol.toPrimitive];
  1769. if (prim !== undefined) {
  1770. var res = prim.call(input, hint || "default");
  1771. if (typeof res !== "object") return res;
  1772. throw new TypeError("@@toPrimitive must return a primitive value.");
  1773. }
  1774. return (hint === "string" ? String : Number)(input);
  1775. }
  1776. function _toPropertyKey(arg) {
  1777. var key = _toPrimitive(arg, "string");
  1778. return typeof key === "symbol" ? key : String(key);
  1779. }
  1780. function _addElementPlacement(element, placements, silent) {
  1781. var keys = placements[element.placement];
  1782. if (!silent && keys.indexOf(element.key) !== -1) {
  1783. throw new TypeError("Duplicated element (" + element.key + ")");
  1784. }
  1785. keys.push(element.key);
  1786. }
  1787. function _fromElementDescriptor(element) {
  1788. var obj = {
  1789. kind: element.kind,
  1790. key: element.key,
  1791. placement: element.placement,
  1792. descriptor: element.descriptor
  1793. };
  1794. var desc = {
  1795. value: "Descriptor",
  1796. configurable: true
  1797. };
  1798. Object.defineProperty(obj, Symbol.toStringTag, desc);
  1799. if (element.kind === "field") obj.initializer = element.initializer;
  1800. return obj;
  1801. }
  1802. function _toElementDescriptors(elementObjects) {
  1803. if (elementObjects === undefined) return;
  1804. return _toArray(elementObjects).map(function (elementObject) {
  1805. var element = _toElementDescriptor(elementObject);
  1806. _disallowProperty(elementObject, "finisher", "An element descriptor");
  1807. _disallowProperty(elementObject, "extras", "An element descriptor");
  1808. return element;
  1809. });
  1810. }
  1811. function _toElementDescriptor(elementObject) {
  1812. var kind = String(elementObject.kind);
  1813. if (kind !== "method" && kind !== "field") {
  1814. throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
  1815. }
  1816. var key = _toPropertyKey(elementObject.key);
  1817. var placement = String(elementObject.placement);
  1818. if (placement !== "static" && placement !== "prototype" && placement !== "own") {
  1819. throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"');
  1820. }
  1821. var descriptor = elementObject.descriptor;
  1822. _disallowProperty(elementObject, "elements", "An element descriptor");
  1823. var element = {
  1824. kind: kind,
  1825. key: key,
  1826. placement: placement,
  1827. descriptor: Object.assign({}, descriptor)
  1828. };
  1829. if (kind !== "field") {
  1830. _disallowProperty(elementObject, "initializer", "A method descriptor");
  1831. } else {
  1832. _disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");
  1833. _disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");
  1834. _disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");
  1835. element.initializer = elementObject.initializer;
  1836. }
  1837. return element;
  1838. }
  1839. function _toElementFinisherExtras(elementObject) {
  1840. var element = _toElementDescriptor(elementObject);
  1841. var finisher = _optionalCallableProperty(elementObject, "finisher");
  1842. var extras = _toElementDescriptors(elementObject.extras);
  1843. return {
  1844. element: element,
  1845. finisher: finisher,
  1846. extras: extras
  1847. };
  1848. }
  1849. function _fromClassDescriptor(elements) {
  1850. var obj = {
  1851. kind: "class",
  1852. elements: elements.map(_fromElementDescriptor)
  1853. };
  1854. var desc = {
  1855. value: "Descriptor",
  1856. configurable: true
  1857. };
  1858. Object.defineProperty(obj, Symbol.toStringTag, desc);
  1859. return obj;
  1860. }
  1861. function _toClassDescriptor(obj) {
  1862. var kind = String(obj.kind);
  1863. if (kind !== "class") {
  1864. throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
  1865. }
  1866. _disallowProperty(obj, "key", "A class descriptor");
  1867. _disallowProperty(obj, "placement", "A class descriptor");
  1868. _disallowProperty(obj, "descriptor", "A class descriptor");
  1869. _disallowProperty(obj, "initializer", "A class descriptor");
  1870. _disallowProperty(obj, "extras", "A class descriptor");
  1871. var finisher = _optionalCallableProperty(obj, "finisher");
  1872. var elements = _toElementDescriptors(obj.elements);
  1873. return {
  1874. elements: elements,
  1875. finisher: finisher
  1876. };
  1877. }
  1878. function _disallowProperty(obj, name, objectType) {
  1879. if (obj[name] !== undefined) {
  1880. throw new TypeError(objectType + " can't have a ." + name + " property.");
  1881. }
  1882. }
  1883. function _optionalCallableProperty(obj, name) {
  1884. var value = obj[name];
  1885. if (value !== undefined && typeof value !== "function") {
  1886. throw new TypeError("Expected '" + name + "' to be a function");
  1887. }
  1888. return value;
  1889. }
  1890. /**
  1891. * @class
  1892. */
  1893. var LineByLine =
  1894. /*#__PURE__*/
  1895. function () {
  1896. function LineByLine(file, options) {
  1897. _classCallCheck(this, LineByLine);
  1898. options = options || {};
  1899. if (!options.readChunk) options.readChunk = 1024;
  1900. if (!options.newLineCharacter) {
  1901. options.newLineCharacter = 0x0a; //linux line ending
  1902. } else {
  1903. options.newLineCharacter = options.newLineCharacter.charCodeAt(0);
  1904. }
  1905. if (typeof file === 'number') {
  1906. this.fd = file;
  1907. } else {
  1908. this.fd = fs.openSync(file, 'r');
  1909. }
  1910. this.options = options;
  1911. this.newLineCharacter = options.newLineCharacter;
  1912. this.reset();
  1913. }
  1914. _createClass(LineByLine, [{
  1915. key: "_searchInBuffer",
  1916. value: function _searchInBuffer(buffer, hexNeedle) {
  1917. var found = -1;
  1918. for (var i = 0; i <= buffer.length; i++) {
  1919. var b_byte = buffer[i];
  1920. if (b_byte === hexNeedle) {
  1921. found = i;
  1922. break;
  1923. }
  1924. }
  1925. return found;
  1926. }
  1927. }, {
  1928. key: "reset",
  1929. value: function reset() {
  1930. this.eofReached = false;
  1931. this.linesCache = [];
  1932. this.fdPosition = 0;
  1933. }
  1934. }, {
  1935. key: "close",
  1936. value: function close() {
  1937. fs.closeSync(this.fd);
  1938. this.fd = null;
  1939. }
  1940. }, {
  1941. key: "_extractLines",
  1942. value: function _extractLines(buffer) {
  1943. var line;
  1944. var lines = [];
  1945. var bufferPosition = 0;
  1946. var lastNewLineBufferPosition = 0;
  1947. while (true) {
  1948. var bufferPositionValue = buffer[bufferPosition++];
  1949. if (bufferPositionValue === this.newLineCharacter) {
  1950. line = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  1951. lines.push(line);
  1952. lastNewLineBufferPosition = bufferPosition;
  1953. } else if (!bufferPositionValue) {
  1954. break;
  1955. }
  1956. }
  1957. var leftovers = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  1958. if (leftovers.length) {
  1959. lines.push(leftovers);
  1960. }
  1961. return lines;
  1962. }
  1963. }, {
  1964. key: "_readChunk",
  1965. value: function _readChunk(lineLeftovers) {
  1966. var totalBytesRead = 0;
  1967. var bytesRead;
  1968. var buffers = [];
  1969. do {
  1970. var readBuffer = new Buffer(this.options.readChunk);
  1971. bytesRead = fs.readSync(this.fd, readBuffer, 0, this.options.readChunk, this.fdPosition);
  1972. totalBytesRead = totalBytesRead + bytesRead;
  1973. this.fdPosition = this.fdPosition + bytesRead;
  1974. buffers.push(readBuffer);
  1975. } while (bytesRead && this._searchInBuffer(buffers[buffers.length - 1], this.options.newLineCharacter) === -1);
  1976. var bufferData = Buffer.concat(buffers);
  1977. if (bytesRead < this.options.readChunk) {
  1978. this.eofReached = true;
  1979. bufferData = bufferData.slice(0, totalBytesRead);
  1980. }
  1981. if (totalBytesRead) {
  1982. this.linesCache = this._extractLines(bufferData);
  1983. if (lineLeftovers) {
  1984. this.linesCache[0] = Buffer.concat([lineLeftovers, this.linesCache[0]]);
  1985. }
  1986. }
  1987. return totalBytesRead;
  1988. }
  1989. }, {
  1990. key: "next",
  1991. value: function next() {
  1992. if (!this.fd) return false;
  1993. var line = false;
  1994. if (this.eofReached && this.linesCache.length === 0) {
  1995. return line;
  1996. }
  1997. var bytesRead;
  1998. if (!this.linesCache.length) {
  1999. bytesRead = this._readChunk();
  2000. }
  2001. if (this.linesCache.length) {
  2002. line = this.linesCache.shift();
  2003. var lastLineCharacter = line[line.length - 1];
  2004. if (lastLineCharacter !== 0x0a) {
  2005. bytesRead = this._readChunk(line);
  2006. if (bytesRead) {
  2007. line = this.linesCache.shift();
  2008. }
  2009. }
  2010. }
  2011. if (this.eofReached && this.linesCache.length === 0) {
  2012. this.close();
  2013. }
  2014. if (line && line[line.length - 1] === this.newLineCharacter) {
  2015. line = line.slice(0, line.length - 1);
  2016. }
  2017. return line;
  2018. }
  2019. }]);
  2020. return LineByLine;
  2021. }();
  2022. var readlines = LineByLine;
  2023. var ConfigError =
  2024. /*#__PURE__*/
  2025. function (_Error) {
  2026. _inherits(ConfigError, _Error);
  2027. function ConfigError() {
  2028. _classCallCheck(this, ConfigError);
  2029. return _possibleConstructorReturn(this, _getPrototypeOf(ConfigError).apply(this, arguments));
  2030. }
  2031. return ConfigError;
  2032. }(_wrapNativeSuper(Error));
  2033. var DebugError =
  2034. /*#__PURE__*/
  2035. function (_Error2) {
  2036. _inherits(DebugError, _Error2);
  2037. function DebugError() {
  2038. _classCallCheck(this, DebugError);
  2039. return _possibleConstructorReturn(this, _getPrototypeOf(DebugError).apply(this, arguments));
  2040. }
  2041. return DebugError;
  2042. }(_wrapNativeSuper(Error));
  2043. var UndefinedParserError$1 =
  2044. /*#__PURE__*/
  2045. function (_Error3) {
  2046. _inherits(UndefinedParserError, _Error3);
  2047. function UndefinedParserError() {
  2048. _classCallCheck(this, UndefinedParserError);
  2049. return _possibleConstructorReturn(this, _getPrototypeOf(UndefinedParserError).apply(this, arguments));
  2050. }
  2051. return UndefinedParserError;
  2052. }(_wrapNativeSuper(Error));
  2053. var errors = {
  2054. ConfigError,
  2055. DebugError,
  2056. UndefinedParserError: UndefinedParserError$1
  2057. };
  2058. var semver = createCommonjsModule(function (module, exports) {
  2059. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  2060. /* nomin */
  2061. var debug;
  2062. /* nomin */
  2063. if (typeof process === 'object' &&
  2064. /* nomin */
  2065. process.env &&
  2066. /* nomin */
  2067. process.env.NODE_DEBUG &&
  2068. /* nomin */
  2069. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  2070. /* nomin */
  2071. debug = function debug() {
  2072. /* nomin */
  2073. var args = Array.prototype.slice.call(arguments, 0);
  2074. /* nomin */
  2075. args.unshift('SEMVER');
  2076. /* nomin */
  2077. console.log.apply(console, args);
  2078. /* nomin */
  2079. };
  2080. /* nomin */
  2081. else
  2082. /* nomin */
  2083. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  2084. // Not necessarily the package version of this code.
  2085. exports.SEMVER_SPEC_VERSION = '2.0.0';
  2086. var MAX_LENGTH = 256;
  2087. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // The actual regexps go on exports.re
  2088. var re = exports.re = [];
  2089. var src = exports.src = [];
  2090. var R = 0; // The following Regular Expressions can be used for tokenizing,
  2091. // validating, and parsing SemVer version strings.
  2092. // ## Numeric Identifier
  2093. // A single `0`, or a non-zero digit followed by zero or more digits.
  2094. var NUMERICIDENTIFIER = R++;
  2095. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  2096. var NUMERICIDENTIFIERLOOSE = R++;
  2097. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  2098. // Zero or more digits, followed by a letter or hyphen, and then zero or
  2099. // more letters, digits, or hyphens.
  2100. var NONNUMERICIDENTIFIER = R++;
  2101. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  2102. // Three dot-separated numeric identifiers.
  2103. var MAINVERSION = R++;
  2104. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  2105. var MAINVERSIONLOOSE = R++;
  2106. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  2107. // A numeric identifier, or a non-numeric identifier.
  2108. var PRERELEASEIDENTIFIER = R++;
  2109. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  2110. var PRERELEASEIDENTIFIERLOOSE = R++;
  2111. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  2112. // Hyphen, followed by one or more dot-separated pre-release version
  2113. // identifiers.
  2114. var PRERELEASE = R++;
  2115. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  2116. var PRERELEASELOOSE = R++;
  2117. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  2118. // Any combination of digits, letters, or hyphens.
  2119. var BUILDIDENTIFIER = R++;
  2120. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  2121. // Plus sign, followed by one or more period-separated build metadata
  2122. // identifiers.
  2123. var BUILD = R++;
  2124. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  2125. // A main version, followed optionally by a pre-release version and
  2126. // build metadata.
  2127. // Note that the only major, minor, patch, and pre-release sections of
  2128. // the version string are capturing groups. The build metadata is not a
  2129. // capturing group, because it should not ever be used in version
  2130. // comparison.
  2131. var FULL = R++;
  2132. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  2133. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  2134. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  2135. // common in the npm registry.
  2136. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  2137. var LOOSE = R++;
  2138. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  2139. var GTLT = R++;
  2140. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  2141. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  2142. // Only the first item is strictly required.
  2143. var XRANGEIDENTIFIERLOOSE = R++;
  2144. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  2145. var XRANGEIDENTIFIER = R++;
  2146. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  2147. var XRANGEPLAIN = R++;
  2148. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  2149. var XRANGEPLAINLOOSE = R++;
  2150. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  2151. var XRANGE = R++;
  2152. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  2153. var XRANGELOOSE = R++;
  2154. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Tilde ranges.
  2155. // Meaning is "reasonably at or greater than"
  2156. var LONETILDE = R++;
  2157. src[LONETILDE] = '(?:~>?)';
  2158. var TILDETRIM = R++;
  2159. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  2160. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  2161. var tildeTrimReplace = '$1~';
  2162. var TILDE = R++;
  2163. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  2164. var TILDELOOSE = R++;
  2165. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  2166. // Meaning is "at least and backwards compatible with"
  2167. var LONECARET = R++;
  2168. src[LONECARET] = '(?:\\^)';
  2169. var CARETTRIM = R++;
  2170. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  2171. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  2172. var caretTrimReplace = '$1^';
  2173. var CARET = R++;
  2174. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  2175. var CARETLOOSE = R++;
  2176. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  2177. var COMPARATORLOOSE = R++;
  2178. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  2179. var COMPARATOR = R++;
  2180. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  2181. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  2182. var COMPARATORTRIM = R++;
  2183. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  2184. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  2185. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  2186. // Note that these all use the loose form, because they'll be
  2187. // checked against either the strict or loose comparator form
  2188. // later.
  2189. var HYPHENRANGE = R++;
  2190. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  2191. var HYPHENRANGELOOSE = R++;
  2192. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  2193. var STAR = R++;
  2194. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  2195. // All are flag-free, unless they were created above with a flag.
  2196. for (var i = 0; i < R; i++) {
  2197. debug(i, src[i]);
  2198. if (!re[i]) re[i] = new RegExp(src[i]);
  2199. }
  2200. exports.parse = parse;
  2201. function parse(version, loose) {
  2202. if (version instanceof SemVer) return version;
  2203. if (typeof version !== 'string') return null;
  2204. if (version.length > MAX_LENGTH) return null;
  2205. var r = loose ? re[LOOSE] : re[FULL];
  2206. if (!r.test(version)) return null;
  2207. try {
  2208. return new SemVer(version, loose);
  2209. } catch (er) {
  2210. return null;
  2211. }
  2212. }
  2213. exports.valid = valid;
  2214. function valid(version, loose) {
  2215. var v = parse(version, loose);
  2216. return v ? v.version : null;
  2217. }
  2218. exports.clean = clean;
  2219. function clean(version, loose) {
  2220. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  2221. return s ? s.version : null;
  2222. }
  2223. exports.SemVer = SemVer;
  2224. function SemVer(version, loose) {
  2225. if (version instanceof SemVer) {
  2226. if (version.loose === loose) return version;else version = version.version;
  2227. } else if (typeof version !== 'string') {
  2228. throw new TypeError('Invalid Version: ' + version);
  2229. }
  2230. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  2231. if (!(this instanceof SemVer)) return new SemVer(version, loose);
  2232. debug('SemVer', version, loose);
  2233. this.loose = loose;
  2234. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  2235. if (!m) throw new TypeError('Invalid Version: ' + version);
  2236. this.raw = version; // these are actually numbers
  2237. this.major = +m[1];
  2238. this.minor = +m[2];
  2239. this.patch = +m[3];
  2240. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  2241. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  2242. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  2243. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  2244. if (/^[0-9]+$/.test(id)) {
  2245. var num = +id;
  2246. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  2247. }
  2248. return id;
  2249. });
  2250. this.build = m[5] ? m[5].split('.') : [];
  2251. this.format();
  2252. }
  2253. SemVer.prototype.format = function () {
  2254. this.version = this.major + '.' + this.minor + '.' + this.patch;
  2255. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  2256. return this.version;
  2257. };
  2258. SemVer.prototype.toString = function () {
  2259. return this.version;
  2260. };
  2261. SemVer.prototype.compare = function (other) {
  2262. debug('SemVer.compare', this.version, this.loose, other);
  2263. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  2264. return this.compareMain(other) || this.comparePre(other);
  2265. };
  2266. SemVer.prototype.compareMain = function (other) {
  2267. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  2268. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  2269. };
  2270. SemVer.prototype.comparePre = function (other) {
  2271. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); // NOT having a prerelease is > having one
  2272. 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;
  2273. var i = 0;
  2274. do {
  2275. var a = this.prerelease[i];
  2276. var b = other.prerelease[i];
  2277. debug('prerelease compare', i, a, b);
  2278. 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);
  2279. } while (++i);
  2280. }; // preminor will bump the version up to the next minor release, and immediately
  2281. // down to pre-release. premajor and prepatch work the same way.
  2282. SemVer.prototype.inc = function (release, identifier) {
  2283. switch (release) {
  2284. case 'premajor':
  2285. this.prerelease.length = 0;
  2286. this.patch = 0;
  2287. this.minor = 0;
  2288. this.major++;
  2289. this.inc('pre', identifier);
  2290. break;
  2291. case 'preminor':
  2292. this.prerelease.length = 0;
  2293. this.patch = 0;
  2294. this.minor++;
  2295. this.inc('pre', identifier);
  2296. break;
  2297. case 'prepatch':
  2298. // If this is already a prerelease, it will bump to the next version
  2299. // drop any prereleases that might already exist, since they are not
  2300. // relevant at this point.
  2301. this.prerelease.length = 0;
  2302. this.inc('patch', identifier);
  2303. this.inc('pre', identifier);
  2304. break;
  2305. // If the input is a non-prerelease version, this acts the same as
  2306. // prepatch.
  2307. case 'prerelease':
  2308. if (this.prerelease.length === 0) this.inc('patch', identifier);
  2309. this.inc('pre', identifier);
  2310. break;
  2311. case 'major':
  2312. // If this is a pre-major version, bump up to the same major version.
  2313. // Otherwise increment major.
  2314. // 1.0.0-5 bumps to 1.0.0
  2315. // 1.1.0 bumps to 2.0.0
  2316. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  2317. this.minor = 0;
  2318. this.patch = 0;
  2319. this.prerelease = [];
  2320. break;
  2321. case 'minor':
  2322. // If this is a pre-minor version, bump up to the same minor version.
  2323. // Otherwise increment minor.
  2324. // 1.2.0-5 bumps to 1.2.0
  2325. // 1.2.1 bumps to 1.3.0
  2326. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  2327. this.patch = 0;
  2328. this.prerelease = [];
  2329. break;
  2330. case 'patch':
  2331. // If this is not a pre-release version, it will increment the patch.
  2332. // If it is a pre-release it will bump up to the same patch version.
  2333. // 1.2.0-5 patches to 1.2.0
  2334. // 1.2.0 patches to 1.2.1
  2335. if (this.prerelease.length === 0) this.patch++;
  2336. this.prerelease = [];
  2337. break;
  2338. // This probably shouldn't be used publicly.
  2339. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  2340. case 'pre':
  2341. if (this.prerelease.length === 0) this.prerelease = [0];else {
  2342. var i = this.prerelease.length;
  2343. while (--i >= 0) {
  2344. if (typeof this.prerelease[i] === 'number') {
  2345. this.prerelease[i]++;
  2346. i = -2;
  2347. }
  2348. }
  2349. if (i === -1) // didn't increment anything
  2350. this.prerelease.push(0);
  2351. }
  2352. if (identifier) {
  2353. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  2354. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  2355. if (this.prerelease[0] === identifier) {
  2356. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  2357. } else this.prerelease = [identifier, 0];
  2358. }
  2359. break;
  2360. default:
  2361. throw new Error('invalid increment argument: ' + release);
  2362. }
  2363. this.format();
  2364. this.raw = this.version;
  2365. return this;
  2366. };
  2367. exports.inc = inc;
  2368. function inc(version, release, loose, identifier) {
  2369. if (typeof loose === 'string') {
  2370. identifier = loose;
  2371. loose = undefined;
  2372. }
  2373. try {
  2374. return new SemVer(version, loose).inc(release, identifier).version;
  2375. } catch (er) {
  2376. return null;
  2377. }
  2378. }
  2379. exports.diff = diff;
  2380. function diff(version1, version2) {
  2381. if (eq(version1, version2)) {
  2382. return null;
  2383. } else {
  2384. var v1 = parse(version1);
  2385. var v2 = parse(version2);
  2386. if (v1.prerelease.length || v2.prerelease.length) {
  2387. for (var key in v1) {
  2388. if (key === 'major' || key === 'minor' || key === 'patch') {
  2389. if (v1[key] !== v2[key]) {
  2390. return 'pre' + key;
  2391. }
  2392. }
  2393. }
  2394. return 'prerelease';
  2395. }
  2396. for (var key in v1) {
  2397. if (key === 'major' || key === 'minor' || key === 'patch') {
  2398. if (v1[key] !== v2[key]) {
  2399. return key;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. exports.compareIdentifiers = compareIdentifiers;
  2406. var numeric = /^[0-9]+$/;
  2407. function compareIdentifiers(a, b) {
  2408. var anum = numeric.test(a);
  2409. var bnum = numeric.test(b);
  2410. if (anum && bnum) {
  2411. a = +a;
  2412. b = +b;
  2413. }
  2414. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  2415. }
  2416. exports.rcompareIdentifiers = rcompareIdentifiers;
  2417. function rcompareIdentifiers(a, b) {
  2418. return compareIdentifiers(b, a);
  2419. }
  2420. exports.major = major;
  2421. function major(a, loose) {
  2422. return new SemVer(a, loose).major;
  2423. }
  2424. exports.minor = minor;
  2425. function minor(a, loose) {
  2426. return new SemVer(a, loose).minor;
  2427. }
  2428. exports.patch = patch;
  2429. function patch(a, loose) {
  2430. return new SemVer(a, loose).patch;
  2431. }
  2432. exports.compare = compare;
  2433. function compare(a, b, loose) {
  2434. return new SemVer(a, loose).compare(new SemVer(b, loose));
  2435. }
  2436. exports.compareLoose = compareLoose;
  2437. function compareLoose(a, b) {
  2438. return compare(a, b, true);
  2439. }
  2440. exports.rcompare = rcompare;
  2441. function rcompare(a, b, loose) {
  2442. return compare(b, a, loose);
  2443. }
  2444. exports.sort = sort;
  2445. function sort(list, loose) {
  2446. return list.sort(function (a, b) {
  2447. return exports.compare(a, b, loose);
  2448. });
  2449. }
  2450. exports.rsort = rsort;
  2451. function rsort(list, loose) {
  2452. return list.sort(function (a, b) {
  2453. return exports.rcompare(a, b, loose);
  2454. });
  2455. }
  2456. exports.gt = gt;
  2457. function gt(a, b, loose) {
  2458. return compare(a, b, loose) > 0;
  2459. }
  2460. exports.lt = lt;
  2461. function lt(a, b, loose) {
  2462. return compare(a, b, loose) < 0;
  2463. }
  2464. exports.eq = eq;
  2465. function eq(a, b, loose) {
  2466. return compare(a, b, loose) === 0;
  2467. }
  2468. exports.neq = neq;
  2469. function neq(a, b, loose) {
  2470. return compare(a, b, loose) !== 0;
  2471. }
  2472. exports.gte = gte;
  2473. function gte(a, b, loose) {
  2474. return compare(a, b, loose) >= 0;
  2475. }
  2476. exports.lte = lte;
  2477. function lte(a, b, loose) {
  2478. return compare(a, b, loose) <= 0;
  2479. }
  2480. exports.cmp = cmp;
  2481. function cmp(a, op, b, loose) {
  2482. var ret;
  2483. switch (op) {
  2484. case '===':
  2485. if (typeof a === 'object') a = a.version;
  2486. if (typeof b === 'object') b = b.version;
  2487. ret = a === b;
  2488. break;
  2489. case '!==':
  2490. if (typeof a === 'object') a = a.version;
  2491. if (typeof b === 'object') b = b.version;
  2492. ret = a !== b;
  2493. break;
  2494. case '':
  2495. case '=':
  2496. case '==':
  2497. ret = eq(a, b, loose);
  2498. break;
  2499. case '!=':
  2500. ret = neq(a, b, loose);
  2501. break;
  2502. case '>':
  2503. ret = gt(a, b, loose);
  2504. break;
  2505. case '>=':
  2506. ret = gte(a, b, loose);
  2507. break;
  2508. case '<':
  2509. ret = lt(a, b, loose);
  2510. break;
  2511. case '<=':
  2512. ret = lte(a, b, loose);
  2513. break;
  2514. default:
  2515. throw new TypeError('Invalid operator: ' + op);
  2516. }
  2517. return ret;
  2518. }
  2519. exports.Comparator = Comparator;
  2520. function Comparator(comp, loose) {
  2521. if (comp instanceof Comparator) {
  2522. if (comp.loose === loose) return comp;else comp = comp.value;
  2523. }
  2524. if (!(this instanceof Comparator)) return new Comparator(comp, loose);
  2525. debug('comparator', comp, loose);
  2526. this.loose = loose;
  2527. this.parse(comp);
  2528. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  2529. debug('comp', this);
  2530. }
  2531. var ANY = {};
  2532. Comparator.prototype.parse = function (comp) {
  2533. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2534. var m = comp.match(r);
  2535. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  2536. this.operator = m[1];
  2537. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  2538. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.loose);
  2539. };
  2540. Comparator.prototype.toString = function () {
  2541. return this.value;
  2542. };
  2543. Comparator.prototype.test = function (version) {
  2544. debug('Comparator.test', version, this.loose);
  2545. if (this.semver === ANY) return true;
  2546. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2547. return cmp(version, this.operator, this.semver, this.loose);
  2548. };
  2549. Comparator.prototype.intersects = function (comp, loose) {
  2550. if (!(comp instanceof Comparator)) {
  2551. throw new TypeError('a Comparator is required');
  2552. }
  2553. var rangeTmp;
  2554. if (this.operator === '') {
  2555. rangeTmp = new Range(comp.value, loose);
  2556. return satisfies(this.value, rangeTmp, loose);
  2557. } else if (comp.operator === '') {
  2558. rangeTmp = new Range(this.value, loose);
  2559. return satisfies(comp.semver, rangeTmp, loose);
  2560. }
  2561. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  2562. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  2563. var sameSemVer = this.semver.version === comp.semver.version;
  2564. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  2565. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, loose) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  2566. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, loose) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  2567. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  2568. };
  2569. exports.Range = Range;
  2570. function Range(range, loose) {
  2571. if (range instanceof Range) {
  2572. if (range.loose === loose) {
  2573. return range;
  2574. } else {
  2575. return new Range(range.raw, loose);
  2576. }
  2577. }
  2578. if (range instanceof Comparator) {
  2579. return new Range(range.value, loose);
  2580. }
  2581. if (!(this instanceof Range)) return new Range(range, loose);
  2582. this.loose = loose; // First, split based on boolean or ||
  2583. this.raw = range;
  2584. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  2585. return this.parseRange(range.trim());
  2586. }, this).filter(function (c) {
  2587. // throw out any that are not relevant for whatever reason
  2588. return c.length;
  2589. });
  2590. if (!this.set.length) {
  2591. throw new TypeError('Invalid SemVer Range: ' + range);
  2592. }
  2593. this.format();
  2594. }
  2595. Range.prototype.format = function () {
  2596. this.range = this.set.map(function (comps) {
  2597. return comps.join(' ').trim();
  2598. }).join('||').trim();
  2599. return this.range;
  2600. };
  2601. Range.prototype.toString = function () {
  2602. return this.range;
  2603. };
  2604. Range.prototype.parseRange = function (range) {
  2605. var loose = this.loose;
  2606. range = range.trim();
  2607. debug('range', range, loose); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  2608. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  2609. range = range.replace(hr, hyphenReplace);
  2610. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  2611. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  2612. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  2613. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  2614. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  2615. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  2616. // ready to be split into comparators.
  2617. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2618. var set = range.split(' ').map(function (comp) {
  2619. return parseComparator(comp, loose);
  2620. }).join(' ').split(/\s+/);
  2621. if (this.loose) {
  2622. // in loose mode, throw out any that are not valid comparators
  2623. set = set.filter(function (comp) {
  2624. return !!comp.match(compRe);
  2625. });
  2626. }
  2627. set = set.map(function (comp) {
  2628. return new Comparator(comp, loose);
  2629. });
  2630. return set;
  2631. };
  2632. Range.prototype.intersects = function (range, loose) {
  2633. if (!(range instanceof Range)) {
  2634. throw new TypeError('a Range is required');
  2635. }
  2636. return this.set.some(function (thisComparators) {
  2637. return thisComparators.every(function (thisComparator) {
  2638. return range.set.some(function (rangeComparators) {
  2639. return rangeComparators.every(function (rangeComparator) {
  2640. return thisComparator.intersects(rangeComparator, loose);
  2641. });
  2642. });
  2643. });
  2644. });
  2645. }; // Mostly just for testing and legacy API reasons
  2646. exports.toComparators = toComparators;
  2647. function toComparators(range, loose) {
  2648. return new Range(range, loose).set.map(function (comp) {
  2649. return comp.map(function (c) {
  2650. return c.value;
  2651. }).join(' ').trim().split(' ');
  2652. });
  2653. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  2654. // already replaced the hyphen ranges
  2655. // turn into a set of JUST comparators.
  2656. function parseComparator(comp, loose) {
  2657. debug('comp', comp);
  2658. comp = replaceCarets(comp, loose);
  2659. debug('caret', comp);
  2660. comp = replaceTildes(comp, loose);
  2661. debug('tildes', comp);
  2662. comp = replaceXRanges(comp, loose);
  2663. debug('xrange', comp);
  2664. comp = replaceStars(comp, loose);
  2665. debug('stars', comp);
  2666. return comp;
  2667. }
  2668. function isX(id) {
  2669. return !id || id.toLowerCase() === 'x' || id === '*';
  2670. } // ~, ~> --> * (any, kinda silly)
  2671. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  2672. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  2673. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  2674. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  2675. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  2676. function replaceTildes(comp, loose) {
  2677. return comp.trim().split(/\s+/).map(function (comp) {
  2678. return replaceTilde(comp, loose);
  2679. }).join(' ');
  2680. }
  2681. function replaceTilde(comp, loose) {
  2682. var r = loose ? re[TILDELOOSE] : re[TILDE];
  2683. return comp.replace(r, function (_, M, m, p, pr) {
  2684. debug('tilde', comp, _, M, m, p, pr);
  2685. var ret;
  2686. 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
  2687. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  2688. debug('replaceTilde pr', pr);
  2689. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2690. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2691. } else // ~1.2.3 == >=1.2.3 <1.3.0
  2692. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2693. debug('tilde return', ret);
  2694. return ret;
  2695. });
  2696. } // ^ --> * (any, kinda silly)
  2697. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  2698. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  2699. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  2700. // ^1.2.3 --> >=1.2.3 <2.0.0
  2701. // ^1.2.0 --> >=1.2.0 <2.0.0
  2702. function replaceCarets(comp, loose) {
  2703. return comp.trim().split(/\s+/).map(function (comp) {
  2704. return replaceCaret(comp, loose);
  2705. }).join(' ');
  2706. }
  2707. function replaceCaret(comp, loose) {
  2708. debug('caret', comp, loose);
  2709. var r = loose ? re[CARETLOOSE] : re[CARET];
  2710. return comp.replace(r, function (_, M, m, p, pr) {
  2711. debug('caret', comp, _, M, m, p, pr);
  2712. var ret;
  2713. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  2714. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  2715. } else if (pr) {
  2716. debug('replaceCaret pr', pr);
  2717. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2718. if (M === '0') {
  2719. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2720. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  2721. } else {
  2722. debug('no pr');
  2723. if (M === '0') {
  2724. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2725. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  2726. }
  2727. debug('caret return', ret);
  2728. return ret;
  2729. });
  2730. }
  2731. function replaceXRanges(comp, loose) {
  2732. debug('replaceXRanges', comp, loose);
  2733. return comp.split(/\s+/).map(function (comp) {
  2734. return replaceXRange(comp, loose);
  2735. }).join(' ');
  2736. }
  2737. function replaceXRange(comp, loose) {
  2738. comp = comp.trim();
  2739. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  2740. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  2741. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  2742. var xM = isX(M);
  2743. var xm = xM || isX(m);
  2744. var xp = xm || isX(p);
  2745. var anyX = xp;
  2746. if (gtlt === '=' && anyX) gtlt = '';
  2747. if (xM) {
  2748. if (gtlt === '>' || gtlt === '<') {
  2749. // nothing is allowed
  2750. ret = '<0.0.0';
  2751. } else {
  2752. // nothing is forbidden
  2753. ret = '*';
  2754. }
  2755. } else if (gtlt && anyX) {
  2756. // replace X with 0
  2757. if (xm) m = 0;
  2758. if (xp) p = 0;
  2759. if (gtlt === '>') {
  2760. // >1 => >=2.0.0
  2761. // >1.2 => >=1.3.0
  2762. // >1.2.3 => >= 1.2.4
  2763. gtlt = '>=';
  2764. if (xm) {
  2765. M = +M + 1;
  2766. m = 0;
  2767. p = 0;
  2768. } else if (xp) {
  2769. m = +m + 1;
  2770. p = 0;
  2771. }
  2772. } else if (gtlt === '<=') {
  2773. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  2774. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  2775. gtlt = '<';
  2776. if (xm) M = +M + 1;else m = +m + 1;
  2777. }
  2778. ret = gtlt + M + '.' + m + '.' + p;
  2779. } else if (xm) {
  2780. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2781. } else if (xp) {
  2782. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2783. }
  2784. debug('xRange return', ret);
  2785. return ret;
  2786. });
  2787. } // Because * is AND-ed with everything else in the comparator,
  2788. // and '' means "any version", just remove the *s entirely.
  2789. function replaceStars(comp, loose) {
  2790. debug('replaceStars', comp, loose); // Looseness is ignored here. star is always as loose as it gets!
  2791. return comp.trim().replace(re[STAR], '');
  2792. } // This function is passed to string.replace(re[HYPHENRANGE])
  2793. // M, m, patch, prerelease, build
  2794. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  2795. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  2796. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  2797. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  2798. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  2799. 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;
  2800. return (from + ' ' + to).trim();
  2801. } // if ANY of the sets match ALL of its comparators, then pass
  2802. Range.prototype.test = function (version) {
  2803. if (!version) return false;
  2804. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2805. for (var i = 0; i < this.set.length; i++) {
  2806. if (testSet(this.set[i], version)) return true;
  2807. }
  2808. return false;
  2809. };
  2810. function testSet(set, version) {
  2811. for (var i = 0; i < set.length; i++) {
  2812. if (!set[i].test(version)) return false;
  2813. }
  2814. if (version.prerelease.length) {
  2815. // Find the set of versions that are allowed to have prereleases
  2816. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  2817. // That should allow `1.2.3-pr.2` to pass.
  2818. // However, `1.2.4-alpha.notready` should NOT be allowed,
  2819. // even though it's within the range set by the comparators.
  2820. for (var i = 0; i < set.length; i++) {
  2821. debug(set[i].semver);
  2822. if (set[i].semver === ANY) continue;
  2823. if (set[i].semver.prerelease.length > 0) {
  2824. var allowed = set[i].semver;
  2825. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  2826. }
  2827. } // Version has a -pre, but it's not one of the ones we like.
  2828. return false;
  2829. }
  2830. return true;
  2831. }
  2832. exports.satisfies = satisfies;
  2833. function satisfies(version, range, loose) {
  2834. try {
  2835. range = new Range(range, loose);
  2836. } catch (er) {
  2837. return false;
  2838. }
  2839. return range.test(version);
  2840. }
  2841. exports.maxSatisfying = maxSatisfying;
  2842. function maxSatisfying(versions, range, loose) {
  2843. var max = null;
  2844. var maxSV = null;
  2845. try {
  2846. var rangeObj = new Range(range, loose);
  2847. } catch (er) {
  2848. return null;
  2849. }
  2850. versions.forEach(function (v) {
  2851. if (rangeObj.test(v)) {
  2852. // satisfies(v, range, loose)
  2853. if (!max || maxSV.compare(v) === -1) {
  2854. // compare(max, v, true)
  2855. max = v;
  2856. maxSV = new SemVer(max, loose);
  2857. }
  2858. }
  2859. });
  2860. return max;
  2861. }
  2862. exports.minSatisfying = minSatisfying;
  2863. function minSatisfying(versions, range, loose) {
  2864. var min = null;
  2865. var minSV = null;
  2866. try {
  2867. var rangeObj = new Range(range, loose);
  2868. } catch (er) {
  2869. return null;
  2870. }
  2871. versions.forEach(function (v) {
  2872. if (rangeObj.test(v)) {
  2873. // satisfies(v, range, loose)
  2874. if (!min || minSV.compare(v) === 1) {
  2875. // compare(min, v, true)
  2876. min = v;
  2877. minSV = new SemVer(min, loose);
  2878. }
  2879. }
  2880. });
  2881. return min;
  2882. }
  2883. exports.validRange = validRange;
  2884. function validRange(range, loose) {
  2885. try {
  2886. // Return '*' instead of '' so that truthiness works.
  2887. // This will throw if it's invalid anyway
  2888. return new Range(range, loose).range || '*';
  2889. } catch (er) {
  2890. return null;
  2891. }
  2892. } // Determine if version is less than all the versions possible in the range
  2893. exports.ltr = ltr;
  2894. function ltr(version, range, loose) {
  2895. return outside(version, range, '<', loose);
  2896. } // Determine if version is greater than all the versions possible in the range.
  2897. exports.gtr = gtr;
  2898. function gtr(version, range, loose) {
  2899. return outside(version, range, '>', loose);
  2900. }
  2901. exports.outside = outside;
  2902. function outside(version, range, hilo, loose) {
  2903. version = new SemVer(version, loose);
  2904. range = new Range(range, loose);
  2905. var gtfn, ltefn, ltfn, comp, ecomp;
  2906. switch (hilo) {
  2907. case '>':
  2908. gtfn = gt;
  2909. ltefn = lte;
  2910. ltfn = lt;
  2911. comp = '>';
  2912. ecomp = '>=';
  2913. break;
  2914. case '<':
  2915. gtfn = lt;
  2916. ltefn = gte;
  2917. ltfn = gt;
  2918. comp = '<';
  2919. ecomp = '<=';
  2920. break;
  2921. default:
  2922. throw new TypeError('Must provide a hilo val of "<" or ">"');
  2923. } // If it satisifes the range it is not outside
  2924. if (satisfies(version, range, loose)) {
  2925. return false;
  2926. } // From now on, variable terms are as if we're in "gtr" mode.
  2927. // but note that everything is flipped for the "ltr" function.
  2928. for (var i = 0; i < range.set.length; ++i) {
  2929. var comparators = range.set[i];
  2930. var high = null;
  2931. var low = null;
  2932. comparators.forEach(function (comparator) {
  2933. if (comparator.semver === ANY) {
  2934. comparator = new Comparator('>=0.0.0');
  2935. }
  2936. high = high || comparator;
  2937. low = low || comparator;
  2938. if (gtfn(comparator.semver, high.semver, loose)) {
  2939. high = comparator;
  2940. } else if (ltfn(comparator.semver, low.semver, loose)) {
  2941. low = comparator;
  2942. }
  2943. }); // If the edge version comparator has a operator then our version
  2944. // isn't outside it
  2945. if (high.operator === comp || high.operator === ecomp) {
  2946. return false;
  2947. } // If the lowest version comparator has an operator and our version
  2948. // is less than it then it isn't higher than the range
  2949. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  2950. return false;
  2951. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  2952. return false;
  2953. }
  2954. }
  2955. return true;
  2956. }
  2957. exports.prerelease = prerelease;
  2958. function prerelease(version, loose) {
  2959. var parsed = parse(version, loose);
  2960. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  2961. }
  2962. exports.intersects = intersects;
  2963. function intersects(r1, r2, loose) {
  2964. r1 = new Range(r1, loose);
  2965. r2 = new Range(r2, loose);
  2966. return r1.intersects(r2);
  2967. }
  2968. });
  2969. var arrayify = function arrayify(object, keyName) {
  2970. return Object.keys(object).reduce(function (array, key) {
  2971. return array.concat(Object.assign({
  2972. [keyName]: key
  2973. }, object[key]));
  2974. }, []);
  2975. };
  2976. var dedent_1 = createCommonjsModule(function (module) {
  2977. "use strict";
  2978. function dedent(strings) {
  2979. var raw = void 0;
  2980. if (typeof strings === "string") {
  2981. // dedent can be used as a plain function
  2982. raw = [strings];
  2983. } else {
  2984. raw = strings.raw;
  2985. } // first, perform interpolation
  2986. var result = "";
  2987. for (var i = 0; i < raw.length; i++) {
  2988. result += raw[i]. // join lines when there is a suppressed newline
  2989. replace(/\\\n[ \t]*/g, ""). // handle escaped backticks
  2990. replace(/\\`/g, "`");
  2991. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  2992. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  2993. }
  2994. } // now strip indentation
  2995. var lines = result.split("\n");
  2996. var mindent = null;
  2997. lines.forEach(function (l) {
  2998. var m = l.match(/^(\s+)\S+/);
  2999. if (m) {
  3000. var indent = m[1].length;
  3001. if (!mindent) {
  3002. // this is the first indented line
  3003. mindent = indent;
  3004. } else {
  3005. mindent = Math.min(mindent, indent);
  3006. }
  3007. }
  3008. });
  3009. if (mindent !== null) {
  3010. result = lines.map(function (l) {
  3011. return l[0] === " " ? l.slice(mindent) : l;
  3012. }).join("\n");
  3013. } // dedent eats leading and trailing whitespace too
  3014. result = result.trim(); // handle escaped newlines at the end to ensure they don't get stripped too
  3015. return result.replace(/\\n/g, "\n");
  3016. }
  3017. {
  3018. module.exports = dedent;
  3019. }
  3020. });
  3021. var CATEGORY_CONFIG = "Config";
  3022. var CATEGORY_EDITOR = "Editor";
  3023. var CATEGORY_FORMAT = "Format";
  3024. var CATEGORY_OTHER = "Other";
  3025. var CATEGORY_OUTPUT = "Output";
  3026. var CATEGORY_GLOBAL = "Global";
  3027. var CATEGORY_SPECIAL = "Special";
  3028. /**
  3029. * @typedef {Object} OptionInfo
  3030. * @property {string} since - available since version
  3031. * @property {string} category
  3032. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  3033. * @property {boolean} array - indicate it's an array of the specified type
  3034. * @property {boolean?} deprecated - deprecated since version
  3035. * @property {OptionRedirectInfo?} redirect - redirect deprecated option
  3036. * @property {string} description
  3037. * @property {string?} oppositeDescription - for `false` option
  3038. * @property {OptionValueInfo} default
  3039. * @property {OptionRangeInfo?} range - for type int
  3040. * @property {OptionChoiceInfo?} choices - for type choice
  3041. * @property {(value: any) => boolean} exception
  3042. *
  3043. * @typedef {number | boolean | string} OptionValue
  3044. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  3045. *
  3046. * @typedef {Object} OptionRedirectInfo
  3047. * @property {string} option
  3048. * @property {OptionValue} value
  3049. *
  3050. * @typedef {Object} OptionRangeInfo
  3051. * @property {number} start - recommended range start
  3052. * @property {number} end - recommended range end
  3053. * @property {number} step - recommended range step
  3054. *
  3055. * @typedef {Object} OptionChoiceInfo
  3056. * @property {boolean | string} value - boolean for the option that is originally boolean type
  3057. * @property {string?} description - undefined if redirect
  3058. * @property {string?} since - undefined if available since the first version of the option
  3059. * @property {string?} deprecated - deprecated since version
  3060. * @property {OptionValueInfo?} redirect - redirect deprecated value
  3061. *
  3062. * @property {string?} cliName
  3063. * @property {string?} cliCategory
  3064. * @property {string?} cliDescription
  3065. */
  3066. /** @type {{ [name: string]: OptionInfo } */
  3067. var options$2 = {
  3068. cursorOffset: {
  3069. since: "1.4.0",
  3070. category: CATEGORY_SPECIAL,
  3071. type: "int",
  3072. default: -1,
  3073. range: {
  3074. start: -1,
  3075. end: Infinity,
  3076. step: 1
  3077. },
  3078. description: dedent_1`
  3079. Print (to stderr) where a cursor at the given position would move to after formatting.
  3080. This option cannot be used with --range-start and --range-end.
  3081. `,
  3082. cliCategory: CATEGORY_EDITOR
  3083. },
  3084. endOfLine: {
  3085. since: "1.15.0",
  3086. category: CATEGORY_GLOBAL,
  3087. type: "choice",
  3088. default: "auto",
  3089. description: "Which end of line characters to apply.",
  3090. choices: [{
  3091. value: "auto",
  3092. description: dedent_1`
  3093. Maintain existing
  3094. (mixed values within one file are normalised by looking at what's used after the first line)
  3095. `
  3096. }, {
  3097. value: "lf",
  3098. description: "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
  3099. }, {
  3100. value: "crlf",
  3101. description: "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
  3102. }, {
  3103. value: "cr",
  3104. description: "Carriage Return character only (\\r), used very rarely"
  3105. }]
  3106. },
  3107. filepath: {
  3108. since: "1.4.0",
  3109. category: CATEGORY_SPECIAL,
  3110. type: "path",
  3111. description: "Specify the input filepath. This will be used to do parser inference.",
  3112. cliName: "stdin-filepath",
  3113. cliCategory: CATEGORY_OTHER,
  3114. cliDescription: "Path to the file to pretend that stdin comes from."
  3115. },
  3116. insertPragma: {
  3117. since: "1.8.0",
  3118. category: CATEGORY_SPECIAL,
  3119. type: "boolean",
  3120. default: false,
  3121. description: "Insert @format pragma into file's first docblock comment.",
  3122. cliCategory: CATEGORY_OTHER
  3123. },
  3124. parser: {
  3125. since: "0.0.10",
  3126. category: CATEGORY_GLOBAL,
  3127. type: "choice",
  3128. default: [{
  3129. since: "0.0.10",
  3130. value: "babylon"
  3131. }, {
  3132. since: "1.13.0",
  3133. value: undefined
  3134. }],
  3135. description: "Which parser to use.",
  3136. exception: function exception(value) {
  3137. return typeof value === "string" || typeof value === "function";
  3138. },
  3139. choices: [{
  3140. value: "flow",
  3141. description: "Flow"
  3142. }, {
  3143. value: "babylon",
  3144. description: "JavaScript",
  3145. deprecated: "1.16.0",
  3146. redirect: "babel"
  3147. }, {
  3148. value: "babel",
  3149. since: "1.16.0",
  3150. description: "JavaScript"
  3151. }, {
  3152. value: "babel-flow",
  3153. since: "1.16.0",
  3154. description: "Flow"
  3155. }, {
  3156. value: "typescript",
  3157. since: "1.4.0",
  3158. description: "TypeScript"
  3159. }, {
  3160. value: "css",
  3161. since: "1.7.1",
  3162. description: "CSS"
  3163. }, {
  3164. value: "postcss",
  3165. since: "1.4.0",
  3166. description: "CSS/Less/SCSS",
  3167. deprecated: "1.7.1",
  3168. redirect: "css"
  3169. }, {
  3170. value: "less",
  3171. since: "1.7.1",
  3172. description: "Less"
  3173. }, {
  3174. value: "scss",
  3175. since: "1.7.1",
  3176. description: "SCSS"
  3177. }, {
  3178. value: "json",
  3179. since: "1.5.0",
  3180. description: "JSON"
  3181. }, {
  3182. value: "json5",
  3183. since: "1.13.0",
  3184. description: "JSON5"
  3185. }, {
  3186. value: "json-stringify",
  3187. since: "1.13.0",
  3188. description: "JSON.stringify"
  3189. }, {
  3190. value: "graphql",
  3191. since: "1.5.0",
  3192. description: "GraphQL"
  3193. }, {
  3194. value: "markdown",
  3195. since: "1.8.0",
  3196. description: "Markdown"
  3197. }, {
  3198. value: "mdx",
  3199. since: "1.15.0",
  3200. description: "MDX"
  3201. }, {
  3202. value: "vue",
  3203. since: "1.10.0",
  3204. description: "Vue"
  3205. }, {
  3206. value: "yaml",
  3207. since: "1.14.0",
  3208. description: "YAML"
  3209. }, {
  3210. value: "glimmer",
  3211. since: null,
  3212. description: "Handlebars"
  3213. }, {
  3214. value: "html",
  3215. since: "1.15.0",
  3216. description: "HTML"
  3217. }, {
  3218. value: "angular",
  3219. since: "1.15.0",
  3220. description: "Angular"
  3221. }, {
  3222. value: "lwc",
  3223. since: "1.17.0",
  3224. description: "Lightning Web Components"
  3225. }]
  3226. },
  3227. plugins: {
  3228. since: "1.10.0",
  3229. type: "path",
  3230. array: true,
  3231. default: [{
  3232. value: []
  3233. }],
  3234. category: CATEGORY_GLOBAL,
  3235. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  3236. exception: function exception(value) {
  3237. return typeof value === "string" || typeof value === "object";
  3238. },
  3239. cliName: "plugin",
  3240. cliCategory: CATEGORY_CONFIG
  3241. },
  3242. pluginSearchDirs: {
  3243. since: "1.13.0",
  3244. type: "path",
  3245. array: true,
  3246. default: [{
  3247. value: []
  3248. }],
  3249. category: CATEGORY_GLOBAL,
  3250. description: dedent_1`
  3251. Custom directory that contains prettier plugins in node_modules subdirectory.
  3252. Overrides default behavior when plugins are searched relatively to the location of Prettier.
  3253. Multiple values are accepted.
  3254. `,
  3255. exception: function exception(value) {
  3256. return typeof value === "string" || typeof value === "object";
  3257. },
  3258. cliName: "plugin-search-dir",
  3259. cliCategory: CATEGORY_CONFIG
  3260. },
  3261. printWidth: {
  3262. since: "0.0.0",
  3263. category: CATEGORY_GLOBAL,
  3264. type: "int",
  3265. default: 80,
  3266. description: "The line length where Prettier will try wrap.",
  3267. range: {
  3268. start: 0,
  3269. end: Infinity,
  3270. step: 1
  3271. }
  3272. },
  3273. rangeEnd: {
  3274. since: "1.4.0",
  3275. category: CATEGORY_SPECIAL,
  3276. type: "int",
  3277. default: Infinity,
  3278. range: {
  3279. start: 0,
  3280. end: Infinity,
  3281. step: 1
  3282. },
  3283. description: dedent_1`
  3284. Format code ending at a given character offset (exclusive).
  3285. The range will extend forwards to the end of the selected statement.
  3286. This option cannot be used with --cursor-offset.
  3287. `,
  3288. cliCategory: CATEGORY_EDITOR
  3289. },
  3290. rangeStart: {
  3291. since: "1.4.0",
  3292. category: CATEGORY_SPECIAL,
  3293. type: "int",
  3294. default: 0,
  3295. range: {
  3296. start: 0,
  3297. end: Infinity,
  3298. step: 1
  3299. },
  3300. description: dedent_1`
  3301. Format code starting at a given character offset.
  3302. The range will extend backwards to the start of the first line containing the selected statement.
  3303. This option cannot be used with --cursor-offset.
  3304. `,
  3305. cliCategory: CATEGORY_EDITOR
  3306. },
  3307. requirePragma: {
  3308. since: "1.7.0",
  3309. category: CATEGORY_SPECIAL,
  3310. type: "boolean",
  3311. default: false,
  3312. description: dedent_1`
  3313. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  3314. in order for it to be formatted.
  3315. `,
  3316. cliCategory: CATEGORY_OTHER
  3317. },
  3318. tabWidth: {
  3319. type: "int",
  3320. category: CATEGORY_GLOBAL,
  3321. default: 2,
  3322. description: "Number of spaces per indentation level.",
  3323. range: {
  3324. start: 0,
  3325. end: Infinity,
  3326. step: 1
  3327. }
  3328. },
  3329. useFlowParser: {
  3330. since: "0.0.0",
  3331. category: CATEGORY_GLOBAL,
  3332. type: "boolean",
  3333. default: [{
  3334. since: "0.0.0",
  3335. value: false
  3336. }, {
  3337. since: "1.15.0",
  3338. value: undefined
  3339. }],
  3340. deprecated: "0.0.10",
  3341. description: "Use flow parser.",
  3342. redirect: {
  3343. option: "parser",
  3344. value: "flow"
  3345. },
  3346. cliName: "flow-parser"
  3347. },
  3348. useTabs: {
  3349. since: "1.0.0",
  3350. category: CATEGORY_GLOBAL,
  3351. type: "boolean",
  3352. default: false,
  3353. description: "Indent with tabs instead of spaces."
  3354. }
  3355. };
  3356. var coreOptions$1 = {
  3357. CATEGORY_CONFIG,
  3358. CATEGORY_EDITOR,
  3359. CATEGORY_FORMAT,
  3360. CATEGORY_OTHER,
  3361. CATEGORY_OUTPUT,
  3362. CATEGORY_GLOBAL,
  3363. CATEGORY_SPECIAL,
  3364. options: options$2
  3365. };
  3366. var require$$0 = ( _package$1 && _package ) || _package$1;
  3367. var currentVersion = require$$0.version;
  3368. var coreOptions = coreOptions$1.options;
  3369. function getSupportInfo$2(version, opts) {
  3370. opts = Object.assign({
  3371. plugins: [],
  3372. showUnreleased: false,
  3373. showDeprecated: false,
  3374. showInternal: false
  3375. }, opts);
  3376. if (!version) {
  3377. // pre-release version is smaller than the normal version in semver,
  3378. // we need to treat it as the normal one so as to test new features.
  3379. version = currentVersion.split("-", 1)[0];
  3380. }
  3381. var plugins = opts.plugins;
  3382. var options = arrayify(Object.assign(plugins.reduce(function (currentOptions, plugin) {
  3383. return Object.assign(currentOptions, plugin.options);
  3384. }, {}), coreOptions), "name").sort(function (a, b) {
  3385. return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
  3386. }).filter(filterSince).filter(filterDeprecated).map(mapDeprecated).map(mapInternal).map(function (option) {
  3387. var newOption = Object.assign({}, option);
  3388. if (Array.isArray(newOption.default)) {
  3389. newOption.default = newOption.default.length === 1 ? newOption.default[0].value : newOption.default.filter(filterSince).sort(function (info1, info2) {
  3390. return semver.compare(info2.since, info1.since);
  3391. })[0].value;
  3392. }
  3393. if (Array.isArray(newOption.choices)) {
  3394. newOption.choices = newOption.choices.filter(filterSince).filter(filterDeprecated).map(mapDeprecated);
  3395. }
  3396. return newOption;
  3397. }).map(function (option) {
  3398. var filteredPlugins = plugins.filter(function (plugin) {
  3399. return plugin.defaultOptions && plugin.defaultOptions[option.name];
  3400. });
  3401. var pluginDefaults = filteredPlugins.reduce(function (reduced, plugin) {
  3402. reduced[plugin.name] = plugin.defaultOptions[option.name];
  3403. return reduced;
  3404. }, {});
  3405. return Object.assign(option, {
  3406. pluginDefaults
  3407. });
  3408. });
  3409. var usePostCssParser = semver.lt(version, "1.7.1");
  3410. var useBabylonParser = semver.lt(version, "1.16.0");
  3411. var languages = plugins.reduce(function (all, plugin) {
  3412. return all.concat(plugin.languages || []);
  3413. }, []).filter(filterSince).map(function (language) {
  3414. // Prevent breaking changes
  3415. if (language.name === "Markdown") {
  3416. return Object.assign({}, language, {
  3417. parsers: ["markdown"]
  3418. });
  3419. }
  3420. if (language.name === "TypeScript") {
  3421. return Object.assign({}, language, {
  3422. parsers: ["typescript"]
  3423. });
  3424. } // "babylon" was renamed to "babel" in 1.16.0
  3425. if (useBabylonParser && language.parsers.indexOf("babel") !== -1) {
  3426. return Object.assign({}, language, {
  3427. parsers: language.parsers.map(function (parser) {
  3428. return parser === "babel" ? "babylon" : parser;
  3429. })
  3430. });
  3431. }
  3432. if (usePostCssParser && (language.name === "CSS" || language.group === "CSS")) {
  3433. return Object.assign({}, language, {
  3434. parsers: ["postcss"]
  3435. });
  3436. }
  3437. return language;
  3438. });
  3439. return {
  3440. languages,
  3441. options
  3442. };
  3443. function filterSince(object) {
  3444. return opts.showUnreleased || !("since" in object) || object.since && semver.gte(version, object.since);
  3445. }
  3446. function filterDeprecated(object) {
  3447. return opts.showDeprecated || !("deprecated" in object) || object.deprecated && semver.lt(version, object.deprecated);
  3448. }
  3449. function mapDeprecated(object) {
  3450. if (!object.deprecated || opts.showDeprecated) {
  3451. return object;
  3452. }
  3453. var newObject = Object.assign({}, object);
  3454. delete newObject.deprecated;
  3455. delete newObject.redirect;
  3456. return newObject;
  3457. }
  3458. function mapInternal(object) {
  3459. if (opts.showInternal) {
  3460. return object;
  3461. }
  3462. var newObject = Object.assign({}, object);
  3463. delete newObject.cliName;
  3464. delete newObject.cliCategory;
  3465. delete newObject.cliDescription;
  3466. return newObject;
  3467. }
  3468. }
  3469. var support = {
  3470. getSupportInfo: getSupportInfo$2
  3471. };
  3472. /*! *****************************************************************************
  3473. Copyright (c) Microsoft Corporation. All rights reserved.
  3474. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  3475. this file except in compliance with the License. You may obtain a copy of the
  3476. License at http://www.apache.org/licenses/LICENSE-2.0
  3477. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  3478. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  3479. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  3480. MERCHANTABLITY OR NON-INFRINGEMENT.
  3481. See the Apache Version 2.0 License for specific language governing permissions
  3482. and limitations under the License.
  3483. ***************************************************************************** */
  3484. /* global Reflect, Promise */
  3485. var _extendStatics = function extendStatics(d, b) {
  3486. _extendStatics = Object.setPrototypeOf || {
  3487. __proto__: []
  3488. } instanceof Array && function (d, b) {
  3489. d.__proto__ = b;
  3490. } || function (d, b) {
  3491. for (var p in b) {
  3492. if (b.hasOwnProperty(p)) d[p] = b[p];
  3493. }
  3494. };
  3495. return _extendStatics(d, b);
  3496. };
  3497. function __extends(d, b) {
  3498. _extendStatics(d, b);
  3499. function __() {
  3500. this.constructor = d;
  3501. }
  3502. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3503. }
  3504. var _assign = function __assign() {
  3505. _assign = Object.assign || function __assign(t) {
  3506. for (var s, i = 1, n = arguments.length; i < n; i++) {
  3507. s = arguments[i];
  3508. for (var p in s) {
  3509. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  3510. }
  3511. }
  3512. return t;
  3513. };
  3514. return _assign.apply(this, arguments);
  3515. };
  3516. function __rest(s, e) {
  3517. var t = {};
  3518. for (var p in s) {
  3519. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  3520. }
  3521. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  3522. if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
  3523. }
  3524. return t;
  3525. }
  3526. function __decorate(decorators, target, key, desc) {
  3527. var c = arguments.length,
  3528. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  3529. d;
  3530. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
  3531. if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  3532. }
  3533. return c > 3 && r && Object.defineProperty(target, key, r), r;
  3534. }
  3535. function __param(paramIndex, decorator) {
  3536. return function (target, key) {
  3537. decorator(target, key, paramIndex);
  3538. };
  3539. }
  3540. function __metadata(metadataKey, metadataValue) {
  3541. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  3542. }
  3543. function __awaiter(thisArg, _arguments, P, generator) {
  3544. return new (P || (P = Promise))(function (resolve, reject) {
  3545. function fulfilled(value) {
  3546. try {
  3547. step(generator.next(value));
  3548. } catch (e) {
  3549. reject(e);
  3550. }
  3551. }
  3552. function rejected(value) {
  3553. try {
  3554. step(generator["throw"](value));
  3555. } catch (e) {
  3556. reject(e);
  3557. }
  3558. }
  3559. function step(result) {
  3560. result.done ? resolve(result.value) : new P(function (resolve) {
  3561. resolve(result.value);
  3562. }).then(fulfilled, rejected);
  3563. }
  3564. step((generator = generator.apply(thisArg, _arguments || [])).next());
  3565. });
  3566. }
  3567. function __generator(thisArg, body) {
  3568. var _ = {
  3569. label: 0,
  3570. sent: function sent() {
  3571. if (t[0] & 1) throw t[1];
  3572. return t[1];
  3573. },
  3574. trys: [],
  3575. ops: []
  3576. },
  3577. f,
  3578. y,
  3579. t,
  3580. g;
  3581. return g = {
  3582. next: verb(0),
  3583. "throw": verb(1),
  3584. "return": verb(2)
  3585. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  3586. return this;
  3587. }), g;
  3588. function verb(n) {
  3589. return function (v) {
  3590. return step([n, v]);
  3591. };
  3592. }
  3593. function step(op) {
  3594. if (f) throw new TypeError("Generator is already executing.");
  3595. while (_) {
  3596. try {
  3597. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  3598. if (y = 0, t) op = [op[0] & 2, t.value];
  3599. switch (op[0]) {
  3600. case 0:
  3601. case 1:
  3602. t = op;
  3603. break;
  3604. case 4:
  3605. _.label++;
  3606. return {
  3607. value: op[1],
  3608. done: false
  3609. };
  3610. case 5:
  3611. _.label++;
  3612. y = op[1];
  3613. op = [0];
  3614. continue;
  3615. case 7:
  3616. op = _.ops.pop();
  3617. _.trys.pop();
  3618. continue;
  3619. default:
  3620. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  3621. _ = 0;
  3622. continue;
  3623. }
  3624. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  3625. _.label = op[1];
  3626. break;
  3627. }
  3628. if (op[0] === 6 && _.label < t[1]) {
  3629. _.label = t[1];
  3630. t = op;
  3631. break;
  3632. }
  3633. if (t && _.label < t[2]) {
  3634. _.label = t[2];
  3635. _.ops.push(op);
  3636. break;
  3637. }
  3638. if (t[2]) _.ops.pop();
  3639. _.trys.pop();
  3640. continue;
  3641. }
  3642. op = body.call(thisArg, _);
  3643. } catch (e) {
  3644. op = [6, e];
  3645. y = 0;
  3646. } finally {
  3647. f = t = 0;
  3648. }
  3649. }
  3650. if (op[0] & 5) throw op[1];
  3651. return {
  3652. value: op[0] ? op[1] : void 0,
  3653. done: true
  3654. };
  3655. }
  3656. }
  3657. function __exportStar(m, exports) {
  3658. for (var p in m) {
  3659. if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  3660. }
  3661. }
  3662. function __values(o) {
  3663. var m = typeof Symbol === "function" && o[Symbol.iterator],
  3664. i = 0;
  3665. if (m) return m.call(o);
  3666. return {
  3667. next: function next() {
  3668. if (o && i >= o.length) o = void 0;
  3669. return {
  3670. value: o && o[i++],
  3671. done: !o
  3672. };
  3673. }
  3674. };
  3675. }
  3676. function __read(o, n) {
  3677. var m = typeof Symbol === "function" && o[Symbol.iterator];
  3678. if (!m) return o;
  3679. var i = m.call(o),
  3680. r,
  3681. ar = [],
  3682. e;
  3683. try {
  3684. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
  3685. ar.push(r.value);
  3686. }
  3687. } catch (error) {
  3688. e = {
  3689. error: error
  3690. };
  3691. } finally {
  3692. try {
  3693. if (r && !r.done && (m = i["return"])) m.call(i);
  3694. } finally {
  3695. if (e) throw e.error;
  3696. }
  3697. }
  3698. return ar;
  3699. }
  3700. function __spread() {
  3701. for (var ar = [], i = 0; i < arguments.length; i++) {
  3702. ar = ar.concat(__read(arguments[i]));
  3703. }
  3704. return ar;
  3705. }
  3706. function __await(v) {
  3707. return this instanceof __await ? (this.v = v, this) : new __await(v);
  3708. }
  3709. function __asyncGenerator(thisArg, _arguments, generator) {
  3710. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  3711. var g = generator.apply(thisArg, _arguments || []),
  3712. i,
  3713. q = [];
  3714. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  3715. return this;
  3716. }, i;
  3717. function verb(n) {
  3718. if (g[n]) i[n] = function (v) {
  3719. return new Promise(function (a, b) {
  3720. q.push([n, v, a, b]) > 1 || resume(n, v);
  3721. });
  3722. };
  3723. }
  3724. function resume(n, v) {
  3725. try {
  3726. step(g[n](v));
  3727. } catch (e) {
  3728. settle(q[0][3], e);
  3729. }
  3730. }
  3731. function step(r) {
  3732. r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
  3733. }
  3734. function fulfill(value) {
  3735. resume("next", value);
  3736. }
  3737. function reject(value) {
  3738. resume("throw", value);
  3739. }
  3740. function settle(f, v) {
  3741. if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
  3742. }
  3743. }
  3744. function __asyncDelegator(o) {
  3745. var i, p;
  3746. return i = {}, verb("next"), verb("throw", function (e) {
  3747. throw e;
  3748. }), verb("return"), i[Symbol.iterator] = function () {
  3749. return this;
  3750. }, i;
  3751. function verb(n, f) {
  3752. i[n] = o[n] ? function (v) {
  3753. return (p = !p) ? {
  3754. value: __await(o[n](v)),
  3755. done: n === "return"
  3756. } : f ? f(v) : v;
  3757. } : f;
  3758. }
  3759. }
  3760. function __asyncValues(o) {
  3761. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  3762. var m = o[Symbol.asyncIterator],
  3763. i;
  3764. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  3765. return this;
  3766. }, i);
  3767. function verb(n) {
  3768. i[n] = o[n] && function (v) {
  3769. return new Promise(function (resolve, reject) {
  3770. v = o[n](v), settle(resolve, reject, v.done, v.value);
  3771. });
  3772. };
  3773. }
  3774. function settle(resolve, reject, d, v) {
  3775. Promise.resolve(v).then(function (v) {
  3776. resolve({
  3777. value: v,
  3778. done: d
  3779. });
  3780. }, reject);
  3781. }
  3782. }
  3783. function __makeTemplateObject(cooked, raw) {
  3784. if (Object.defineProperty) {
  3785. Object.defineProperty(cooked, "raw", {
  3786. value: raw
  3787. });
  3788. } else {
  3789. cooked.raw = raw;
  3790. }
  3791. return cooked;
  3792. }
  3793. function __importStar(mod) {
  3794. if (mod && mod.__esModule) return mod;
  3795. var result = {};
  3796. if (mod != null) for (var k in mod) {
  3797. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  3798. }
  3799. result.default = mod;
  3800. return result;
  3801. }
  3802. function __importDefault(mod) {
  3803. return mod && mod.__esModule ? mod : {
  3804. default: mod
  3805. };
  3806. }
  3807. var tslib_1 = Object.freeze({
  3808. __extends: __extends,
  3809. get __assign () { return _assign; },
  3810. __rest: __rest,
  3811. __decorate: __decorate,
  3812. __param: __param,
  3813. __metadata: __metadata,
  3814. __awaiter: __awaiter,
  3815. __generator: __generator,
  3816. __exportStar: __exportStar,
  3817. __values: __values,
  3818. __read: __read,
  3819. __spread: __spread,
  3820. __await: __await,
  3821. __asyncGenerator: __asyncGenerator,
  3822. __asyncDelegator: __asyncDelegator,
  3823. __asyncValues: __asyncValues,
  3824. __makeTemplateObject: __makeTemplateObject,
  3825. __importStar: __importStar,
  3826. __importDefault: __importDefault
  3827. });
  3828. var api = createCommonjsModule(function (module, exports) {
  3829. "use strict";
  3830. Object.defineProperty(exports, "__esModule", {
  3831. value: true
  3832. });
  3833. exports.apiDescriptor = {
  3834. key: function key(_key) {
  3835. return /^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(_key) ? _key : JSON.stringify(_key);
  3836. },
  3837. value(value) {
  3838. if (value === null || typeof value !== 'object') {
  3839. return JSON.stringify(value);
  3840. }
  3841. if (Array.isArray(value)) {
  3842. return `[${value.map(function (subValue) {
  3843. return exports.apiDescriptor.value(subValue);
  3844. }).join(', ')}]`;
  3845. }
  3846. var keys = Object.keys(value);
  3847. return keys.length === 0 ? '{}' : `{ ${keys.map(function (key) {
  3848. return `${exports.apiDescriptor.key(key)}: ${exports.apiDescriptor.value(value[key])}`;
  3849. }).join(', ')} }`;
  3850. },
  3851. pair: function pair(_ref) {
  3852. var key = _ref.key,
  3853. value = _ref.value;
  3854. return exports.apiDescriptor.value({
  3855. [key]: value
  3856. });
  3857. }
  3858. };
  3859. });
  3860. unwrapExports(api);
  3861. var descriptors = createCommonjsModule(function (module, exports) {
  3862. "use strict";
  3863. Object.defineProperty(exports, "__esModule", {
  3864. value: true
  3865. });
  3866. tslib_1.__exportStar(api, exports);
  3867. });
  3868. unwrapExports(descriptors);
  3869. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  3870. var escapeStringRegexp = function escapeStringRegexp(str) {
  3871. if (typeof str !== 'string') {
  3872. throw new TypeError('Expected a string');
  3873. }
  3874. return str.replace(matchOperatorsRe, '\\$&');
  3875. };
  3876. var colorName = {
  3877. "aliceblue": [240, 248, 255],
  3878. "antiquewhite": [250, 235, 215],
  3879. "aqua": [0, 255, 255],
  3880. "aquamarine": [127, 255, 212],
  3881. "azure": [240, 255, 255],
  3882. "beige": [245, 245, 220],
  3883. "bisque": [255, 228, 196],
  3884. "black": [0, 0, 0],
  3885. "blanchedalmond": [255, 235, 205],
  3886. "blue": [0, 0, 255],
  3887. "blueviolet": [138, 43, 226],
  3888. "brown": [165, 42, 42],
  3889. "burlywood": [222, 184, 135],
  3890. "cadetblue": [95, 158, 160],
  3891. "chartreuse": [127, 255, 0],
  3892. "chocolate": [210, 105, 30],
  3893. "coral": [255, 127, 80],
  3894. "cornflowerblue": [100, 149, 237],
  3895. "cornsilk": [255, 248, 220],
  3896. "crimson": [220, 20, 60],
  3897. "cyan": [0, 255, 255],
  3898. "darkblue": [0, 0, 139],
  3899. "darkcyan": [0, 139, 139],
  3900. "darkgoldenrod": [184, 134, 11],
  3901. "darkgray": [169, 169, 169],
  3902. "darkgreen": [0, 100, 0],
  3903. "darkgrey": [169, 169, 169],
  3904. "darkkhaki": [189, 183, 107],
  3905. "darkmagenta": [139, 0, 139],
  3906. "darkolivegreen": [85, 107, 47],
  3907. "darkorange": [255, 140, 0],
  3908. "darkorchid": [153, 50, 204],
  3909. "darkred": [139, 0, 0],
  3910. "darksalmon": [233, 150, 122],
  3911. "darkseagreen": [143, 188, 143],
  3912. "darkslateblue": [72, 61, 139],
  3913. "darkslategray": [47, 79, 79],
  3914. "darkslategrey": [47, 79, 79],
  3915. "darkturquoise": [0, 206, 209],
  3916. "darkviolet": [148, 0, 211],
  3917. "deeppink": [255, 20, 147],
  3918. "deepskyblue": [0, 191, 255],
  3919. "dimgray": [105, 105, 105],
  3920. "dimgrey": [105, 105, 105],
  3921. "dodgerblue": [30, 144, 255],
  3922. "firebrick": [178, 34, 34],
  3923. "floralwhite": [255, 250, 240],
  3924. "forestgreen": [34, 139, 34],
  3925. "fuchsia": [255, 0, 255],
  3926. "gainsboro": [220, 220, 220],
  3927. "ghostwhite": [248, 248, 255],
  3928. "gold": [255, 215, 0],
  3929. "goldenrod": [218, 165, 32],
  3930. "gray": [128, 128, 128],
  3931. "green": [0, 128, 0],
  3932. "greenyellow": [173, 255, 47],
  3933. "grey": [128, 128, 128],
  3934. "honeydew": [240, 255, 240],
  3935. "hotpink": [255, 105, 180],
  3936. "indianred": [205, 92, 92],
  3937. "indigo": [75, 0, 130],
  3938. "ivory": [255, 255, 240],
  3939. "khaki": [240, 230, 140],
  3940. "lavender": [230, 230, 250],
  3941. "lavenderblush": [255, 240, 245],
  3942. "lawngreen": [124, 252, 0],
  3943. "lemonchiffon": [255, 250, 205],
  3944. "lightblue": [173, 216, 230],
  3945. "lightcoral": [240, 128, 128],
  3946. "lightcyan": [224, 255, 255],
  3947. "lightgoldenrodyellow": [250, 250, 210],
  3948. "lightgray": [211, 211, 211],
  3949. "lightgreen": [144, 238, 144],
  3950. "lightgrey": [211, 211, 211],
  3951. "lightpink": [255, 182, 193],
  3952. "lightsalmon": [255, 160, 122],
  3953. "lightseagreen": [32, 178, 170],
  3954. "lightskyblue": [135, 206, 250],
  3955. "lightslategray": [119, 136, 153],
  3956. "lightslategrey": [119, 136, 153],
  3957. "lightsteelblue": [176, 196, 222],
  3958. "lightyellow": [255, 255, 224],
  3959. "lime": [0, 255, 0],
  3960. "limegreen": [50, 205, 50],
  3961. "linen": [250, 240, 230],
  3962. "magenta": [255, 0, 255],
  3963. "maroon": [128, 0, 0],
  3964. "mediumaquamarine": [102, 205, 170],
  3965. "mediumblue": [0, 0, 205],
  3966. "mediumorchid": [186, 85, 211],
  3967. "mediumpurple": [147, 112, 219],
  3968. "mediumseagreen": [60, 179, 113],
  3969. "mediumslateblue": [123, 104, 238],
  3970. "mediumspringgreen": [0, 250, 154],
  3971. "mediumturquoise": [72, 209, 204],
  3972. "mediumvioletred": [199, 21, 133],
  3973. "midnightblue": [25, 25, 112],
  3974. "mintcream": [245, 255, 250],
  3975. "mistyrose": [255, 228, 225],
  3976. "moccasin": [255, 228, 181],
  3977. "navajowhite": [255, 222, 173],
  3978. "navy": [0, 0, 128],
  3979. "oldlace": [253, 245, 230],
  3980. "olive": [128, 128, 0],
  3981. "olivedrab": [107, 142, 35],
  3982. "orange": [255, 165, 0],
  3983. "orangered": [255, 69, 0],
  3984. "orchid": [218, 112, 214],
  3985. "palegoldenrod": [238, 232, 170],
  3986. "palegreen": [152, 251, 152],
  3987. "paleturquoise": [175, 238, 238],
  3988. "palevioletred": [219, 112, 147],
  3989. "papayawhip": [255, 239, 213],
  3990. "peachpuff": [255, 218, 185],
  3991. "peru": [205, 133, 63],
  3992. "pink": [255, 192, 203],
  3993. "plum": [221, 160, 221],
  3994. "powderblue": [176, 224, 230],
  3995. "purple": [128, 0, 128],
  3996. "rebeccapurple": [102, 51, 153],
  3997. "red": [255, 0, 0],
  3998. "rosybrown": [188, 143, 143],
  3999. "royalblue": [65, 105, 225],
  4000. "saddlebrown": [139, 69, 19],
  4001. "salmon": [250, 128, 114],
  4002. "sandybrown": [244, 164, 96],
  4003. "seagreen": [46, 139, 87],
  4004. "seashell": [255, 245, 238],
  4005. "sienna": [160, 82, 45],
  4006. "silver": [192, 192, 192],
  4007. "skyblue": [135, 206, 235],
  4008. "slateblue": [106, 90, 205],
  4009. "slategray": [112, 128, 144],
  4010. "slategrey": [112, 128, 144],
  4011. "snow": [255, 250, 250],
  4012. "springgreen": [0, 255, 127],
  4013. "steelblue": [70, 130, 180],
  4014. "tan": [210, 180, 140],
  4015. "teal": [0, 128, 128],
  4016. "thistle": [216, 191, 216],
  4017. "tomato": [255, 99, 71],
  4018. "turquoise": [64, 224, 208],
  4019. "violet": [238, 130, 238],
  4020. "wheat": [245, 222, 179],
  4021. "white": [255, 255, 255],
  4022. "whitesmoke": [245, 245, 245],
  4023. "yellow": [255, 255, 0],
  4024. "yellowgreen": [154, 205, 50]
  4025. };
  4026. var conversions = createCommonjsModule(function (module) {
  4027. /* MIT license */
  4028. // NOTE: conversions should only return primitive values (i.e. arrays, or
  4029. // values that give correct `typeof` results).
  4030. // do not use box values types (i.e. Number(), String(), etc.)
  4031. var reverseKeywords = {};
  4032. for (var key in colorName) {
  4033. if (colorName.hasOwnProperty(key)) {
  4034. reverseKeywords[colorName[key]] = key;
  4035. }
  4036. }
  4037. var convert = module.exports = {
  4038. rgb: {
  4039. channels: 3,
  4040. labels: 'rgb'
  4041. },
  4042. hsl: {
  4043. channels: 3,
  4044. labels: 'hsl'
  4045. },
  4046. hsv: {
  4047. channels: 3,
  4048. labels: 'hsv'
  4049. },
  4050. hwb: {
  4051. channels: 3,
  4052. labels: 'hwb'
  4053. },
  4054. cmyk: {
  4055. channels: 4,
  4056. labels: 'cmyk'
  4057. },
  4058. xyz: {
  4059. channels: 3,
  4060. labels: 'xyz'
  4061. },
  4062. lab: {
  4063. channels: 3,
  4064. labels: 'lab'
  4065. },
  4066. lch: {
  4067. channels: 3,
  4068. labels: 'lch'
  4069. },
  4070. hex: {
  4071. channels: 1,
  4072. labels: ['hex']
  4073. },
  4074. keyword: {
  4075. channels: 1,
  4076. labels: ['keyword']
  4077. },
  4078. ansi16: {
  4079. channels: 1,
  4080. labels: ['ansi16']
  4081. },
  4082. ansi256: {
  4083. channels: 1,
  4084. labels: ['ansi256']
  4085. },
  4086. hcg: {
  4087. channels: 3,
  4088. labels: ['h', 'c', 'g']
  4089. },
  4090. apple: {
  4091. channels: 3,
  4092. labels: ['r16', 'g16', 'b16']
  4093. },
  4094. gray: {
  4095. channels: 1,
  4096. labels: ['gray']
  4097. }
  4098. }; // hide .channels and .labels properties
  4099. for (var model in convert) {
  4100. if (convert.hasOwnProperty(model)) {
  4101. if (!('channels' in convert[model])) {
  4102. throw new Error('missing channels property: ' + model);
  4103. }
  4104. if (!('labels' in convert[model])) {
  4105. throw new Error('missing channel labels property: ' + model);
  4106. }
  4107. if (convert[model].labels.length !== convert[model].channels) {
  4108. throw new Error('channel and label counts mismatch: ' + model);
  4109. }
  4110. var channels = convert[model].channels;
  4111. var labels = convert[model].labels;
  4112. delete convert[model].channels;
  4113. delete convert[model].labels;
  4114. Object.defineProperty(convert[model], 'channels', {
  4115. value: channels
  4116. });
  4117. Object.defineProperty(convert[model], 'labels', {
  4118. value: labels
  4119. });
  4120. }
  4121. }
  4122. convert.rgb.hsl = function (rgb) {
  4123. var r = rgb[0] / 255;
  4124. var g = rgb[1] / 255;
  4125. var b = rgb[2] / 255;
  4126. var min = Math.min(r, g, b);
  4127. var max = Math.max(r, g, b);
  4128. var delta = max - min;
  4129. var h;
  4130. var s;
  4131. var l;
  4132. if (max === min) {
  4133. h = 0;
  4134. } else if (r === max) {
  4135. h = (g - b) / delta;
  4136. } else if (g === max) {
  4137. h = 2 + (b - r) / delta;
  4138. } else if (b === max) {
  4139. h = 4 + (r - g) / delta;
  4140. }
  4141. h = Math.min(h * 60, 360);
  4142. if (h < 0) {
  4143. h += 360;
  4144. }
  4145. l = (min + max) / 2;
  4146. if (max === min) {
  4147. s = 0;
  4148. } else if (l <= 0.5) {
  4149. s = delta / (max + min);
  4150. } else {
  4151. s = delta / (2 - max - min);
  4152. }
  4153. return [h, s * 100, l * 100];
  4154. };
  4155. convert.rgb.hsv = function (rgb) {
  4156. var r = rgb[0];
  4157. var g = rgb[1];
  4158. var b = rgb[2];
  4159. var min = Math.min(r, g, b);
  4160. var max = Math.max(r, g, b);
  4161. var delta = max - min;
  4162. var h;
  4163. var s;
  4164. var v;
  4165. if (max === 0) {
  4166. s = 0;
  4167. } else {
  4168. s = delta / max * 1000 / 10;
  4169. }
  4170. if (max === min) {
  4171. h = 0;
  4172. } else if (r === max) {
  4173. h = (g - b) / delta;
  4174. } else if (g === max) {
  4175. h = 2 + (b - r) / delta;
  4176. } else if (b === max) {
  4177. h = 4 + (r - g) / delta;
  4178. }
  4179. h = Math.min(h * 60, 360);
  4180. if (h < 0) {
  4181. h += 360;
  4182. }
  4183. v = max / 255 * 1000 / 10;
  4184. return [h, s, v];
  4185. };
  4186. convert.rgb.hwb = function (rgb) {
  4187. var r = rgb[0];
  4188. var g = rgb[1];
  4189. var b = rgb[2];
  4190. var h = convert.rgb.hsl(rgb)[0];
  4191. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  4192. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  4193. return [h, w * 100, b * 100];
  4194. };
  4195. convert.rgb.cmyk = function (rgb) {
  4196. var r = rgb[0] / 255;
  4197. var g = rgb[1] / 255;
  4198. var b = rgb[2] / 255;
  4199. var c;
  4200. var m;
  4201. var y;
  4202. var k;
  4203. k = Math.min(1 - r, 1 - g, 1 - b);
  4204. c = (1 - r - k) / (1 - k) || 0;
  4205. m = (1 - g - k) / (1 - k) || 0;
  4206. y = (1 - b - k) / (1 - k) || 0;
  4207. return [c * 100, m * 100, y * 100, k * 100];
  4208. };
  4209. /**
  4210. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  4211. * */
  4212. function comparativeDistance(x, y) {
  4213. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  4214. }
  4215. convert.rgb.keyword = function (rgb) {
  4216. var reversed = reverseKeywords[rgb];
  4217. if (reversed) {
  4218. return reversed;
  4219. }
  4220. var currentClosestDistance = Infinity;
  4221. var currentClosestKeyword;
  4222. for (var keyword in colorName) {
  4223. if (colorName.hasOwnProperty(keyword)) {
  4224. var value = colorName[keyword]; // Compute comparative distance
  4225. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  4226. if (distance < currentClosestDistance) {
  4227. currentClosestDistance = distance;
  4228. currentClosestKeyword = keyword;
  4229. }
  4230. }
  4231. }
  4232. return currentClosestKeyword;
  4233. };
  4234. convert.keyword.rgb = function (keyword) {
  4235. return colorName[keyword];
  4236. };
  4237. convert.rgb.xyz = function (rgb) {
  4238. var r = rgb[0] / 255;
  4239. var g = rgb[1] / 255;
  4240. var b = rgb[2] / 255; // assume sRGB
  4241. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  4242. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  4243. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  4244. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  4245. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  4246. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  4247. return [x * 100, y * 100, z * 100];
  4248. };
  4249. convert.rgb.lab = function (rgb) {
  4250. var xyz = convert.rgb.xyz(rgb);
  4251. var x = xyz[0];
  4252. var y = xyz[1];
  4253. var z = xyz[2];
  4254. var l;
  4255. var a;
  4256. var b;
  4257. x /= 95.047;
  4258. y /= 100;
  4259. z /= 108.883;
  4260. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4261. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4262. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4263. l = 116 * y - 16;
  4264. a = 500 * (x - y);
  4265. b = 200 * (y - z);
  4266. return [l, a, b];
  4267. };
  4268. convert.hsl.rgb = function (hsl) {
  4269. var h = hsl[0] / 360;
  4270. var s = hsl[1] / 100;
  4271. var l = hsl[2] / 100;
  4272. var t1;
  4273. var t2;
  4274. var t3;
  4275. var rgb;
  4276. var val;
  4277. if (s === 0) {
  4278. val = l * 255;
  4279. return [val, val, val];
  4280. }
  4281. if (l < 0.5) {
  4282. t2 = l * (1 + s);
  4283. } else {
  4284. t2 = l + s - l * s;
  4285. }
  4286. t1 = 2 * l - t2;
  4287. rgb = [0, 0, 0];
  4288. for (var i = 0; i < 3; i++) {
  4289. t3 = h + 1 / 3 * -(i - 1);
  4290. if (t3 < 0) {
  4291. t3++;
  4292. }
  4293. if (t3 > 1) {
  4294. t3--;
  4295. }
  4296. if (6 * t3 < 1) {
  4297. val = t1 + (t2 - t1) * 6 * t3;
  4298. } else if (2 * t3 < 1) {
  4299. val = t2;
  4300. } else if (3 * t3 < 2) {
  4301. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  4302. } else {
  4303. val = t1;
  4304. }
  4305. rgb[i] = val * 255;
  4306. }
  4307. return rgb;
  4308. };
  4309. convert.hsl.hsv = function (hsl) {
  4310. var h = hsl[0];
  4311. var s = hsl[1] / 100;
  4312. var l = hsl[2] / 100;
  4313. var smin = s;
  4314. var lmin = Math.max(l, 0.01);
  4315. var sv;
  4316. var v;
  4317. l *= 2;
  4318. s *= l <= 1 ? l : 2 - l;
  4319. smin *= lmin <= 1 ? lmin : 2 - lmin;
  4320. v = (l + s) / 2;
  4321. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  4322. return [h, sv * 100, v * 100];
  4323. };
  4324. convert.hsv.rgb = function (hsv) {
  4325. var h = hsv[0] / 60;
  4326. var s = hsv[1] / 100;
  4327. var v = hsv[2] / 100;
  4328. var hi = Math.floor(h) % 6;
  4329. var f = h - Math.floor(h);
  4330. var p = 255 * v * (1 - s);
  4331. var q = 255 * v * (1 - s * f);
  4332. var t = 255 * v * (1 - s * (1 - f));
  4333. v *= 255;
  4334. switch (hi) {
  4335. case 0:
  4336. return [v, t, p];
  4337. case 1:
  4338. return [q, v, p];
  4339. case 2:
  4340. return [p, v, t];
  4341. case 3:
  4342. return [p, q, v];
  4343. case 4:
  4344. return [t, p, v];
  4345. case 5:
  4346. return [v, p, q];
  4347. }
  4348. };
  4349. convert.hsv.hsl = function (hsv) {
  4350. var h = hsv[0];
  4351. var s = hsv[1] / 100;
  4352. var v = hsv[2] / 100;
  4353. var vmin = Math.max(v, 0.01);
  4354. var lmin;
  4355. var sl;
  4356. var l;
  4357. l = (2 - s) * v;
  4358. lmin = (2 - s) * vmin;
  4359. sl = s * vmin;
  4360. sl /= lmin <= 1 ? lmin : 2 - lmin;
  4361. sl = sl || 0;
  4362. l /= 2;
  4363. return [h, sl * 100, l * 100];
  4364. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  4365. convert.hwb.rgb = function (hwb) {
  4366. var h = hwb[0] / 360;
  4367. var wh = hwb[1] / 100;
  4368. var bl = hwb[2] / 100;
  4369. var ratio = wh + bl;
  4370. var i;
  4371. var v;
  4372. var f;
  4373. var n; // wh + bl cant be > 1
  4374. if (ratio > 1) {
  4375. wh /= ratio;
  4376. bl /= ratio;
  4377. }
  4378. i = Math.floor(6 * h);
  4379. v = 1 - bl;
  4380. f = 6 * h - i;
  4381. if ((i & 0x01) !== 0) {
  4382. f = 1 - f;
  4383. }
  4384. n = wh + f * (v - wh); // linear interpolation
  4385. var r;
  4386. var g;
  4387. var b;
  4388. switch (i) {
  4389. default:
  4390. case 6:
  4391. case 0:
  4392. r = v;
  4393. g = n;
  4394. b = wh;
  4395. break;
  4396. case 1:
  4397. r = n;
  4398. g = v;
  4399. b = wh;
  4400. break;
  4401. case 2:
  4402. r = wh;
  4403. g = v;
  4404. b = n;
  4405. break;
  4406. case 3:
  4407. r = wh;
  4408. g = n;
  4409. b = v;
  4410. break;
  4411. case 4:
  4412. r = n;
  4413. g = wh;
  4414. b = v;
  4415. break;
  4416. case 5:
  4417. r = v;
  4418. g = wh;
  4419. b = n;
  4420. break;
  4421. }
  4422. return [r * 255, g * 255, b * 255];
  4423. };
  4424. convert.cmyk.rgb = function (cmyk) {
  4425. var c = cmyk[0] / 100;
  4426. var m = cmyk[1] / 100;
  4427. var y = cmyk[2] / 100;
  4428. var k = cmyk[3] / 100;
  4429. var r;
  4430. var g;
  4431. var b;
  4432. r = 1 - Math.min(1, c * (1 - k) + k);
  4433. g = 1 - Math.min(1, m * (1 - k) + k);
  4434. b = 1 - Math.min(1, y * (1 - k) + k);
  4435. return [r * 255, g * 255, b * 255];
  4436. };
  4437. convert.xyz.rgb = function (xyz) {
  4438. var x = xyz[0] / 100;
  4439. var y = xyz[1] / 100;
  4440. var z = xyz[2] / 100;
  4441. var r;
  4442. var g;
  4443. var b;
  4444. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  4445. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  4446. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  4447. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  4448. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  4449. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  4450. r = Math.min(Math.max(0, r), 1);
  4451. g = Math.min(Math.max(0, g), 1);
  4452. b = Math.min(Math.max(0, b), 1);
  4453. return [r * 255, g * 255, b * 255];
  4454. };
  4455. convert.xyz.lab = function (xyz) {
  4456. var x = xyz[0];
  4457. var y = xyz[1];
  4458. var z = xyz[2];
  4459. var l;
  4460. var a;
  4461. var b;
  4462. x /= 95.047;
  4463. y /= 100;
  4464. z /= 108.883;
  4465. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4466. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4467. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4468. l = 116 * y - 16;
  4469. a = 500 * (x - y);
  4470. b = 200 * (y - z);
  4471. return [l, a, b];
  4472. };
  4473. convert.lab.xyz = function (lab) {
  4474. var l = lab[0];
  4475. var a = lab[1];
  4476. var b = lab[2];
  4477. var x;
  4478. var y;
  4479. var z;
  4480. y = (l + 16) / 116;
  4481. x = a / 500 + y;
  4482. z = y - b / 200;
  4483. var y2 = Math.pow(y, 3);
  4484. var x2 = Math.pow(x, 3);
  4485. var z2 = Math.pow(z, 3);
  4486. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  4487. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  4488. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  4489. x *= 95.047;
  4490. y *= 100;
  4491. z *= 108.883;
  4492. return [x, y, z];
  4493. };
  4494. convert.lab.lch = function (lab) {
  4495. var l = lab[0];
  4496. var a = lab[1];
  4497. var b = lab[2];
  4498. var hr;
  4499. var h;
  4500. var c;
  4501. hr = Math.atan2(b, a);
  4502. h = hr * 360 / 2 / Math.PI;
  4503. if (h < 0) {
  4504. h += 360;
  4505. }
  4506. c = Math.sqrt(a * a + b * b);
  4507. return [l, c, h];
  4508. };
  4509. convert.lch.lab = function (lch) {
  4510. var l = lch[0];
  4511. var c = lch[1];
  4512. var h = lch[2];
  4513. var a;
  4514. var b;
  4515. var hr;
  4516. hr = h / 360 * 2 * Math.PI;
  4517. a = c * Math.cos(hr);
  4518. b = c * Math.sin(hr);
  4519. return [l, a, b];
  4520. };
  4521. convert.rgb.ansi16 = function (args) {
  4522. var r = args[0];
  4523. var g = args[1];
  4524. var b = args[2];
  4525. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  4526. value = Math.round(value / 50);
  4527. if (value === 0) {
  4528. return 30;
  4529. }
  4530. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  4531. if (value === 2) {
  4532. ansi += 60;
  4533. }
  4534. return ansi;
  4535. };
  4536. convert.hsv.ansi16 = function (args) {
  4537. // optimization here; we already know the value and don't need to get
  4538. // it converted for us.
  4539. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  4540. };
  4541. convert.rgb.ansi256 = function (args) {
  4542. var r = args[0];
  4543. var g = args[1];
  4544. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  4545. // black and white. normal palette only has 4 greyscale shades.
  4546. if (r === g && g === b) {
  4547. if (r < 8) {
  4548. return 16;
  4549. }
  4550. if (r > 248) {
  4551. return 231;
  4552. }
  4553. return Math.round((r - 8) / 247 * 24) + 232;
  4554. }
  4555. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  4556. return ansi;
  4557. };
  4558. convert.ansi16.rgb = function (args) {
  4559. var color = args % 10; // handle greyscale
  4560. if (color === 0 || color === 7) {
  4561. if (args > 50) {
  4562. color += 3.5;
  4563. }
  4564. color = color / 10.5 * 255;
  4565. return [color, color, color];
  4566. }
  4567. var mult = (~~(args > 50) + 1) * 0.5;
  4568. var r = (color & 1) * mult * 255;
  4569. var g = (color >> 1 & 1) * mult * 255;
  4570. var b = (color >> 2 & 1) * mult * 255;
  4571. return [r, g, b];
  4572. };
  4573. convert.ansi256.rgb = function (args) {
  4574. // handle greyscale
  4575. if (args >= 232) {
  4576. var c = (args - 232) * 10 + 8;
  4577. return [c, c, c];
  4578. }
  4579. args -= 16;
  4580. var rem;
  4581. var r = Math.floor(args / 36) / 5 * 255;
  4582. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  4583. var b = rem % 6 / 5 * 255;
  4584. return [r, g, b];
  4585. };
  4586. convert.rgb.hex = function (args) {
  4587. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  4588. var string = integer.toString(16).toUpperCase();
  4589. return '000000'.substring(string.length) + string;
  4590. };
  4591. convert.hex.rgb = function (args) {
  4592. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  4593. if (!match) {
  4594. return [0, 0, 0];
  4595. }
  4596. var colorString = match[0];
  4597. if (match[0].length === 3) {
  4598. colorString = colorString.split('').map(function (char) {
  4599. return char + char;
  4600. }).join('');
  4601. }
  4602. var integer = parseInt(colorString, 16);
  4603. var r = integer >> 16 & 0xFF;
  4604. var g = integer >> 8 & 0xFF;
  4605. var b = integer & 0xFF;
  4606. return [r, g, b];
  4607. };
  4608. convert.rgb.hcg = function (rgb) {
  4609. var r = rgb[0] / 255;
  4610. var g = rgb[1] / 255;
  4611. var b = rgb[2] / 255;
  4612. var max = Math.max(Math.max(r, g), b);
  4613. var min = Math.min(Math.min(r, g), b);
  4614. var chroma = max - min;
  4615. var grayscale;
  4616. var hue;
  4617. if (chroma < 1) {
  4618. grayscale = min / (1 - chroma);
  4619. } else {
  4620. grayscale = 0;
  4621. }
  4622. if (chroma <= 0) {
  4623. hue = 0;
  4624. } else if (max === r) {
  4625. hue = (g - b) / chroma % 6;
  4626. } else if (max === g) {
  4627. hue = 2 + (b - r) / chroma;
  4628. } else {
  4629. hue = 4 + (r - g) / chroma + 4;
  4630. }
  4631. hue /= 6;
  4632. hue %= 1;
  4633. return [hue * 360, chroma * 100, grayscale * 100];
  4634. };
  4635. convert.hsl.hcg = function (hsl) {
  4636. var s = hsl[1] / 100;
  4637. var l = hsl[2] / 100;
  4638. var c = 1;
  4639. var f = 0;
  4640. if (l < 0.5) {
  4641. c = 2.0 * s * l;
  4642. } else {
  4643. c = 2.0 * s * (1.0 - l);
  4644. }
  4645. if (c < 1.0) {
  4646. f = (l - 0.5 * c) / (1.0 - c);
  4647. }
  4648. return [hsl[0], c * 100, f * 100];
  4649. };
  4650. convert.hsv.hcg = function (hsv) {
  4651. var s = hsv[1] / 100;
  4652. var v = hsv[2] / 100;
  4653. var c = s * v;
  4654. var f = 0;
  4655. if (c < 1.0) {
  4656. f = (v - c) / (1 - c);
  4657. }
  4658. return [hsv[0], c * 100, f * 100];
  4659. };
  4660. convert.hcg.rgb = function (hcg) {
  4661. var h = hcg[0] / 360;
  4662. var c = hcg[1] / 100;
  4663. var g = hcg[2] / 100;
  4664. if (c === 0.0) {
  4665. return [g * 255, g * 255, g * 255];
  4666. }
  4667. var pure = [0, 0, 0];
  4668. var hi = h % 1 * 6;
  4669. var v = hi % 1;
  4670. var w = 1 - v;
  4671. var mg = 0;
  4672. switch (Math.floor(hi)) {
  4673. case 0:
  4674. pure[0] = 1;
  4675. pure[1] = v;
  4676. pure[2] = 0;
  4677. break;
  4678. case 1:
  4679. pure[0] = w;
  4680. pure[1] = 1;
  4681. pure[2] = 0;
  4682. break;
  4683. case 2:
  4684. pure[0] = 0;
  4685. pure[1] = 1;
  4686. pure[2] = v;
  4687. break;
  4688. case 3:
  4689. pure[0] = 0;
  4690. pure[1] = w;
  4691. pure[2] = 1;
  4692. break;
  4693. case 4:
  4694. pure[0] = v;
  4695. pure[1] = 0;
  4696. pure[2] = 1;
  4697. break;
  4698. default:
  4699. pure[0] = 1;
  4700. pure[1] = 0;
  4701. pure[2] = w;
  4702. }
  4703. mg = (1.0 - c) * g;
  4704. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  4705. };
  4706. convert.hcg.hsv = function (hcg) {
  4707. var c = hcg[1] / 100;
  4708. var g = hcg[2] / 100;
  4709. var v = c + g * (1.0 - c);
  4710. var f = 0;
  4711. if (v > 0.0) {
  4712. f = c / v;
  4713. }
  4714. return [hcg[0], f * 100, v * 100];
  4715. };
  4716. convert.hcg.hsl = function (hcg) {
  4717. var c = hcg[1] / 100;
  4718. var g = hcg[2] / 100;
  4719. var l = g * (1.0 - c) + 0.5 * c;
  4720. var s = 0;
  4721. if (l > 0.0 && l < 0.5) {
  4722. s = c / (2 * l);
  4723. } else if (l >= 0.5 && l < 1.0) {
  4724. s = c / (2 * (1 - l));
  4725. }
  4726. return [hcg[0], s * 100, l * 100];
  4727. };
  4728. convert.hcg.hwb = function (hcg) {
  4729. var c = hcg[1] / 100;
  4730. var g = hcg[2] / 100;
  4731. var v = c + g * (1.0 - c);
  4732. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  4733. };
  4734. convert.hwb.hcg = function (hwb) {
  4735. var w = hwb[1] / 100;
  4736. var b = hwb[2] / 100;
  4737. var v = 1 - b;
  4738. var c = v - w;
  4739. var g = 0;
  4740. if (c < 1) {
  4741. g = (v - c) / (1 - c);
  4742. }
  4743. return [hwb[0], c * 100, g * 100];
  4744. };
  4745. convert.apple.rgb = function (apple) {
  4746. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  4747. };
  4748. convert.rgb.apple = function (rgb) {
  4749. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  4750. };
  4751. convert.gray.rgb = function (args) {
  4752. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  4753. };
  4754. convert.gray.hsl = convert.gray.hsv = function (args) {
  4755. return [0, 0, args[0]];
  4756. };
  4757. convert.gray.hwb = function (gray) {
  4758. return [0, 100, gray[0]];
  4759. };
  4760. convert.gray.cmyk = function (gray) {
  4761. return [0, 0, 0, gray[0]];
  4762. };
  4763. convert.gray.lab = function (gray) {
  4764. return [gray[0], 0, 0];
  4765. };
  4766. convert.gray.hex = function (gray) {
  4767. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  4768. var integer = (val << 16) + (val << 8) + val;
  4769. var string = integer.toString(16).toUpperCase();
  4770. return '000000'.substring(string.length) + string;
  4771. };
  4772. convert.rgb.gray = function (rgb) {
  4773. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  4774. return [val / 255 * 100];
  4775. };
  4776. });
  4777. /*
  4778. this function routes a model to all other models.
  4779. all functions that are routed have a property `.conversion` attached
  4780. to the returned synthetic function. This property is an array
  4781. of strings, each with the steps in between the 'from' and 'to'
  4782. color models (inclusive).
  4783. conversions that are not possible simply are not included.
  4784. */
  4785. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  4786. var models$1 = Object.keys(conversions);
  4787. function buildGraph() {
  4788. var graph = {};
  4789. for (var len = models$1.length, i = 0; i < len; i++) {
  4790. graph[models$1[i]] = {
  4791. // http://jsperf.com/1-vs-infinity
  4792. // micro-opt, but this is simple.
  4793. distance: -1,
  4794. parent: null
  4795. };
  4796. }
  4797. return graph;
  4798. } // https://en.wikipedia.org/wiki/Breadth-first_search
  4799. function deriveBFS(fromModel) {
  4800. var graph = buildGraph();
  4801. var queue = [fromModel]; // unshift -> queue -> pop
  4802. graph[fromModel].distance = 0;
  4803. while (queue.length) {
  4804. var current = queue.pop();
  4805. var adjacents = Object.keys(conversions[current]);
  4806. for (var len = adjacents.length, i = 0; i < len; i++) {
  4807. var adjacent = adjacents[i];
  4808. var node = graph[adjacent];
  4809. if (node.distance === -1) {
  4810. node.distance = graph[current].distance + 1;
  4811. node.parent = current;
  4812. queue.unshift(adjacent);
  4813. }
  4814. }
  4815. }
  4816. return graph;
  4817. }
  4818. function link(from, to) {
  4819. return function (args) {
  4820. return to(from(args));
  4821. };
  4822. }
  4823. function wrapConversion(toModel, graph) {
  4824. var path$$1 = [graph[toModel].parent, toModel];
  4825. var fn = conversions[graph[toModel].parent][toModel];
  4826. var cur = graph[toModel].parent;
  4827. while (graph[cur].parent) {
  4828. path$$1.unshift(graph[cur].parent);
  4829. fn = link(conversions[graph[cur].parent][cur], fn);
  4830. cur = graph[cur].parent;
  4831. }
  4832. fn.conversion = path$$1;
  4833. return fn;
  4834. }
  4835. var route = function route(fromModel) {
  4836. var graph = deriveBFS(fromModel);
  4837. var conversion = {};
  4838. var models = Object.keys(graph);
  4839. for (var len = models.length, i = 0; i < len; i++) {
  4840. var toModel = models[i];
  4841. var node = graph[toModel];
  4842. if (node.parent === null) {
  4843. // no possible conversion, or this node is the source model.
  4844. continue;
  4845. }
  4846. conversion[toModel] = wrapConversion(toModel, graph);
  4847. }
  4848. return conversion;
  4849. };
  4850. var convert = {};
  4851. var models = Object.keys(conversions);
  4852. function wrapRaw(fn) {
  4853. var wrappedFn = function wrappedFn(args) {
  4854. if (args === undefined || args === null) {
  4855. return args;
  4856. }
  4857. if (arguments.length > 1) {
  4858. args = Array.prototype.slice.call(arguments);
  4859. }
  4860. return fn(args);
  4861. }; // preserve .conversion property if there is one
  4862. if ('conversion' in fn) {
  4863. wrappedFn.conversion = fn.conversion;
  4864. }
  4865. return wrappedFn;
  4866. }
  4867. function wrapRounded(fn) {
  4868. var wrappedFn = function wrappedFn(args) {
  4869. if (args === undefined || args === null) {
  4870. return args;
  4871. }
  4872. if (arguments.length > 1) {
  4873. args = Array.prototype.slice.call(arguments);
  4874. }
  4875. var result = fn(args); // we're assuming the result is an array here.
  4876. // see notice in conversions.js; don't use box types
  4877. // in conversion functions.
  4878. if (typeof result === 'object') {
  4879. for (var len = result.length, i = 0; i < len; i++) {
  4880. result[i] = Math.round(result[i]);
  4881. }
  4882. }
  4883. return result;
  4884. }; // preserve .conversion property if there is one
  4885. if ('conversion' in fn) {
  4886. wrappedFn.conversion = fn.conversion;
  4887. }
  4888. return wrappedFn;
  4889. }
  4890. models.forEach(function (fromModel) {
  4891. convert[fromModel] = {};
  4892. Object.defineProperty(convert[fromModel], 'channels', {
  4893. value: conversions[fromModel].channels
  4894. });
  4895. Object.defineProperty(convert[fromModel], 'labels', {
  4896. value: conversions[fromModel].labels
  4897. });
  4898. var routes = route(fromModel);
  4899. var routeModels = Object.keys(routes);
  4900. routeModels.forEach(function (toModel) {
  4901. var fn = routes[toModel];
  4902. convert[fromModel][toModel] = wrapRounded(fn);
  4903. convert[fromModel][toModel].raw = wrapRaw(fn);
  4904. });
  4905. });
  4906. var colorConvert = convert;
  4907. var ansiStyles = createCommonjsModule(function (module) {
  4908. 'use strict';
  4909. var wrapAnsi16 = function wrapAnsi16(fn, offset) {
  4910. return function () {
  4911. var code = fn.apply(colorConvert, arguments);
  4912. return `\u001B[${code + offset}m`;
  4913. };
  4914. };
  4915. var wrapAnsi256 = function wrapAnsi256(fn, offset) {
  4916. return function () {
  4917. var code = fn.apply(colorConvert, arguments);
  4918. return `\u001B[${38 + offset};5;${code}m`;
  4919. };
  4920. };
  4921. var wrapAnsi16m = function wrapAnsi16m(fn, offset) {
  4922. return function () {
  4923. var rgb = fn.apply(colorConvert, arguments);
  4924. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  4925. };
  4926. };
  4927. function assembleStyles() {
  4928. var codes = new Map();
  4929. var styles = {
  4930. modifier: {
  4931. reset: [0, 0],
  4932. // 21 isn't widely supported and 22 does the same thing
  4933. bold: [1, 22],
  4934. dim: [2, 22],
  4935. italic: [3, 23],
  4936. underline: [4, 24],
  4937. inverse: [7, 27],
  4938. hidden: [8, 28],
  4939. strikethrough: [9, 29]
  4940. },
  4941. color: {
  4942. black: [30, 39],
  4943. red: [31, 39],
  4944. green: [32, 39],
  4945. yellow: [33, 39],
  4946. blue: [34, 39],
  4947. magenta: [35, 39],
  4948. cyan: [36, 39],
  4949. white: [37, 39],
  4950. gray: [90, 39],
  4951. // Bright color
  4952. redBright: [91, 39],
  4953. greenBright: [92, 39],
  4954. yellowBright: [93, 39],
  4955. blueBright: [94, 39],
  4956. magentaBright: [95, 39],
  4957. cyanBright: [96, 39],
  4958. whiteBright: [97, 39]
  4959. },
  4960. bgColor: {
  4961. bgBlack: [40, 49],
  4962. bgRed: [41, 49],
  4963. bgGreen: [42, 49],
  4964. bgYellow: [43, 49],
  4965. bgBlue: [44, 49],
  4966. bgMagenta: [45, 49],
  4967. bgCyan: [46, 49],
  4968. bgWhite: [47, 49],
  4969. // Bright color
  4970. bgBlackBright: [100, 49],
  4971. bgRedBright: [101, 49],
  4972. bgGreenBright: [102, 49],
  4973. bgYellowBright: [103, 49],
  4974. bgBlueBright: [104, 49],
  4975. bgMagentaBright: [105, 49],
  4976. bgCyanBright: [106, 49],
  4977. bgWhiteBright: [107, 49]
  4978. }
  4979. }; // Fix humans
  4980. styles.color.grey = styles.color.gray;
  4981. var _arr = Object.keys(styles);
  4982. for (var _i = 0; _i < _arr.length; _i++) {
  4983. var groupName = _arr[_i];
  4984. var group = styles[groupName];
  4985. var _arr3 = Object.keys(group);
  4986. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  4987. var styleName = _arr3[_i3];
  4988. var style = group[styleName];
  4989. styles[styleName] = {
  4990. open: `\u001B[${style[0]}m`,
  4991. close: `\u001B[${style[1]}m`
  4992. };
  4993. group[styleName] = styles[styleName];
  4994. codes.set(style[0], style[1]);
  4995. }
  4996. Object.defineProperty(styles, groupName, {
  4997. value: group,
  4998. enumerable: false
  4999. });
  5000. Object.defineProperty(styles, 'codes', {
  5001. value: codes,
  5002. enumerable: false
  5003. });
  5004. }
  5005. var ansi2ansi = function ansi2ansi(n) {
  5006. return n;
  5007. };
  5008. var rgb2rgb = function rgb2rgb(r, g, b) {
  5009. return [r, g, b];
  5010. };
  5011. styles.color.close = '\u001B[39m';
  5012. styles.bgColor.close = '\u001B[49m';
  5013. styles.color.ansi = {
  5014. ansi: wrapAnsi16(ansi2ansi, 0)
  5015. };
  5016. styles.color.ansi256 = {
  5017. ansi256: wrapAnsi256(ansi2ansi, 0)
  5018. };
  5019. styles.color.ansi16m = {
  5020. rgb: wrapAnsi16m(rgb2rgb, 0)
  5021. };
  5022. styles.bgColor.ansi = {
  5023. ansi: wrapAnsi16(ansi2ansi, 10)
  5024. };
  5025. styles.bgColor.ansi256 = {
  5026. ansi256: wrapAnsi256(ansi2ansi, 10)
  5027. };
  5028. styles.bgColor.ansi16m = {
  5029. rgb: wrapAnsi16m(rgb2rgb, 10)
  5030. };
  5031. var _arr2 = Object.keys(colorConvert);
  5032. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  5033. var key = _arr2[_i2];
  5034. if (typeof colorConvert[key] !== 'object') {
  5035. continue;
  5036. }
  5037. var suite = colorConvert[key];
  5038. if (key === 'ansi16') {
  5039. key = 'ansi';
  5040. }
  5041. if ('ansi16' in suite) {
  5042. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  5043. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  5044. }
  5045. if ('ansi256' in suite) {
  5046. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  5047. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  5048. }
  5049. if ('rgb' in suite) {
  5050. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  5051. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  5052. }
  5053. }
  5054. return styles;
  5055. } // Make the export immutable
  5056. Object.defineProperty(module, 'exports', {
  5057. enumerable: true,
  5058. get: assembleStyles
  5059. });
  5060. });
  5061. var hasFlag = createCommonjsModule(function (module) {
  5062. 'use strict';
  5063. module.exports = function (flag, argv) {
  5064. argv = argv || process.argv;
  5065. var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  5066. var pos = argv.indexOf(prefix + flag);
  5067. var terminatorPos = argv.indexOf('--');
  5068. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  5069. };
  5070. });
  5071. var env = process.env;
  5072. var forceColor;
  5073. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  5074. forceColor = false;
  5075. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  5076. forceColor = true;
  5077. }
  5078. if ('FORCE_COLOR' in env) {
  5079. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  5080. }
  5081. function translateLevel(level) {
  5082. if (level === 0) {
  5083. return false;
  5084. }
  5085. return {
  5086. level,
  5087. hasBasic: true,
  5088. has256: level >= 2,
  5089. has16m: level >= 3
  5090. };
  5091. }
  5092. function supportsColor(stream) {
  5093. if (forceColor === false) {
  5094. return 0;
  5095. }
  5096. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  5097. return 3;
  5098. }
  5099. if (hasFlag('color=256')) {
  5100. return 2;
  5101. }
  5102. if (stream && !stream.isTTY && forceColor !== true) {
  5103. return 0;
  5104. }
  5105. var min = forceColor ? 1 : 0;
  5106. if (process.platform === 'win32') {
  5107. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  5108. // libuv that enables 256 color output on Windows. Anything earlier and it
  5109. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  5110. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  5111. // release that supports 256 colors. Windows 10 build 14931 is the first release
  5112. // that supports 16m/TrueColor.
  5113. var osRelease = os.release().split('.');
  5114. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  5115. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  5116. }
  5117. return 1;
  5118. }
  5119. if ('CI' in env) {
  5120. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  5121. return sign in env;
  5122. }) || env.CI_NAME === 'codeship') {
  5123. return 1;
  5124. }
  5125. return min;
  5126. }
  5127. if ('TEAMCITY_VERSION' in env) {
  5128. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  5129. }
  5130. if (env.COLORTERM === 'truecolor') {
  5131. return 3;
  5132. }
  5133. if ('TERM_PROGRAM' in env) {
  5134. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  5135. switch (env.TERM_PROGRAM) {
  5136. case 'iTerm.app':
  5137. return version >= 3 ? 3 : 2;
  5138. case 'Apple_Terminal':
  5139. return 2;
  5140. // No default
  5141. }
  5142. }
  5143. if (/-256(color)?$/i.test(env.TERM)) {
  5144. return 2;
  5145. }
  5146. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  5147. return 1;
  5148. }
  5149. if ('COLORTERM' in env) {
  5150. return 1;
  5151. }
  5152. if (env.TERM === 'dumb') {
  5153. return min;
  5154. }
  5155. return min;
  5156. }
  5157. function getSupportLevel(stream) {
  5158. var level = supportsColor(stream);
  5159. return translateLevel(level);
  5160. }
  5161. var supportsColor_1 = {
  5162. supportsColor: getSupportLevel,
  5163. stdout: getSupportLevel(process.stdout),
  5164. stderr: getSupportLevel(process.stderr)
  5165. };
  5166. var templates = createCommonjsModule(function (module) {
  5167. 'use strict';
  5168. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  5169. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  5170. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  5171. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  5172. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  5173. function unescape(c) {
  5174. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  5175. return String.fromCharCode(parseInt(c.slice(1), 16));
  5176. }
  5177. return ESCAPES.get(c) || c;
  5178. }
  5179. function parseArguments(name, args) {
  5180. var results = [];
  5181. var chunks = args.trim().split(/\s*,\s*/g);
  5182. var matches;
  5183. var _iteratorNormalCompletion = true;
  5184. var _didIteratorError = false;
  5185. var _iteratorError = undefined;
  5186. try {
  5187. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5188. var chunk = _step.value;
  5189. if (!isNaN(chunk)) {
  5190. results.push(Number(chunk));
  5191. } else if (matches = chunk.match(STRING_REGEX)) {
  5192. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  5193. return escape ? unescape(escape) : chr;
  5194. }));
  5195. } else {
  5196. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  5197. }
  5198. }
  5199. } catch (err) {
  5200. _didIteratorError = true;
  5201. _iteratorError = err;
  5202. } finally {
  5203. try {
  5204. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5205. _iterator.return();
  5206. }
  5207. } finally {
  5208. if (_didIteratorError) {
  5209. throw _iteratorError;
  5210. }
  5211. }
  5212. }
  5213. return results;
  5214. }
  5215. function parseStyle(style) {
  5216. STYLE_REGEX.lastIndex = 0;
  5217. var results = [];
  5218. var matches;
  5219. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  5220. var name = matches[1];
  5221. if (matches[2]) {
  5222. var args = parseArguments(name, matches[2]);
  5223. results.push([name].concat(args));
  5224. } else {
  5225. results.push([name]);
  5226. }
  5227. }
  5228. return results;
  5229. }
  5230. function buildStyle(chalk, styles) {
  5231. var enabled = {};
  5232. var _iteratorNormalCompletion2 = true;
  5233. var _didIteratorError2 = false;
  5234. var _iteratorError2 = undefined;
  5235. try {
  5236. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5237. var layer = _step2.value;
  5238. var _iteratorNormalCompletion3 = true;
  5239. var _didIteratorError3 = false;
  5240. var _iteratorError3 = undefined;
  5241. try {
  5242. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  5243. var style = _step3.value;
  5244. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  5245. }
  5246. } catch (err) {
  5247. _didIteratorError3 = true;
  5248. _iteratorError3 = err;
  5249. } finally {
  5250. try {
  5251. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  5252. _iterator3.return();
  5253. }
  5254. } finally {
  5255. if (_didIteratorError3) {
  5256. throw _iteratorError3;
  5257. }
  5258. }
  5259. }
  5260. }
  5261. } catch (err) {
  5262. _didIteratorError2 = true;
  5263. _iteratorError2 = err;
  5264. } finally {
  5265. try {
  5266. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5267. _iterator2.return();
  5268. }
  5269. } finally {
  5270. if (_didIteratorError2) {
  5271. throw _iteratorError2;
  5272. }
  5273. }
  5274. }
  5275. var current = chalk;
  5276. var _arr = Object.keys(enabled);
  5277. for (var _i = 0; _i < _arr.length; _i++) {
  5278. var styleName = _arr[_i];
  5279. if (Array.isArray(enabled[styleName])) {
  5280. if (!(styleName in current)) {
  5281. throw new Error(`Unknown Chalk style: ${styleName}`);
  5282. }
  5283. if (enabled[styleName].length > 0) {
  5284. current = current[styleName].apply(current, enabled[styleName]);
  5285. } else {
  5286. current = current[styleName];
  5287. }
  5288. }
  5289. }
  5290. return current;
  5291. }
  5292. module.exports = function (chalk, tmp) {
  5293. var styles = [];
  5294. var chunks = [];
  5295. var chunk = []; // eslint-disable-next-line max-params
  5296. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  5297. if (escapeChar) {
  5298. chunk.push(unescape(escapeChar));
  5299. } else if (style) {
  5300. var str = chunk.join('');
  5301. chunk = [];
  5302. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  5303. styles.push({
  5304. inverse,
  5305. styles: parseStyle(style)
  5306. });
  5307. } else if (close) {
  5308. if (styles.length === 0) {
  5309. throw new Error('Found extraneous } in Chalk template literal');
  5310. }
  5311. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  5312. chunk = [];
  5313. styles.pop();
  5314. } else {
  5315. chunk.push(chr);
  5316. }
  5317. });
  5318. chunks.push(chunk.join(''));
  5319. if (styles.length > 0) {
  5320. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  5321. throw new Error(errMsg);
  5322. }
  5323. return chunks.join('');
  5324. };
  5325. });
  5326. var chalk = createCommonjsModule(function (module) {
  5327. 'use strict';
  5328. var stdoutColor = supportsColor_1.stdout;
  5329. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  5330. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  5331. var skipModels = new Set(['gray']);
  5332. var styles = Object.create(null);
  5333. function applyOptions(obj, options) {
  5334. options = options || {}; // Detect level if not set manually
  5335. var scLevel = stdoutColor ? stdoutColor.level : 0;
  5336. obj.level = options.level === undefined ? scLevel : options.level;
  5337. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  5338. }
  5339. function Chalk(options) {
  5340. // We check for this.template here since calling `chalk.constructor()`
  5341. // by itself will have a `this` of a previously constructed chalk object
  5342. if (!this || !(this instanceof Chalk) || this.template) {
  5343. var _chalk = {};
  5344. applyOptions(_chalk, options);
  5345. _chalk.template = function () {
  5346. var args = [].slice.call(arguments);
  5347. return chalkTag.apply(null, [_chalk.template].concat(args));
  5348. };
  5349. Object.setPrototypeOf(_chalk, Chalk.prototype);
  5350. Object.setPrototypeOf(_chalk.template, _chalk);
  5351. _chalk.template.constructor = Chalk;
  5352. return _chalk.template;
  5353. }
  5354. applyOptions(this, options);
  5355. } // Use bright blue on Windows as the normal blue color is illegible
  5356. if (isSimpleWindowsTerm) {
  5357. ansiStyles.blue.open = '\u001B[94m';
  5358. }
  5359. var _arr = Object.keys(ansiStyles);
  5360. var _loop = function _loop() {
  5361. var key = _arr[_i];
  5362. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  5363. styles[key] = {
  5364. get() {
  5365. var codes = ansiStyles[key];
  5366. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  5367. }
  5368. };
  5369. };
  5370. for (var _i = 0; _i < _arr.length; _i++) {
  5371. _loop();
  5372. }
  5373. styles.visible = {
  5374. get() {
  5375. return build.call(this, this._styles || [], true, 'visible');
  5376. }
  5377. };
  5378. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  5379. var _arr2 = Object.keys(ansiStyles.color.ansi);
  5380. var _loop2 = function _loop2() {
  5381. var model = _arr2[_i2];
  5382. if (skipModels.has(model)) {
  5383. return "continue";
  5384. }
  5385. styles[model] = {
  5386. get() {
  5387. var level = this.level;
  5388. return function () {
  5389. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  5390. var codes = {
  5391. open,
  5392. close: ansiStyles.color.close,
  5393. closeRe: ansiStyles.color.closeRe
  5394. };
  5395. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5396. };
  5397. }
  5398. };
  5399. };
  5400. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  5401. var _ret = _loop2();
  5402. if (_ret === "continue") continue;
  5403. }
  5404. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  5405. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  5406. var _loop3 = function _loop3() {
  5407. var model = _arr3[_i3];
  5408. if (skipModels.has(model)) {
  5409. return "continue";
  5410. }
  5411. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  5412. styles[bgModel] = {
  5413. get() {
  5414. var level = this.level;
  5415. return function () {
  5416. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  5417. var codes = {
  5418. open,
  5419. close: ansiStyles.bgColor.close,
  5420. closeRe: ansiStyles.bgColor.closeRe
  5421. };
  5422. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5423. };
  5424. }
  5425. };
  5426. };
  5427. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  5428. var _ret2 = _loop3();
  5429. if (_ret2 === "continue") continue;
  5430. }
  5431. var proto = Object.defineProperties(function () {}, styles);
  5432. function build(_styles, _empty, key) {
  5433. var builder = function builder() {
  5434. return applyStyle.apply(builder, arguments);
  5435. };
  5436. builder._styles = _styles;
  5437. builder._empty = _empty;
  5438. var self = this;
  5439. Object.defineProperty(builder, 'level', {
  5440. enumerable: true,
  5441. get() {
  5442. return self.level;
  5443. },
  5444. set(level) {
  5445. self.level = level;
  5446. }
  5447. });
  5448. Object.defineProperty(builder, 'enabled', {
  5449. enumerable: true,
  5450. get() {
  5451. return self.enabled;
  5452. },
  5453. set(enabled) {
  5454. self.enabled = enabled;
  5455. }
  5456. }); // See below for fix regarding invisible grey/dim combination on Windows
  5457. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  5458. // no way to create a function with a different prototype
  5459. builder.__proto__ = proto; // eslint-disable-line no-proto
  5460. return builder;
  5461. }
  5462. function applyStyle() {
  5463. // Support varags, but simply cast to string in case there's only one arg
  5464. var args = arguments;
  5465. var argsLen = args.length;
  5466. var str = String(arguments[0]);
  5467. if (argsLen === 0) {
  5468. return '';
  5469. }
  5470. if (argsLen > 1) {
  5471. // Don't slice `arguments`, it prevents V8 optimizations
  5472. for (var a = 1; a < argsLen; a++) {
  5473. str += ' ' + args[a];
  5474. }
  5475. }
  5476. if (!this.enabled || this.level <= 0 || !str) {
  5477. return this._empty ? '' : str;
  5478. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  5479. // see https://github.com/chalk/chalk/issues/58
  5480. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  5481. var originalDim = ansiStyles.dim.open;
  5482. if (isSimpleWindowsTerm && this.hasGrey) {
  5483. ansiStyles.dim.open = '';
  5484. }
  5485. var _iteratorNormalCompletion = true;
  5486. var _didIteratorError = false;
  5487. var _iteratorError = undefined;
  5488. try {
  5489. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5490. var code = _step.value;
  5491. // Replace any instances already present with a re-opening code
  5492. // otherwise only the part of the string until said closing code
  5493. // will be colored, and the rest will simply be 'plain'.
  5494. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  5495. // after next line to fix a bleed issue on macOS
  5496. // https://github.com/chalk/chalk/pull/92
  5497. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  5498. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  5499. } catch (err) {
  5500. _didIteratorError = true;
  5501. _iteratorError = err;
  5502. } finally {
  5503. try {
  5504. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5505. _iterator.return();
  5506. }
  5507. } finally {
  5508. if (_didIteratorError) {
  5509. throw _iteratorError;
  5510. }
  5511. }
  5512. }
  5513. ansiStyles.dim.open = originalDim;
  5514. return str;
  5515. }
  5516. function chalkTag(chalk, strings) {
  5517. if (!Array.isArray(strings)) {
  5518. // If chalk() was called by itself or with a string,
  5519. // return the string itself as a string.
  5520. return [].slice.call(arguments, 1).join(' ');
  5521. }
  5522. var args = [].slice.call(arguments, 2);
  5523. var parts = [strings.raw[0]];
  5524. for (var i = 1; i < strings.length; i++) {
  5525. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  5526. parts.push(String(strings.raw[i]));
  5527. }
  5528. return templates(chalk, parts.join(''));
  5529. }
  5530. Object.defineProperties(Chalk.prototype, styles);
  5531. module.exports = Chalk(); // eslint-disable-line new-cap
  5532. module.exports.supportsColor = stdoutColor;
  5533. module.exports.default = module.exports; // For TypeScript
  5534. });
  5535. var common = createCommonjsModule(function (module, exports) {
  5536. "use strict";
  5537. Object.defineProperty(exports, "__esModule", {
  5538. value: true
  5539. });
  5540. exports.commonDeprecatedHandler = function (keyOrPair, redirectTo, _ref) {
  5541. var descriptor = _ref.descriptor;
  5542. var messages = [`${chalk.default.yellow(typeof keyOrPair === 'string' ? descriptor.key(keyOrPair) : descriptor.pair(keyOrPair))} is deprecated`];
  5543. if (redirectTo) {
  5544. messages.push(`we now treat it as ${chalk.default.blue(typeof redirectTo === 'string' ? descriptor.key(redirectTo) : descriptor.pair(redirectTo))}`);
  5545. }
  5546. return messages.join('; ') + '.';
  5547. };
  5548. });
  5549. unwrapExports(common);
  5550. var deprecated = createCommonjsModule(function (module, exports) {
  5551. "use strict";
  5552. Object.defineProperty(exports, "__esModule", {
  5553. value: true
  5554. });
  5555. tslib_1.__exportStar(common, exports);
  5556. });
  5557. unwrapExports(deprecated);
  5558. var common$2 = createCommonjsModule(function (module, exports) {
  5559. "use strict";
  5560. Object.defineProperty(exports, "__esModule", {
  5561. value: true
  5562. });
  5563. exports.commonInvalidHandler = function (key, value, utils) {
  5564. return [`Invalid ${chalk.default.red(utils.descriptor.key(key))} value.`, `Expected ${chalk.default.blue(utils.schemas[key].expected(utils))},`, `but received ${chalk.default.red(utils.descriptor.value(value))}.`].join(' ');
  5565. };
  5566. });
  5567. unwrapExports(common$2);
  5568. var invalid = createCommonjsModule(function (module, exports) {
  5569. "use strict";
  5570. Object.defineProperty(exports, "__esModule", {
  5571. value: true
  5572. });
  5573. tslib_1.__exportStar(common$2, exports);
  5574. });
  5575. unwrapExports(invalid);
  5576. /* eslint-disable no-nested-ternary */
  5577. var arr = [];
  5578. var charCodeCache = [];
  5579. var leven$1 = function leven(a, b) {
  5580. if (a === b) {
  5581. return 0;
  5582. }
  5583. var swap = a; // Swapping the strings if `a` is longer than `b` so we know which one is the
  5584. // shortest & which one is the longest
  5585. if (a.length > b.length) {
  5586. a = b;
  5587. b = swap;
  5588. }
  5589. var aLen = a.length;
  5590. var bLen = b.length;
  5591. if (aLen === 0) {
  5592. return bLen;
  5593. }
  5594. if (bLen === 0) {
  5595. return aLen;
  5596. } // Performing suffix trimming:
  5597. // We can linearly drop suffix common to both strings since they
  5598. // don't increase distance at all
  5599. // Note: `~-` is the bitwise way to perform a `- 1` operation
  5600. while (aLen > 0 && a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen)) {
  5601. aLen--;
  5602. bLen--;
  5603. }
  5604. if (aLen === 0) {
  5605. return bLen;
  5606. } // Performing prefix trimming
  5607. // We can linearly drop prefix common to both strings since they
  5608. // don't increase distance at all
  5609. var start = 0;
  5610. while (start < aLen && a.charCodeAt(start) === b.charCodeAt(start)) {
  5611. start++;
  5612. }
  5613. aLen -= start;
  5614. bLen -= start;
  5615. if (aLen === 0) {
  5616. return bLen;
  5617. }
  5618. var bCharCode;
  5619. var ret;
  5620. var tmp;
  5621. var tmp2;
  5622. var i = 0;
  5623. var j = 0;
  5624. while (i < aLen) {
  5625. charCodeCache[start + i] = a.charCodeAt(start + i);
  5626. arr[i] = ++i;
  5627. }
  5628. while (j < bLen) {
  5629. bCharCode = b.charCodeAt(start + j);
  5630. tmp = j++;
  5631. ret = j;
  5632. for (i = 0; i < aLen; i++) {
  5633. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  5634. tmp = arr[i];
  5635. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  5636. }
  5637. }
  5638. return ret;
  5639. };
  5640. var leven_1 = createCommonjsModule(function (module, exports) {
  5641. "use strict";
  5642. Object.defineProperty(exports, "__esModule", {
  5643. value: true
  5644. });
  5645. exports.levenUnknownHandler = function (key, value, _ref) {
  5646. var descriptor = _ref.descriptor,
  5647. logger = _ref.logger,
  5648. schemas = _ref.schemas;
  5649. var messages = [`Ignored unknown option ${chalk.default.yellow(descriptor.pair({
  5650. key,
  5651. value
  5652. }))}.`];
  5653. var suggestion = Object.keys(schemas).sort().find(function (knownKey) {
  5654. return leven$1(key, knownKey) < 3;
  5655. });
  5656. if (suggestion) {
  5657. messages.push(`Did you mean ${chalk.default.blue(descriptor.key(suggestion))}?`);
  5658. }
  5659. logger.warn(messages.join(' '));
  5660. };
  5661. });
  5662. unwrapExports(leven_1);
  5663. var unknown = createCommonjsModule(function (module, exports) {
  5664. "use strict";
  5665. Object.defineProperty(exports, "__esModule", {
  5666. value: true
  5667. });
  5668. tslib_1.__exportStar(leven_1, exports);
  5669. });
  5670. unwrapExports(unknown);
  5671. var handlers = createCommonjsModule(function (module, exports) {
  5672. "use strict";
  5673. Object.defineProperty(exports, "__esModule", {
  5674. value: true
  5675. });
  5676. tslib_1.__exportStar(deprecated, exports);
  5677. tslib_1.__exportStar(invalid, exports);
  5678. tslib_1.__exportStar(unknown, exports);
  5679. });
  5680. unwrapExports(handlers);
  5681. var schema = createCommonjsModule(function (module, exports) {
  5682. "use strict";
  5683. Object.defineProperty(exports, "__esModule", {
  5684. value: true
  5685. });
  5686. var HANDLER_KEYS = ['default', 'expected', 'validate', 'deprecated', 'forward', 'redirect', 'overlap', 'preprocess', 'postprocess'];
  5687. function createSchema(SchemaConstructor, parameters) {
  5688. var schema = new SchemaConstructor(parameters);
  5689. var subSchema = Object.create(schema);
  5690. for (var _i = 0; _i < HANDLER_KEYS.length; _i++) {
  5691. var handlerKey = HANDLER_KEYS[_i];
  5692. if (handlerKey in parameters) {
  5693. subSchema[handlerKey] = normalizeHandler(parameters[handlerKey], schema, Schema.prototype[handlerKey].length);
  5694. }
  5695. }
  5696. return subSchema;
  5697. }
  5698. exports.createSchema = createSchema;
  5699. var Schema =
  5700. /*#__PURE__*/
  5701. function () {
  5702. function Schema(parameters) {
  5703. _classCallCheck(this, Schema);
  5704. this.name = parameters.name;
  5705. }
  5706. _createClass(Schema, [{
  5707. key: "default",
  5708. value: function _default(_utils) {
  5709. return undefined;
  5710. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  5711. }, {
  5712. key: "expected",
  5713. value: function expected(_utils) {
  5714. return 'nothing';
  5715. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  5716. }, {
  5717. key: "validate",
  5718. value: function validate(_value, _utils) {
  5719. return false;
  5720. }
  5721. }, {
  5722. key: "deprecated",
  5723. value: function deprecated(_value, _utils) {
  5724. return false;
  5725. }
  5726. }, {
  5727. key: "forward",
  5728. value: function forward(_value, _utils) {
  5729. return undefined;
  5730. }
  5731. }, {
  5732. key: "redirect",
  5733. value: function redirect(_value, _utils) {
  5734. return undefined;
  5735. }
  5736. }, {
  5737. key: "overlap",
  5738. value: function overlap(currentValue, _newValue, _utils) {
  5739. return currentValue;
  5740. }
  5741. }, {
  5742. key: "preprocess",
  5743. value: function preprocess(value, _utils) {
  5744. return value;
  5745. }
  5746. }, {
  5747. key: "postprocess",
  5748. value: function postprocess(value, _utils) {
  5749. return value;
  5750. }
  5751. }], [{
  5752. key: "create",
  5753. value: function create(parameters) {
  5754. // @ts-ignore: https://github.com/Microsoft/TypeScript/issues/5863
  5755. return createSchema(this, parameters);
  5756. }
  5757. }]);
  5758. return Schema;
  5759. }();
  5760. exports.Schema = Schema;
  5761. function normalizeHandler(handler, superSchema, handlerArgumentsLength) {
  5762. return typeof handler === 'function' ? function () {
  5763. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5764. args[_key] = arguments[_key];
  5765. }
  5766. return handler.apply(void 0, _toConsumableArray(args.slice(0, handlerArgumentsLength - 1)).concat([superSchema], _toConsumableArray(args.slice(handlerArgumentsLength - 1))));
  5767. } : function () {
  5768. return handler;
  5769. };
  5770. }
  5771. });
  5772. unwrapExports(schema);
  5773. var alias = createCommonjsModule(function (module, exports) {
  5774. "use strict";
  5775. Object.defineProperty(exports, "__esModule", {
  5776. value: true
  5777. });
  5778. var AliasSchema =
  5779. /*#__PURE__*/
  5780. function (_schema_1$Schema) {
  5781. _inherits(AliasSchema, _schema_1$Schema);
  5782. function AliasSchema(parameters) {
  5783. var _this;
  5784. _classCallCheck(this, AliasSchema);
  5785. _this = _possibleConstructorReturn(this, _getPrototypeOf(AliasSchema).call(this, parameters));
  5786. _this._sourceName = parameters.sourceName;
  5787. return _this;
  5788. }
  5789. _createClass(AliasSchema, [{
  5790. key: "expected",
  5791. value: function expected(utils) {
  5792. return utils.schemas[this._sourceName].expected(utils);
  5793. }
  5794. }, {
  5795. key: "validate",
  5796. value: function validate(value, utils) {
  5797. return utils.schemas[this._sourceName].validate(value, utils);
  5798. }
  5799. }, {
  5800. key: "redirect",
  5801. value: function redirect(_value, _utils) {
  5802. return this._sourceName;
  5803. }
  5804. }]);
  5805. return AliasSchema;
  5806. }(schema.Schema);
  5807. exports.AliasSchema = AliasSchema;
  5808. });
  5809. unwrapExports(alias);
  5810. var any = createCommonjsModule(function (module, exports) {
  5811. "use strict";
  5812. Object.defineProperty(exports, "__esModule", {
  5813. value: true
  5814. });
  5815. var AnySchema =
  5816. /*#__PURE__*/
  5817. function (_schema_1$Schema) {
  5818. _inherits(AnySchema, _schema_1$Schema);
  5819. function AnySchema() {
  5820. _classCallCheck(this, AnySchema);
  5821. return _possibleConstructorReturn(this, _getPrototypeOf(AnySchema).apply(this, arguments));
  5822. }
  5823. _createClass(AnySchema, [{
  5824. key: "expected",
  5825. value: function expected() {
  5826. return 'anything';
  5827. }
  5828. }, {
  5829. key: "validate",
  5830. value: function validate() {
  5831. return true;
  5832. }
  5833. }]);
  5834. return AnySchema;
  5835. }(schema.Schema);
  5836. exports.AnySchema = AnySchema;
  5837. });
  5838. unwrapExports(any);
  5839. var array$2 = createCommonjsModule(function (module, exports) {
  5840. "use strict";
  5841. Object.defineProperty(exports, "__esModule", {
  5842. value: true
  5843. });
  5844. var ArraySchema =
  5845. /*#__PURE__*/
  5846. function (_schema_1$Schema) {
  5847. _inherits(ArraySchema, _schema_1$Schema);
  5848. function ArraySchema(_a) {
  5849. var _this;
  5850. _classCallCheck(this, ArraySchema);
  5851. var valueSchema = _a.valueSchema,
  5852. _a$name = _a.name,
  5853. name = _a$name === void 0 ? valueSchema.name : _a$name,
  5854. handlers = tslib_1.__rest(_a, ["valueSchema", "name"]);
  5855. _this = _possibleConstructorReturn(this, _getPrototypeOf(ArraySchema).call(this, Object.assign({}, handlers, {
  5856. name
  5857. })));
  5858. _this._valueSchema = valueSchema;
  5859. return _this;
  5860. }
  5861. _createClass(ArraySchema, [{
  5862. key: "expected",
  5863. value: function expected(utils) {
  5864. return `an array of ${this._valueSchema.expected(utils)}`;
  5865. }
  5866. }, {
  5867. key: "validate",
  5868. value: function validate(value, utils) {
  5869. if (!Array.isArray(value)) {
  5870. return false;
  5871. }
  5872. var invalidValues = [];
  5873. var _iteratorNormalCompletion = true;
  5874. var _didIteratorError = false;
  5875. var _iteratorError = undefined;
  5876. try {
  5877. for (var _iterator = value[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5878. var subValue = _step.value;
  5879. var subValidateResult = utils.normalizeValidateResult(this._valueSchema.validate(subValue, utils), subValue);
  5880. if (subValidateResult !== true) {
  5881. invalidValues.push(subValidateResult.value);
  5882. }
  5883. }
  5884. } catch (err) {
  5885. _didIteratorError = true;
  5886. _iteratorError = err;
  5887. } finally {
  5888. try {
  5889. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5890. _iterator.return();
  5891. }
  5892. } finally {
  5893. if (_didIteratorError) {
  5894. throw _iteratorError;
  5895. }
  5896. }
  5897. }
  5898. return invalidValues.length === 0 ? true : {
  5899. value: invalidValues
  5900. };
  5901. }
  5902. }, {
  5903. key: "deprecated",
  5904. value: function deprecated(value, utils) {
  5905. var deprecatedResult = [];
  5906. var _iteratorNormalCompletion2 = true;
  5907. var _didIteratorError2 = false;
  5908. var _iteratorError2 = undefined;
  5909. try {
  5910. for (var _iterator2 = value[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5911. var subValue = _step2.value;
  5912. var subDeprecatedResult = utils.normalizeDeprecatedResult(this._valueSchema.deprecated(subValue, utils), subValue);
  5913. if (subDeprecatedResult !== false) {
  5914. deprecatedResult.push.apply(deprecatedResult, _toConsumableArray(subDeprecatedResult.map(function (_ref) {
  5915. var deprecatedValue = _ref.value;
  5916. return {
  5917. value: [deprecatedValue]
  5918. };
  5919. })));
  5920. }
  5921. }
  5922. } catch (err) {
  5923. _didIteratorError2 = true;
  5924. _iteratorError2 = err;
  5925. } finally {
  5926. try {
  5927. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5928. _iterator2.return();
  5929. }
  5930. } finally {
  5931. if (_didIteratorError2) {
  5932. throw _iteratorError2;
  5933. }
  5934. }
  5935. }
  5936. return deprecatedResult;
  5937. }
  5938. }, {
  5939. key: "forward",
  5940. value: function forward(value, utils) {
  5941. var forwardResult = [];
  5942. var _iteratorNormalCompletion3 = true;
  5943. var _didIteratorError3 = false;
  5944. var _iteratorError3 = undefined;
  5945. try {
  5946. for (var _iterator3 = value[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  5947. var subValue = _step3.value;
  5948. var subForwardResult = utils.normalizeForwardResult(this._valueSchema.forward(subValue, utils), subValue);
  5949. forwardResult.push.apply(forwardResult, _toConsumableArray(subForwardResult.map(wrapTransferResult)));
  5950. }
  5951. } catch (err) {
  5952. _didIteratorError3 = true;
  5953. _iteratorError3 = err;
  5954. } finally {
  5955. try {
  5956. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  5957. _iterator3.return();
  5958. }
  5959. } finally {
  5960. if (_didIteratorError3) {
  5961. throw _iteratorError3;
  5962. }
  5963. }
  5964. }
  5965. return forwardResult;
  5966. }
  5967. }, {
  5968. key: "redirect",
  5969. value: function redirect(value, utils) {
  5970. var remain = [];
  5971. var redirect = [];
  5972. var _iteratorNormalCompletion4 = true;
  5973. var _didIteratorError4 = false;
  5974. var _iteratorError4 = undefined;
  5975. try {
  5976. for (var _iterator4 = value[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  5977. var subValue = _step4.value;
  5978. var subRedirectResult = utils.normalizeRedirectResult(this._valueSchema.redirect(subValue, utils), subValue);
  5979. if ('remain' in subRedirectResult) {
  5980. remain.push(subRedirectResult.remain);
  5981. }
  5982. redirect.push.apply(redirect, _toConsumableArray(subRedirectResult.redirect.map(wrapTransferResult)));
  5983. }
  5984. } catch (err) {
  5985. _didIteratorError4 = true;
  5986. _iteratorError4 = err;
  5987. } finally {
  5988. try {
  5989. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  5990. _iterator4.return();
  5991. }
  5992. } finally {
  5993. if (_didIteratorError4) {
  5994. throw _iteratorError4;
  5995. }
  5996. }
  5997. }
  5998. return remain.length === 0 ? {
  5999. redirect
  6000. } : {
  6001. redirect,
  6002. remain
  6003. };
  6004. }
  6005. }, {
  6006. key: "overlap",
  6007. value: function overlap(currentValue, newValue) {
  6008. return currentValue.concat(newValue);
  6009. }
  6010. }]);
  6011. return ArraySchema;
  6012. }(schema.Schema);
  6013. exports.ArraySchema = ArraySchema;
  6014. function wrapTransferResult(_ref2) {
  6015. var from = _ref2.from,
  6016. to = _ref2.to;
  6017. return {
  6018. from: [from],
  6019. to
  6020. };
  6021. }
  6022. });
  6023. unwrapExports(array$2);
  6024. var boolean_1 = createCommonjsModule(function (module, exports) {
  6025. "use strict";
  6026. Object.defineProperty(exports, "__esModule", {
  6027. value: true
  6028. });
  6029. var BooleanSchema =
  6030. /*#__PURE__*/
  6031. function (_schema_1$Schema) {
  6032. _inherits(BooleanSchema, _schema_1$Schema);
  6033. function BooleanSchema() {
  6034. _classCallCheck(this, BooleanSchema);
  6035. return _possibleConstructorReturn(this, _getPrototypeOf(BooleanSchema).apply(this, arguments));
  6036. }
  6037. _createClass(BooleanSchema, [{
  6038. key: "expected",
  6039. value: function expected() {
  6040. return 'true or false';
  6041. }
  6042. }, {
  6043. key: "validate",
  6044. value: function validate(value) {
  6045. return typeof value === 'boolean';
  6046. }
  6047. }]);
  6048. return BooleanSchema;
  6049. }(schema.Schema);
  6050. exports.BooleanSchema = BooleanSchema;
  6051. });
  6052. unwrapExports(boolean_1);
  6053. var utils = createCommonjsModule(function (module, exports) {
  6054. "use strict";
  6055. Object.defineProperty(exports, "__esModule", {
  6056. value: true
  6057. });
  6058. function recordFromArray(array, mainKey) {
  6059. var record = Object.create(null);
  6060. var _iteratorNormalCompletion = true;
  6061. var _didIteratorError = false;
  6062. var _iteratorError = undefined;
  6063. try {
  6064. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6065. var value = _step.value;
  6066. var key = value[mainKey]; // istanbul ignore next
  6067. if (record[key]) {
  6068. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6069. } // @ts-ignore
  6070. record[key] = value;
  6071. }
  6072. } catch (err) {
  6073. _didIteratorError = true;
  6074. _iteratorError = err;
  6075. } finally {
  6076. try {
  6077. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6078. _iterator.return();
  6079. }
  6080. } finally {
  6081. if (_didIteratorError) {
  6082. throw _iteratorError;
  6083. }
  6084. }
  6085. }
  6086. return record;
  6087. }
  6088. exports.recordFromArray = recordFromArray;
  6089. function mapFromArray(array, mainKey) {
  6090. var map = new Map();
  6091. var _iteratorNormalCompletion2 = true;
  6092. var _didIteratorError2 = false;
  6093. var _iteratorError2 = undefined;
  6094. try {
  6095. for (var _iterator2 = array[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6096. var value = _step2.value;
  6097. var key = value[mainKey]; // istanbul ignore next
  6098. if (map.has(key)) {
  6099. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6100. }
  6101. map.set(key, value);
  6102. }
  6103. } catch (err) {
  6104. _didIteratorError2 = true;
  6105. _iteratorError2 = err;
  6106. } finally {
  6107. try {
  6108. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6109. _iterator2.return();
  6110. }
  6111. } finally {
  6112. if (_didIteratorError2) {
  6113. throw _iteratorError2;
  6114. }
  6115. }
  6116. }
  6117. return map;
  6118. }
  6119. exports.mapFromArray = mapFromArray;
  6120. function createAutoChecklist() {
  6121. var map = Object.create(null);
  6122. return function (id) {
  6123. var idString = JSON.stringify(id);
  6124. if (map[idString]) {
  6125. return true;
  6126. }
  6127. map[idString] = true;
  6128. return false;
  6129. };
  6130. }
  6131. exports.createAutoChecklist = createAutoChecklist;
  6132. function partition(array, predicate) {
  6133. var trueArray = [];
  6134. var falseArray = [];
  6135. var _iteratorNormalCompletion3 = true;
  6136. var _didIteratorError3 = false;
  6137. var _iteratorError3 = undefined;
  6138. try {
  6139. for (var _iterator3 = array[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6140. var value = _step3.value;
  6141. if (predicate(value)) {
  6142. trueArray.push(value);
  6143. } else {
  6144. falseArray.push(value);
  6145. }
  6146. }
  6147. } catch (err) {
  6148. _didIteratorError3 = true;
  6149. _iteratorError3 = err;
  6150. } finally {
  6151. try {
  6152. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6153. _iterator3.return();
  6154. }
  6155. } finally {
  6156. if (_didIteratorError3) {
  6157. throw _iteratorError3;
  6158. }
  6159. }
  6160. }
  6161. return [trueArray, falseArray];
  6162. }
  6163. exports.partition = partition;
  6164. function isInt(value) {
  6165. return value === Math.floor(value);
  6166. }
  6167. exports.isInt = isInt;
  6168. function comparePrimitive(a, b) {
  6169. if (a === b) {
  6170. return 0;
  6171. }
  6172. var typeofA = typeof a;
  6173. var typeofB = typeof b;
  6174. var orders = ['undefined', 'object', 'boolean', 'number', 'string'];
  6175. if (typeofA !== typeofB) {
  6176. return orders.indexOf(typeofA) - orders.indexOf(typeofB);
  6177. }
  6178. if (typeofA !== 'string') {
  6179. return Number(a) - Number(b);
  6180. }
  6181. return a.localeCompare(b);
  6182. }
  6183. exports.comparePrimitive = comparePrimitive;
  6184. function normalizeDefaultResult(result) {
  6185. return result === undefined ? {} : result;
  6186. }
  6187. exports.normalizeDefaultResult = normalizeDefaultResult;
  6188. function normalizeValidateResult(result, value) {
  6189. return result === true ? true : result === false ? {
  6190. value
  6191. } : result;
  6192. }
  6193. exports.normalizeValidateResult = normalizeValidateResult;
  6194. function normalizeDeprecatedResult(result, value) {
  6195. var doNotNormalizeTrue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6196. return result === false ? false : result === true ? doNotNormalizeTrue ? true : [{
  6197. value
  6198. }] : 'value' in result ? [result] : result.length === 0 ? false : result;
  6199. }
  6200. exports.normalizeDeprecatedResult = normalizeDeprecatedResult;
  6201. function normalizeTransferResult(result, value) {
  6202. return typeof result === 'string' || 'key' in result ? {
  6203. from: value,
  6204. to: result
  6205. } : 'from' in result ? {
  6206. from: result.from,
  6207. to: result.to
  6208. } : {
  6209. from: value,
  6210. to: result.to
  6211. };
  6212. }
  6213. exports.normalizeTransferResult = normalizeTransferResult;
  6214. function normalizeForwardResult(result, value) {
  6215. return result === undefined ? [] : Array.isArray(result) ? result.map(function (transferResult) {
  6216. return normalizeTransferResult(transferResult, value);
  6217. }) : [normalizeTransferResult(result, value)];
  6218. }
  6219. exports.normalizeForwardResult = normalizeForwardResult;
  6220. function normalizeRedirectResult(result, value) {
  6221. var redirect = normalizeForwardResult(typeof result === 'object' && 'redirect' in result ? result.redirect : result, value);
  6222. return redirect.length === 0 ? {
  6223. remain: value,
  6224. redirect
  6225. } : typeof result === 'object' && 'remain' in result ? {
  6226. remain: result.remain,
  6227. redirect
  6228. } : {
  6229. redirect
  6230. };
  6231. }
  6232. exports.normalizeRedirectResult = normalizeRedirectResult;
  6233. });
  6234. unwrapExports(utils);
  6235. var choice = createCommonjsModule(function (module, exports) {
  6236. "use strict";
  6237. Object.defineProperty(exports, "__esModule", {
  6238. value: true
  6239. });
  6240. var ChoiceSchema =
  6241. /*#__PURE__*/
  6242. function (_schema_1$Schema) {
  6243. _inherits(ChoiceSchema, _schema_1$Schema);
  6244. function ChoiceSchema(parameters) {
  6245. var _this;
  6246. _classCallCheck(this, ChoiceSchema);
  6247. _this = _possibleConstructorReturn(this, _getPrototypeOf(ChoiceSchema).call(this, parameters));
  6248. _this._choices = utils.mapFromArray(parameters.choices.map(function (choice) {
  6249. return choice && typeof choice === 'object' ? choice : {
  6250. value: choice
  6251. };
  6252. }), 'value');
  6253. return _this;
  6254. }
  6255. _createClass(ChoiceSchema, [{
  6256. key: "expected",
  6257. value: function expected(_ref) {
  6258. var _this2 = this;
  6259. var descriptor = _ref.descriptor;
  6260. var choiceValues = Array.from(this._choices.keys()).map(function (value) {
  6261. return _this2._choices.get(value);
  6262. }).filter(function (choiceInfo) {
  6263. return !choiceInfo.deprecated;
  6264. }).map(function (choiceInfo) {
  6265. return choiceInfo.value;
  6266. }).sort(utils.comparePrimitive).map(descriptor.value);
  6267. var head = choiceValues.slice(0, -2);
  6268. var tail = choiceValues.slice(-2);
  6269. return head.concat(tail.join(' or ')).join(', ');
  6270. }
  6271. }, {
  6272. key: "validate",
  6273. value: function validate(value) {
  6274. return this._choices.has(value);
  6275. }
  6276. }, {
  6277. key: "deprecated",
  6278. value: function deprecated(value) {
  6279. var choiceInfo = this._choices.get(value);
  6280. return choiceInfo && choiceInfo.deprecated ? {
  6281. value
  6282. } : false;
  6283. }
  6284. }, {
  6285. key: "forward",
  6286. value: function forward(value) {
  6287. var choiceInfo = this._choices.get(value);
  6288. return choiceInfo ? choiceInfo.forward : undefined;
  6289. }
  6290. }, {
  6291. key: "redirect",
  6292. value: function redirect(value) {
  6293. var choiceInfo = this._choices.get(value);
  6294. return choiceInfo ? choiceInfo.redirect : undefined;
  6295. }
  6296. }]);
  6297. return ChoiceSchema;
  6298. }(schema.Schema);
  6299. exports.ChoiceSchema = ChoiceSchema;
  6300. });
  6301. unwrapExports(choice);
  6302. var number = createCommonjsModule(function (module, exports) {
  6303. "use strict";
  6304. Object.defineProperty(exports, "__esModule", {
  6305. value: true
  6306. });
  6307. var NumberSchema =
  6308. /*#__PURE__*/
  6309. function (_schema_1$Schema) {
  6310. _inherits(NumberSchema, _schema_1$Schema);
  6311. function NumberSchema() {
  6312. _classCallCheck(this, NumberSchema);
  6313. return _possibleConstructorReturn(this, _getPrototypeOf(NumberSchema).apply(this, arguments));
  6314. }
  6315. _createClass(NumberSchema, [{
  6316. key: "expected",
  6317. value: function expected() {
  6318. return 'a number';
  6319. }
  6320. }, {
  6321. key: "validate",
  6322. value: function validate(value, _utils) {
  6323. return typeof value === 'number';
  6324. }
  6325. }]);
  6326. return NumberSchema;
  6327. }(schema.Schema);
  6328. exports.NumberSchema = NumberSchema;
  6329. });
  6330. unwrapExports(number);
  6331. var integer = createCommonjsModule(function (module, exports) {
  6332. "use strict";
  6333. Object.defineProperty(exports, "__esModule", {
  6334. value: true
  6335. });
  6336. var IntegerSchema =
  6337. /*#__PURE__*/
  6338. function (_number_1$NumberSchem) {
  6339. _inherits(IntegerSchema, _number_1$NumberSchem);
  6340. function IntegerSchema() {
  6341. _classCallCheck(this, IntegerSchema);
  6342. return _possibleConstructorReturn(this, _getPrototypeOf(IntegerSchema).apply(this, arguments));
  6343. }
  6344. _createClass(IntegerSchema, [{
  6345. key: "expected",
  6346. value: function expected() {
  6347. return 'an integer';
  6348. }
  6349. }, {
  6350. key: "validate",
  6351. value: function validate(value, utils$$2) {
  6352. return utils$$2.normalizeValidateResult(_get(_getPrototypeOf(IntegerSchema.prototype), "validate", this).call(this, value, utils$$2), value) === true && utils.isInt(value);
  6353. }
  6354. }]);
  6355. return IntegerSchema;
  6356. }(number.NumberSchema);
  6357. exports.IntegerSchema = IntegerSchema;
  6358. });
  6359. unwrapExports(integer);
  6360. var string = createCommonjsModule(function (module, exports) {
  6361. "use strict";
  6362. Object.defineProperty(exports, "__esModule", {
  6363. value: true
  6364. });
  6365. var StringSchema =
  6366. /*#__PURE__*/
  6367. function (_schema_1$Schema) {
  6368. _inherits(StringSchema, _schema_1$Schema);
  6369. function StringSchema() {
  6370. _classCallCheck(this, StringSchema);
  6371. return _possibleConstructorReturn(this, _getPrototypeOf(StringSchema).apply(this, arguments));
  6372. }
  6373. _createClass(StringSchema, [{
  6374. key: "expected",
  6375. value: function expected() {
  6376. return 'a string';
  6377. }
  6378. }, {
  6379. key: "validate",
  6380. value: function validate(value) {
  6381. return typeof value === 'string';
  6382. }
  6383. }]);
  6384. return StringSchema;
  6385. }(schema.Schema);
  6386. exports.StringSchema = StringSchema;
  6387. });
  6388. unwrapExports(string);
  6389. var schemas = createCommonjsModule(function (module, exports) {
  6390. "use strict";
  6391. Object.defineProperty(exports, "__esModule", {
  6392. value: true
  6393. });
  6394. tslib_1.__exportStar(alias, exports);
  6395. tslib_1.__exportStar(any, exports);
  6396. tslib_1.__exportStar(array$2, exports);
  6397. tslib_1.__exportStar(boolean_1, exports);
  6398. tslib_1.__exportStar(choice, exports);
  6399. tslib_1.__exportStar(integer, exports);
  6400. tslib_1.__exportStar(number, exports);
  6401. tslib_1.__exportStar(string, exports);
  6402. });
  6403. unwrapExports(schemas);
  6404. var defaults = createCommonjsModule(function (module, exports) {
  6405. "use strict";
  6406. Object.defineProperty(exports, "__esModule", {
  6407. value: true
  6408. });
  6409. exports.defaultDescriptor = api.apiDescriptor;
  6410. exports.defaultUnknownHandler = leven_1.levenUnknownHandler;
  6411. exports.defaultInvalidHandler = invalid.commonInvalidHandler;
  6412. exports.defaultDeprecatedHandler = common.commonDeprecatedHandler;
  6413. });
  6414. unwrapExports(defaults);
  6415. var normalize$1 = createCommonjsModule(function (module, exports) {
  6416. "use strict";
  6417. Object.defineProperty(exports, "__esModule", {
  6418. value: true
  6419. });
  6420. exports.normalize = function (options, schemas, opts) {
  6421. return new Normalizer(schemas, opts).normalize(options);
  6422. };
  6423. var Normalizer =
  6424. /*#__PURE__*/
  6425. function () {
  6426. function Normalizer(schemas, opts) {
  6427. _classCallCheck(this, Normalizer);
  6428. // istanbul ignore next
  6429. var _ref = opts || {},
  6430. _ref$logger = _ref.logger,
  6431. logger = _ref$logger === void 0 ? console : _ref$logger,
  6432. _ref$descriptor = _ref.descriptor,
  6433. descriptor = _ref$descriptor === void 0 ? defaults.defaultDescriptor : _ref$descriptor,
  6434. _ref$unknown = _ref.unknown,
  6435. unknown = _ref$unknown === void 0 ? defaults.defaultUnknownHandler : _ref$unknown,
  6436. _ref$invalid = _ref.invalid,
  6437. invalid = _ref$invalid === void 0 ? defaults.defaultInvalidHandler : _ref$invalid,
  6438. _ref$deprecated = _ref.deprecated,
  6439. deprecated = _ref$deprecated === void 0 ? defaults.defaultDeprecatedHandler : _ref$deprecated;
  6440. this._utils = {
  6441. descriptor,
  6442. logger:
  6443. /* istanbul ignore next */
  6444. logger || {
  6445. warn: function warn() {}
  6446. },
  6447. schemas: utils.recordFromArray(schemas, 'name'),
  6448. normalizeDefaultResult: utils.normalizeDefaultResult,
  6449. normalizeDeprecatedResult: utils.normalizeDeprecatedResult,
  6450. normalizeForwardResult: utils.normalizeForwardResult,
  6451. normalizeRedirectResult: utils.normalizeRedirectResult,
  6452. normalizeValidateResult: utils.normalizeValidateResult
  6453. };
  6454. this._unknownHandler = unknown;
  6455. this._invalidHandler = invalid;
  6456. this._deprecatedHandler = deprecated;
  6457. this.cleanHistory();
  6458. }
  6459. _createClass(Normalizer, [{
  6460. key: "cleanHistory",
  6461. value: function cleanHistory() {
  6462. this._hasDeprecationWarned = utils.createAutoChecklist();
  6463. }
  6464. }, {
  6465. key: "normalize",
  6466. value: function normalize(options) {
  6467. var _this = this;
  6468. var normalized = {};
  6469. var restOptionsArray = [options];
  6470. var applyNormalization = function applyNormalization() {
  6471. while (restOptionsArray.length !== 0) {
  6472. var currentOptions = restOptionsArray.shift();
  6473. var transferredOptionsArray = _this._applyNormalization(currentOptions, normalized);
  6474. restOptionsArray.push.apply(restOptionsArray, _toConsumableArray(transferredOptionsArray));
  6475. }
  6476. };
  6477. applyNormalization();
  6478. var _arr = Object.keys(this._utils.schemas);
  6479. for (var _i = 0; _i < _arr.length; _i++) {
  6480. var key = _arr[_i];
  6481. var schema = this._utils.schemas[key];
  6482. if (!(key in normalized)) {
  6483. var defaultResult = utils.normalizeDefaultResult(schema.default(this._utils));
  6484. if ('value' in defaultResult) {
  6485. restOptionsArray.push({
  6486. [key]: defaultResult.value
  6487. });
  6488. }
  6489. }
  6490. }
  6491. applyNormalization();
  6492. var _arr2 = Object.keys(this._utils.schemas);
  6493. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  6494. var _key = _arr2[_i2];
  6495. var _schema = this._utils.schemas[_key];
  6496. if (_key in normalized) {
  6497. normalized[_key] = _schema.postprocess(normalized[_key], this._utils);
  6498. }
  6499. }
  6500. return normalized;
  6501. }
  6502. }, {
  6503. key: "_applyNormalization",
  6504. value: function _applyNormalization(options, normalized) {
  6505. var _this2 = this;
  6506. var transferredOptionsArray = [];
  6507. var _utils_1$partition = utils.partition(Object.keys(options), function (key) {
  6508. return key in _this2._utils.schemas;
  6509. }),
  6510. _utils_1$partition2 = _slicedToArray(_utils_1$partition, 2),
  6511. knownOptionNames = _utils_1$partition2[0],
  6512. unknownOptionNames = _utils_1$partition2[1];
  6513. var _iteratorNormalCompletion = true;
  6514. var _didIteratorError = false;
  6515. var _iteratorError = undefined;
  6516. try {
  6517. var _loop = function _loop() {
  6518. var key = _step.value;
  6519. var schema = _this2._utils.schemas[key];
  6520. var value = schema.preprocess(options[key], _this2._utils);
  6521. var validateResult = utils.normalizeValidateResult(schema.validate(value, _this2._utils), value);
  6522. if (validateResult !== true) {
  6523. var invalidValue = validateResult.value;
  6524. var errorMessageOrError = _this2._invalidHandler(key, invalidValue, _this2._utils);
  6525. throw typeof errorMessageOrError === 'string' ? new Error(errorMessageOrError) :
  6526. /* istanbul ignore next*/
  6527. errorMessageOrError;
  6528. }
  6529. var appendTransferredOptions = function appendTransferredOptions(_ref2) {
  6530. var from = _ref2.from,
  6531. to = _ref2.to;
  6532. transferredOptionsArray.push(typeof to === 'string' ? {
  6533. [to]: from
  6534. } : {
  6535. [to.key]: to.value
  6536. });
  6537. };
  6538. var warnDeprecated = function warnDeprecated(_ref3) {
  6539. var currentValue = _ref3.value,
  6540. redirectTo = _ref3.redirectTo;
  6541. var deprecatedResult = utils.normalizeDeprecatedResult(schema.deprecated(currentValue, _this2._utils), value,
  6542. /* doNotNormalizeTrue */
  6543. true);
  6544. if (deprecatedResult === false) {
  6545. return;
  6546. }
  6547. if (deprecatedResult === true) {
  6548. if (!_this2._hasDeprecationWarned(key)) {
  6549. _this2._utils.logger.warn(_this2._deprecatedHandler(key, redirectTo, _this2._utils));
  6550. }
  6551. } else {
  6552. var _iteratorNormalCompletion3 = true;
  6553. var _didIteratorError3 = false;
  6554. var _iteratorError3 = undefined;
  6555. try {
  6556. for (var _iterator3 = deprecatedResult[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6557. var deprecatedValue = _step3.value.value;
  6558. var pair = {
  6559. key,
  6560. value: deprecatedValue
  6561. };
  6562. if (!_this2._hasDeprecationWarned(pair)) {
  6563. var redirectToPair = typeof redirectTo === 'string' ? {
  6564. key: redirectTo,
  6565. value: deprecatedValue
  6566. } : redirectTo;
  6567. _this2._utils.logger.warn(_this2._deprecatedHandler(pair, redirectToPair, _this2._utils));
  6568. }
  6569. }
  6570. } catch (err) {
  6571. _didIteratorError3 = true;
  6572. _iteratorError3 = err;
  6573. } finally {
  6574. try {
  6575. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6576. _iterator3.return();
  6577. }
  6578. } finally {
  6579. if (_didIteratorError3) {
  6580. throw _iteratorError3;
  6581. }
  6582. }
  6583. }
  6584. }
  6585. };
  6586. var forwardResult = utils.normalizeForwardResult(schema.forward(value, _this2._utils), value);
  6587. forwardResult.forEach(appendTransferredOptions);
  6588. var redirectResult = utils.normalizeRedirectResult(schema.redirect(value, _this2._utils), value);
  6589. redirectResult.redirect.forEach(appendTransferredOptions);
  6590. if ('remain' in redirectResult) {
  6591. var remainingValue = redirectResult.remain;
  6592. normalized[key] = key in normalized ? schema.overlap(normalized[key], remainingValue, _this2._utils) : remainingValue;
  6593. warnDeprecated({
  6594. value: remainingValue
  6595. });
  6596. }
  6597. var _iteratorNormalCompletion4 = true;
  6598. var _didIteratorError4 = false;
  6599. var _iteratorError4 = undefined;
  6600. try {
  6601. for (var _iterator4 = redirectResult.redirect[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  6602. var _step4$value = _step4.value,
  6603. from = _step4$value.from,
  6604. to = _step4$value.to;
  6605. warnDeprecated({
  6606. value: from,
  6607. redirectTo: to
  6608. });
  6609. }
  6610. } catch (err) {
  6611. _didIteratorError4 = true;
  6612. _iteratorError4 = err;
  6613. } finally {
  6614. try {
  6615. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  6616. _iterator4.return();
  6617. }
  6618. } finally {
  6619. if (_didIteratorError4) {
  6620. throw _iteratorError4;
  6621. }
  6622. }
  6623. }
  6624. };
  6625. for (var _iterator = knownOptionNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6626. _loop();
  6627. }
  6628. } catch (err) {
  6629. _didIteratorError = true;
  6630. _iteratorError = err;
  6631. } finally {
  6632. try {
  6633. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6634. _iterator.return();
  6635. }
  6636. } finally {
  6637. if (_didIteratorError) {
  6638. throw _iteratorError;
  6639. }
  6640. }
  6641. }
  6642. var _iteratorNormalCompletion2 = true;
  6643. var _didIteratorError2 = false;
  6644. var _iteratorError2 = undefined;
  6645. try {
  6646. for (var _iterator2 = unknownOptionNames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6647. var key = _step2.value;
  6648. var value = options[key];
  6649. var unknownResult = this._unknownHandler(key, value, this._utils);
  6650. if (unknownResult) {
  6651. var _arr3 = Object.keys(unknownResult);
  6652. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  6653. var unknownKey = _arr3[_i3];
  6654. var unknownOption = {
  6655. [unknownKey]: unknownResult[unknownKey]
  6656. };
  6657. if (unknownKey in this._utils.schemas) {
  6658. transferredOptionsArray.push(unknownOption);
  6659. } else {
  6660. Object.assign(normalized, unknownOption);
  6661. }
  6662. }
  6663. }
  6664. }
  6665. } catch (err) {
  6666. _didIteratorError2 = true;
  6667. _iteratorError2 = err;
  6668. } finally {
  6669. try {
  6670. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6671. _iterator2.return();
  6672. }
  6673. } finally {
  6674. if (_didIteratorError2) {
  6675. throw _iteratorError2;
  6676. }
  6677. }
  6678. }
  6679. return transferredOptionsArray;
  6680. }
  6681. }]);
  6682. return Normalizer;
  6683. }();
  6684. exports.Normalizer = Normalizer;
  6685. });
  6686. unwrapExports(normalize$1);
  6687. var lib$1 = createCommonjsModule(function (module, exports) {
  6688. "use strict";
  6689. Object.defineProperty(exports, "__esModule", {
  6690. value: true
  6691. });
  6692. tslib_1.__exportStar(descriptors, exports);
  6693. tslib_1.__exportStar(handlers, exports);
  6694. tslib_1.__exportStar(schemas, exports);
  6695. tslib_1.__exportStar(normalize$1, exports);
  6696. tslib_1.__exportStar(schema, exports);
  6697. });
  6698. unwrapExports(lib$1);
  6699. var hasFlag$3 = function hasFlag(flag, argv) {
  6700. argv = argv || process.argv;
  6701. var terminatorPos = argv.indexOf('--');
  6702. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  6703. var pos = argv.indexOf(prefix + flag);
  6704. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  6705. };
  6706. var supportsColor$1 = createCommonjsModule(function (module) {
  6707. 'use strict';
  6708. var env = process.env;
  6709. var support = function support(level) {
  6710. if (level === 0) {
  6711. return false;
  6712. }
  6713. return {
  6714. level,
  6715. hasBasic: true,
  6716. has256: level >= 2,
  6717. has16m: level >= 3
  6718. };
  6719. };
  6720. var supportLevel = function () {
  6721. if (hasFlag$3('no-color') || hasFlag$3('no-colors') || hasFlag$3('color=false')) {
  6722. return 0;
  6723. }
  6724. if (hasFlag$3('color=16m') || hasFlag$3('color=full') || hasFlag$3('color=truecolor')) {
  6725. return 3;
  6726. }
  6727. if (hasFlag$3('color=256')) {
  6728. return 2;
  6729. }
  6730. if (hasFlag$3('color') || hasFlag$3('colors') || hasFlag$3('color=true') || hasFlag$3('color=always')) {
  6731. return 1;
  6732. }
  6733. if (process.stdout && !process.stdout.isTTY) {
  6734. return 0;
  6735. }
  6736. if (process.platform === 'win32') {
  6737. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  6738. // libuv that enables 256 color output on Windows. Anything earlier and it
  6739. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  6740. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  6741. // release that supports 256 colors.
  6742. var osRelease = os.release().split('.');
  6743. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  6744. return 2;
  6745. }
  6746. return 1;
  6747. }
  6748. if ('CI' in env) {
  6749. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  6750. return sign in env;
  6751. }) || env.CI_NAME === 'codeship') {
  6752. return 1;
  6753. }
  6754. return 0;
  6755. }
  6756. if ('TEAMCITY_VERSION' in env) {
  6757. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  6758. }
  6759. if ('TERM_PROGRAM' in env) {
  6760. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  6761. switch (env.TERM_PROGRAM) {
  6762. case 'iTerm.app':
  6763. return version >= 3 ? 3 : 2;
  6764. case 'Hyper':
  6765. return 3;
  6766. case 'Apple_Terminal':
  6767. return 2;
  6768. // No default
  6769. }
  6770. }
  6771. if (/-256(color)?$/i.test(env.TERM)) {
  6772. return 2;
  6773. }
  6774. if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  6775. return 1;
  6776. }
  6777. if ('COLORTERM' in env) {
  6778. return 1;
  6779. }
  6780. if (env.TERM === 'dumb') {
  6781. return 0;
  6782. }
  6783. return 0;
  6784. }();
  6785. if ('FORCE_COLOR' in env) {
  6786. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : supportLevel || 1;
  6787. }
  6788. module.exports = process && support(supportLevel);
  6789. });
  6790. var templates$2 = createCommonjsModule(function (module) {
  6791. 'use strict';
  6792. var TEMPLATE_REGEX = /(?:\\(u[a-f0-9]{4}|x[a-f0-9]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  6793. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  6794. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  6795. var ESCAPE_REGEX = /\\(u[0-9a-f]{4}|x[0-9a-f]{2}|.)|([^\\])/gi;
  6796. var ESCAPES = {
  6797. n: '\n',
  6798. r: '\r',
  6799. t: '\t',
  6800. b: '\b',
  6801. f: '\f',
  6802. v: '\v',
  6803. 0: '\0',
  6804. '\\': '\\',
  6805. e: '\u001b',
  6806. a: '\u0007'
  6807. };
  6808. function unescape(c) {
  6809. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  6810. return String.fromCharCode(parseInt(c.slice(1), 16));
  6811. }
  6812. return ESCAPES[c] || c;
  6813. }
  6814. function parseArguments(name, args) {
  6815. var results = [];
  6816. var chunks = args.trim().split(/\s*,\s*/g);
  6817. var matches;
  6818. var _iteratorNormalCompletion = true;
  6819. var _didIteratorError = false;
  6820. var _iteratorError = undefined;
  6821. try {
  6822. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6823. var chunk = _step.value;
  6824. if (!isNaN(chunk)) {
  6825. results.push(Number(chunk));
  6826. } else if (matches = chunk.match(STRING_REGEX)) {
  6827. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  6828. return escape ? unescape(escape) : chr;
  6829. }));
  6830. } else {
  6831. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  6832. }
  6833. }
  6834. } catch (err) {
  6835. _didIteratorError = true;
  6836. _iteratorError = err;
  6837. } finally {
  6838. try {
  6839. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6840. _iterator.return();
  6841. }
  6842. } finally {
  6843. if (_didIteratorError) {
  6844. throw _iteratorError;
  6845. }
  6846. }
  6847. }
  6848. return results;
  6849. }
  6850. function parseStyle(style) {
  6851. STYLE_REGEX.lastIndex = 0;
  6852. var results = [];
  6853. var matches;
  6854. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  6855. var name = matches[1];
  6856. if (matches[2]) {
  6857. var args = parseArguments(name, matches[2]);
  6858. results.push([name].concat(args));
  6859. } else {
  6860. results.push([name]);
  6861. }
  6862. }
  6863. return results;
  6864. }
  6865. function buildStyle(chalk, styles) {
  6866. var enabled = {};
  6867. var _iteratorNormalCompletion2 = true;
  6868. var _didIteratorError2 = false;
  6869. var _iteratorError2 = undefined;
  6870. try {
  6871. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6872. var layer = _step2.value;
  6873. var _iteratorNormalCompletion3 = true;
  6874. var _didIteratorError3 = false;
  6875. var _iteratorError3 = undefined;
  6876. try {
  6877. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6878. var style = _step3.value;
  6879. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  6880. }
  6881. } catch (err) {
  6882. _didIteratorError3 = true;
  6883. _iteratorError3 = err;
  6884. } finally {
  6885. try {
  6886. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6887. _iterator3.return();
  6888. }
  6889. } finally {
  6890. if (_didIteratorError3) {
  6891. throw _iteratorError3;
  6892. }
  6893. }
  6894. }
  6895. }
  6896. } catch (err) {
  6897. _didIteratorError2 = true;
  6898. _iteratorError2 = err;
  6899. } finally {
  6900. try {
  6901. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6902. _iterator2.return();
  6903. }
  6904. } finally {
  6905. if (_didIteratorError2) {
  6906. throw _iteratorError2;
  6907. }
  6908. }
  6909. }
  6910. var current = chalk;
  6911. var _arr = Object.keys(enabled);
  6912. for (var _i = 0; _i < _arr.length; _i++) {
  6913. var styleName = _arr[_i];
  6914. if (Array.isArray(enabled[styleName])) {
  6915. if (!(styleName in current)) {
  6916. throw new Error(`Unknown Chalk style: ${styleName}`);
  6917. }
  6918. if (enabled[styleName].length > 0) {
  6919. current = current[styleName].apply(current, enabled[styleName]);
  6920. } else {
  6921. current = current[styleName];
  6922. }
  6923. }
  6924. }
  6925. return current;
  6926. }
  6927. module.exports = function (chalk, tmp) {
  6928. var styles = [];
  6929. var chunks = [];
  6930. var chunk = []; // eslint-disable-next-line max-params
  6931. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  6932. if (escapeChar) {
  6933. chunk.push(unescape(escapeChar));
  6934. } else if (style) {
  6935. var str = chunk.join('');
  6936. chunk = [];
  6937. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  6938. styles.push({
  6939. inverse,
  6940. styles: parseStyle(style)
  6941. });
  6942. } else if (close) {
  6943. if (styles.length === 0) {
  6944. throw new Error('Found extraneous } in Chalk template literal');
  6945. }
  6946. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  6947. chunk = [];
  6948. styles.pop();
  6949. } else {
  6950. chunk.push(chr);
  6951. }
  6952. });
  6953. chunks.push(chunk.join(''));
  6954. if (styles.length > 0) {
  6955. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  6956. throw new Error(errMsg);
  6957. }
  6958. return chunks.join('');
  6959. };
  6960. });
  6961. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  6962. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  6963. var skipModels = new Set(['gray']);
  6964. var styles = Object.create(null);
  6965. function applyOptions(obj, options) {
  6966. options = options || {}; // Detect level if not set manually
  6967. var scLevel = supportsColor$1 ? supportsColor$1.level : 0;
  6968. obj.level = options.level === undefined ? scLevel : options.level;
  6969. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  6970. }
  6971. function Chalk(options) {
  6972. // We check for this.template here since calling `chalk.constructor()`
  6973. // by itself will have a `this` of a previously constructed chalk object
  6974. if (!this || !(this instanceof Chalk) || this.template) {
  6975. var _chalk = {};
  6976. applyOptions(_chalk, options);
  6977. _chalk.template = function () {
  6978. var args = [].slice.call(arguments);
  6979. return chalkTag.apply(null, [_chalk.template].concat(args));
  6980. };
  6981. Object.setPrototypeOf(_chalk, Chalk.prototype);
  6982. Object.setPrototypeOf(_chalk.template, _chalk);
  6983. _chalk.template.constructor = Chalk;
  6984. return _chalk.template;
  6985. }
  6986. applyOptions(this, options);
  6987. } // Use bright blue on Windows as the normal blue color is illegible
  6988. if (isSimpleWindowsTerm) {
  6989. ansiStyles.blue.open = '\u001B[94m';
  6990. }
  6991. var _arr = Object.keys(ansiStyles);
  6992. var _loop = function _loop() {
  6993. var key = _arr[_i];
  6994. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  6995. styles[key] = {
  6996. get() {
  6997. var codes = ansiStyles[key];
  6998. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
  6999. }
  7000. };
  7001. };
  7002. for (var _i = 0; _i < _arr.length; _i++) {
  7003. _loop();
  7004. }
  7005. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  7006. var _arr2 = Object.keys(ansiStyles.color.ansi);
  7007. var _loop2 = function _loop2() {
  7008. var model = _arr2[_i2];
  7009. if (skipModels.has(model)) {
  7010. return "continue";
  7011. }
  7012. styles[model] = {
  7013. get() {
  7014. var level = this.level;
  7015. return function () {
  7016. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  7017. var codes = {
  7018. open,
  7019. close: ansiStyles.color.close,
  7020. closeRe: ansiStyles.color.closeRe
  7021. };
  7022. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  7023. };
  7024. }
  7025. };
  7026. };
  7027. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  7028. var _ret = _loop2();
  7029. if (_ret === "continue") continue;
  7030. }
  7031. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  7032. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  7033. var _loop3 = function _loop3() {
  7034. var model = _arr3[_i3];
  7035. if (skipModels.has(model)) {
  7036. return "continue";
  7037. }
  7038. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  7039. styles[bgModel] = {
  7040. get() {
  7041. var level = this.level;
  7042. return function () {
  7043. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  7044. var codes = {
  7045. open,
  7046. close: ansiStyles.bgColor.close,
  7047. closeRe: ansiStyles.bgColor.closeRe
  7048. };
  7049. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  7050. };
  7051. }
  7052. };
  7053. };
  7054. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  7055. var _ret2 = _loop3();
  7056. if (_ret2 === "continue") continue;
  7057. }
  7058. var proto = Object.defineProperties(function () {}, styles);
  7059. function build(_styles, key) {
  7060. var builder = function builder() {
  7061. return applyStyle.apply(builder, arguments);
  7062. };
  7063. builder._styles = _styles;
  7064. var self = this;
  7065. Object.defineProperty(builder, 'level', {
  7066. enumerable: true,
  7067. get() {
  7068. return self.level;
  7069. },
  7070. set(level) {
  7071. self.level = level;
  7072. }
  7073. });
  7074. Object.defineProperty(builder, 'enabled', {
  7075. enumerable: true,
  7076. get() {
  7077. return self.enabled;
  7078. },
  7079. set(enabled) {
  7080. self.enabled = enabled;
  7081. }
  7082. }); // See below for fix regarding invisible grey/dim combination on Windows
  7083. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  7084. // no way to create a function with a different prototype
  7085. builder.__proto__ = proto; // eslint-disable-line no-proto
  7086. return builder;
  7087. }
  7088. function applyStyle() {
  7089. // Support varags, but simply cast to string in case there's only one arg
  7090. var args = arguments;
  7091. var argsLen = args.length;
  7092. var str = String(arguments[0]);
  7093. if (argsLen === 0) {
  7094. return '';
  7095. }
  7096. if (argsLen > 1) {
  7097. // Don't slice `arguments`, it prevents V8 optimizations
  7098. for (var a = 1; a < argsLen; a++) {
  7099. str += ' ' + args[a];
  7100. }
  7101. }
  7102. if (!this.enabled || this.level <= 0 || !str) {
  7103. return str;
  7104. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  7105. // see https://github.com/chalk/chalk/issues/58
  7106. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  7107. var originalDim = ansiStyles.dim.open;
  7108. if (isSimpleWindowsTerm && this.hasGrey) {
  7109. ansiStyles.dim.open = '';
  7110. }
  7111. var _iteratorNormalCompletion = true;
  7112. var _didIteratorError = false;
  7113. var _iteratorError = undefined;
  7114. try {
  7115. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7116. var code = _step.value;
  7117. // Replace any instances already present with a re-opening code
  7118. // otherwise only the part of the string until said closing code
  7119. // will be colored, and the rest will simply be 'plain'.
  7120. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  7121. // after next line to fix a bleed issue on macOS
  7122. // https://github.com/chalk/chalk/pull/92
  7123. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  7124. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  7125. } catch (err) {
  7126. _didIteratorError = true;
  7127. _iteratorError = err;
  7128. } finally {
  7129. try {
  7130. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7131. _iterator.return();
  7132. }
  7133. } finally {
  7134. if (_didIteratorError) {
  7135. throw _iteratorError;
  7136. }
  7137. }
  7138. }
  7139. ansiStyles.dim.open = originalDim;
  7140. return str;
  7141. }
  7142. function chalkTag(chalk, strings) {
  7143. if (!Array.isArray(strings)) {
  7144. // If chalk() was called by itself or with a string,
  7145. // return the string itself as a string.
  7146. return [].slice.call(arguments, 1).join(' ');
  7147. }
  7148. var args = [].slice.call(arguments, 2);
  7149. var parts = [strings.raw[0]];
  7150. for (var i = 1; i < strings.length; i++) {
  7151. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  7152. parts.push(String(strings.raw[i]));
  7153. }
  7154. return templates$2(chalk, parts.join(''));
  7155. }
  7156. Object.defineProperties(Chalk.prototype, styles);
  7157. var chalk$2 = Chalk(); // eslint-disable-line new-cap
  7158. var supportsColor_1$2 = supportsColor$1;
  7159. chalk$2.supportsColor = supportsColor_1$2;
  7160. var cliDescriptor = {
  7161. key: function key(_key) {
  7162. return _key.length === 1 ? `-${_key}` : `--${_key}`;
  7163. },
  7164. value: function value(_value) {
  7165. return lib$1.apiDescriptor.value(_value);
  7166. },
  7167. pair: function pair(_ref) {
  7168. var key = _ref.key,
  7169. value = _ref.value;
  7170. return value === false ? `--no-${key}` : value === true ? cliDescriptor.key(key) : value === "" ? `${cliDescriptor.key(key)} without an argument` : `${cliDescriptor.key(key)}=${value}`;
  7171. }
  7172. };
  7173. var FlagSchema =
  7174. /*#__PURE__*/
  7175. function (_vnopts$ChoiceSchema) {
  7176. _inherits(FlagSchema, _vnopts$ChoiceSchema);
  7177. function FlagSchema(_ref2) {
  7178. var _this;
  7179. var name = _ref2.name,
  7180. flags = _ref2.flags;
  7181. _classCallCheck(this, FlagSchema);
  7182. _this = _possibleConstructorReturn(this, _getPrototypeOf(FlagSchema).call(this, {
  7183. name,
  7184. choices: flags
  7185. }));
  7186. _this._flags = flags.slice().sort();
  7187. return _this;
  7188. }
  7189. _createClass(FlagSchema, [{
  7190. key: "preprocess",
  7191. value: function preprocess(value, utils) {
  7192. if (typeof value === "string" && value.length !== 0 && this._flags.indexOf(value) === -1) {
  7193. var suggestion = this._flags.find(function (flag) {
  7194. return leven$1(flag, value) < 3;
  7195. });
  7196. if (suggestion) {
  7197. utils.logger.warn([`Unknown flag ${chalk$2.yellow(utils.descriptor.value(value))},`, `did you mean ${chalk$2.blue(utils.descriptor.value(suggestion))}?`].join(" "));
  7198. return suggestion;
  7199. }
  7200. }
  7201. return value;
  7202. }
  7203. }, {
  7204. key: "expected",
  7205. value: function expected() {
  7206. return "a flag";
  7207. }
  7208. }]);
  7209. return FlagSchema;
  7210. }(lib$1.ChoiceSchema);
  7211. var hasDeprecationWarned;
  7212. function normalizeOptions$1(options, optionInfos) {
  7213. var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  7214. logger = _ref3.logger,
  7215. _ref3$isCLI = _ref3.isCLI,
  7216. isCLI = _ref3$isCLI === void 0 ? false : _ref3$isCLI,
  7217. _ref3$passThrough = _ref3.passThrough,
  7218. passThrough = _ref3$passThrough === void 0 ? false : _ref3$passThrough;
  7219. var unknown = !passThrough ? lib$1.levenUnknownHandler : Array.isArray(passThrough) ? function (key, value) {
  7220. return passThrough.indexOf(key) === -1 ? undefined : {
  7221. [key]: value
  7222. };
  7223. } : function (key, value) {
  7224. return {
  7225. [key]: value
  7226. };
  7227. };
  7228. var descriptor = isCLI ? cliDescriptor : lib$1.apiDescriptor;
  7229. var schemas = optionInfosToSchemas(optionInfos, {
  7230. isCLI
  7231. });
  7232. var normalizer = new lib$1.Normalizer(schemas, {
  7233. logger,
  7234. unknown,
  7235. descriptor
  7236. });
  7237. var shouldSuppressDuplicateDeprecationWarnings = logger !== false;
  7238. if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) {
  7239. normalizer._hasDeprecationWarned = hasDeprecationWarned;
  7240. }
  7241. var normalized = normalizer.normalize(options);
  7242. if (shouldSuppressDuplicateDeprecationWarnings) {
  7243. hasDeprecationWarned = normalizer._hasDeprecationWarned;
  7244. }
  7245. return normalized;
  7246. }
  7247. function optionInfosToSchemas(optionInfos, _ref4) {
  7248. var isCLI = _ref4.isCLI;
  7249. var schemas = [];
  7250. if (isCLI) {
  7251. schemas.push(lib$1.AnySchema.create({
  7252. name: "_"
  7253. }));
  7254. }
  7255. var _iteratorNormalCompletion = true;
  7256. var _didIteratorError = false;
  7257. var _iteratorError = undefined;
  7258. try {
  7259. for (var _iterator = optionInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7260. var optionInfo = _step.value;
  7261. schemas.push(optionInfoToSchema(optionInfo, {
  7262. isCLI,
  7263. optionInfos
  7264. }));
  7265. if (optionInfo.alias && isCLI) {
  7266. schemas.push(lib$1.AliasSchema.create({
  7267. name: optionInfo.alias,
  7268. sourceName: optionInfo.name
  7269. }));
  7270. }
  7271. }
  7272. } catch (err) {
  7273. _didIteratorError = true;
  7274. _iteratorError = err;
  7275. } finally {
  7276. try {
  7277. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7278. _iterator.return();
  7279. }
  7280. } finally {
  7281. if (_didIteratorError) {
  7282. throw _iteratorError;
  7283. }
  7284. }
  7285. }
  7286. return schemas;
  7287. }
  7288. function optionInfoToSchema(optionInfo, _ref5) {
  7289. var isCLI = _ref5.isCLI,
  7290. optionInfos = _ref5.optionInfos;
  7291. var SchemaConstructor;
  7292. var parameters = {
  7293. name: optionInfo.name
  7294. };
  7295. var handlers = {};
  7296. switch (optionInfo.type) {
  7297. case "int":
  7298. SchemaConstructor = lib$1.IntegerSchema;
  7299. if (isCLI) {
  7300. parameters.preprocess = function (value) {
  7301. return Number(value);
  7302. };
  7303. }
  7304. break;
  7305. case "choice":
  7306. SchemaConstructor = lib$1.ChoiceSchema;
  7307. parameters.choices = optionInfo.choices.map(function (choiceInfo) {
  7308. return typeof choiceInfo === "object" && choiceInfo.redirect ? Object.assign({}, choiceInfo, {
  7309. redirect: {
  7310. to: {
  7311. key: optionInfo.name,
  7312. value: choiceInfo.redirect
  7313. }
  7314. }
  7315. }) : choiceInfo;
  7316. });
  7317. break;
  7318. case "boolean":
  7319. SchemaConstructor = lib$1.BooleanSchema;
  7320. break;
  7321. case "flag":
  7322. SchemaConstructor = FlagSchema;
  7323. parameters.flags = optionInfos.map(function (optionInfo) {
  7324. return [].concat(optionInfo.alias || [], optionInfo.description ? optionInfo.name : [], optionInfo.oppositeDescription ? `no-${optionInfo.name}` : []);
  7325. }).reduce(function (a, b) {
  7326. return a.concat(b);
  7327. }, []);
  7328. break;
  7329. case "path":
  7330. SchemaConstructor = lib$1.StringSchema;
  7331. break;
  7332. default:
  7333. throw new Error(`Unexpected type ${optionInfo.type}`);
  7334. }
  7335. if (optionInfo.exception) {
  7336. parameters.validate = function (value, schema, utils) {
  7337. return optionInfo.exception(value) || schema.validate(value, utils);
  7338. };
  7339. } else {
  7340. parameters.validate = function (value, schema, utils) {
  7341. return value === undefined || schema.validate(value, utils);
  7342. };
  7343. }
  7344. if (optionInfo.redirect) {
  7345. handlers.redirect = function (value) {
  7346. return !value ? undefined : {
  7347. to: {
  7348. key: optionInfo.redirect.option,
  7349. value: optionInfo.redirect.value
  7350. }
  7351. };
  7352. };
  7353. }
  7354. if (optionInfo.deprecated) {
  7355. handlers.deprecated = true;
  7356. } // allow CLI overriding, e.g., prettier package.json --tab-width 1 --tab-width 2
  7357. if (isCLI && !optionInfo.array) {
  7358. var originalPreprocess = parameters.preprocess || function (x) {
  7359. return x;
  7360. };
  7361. parameters.preprocess = function (value, schema, utils) {
  7362. return schema.preprocess(originalPreprocess(Array.isArray(value) ? value[value.length - 1] : value), utils);
  7363. };
  7364. }
  7365. return optionInfo.array ? lib$1.ArraySchema.create(Object.assign(isCLI ? {
  7366. preprocess: function preprocess(v) {
  7367. return [].concat(v);
  7368. }
  7369. } : {}, handlers, {
  7370. valueSchema: SchemaConstructor.create(parameters)
  7371. })) : SchemaConstructor.create(Object.assign({}, parameters, handlers));
  7372. }
  7373. function normalizeApiOptions(options, optionInfos, opts) {
  7374. return normalizeOptions$1(options, optionInfos, opts);
  7375. }
  7376. function normalizeCliOptions(options, optionInfos, opts) {
  7377. return normalizeOptions$1(options, optionInfos, Object.assign({
  7378. isCLI: true
  7379. }, opts));
  7380. }
  7381. var optionsNormalizer = {
  7382. normalizeApiOptions,
  7383. normalizeCliOptions
  7384. };
  7385. var getLast = function getLast(arr) {
  7386. return arr.length > 0 ? arr[arr.length - 1] : null;
  7387. };
  7388. function locStart$1(node, opts) {
  7389. opts = opts || {}; // Handle nodes with decorators. They should start at the first decorator
  7390. if (!opts.ignoreDecorators && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0) {
  7391. return locStart$1(node.declaration.decorators[0]);
  7392. }
  7393. if (!opts.ignoreDecorators && node.decorators && node.decorators.length > 0) {
  7394. return locStart$1(node.decorators[0]);
  7395. }
  7396. if (node.__location) {
  7397. return node.__location.startOffset;
  7398. }
  7399. if (node.range) {
  7400. return node.range[0];
  7401. }
  7402. if (typeof node.start === "number") {
  7403. return node.start;
  7404. }
  7405. if (node.loc) {
  7406. return node.loc.start;
  7407. }
  7408. return null;
  7409. }
  7410. function locEnd$1(node) {
  7411. var endNode = node.nodes && getLast(node.nodes);
  7412. if (endNode && node.source && !node.source.end) {
  7413. node = endNode;
  7414. }
  7415. if (node.__location) {
  7416. return node.__location.endOffset;
  7417. }
  7418. var loc = node.range ? node.range[1] : typeof node.end === "number" ? node.end : null;
  7419. if (node.typeAnnotation) {
  7420. return Math.max(loc, locEnd$1(node.typeAnnotation));
  7421. }
  7422. if (node.loc && !loc) {
  7423. return node.loc.end;
  7424. }
  7425. return loc;
  7426. }
  7427. var loc = {
  7428. locStart: locStart$1,
  7429. locEnd: locEnd$1
  7430. };
  7431. var jsTokens = createCommonjsModule(function (module, exports) {
  7432. // Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
  7433. // License: MIT. (See LICENSE.)
  7434. Object.defineProperty(exports, "__esModule", {
  7435. value: true
  7436. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  7437. // (run `npm run build`).
  7438. exports.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
  7439. exports.matchToToken = function (match) {
  7440. var token = {
  7441. type: "invalid",
  7442. value: match[0],
  7443. closed: undefined
  7444. };
  7445. 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";
  7446. return token;
  7447. };
  7448. });
  7449. unwrapExports(jsTokens);
  7450. var ast = createCommonjsModule(function (module) {
  7451. /*
  7452. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7453. Redistribution and use in source and binary forms, with or without
  7454. modification, are permitted provided that the following conditions are met:
  7455. * Redistributions of source code must retain the above copyright
  7456. notice, this list of conditions and the following disclaimer.
  7457. * Redistributions in binary form must reproduce the above copyright
  7458. notice, this list of conditions and the following disclaimer in the
  7459. documentation and/or other materials provided with the distribution.
  7460. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  7461. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7462. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7463. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7464. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7465. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7466. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7467. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7468. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7469. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7470. */
  7471. (function () {
  7472. 'use strict';
  7473. function isExpression(node) {
  7474. if (node == null) {
  7475. return false;
  7476. }
  7477. switch (node.type) {
  7478. case 'ArrayExpression':
  7479. case 'AssignmentExpression':
  7480. case 'BinaryExpression':
  7481. case 'CallExpression':
  7482. case 'ConditionalExpression':
  7483. case 'FunctionExpression':
  7484. case 'Identifier':
  7485. case 'Literal':
  7486. case 'LogicalExpression':
  7487. case 'MemberExpression':
  7488. case 'NewExpression':
  7489. case 'ObjectExpression':
  7490. case 'SequenceExpression':
  7491. case 'ThisExpression':
  7492. case 'UnaryExpression':
  7493. case 'UpdateExpression':
  7494. return true;
  7495. }
  7496. return false;
  7497. }
  7498. function isIterationStatement(node) {
  7499. if (node == null) {
  7500. return false;
  7501. }
  7502. switch (node.type) {
  7503. case 'DoWhileStatement':
  7504. case 'ForInStatement':
  7505. case 'ForStatement':
  7506. case 'WhileStatement':
  7507. return true;
  7508. }
  7509. return false;
  7510. }
  7511. function isStatement(node) {
  7512. if (node == null) {
  7513. return false;
  7514. }
  7515. switch (node.type) {
  7516. case 'BlockStatement':
  7517. case 'BreakStatement':
  7518. case 'ContinueStatement':
  7519. case 'DebuggerStatement':
  7520. case 'DoWhileStatement':
  7521. case 'EmptyStatement':
  7522. case 'ExpressionStatement':
  7523. case 'ForInStatement':
  7524. case 'ForStatement':
  7525. case 'IfStatement':
  7526. case 'LabeledStatement':
  7527. case 'ReturnStatement':
  7528. case 'SwitchStatement':
  7529. case 'ThrowStatement':
  7530. case 'TryStatement':
  7531. case 'VariableDeclaration':
  7532. case 'WhileStatement':
  7533. case 'WithStatement':
  7534. return true;
  7535. }
  7536. return false;
  7537. }
  7538. function isSourceElement(node) {
  7539. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  7540. }
  7541. function trailingStatement(node) {
  7542. switch (node.type) {
  7543. case 'IfStatement':
  7544. if (node.alternate != null) {
  7545. return node.alternate;
  7546. }
  7547. return node.consequent;
  7548. case 'LabeledStatement':
  7549. case 'ForStatement':
  7550. case 'ForInStatement':
  7551. case 'WhileStatement':
  7552. case 'WithStatement':
  7553. return node.body;
  7554. }
  7555. return null;
  7556. }
  7557. function isProblematicIfStatement(node) {
  7558. var current;
  7559. if (node.type !== 'IfStatement') {
  7560. return false;
  7561. }
  7562. if (node.alternate == null) {
  7563. return false;
  7564. }
  7565. current = node.consequent;
  7566. do {
  7567. if (current.type === 'IfStatement') {
  7568. if (current.alternate == null) {
  7569. return true;
  7570. }
  7571. }
  7572. current = trailingStatement(current);
  7573. } while (current);
  7574. return false;
  7575. }
  7576. module.exports = {
  7577. isExpression: isExpression,
  7578. isStatement: isStatement,
  7579. isIterationStatement: isIterationStatement,
  7580. isSourceElement: isSourceElement,
  7581. isProblematicIfStatement: isProblematicIfStatement,
  7582. trailingStatement: trailingStatement
  7583. };
  7584. })();
  7585. /* vim: set sw=4 ts=4 et tw=80 : */
  7586. });
  7587. var code = createCommonjsModule(function (module) {
  7588. /*
  7589. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  7590. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  7591. Redistribution and use in source and binary forms, with or without
  7592. modification, are permitted provided that the following conditions are met:
  7593. * Redistributions of source code must retain the above copyright
  7594. notice, this list of conditions and the following disclaimer.
  7595. * Redistributions in binary form must reproduce the above copyright
  7596. notice, this list of conditions and the following disclaimer in the
  7597. documentation and/or other materials provided with the distribution.
  7598. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7599. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7600. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7601. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7602. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7603. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7604. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7605. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7606. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7607. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7608. */
  7609. (function () {
  7610. 'use strict';
  7611. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch; // See `tools/generate-identifier-regex.js`.
  7612. ES5Regex = {
  7613. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierStart:
  7614. 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]/,
  7615. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierPart:
  7616. 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]/
  7617. };
  7618. ES6Regex = {
  7619. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  7620. 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]/,
  7621. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  7622. 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]/
  7623. };
  7624. function isDecimalDigit(ch) {
  7625. return 0x30 <= ch && ch <= 0x39; // 0..9
  7626. }
  7627. function isHexDigit(ch) {
  7628. return 0x30 <= ch && ch <= 0x39 || // 0..9
  7629. 0x61 <= ch && ch <= 0x66 || // a..f
  7630. 0x41 <= ch && ch <= 0x46; // A..F
  7631. }
  7632. function isOctalDigit(ch) {
  7633. return ch >= 0x30 && ch <= 0x37; // 0..7
  7634. } // 7.2 White Space
  7635. NON_ASCII_WHITESPACES = [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF];
  7636. function isWhiteSpace(ch) {
  7637. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 || ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  7638. } // 7.3 Line Terminators
  7639. function isLineTerminator(ch) {
  7640. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  7641. } // 7.6 Identifier Names and Identifiers
  7642. function fromCodePoint(cp) {
  7643. if (cp <= 0xFFFF) {
  7644. return String.fromCharCode(cp);
  7645. }
  7646. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  7647. var cu2 = String.fromCharCode((cp - 0x10000) % 0x400 + 0xDC00);
  7648. return cu1 + cu2;
  7649. }
  7650. IDENTIFIER_START = new Array(0x80);
  7651. for (ch = 0; ch < 0x80; ++ch) {
  7652. IDENTIFIER_START[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  7653. ch >= 0x41 && ch <= 0x5A || // A..Z
  7654. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7655. }
  7656. IDENTIFIER_PART = new Array(0x80);
  7657. for (ch = 0; ch < 0x80; ++ch) {
  7658. IDENTIFIER_PART[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  7659. ch >= 0x41 && ch <= 0x5A || // A..Z
  7660. ch >= 0x30 && ch <= 0x39 || // 0..9
  7661. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7662. }
  7663. function isIdentifierStartES5(ch) {
  7664. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7665. }
  7666. function isIdentifierPartES5(ch) {
  7667. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7668. }
  7669. function isIdentifierStartES6(ch) {
  7670. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7671. }
  7672. function isIdentifierPartES6(ch) {
  7673. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7674. }
  7675. module.exports = {
  7676. isDecimalDigit: isDecimalDigit,
  7677. isHexDigit: isHexDigit,
  7678. isOctalDigit: isOctalDigit,
  7679. isWhiteSpace: isWhiteSpace,
  7680. isLineTerminator: isLineTerminator,
  7681. isIdentifierStartES5: isIdentifierStartES5,
  7682. isIdentifierPartES5: isIdentifierPartES5,
  7683. isIdentifierStartES6: isIdentifierStartES6,
  7684. isIdentifierPartES6: isIdentifierPartES6
  7685. };
  7686. })();
  7687. /* vim: set sw=4 ts=4 et tw=80 : */
  7688. });
  7689. var keyword = createCommonjsModule(function (module) {
  7690. /*
  7691. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7692. Redistribution and use in source and binary forms, with or without
  7693. modification, are permitted provided that the following conditions are met:
  7694. * Redistributions of source code must retain the above copyright
  7695. notice, this list of conditions and the following disclaimer.
  7696. * Redistributions in binary form must reproduce the above copyright
  7697. notice, this list of conditions and the following disclaimer in the
  7698. documentation and/or other materials provided with the distribution.
  7699. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7700. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7701. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7702. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7703. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7704. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7705. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7706. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7707. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7708. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7709. */
  7710. (function () {
  7711. 'use strict';
  7712. var code$$1 = code;
  7713. function isStrictModeReservedWordES6(id) {
  7714. switch (id) {
  7715. case 'implements':
  7716. case 'interface':
  7717. case 'package':
  7718. case 'private':
  7719. case 'protected':
  7720. case 'public':
  7721. case 'static':
  7722. case 'let':
  7723. return true;
  7724. default:
  7725. return false;
  7726. }
  7727. }
  7728. function isKeywordES5(id, strict) {
  7729. // yield should not be treated as keyword under non-strict mode.
  7730. if (!strict && id === 'yield') {
  7731. return false;
  7732. }
  7733. return isKeywordES6(id, strict);
  7734. }
  7735. function isKeywordES6(id, strict) {
  7736. if (strict && isStrictModeReservedWordES6(id)) {
  7737. return true;
  7738. }
  7739. switch (id.length) {
  7740. case 2:
  7741. return id === 'if' || id === 'in' || id === 'do';
  7742. case 3:
  7743. return id === 'var' || id === 'for' || id === 'new' || id === 'try';
  7744. case 4:
  7745. return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
  7746. case 5:
  7747. return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
  7748. case 6:
  7749. return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
  7750. case 7:
  7751. return id === 'default' || id === 'finally' || id === 'extends';
  7752. case 8:
  7753. return id === 'function' || id === 'continue' || id === 'debugger';
  7754. case 10:
  7755. return id === 'instanceof';
  7756. default:
  7757. return false;
  7758. }
  7759. }
  7760. function isReservedWordES5(id, strict) {
  7761. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  7762. }
  7763. function isReservedWordES6(id, strict) {
  7764. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  7765. }
  7766. function isRestrictedWord(id) {
  7767. return id === 'eval' || id === 'arguments';
  7768. }
  7769. function isIdentifierNameES5(id) {
  7770. var i, iz, ch;
  7771. if (id.length === 0) {
  7772. return false;
  7773. }
  7774. ch = id.charCodeAt(0);
  7775. if (!code$$1.isIdentifierStartES5(ch)) {
  7776. return false;
  7777. }
  7778. for (i = 1, iz = id.length; i < iz; ++i) {
  7779. ch = id.charCodeAt(i);
  7780. if (!code$$1.isIdentifierPartES5(ch)) {
  7781. return false;
  7782. }
  7783. }
  7784. return true;
  7785. }
  7786. function decodeUtf16(lead, trail) {
  7787. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  7788. }
  7789. function isIdentifierNameES6(id) {
  7790. var i, iz, ch, lowCh, check;
  7791. if (id.length === 0) {
  7792. return false;
  7793. }
  7794. check = code$$1.isIdentifierStartES6;
  7795. for (i = 0, iz = id.length; i < iz; ++i) {
  7796. ch = id.charCodeAt(i);
  7797. if (0xD800 <= ch && ch <= 0xDBFF) {
  7798. ++i;
  7799. if (i >= iz) {
  7800. return false;
  7801. }
  7802. lowCh = id.charCodeAt(i);
  7803. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  7804. return false;
  7805. }
  7806. ch = decodeUtf16(ch, lowCh);
  7807. }
  7808. if (!check(ch)) {
  7809. return false;
  7810. }
  7811. check = code$$1.isIdentifierPartES6;
  7812. }
  7813. return true;
  7814. }
  7815. function isIdentifierES5(id, strict) {
  7816. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  7817. }
  7818. function isIdentifierES6(id, strict) {
  7819. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  7820. }
  7821. module.exports = {
  7822. isKeywordES5: isKeywordES5,
  7823. isKeywordES6: isKeywordES6,
  7824. isReservedWordES5: isReservedWordES5,
  7825. isReservedWordES6: isReservedWordES6,
  7826. isRestrictedWord: isRestrictedWord,
  7827. isIdentifierNameES5: isIdentifierNameES5,
  7828. isIdentifierNameES6: isIdentifierNameES6,
  7829. isIdentifierES5: isIdentifierES5,
  7830. isIdentifierES6: isIdentifierES6
  7831. };
  7832. })();
  7833. /* vim: set sw=4 ts=4 et tw=80 : */
  7834. });
  7835. var utils$2 = createCommonjsModule(function (module, exports) {
  7836. /*
  7837. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7838. Redistribution and use in source and binary forms, with or without
  7839. modification, are permitted provided that the following conditions are met:
  7840. * Redistributions of source code must retain the above copyright
  7841. notice, this list of conditions and the following disclaimer.
  7842. * Redistributions in binary form must reproduce the above copyright
  7843. notice, this list of conditions and the following disclaimer in the
  7844. documentation and/or other materials provided with the distribution.
  7845. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7846. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7847. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7848. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7849. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7850. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7851. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7852. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7853. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7854. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7855. */
  7856. (function () {
  7857. 'use strict';
  7858. exports.ast = ast;
  7859. exports.code = code;
  7860. exports.keyword = keyword;
  7861. })();
  7862. /* vim: set sw=4 ts=4 et tw=80 : */
  7863. });
  7864. var hasFlag$6 = createCommonjsModule(function (module) {
  7865. 'use strict';
  7866. module.exports = function (flag, argv) {
  7867. argv = argv || process.argv;
  7868. var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  7869. var pos = argv.indexOf(prefix + flag);
  7870. var terminatorPos = argv.indexOf('--');
  7871. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  7872. };
  7873. });
  7874. var env$1 = process.env;
  7875. var forceColor$1;
  7876. if (hasFlag$6('no-color') || hasFlag$6('no-colors') || hasFlag$6('color=false')) {
  7877. forceColor$1 = false;
  7878. } else if (hasFlag$6('color') || hasFlag$6('colors') || hasFlag$6('color=true') || hasFlag$6('color=always')) {
  7879. forceColor$1 = true;
  7880. }
  7881. if ('FORCE_COLOR' in env$1) {
  7882. forceColor$1 = env$1.FORCE_COLOR.length === 0 || parseInt(env$1.FORCE_COLOR, 10) !== 0;
  7883. }
  7884. function translateLevel$1(level) {
  7885. if (level === 0) {
  7886. return false;
  7887. }
  7888. return {
  7889. level,
  7890. hasBasic: true,
  7891. has256: level >= 2,
  7892. has16m: level >= 3
  7893. };
  7894. }
  7895. function supportsColor$4(stream) {
  7896. if (forceColor$1 === false) {
  7897. return 0;
  7898. }
  7899. if (hasFlag$6('color=16m') || hasFlag$6('color=full') || hasFlag$6('color=truecolor')) {
  7900. return 3;
  7901. }
  7902. if (hasFlag$6('color=256')) {
  7903. return 2;
  7904. }
  7905. if (stream && !stream.isTTY && forceColor$1 !== true) {
  7906. return 0;
  7907. }
  7908. var min = forceColor$1 ? 1 : 0;
  7909. if (process.platform === 'win32') {
  7910. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  7911. // libuv that enables 256 color output on Windows. Anything earlier and it
  7912. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  7913. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  7914. // release that supports 256 colors. Windows 10 build 14931 is the first release
  7915. // that supports 16m/TrueColor.
  7916. var osRelease = os.release().split('.');
  7917. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  7918. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  7919. }
  7920. return 1;
  7921. }
  7922. if ('CI' in env$1) {
  7923. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  7924. return sign in env$1;
  7925. }) || env$1.CI_NAME === 'codeship') {
  7926. return 1;
  7927. }
  7928. return min;
  7929. }
  7930. if ('TEAMCITY_VERSION' in env$1) {
  7931. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env$1.TEAMCITY_VERSION) ? 1 : 0;
  7932. }
  7933. if (env$1.COLORTERM === 'truecolor') {
  7934. return 3;
  7935. }
  7936. if ('TERM_PROGRAM' in env$1) {
  7937. var version = parseInt((env$1.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  7938. switch (env$1.TERM_PROGRAM) {
  7939. case 'iTerm.app':
  7940. return version >= 3 ? 3 : 2;
  7941. case 'Apple_Terminal':
  7942. return 2;
  7943. // No default
  7944. }
  7945. }
  7946. if (/-256(color)?$/i.test(env$1.TERM)) {
  7947. return 2;
  7948. }
  7949. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env$1.TERM)) {
  7950. return 1;
  7951. }
  7952. if ('COLORTERM' in env$1) {
  7953. return 1;
  7954. }
  7955. if (env$1.TERM === 'dumb') {
  7956. return min;
  7957. }
  7958. return min;
  7959. }
  7960. function getSupportLevel$1(stream) {
  7961. var level = supportsColor$4(stream);
  7962. return translateLevel$1(level);
  7963. }
  7964. var supportsColor_1$3 = {
  7965. supportsColor: getSupportLevel$1,
  7966. stdout: getSupportLevel$1(process.stdout),
  7967. stderr: getSupportLevel$1(process.stderr)
  7968. };
  7969. var templates$4 = createCommonjsModule(function (module) {
  7970. 'use strict';
  7971. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  7972. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  7973. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  7974. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  7975. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  7976. function unescape(c) {
  7977. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  7978. return String.fromCharCode(parseInt(c.slice(1), 16));
  7979. }
  7980. return ESCAPES.get(c) || c;
  7981. }
  7982. function parseArguments(name, args) {
  7983. var results = [];
  7984. var chunks = args.trim().split(/\s*,\s*/g);
  7985. var matches;
  7986. var _iteratorNormalCompletion = true;
  7987. var _didIteratorError = false;
  7988. var _iteratorError = undefined;
  7989. try {
  7990. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7991. var chunk = _step.value;
  7992. if (!isNaN(chunk)) {
  7993. results.push(Number(chunk));
  7994. } else if (matches = chunk.match(STRING_REGEX)) {
  7995. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  7996. return escape ? unescape(escape) : chr;
  7997. }));
  7998. } else {
  7999. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  8000. }
  8001. }
  8002. } catch (err) {
  8003. _didIteratorError = true;
  8004. _iteratorError = err;
  8005. } finally {
  8006. try {
  8007. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8008. _iterator.return();
  8009. }
  8010. } finally {
  8011. if (_didIteratorError) {
  8012. throw _iteratorError;
  8013. }
  8014. }
  8015. }
  8016. return results;
  8017. }
  8018. function parseStyle(style) {
  8019. STYLE_REGEX.lastIndex = 0;
  8020. var results = [];
  8021. var matches;
  8022. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  8023. var name = matches[1];
  8024. if (matches[2]) {
  8025. var args = parseArguments(name, matches[2]);
  8026. results.push([name].concat(args));
  8027. } else {
  8028. results.push([name]);
  8029. }
  8030. }
  8031. return results;
  8032. }
  8033. function buildStyle(chalk, styles) {
  8034. var enabled = {};
  8035. var _iteratorNormalCompletion2 = true;
  8036. var _didIteratorError2 = false;
  8037. var _iteratorError2 = undefined;
  8038. try {
  8039. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8040. var layer = _step2.value;
  8041. var _iteratorNormalCompletion3 = true;
  8042. var _didIteratorError3 = false;
  8043. var _iteratorError3 = undefined;
  8044. try {
  8045. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  8046. var style = _step3.value;
  8047. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  8048. }
  8049. } catch (err) {
  8050. _didIteratorError3 = true;
  8051. _iteratorError3 = err;
  8052. } finally {
  8053. try {
  8054. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  8055. _iterator3.return();
  8056. }
  8057. } finally {
  8058. if (_didIteratorError3) {
  8059. throw _iteratorError3;
  8060. }
  8061. }
  8062. }
  8063. }
  8064. } catch (err) {
  8065. _didIteratorError2 = true;
  8066. _iteratorError2 = err;
  8067. } finally {
  8068. try {
  8069. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8070. _iterator2.return();
  8071. }
  8072. } finally {
  8073. if (_didIteratorError2) {
  8074. throw _iteratorError2;
  8075. }
  8076. }
  8077. }
  8078. var current = chalk;
  8079. var _arr = Object.keys(enabled);
  8080. for (var _i = 0; _i < _arr.length; _i++) {
  8081. var styleName = _arr[_i];
  8082. if (Array.isArray(enabled[styleName])) {
  8083. if (!(styleName in current)) {
  8084. throw new Error(`Unknown Chalk style: ${styleName}`);
  8085. }
  8086. if (enabled[styleName].length > 0) {
  8087. current = current[styleName].apply(current, enabled[styleName]);
  8088. } else {
  8089. current = current[styleName];
  8090. }
  8091. }
  8092. }
  8093. return current;
  8094. }
  8095. module.exports = function (chalk, tmp) {
  8096. var styles = [];
  8097. var chunks = [];
  8098. var chunk = []; // eslint-disable-next-line max-params
  8099. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  8100. if (escapeChar) {
  8101. chunk.push(unescape(escapeChar));
  8102. } else if (style) {
  8103. var str = chunk.join('');
  8104. chunk = [];
  8105. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  8106. styles.push({
  8107. inverse,
  8108. styles: parseStyle(style)
  8109. });
  8110. } else if (close) {
  8111. if (styles.length === 0) {
  8112. throw new Error('Found extraneous } in Chalk template literal');
  8113. }
  8114. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  8115. chunk = [];
  8116. styles.pop();
  8117. } else {
  8118. chunk.push(chr);
  8119. }
  8120. });
  8121. chunks.push(chunk.join(''));
  8122. if (styles.length > 0) {
  8123. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  8124. throw new Error(errMsg);
  8125. }
  8126. return chunks.join('');
  8127. };
  8128. });
  8129. var chalk$5 = createCommonjsModule(function (module) {
  8130. 'use strict';
  8131. var stdoutColor = supportsColor_1$3.stdout;
  8132. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  8133. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  8134. var skipModels = new Set(['gray']);
  8135. var styles = Object.create(null);
  8136. function applyOptions(obj, options) {
  8137. options = options || {}; // Detect level if not set manually
  8138. var scLevel = stdoutColor ? stdoutColor.level : 0;
  8139. obj.level = options.level === undefined ? scLevel : options.level;
  8140. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  8141. }
  8142. function Chalk(options) {
  8143. // We check for this.template here since calling `chalk.constructor()`
  8144. // by itself will have a `this` of a previously constructed chalk object
  8145. if (!this || !(this instanceof Chalk) || this.template) {
  8146. var _chalk = {};
  8147. applyOptions(_chalk, options);
  8148. _chalk.template = function () {
  8149. var args = [].slice.call(arguments);
  8150. return chalkTag.apply(null, [_chalk.template].concat(args));
  8151. };
  8152. Object.setPrototypeOf(_chalk, Chalk.prototype);
  8153. Object.setPrototypeOf(_chalk.template, _chalk);
  8154. _chalk.template.constructor = Chalk;
  8155. return _chalk.template;
  8156. }
  8157. applyOptions(this, options);
  8158. } // Use bright blue on Windows as the normal blue color is illegible
  8159. if (isSimpleWindowsTerm) {
  8160. ansiStyles.blue.open = '\u001B[94m';
  8161. }
  8162. var _arr = Object.keys(ansiStyles);
  8163. var _loop = function _loop() {
  8164. var key = _arr[_i];
  8165. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  8166. styles[key] = {
  8167. get() {
  8168. var codes = ansiStyles[key];
  8169. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  8170. }
  8171. };
  8172. };
  8173. for (var _i = 0; _i < _arr.length; _i++) {
  8174. _loop();
  8175. }
  8176. styles.visible = {
  8177. get() {
  8178. return build.call(this, this._styles || [], true, 'visible');
  8179. }
  8180. };
  8181. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  8182. var _arr2 = Object.keys(ansiStyles.color.ansi);
  8183. var _loop2 = function _loop2() {
  8184. var model = _arr2[_i2];
  8185. if (skipModels.has(model)) {
  8186. return "continue";
  8187. }
  8188. styles[model] = {
  8189. get() {
  8190. var level = this.level;
  8191. return function () {
  8192. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  8193. var codes = {
  8194. open,
  8195. close: ansiStyles.color.close,
  8196. closeRe: ansiStyles.color.closeRe
  8197. };
  8198. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  8199. };
  8200. }
  8201. };
  8202. };
  8203. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  8204. var _ret = _loop2();
  8205. if (_ret === "continue") continue;
  8206. }
  8207. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  8208. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  8209. var _loop3 = function _loop3() {
  8210. var model = _arr3[_i3];
  8211. if (skipModels.has(model)) {
  8212. return "continue";
  8213. }
  8214. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  8215. styles[bgModel] = {
  8216. get() {
  8217. var level = this.level;
  8218. return function () {
  8219. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  8220. var codes = {
  8221. open,
  8222. close: ansiStyles.bgColor.close,
  8223. closeRe: ansiStyles.bgColor.closeRe
  8224. };
  8225. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  8226. };
  8227. }
  8228. };
  8229. };
  8230. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  8231. var _ret2 = _loop3();
  8232. if (_ret2 === "continue") continue;
  8233. }
  8234. var proto = Object.defineProperties(function () {}, styles);
  8235. function build(_styles, _empty, key) {
  8236. var builder = function builder() {
  8237. return applyStyle.apply(builder, arguments);
  8238. };
  8239. builder._styles = _styles;
  8240. builder._empty = _empty;
  8241. var self = this;
  8242. Object.defineProperty(builder, 'level', {
  8243. enumerable: true,
  8244. get() {
  8245. return self.level;
  8246. },
  8247. set(level) {
  8248. self.level = level;
  8249. }
  8250. });
  8251. Object.defineProperty(builder, 'enabled', {
  8252. enumerable: true,
  8253. get() {
  8254. return self.enabled;
  8255. },
  8256. set(enabled) {
  8257. self.enabled = enabled;
  8258. }
  8259. }); // See below for fix regarding invisible grey/dim combination on Windows
  8260. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  8261. // no way to create a function with a different prototype
  8262. builder.__proto__ = proto; // eslint-disable-line no-proto
  8263. return builder;
  8264. }
  8265. function applyStyle() {
  8266. // Support varags, but simply cast to string in case there's only one arg
  8267. var args = arguments;
  8268. var argsLen = args.length;
  8269. var str = String(arguments[0]);
  8270. if (argsLen === 0) {
  8271. return '';
  8272. }
  8273. if (argsLen > 1) {
  8274. // Don't slice `arguments`, it prevents V8 optimizations
  8275. for (var a = 1; a < argsLen; a++) {
  8276. str += ' ' + args[a];
  8277. }
  8278. }
  8279. if (!this.enabled || this.level <= 0 || !str) {
  8280. return this._empty ? '' : str;
  8281. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  8282. // see https://github.com/chalk/chalk/issues/58
  8283. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  8284. var originalDim = ansiStyles.dim.open;
  8285. if (isSimpleWindowsTerm && this.hasGrey) {
  8286. ansiStyles.dim.open = '';
  8287. }
  8288. var _iteratorNormalCompletion = true;
  8289. var _didIteratorError = false;
  8290. var _iteratorError = undefined;
  8291. try {
  8292. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8293. var code = _step.value;
  8294. // Replace any instances already present with a re-opening code
  8295. // otherwise only the part of the string until said closing code
  8296. // will be colored, and the rest will simply be 'plain'.
  8297. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  8298. // after next line to fix a bleed issue on macOS
  8299. // https://github.com/chalk/chalk/pull/92
  8300. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  8301. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  8302. } catch (err) {
  8303. _didIteratorError = true;
  8304. _iteratorError = err;
  8305. } finally {
  8306. try {
  8307. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8308. _iterator.return();
  8309. }
  8310. } finally {
  8311. if (_didIteratorError) {
  8312. throw _iteratorError;
  8313. }
  8314. }
  8315. }
  8316. ansiStyles.dim.open = originalDim;
  8317. return str;
  8318. }
  8319. function chalkTag(chalk, strings) {
  8320. if (!Array.isArray(strings)) {
  8321. // If chalk() was called by itself or with a string,
  8322. // return the string itself as a string.
  8323. return [].slice.call(arguments, 1).join(' ');
  8324. }
  8325. var args = [].slice.call(arguments, 2);
  8326. var parts = [strings.raw[0]];
  8327. for (var i = 1; i < strings.length; i++) {
  8328. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  8329. parts.push(String(strings.raw[i]));
  8330. }
  8331. return templates$4(chalk, parts.join(''));
  8332. }
  8333. Object.defineProperties(Chalk.prototype, styles);
  8334. module.exports = Chalk(); // eslint-disable-line new-cap
  8335. module.exports.supportsColor = stdoutColor;
  8336. module.exports.default = module.exports; // For TypeScript
  8337. });
  8338. var lib$3 = createCommonjsModule(function (module, exports) {
  8339. "use strict";
  8340. Object.defineProperty(exports, "__esModule", {
  8341. value: true
  8342. });
  8343. exports.shouldHighlight = shouldHighlight;
  8344. exports.getChalk = getChalk;
  8345. exports.default = highlight;
  8346. function _jsTokens() {
  8347. var data = _interopRequireWildcard$$1(jsTokens);
  8348. _jsTokens = function _jsTokens() {
  8349. return data;
  8350. };
  8351. return data;
  8352. }
  8353. function _esutils() {
  8354. var data = _interopRequireDefault$$1(utils$2);
  8355. _esutils = function _esutils() {
  8356. return data;
  8357. };
  8358. return data;
  8359. }
  8360. function _chalk() {
  8361. var data = _interopRequireDefault$$1(chalk$5);
  8362. _chalk = function _chalk() {
  8363. return data;
  8364. };
  8365. return data;
  8366. }
  8367. function _interopRequireDefault$$1(obj) {
  8368. return obj && obj.__esModule ? obj : {
  8369. default: obj
  8370. };
  8371. }
  8372. function _interopRequireWildcard$$1(obj) {
  8373. if (obj && obj.__esModule) {
  8374. return obj;
  8375. } else {
  8376. var newObj = {};
  8377. if (obj != null) {
  8378. for (var key in obj) {
  8379. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  8380. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  8381. if (desc.get || desc.set) {
  8382. Object.defineProperty(newObj, key, desc);
  8383. } else {
  8384. newObj[key] = obj[key];
  8385. }
  8386. }
  8387. }
  8388. }
  8389. newObj.default = obj;
  8390. return newObj;
  8391. }
  8392. }
  8393. function getDefs(chalk) {
  8394. return {
  8395. keyword: chalk.cyan,
  8396. capitalized: chalk.yellow,
  8397. jsx_tag: chalk.yellow,
  8398. punctuator: chalk.yellow,
  8399. number: chalk.magenta,
  8400. string: chalk.green,
  8401. regex: chalk.magenta,
  8402. comment: chalk.grey,
  8403. invalid: chalk.white.bgRed.bold
  8404. };
  8405. }
  8406. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  8407. var JSX_TAG = /^[a-z][\w-]*$/i;
  8408. var BRACKET = /^[()[\]{}]$/;
  8409. function getTokenType(match) {
  8410. var _match$slice = match.slice(-2),
  8411. _match$slice2 = _slicedToArray(_match$slice, 2),
  8412. offset = _match$slice2[0],
  8413. text = _match$slice2[1];
  8414. var token = (0, _jsTokens().matchToToken)(match);
  8415. if (token.type === "name") {
  8416. if (_esutils().default.keyword.isReservedWordES6(token.value)) {
  8417. return "keyword";
  8418. }
  8419. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  8420. return "jsx_tag";
  8421. }
  8422. if (token.value[0] !== token.value[0].toLowerCase()) {
  8423. return "capitalized";
  8424. }
  8425. }
  8426. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  8427. return "bracket";
  8428. }
  8429. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  8430. return "punctuator";
  8431. }
  8432. return token.type;
  8433. }
  8434. function highlightTokens(defs, text) {
  8435. return text.replace(_jsTokens().default, function () {
  8436. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  8437. args[_key] = arguments[_key];
  8438. }
  8439. var type = getTokenType(args);
  8440. var colorize = defs[type];
  8441. if (colorize) {
  8442. return args[0].split(NEWLINE).map(function (str) {
  8443. return colorize(str);
  8444. }).join("\n");
  8445. } else {
  8446. return args[0];
  8447. }
  8448. });
  8449. }
  8450. function shouldHighlight(options) {
  8451. return _chalk().default.supportsColor || options.forceColor;
  8452. }
  8453. function getChalk(options) {
  8454. var chalk = _chalk().default;
  8455. if (options.forceColor) {
  8456. chalk = new (_chalk().default.constructor)({
  8457. enabled: true,
  8458. level: 1
  8459. });
  8460. }
  8461. return chalk;
  8462. }
  8463. function highlight(code) {
  8464. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  8465. if (shouldHighlight(options)) {
  8466. var chalk = getChalk(options);
  8467. var defs = getDefs(chalk);
  8468. return highlightTokens(defs, code);
  8469. } else {
  8470. return code;
  8471. }
  8472. }
  8473. });
  8474. unwrapExports(lib$3);
  8475. var lib$2 = createCommonjsModule(function (module, exports) {
  8476. "use strict";
  8477. Object.defineProperty(exports, "__esModule", {
  8478. value: true
  8479. });
  8480. exports.codeFrameColumns = codeFrameColumns;
  8481. exports.default = _default;
  8482. function _highlight() {
  8483. var data = _interopRequireWildcard(lib$3);
  8484. _highlight = function _highlight() {
  8485. return data;
  8486. };
  8487. return data;
  8488. }
  8489. function _interopRequireWildcard(obj) {
  8490. if (obj && obj.__esModule) {
  8491. return obj;
  8492. } else {
  8493. var newObj = {};
  8494. if (obj != null) {
  8495. for (var key in obj) {
  8496. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  8497. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  8498. if (desc.get || desc.set) {
  8499. Object.defineProperty(newObj, key, desc);
  8500. } else {
  8501. newObj[key] = obj[key];
  8502. }
  8503. }
  8504. }
  8505. }
  8506. newObj.default = obj;
  8507. return newObj;
  8508. }
  8509. }
  8510. var deprecationWarningShown = false;
  8511. function getDefs(chalk) {
  8512. return {
  8513. gutter: chalk.grey,
  8514. marker: chalk.red.bold,
  8515. message: chalk.red.bold
  8516. };
  8517. }
  8518. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  8519. function getMarkerLines(loc, source, opts) {
  8520. var startLoc = Object.assign({
  8521. column: 0,
  8522. line: -1
  8523. }, loc.start);
  8524. var endLoc = Object.assign({}, startLoc, loc.end);
  8525. var _ref = opts || {},
  8526. _ref$linesAbove = _ref.linesAbove,
  8527. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  8528. _ref$linesBelow = _ref.linesBelow,
  8529. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  8530. var startLine = startLoc.line;
  8531. var startColumn = startLoc.column;
  8532. var endLine = endLoc.line;
  8533. var endColumn = endLoc.column;
  8534. var start = Math.max(startLine - (linesAbove + 1), 0);
  8535. var end = Math.min(source.length, endLine + linesBelow);
  8536. if (startLine === -1) {
  8537. start = 0;
  8538. }
  8539. if (endLine === -1) {
  8540. end = source.length;
  8541. }
  8542. var lineDiff = endLine - startLine;
  8543. var markerLines = {};
  8544. if (lineDiff) {
  8545. for (var i = 0; i <= lineDiff; i++) {
  8546. var lineNumber = i + startLine;
  8547. if (!startColumn) {
  8548. markerLines[lineNumber] = true;
  8549. } else if (i === 0) {
  8550. var sourceLength = source[lineNumber - 1].length;
  8551. markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
  8552. } else if (i === lineDiff) {
  8553. markerLines[lineNumber] = [0, endColumn];
  8554. } else {
  8555. var _sourceLength = source[lineNumber - i].length;
  8556. markerLines[lineNumber] = [0, _sourceLength];
  8557. }
  8558. }
  8559. } else {
  8560. if (startColumn === endColumn) {
  8561. if (startColumn) {
  8562. markerLines[startLine] = [startColumn, 0];
  8563. } else {
  8564. markerLines[startLine] = true;
  8565. }
  8566. } else {
  8567. markerLines[startLine] = [startColumn, endColumn - startColumn];
  8568. }
  8569. }
  8570. return {
  8571. start,
  8572. end,
  8573. markerLines
  8574. };
  8575. }
  8576. function codeFrameColumns(rawLines, loc) {
  8577. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  8578. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
  8579. var chalk = (0, _highlight().getChalk)(opts);
  8580. var defs = getDefs(chalk);
  8581. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  8582. return highlighted ? chalkFn(string) : string;
  8583. };
  8584. if (highlighted) rawLines = (0, _highlight().default)(rawLines, opts);
  8585. var lines = rawLines.split(NEWLINE);
  8586. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  8587. start = _getMarkerLines.start,
  8588. end = _getMarkerLines.end,
  8589. markerLines = _getMarkerLines.markerLines;
  8590. var hasColumns = loc.start && typeof loc.start.column === "number";
  8591. var numberMaxWidth = String(end).length;
  8592. var frame = lines.slice(start, end).map(function (line, index) {
  8593. var number = start + 1 + index;
  8594. var paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  8595. var gutter = ` ${paddedNumber} | `;
  8596. var hasMarker = markerLines[number];
  8597. var lastMarkerLine = !markerLines[number + 1];
  8598. if (hasMarker) {
  8599. var markerLine = "";
  8600. if (Array.isArray(hasMarker)) {
  8601. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  8602. var numberOfMarkers = hasMarker[1] || 1;
  8603. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  8604. if (lastMarkerLine && opts.message) {
  8605. markerLine += " " + maybeHighlight(defs.message, opts.message);
  8606. }
  8607. }
  8608. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  8609. } else {
  8610. return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
  8611. }
  8612. }).join("\n");
  8613. if (opts.message && !hasColumns) {
  8614. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  8615. }
  8616. if (highlighted) {
  8617. return chalk.reset(frame);
  8618. } else {
  8619. return frame;
  8620. }
  8621. }
  8622. function _default(rawLines, lineNumber, colNumber) {
  8623. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  8624. if (!deprecationWarningShown) {
  8625. deprecationWarningShown = true;
  8626. var message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  8627. if (process.emitWarning) {
  8628. process.emitWarning(message, "DeprecationWarning");
  8629. } else {
  8630. var deprecationError = new Error(message);
  8631. deprecationError.name = "DeprecationWarning";
  8632. console.warn(new Error(message));
  8633. }
  8634. }
  8635. colNumber = Math.max(colNumber, 0);
  8636. var location = {
  8637. start: {
  8638. column: colNumber,
  8639. line: lineNumber
  8640. }
  8641. };
  8642. return codeFrameColumns(rawLines, location, opts);
  8643. }
  8644. });
  8645. unwrapExports(lib$2);
  8646. var ConfigError$1 = errors.ConfigError;
  8647. var locStart = loc.locStart;
  8648. var locEnd = loc.locEnd; // Use defineProperties()/getOwnPropertyDescriptor() to prevent
  8649. // triggering the parsers getters.
  8650. var ownNames = Object.getOwnPropertyNames;
  8651. var ownDescriptor = Object.getOwnPropertyDescriptor;
  8652. function getParsers(options) {
  8653. var parsers = {};
  8654. var _iteratorNormalCompletion = true;
  8655. var _didIteratorError = false;
  8656. var _iteratorError = undefined;
  8657. try {
  8658. for (var _iterator = options.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8659. var plugin = _step.value;
  8660. if (!plugin.parsers) {
  8661. continue;
  8662. }
  8663. var _iteratorNormalCompletion2 = true;
  8664. var _didIteratorError2 = false;
  8665. var _iteratorError2 = undefined;
  8666. try {
  8667. for (var _iterator2 = ownNames(plugin.parsers)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8668. var name = _step2.value;
  8669. Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name));
  8670. }
  8671. } catch (err) {
  8672. _didIteratorError2 = true;
  8673. _iteratorError2 = err;
  8674. } finally {
  8675. try {
  8676. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8677. _iterator2.return();
  8678. }
  8679. } finally {
  8680. if (_didIteratorError2) {
  8681. throw _iteratorError2;
  8682. }
  8683. }
  8684. }
  8685. }
  8686. } catch (err) {
  8687. _didIteratorError = true;
  8688. _iteratorError = err;
  8689. } finally {
  8690. try {
  8691. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8692. _iterator.return();
  8693. }
  8694. } finally {
  8695. if (_didIteratorError) {
  8696. throw _iteratorError;
  8697. }
  8698. }
  8699. }
  8700. return parsers;
  8701. }
  8702. function resolveParser$1(opts, parsers) {
  8703. parsers = parsers || getParsers(opts);
  8704. if (typeof opts.parser === "function") {
  8705. // Custom parser API always works with JavaScript.
  8706. return {
  8707. parse: opts.parser,
  8708. astFormat: "estree",
  8709. locStart,
  8710. locEnd
  8711. };
  8712. }
  8713. if (typeof opts.parser === "string") {
  8714. if (parsers.hasOwnProperty(opts.parser)) {
  8715. return parsers[opts.parser];
  8716. }
  8717. /* istanbul ignore next */
  8718. {
  8719. try {
  8720. return {
  8721. parse: require(path.resolve(process.cwd(), opts.parser)),
  8722. astFormat: "estree",
  8723. locStart,
  8724. locEnd
  8725. };
  8726. } catch (err) {
  8727. /* istanbul ignore next */
  8728. throw new ConfigError$1(`Couldn't resolve parser "${opts.parser}"`);
  8729. }
  8730. }
  8731. }
  8732. }
  8733. function parse$2(text, opts) {
  8734. var parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call
  8735. // the parsers getters when actually calling the parser `parse` function.
  8736. var parsersForCustomParserApi = Object.keys(parsers).reduce(function (object, parserName) {
  8737. return Object.defineProperty(object, parserName, {
  8738. enumerable: true,
  8739. get() {
  8740. return parsers[parserName].parse;
  8741. }
  8742. });
  8743. }, {});
  8744. var parser = resolveParser$1(opts, parsers);
  8745. try {
  8746. if (parser.preprocess) {
  8747. text = parser.preprocess(text, opts);
  8748. }
  8749. return {
  8750. text,
  8751. ast: parser.parse(text, parsersForCustomParserApi, opts)
  8752. };
  8753. } catch (error) {
  8754. var loc$$1 = error.loc;
  8755. if (loc$$1) {
  8756. var codeFrame = lib$2;
  8757. error.codeFrame = codeFrame.codeFrameColumns(text, loc$$1, {
  8758. highlightCode: true
  8759. });
  8760. error.message += "\n" + error.codeFrame;
  8761. throw error;
  8762. }
  8763. /* istanbul ignore next */
  8764. throw error.stack;
  8765. }
  8766. }
  8767. var parser = {
  8768. parse: parse$2,
  8769. resolveParser: resolveParser$1
  8770. };
  8771. var UndefinedParserError = errors.UndefinedParserError;
  8772. var getSupportInfo$1 = support.getSupportInfo;
  8773. var resolveParser = parser.resolveParser;
  8774. var hiddenDefaults = {
  8775. astFormat: "estree",
  8776. printer: {},
  8777. originalText: undefined,
  8778. locStart: null,
  8779. locEnd: null
  8780. }; // Copy options and fill in default values.
  8781. function normalize(options, opts) {
  8782. opts = opts || {};
  8783. var rawOptions = Object.assign({}, options);
  8784. var supportOptions = getSupportInfo$1(null, {
  8785. plugins: options.plugins,
  8786. showUnreleased: true,
  8787. showDeprecated: true
  8788. }).options;
  8789. var defaults = supportOptions.reduce(function (reduced, optionInfo) {
  8790. return optionInfo.default !== undefined ? Object.assign(reduced, {
  8791. [optionInfo.name]: optionInfo.default
  8792. }) : reduced;
  8793. }, Object.assign({}, hiddenDefaults));
  8794. if (!rawOptions.parser) {
  8795. if (!rawOptions.filepath) {
  8796. var logger = opts.logger || console;
  8797. logger.warn("No parser and no filepath given, using 'babel' the parser now " + "but this will throw an error in the future. " + "Please specify a parser or a filepath so one can be inferred.");
  8798. rawOptions.parser = "babel";
  8799. } else {
  8800. rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins);
  8801. if (!rawOptions.parser) {
  8802. throw new UndefinedParserError(`No parser could be inferred for file: ${rawOptions.filepath}`);
  8803. }
  8804. }
  8805. }
  8806. var parser$$1 = resolveParser(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(function (x) {
  8807. return x.name === "parser";
  8808. })], {
  8809. passThrough: true,
  8810. logger: false
  8811. }));
  8812. rawOptions.astFormat = parser$$1.astFormat;
  8813. rawOptions.locEnd = parser$$1.locEnd;
  8814. rawOptions.locStart = parser$$1.locStart;
  8815. var plugin = getPlugin(rawOptions);
  8816. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  8817. var pluginDefaults = supportOptions.filter(function (optionInfo) {
  8818. return optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name];
  8819. }).reduce(function (reduced, optionInfo) {
  8820. return Object.assign(reduced, {
  8821. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  8822. });
  8823. }, {});
  8824. var mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  8825. Object.keys(mixedDefaults).forEach(function (k) {
  8826. if (rawOptions[k] == null) {
  8827. rawOptions[k] = mixedDefaults[k];
  8828. }
  8829. });
  8830. if (rawOptions.parser === "json") {
  8831. rawOptions.trailingComma = "none";
  8832. }
  8833. return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({
  8834. passThrough: Object.keys(hiddenDefaults)
  8835. }, opts));
  8836. }
  8837. function getPlugin(options) {
  8838. var astFormat = options.astFormat;
  8839. if (!astFormat) {
  8840. throw new Error("getPlugin() requires astFormat to be set");
  8841. }
  8842. var printerPlugin = options.plugins.find(function (plugin) {
  8843. return plugin.printers && plugin.printers[astFormat];
  8844. });
  8845. if (!printerPlugin) {
  8846. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  8847. }
  8848. return printerPlugin;
  8849. }
  8850. function getInterpreter(filepath) {
  8851. if (typeof filepath !== "string") {
  8852. return "";
  8853. }
  8854. var fd;
  8855. try {
  8856. fd = fs.openSync(filepath, "r");
  8857. } catch (err) {
  8858. return "";
  8859. }
  8860. try {
  8861. var liner = new readlines(fd);
  8862. var firstLine = liner.next().toString("utf8"); // #!/bin/env node, #!/usr/bin/env node
  8863. var m1 = firstLine.match(/^#!\/(?:usr\/)?bin\/env\s+(\S+)/);
  8864. if (m1) {
  8865. return m1[1];
  8866. } // #!/bin/node, #!/usr/bin/node, #!/usr/local/bin/node
  8867. var m2 = firstLine.match(/^#!\/(?:usr\/(?:local\/)?)?bin\/(\S+)/);
  8868. if (m2) {
  8869. return m2[1];
  8870. }
  8871. return "";
  8872. } catch (err) {
  8873. // There are some weird cases where paths are missing, causing Jest
  8874. // failures. It's unclear what these correspond to in the real world.
  8875. return "";
  8876. } finally {
  8877. try {
  8878. // There are some weird cases where paths are missing, causing Jest
  8879. // failures. It's unclear what these correspond to in the real world.
  8880. fs.closeSync(fd);
  8881. } catch (err) {// nop
  8882. }
  8883. }
  8884. }
  8885. function inferParser(filepath, plugins) {
  8886. var filepathParts = normalizePath(filepath).split("/");
  8887. var filename = filepathParts[filepathParts.length - 1].toLowerCase(); // If the file has no extension, we can try to infer the language from the
  8888. // interpreter in the shebang line, if any; but since this requires FS access,
  8889. // do it last.
  8890. var language = getSupportInfo$1(null, {
  8891. plugins
  8892. }).languages.find(function (language) {
  8893. return language.since !== null && (language.extensions && language.extensions.some(function (extension) {
  8894. return filename.endsWith(extension);
  8895. }) || language.filenames && language.filenames.find(function (name) {
  8896. return name.toLowerCase() === filename;
  8897. }) || filename.indexOf(".") === -1 && language.interpreters && language.interpreters.indexOf(getInterpreter(filepath)) !== -1);
  8898. });
  8899. return language && language.parsers[0];
  8900. }
  8901. var options = {
  8902. normalize,
  8903. hiddenDefaults,
  8904. inferParser
  8905. };
  8906. function massageAST(ast, options, parent) {
  8907. if (Array.isArray(ast)) {
  8908. return ast.map(function (e) {
  8909. return massageAST(e, options, parent);
  8910. }).filter(function (e) {
  8911. return e;
  8912. });
  8913. }
  8914. if (!ast || typeof ast !== "object") {
  8915. return ast;
  8916. }
  8917. var newObj = {};
  8918. var _arr = Object.keys(ast);
  8919. for (var _i = 0; _i < _arr.length; _i++) {
  8920. var key = _arr[_i];
  8921. if (typeof ast[key] !== "function") {
  8922. newObj[key] = massageAST(ast[key], options, ast);
  8923. }
  8924. }
  8925. if (options.printer.massageAstNode) {
  8926. var result = options.printer.massageAstNode(ast, newObj, parent);
  8927. if (result === null) {
  8928. return undefined;
  8929. }
  8930. if (result) {
  8931. return result;
  8932. }
  8933. }
  8934. return newObj;
  8935. }
  8936. var massageAst = massageAST;
  8937. function concat$1(parts) {
  8938. return {
  8939. type: "concat",
  8940. parts
  8941. };
  8942. }
  8943. function indent$1(contents) {
  8944. return {
  8945. type: "indent",
  8946. contents
  8947. };
  8948. }
  8949. function align(n, contents) {
  8950. return {
  8951. type: "align",
  8952. contents,
  8953. n
  8954. };
  8955. }
  8956. function group(contents, opts) {
  8957. opts = opts || {};
  8958. return {
  8959. type: "group",
  8960. id: opts.id,
  8961. contents: contents,
  8962. break: !!opts.shouldBreak,
  8963. expandedStates: opts.expandedStates
  8964. };
  8965. }
  8966. function dedentToRoot(contents) {
  8967. return align(-Infinity, contents);
  8968. }
  8969. function markAsRoot(contents) {
  8970. return align({
  8971. type: "root"
  8972. }, contents);
  8973. }
  8974. function dedent$1(contents) {
  8975. return align(-1, contents);
  8976. }
  8977. function conditionalGroup(states, opts) {
  8978. return group(states[0], Object.assign(opts || {}, {
  8979. expandedStates: states
  8980. }));
  8981. }
  8982. function fill(parts) {
  8983. return {
  8984. type: "fill",
  8985. parts
  8986. };
  8987. }
  8988. function ifBreak(breakContents, flatContents, opts) {
  8989. opts = opts || {};
  8990. return {
  8991. type: "if-break",
  8992. breakContents,
  8993. flatContents,
  8994. groupId: opts.groupId
  8995. };
  8996. }
  8997. function lineSuffix$1(contents) {
  8998. return {
  8999. type: "line-suffix",
  9000. contents
  9001. };
  9002. }
  9003. var lineSuffixBoundary = {
  9004. type: "line-suffix-boundary"
  9005. };
  9006. var breakParent$1 = {
  9007. type: "break-parent"
  9008. };
  9009. var trim = {
  9010. type: "trim"
  9011. };
  9012. var line$2 = {
  9013. type: "line"
  9014. };
  9015. var softline = {
  9016. type: "line",
  9017. soft: true
  9018. };
  9019. var hardline$1 = concat$1([{
  9020. type: "line",
  9021. hard: true
  9022. }, breakParent$1]);
  9023. var literalline = concat$1([{
  9024. type: "line",
  9025. hard: true,
  9026. literal: true
  9027. }, breakParent$1]);
  9028. var cursor$1 = {
  9029. type: "cursor",
  9030. placeholder: Symbol("cursor")
  9031. };
  9032. function join$1(sep, arr) {
  9033. var res = [];
  9034. for (var i = 0; i < arr.length; i++) {
  9035. if (i !== 0) {
  9036. res.push(sep);
  9037. }
  9038. res.push(arr[i]);
  9039. }
  9040. return concat$1(res);
  9041. }
  9042. function addAlignmentToDoc(doc, size, tabWidth) {
  9043. var aligned = doc;
  9044. if (size > 0) {
  9045. // Use indent to add tabs for all the levels of tabs we need
  9046. for (var i = 0; i < Math.floor(size / tabWidth); ++i) {
  9047. aligned = indent$1(aligned);
  9048. } // Use align for all the spaces that are needed
  9049. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  9050. // indentation, so we use -Infinity to reset the indentation to 0
  9051. aligned = align(-Infinity, aligned);
  9052. }
  9053. return aligned;
  9054. }
  9055. var docBuilders = {
  9056. concat: concat$1,
  9057. join: join$1,
  9058. line: line$2,
  9059. softline,
  9060. hardline: hardline$1,
  9061. literalline,
  9062. group,
  9063. conditionalGroup,
  9064. fill,
  9065. lineSuffix: lineSuffix$1,
  9066. lineSuffixBoundary,
  9067. cursor: cursor$1,
  9068. breakParent: breakParent$1,
  9069. ifBreak,
  9070. trim,
  9071. indent: indent$1,
  9072. align,
  9073. addAlignmentToDoc,
  9074. markAsRoot,
  9075. dedentToRoot,
  9076. dedent: dedent$1
  9077. };
  9078. var ansiRegex = createCommonjsModule(function (module) {
  9079. 'use strict';
  9080. module.exports = function (options) {
  9081. options = Object.assign({
  9082. onlyFirst: false
  9083. }, options);
  9084. var pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  9085. return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
  9086. };
  9087. });
  9088. var stripAnsi = function stripAnsi(input) {
  9089. return typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
  9090. };
  9091. var isFullwidthCodePoint = createCommonjsModule(function (module) {
  9092. 'use strict';
  9093. /* eslint-disable yoda */
  9094. module.exports = function (x) {
  9095. if (Number.isNaN(x)) {
  9096. return false;
  9097. } // code points are derived from:
  9098. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  9099. if (x >= 0x1100 && (x <= 0x115f || // Hangul Jamo
  9100. x === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  9101. x === 0x232a || // RIGHT-POINTING ANGLE BRACKET
  9102. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  9103. 0x2e80 <= x && x <= 0x3247 && x !== 0x303f || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  9104. 0x3250 <= x && x <= 0x4dbf || // CJK Unified Ideographs .. Yi Radicals
  9105. 0x4e00 <= x && x <= 0xa4c6 || // Hangul Jamo Extended-A
  9106. 0xa960 <= x && x <= 0xa97c || // Hangul Syllables
  9107. 0xac00 <= x && x <= 0xd7a3 || // CJK Compatibility Ideographs
  9108. 0xf900 <= x && x <= 0xfaff || // Vertical Forms
  9109. 0xfe10 <= x && x <= 0xfe19 || // CJK Compatibility Forms .. Small Form Variants
  9110. 0xfe30 <= x && x <= 0xfe6b || // Halfwidth and Fullwidth Forms
  9111. 0xff01 <= x && x <= 0xff60 || 0xffe0 <= x && x <= 0xffe6 || // Kana Supplement
  9112. 0x1b000 <= x && x <= 0x1b001 || // Enclosed Ideographic Supplement
  9113. 0x1f200 <= x && x <= 0x1f251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  9114. 0x20000 <= x && x <= 0x3fffd)) {
  9115. return true;
  9116. }
  9117. return false;
  9118. };
  9119. });
  9120. var emojiRegex = function emojiRegex() {
  9121. // https://mths.be/emoji
  9122. 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|\u200D\u2620\uFE0F)|\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])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDB0-\uDDB3])|(?:\uD83C[\uDFFB-\uDFFF])\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDB0-\uDDB3]))|\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]|\uD83E[\uDDB0-\uDDB3])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2695\u2696\u2708]|\uD83D\uDC68(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\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]|\uD83E[\uDDB0-\uDDB3])|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\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\uDDB5\uDDB6\uDDD1-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDEEB\uDEEC\uDEF4-\uDEF9]|\uD83E[\uDD10-\uDD3A\uDD3C-\uDD3E\uDD40-\uDD45\uDD47-\uDD70\uDD73-\uDD76\uDD7A\uDD7C-\uDDA2\uDDB0-\uDDB9\uDDC0-\uDDC2\uDDD0-\uDDFF])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEF9]|\uD83E[\uDD10-\uDD3A\uDD3C-\uDD3E\uDD40-\uDD45\uDD47-\uDD70\uDD73-\uDD76\uDD7A\uDD7C-\uDDA2\uDDB0-\uDDB9\uDDC0-\uDDC2\uDDD0-\uDDFF])\uFE0F|(?:[\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\uDDB5\uDDB6\uDDB8\uDDB9\uDDD1-\uDDDD])/g;
  9123. };
  9124. var stringWidth = createCommonjsModule(function (module) {
  9125. 'use strict';
  9126. var emojiRegex$$1 = emojiRegex();
  9127. module.exports = function (input) {
  9128. input = input.replace(emojiRegex$$1, ' ');
  9129. if (typeof input !== 'string' || input.length === 0) {
  9130. return 0;
  9131. }
  9132. input = stripAnsi(input);
  9133. var width = 0;
  9134. for (var i = 0; i < input.length; i++) {
  9135. var code = input.codePointAt(i); // Ignore control characters
  9136. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  9137. continue;
  9138. } // Ignore combining characters
  9139. if (code >= 0x300 && code <= 0x36F) {
  9140. continue;
  9141. } // Surrogates
  9142. if (code > 0xFFFF) {
  9143. i++;
  9144. }
  9145. width += isFullwidthCodePoint(code) ? 2 : 1;
  9146. }
  9147. return width;
  9148. };
  9149. });
  9150. var notAsciiRegex = /[^\x20-\x7F]/;
  9151. function isExportDeclaration(node) {
  9152. if (node) {
  9153. switch (node.type) {
  9154. case "ExportDefaultDeclaration":
  9155. case "ExportDefaultSpecifier":
  9156. case "DeclareExportDeclaration":
  9157. case "ExportNamedDeclaration":
  9158. case "ExportAllDeclaration":
  9159. return true;
  9160. }
  9161. }
  9162. return false;
  9163. }
  9164. function getParentExportDeclaration(path$$1) {
  9165. var parentNode = path$$1.getParentNode();
  9166. if (path$$1.getName() === "declaration" && isExportDeclaration(parentNode)) {
  9167. return parentNode;
  9168. }
  9169. return null;
  9170. }
  9171. function getPenultimate(arr) {
  9172. if (arr.length > 1) {
  9173. return arr[arr.length - 2];
  9174. }
  9175. return null;
  9176. }
  9177. function skip(chars) {
  9178. return function (text, index, opts) {
  9179. var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  9180. // to check for failures (did someone say monads?).
  9181. if (index === false) {
  9182. return false;
  9183. }
  9184. var length = text.length;
  9185. var cursor = index;
  9186. while (cursor >= 0 && cursor < length) {
  9187. var c = text.charAt(cursor);
  9188. if (chars instanceof RegExp) {
  9189. if (!chars.test(c)) {
  9190. return cursor;
  9191. }
  9192. } else if (chars.indexOf(c) === -1) {
  9193. return cursor;
  9194. }
  9195. backwards ? cursor-- : cursor++;
  9196. }
  9197. if (cursor === -1 || cursor === length) {
  9198. // If we reached the beginning or end of the file, return the
  9199. // out-of-bounds cursor. It's up to the caller to handle this
  9200. // correctly. We don't want to indicate `false` though if it
  9201. // actually skipped valid characters.
  9202. return cursor;
  9203. }
  9204. return false;
  9205. };
  9206. }
  9207. var skipWhitespace = skip(/\s/);
  9208. var skipSpaces = skip(" \t");
  9209. var skipToLineEnd = skip(",; \t");
  9210. var skipEverythingButNewLine = skip(/[^\r\n]/);
  9211. function skipInlineComment(text, index) {
  9212. if (index === false) {
  9213. return false;
  9214. }
  9215. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  9216. for (var i = index + 2; i < text.length; ++i) {
  9217. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  9218. return i + 2;
  9219. }
  9220. }
  9221. }
  9222. return index;
  9223. }
  9224. function skipTrailingComment(text, index) {
  9225. if (index === false) {
  9226. return false;
  9227. }
  9228. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  9229. return skipEverythingButNewLine(text, index);
  9230. }
  9231. return index;
  9232. } // This one doesn't use the above helper function because it wants to
  9233. // test \r\n in order and `skip` doesn't support ordering and we only
  9234. // want to skip one newline. It's simple to implement.
  9235. function skipNewline$1(text, index, opts) {
  9236. var backwards = opts && opts.backwards;
  9237. if (index === false) {
  9238. return false;
  9239. }
  9240. var atIndex = text.charAt(index);
  9241. if (backwards) {
  9242. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  9243. return index - 2;
  9244. }
  9245. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  9246. return index - 1;
  9247. }
  9248. } else {
  9249. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  9250. return index + 2;
  9251. }
  9252. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  9253. return index + 1;
  9254. }
  9255. }
  9256. return index;
  9257. }
  9258. function hasNewline$1(text, index, opts) {
  9259. opts = opts || {};
  9260. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  9261. var idx2 = skipNewline$1(text, idx, opts);
  9262. return idx !== idx2;
  9263. }
  9264. function hasNewlineInRange(text, start, end) {
  9265. for (var i = start; i < end; ++i) {
  9266. if (text.charAt(i) === "\n") {
  9267. return true;
  9268. }
  9269. }
  9270. return false;
  9271. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  9272. function isPreviousLineEmpty$1(text, node, locStart) {
  9273. var idx = locStart(node) - 1;
  9274. idx = skipSpaces(text, idx, {
  9275. backwards: true
  9276. });
  9277. idx = skipNewline$1(text, idx, {
  9278. backwards: true
  9279. });
  9280. idx = skipSpaces(text, idx, {
  9281. backwards: true
  9282. });
  9283. var idx2 = skipNewline$1(text, idx, {
  9284. backwards: true
  9285. });
  9286. return idx !== idx2;
  9287. }
  9288. function isNextLineEmptyAfterIndex(text, index) {
  9289. var oldIdx = null;
  9290. var idx = index;
  9291. while (idx !== oldIdx) {
  9292. // We need to skip all the potential trailing inline comments
  9293. oldIdx = idx;
  9294. idx = skipToLineEnd(text, idx);
  9295. idx = skipInlineComment(text, idx);
  9296. idx = skipSpaces(text, idx);
  9297. }
  9298. idx = skipTrailingComment(text, idx);
  9299. idx = skipNewline$1(text, idx);
  9300. return hasNewline$1(text, idx);
  9301. }
  9302. function isNextLineEmpty(text, node, locEnd) {
  9303. return isNextLineEmptyAfterIndex(text, locEnd(node));
  9304. }
  9305. function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
  9306. var oldIdx = null;
  9307. while (idx !== oldIdx) {
  9308. oldIdx = idx;
  9309. idx = skipSpaces(text, idx);
  9310. idx = skipInlineComment(text, idx);
  9311. idx = skipTrailingComment(text, idx);
  9312. idx = skipNewline$1(text, idx);
  9313. }
  9314. return idx;
  9315. }
  9316. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  9317. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
  9318. }
  9319. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  9320. return text.charAt(getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  9321. }
  9322. function hasSpaces(text, index, opts) {
  9323. opts = opts || {};
  9324. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  9325. return idx !== index;
  9326. }
  9327. function setLocStart(node, index) {
  9328. if (node.range) {
  9329. node.range[0] = index;
  9330. } else {
  9331. node.start = index;
  9332. }
  9333. }
  9334. function setLocEnd(node, index) {
  9335. if (node.range) {
  9336. node.range[1] = index;
  9337. } else {
  9338. node.end = index;
  9339. }
  9340. }
  9341. var PRECEDENCE = {};
  9342. [["|>"], ["||", "??"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(function (tier, i) {
  9343. tier.forEach(function (op) {
  9344. PRECEDENCE[op] = i;
  9345. });
  9346. });
  9347. function getPrecedence(op) {
  9348. return PRECEDENCE[op];
  9349. }
  9350. var equalityOperators = {
  9351. "==": true,
  9352. "!=": true,
  9353. "===": true,
  9354. "!==": true
  9355. };
  9356. var multiplicativeOperators = {
  9357. "*": true,
  9358. "/": true,
  9359. "%": true
  9360. };
  9361. var bitshiftOperators = {
  9362. ">>": true,
  9363. ">>>": true,
  9364. "<<": true
  9365. };
  9366. function shouldFlatten(parentOp, nodeOp) {
  9367. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  9368. return false;
  9369. } // ** is right-associative
  9370. // x ** y ** z --> x ** (y ** z)
  9371. if (parentOp === "**") {
  9372. return false;
  9373. } // x == y == z --> (x == y) == z
  9374. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  9375. return false;
  9376. } // x * y % z --> (x * y) % z
  9377. if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
  9378. return false;
  9379. } // x * y / z --> (x * y) / z
  9380. // x / y * z --> (x / y) * z
  9381. if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
  9382. return false;
  9383. } // x << y << z --> (x << y) << z
  9384. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  9385. return false;
  9386. }
  9387. return true;
  9388. }
  9389. function isBitwiseOperator(operator) {
  9390. return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
  9391. } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
  9392. // holds) `function`, `class`, or `do {}`. Will be overzealous if there's
  9393. // already necessary grouping parentheses.
  9394. function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
  9395. node = getLeftMost(node);
  9396. switch (node.type) {
  9397. case "FunctionExpression":
  9398. case "ClassExpression":
  9399. case "DoExpression":
  9400. return forbidFunctionClassAndDoExpr;
  9401. case "ObjectExpression":
  9402. return true;
  9403. case "MemberExpression":
  9404. return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  9405. case "TaggedTemplateExpression":
  9406. if (node.tag.type === "FunctionExpression") {
  9407. // IIFEs are always already parenthesized
  9408. return false;
  9409. }
  9410. return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
  9411. case "CallExpression":
  9412. if (node.callee.type === "FunctionExpression") {
  9413. // IIFEs are always already parenthesized
  9414. return false;
  9415. }
  9416. return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
  9417. case "ConditionalExpression":
  9418. return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
  9419. case "UpdateExpression":
  9420. return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
  9421. case "BindExpression":
  9422. return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  9423. case "SequenceExpression":
  9424. return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
  9425. case "TSAsExpression":
  9426. return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
  9427. default:
  9428. return false;
  9429. }
  9430. }
  9431. function getLeftMost(node) {
  9432. if (node.left) {
  9433. return getLeftMost(node.left);
  9434. }
  9435. return node;
  9436. }
  9437. function getAlignmentSize(value, tabWidth, startIndex) {
  9438. startIndex = startIndex || 0;
  9439. var size = 0;
  9440. for (var i = startIndex; i < value.length; ++i) {
  9441. if (value[i] === "\t") {
  9442. // Tabs behave in a way that they are aligned to the nearest
  9443. // multiple of tabWidth:
  9444. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  9445. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  9446. size = size + tabWidth - size % tabWidth;
  9447. } else {
  9448. size++;
  9449. }
  9450. }
  9451. return size;
  9452. }
  9453. function getIndentSize(value, tabWidth) {
  9454. var lastNewlineIndex = value.lastIndexOf("\n");
  9455. if (lastNewlineIndex === -1) {
  9456. return 0;
  9457. }
  9458. return getAlignmentSize( // All the leading whitespaces
  9459. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0], tabWidth);
  9460. }
  9461. function getPreferredQuote(raw, preferredQuote) {
  9462. // `rawContent` is the string exactly like it appeared in the input source
  9463. // code, without its enclosing quotes.
  9464. var rawContent = raw.slice(1, -1);
  9465. var double = {
  9466. quote: '"',
  9467. regex: /"/g
  9468. };
  9469. var single = {
  9470. quote: "'",
  9471. regex: /'/g
  9472. };
  9473. var preferred = preferredQuote === "'" ? single : double;
  9474. var alternate = preferred === single ? double : single;
  9475. var result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
  9476. // the string, we might want to enclose with the alternate quote instead, to
  9477. // minimize the number of escaped quotes.
  9478. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  9479. var numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  9480. var numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  9481. result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
  9482. }
  9483. return result;
  9484. }
  9485. function printString(raw, options, isDirectiveLiteral) {
  9486. // `rawContent` is the string exactly like it appeared in the input source
  9487. // code, without its enclosing quotes.
  9488. var rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
  9489. // the quotes on a DirectiveLiteral.
  9490. var canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
  9491. var enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
  9492. // change the escape sequences they use.
  9493. // See https://github.com/prettier/prettier/issues/1555
  9494. // and https://tc39.github.io/ecma262/#directive-prologue
  9495. if (isDirectiveLiteral) {
  9496. if (canChangeDirectiveQuotes) {
  9497. return enclosingQuote + rawContent + enclosingQuote;
  9498. }
  9499. return raw;
  9500. } // It might sound unnecessary to use `makeString` even if the string already
  9501. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  9502. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  9503. // sure that we consistently output the minimum amount of escaped quotes.
  9504. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.embeddedInHtml));
  9505. }
  9506. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  9507. var otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  9508. var regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
  9509. // enclose `rawContent` with `enclosingQuote`.
  9510. var newContent = rawContent.replace(regex, function (match, escaped, quote) {
  9511. // If we matched an escape, and the escaped character is a quote of the
  9512. // other type than we intend to enclose the string with, there's no need for
  9513. // it to be escaped, so return it _without_ the backslash.
  9514. if (escaped === otherQuote) {
  9515. return escaped;
  9516. } // If we matched an unescaped quote and it is of the _same_ type as we
  9517. // intend to enclose the string with, it must be escaped, so return it with
  9518. // a backslash.
  9519. if (quote === enclosingQuote) {
  9520. return "\\" + quote;
  9521. }
  9522. if (quote) {
  9523. return quote;
  9524. } // Unescape any unnecessarily escaped character.
  9525. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  9526. return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) ? escaped : "\\" + escaped;
  9527. });
  9528. return enclosingQuote + newContent + enclosingQuote;
  9529. }
  9530. function printNumber(rawNumber) {
  9531. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  9532. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  9533. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  9534. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  9535. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  9536. .replace(/\.(?=e|$)/, "");
  9537. }
  9538. function getMaxContinuousCount(str, target) {
  9539. var results = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  9540. if (results === null) {
  9541. return 0;
  9542. }
  9543. return results.reduce(function (maxCount, result) {
  9544. return Math.max(maxCount, result.length / target.length);
  9545. }, 0);
  9546. }
  9547. function getMinNotPresentContinuousCount(str, target) {
  9548. var matches = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  9549. if (matches === null) {
  9550. return 0;
  9551. }
  9552. var countPresent = new Map();
  9553. var max = 0;
  9554. var _iteratorNormalCompletion = true;
  9555. var _didIteratorError = false;
  9556. var _iteratorError = undefined;
  9557. try {
  9558. for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  9559. var match = _step.value;
  9560. var count = match.length / target.length;
  9561. countPresent.set(count, true);
  9562. if (count > max) {
  9563. max = count;
  9564. }
  9565. }
  9566. } catch (err) {
  9567. _didIteratorError = true;
  9568. _iteratorError = err;
  9569. } finally {
  9570. try {
  9571. if (!_iteratorNormalCompletion && _iterator.return != null) {
  9572. _iterator.return();
  9573. }
  9574. } finally {
  9575. if (_didIteratorError) {
  9576. throw _iteratorError;
  9577. }
  9578. }
  9579. }
  9580. for (var i = 1; i < max; i++) {
  9581. if (!countPresent.get(i)) {
  9582. return i;
  9583. }
  9584. }
  9585. return max + 1;
  9586. }
  9587. function getStringWidth$1(text) {
  9588. if (!text) {
  9589. return 0;
  9590. } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
  9591. if (!notAsciiRegex.test(text)) {
  9592. return text.length;
  9593. }
  9594. return stringWidth(text);
  9595. }
  9596. function hasIgnoreComment(path$$1) {
  9597. var node = path$$1.getValue();
  9598. return hasNodeIgnoreComment(node);
  9599. }
  9600. function hasNodeIgnoreComment(node) {
  9601. return node && node.comments && node.comments.length > 0 && node.comments.some(function (comment) {
  9602. return comment.value.trim() === "prettier-ignore";
  9603. });
  9604. }
  9605. function matchAncestorTypes(path$$1, types, index) {
  9606. index = index || 0;
  9607. types = types.slice();
  9608. while (types.length) {
  9609. var parent = path$$1.getParentNode(index);
  9610. var type = types.shift();
  9611. if (!parent || parent.type !== type) {
  9612. return false;
  9613. }
  9614. index++;
  9615. }
  9616. return true;
  9617. }
  9618. function addCommentHelper(node, comment) {
  9619. var comments = node.comments || (node.comments = []);
  9620. comments.push(comment);
  9621. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  9622. // We already "print" it via the raw text, we don't need to re-print it as a
  9623. // comment
  9624. if (node.type === "JSXText") {
  9625. comment.printed = true;
  9626. }
  9627. }
  9628. function addLeadingComment$1(node, comment) {
  9629. comment.leading = true;
  9630. comment.trailing = false;
  9631. addCommentHelper(node, comment);
  9632. }
  9633. function addDanglingComment$1(node, comment) {
  9634. comment.leading = false;
  9635. comment.trailing = false;
  9636. addCommentHelper(node, comment);
  9637. }
  9638. function addTrailingComment$1(node, comment) {
  9639. comment.leading = false;
  9640. comment.trailing = true;
  9641. addCommentHelper(node, comment);
  9642. }
  9643. function isWithinParentArrayProperty(path$$1, propertyName) {
  9644. var node = path$$1.getValue();
  9645. var parent = path$$1.getParentNode();
  9646. if (parent == null) {
  9647. return false;
  9648. }
  9649. if (!Array.isArray(parent[propertyName])) {
  9650. return false;
  9651. }
  9652. var key = path$$1.getName();
  9653. return parent[propertyName][key] === node;
  9654. }
  9655. function replaceEndOfLineWith(text, replacement) {
  9656. var parts = [];
  9657. var _iteratorNormalCompletion2 = true;
  9658. var _didIteratorError2 = false;
  9659. var _iteratorError2 = undefined;
  9660. try {
  9661. for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  9662. var part = _step2.value;
  9663. if (parts.length !== 0) {
  9664. parts.push(replacement);
  9665. }
  9666. parts.push(part);
  9667. }
  9668. } catch (err) {
  9669. _didIteratorError2 = true;
  9670. _iteratorError2 = err;
  9671. } finally {
  9672. try {
  9673. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  9674. _iterator2.return();
  9675. }
  9676. } finally {
  9677. if (_didIteratorError2) {
  9678. throw _iteratorError2;
  9679. }
  9680. }
  9681. }
  9682. return parts;
  9683. }
  9684. var util$1 = {
  9685. replaceEndOfLineWith,
  9686. getStringWidth: getStringWidth$1,
  9687. getMaxContinuousCount,
  9688. getMinNotPresentContinuousCount,
  9689. getPrecedence,
  9690. shouldFlatten,
  9691. isBitwiseOperator,
  9692. isExportDeclaration,
  9693. getParentExportDeclaration,
  9694. getPenultimate,
  9695. getLast,
  9696. getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
  9697. getNextNonSpaceNonCommentCharacterIndex,
  9698. getNextNonSpaceNonCommentCharacter,
  9699. skip,
  9700. skipWhitespace,
  9701. skipSpaces,
  9702. skipToLineEnd,
  9703. skipEverythingButNewLine,
  9704. skipInlineComment,
  9705. skipTrailingComment,
  9706. skipNewline: skipNewline$1,
  9707. isNextLineEmptyAfterIndex,
  9708. isNextLineEmpty,
  9709. isPreviousLineEmpty: isPreviousLineEmpty$1,
  9710. hasNewline: hasNewline$1,
  9711. hasNewlineInRange,
  9712. hasSpaces,
  9713. setLocStart,
  9714. setLocEnd,
  9715. startsWithNoLookaheadToken,
  9716. getAlignmentSize,
  9717. getIndentSize,
  9718. getPreferredQuote,
  9719. printString,
  9720. printNumber,
  9721. hasIgnoreComment,
  9722. hasNodeIgnoreComment,
  9723. makeString,
  9724. matchAncestorTypes,
  9725. addLeadingComment: addLeadingComment$1,
  9726. addDanglingComment: addDanglingComment$1,
  9727. addTrailingComment: addTrailingComment$1,
  9728. isWithinParentArrayProperty
  9729. };
  9730. function guessEndOfLine$1(text) {
  9731. var index = text.indexOf("\r");
  9732. if (index >= 0) {
  9733. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  9734. }
  9735. return "lf";
  9736. }
  9737. function convertEndOfLineToChars$2(value) {
  9738. switch (value) {
  9739. case "cr":
  9740. return "\r";
  9741. case "crlf":
  9742. return "\r\n";
  9743. default:
  9744. return "\n";
  9745. }
  9746. }
  9747. var endOfLine = {
  9748. guessEndOfLine: guessEndOfLine$1,
  9749. convertEndOfLineToChars: convertEndOfLineToChars$2
  9750. };
  9751. var getStringWidth = util$1.getStringWidth;
  9752. var convertEndOfLineToChars$1 = endOfLine.convertEndOfLineToChars;
  9753. var concat$2 = docBuilders.concat;
  9754. var fill$1 = docBuilders.fill;
  9755. var cursor$2 = docBuilders.cursor;
  9756. /** @type {{[groupId: PropertyKey]: MODE}} */
  9757. var groupModeMap;
  9758. var MODE_BREAK = 1;
  9759. var MODE_FLAT = 2;
  9760. function rootIndent() {
  9761. return {
  9762. value: "",
  9763. length: 0,
  9764. queue: []
  9765. };
  9766. }
  9767. function makeIndent(ind, options) {
  9768. return generateInd(ind, {
  9769. type: "indent"
  9770. }, options);
  9771. }
  9772. function makeAlign(ind, n, options) {
  9773. return n === -Infinity ? ind.root || rootIndent() : n < 0 ? generateInd(ind, {
  9774. type: "dedent"
  9775. }, options) : !n ? ind : n.type === "root" ? Object.assign({}, ind, {
  9776. root: ind
  9777. }) : typeof n === "string" ? generateInd(ind, {
  9778. type: "stringAlign",
  9779. n
  9780. }, options) : generateInd(ind, {
  9781. type: "numberAlign",
  9782. n
  9783. }, options);
  9784. }
  9785. function generateInd(ind, newPart, options) {
  9786. var queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  9787. var value = "";
  9788. var length = 0;
  9789. var lastTabs = 0;
  9790. var lastSpaces = 0;
  9791. var _iteratorNormalCompletion = true;
  9792. var _didIteratorError = false;
  9793. var _iteratorError = undefined;
  9794. try {
  9795. for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  9796. var part = _step.value;
  9797. switch (part.type) {
  9798. case "indent":
  9799. flush();
  9800. if (options.useTabs) {
  9801. addTabs(1);
  9802. } else {
  9803. addSpaces(options.tabWidth);
  9804. }
  9805. break;
  9806. case "stringAlign":
  9807. flush();
  9808. value += part.n;
  9809. length += part.n.length;
  9810. break;
  9811. case "numberAlign":
  9812. lastTabs += 1;
  9813. lastSpaces += part.n;
  9814. break;
  9815. /* istanbul ignore next */
  9816. default:
  9817. throw new Error(`Unexpected type '${part.type}'`);
  9818. }
  9819. }
  9820. } catch (err) {
  9821. _didIteratorError = true;
  9822. _iteratorError = err;
  9823. } finally {
  9824. try {
  9825. if (!_iteratorNormalCompletion && _iterator.return != null) {
  9826. _iterator.return();
  9827. }
  9828. } finally {
  9829. if (_didIteratorError) {
  9830. throw _iteratorError;
  9831. }
  9832. }
  9833. }
  9834. flushSpaces();
  9835. return Object.assign({}, ind, {
  9836. value,
  9837. length,
  9838. queue
  9839. });
  9840. function addTabs(count) {
  9841. value += "\t".repeat(count);
  9842. length += options.tabWidth * count;
  9843. }
  9844. function addSpaces(count) {
  9845. value += " ".repeat(count);
  9846. length += count;
  9847. }
  9848. function flush() {
  9849. if (options.useTabs) {
  9850. flushTabs();
  9851. } else {
  9852. flushSpaces();
  9853. }
  9854. }
  9855. function flushTabs() {
  9856. if (lastTabs > 0) {
  9857. addTabs(lastTabs);
  9858. }
  9859. resetLast();
  9860. }
  9861. function flushSpaces() {
  9862. if (lastSpaces > 0) {
  9863. addSpaces(lastSpaces);
  9864. }
  9865. resetLast();
  9866. }
  9867. function resetLast() {
  9868. lastTabs = 0;
  9869. lastSpaces = 0;
  9870. }
  9871. }
  9872. function trim$1(out) {
  9873. if (out.length === 0) {
  9874. return 0;
  9875. }
  9876. var trimCount = 0; // Trim whitespace at the end of line
  9877. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[ \t]*$/)) {
  9878. trimCount += out.pop().length;
  9879. }
  9880. if (out.length && typeof out[out.length - 1] === "string") {
  9881. var trimmed = out[out.length - 1].replace(/[ \t]*$/, "");
  9882. trimCount += out[out.length - 1].length - trimmed.length;
  9883. out[out.length - 1] = trimmed;
  9884. }
  9885. return trimCount;
  9886. }
  9887. function fits(next, restCommands, width, options, mustBeFlat) {
  9888. var restIdx = restCommands.length;
  9889. var cmds = [next]; // `out` is only used for width counting because `trim` requires to look
  9890. // backwards for space characters.
  9891. var out = [];
  9892. while (width >= 0) {
  9893. if (cmds.length === 0) {
  9894. if (restIdx === 0) {
  9895. return true;
  9896. }
  9897. cmds.push(restCommands[restIdx - 1]);
  9898. restIdx--;
  9899. continue;
  9900. }
  9901. var x = cmds.pop();
  9902. var ind = x[0];
  9903. var mode = x[1];
  9904. var doc = x[2];
  9905. if (typeof doc === "string") {
  9906. out.push(doc);
  9907. width -= getStringWidth(doc);
  9908. } else {
  9909. switch (doc.type) {
  9910. case "concat":
  9911. for (var i = doc.parts.length - 1; i >= 0; i--) {
  9912. cmds.push([ind, mode, doc.parts[i]]);
  9913. }
  9914. break;
  9915. case "indent":
  9916. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  9917. break;
  9918. case "align":
  9919. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  9920. break;
  9921. case "trim":
  9922. width += trim$1(out);
  9923. break;
  9924. case "group":
  9925. if (mustBeFlat && doc.break) {
  9926. return false;
  9927. }
  9928. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  9929. if (doc.id) {
  9930. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  9931. }
  9932. break;
  9933. case "fill":
  9934. for (var _i = doc.parts.length - 1; _i >= 0; _i--) {
  9935. cmds.push([ind, mode, doc.parts[_i]]);
  9936. }
  9937. break;
  9938. case "if-break":
  9939. {
  9940. var groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  9941. if (groupMode === MODE_BREAK) {
  9942. if (doc.breakContents) {
  9943. cmds.push([ind, mode, doc.breakContents]);
  9944. }
  9945. }
  9946. if (groupMode === MODE_FLAT) {
  9947. if (doc.flatContents) {
  9948. cmds.push([ind, mode, doc.flatContents]);
  9949. }
  9950. }
  9951. break;
  9952. }
  9953. case "line":
  9954. switch (mode) {
  9955. // fallthrough
  9956. case MODE_FLAT:
  9957. if (!doc.hard) {
  9958. if (!doc.soft) {
  9959. out.push(" ");
  9960. width -= 1;
  9961. }
  9962. break;
  9963. }
  9964. return true;
  9965. case MODE_BREAK:
  9966. return true;
  9967. }
  9968. break;
  9969. }
  9970. }
  9971. }
  9972. return false;
  9973. }
  9974. function printDocToString$1(doc, options) {
  9975. groupModeMap = {};
  9976. var width = options.printWidth;
  9977. var newLine = convertEndOfLineToChars$1(options.endOfLine);
  9978. var pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  9979. // while loop which is much faster. The while loop below adds new
  9980. // cmds to the array instead of recursively calling `print`.
  9981. var cmds = [[rootIndent(), MODE_BREAK, doc]];
  9982. var out = [];
  9983. var shouldRemeasure = false;
  9984. var lineSuffix = [];
  9985. while (cmds.length !== 0) {
  9986. var x = cmds.pop();
  9987. var ind = x[0];
  9988. var mode = x[1];
  9989. var _doc = x[2];
  9990. if (typeof _doc === "string") {
  9991. out.push(_doc);
  9992. pos += getStringWidth(_doc);
  9993. } else {
  9994. switch (_doc.type) {
  9995. case "cursor":
  9996. out.push(cursor$2.placeholder);
  9997. break;
  9998. case "concat":
  9999. for (var i = _doc.parts.length - 1; i >= 0; i--) {
  10000. cmds.push([ind, mode, _doc.parts[i]]);
  10001. }
  10002. break;
  10003. case "indent":
  10004. cmds.push([makeIndent(ind, options), mode, _doc.contents]);
  10005. break;
  10006. case "align":
  10007. cmds.push([makeAlign(ind, _doc.n, options), mode, _doc.contents]);
  10008. break;
  10009. case "trim":
  10010. pos -= trim$1(out);
  10011. break;
  10012. case "group":
  10013. switch (mode) {
  10014. case MODE_FLAT:
  10015. if (!shouldRemeasure) {
  10016. cmds.push([ind, _doc.break ? MODE_BREAK : MODE_FLAT, _doc.contents]);
  10017. break;
  10018. }
  10019. // fallthrough
  10020. case MODE_BREAK:
  10021. {
  10022. shouldRemeasure = false;
  10023. var next = [ind, MODE_FLAT, _doc.contents];
  10024. var rem = width - pos;
  10025. if (!_doc.break && fits(next, cmds, rem, options)) {
  10026. cmds.push(next);
  10027. } else {
  10028. // Expanded states are a rare case where a document
  10029. // can manually provide multiple representations of
  10030. // itself. It provides an array of documents
  10031. // going from the least expanded (most flattened)
  10032. // representation first to the most expanded. If a
  10033. // group has these, we need to manually go through
  10034. // these states and find the first one that fits.
  10035. if (_doc.expandedStates) {
  10036. var mostExpanded = _doc.expandedStates[_doc.expandedStates.length - 1];
  10037. if (_doc.break) {
  10038. cmds.push([ind, MODE_BREAK, mostExpanded]);
  10039. break;
  10040. } else {
  10041. for (var _i2 = 1; _i2 < _doc.expandedStates.length + 1; _i2++) {
  10042. if (_i2 >= _doc.expandedStates.length) {
  10043. cmds.push([ind, MODE_BREAK, mostExpanded]);
  10044. break;
  10045. } else {
  10046. var state = _doc.expandedStates[_i2];
  10047. var cmd = [ind, MODE_FLAT, state];
  10048. if (fits(cmd, cmds, rem, options)) {
  10049. cmds.push(cmd);
  10050. break;
  10051. }
  10052. }
  10053. }
  10054. }
  10055. } else {
  10056. cmds.push([ind, MODE_BREAK, _doc.contents]);
  10057. }
  10058. }
  10059. break;
  10060. }
  10061. }
  10062. if (_doc.id) {
  10063. groupModeMap[_doc.id] = cmds[cmds.length - 1][1];
  10064. }
  10065. break;
  10066. // Fills each line with as much code as possible before moving to a new
  10067. // line with the same indentation.
  10068. //
  10069. // Expects doc.parts to be an array of alternating content and
  10070. // whitespace. The whitespace contains the linebreaks.
  10071. //
  10072. // For example:
  10073. // ["I", line, "love", line, "monkeys"]
  10074. // or
  10075. // [{ type: group, ... }, softline, { type: group, ... }]
  10076. //
  10077. // It uses this parts structure to handle three main layout cases:
  10078. // * The first two content items fit on the same line without
  10079. // breaking
  10080. // -> output the first content item and the whitespace "flat".
  10081. // * Only the first content item fits on the line without breaking
  10082. // -> output the first content item "flat" and the whitespace with
  10083. // "break".
  10084. // * Neither content item fits on the line without breaking
  10085. // -> output the first content item and the whitespace with "break".
  10086. case "fill":
  10087. {
  10088. var _rem = width - pos;
  10089. var parts = _doc.parts;
  10090. if (parts.length === 0) {
  10091. break;
  10092. }
  10093. var content = parts[0];
  10094. var contentFlatCmd = [ind, MODE_FLAT, content];
  10095. var contentBreakCmd = [ind, MODE_BREAK, content];
  10096. var contentFits = fits(contentFlatCmd, [], _rem, options, true);
  10097. if (parts.length === 1) {
  10098. if (contentFits) {
  10099. cmds.push(contentFlatCmd);
  10100. } else {
  10101. cmds.push(contentBreakCmd);
  10102. }
  10103. break;
  10104. }
  10105. var whitespace = parts[1];
  10106. var whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  10107. var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  10108. if (parts.length === 2) {
  10109. if (contentFits) {
  10110. cmds.push(whitespaceFlatCmd);
  10111. cmds.push(contentFlatCmd);
  10112. } else {
  10113. cmds.push(whitespaceBreakCmd);
  10114. cmds.push(contentBreakCmd);
  10115. }
  10116. break;
  10117. } // At this point we've handled the first pair (context, separator)
  10118. // and will create a new fill doc for the rest of the content.
  10119. // Ideally we wouldn't mutate the array here but coping all the
  10120. // elements to a new array would make this algorithm quadratic,
  10121. // which is unusable for large arrays (e.g. large texts in JSX).
  10122. parts.splice(0, 2);
  10123. var remainingCmd = [ind, mode, fill$1(parts)];
  10124. var secondContent = parts[0];
  10125. var firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$2([content, whitespace, secondContent])];
  10126. var firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], _rem, options, true);
  10127. if (firstAndSecondContentFits) {
  10128. cmds.push(remainingCmd);
  10129. cmds.push(whitespaceFlatCmd);
  10130. cmds.push(contentFlatCmd);
  10131. } else if (contentFits) {
  10132. cmds.push(remainingCmd);
  10133. cmds.push(whitespaceBreakCmd);
  10134. cmds.push(contentFlatCmd);
  10135. } else {
  10136. cmds.push(remainingCmd);
  10137. cmds.push(whitespaceBreakCmd);
  10138. cmds.push(contentBreakCmd);
  10139. }
  10140. break;
  10141. }
  10142. case "if-break":
  10143. {
  10144. var groupMode = _doc.groupId ? groupModeMap[_doc.groupId] : mode;
  10145. if (groupMode === MODE_BREAK) {
  10146. if (_doc.breakContents) {
  10147. cmds.push([ind, mode, _doc.breakContents]);
  10148. }
  10149. }
  10150. if (groupMode === MODE_FLAT) {
  10151. if (_doc.flatContents) {
  10152. cmds.push([ind, mode, _doc.flatContents]);
  10153. }
  10154. }
  10155. break;
  10156. }
  10157. case "line-suffix":
  10158. lineSuffix.push([ind, mode, _doc.contents]);
  10159. break;
  10160. case "line-suffix-boundary":
  10161. if (lineSuffix.length > 0) {
  10162. cmds.push([ind, mode, {
  10163. type: "line",
  10164. hard: true
  10165. }]);
  10166. }
  10167. break;
  10168. case "line":
  10169. switch (mode) {
  10170. case MODE_FLAT:
  10171. if (!_doc.hard) {
  10172. if (!_doc.soft) {
  10173. out.push(" ");
  10174. pos += 1;
  10175. }
  10176. break;
  10177. } else {
  10178. // This line was forced into the output even if we
  10179. // were in flattened mode, so we need to tell the next
  10180. // group that no matter what, it needs to remeasure
  10181. // because the previous measurement didn't accurately
  10182. // capture the entire expression (this is necessary
  10183. // for nested groups)
  10184. shouldRemeasure = true;
  10185. }
  10186. // fallthrough
  10187. case MODE_BREAK:
  10188. if (lineSuffix.length) {
  10189. cmds.push([ind, mode, _doc]);
  10190. [].push.apply(cmds, lineSuffix.reverse());
  10191. lineSuffix = [];
  10192. break;
  10193. }
  10194. if (_doc.literal) {
  10195. if (ind.root) {
  10196. out.push(newLine, ind.root.value);
  10197. pos = ind.root.length;
  10198. } else {
  10199. out.push(newLine);
  10200. pos = 0;
  10201. }
  10202. } else {
  10203. pos -= trim$1(out);
  10204. out.push(newLine + ind.value);
  10205. pos = ind.length;
  10206. }
  10207. break;
  10208. }
  10209. break;
  10210. default:
  10211. }
  10212. }
  10213. }
  10214. var cursorPlaceholderIndex = out.indexOf(cursor$2.placeholder);
  10215. if (cursorPlaceholderIndex !== -1) {
  10216. var otherCursorPlaceholderIndex = out.indexOf(cursor$2.placeholder, cursorPlaceholderIndex + 1);
  10217. var beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  10218. var aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  10219. var afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  10220. return {
  10221. formatted: beforeCursor + aroundCursor + afterCursor,
  10222. cursorNodeStart: beforeCursor.length,
  10223. cursorNodeText: aroundCursor
  10224. };
  10225. }
  10226. return {
  10227. formatted: out.join("")
  10228. };
  10229. }
  10230. var docPrinter = {
  10231. printDocToString: printDocToString$1
  10232. };
  10233. var traverseDocOnExitStackMarker = {};
  10234. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  10235. var docsStack = [doc];
  10236. while (docsStack.length !== 0) {
  10237. var _doc = docsStack.pop();
  10238. if (_doc === traverseDocOnExitStackMarker) {
  10239. onExit(docsStack.pop());
  10240. continue;
  10241. }
  10242. var shouldRecurse = true;
  10243. if (onEnter) {
  10244. if (onEnter(_doc) === false) {
  10245. shouldRecurse = false;
  10246. }
  10247. }
  10248. if (onExit) {
  10249. docsStack.push(_doc);
  10250. docsStack.push(traverseDocOnExitStackMarker);
  10251. }
  10252. if (shouldRecurse) {
  10253. // When there are multiple parts to process,
  10254. // the parts need to be pushed onto the stack in reverse order,
  10255. // so that they are processed in the original order
  10256. // when the stack is popped.
  10257. if (_doc.type === "concat" || _doc.type === "fill") {
  10258. for (var ic = _doc.parts.length, i = ic - 1; i >= 0; --i) {
  10259. docsStack.push(_doc.parts[i]);
  10260. }
  10261. } else if (_doc.type === "if-break") {
  10262. if (_doc.flatContents) {
  10263. docsStack.push(_doc.flatContents);
  10264. }
  10265. if (_doc.breakContents) {
  10266. docsStack.push(_doc.breakContents);
  10267. }
  10268. } else if (_doc.type === "group" && _doc.expandedStates) {
  10269. if (shouldTraverseConditionalGroups) {
  10270. for (var _ic = _doc.expandedStates.length, _i = _ic - 1; _i >= 0; --_i) {
  10271. docsStack.push(_doc.expandedStates[_i]);
  10272. }
  10273. } else {
  10274. docsStack.push(_doc.contents);
  10275. }
  10276. } else if (_doc.contents) {
  10277. docsStack.push(_doc.contents);
  10278. }
  10279. }
  10280. }
  10281. }
  10282. function mapDoc$1(doc, cb) {
  10283. if (doc.type === "concat" || doc.type === "fill") {
  10284. var parts = doc.parts.map(function (part) {
  10285. return mapDoc$1(part, cb);
  10286. });
  10287. return cb(Object.assign({}, doc, {
  10288. parts
  10289. }));
  10290. } else if (doc.type === "if-break") {
  10291. var breakContents = doc.breakContents && mapDoc$1(doc.breakContents, cb);
  10292. var flatContents = doc.flatContents && mapDoc$1(doc.flatContents, cb);
  10293. return cb(Object.assign({}, doc, {
  10294. breakContents,
  10295. flatContents
  10296. }));
  10297. } else if (doc.contents) {
  10298. var contents = mapDoc$1(doc.contents, cb);
  10299. return cb(Object.assign({}, doc, {
  10300. contents
  10301. }));
  10302. }
  10303. return cb(doc);
  10304. }
  10305. function findInDoc(doc, fn, defaultValue) {
  10306. var result = defaultValue;
  10307. var hasStopped = false;
  10308. function findInDocOnEnterFn(doc) {
  10309. var maybeResult = fn(doc);
  10310. if (maybeResult !== undefined) {
  10311. hasStopped = true;
  10312. result = maybeResult;
  10313. }
  10314. if (hasStopped) {
  10315. return false;
  10316. }
  10317. }
  10318. traverseDoc(doc, findInDocOnEnterFn);
  10319. return result;
  10320. }
  10321. function isEmpty(n) {
  10322. return typeof n === "string" && n.length === 0;
  10323. }
  10324. function isLineNextFn(doc) {
  10325. if (typeof doc === "string") {
  10326. return false;
  10327. }
  10328. if (doc.type === "line") {
  10329. return true;
  10330. }
  10331. }
  10332. function isLineNext(doc) {
  10333. return findInDoc(doc, isLineNextFn, false);
  10334. }
  10335. function willBreakFn(doc) {
  10336. if (doc.type === "group" && doc.break) {
  10337. return true;
  10338. }
  10339. if (doc.type === "line" && doc.hard) {
  10340. return true;
  10341. }
  10342. if (doc.type === "break-parent") {
  10343. return true;
  10344. }
  10345. }
  10346. function willBreak(doc) {
  10347. return findInDoc(doc, willBreakFn, false);
  10348. }
  10349. function breakParentGroup(groupStack) {
  10350. if (groupStack.length > 0) {
  10351. var parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  10352. // the user is expected to manually handle what breaks.
  10353. if (!parentGroup.expandedStates) {
  10354. parentGroup.break = true;
  10355. }
  10356. }
  10357. return null;
  10358. }
  10359. function propagateBreaks(doc) {
  10360. var alreadyVisitedSet = new Set();
  10361. var groupStack = [];
  10362. function propagateBreaksOnEnterFn(doc) {
  10363. if (doc.type === "break-parent") {
  10364. breakParentGroup(groupStack);
  10365. }
  10366. if (doc.type === "group") {
  10367. groupStack.push(doc);
  10368. if (alreadyVisitedSet.has(doc)) {
  10369. return false;
  10370. }
  10371. alreadyVisitedSet.add(doc);
  10372. }
  10373. }
  10374. function propagateBreaksOnExitFn(doc) {
  10375. if (doc.type === "group") {
  10376. var group = groupStack.pop();
  10377. if (group.break) {
  10378. breakParentGroup(groupStack);
  10379. }
  10380. }
  10381. }
  10382. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
  10383. /* shouldTraverseConditionalGroups */
  10384. true);
  10385. }
  10386. function removeLinesFn(doc) {
  10387. // Force this doc into flat mode by statically converting all
  10388. // lines into spaces (or soft lines into nothing). Hard lines
  10389. // should still output because there's too great of a chance
  10390. // of breaking existing assumptions otherwise.
  10391. if (doc.type === "line" && !doc.hard) {
  10392. return doc.soft ? "" : " ";
  10393. } else if (doc.type === "if-break") {
  10394. return doc.flatContents || "";
  10395. }
  10396. return doc;
  10397. }
  10398. function removeLines(doc) {
  10399. return mapDoc$1(doc, removeLinesFn);
  10400. }
  10401. function stripTrailingHardline(doc) {
  10402. // HACK remove ending hardline, original PR: #1984
  10403. if (doc.type === "concat" && doc.parts.length !== 0) {
  10404. var lastPart = doc.parts[doc.parts.length - 1];
  10405. if (lastPart.type === "concat") {
  10406. if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
  10407. return {
  10408. type: "concat",
  10409. parts: doc.parts.slice(0, -1)
  10410. };
  10411. }
  10412. return {
  10413. type: "concat",
  10414. parts: doc.parts.slice(0, -1).concat(stripTrailingHardline(lastPart))
  10415. };
  10416. }
  10417. }
  10418. return doc;
  10419. }
  10420. var docUtils = {
  10421. isEmpty,
  10422. willBreak,
  10423. isLineNext,
  10424. traverseDoc,
  10425. findInDoc,
  10426. mapDoc: mapDoc$1,
  10427. propagateBreaks,
  10428. removeLines,
  10429. stripTrailingHardline
  10430. };
  10431. function flattenDoc(doc) {
  10432. if (doc.type === "concat") {
  10433. var res = [];
  10434. for (var i = 0; i < doc.parts.length; ++i) {
  10435. var doc2 = doc.parts[i];
  10436. if (typeof doc2 !== "string" && doc2.type === "concat") {
  10437. [].push.apply(res, flattenDoc(doc2).parts);
  10438. } else {
  10439. var flattened = flattenDoc(doc2);
  10440. if (flattened !== "") {
  10441. res.push(flattened);
  10442. }
  10443. }
  10444. }
  10445. return Object.assign({}, doc, {
  10446. parts: res
  10447. });
  10448. } else if (doc.type === "if-break") {
  10449. return Object.assign({}, doc, {
  10450. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  10451. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  10452. });
  10453. } else if (doc.type === "group") {
  10454. return Object.assign({}, doc, {
  10455. contents: flattenDoc(doc.contents),
  10456. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  10457. });
  10458. } else if (doc.contents) {
  10459. return Object.assign({}, doc, {
  10460. contents: flattenDoc(doc.contents)
  10461. });
  10462. }
  10463. return doc;
  10464. }
  10465. function printDoc(doc) {
  10466. if (typeof doc === "string") {
  10467. return JSON.stringify(doc);
  10468. }
  10469. if (doc.type === "line") {
  10470. if (doc.literal) {
  10471. return "literalline";
  10472. }
  10473. if (doc.hard) {
  10474. return "hardline";
  10475. }
  10476. if (doc.soft) {
  10477. return "softline";
  10478. }
  10479. return "line";
  10480. }
  10481. if (doc.type === "break-parent") {
  10482. return "breakParent";
  10483. }
  10484. if (doc.type === "trim") {
  10485. return "trim";
  10486. }
  10487. if (doc.type === "concat") {
  10488. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  10489. }
  10490. if (doc.type === "indent") {
  10491. return "indent(" + printDoc(doc.contents) + ")";
  10492. }
  10493. if (doc.type === "align") {
  10494. 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) + ")";
  10495. }
  10496. if (doc.type === "if-break") {
  10497. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  10498. }
  10499. if (doc.type === "group") {
  10500. if (doc.expandedStates) {
  10501. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  10502. }
  10503. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  10504. }
  10505. if (doc.type === "fill") {
  10506. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  10507. }
  10508. if (doc.type === "line-suffix") {
  10509. return "lineSuffix(" + printDoc(doc.contents) + ")";
  10510. }
  10511. if (doc.type === "line-suffix-boundary") {
  10512. return "lineSuffixBoundary";
  10513. }
  10514. throw new Error("Unknown doc type " + doc.type);
  10515. }
  10516. var docDebug = {
  10517. printDocToDebug: function printDocToDebug(doc) {
  10518. return printDoc(flattenDoc(doc));
  10519. }
  10520. };
  10521. var doc = {
  10522. builders: docBuilders,
  10523. printer: docPrinter,
  10524. utils: docUtils,
  10525. debug: docDebug
  10526. };
  10527. var mapDoc$2 = doc.utils.mapDoc;
  10528. function isNextLineEmpty$1(text, node, options) {
  10529. return util$1.isNextLineEmpty(text, node, options.locEnd);
  10530. }
  10531. function isPreviousLineEmpty$2(text, node, options) {
  10532. return util$1.isPreviousLineEmpty(text, node, options.locStart);
  10533. }
  10534. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  10535. return util$1.getNextNonSpaceNonCommentCharacterIndex(text, node, options.locEnd);
  10536. }
  10537. var utilShared = {
  10538. getMaxContinuousCount: util$1.getMaxContinuousCount,
  10539. getStringWidth: util$1.getStringWidth,
  10540. getAlignmentSize: util$1.getAlignmentSize,
  10541. getIndentSize: util$1.getIndentSize,
  10542. skip: util$1.skip,
  10543. skipWhitespace: util$1.skipWhitespace,
  10544. skipSpaces: util$1.skipSpaces,
  10545. skipNewline: util$1.skipNewline,
  10546. skipToLineEnd: util$1.skipToLineEnd,
  10547. skipEverythingButNewLine: util$1.skipEverythingButNewLine,
  10548. skipInlineComment: util$1.skipInlineComment,
  10549. skipTrailingComment: util$1.skipTrailingComment,
  10550. hasNewline: util$1.hasNewline,
  10551. hasNewlineInRange: util$1.hasNewlineInRange,
  10552. hasSpaces: util$1.hasSpaces,
  10553. isNextLineEmpty: isNextLineEmpty$1,
  10554. isNextLineEmptyAfterIndex: util$1.isNextLineEmptyAfterIndex,
  10555. isPreviousLineEmpty: isPreviousLineEmpty$2,
  10556. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  10557. mapDoc: mapDoc$2,
  10558. // TODO: remove in 2.0, we already exposed it in docUtils
  10559. makeString: util$1.makeString,
  10560. addLeadingComment: util$1.addLeadingComment,
  10561. addDanglingComment: util$1.addDanglingComment,
  10562. addTrailingComment: util$1.addTrailingComment
  10563. };
  10564. var _require$$0$builders = doc.builders;
  10565. var concat = _require$$0$builders.concat;
  10566. var hardline = _require$$0$builders.hardline;
  10567. var breakParent = _require$$0$builders.breakParent;
  10568. var indent = _require$$0$builders.indent;
  10569. var lineSuffix = _require$$0$builders.lineSuffix;
  10570. var join = _require$$0$builders.join;
  10571. var cursor = _require$$0$builders.cursor;
  10572. var hasNewline = util$1.hasNewline;
  10573. var skipNewline = util$1.skipNewline;
  10574. var isPreviousLineEmpty = util$1.isPreviousLineEmpty;
  10575. var addLeadingComment = utilShared.addLeadingComment;
  10576. var addDanglingComment = utilShared.addDanglingComment;
  10577. var addTrailingComment = utilShared.addTrailingComment;
  10578. var childNodesCacheKey = Symbol("child-nodes");
  10579. function getSortedChildNodes(node, options, resultArray) {
  10580. if (!node) {
  10581. return;
  10582. }
  10583. var printer = options.printer,
  10584. locStart = options.locStart,
  10585. locEnd = options.locEnd;
  10586. if (resultArray) {
  10587. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  10588. // This reverse insertion sort almost always takes constant
  10589. // time because we almost always (maybe always?) append the
  10590. // nodes in order anyway.
  10591. var i;
  10592. for (i = resultArray.length - 1; i >= 0; --i) {
  10593. if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
  10594. break;
  10595. }
  10596. }
  10597. resultArray.splice(i + 1, 0, node);
  10598. return;
  10599. }
  10600. } else if (node[childNodesCacheKey]) {
  10601. return node[childNodesCacheKey];
  10602. }
  10603. var childNodes;
  10604. if (printer.getCommentChildNodes) {
  10605. childNodes = printer.getCommentChildNodes(node);
  10606. } else if (node && typeof node === "object") {
  10607. childNodes = Object.keys(node).filter(function (n) {
  10608. return n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode";
  10609. }).map(function (n) {
  10610. return node[n];
  10611. });
  10612. }
  10613. if (!childNodes) {
  10614. return;
  10615. }
  10616. if (!resultArray) {
  10617. Object.defineProperty(node, childNodesCacheKey, {
  10618. value: resultArray = [],
  10619. enumerable: false
  10620. });
  10621. }
  10622. childNodes.forEach(function (childNode) {
  10623. getSortedChildNodes(childNode, options, resultArray);
  10624. });
  10625. return resultArray;
  10626. } // As efficiently as possible, decorate the comment object with
  10627. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  10628. // least one of which is guaranteed to be defined.
  10629. function decorateComment(node, comment, options) {
  10630. var locStart = options.locStart,
  10631. locEnd = options.locEnd;
  10632. var childNodes = getSortedChildNodes(node, options);
  10633. var precedingNode;
  10634. var followingNode; // Time to dust off the old binary search robes and wizard hat.
  10635. var left = 0;
  10636. var right = childNodes.length;
  10637. while (left < right) {
  10638. var middle = left + right >> 1;
  10639. var child = childNodes[middle];
  10640. if (locStart(child) - locStart(comment) <= 0 && locEnd(comment) - locEnd(child) <= 0) {
  10641. // The comment is completely contained by this child node.
  10642. comment.enclosingNode = child;
  10643. decorateComment(child, comment, options);
  10644. return; // Abandon the binary search at this level.
  10645. }
  10646. if (locEnd(child) - locStart(comment) <= 0) {
  10647. // This child node falls completely before the comment.
  10648. // Because we will never consider this node or any nodes
  10649. // before it again, this node must be the closest preceding
  10650. // node we have encountered so far.
  10651. precedingNode = child;
  10652. left = middle + 1;
  10653. continue;
  10654. }
  10655. if (locEnd(comment) - locStart(child) <= 0) {
  10656. // This child node falls completely after the comment.
  10657. // Because we will never consider this node or any nodes after
  10658. // it again, this node must be the closest following node we
  10659. // have encountered so far.
  10660. followingNode = child;
  10661. right = middle;
  10662. continue;
  10663. }
  10664. /* istanbul ignore next */
  10665. throw new Error("Comment location overlaps with node location");
  10666. } // We don't want comments inside of different expressions inside of the same
  10667. // template literal to move to another expression.
  10668. if (comment.enclosingNode && comment.enclosingNode.type === "TemplateLiteral") {
  10669. var quasis = comment.enclosingNode.quasis;
  10670. var commentIndex = findExpressionIndexForComment(quasis, comment, options);
  10671. if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
  10672. precedingNode = null;
  10673. }
  10674. if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
  10675. followingNode = null;
  10676. }
  10677. }
  10678. if (precedingNode) {
  10679. comment.precedingNode = precedingNode;
  10680. }
  10681. if (followingNode) {
  10682. comment.followingNode = followingNode;
  10683. }
  10684. }
  10685. function attach(comments, ast, text, options) {
  10686. if (!Array.isArray(comments)) {
  10687. return;
  10688. }
  10689. var tiesToBreak = [];
  10690. var locStart = options.locStart,
  10691. locEnd = options.locEnd;
  10692. comments.forEach(function (comment, i) {
  10693. if (options.parser === "json" || options.parser === "json5" || options.parser === "__js_expression" || options.parser === "__vue_expression") {
  10694. if (locStart(comment) - locStart(ast) <= 0) {
  10695. addLeadingComment(ast, comment);
  10696. return;
  10697. }
  10698. if (locEnd(comment) - locEnd(ast) >= 0) {
  10699. addTrailingComment(ast, comment);
  10700. return;
  10701. }
  10702. }
  10703. decorateComment(ast, comment, options);
  10704. var precedingNode = comment.precedingNode,
  10705. enclosingNode = comment.enclosingNode,
  10706. followingNode = comment.followingNode;
  10707. var pluginHandleOwnLineComment = options.printer.handleComments && options.printer.handleComments.ownLine ? options.printer.handleComments.ownLine : function () {
  10708. return false;
  10709. };
  10710. var pluginHandleEndOfLineComment = options.printer.handleComments && options.printer.handleComments.endOfLine ? options.printer.handleComments.endOfLine : function () {
  10711. return false;
  10712. };
  10713. var pluginHandleRemainingComment = options.printer.handleComments && options.printer.handleComments.remaining ? options.printer.handleComments.remaining : function () {
  10714. return false;
  10715. };
  10716. var isLastComment = comments.length - 1 === i;
  10717. if (hasNewline(text, locStart(comment), {
  10718. backwards: true
  10719. })) {
  10720. // If a comment exists on its own line, prefer a leading comment.
  10721. // We also need to check if it's the first line of the file.
  10722. if (pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)) {// We're good
  10723. } else if (followingNode) {
  10724. // Always a leading comment.
  10725. addLeadingComment(followingNode, comment);
  10726. } else if (precedingNode) {
  10727. addTrailingComment(precedingNode, comment);
  10728. } else if (enclosingNode) {
  10729. addDanglingComment(enclosingNode, comment);
  10730. } else {
  10731. // There are no nodes, let's attach it to the root of the ast
  10732. /* istanbul ignore next */
  10733. addDanglingComment(ast, comment);
  10734. }
  10735. } else if (hasNewline(text, locEnd(comment))) {
  10736. if (pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)) {// We're good
  10737. } else if (precedingNode) {
  10738. // There is content before this comment on the same line, but
  10739. // none after it, so prefer a trailing comment of the previous node.
  10740. addTrailingComment(precedingNode, comment);
  10741. } else if (followingNode) {
  10742. addLeadingComment(followingNode, comment);
  10743. } else if (enclosingNode) {
  10744. addDanglingComment(enclosingNode, comment);
  10745. } else {
  10746. // There are no nodes, let's attach it to the root of the ast
  10747. /* istanbul ignore next */
  10748. addDanglingComment(ast, comment);
  10749. }
  10750. } else {
  10751. if (pluginHandleRemainingComment(comment, text, options, ast, isLastComment)) {// We're good
  10752. } else if (precedingNode && followingNode) {
  10753. // Otherwise, text exists both before and after the comment on
  10754. // the same line. If there is both a preceding and following
  10755. // node, use a tie-breaking algorithm to determine if it should
  10756. // be attached to the next or previous node. In the last case,
  10757. // simply attach the right node;
  10758. var tieCount = tiesToBreak.length;
  10759. if (tieCount > 0) {
  10760. var lastTie = tiesToBreak[tieCount - 1];
  10761. if (lastTie.followingNode !== comment.followingNode) {
  10762. breakTies(tiesToBreak, text, options);
  10763. }
  10764. }
  10765. tiesToBreak.push(comment);
  10766. } else if (precedingNode) {
  10767. addTrailingComment(precedingNode, comment);
  10768. } else if (followingNode) {
  10769. addLeadingComment(followingNode, comment);
  10770. } else if (enclosingNode) {
  10771. addDanglingComment(enclosingNode, comment);
  10772. } else {
  10773. // There are no nodes, let's attach it to the root of the ast
  10774. /* istanbul ignore next */
  10775. addDanglingComment(ast, comment);
  10776. }
  10777. }
  10778. });
  10779. breakTies(tiesToBreak, text, options);
  10780. comments.forEach(function (comment) {
  10781. // These node references were useful for breaking ties, but we
  10782. // don't need them anymore, and they create cycles in the AST that
  10783. // may lead to infinite recursion if we don't delete them here.
  10784. delete comment.precedingNode;
  10785. delete comment.enclosingNode;
  10786. delete comment.followingNode;
  10787. });
  10788. }
  10789. function breakTies(tiesToBreak, text, options) {
  10790. var tieCount = tiesToBreak.length;
  10791. if (tieCount === 0) {
  10792. return;
  10793. }
  10794. var _tiesToBreak$ = tiesToBreak[0],
  10795. precedingNode = _tiesToBreak$.precedingNode,
  10796. followingNode = _tiesToBreak$.followingNode;
  10797. var gapEndPos = options.locStart(followingNode); // Iterate backwards through tiesToBreak, examining the gaps
  10798. // between the tied comments. In order to qualify as leading, a
  10799. // comment must be separated from followingNode by an unbroken series of
  10800. // gaps (or other comments). Gaps should only contain whitespace or open
  10801. // parentheses.
  10802. var indexOfFirstLeadingComment;
  10803. for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
  10804. var comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  10805. assert.strictEqual(comment.precedingNode, precedingNode);
  10806. assert.strictEqual(comment.followingNode, followingNode);
  10807. var gap = text.slice(options.locEnd(comment), gapEndPos).trim();
  10808. if (gap === "" || /^\(+$/.test(gap)) {
  10809. gapEndPos = options.locStart(comment);
  10810. } else {
  10811. // The gap string contained something other than whitespace or open
  10812. // parentheses.
  10813. break;
  10814. }
  10815. }
  10816. tiesToBreak.forEach(function (comment, i) {
  10817. if (i < indexOfFirstLeadingComment) {
  10818. addTrailingComment(precedingNode, comment);
  10819. } else {
  10820. addLeadingComment(followingNode, comment);
  10821. }
  10822. });
  10823. tiesToBreak.length = 0;
  10824. }
  10825. function printComment(commentPath, options) {
  10826. var comment = commentPath.getValue();
  10827. comment.printed = true;
  10828. return options.printer.printComment(commentPath, options);
  10829. }
  10830. function findExpressionIndexForComment(quasis, comment, options) {
  10831. var startPos = options.locStart(comment) - 1;
  10832. for (var i = 1; i < quasis.length; ++i) {
  10833. if (startPos < getQuasiRange(quasis[i]).start) {
  10834. return i - 1;
  10835. }
  10836. } // We haven't found it, it probably means that some of the locations are off.
  10837. // Let's just return the first one.
  10838. /* istanbul ignore next */
  10839. return 0;
  10840. }
  10841. function getQuasiRange(expr) {
  10842. if (expr.start !== undefined) {
  10843. // Babel
  10844. return {
  10845. start: expr.start,
  10846. end: expr.end
  10847. };
  10848. } // Flow
  10849. return {
  10850. start: expr.range[0],
  10851. end: expr.range[1]
  10852. };
  10853. }
  10854. function printLeadingComment(commentPath, print, options) {
  10855. var comment = commentPath.getValue();
  10856. var contents = printComment(commentPath, options);
  10857. if (!contents) {
  10858. return "";
  10859. }
  10860. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // Leading block comments should see if they need to stay on the
  10861. // same line or not.
  10862. if (isBlock) {
  10863. return concat([contents, hasNewline(options.originalText, options.locEnd(comment)) ? hardline : " "]);
  10864. }
  10865. return concat([contents, hardline]);
  10866. }
  10867. function printTrailingComment(commentPath, print, options) {
  10868. var comment = commentPath.getValue();
  10869. var contents = printComment(commentPath, options);
  10870. if (!contents) {
  10871. return "";
  10872. }
  10873. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // We don't want the line to break
  10874. // when the parentParentNode is a ClassDeclaration/-Expression
  10875. // And the parentNode is in the superClass property
  10876. var parentNode = commentPath.getNode(1);
  10877. var parentParentNode = commentPath.getNode(2);
  10878. var isParentSuperClass = parentParentNode && (parentParentNode.type === "ClassDeclaration" || parentParentNode.type === "ClassExpression") && parentParentNode.superClass === parentNode;
  10879. if (hasNewline(options.originalText, options.locStart(comment), {
  10880. backwards: true
  10881. })) {
  10882. // This allows comments at the end of nested structures:
  10883. // {
  10884. // x: 1,
  10885. // y: 2
  10886. // // A comment
  10887. // }
  10888. // Those kinds of comments are almost always leading comments, but
  10889. // here it doesn't go "outside" the block and turns it into a
  10890. // trailing comment for `2`. We can simulate the above by checking
  10891. // if this a comment on its own line; normal trailing comments are
  10892. // always at the end of another expression.
  10893. var isLineBeforeEmpty = isPreviousLineEmpty(options.originalText, comment, options.locStart);
  10894. return lineSuffix(concat([hardline, isLineBeforeEmpty ? hardline : "", contents]));
  10895. } else if (isBlock || isParentSuperClass) {
  10896. // Trailing block comments never need a newline
  10897. return concat([" ", contents]);
  10898. }
  10899. return concat([lineSuffix(concat([" ", contents])), !isBlock ? breakParent : ""]);
  10900. }
  10901. function printDanglingComments(path$$1, options, sameIndent, filter) {
  10902. var parts = [];
  10903. var node = path$$1.getValue();
  10904. if (!node || !node.comments) {
  10905. return "";
  10906. }
  10907. path$$1.each(function (commentPath) {
  10908. var comment = commentPath.getValue();
  10909. if (comment && !comment.leading && !comment.trailing && (!filter || filter(comment))) {
  10910. parts.push(printComment(commentPath, options));
  10911. }
  10912. }, "comments");
  10913. if (parts.length === 0) {
  10914. return "";
  10915. }
  10916. if (sameIndent) {
  10917. return join(hardline, parts);
  10918. }
  10919. return indent(concat([hardline, join(hardline, parts)]));
  10920. }
  10921. function prependCursorPlaceholder(path$$1, options, printed) {
  10922. if (path$$1.getNode() === options.cursorNode && path$$1.getValue()) {
  10923. return concat([cursor, printed, cursor]);
  10924. }
  10925. return printed;
  10926. }
  10927. function printComments(path$$1, print, options, needsSemi) {
  10928. var value = path$$1.getValue();
  10929. var printed = print(path$$1);
  10930. var comments = value && value.comments;
  10931. if (!comments || comments.length === 0) {
  10932. return prependCursorPlaceholder(path$$1, options, printed);
  10933. }
  10934. var leadingParts = [];
  10935. var trailingParts = [needsSemi ? ";" : "", printed];
  10936. path$$1.each(function (commentPath) {
  10937. var comment = commentPath.getValue();
  10938. var leading = comment.leading,
  10939. trailing = comment.trailing;
  10940. if (leading) {
  10941. var contents = printLeadingComment(commentPath, print, options);
  10942. if (!contents) {
  10943. return;
  10944. }
  10945. leadingParts.push(contents);
  10946. var text = options.originalText;
  10947. if (hasNewline(text, skipNewline(text, options.locEnd(comment)))) {
  10948. leadingParts.push(hardline);
  10949. }
  10950. } else if (trailing) {
  10951. trailingParts.push(printTrailingComment(commentPath, print, options));
  10952. }
  10953. }, "comments");
  10954. return prependCursorPlaceholder(path$$1, options, concat(leadingParts.concat(trailingParts)));
  10955. }
  10956. var comments = {
  10957. attach,
  10958. printComments,
  10959. printDanglingComments,
  10960. getSortedChildNodes
  10961. };
  10962. function FastPath(value) {
  10963. assert.ok(this instanceof FastPath);
  10964. this.stack = [value];
  10965. } // The name of the current property is always the penultimate element of
  10966. // this.stack, and always a String.
  10967. FastPath.prototype.getName = function getName() {
  10968. var s = this.stack;
  10969. var len = s.length;
  10970. if (len > 1) {
  10971. return s[len - 2];
  10972. } // Since the name is always a string, null is a safe sentinel value to
  10973. // return if we do not know the name of the (root) value.
  10974. /* istanbul ignore next */
  10975. return null;
  10976. }; // The value of the current property is always the final element of
  10977. // this.stack.
  10978. FastPath.prototype.getValue = function getValue() {
  10979. var s = this.stack;
  10980. return s[s.length - 1];
  10981. };
  10982. function getNodeHelper(path$$1, count) {
  10983. var stackIndex = getNodeStackIndexHelper(path$$1.stack, count);
  10984. return stackIndex === -1 ? null : path$$1.stack[stackIndex];
  10985. }
  10986. function getNodeStackIndexHelper(stack, count) {
  10987. for (var i = stack.length - 1; i >= 0; i -= 2) {
  10988. var value = stack[i];
  10989. if (value && !Array.isArray(value) && --count < 0) {
  10990. return i;
  10991. }
  10992. }
  10993. return -1;
  10994. }
  10995. FastPath.prototype.getNode = function getNode(count) {
  10996. return getNodeHelper(this, ~~count);
  10997. };
  10998. FastPath.prototype.getParentNode = function getParentNode(count) {
  10999. return getNodeHelper(this, ~~count + 1);
  11000. }; // Temporarily push properties named by string arguments given after the
  11001. // callback function onto this.stack, then call the callback with a
  11002. // reference to this (modified) FastPath object. Note that the stack will
  11003. // be restored to its original state after the callback is finished, so it
  11004. // is probably a mistake to retain a reference to the path.
  11005. FastPath.prototype.call = function call(callback
  11006. /*, name1, name2, ... */
  11007. ) {
  11008. var s = this.stack;
  11009. var origLen = s.length;
  11010. var value = s[origLen - 1];
  11011. var argc = arguments.length;
  11012. for (var i = 1; i < argc; ++i) {
  11013. var name = arguments[i];
  11014. value = value[name];
  11015. s.push(name, value);
  11016. }
  11017. var result = callback(this);
  11018. s.length = origLen;
  11019. return result;
  11020. };
  11021. FastPath.prototype.callParent = function callParent(callback, count) {
  11022. var stackIndex = getNodeStackIndexHelper(this.stack, ~~count + 1);
  11023. var parentValues = this.stack.splice(stackIndex + 1);
  11024. var result = callback(this);
  11025. Array.prototype.push.apply(this.stack, parentValues);
  11026. return result;
  11027. }; // Similar to FastPath.prototype.call, except that the value obtained by
  11028. // accessing this.getValue()[name1][name2]... should be array-like. The
  11029. // callback will be called with a reference to this path object for each
  11030. // element of the array.
  11031. FastPath.prototype.each = function each(callback
  11032. /*, name1, name2, ... */
  11033. ) {
  11034. var s = this.stack;
  11035. var origLen = s.length;
  11036. var value = s[origLen - 1];
  11037. var argc = arguments.length;
  11038. for (var i = 1; i < argc; ++i) {
  11039. var name = arguments[i];
  11040. value = value[name];
  11041. s.push(name, value);
  11042. }
  11043. for (var _i = 0; _i < value.length; ++_i) {
  11044. if (_i in value) {
  11045. s.push(_i, value[_i]); // If the callback needs to know the value of i, call
  11046. // path.getName(), assuming path is the parameter name.
  11047. callback(this);
  11048. s.length -= 2;
  11049. }
  11050. }
  11051. s.length = origLen;
  11052. }; // Similar to FastPath.prototype.each, except that the results of the
  11053. // callback function invocations are stored in an array and returned at
  11054. // the end of the iteration.
  11055. FastPath.prototype.map = function map(callback
  11056. /*, name1, name2, ... */
  11057. ) {
  11058. var s = this.stack;
  11059. var origLen = s.length;
  11060. var value = s[origLen - 1];
  11061. var argc = arguments.length;
  11062. for (var i = 1; i < argc; ++i) {
  11063. var name = arguments[i];
  11064. value = value[name];
  11065. s.push(name, value);
  11066. }
  11067. var result = new Array(value.length);
  11068. for (var _i2 = 0; _i2 < value.length; ++_i2) {
  11069. if (_i2 in value) {
  11070. s.push(_i2, value[_i2]);
  11071. result[_i2] = callback(this, _i2);
  11072. s.length -= 2;
  11073. }
  11074. }
  11075. s.length = origLen;
  11076. return result;
  11077. };
  11078. var fastPath = FastPath;
  11079. var normalize$3 = options.normalize;
  11080. function printSubtree(path$$1, print, options$$1, printAstToDoc) {
  11081. if (options$$1.printer.embed) {
  11082. return options$$1.printer.embed(path$$1, print, function (text, partialNextOptions) {
  11083. return textToDoc(text, partialNextOptions, options$$1, printAstToDoc);
  11084. }, options$$1);
  11085. }
  11086. }
  11087. function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) {
  11088. var nextOptions = normalize$3(Object.assign({}, parentOptions, partialNextOptions, {
  11089. parentParser: parentOptions.parser,
  11090. embeddedInHtml: !!(parentOptions.embeddedInHtml || parentOptions.parser === "html" || parentOptions.parser === "vue" || parentOptions.parser === "angular" || parentOptions.parser === "lwc"),
  11091. originalText: text
  11092. }), {
  11093. passThrough: true
  11094. });
  11095. var result = parser.parse(text, nextOptions);
  11096. var ast = result.ast;
  11097. text = result.text;
  11098. var astComments = ast.comments;
  11099. delete ast.comments;
  11100. comments.attach(astComments, ast, text, nextOptions);
  11101. return printAstToDoc(ast, nextOptions);
  11102. }
  11103. var multiparser = {
  11104. printSubtree
  11105. };
  11106. var doc$2 = doc;
  11107. var docBuilders$2 = doc$2.builders;
  11108. var concat$3 = docBuilders$2.concat;
  11109. var hardline$2 = docBuilders$2.hardline;
  11110. var addAlignmentToDoc$1 = docBuilders$2.addAlignmentToDoc;
  11111. var docUtils$2 = doc$2.utils;
  11112. /**
  11113. * Takes an abstract syntax tree (AST) and recursively converts it to a
  11114. * document (series of printing primitives).
  11115. *
  11116. * This is done by descending down the AST recursively. The recursion
  11117. * involves two functions that call each other:
  11118. *
  11119. * 1. printGenerically(), which is defined as an inner function here.
  11120. * It basically takes care of node caching.
  11121. * 2. callPluginPrintFunction(), which checks for some options, and
  11122. * ultimately calls the print() function provided by the plugin.
  11123. *
  11124. * The plugin function will call printGenerically() again for child nodes
  11125. * of the current node, which will do its housekeeping, then call the
  11126. * plugin function again, and so on.
  11127. *
  11128. * All the while, these functions pass a "path" variable around, which
  11129. * is a stack-like data structure (FastPath) that maintains the current
  11130. * state of the recursion. It is called "path", because it represents
  11131. * the path to the current node through the Abstract Syntax Tree.
  11132. */
  11133. function printAstToDoc(ast, options) {
  11134. var alignmentSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  11135. var printer = options.printer;
  11136. if (printer.preprocess) {
  11137. ast = printer.preprocess(ast, options);
  11138. }
  11139. var cache = new Map();
  11140. function printGenerically(path$$1, args) {
  11141. var node = path$$1.getValue();
  11142. var shouldCache = node && typeof node === "object" && args === undefined;
  11143. if (shouldCache && cache.has(node)) {
  11144. return cache.get(node);
  11145. } // We let JSXElement print its comments itself because it adds () around
  11146. // UnionTypeAnnotation has to align the child without the comments
  11147. var res;
  11148. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path$$1, options)) {
  11149. res = callPluginPrintFunction(path$$1, options, printGenerically, args);
  11150. } else {
  11151. // printComments will call the plugin print function and check for
  11152. // comments to print
  11153. res = comments.printComments(path$$1, function (p) {
  11154. return callPluginPrintFunction(p, options, printGenerically, args);
  11155. }, options, args && args.needsSemi);
  11156. }
  11157. if (shouldCache) {
  11158. cache.set(node, res);
  11159. }
  11160. return res;
  11161. }
  11162. var doc$$2 = printGenerically(new fastPath(ast));
  11163. if (alignmentSize > 0) {
  11164. // Add a hardline to make the indents take effect
  11165. // It should be removed in index.js format()
  11166. doc$$2 = addAlignmentToDoc$1(concat$3([hardline$2, doc$$2]), alignmentSize, options.tabWidth);
  11167. }
  11168. docUtils$2.propagateBreaks(doc$$2);
  11169. return doc$$2;
  11170. }
  11171. function callPluginPrintFunction(path$$1, options, printPath, args) {
  11172. assert.ok(path$$1 instanceof fastPath);
  11173. var node = path$$1.getValue();
  11174. var printer = options.printer; // Escape hatch
  11175. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path$$1)) {
  11176. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  11177. }
  11178. if (node) {
  11179. try {
  11180. // Potentially switch to a different parser
  11181. var sub = multiparser.printSubtree(path$$1, printPath, options, printAstToDoc);
  11182. if (sub) {
  11183. return sub;
  11184. }
  11185. } catch (error) {
  11186. /* istanbul ignore if */
  11187. if (process.env.PRETTIER_DEBUG) {
  11188. throw error;
  11189. } // Continue with current parser
  11190. }
  11191. }
  11192. return printer.print(path$$1, options, printPath, args);
  11193. }
  11194. var astToDoc = printAstToDoc;
  11195. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  11196. var resultStartNode = startNodeAndParents.node;
  11197. var resultEndNode = endNodeAndParents.node;
  11198. if (resultStartNode === resultEndNode) {
  11199. return {
  11200. startNode: resultStartNode,
  11201. endNode: resultEndNode
  11202. };
  11203. }
  11204. var _iteratorNormalCompletion = true;
  11205. var _didIteratorError = false;
  11206. var _iteratorError = undefined;
  11207. try {
  11208. for (var _iterator = endNodeAndParents.parentNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  11209. var endParent = _step.value;
  11210. if (endParent.type !== "Program" && endParent.type !== "File" && opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)) {
  11211. resultEndNode = endParent;
  11212. } else {
  11213. break;
  11214. }
  11215. }
  11216. } catch (err) {
  11217. _didIteratorError = true;
  11218. _iteratorError = err;
  11219. } finally {
  11220. try {
  11221. if (!_iteratorNormalCompletion && _iterator.return != null) {
  11222. _iterator.return();
  11223. }
  11224. } finally {
  11225. if (_didIteratorError) {
  11226. throw _iteratorError;
  11227. }
  11228. }
  11229. }
  11230. var _iteratorNormalCompletion2 = true;
  11231. var _didIteratorError2 = false;
  11232. var _iteratorError2 = undefined;
  11233. try {
  11234. for (var _iterator2 = startNodeAndParents.parentNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  11235. var startParent = _step2.value;
  11236. if (startParent.type !== "Program" && startParent.type !== "File" && opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)) {
  11237. resultStartNode = startParent;
  11238. } else {
  11239. break;
  11240. }
  11241. }
  11242. } catch (err) {
  11243. _didIteratorError2 = true;
  11244. _iteratorError2 = err;
  11245. } finally {
  11246. try {
  11247. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  11248. _iterator2.return();
  11249. }
  11250. } finally {
  11251. if (_didIteratorError2) {
  11252. throw _iteratorError2;
  11253. }
  11254. }
  11255. }
  11256. return {
  11257. startNode: resultStartNode,
  11258. endNode: resultEndNode
  11259. };
  11260. }
  11261. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  11262. predicate = predicate || function () {
  11263. return true;
  11264. };
  11265. parentNodes = parentNodes || [];
  11266. var start = options.locStart(node, options.locStart);
  11267. var end = options.locEnd(node, options.locEnd);
  11268. if (start <= offset && offset <= end) {
  11269. var _iteratorNormalCompletion3 = true;
  11270. var _didIteratorError3 = false;
  11271. var _iteratorError3 = undefined;
  11272. try {
  11273. for (var _iterator3 = comments.getSortedChildNodes(node, options)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  11274. var childNode = _step3.value;
  11275. var childResult = findNodeAtOffset(childNode, offset, options, predicate, [node].concat(parentNodes));
  11276. if (childResult) {
  11277. return childResult;
  11278. }
  11279. }
  11280. } catch (err) {
  11281. _didIteratorError3 = true;
  11282. _iteratorError3 = err;
  11283. } finally {
  11284. try {
  11285. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  11286. _iterator3.return();
  11287. }
  11288. } finally {
  11289. if (_didIteratorError3) {
  11290. throw _iteratorError3;
  11291. }
  11292. }
  11293. }
  11294. if (predicate(node)) {
  11295. return {
  11296. node: node,
  11297. parentNodes: parentNodes
  11298. };
  11299. }
  11300. }
  11301. } // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  11302. function isSourceElement(opts, node) {
  11303. if (node == null) {
  11304. return false;
  11305. } // JS and JS like to avoid repetitions
  11306. var jsSourceElements = ["FunctionDeclaration", "BlockStatement", "BreakStatement", "ContinueStatement", "DebuggerStatement", "DoWhileStatement", "EmptyStatement", "ExpressionStatement", "ForInStatement", "ForStatement", "IfStatement", "LabeledStatement", "ReturnStatement", "SwitchStatement", "ThrowStatement", "TryStatement", "VariableDeclaration", "WhileStatement", "WithStatement", "ClassDeclaration", // ES 2015
  11307. "ImportDeclaration", // Module
  11308. "ExportDefaultDeclaration", // Module
  11309. "ExportNamedDeclaration", // Module
  11310. "ExportAllDeclaration", // Module
  11311. "TypeAlias", // Flow
  11312. "InterfaceDeclaration", // Flow, TypeScript
  11313. "TypeAliasDeclaration", // TypeScript
  11314. "ExportAssignment", // TypeScript
  11315. "ExportDeclaration" // TypeScript
  11316. ];
  11317. var jsonSourceElements = ["ObjectExpression", "ArrayExpression", "StringLiteral", "NumericLiteral", "BooleanLiteral", "NullLiteral"];
  11318. var graphqlSourceElements = ["OperationDefinition", "FragmentDefinition", "VariableDefinition", "TypeExtensionDefinition", "ObjectTypeDefinition", "FieldDefinition", "DirectiveDefinition", "EnumTypeDefinition", "EnumValueDefinition", "InputValueDefinition", "InputObjectTypeDefinition", "SchemaDefinition", "OperationTypeDefinition", "InterfaceTypeDefinition", "UnionTypeDefinition", "ScalarTypeDefinition"];
  11319. switch (opts.parser) {
  11320. case "flow":
  11321. case "babel":
  11322. case "typescript":
  11323. return jsSourceElements.indexOf(node.type) > -1;
  11324. case "json":
  11325. return jsonSourceElements.indexOf(node.type) > -1;
  11326. case "graphql":
  11327. return graphqlSourceElements.indexOf(node.kind) > -1;
  11328. case "vue":
  11329. return node.tag !== "root";
  11330. }
  11331. return false;
  11332. }
  11333. function calculateRange(text, opts, ast) {
  11334. // Contract the range so that it has non-whitespace characters at its endpoints.
  11335. // This ensures we can format a range that doesn't end on a node.
  11336. var rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  11337. var startNonWhitespace = Math.max(opts.rangeStart + rangeStringOrig.search(/\S/), opts.rangeStart);
  11338. var endNonWhitespace;
  11339. for (endNonWhitespace = opts.rangeEnd; endNonWhitespace > opts.rangeStart; --endNonWhitespace) {
  11340. if (text[endNonWhitespace - 1].match(/\S/)) {
  11341. break;
  11342. }
  11343. }
  11344. var startNodeAndParents = findNodeAtOffset(ast, startNonWhitespace, opts, function (node) {
  11345. return isSourceElement(opts, node);
  11346. });
  11347. var endNodeAndParents = findNodeAtOffset(ast, endNonWhitespace, opts, function (node) {
  11348. return isSourceElement(opts, node);
  11349. });
  11350. if (!startNodeAndParents || !endNodeAndParents) {
  11351. return {
  11352. rangeStart: 0,
  11353. rangeEnd: 0
  11354. };
  11355. }
  11356. var siblingAncestors = findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts);
  11357. var startNode = siblingAncestors.startNode,
  11358. endNode = siblingAncestors.endNode;
  11359. var rangeStart = Math.min(opts.locStart(startNode, opts.locStart), opts.locStart(endNode, opts.locStart));
  11360. var rangeEnd = Math.max(opts.locEnd(startNode, opts.locEnd), opts.locEnd(endNode, opts.locEnd));
  11361. return {
  11362. rangeStart: rangeStart,
  11363. rangeEnd: rangeEnd
  11364. };
  11365. }
  11366. var rangeUtil = {
  11367. calculateRange,
  11368. findNodeAtOffset
  11369. };
  11370. var normalizeOptions = options.normalize;
  11371. var guessEndOfLine = endOfLine.guessEndOfLine;
  11372. var convertEndOfLineToChars = endOfLine.convertEndOfLineToChars;
  11373. var mapDoc = doc.utils.mapDoc;
  11374. var printDocToString = doc.printer.printDocToString;
  11375. var printDocToDebug = doc.debug.printDocToDebug;
  11376. var UTF8BOM = 0xfeff;
  11377. var CURSOR = Symbol("cursor");
  11378. var PLACEHOLDERS = {
  11379. cursorOffset: "<<<PRETTIER_CURSOR>>>",
  11380. rangeStart: "<<<PRETTIER_RANGE_START>>>",
  11381. rangeEnd: "<<<PRETTIER_RANGE_END>>>"
  11382. };
  11383. function ensureAllCommentsPrinted(astComments) {
  11384. if (!astComments) {
  11385. return;
  11386. }
  11387. for (var i = 0; i < astComments.length; ++i) {
  11388. if (astComments[i].value.trim() === "prettier-ignore") {
  11389. // If there's a prettier-ignore, we're not printing that sub-tree so we
  11390. // don't know if the comments was printed or not.
  11391. return;
  11392. }
  11393. }
  11394. astComments.forEach(function (comment) {
  11395. if (!comment.printed) {
  11396. throw new Error('Comment "' + comment.value.trim() + '" was not printed. Please report this error!');
  11397. }
  11398. delete comment.printed;
  11399. });
  11400. }
  11401. function attachComments(text, ast, opts) {
  11402. var astComments = ast.comments;
  11403. if (astComments) {
  11404. delete ast.comments;
  11405. comments.attach(astComments, ast, text, opts);
  11406. }
  11407. ast.tokens = [];
  11408. opts.originalText = opts.parser === "yaml" ? text : text.trimRight();
  11409. return astComments;
  11410. }
  11411. function coreFormat(text, opts, addAlignmentSize) {
  11412. if (!text || !text.trim().length) {
  11413. return {
  11414. formatted: "",
  11415. cursorOffset: 0
  11416. };
  11417. }
  11418. addAlignmentSize = addAlignmentSize || 0;
  11419. var parsed = parser.parse(text, opts);
  11420. var ast = parsed.ast;
  11421. text = parsed.text;
  11422. if (opts.cursorOffset >= 0) {
  11423. var nodeResult = rangeUtil.findNodeAtOffset(ast, opts.cursorOffset, opts);
  11424. if (nodeResult && nodeResult.node) {
  11425. opts.cursorNode = nodeResult.node;
  11426. }
  11427. }
  11428. var astComments = attachComments(text, ast, opts);
  11429. var doc$$1 = astToDoc(ast, opts, addAlignmentSize);
  11430. var eol = convertEndOfLineToChars(opts.endOfLine);
  11431. var result = printDocToString(opts.endOfLine === "lf" ? doc$$1 : mapDoc(doc$$1, function (currentDoc) {
  11432. return typeof currentDoc === "string" && currentDoc.indexOf("\n") !== -1 ? currentDoc.replace(/\n/g, eol) : currentDoc;
  11433. }), opts);
  11434. ensureAllCommentsPrinted(astComments); // Remove extra leading indentation as well as the added indentation after last newline
  11435. if (addAlignmentSize > 0) {
  11436. var trimmed = result.formatted.trim();
  11437. if (result.cursorNodeStart !== undefined) {
  11438. result.cursorNodeStart -= result.formatted.indexOf(trimmed);
  11439. }
  11440. result.formatted = trimmed + convertEndOfLineToChars(opts.endOfLine);
  11441. }
  11442. if (opts.cursorOffset >= 0) {
  11443. var oldCursorNodeStart;
  11444. var oldCursorNodeText;
  11445. var cursorOffsetRelativeToOldCursorNode;
  11446. var newCursorNodeStart;
  11447. var newCursorNodeText;
  11448. if (opts.cursorNode && result.cursorNodeText) {
  11449. oldCursorNodeStart = opts.locStart(opts.cursorNode);
  11450. oldCursorNodeText = text.slice(oldCursorNodeStart, opts.locEnd(opts.cursorNode));
  11451. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset - oldCursorNodeStart;
  11452. newCursorNodeStart = result.cursorNodeStart;
  11453. newCursorNodeText = result.cursorNodeText;
  11454. } else {
  11455. oldCursorNodeStart = 0;
  11456. oldCursorNodeText = text;
  11457. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset;
  11458. newCursorNodeStart = 0;
  11459. newCursorNodeText = result.formatted;
  11460. }
  11461. if (oldCursorNodeText === newCursorNodeText) {
  11462. return {
  11463. formatted: result.formatted,
  11464. cursorOffset: newCursorNodeStart + cursorOffsetRelativeToOldCursorNode
  11465. };
  11466. } // diff old and new cursor node texts, with a special cursor
  11467. // symbol inserted to find out where it moves to
  11468. var oldCursorNodeCharArray = oldCursorNodeText.split("");
  11469. oldCursorNodeCharArray.splice(cursorOffsetRelativeToOldCursorNode, 0, CURSOR);
  11470. var newCursorNodeCharArray = newCursorNodeText.split("");
  11471. var cursorNodeDiff = lib.diffArrays(oldCursorNodeCharArray, newCursorNodeCharArray);
  11472. var cursorOffset = newCursorNodeStart;
  11473. var _iteratorNormalCompletion = true;
  11474. var _didIteratorError = false;
  11475. var _iteratorError = undefined;
  11476. try {
  11477. for (var _iterator = cursorNodeDiff[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  11478. var entry = _step.value;
  11479. if (entry.removed) {
  11480. if (entry.value.indexOf(CURSOR) > -1) {
  11481. break;
  11482. }
  11483. } else {
  11484. cursorOffset += entry.count;
  11485. }
  11486. }
  11487. } catch (err) {
  11488. _didIteratorError = true;
  11489. _iteratorError = err;
  11490. } finally {
  11491. try {
  11492. if (!_iteratorNormalCompletion && _iterator.return != null) {
  11493. _iterator.return();
  11494. }
  11495. } finally {
  11496. if (_didIteratorError) {
  11497. throw _iteratorError;
  11498. }
  11499. }
  11500. }
  11501. return {
  11502. formatted: result.formatted,
  11503. cursorOffset
  11504. };
  11505. }
  11506. return {
  11507. formatted: result.formatted
  11508. };
  11509. }
  11510. function formatRange(text, opts) {
  11511. var parsed = parser.parse(text, opts);
  11512. var ast = parsed.ast;
  11513. text = parsed.text;
  11514. var range = rangeUtil.calculateRange(text, opts, ast);
  11515. var rangeStart = range.rangeStart;
  11516. var rangeEnd = range.rangeEnd;
  11517. var rangeString = text.slice(rangeStart, rangeEnd); // Try to extend the range backwards to the beginning of the line.
  11518. // This is so we can detect indentation correctly and restore it.
  11519. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  11520. var rangeStart2 = Math.min(rangeStart, text.lastIndexOf("\n", rangeStart) + 1);
  11521. var indentString = text.slice(rangeStart2, rangeStart);
  11522. var alignmentSize = util$1.getAlignmentSize(indentString, opts.tabWidth);
  11523. var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
  11524. rangeStart: 0,
  11525. rangeEnd: Infinity,
  11526. // track the cursor offset only if it's within our range
  11527. cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
  11528. }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
  11529. // we need to remove the newline that was inserted by the `format` call.
  11530. var rangeTrimmed = rangeResult.formatted.trimRight();
  11531. var rangeLeft = text.slice(0, rangeStart);
  11532. var rangeRight = text.slice(rangeEnd);
  11533. var cursorOffset = opts.cursorOffset;
  11534. if (opts.cursorOffset >= rangeEnd) {
  11535. // handle the case where the cursor was past the end of the range
  11536. cursorOffset = opts.cursorOffset - rangeEnd + (rangeStart + rangeTrimmed.length);
  11537. } else if (rangeResult.cursorOffset !== undefined) {
  11538. // handle the case where the cursor was in the range
  11539. cursorOffset = rangeResult.cursorOffset + rangeStart;
  11540. } // keep the cursor as it was if it was before the start of the range
  11541. var formatted;
  11542. if (opts.endOfLine === "lf") {
  11543. formatted = rangeLeft + rangeTrimmed + rangeRight;
  11544. } else {
  11545. var eol = convertEndOfLineToChars(opts.endOfLine);
  11546. if (cursorOffset >= 0) {
  11547. var parts = [rangeLeft, rangeTrimmed, rangeRight];
  11548. var partIndex = 0;
  11549. var partOffset = cursorOffset;
  11550. while (partIndex < parts.length) {
  11551. var part = parts[partIndex];
  11552. if (partOffset < part.length) {
  11553. parts[partIndex] = parts[partIndex].slice(0, partOffset) + PLACEHOLDERS.cursorOffset + parts[partIndex].slice(partOffset);
  11554. break;
  11555. }
  11556. partIndex++;
  11557. partOffset -= part.length;
  11558. }
  11559. var newRangeLeft = parts[0],
  11560. newRangeTrimmed = parts[1],
  11561. newRangeRight = parts[2];
  11562. formatted = (newRangeLeft.replace(/\n/g, eol) + newRangeTrimmed + newRangeRight.replace(/\n/g, eol)).replace(PLACEHOLDERS.cursorOffset, function (_, index) {
  11563. cursorOffset = index;
  11564. return "";
  11565. });
  11566. } else {
  11567. formatted = rangeLeft.replace(/\n/g, eol) + rangeTrimmed + rangeRight.replace(/\n/g, eol);
  11568. }
  11569. }
  11570. return {
  11571. formatted,
  11572. cursorOffset
  11573. };
  11574. }
  11575. function format(text, opts) {
  11576. var selectedParser = parser.resolveParser(opts);
  11577. var hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  11578. if (opts.requirePragma && !hasPragma) {
  11579. return {
  11580. formatted: text
  11581. };
  11582. }
  11583. if (opts.endOfLine === "auto") {
  11584. opts.endOfLine = guessEndOfLine(text);
  11585. }
  11586. var hasCursor = opts.cursorOffset >= 0;
  11587. var hasRangeStart = opts.rangeStart > 0;
  11588. var hasRangeEnd = opts.rangeEnd < text.length; // get rid of CR/CRLF parsing
  11589. if (text.indexOf("\r") !== -1) {
  11590. var offsetKeys = [hasCursor && "cursorOffset", hasRangeStart && "rangeStart", hasRangeEnd && "rangeEnd"].filter(Boolean).sort(function (aKey, bKey) {
  11591. return opts[aKey] - opts[bKey];
  11592. });
  11593. for (var i = offsetKeys.length - 1; i >= 0; i--) {
  11594. var key = offsetKeys[i];
  11595. text = text.slice(0, opts[key]) + PLACEHOLDERS[key] + text.slice(opts[key]);
  11596. }
  11597. text = text.replace(/\r\n?/g, "\n");
  11598. var _loop = function _loop(_i) {
  11599. var key = offsetKeys[_i];
  11600. text = text.replace(PLACEHOLDERS[key], function (_, index) {
  11601. opts[key] = index;
  11602. return "";
  11603. });
  11604. };
  11605. for (var _i = 0; _i < offsetKeys.length; _i++) {
  11606. _loop(_i);
  11607. }
  11608. }
  11609. var hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  11610. if (hasUnicodeBOM) {
  11611. text = text.substring(1);
  11612. if (hasCursor) {
  11613. opts.cursorOffset++;
  11614. }
  11615. if (hasRangeStart) {
  11616. opts.rangeStart++;
  11617. }
  11618. if (hasRangeEnd) {
  11619. opts.rangeEnd++;
  11620. }
  11621. }
  11622. if (!hasCursor) {
  11623. opts.cursorOffset = -1;
  11624. }
  11625. if (opts.rangeStart < 0) {
  11626. opts.rangeStart = 0;
  11627. }
  11628. if (opts.rangeEnd > text.length) {
  11629. opts.rangeEnd = text.length;
  11630. }
  11631. var result = hasRangeStart || hasRangeEnd ? formatRange(text, opts) : coreFormat(opts.insertPragma && opts.printer.insertPragma && !hasPragma ? opts.printer.insertPragma(text) : text, opts);
  11632. if (hasUnicodeBOM) {
  11633. result.formatted = String.fromCharCode(UTF8BOM) + result.formatted;
  11634. if (hasCursor) {
  11635. result.cursorOffset++;
  11636. }
  11637. }
  11638. return result;
  11639. }
  11640. var core = {
  11641. formatWithCursor(text, opts) {
  11642. opts = normalizeOptions(opts);
  11643. return format(text, opts);
  11644. },
  11645. parse(text, opts, massage) {
  11646. opts = normalizeOptions(opts);
  11647. if (text.indexOf("\r") !== -1) {
  11648. text = text.replace(/\r\n?/g, "\n");
  11649. }
  11650. var parsed = parser.parse(text, opts);
  11651. if (massage) {
  11652. parsed.ast = massageAst(parsed.ast, opts);
  11653. }
  11654. return parsed;
  11655. },
  11656. formatAST(ast, opts) {
  11657. opts = normalizeOptions(opts);
  11658. var doc$$1 = astToDoc(ast, opts);
  11659. return printDocToString(doc$$1, opts);
  11660. },
  11661. // Doesn't handle shebang for now
  11662. formatDoc(doc$$1, opts) {
  11663. var debug = printDocToDebug(doc$$1);
  11664. opts = normalizeOptions(Object.assign({}, opts, {
  11665. parser: "babel"
  11666. }));
  11667. return format(debug, opts).formatted;
  11668. },
  11669. printToDoc(text, opts) {
  11670. opts = normalizeOptions(opts);
  11671. var parsed = parser.parse(text, opts);
  11672. var ast = parsed.ast;
  11673. text = parsed.text;
  11674. attachComments(text, ast, opts);
  11675. return astToDoc(ast, opts);
  11676. },
  11677. printDocToString(doc$$1, opts) {
  11678. return printDocToString(doc$$1, normalizeOptions(opts));
  11679. }
  11680. };
  11681. var ignore = createCommonjsModule(function (module) {
  11682. // A simple implementation of make-array
  11683. function make_array(subject) {
  11684. return Array.isArray(subject) ? subject : [subject];
  11685. }
  11686. var REGEX_BLANK_LINE = /^\s+$/;
  11687. var REGEX_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
  11688. var REGEX_LEADING_EXCAPED_HASH = /^\\#/;
  11689. var SLASH = '/';
  11690. var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  11691. /* istanbul ignore next */
  11692. : 'node-ignore';
  11693. var define = function define(object, key, value) {
  11694. return Object.defineProperty(object, key, {
  11695. value
  11696. });
  11697. };
  11698. var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
  11699. // The cases are complicated, see test cases for details
  11700. var sanitizeRange = function sanitizeRange(range) {
  11701. return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) {
  11702. return from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but
  11703. // fatal for JavaScript regular expression, so eliminate it.
  11704. : '';
  11705. });
  11706. }; // > If the pattern ends with a slash,
  11707. // > it is removed for the purpose of the following description,
  11708. // > but it would only find a match with a directory.
  11709. // > In other words, foo/ will match a directory foo and paths underneath it,
  11710. // > but will not match a regular file or a symbolic link foo
  11711. // > (this is consistent with the way how pathspec works in general in Git).
  11712. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  11713. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  11714. // you could use option `mark: true` with `glob`
  11715. // '`foo/`' should not continue with the '`..`'
  11716. var DEFAULT_REPLACER_PREFIX = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
  11717. [// (a\ ) -> (a )
  11718. // (a ) -> (a)
  11719. // (a \ ) -> (a )
  11720. /\\?\s+$/, function (match) {
  11721. return match.indexOf('\\') === 0 ? ' ' : '';
  11722. }], // replace (\ ) with ' '
  11723. [/\\\s/g, function () {
  11724. return ' ';
  11725. }], // Escape metacharacters
  11726. // which is written down by users but means special for regular expressions.
  11727. // > There are 12 characters with special meanings:
  11728. // > - the backslash \,
  11729. // > - the caret ^,
  11730. // > - the dollar sign $,
  11731. // > - the period or dot .,
  11732. // > - the vertical bar or pipe symbol |,
  11733. // > - the question mark ?,
  11734. // > - the asterisk or star *,
  11735. // > - the plus sign +,
  11736. // > - the opening parenthesis (,
  11737. // > - the closing parenthesis ),
  11738. // > - and the opening square bracket [,
  11739. // > - the opening curly brace {,
  11740. // > These special characters are often called "metacharacters".
  11741. [/[\\^$.|*+(){]/g, function (match) {
  11742. return `\\${match}`;
  11743. }], [// > [abc] matches any character inside the brackets
  11744. // > (in this case a, b, or c);
  11745. /\[([^\]/]*)($|\])/g, function (match, p1, p2) {
  11746. return p2 === ']' ? `[${sanitizeRange(p1)}]` : `\\${match}`;
  11747. }], [// > a question mark (?) matches a single character
  11748. /(?!\\)\?/g, function () {
  11749. return '[^/]';
  11750. }], // leading slash
  11751. [// > A leading slash matches the beginning of the pathname.
  11752. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  11753. // A leading slash matches the beginning of the pathname
  11754. /^\//, function () {
  11755. return '^';
  11756. }], // replace special metacharacter slash after the leading slash
  11757. [/\//g, function () {
  11758. return '\\/';
  11759. }], [// > A leading "**" followed by a slash means match in all directories.
  11760. // > For example, "**/foo" matches file or directory "foo" anywhere,
  11761. // > the same as pattern "foo".
  11762. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
  11763. // > under directory "foo".
  11764. // Notice that the '*'s have been replaced as '\\*'
  11765. /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
  11766. function () {
  11767. return '^(?:.*\\/)?';
  11768. }]];
  11769. var DEFAULT_REPLACER_SUFFIX = [// starting
  11770. [// there will be no leading '/'
  11771. // (which has been replaced by section "leading slash")
  11772. // If starts with '**', adding a '^' to the regular expression also works
  11773. /^(?=[^^])/, function startingReplacer() {
  11774. return !/\/(?!$)/.test(this) // > If the pattern does not contain a slash /,
  11775. // > Git treats it as a shell glob pattern
  11776. // Actually, if there is only a trailing slash,
  11777. // git also treats it as a shell glob pattern
  11778. ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for
  11779. // > consumption by fnmatch(3)
  11780. : '^';
  11781. }], // two globstars
  11782. [// Use lookahead assertions so that we could match more than one `'/**'`
  11783. /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
  11784. // should not use '*', or it will be replaced by the next replacer
  11785. // Check if it is not the last `'/**'`
  11786. function (match, index, str) {
  11787. return index + 6 < str.length // case: /**/
  11788. // > A slash followed by two consecutive asterisks then a slash matches
  11789. // > zero or more directories.
  11790. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  11791. // '/**/'
  11792. ? '(?:\\/[^\\/]+)*' // case: /**
  11793. // > A trailing `"/**"` matches everything inside.
  11794. // #21: everything inside but it should not include the current folder
  11795. : '\\/.+';
  11796. }], // intermediate wildcards
  11797. [// Never replace escaped '*'
  11798. // ignore rule '\*' will match the path '*'
  11799. // 'abc.*/' -> go
  11800. // 'abc.*' -> skip this rule
  11801. /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
  11802. // '*.js' doesn't match 'abc'
  11803. function (match, p1) {
  11804. return `${p1}[^\\/]*`;
  11805. }], // trailing wildcard
  11806. [/(\^|\\\/)?\\\*$/, function (match, p1) {
  11807. var prefix = p1 // '\^':
  11808. // '/*' does not match ''
  11809. // '/*' does not match everything
  11810. // '\\\/':
  11811. // 'abc/*' does not match 'abc/'
  11812. ? `${p1}[^/]+` // 'a*' matches 'a'
  11813. // 'a*' matches 'aa'
  11814. : '[^/]*';
  11815. return `${prefix}(?=$|\\/$)`;
  11816. }], [// unescape
  11817. /\\\\\\/g, function () {
  11818. return '\\';
  11819. }]];
  11820. var POSITIVE_REPLACERS = DEFAULT_REPLACER_PREFIX.concat([// 'f'
  11821. // matches
  11822. // - /f(end)
  11823. // - /f/
  11824. // - (start)f(end)
  11825. // - (start)f/
  11826. // doesn't match
  11827. // - oof
  11828. // - foo
  11829. // pseudo:
  11830. // -> (^|/)f(/|$)
  11831. // ending
  11832. [// 'js' will not match 'js.'
  11833. // 'ab' will not match 'abc'
  11834. /(?:[^*/])$/, // 'js*' will not match 'a.js'
  11835. // 'js/' will not match 'a.js'
  11836. // 'js' will match 'a.js' and 'a.js/'
  11837. function (match) {
  11838. return `${match}(?=$|\\/)`;
  11839. }]], DEFAULT_REPLACER_SUFFIX);
  11840. var NEGATIVE_REPLACERS = DEFAULT_REPLACER_PREFIX.concat([// #24, #38
  11841. // The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore)
  11842. // A negative pattern without a trailing wildcard should not
  11843. // re-include the things inside that directory.
  11844. // eg:
  11845. // ['node_modules/*', '!node_modules']
  11846. // should ignore `node_modules/a.js`
  11847. [/(?:[^*])$/, function (match) {
  11848. return `${match}(?=$|\\/$)`;
  11849. }]], DEFAULT_REPLACER_SUFFIX); // A simple cache, because an ignore rule only has only one certain meaning
  11850. var cache = Object.create(null); // @param {pattern}
  11851. var make_regex = function make_regex(pattern, negative, ignorecase) {
  11852. var r = cache[pattern];
  11853. if (r) {
  11854. return r;
  11855. }
  11856. var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS;
  11857. var source = replacers.reduce(function (prev, current) {
  11858. return prev.replace(current[0], current[1].bind(pattern));
  11859. }, pattern);
  11860. return cache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source);
  11861. }; // > A blank line matches no files, so it can serve as a separator for readability.
  11862. var checkPattern = function checkPattern(pattern) {
  11863. return pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
  11864. && pattern.indexOf('#') !== 0;
  11865. };
  11866. var createRule = function createRule(pattern, ignorecase) {
  11867. var origin = pattern;
  11868. var negative = false; // > An optional prefix "!" which negates the pattern;
  11869. if (pattern.indexOf('!') === 0) {
  11870. negative = true;
  11871. pattern = pattern.substr(1);
  11872. }
  11873. pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that
  11874. // > begin with a literal "!", for example, `"\!important!.txt"`.
  11875. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that
  11876. // > begin with a hash.
  11877. .replace(REGEX_LEADING_EXCAPED_HASH, '#');
  11878. var regex = make_regex(pattern, negative, ignorecase);
  11879. return {
  11880. origin,
  11881. pattern,
  11882. negative,
  11883. regex
  11884. };
  11885. };
  11886. var IgnoreBase =
  11887. /*#__PURE__*/
  11888. function () {
  11889. function IgnoreBase() {
  11890. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  11891. _ref$ignorecase = _ref.ignorecase,
  11892. ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase;
  11893. _classCallCheck(this, IgnoreBase);
  11894. this._rules = [];
  11895. this._ignorecase = ignorecase;
  11896. define(this, KEY_IGNORE, true);
  11897. this._initCache();
  11898. }
  11899. _createClass(IgnoreBase, [{
  11900. key: "_initCache",
  11901. value: function _initCache() {
  11902. this._cache = Object.create(null);
  11903. } // @param {Array.<string>|string|Ignore} pattern
  11904. }, {
  11905. key: "add",
  11906. value: function add(pattern) {
  11907. this._added = false;
  11908. if (typeof pattern === 'string') {
  11909. pattern = pattern.split(/\r?\n/g);
  11910. }
  11911. make_array(pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
  11912. // making the behavior changed.
  11913. if (this._added) {
  11914. this._initCache();
  11915. }
  11916. return this;
  11917. } // legacy
  11918. }, {
  11919. key: "addPattern",
  11920. value: function addPattern(pattern) {
  11921. return this.add(pattern);
  11922. }
  11923. }, {
  11924. key: "_addPattern",
  11925. value: function _addPattern(pattern) {
  11926. // #32
  11927. if (pattern && pattern[KEY_IGNORE]) {
  11928. this._rules = this._rules.concat(pattern._rules);
  11929. this._added = true;
  11930. return;
  11931. }
  11932. if (checkPattern(pattern)) {
  11933. var rule = createRule(pattern, this._ignorecase);
  11934. this._added = true;
  11935. this._rules.push(rule);
  11936. }
  11937. }
  11938. }, {
  11939. key: "filter",
  11940. value: function filter(paths) {
  11941. var _this = this;
  11942. return make_array(paths).filter(function (path$$1) {
  11943. return _this._filter(path$$1);
  11944. });
  11945. }
  11946. }, {
  11947. key: "createFilter",
  11948. value: function createFilter() {
  11949. var _this2 = this;
  11950. return function (path$$1) {
  11951. return _this2._filter(path$$1);
  11952. };
  11953. }
  11954. }, {
  11955. key: "ignores",
  11956. value: function ignores(path$$1) {
  11957. return !this._filter(path$$1);
  11958. } // @returns `Boolean` true if the `path` is NOT ignored
  11959. }, {
  11960. key: "_filter",
  11961. value: function _filter(path$$1, slices) {
  11962. if (!path$$1) {
  11963. return false;
  11964. }
  11965. if (path$$1 in this._cache) {
  11966. return this._cache[path$$1];
  11967. }
  11968. if (!slices) {
  11969. // path/to/a.js
  11970. // ['path', 'to', 'a.js']
  11971. slices = path$$1.split(SLASH);
  11972. }
  11973. slices.pop();
  11974. return this._cache[path$$1] = slices.length // > It is not possible to re-include a file if a parent directory of
  11975. // > that file is excluded.
  11976. // If the path contains a parent directory, check the parent first
  11977. ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path$$1) // Or only test the path
  11978. : this._test(path$$1);
  11979. } // @returns {Boolean} true if a file is NOT ignored
  11980. }, {
  11981. key: "_test",
  11982. value: function _test(path$$1) {
  11983. // Explicitly define variable type by setting matched to `0`
  11984. var matched = 0;
  11985. this._rules.forEach(function (rule) {
  11986. // if matched = true, then we only test negative rules
  11987. // if matched = false, then we test non-negative rules
  11988. if (!(matched ^ rule.negative)) {
  11989. matched = rule.negative ^ rule.regex.test(path$$1);
  11990. }
  11991. });
  11992. return !matched;
  11993. }
  11994. }]);
  11995. return IgnoreBase;
  11996. }(); // Windows
  11997. // --------------------------------------------------------------
  11998. /* istanbul ignore if */
  11999. if ( // Detect `process` so that it can run in browsers.
  12000. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  12001. var filter = IgnoreBase.prototype._filter;
  12002. /* eslint no-control-regex: "off" */
  12003. var make_posix = function make_posix(str) {
  12004. return /^\\\\\?\\/.test(str) || /[^\x00-\x80]+/.test(str) ? str : str.replace(/\\/g, '/');
  12005. };
  12006. IgnoreBase.prototype._filter = function filterWin32(path$$1, slices) {
  12007. path$$1 = make_posix(path$$1);
  12008. return filter.call(this, path$$1, slices);
  12009. };
  12010. }
  12011. module.exports = function (options) {
  12012. return new IgnoreBase(options);
  12013. };
  12014. });
  12015. /**
  12016. * @param {string} filename
  12017. * @returns {Promise<null | string>}
  12018. */
  12019. function getFileContentOrNull(filename) {
  12020. return new Promise(function (resolve, reject) {
  12021. fs.readFile(filename, "utf8", function (error, data) {
  12022. if (error && error.code !== "ENOENT") {
  12023. reject(createError(filename, error));
  12024. } else {
  12025. resolve(error ? null : data);
  12026. }
  12027. });
  12028. });
  12029. }
  12030. /**
  12031. * @param {string} filename
  12032. * @returns {null | string}
  12033. */
  12034. getFileContentOrNull.sync = function (filename) {
  12035. try {
  12036. return fs.readFileSync(filename, "utf8");
  12037. } catch (error) {
  12038. if (error && error.code === "ENOENT") {
  12039. return null;
  12040. }
  12041. throw createError(filename, error);
  12042. }
  12043. };
  12044. function createError(filename, error) {
  12045. return new Error(`Unable to read ${filename}: ${error.message}`);
  12046. }
  12047. var getFileContentOrNull_1 = getFileContentOrNull;
  12048. /**
  12049. * @param {undefined | string} ignorePath
  12050. * @param {undefined | boolean} withNodeModules
  12051. */
  12052. function createIgnorer(ignorePath, withNodeModules) {
  12053. return (!ignorePath ? Promise.resolve(null) : getFileContentOrNull_1(path.resolve(ignorePath))).then(function (ignoreContent) {
  12054. return _createIgnorer(ignoreContent, withNodeModules);
  12055. });
  12056. }
  12057. /**
  12058. * @param {undefined | string} ignorePath
  12059. * @param {undefined | boolean} withNodeModules
  12060. */
  12061. createIgnorer.sync = function (ignorePath, withNodeModules) {
  12062. var ignoreContent = !ignorePath ? null : getFileContentOrNull_1.sync(path.resolve(ignorePath));
  12063. return _createIgnorer(ignoreContent, withNodeModules);
  12064. };
  12065. /**
  12066. * @param {null | string} ignoreContent
  12067. * @param {undefined | boolean} withNodeModules
  12068. */
  12069. function _createIgnorer(ignoreContent, withNodeModules) {
  12070. var ignorer = ignore().add(ignoreContent || "");
  12071. if (!withNodeModules) {
  12072. ignorer.add("node_modules");
  12073. }
  12074. return ignorer;
  12075. }
  12076. var createIgnorer_1 = createIgnorer;
  12077. /**
  12078. * @typedef {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} FileInfoOptions
  12079. * @typedef {{ ignored: boolean, inferredParser: string | null }} FileInfoResult
  12080. */
  12081. /**
  12082. * @param {string} filePath
  12083. * @param {FileInfoOptions} opts
  12084. * @returns {Promise<FileInfoResult>}
  12085. *
  12086. * Please note that prettier.getFileInfo() expects opts.plugins to be an array of paths,
  12087. * not an object. A transformation from this array to an object is automatically done
  12088. * internally by the method wrapper. See withPlugins() in index.js.
  12089. */
  12090. function getFileInfo(filePath, opts) {
  12091. return createIgnorer_1(opts.ignorePath, opts.withNodeModules).then(function (ignorer) {
  12092. return _getFileInfo(ignorer, normalizeFilePath(filePath, opts.ignorePath), opts.plugins);
  12093. });
  12094. }
  12095. /**
  12096. * @param {string} filePath
  12097. * @param {FileInfoOptions} opts
  12098. * @returns {FileInfoResult}
  12099. */
  12100. getFileInfo.sync = function (filePath, opts) {
  12101. var ignorer = createIgnorer_1.sync(opts.ignorePath, opts.withNodeModules);
  12102. return _getFileInfo(ignorer, normalizeFilePath(filePath, opts.ignorePath), opts.plugins);
  12103. };
  12104. function _getFileInfo(ignorer, filePath, plugins) {
  12105. var ignored = ignorer.ignores(filePath);
  12106. var inferredParser = options.inferParser(filePath, plugins) || null;
  12107. return {
  12108. ignored,
  12109. inferredParser
  12110. };
  12111. }
  12112. function normalizeFilePath(filePath, ignorePath) {
  12113. return ignorePath ? path.relative(path.dirname(ignorePath), filePath) : filePath;
  12114. }
  12115. var getFileInfo_1 = getFileInfo;
  12116. var lodash_uniqby = createCommonjsModule(function (module, exports) {
  12117. /**
  12118. * lodash (Custom Build) <https://lodash.com/>
  12119. * Build: `lodash modularize exports="npm" -o ./`
  12120. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  12121. * Released under MIT license <https://lodash.com/license>
  12122. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  12123. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  12124. */
  12125. /** Used as the size to enable large array optimizations. */
  12126. var LARGE_ARRAY_SIZE = 200;
  12127. /** Used as the `TypeError` message for "Functions" methods. */
  12128. var FUNC_ERROR_TEXT = 'Expected a function';
  12129. /** Used to stand-in for `undefined` hash values. */
  12130. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  12131. /** Used to compose bitmasks for comparison styles. */
  12132. var UNORDERED_COMPARE_FLAG = 1,
  12133. PARTIAL_COMPARE_FLAG = 2;
  12134. /** Used as references for various `Number` constants. */
  12135. var INFINITY = 1 / 0,
  12136. MAX_SAFE_INTEGER = 9007199254740991;
  12137. /** `Object#toString` result references. */
  12138. var argsTag = '[object Arguments]',
  12139. arrayTag = '[object Array]',
  12140. boolTag = '[object Boolean]',
  12141. dateTag = '[object Date]',
  12142. errorTag = '[object Error]',
  12143. funcTag = '[object Function]',
  12144. genTag = '[object GeneratorFunction]',
  12145. mapTag = '[object Map]',
  12146. numberTag = '[object Number]',
  12147. objectTag = '[object Object]',
  12148. promiseTag = '[object Promise]',
  12149. regexpTag = '[object RegExp]',
  12150. setTag = '[object Set]',
  12151. stringTag = '[object String]',
  12152. symbolTag = '[object Symbol]',
  12153. weakMapTag = '[object WeakMap]';
  12154. var arrayBufferTag = '[object ArrayBuffer]',
  12155. dataViewTag = '[object DataView]',
  12156. float32Tag = '[object Float32Array]',
  12157. float64Tag = '[object Float64Array]',
  12158. int8Tag = '[object Int8Array]',
  12159. int16Tag = '[object Int16Array]',
  12160. int32Tag = '[object Int32Array]',
  12161. uint8Tag = '[object Uint8Array]',
  12162. uint8ClampedTag = '[object Uint8ClampedArray]',
  12163. uint16Tag = '[object Uint16Array]',
  12164. uint32Tag = '[object Uint32Array]';
  12165. /** Used to match property names within property paths. */
  12166. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  12167. reIsPlainProp = /^\w*$/,
  12168. reLeadingDot = /^\./,
  12169. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  12170. /**
  12171. * Used to match `RegExp`
  12172. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  12173. */
  12174. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  12175. /** Used to match backslashes in property paths. */
  12176. var reEscapeChar = /\\(\\)?/g;
  12177. /** Used to detect host constructors (Safari). */
  12178. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  12179. /** Used to detect unsigned integer values. */
  12180. var reIsUint = /^(?:0|[1-9]\d*)$/;
  12181. /** Used to identify `toStringTag` values of typed arrays. */
  12182. var typedArrayTags = {};
  12183. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  12184. 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;
  12185. /** Detect free variable `global` from Node.js. */
  12186. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  12187. /** Detect free variable `self`. */
  12188. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  12189. /** Used as a reference to the global object. */
  12190. var root = freeGlobal || freeSelf || Function('return this')();
  12191. /** Detect free variable `exports`. */
  12192. var freeExports = 'object' == 'object' && exports && !exports.nodeType && exports;
  12193. /** Detect free variable `module`. */
  12194. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  12195. /** Detect the popular CommonJS extension `module.exports`. */
  12196. var moduleExports = freeModule && freeModule.exports === freeExports;
  12197. /** Detect free variable `process` from Node.js. */
  12198. var freeProcess = moduleExports && freeGlobal.process;
  12199. /** Used to access faster Node.js helpers. */
  12200. var nodeUtil = function () {
  12201. try {
  12202. return freeProcess && freeProcess.binding('util');
  12203. } catch (e) {}
  12204. }();
  12205. /* Node.js helper references. */
  12206. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  12207. /**
  12208. * A specialized version of `_.includes` for arrays without support for
  12209. * specifying an index to search from.
  12210. *
  12211. * @private
  12212. * @param {Array} [array] The array to inspect.
  12213. * @param {*} target The value to search for.
  12214. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  12215. */
  12216. function arrayIncludes(array, value) {
  12217. var length = array ? array.length : 0;
  12218. return !!length && baseIndexOf(array, value, 0) > -1;
  12219. }
  12220. /**
  12221. * This function is like `arrayIncludes` except that it accepts a comparator.
  12222. *
  12223. * @private
  12224. * @param {Array} [array] The array to inspect.
  12225. * @param {*} target The value to search for.
  12226. * @param {Function} comparator The comparator invoked per element.
  12227. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  12228. */
  12229. function arrayIncludesWith(array, value, comparator) {
  12230. var index = -1,
  12231. length = array ? array.length : 0;
  12232. while (++index < length) {
  12233. if (comparator(value, array[index])) {
  12234. return true;
  12235. }
  12236. }
  12237. return false;
  12238. }
  12239. /**
  12240. * A specialized version of `_.some` for arrays without support for iteratee
  12241. * shorthands.
  12242. *
  12243. * @private
  12244. * @param {Array} [array] The array to iterate over.
  12245. * @param {Function} predicate The function invoked per iteration.
  12246. * @returns {boolean} Returns `true` if any element passes the predicate check,
  12247. * else `false`.
  12248. */
  12249. function arraySome(array, predicate) {
  12250. var index = -1,
  12251. length = array ? array.length : 0;
  12252. while (++index < length) {
  12253. if (predicate(array[index], index, array)) {
  12254. return true;
  12255. }
  12256. }
  12257. return false;
  12258. }
  12259. /**
  12260. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  12261. * support for iteratee shorthands.
  12262. *
  12263. * @private
  12264. * @param {Array} array The array to inspect.
  12265. * @param {Function} predicate The function invoked per iteration.
  12266. * @param {number} fromIndex The index to search from.
  12267. * @param {boolean} [fromRight] Specify iterating from right to left.
  12268. * @returns {number} Returns the index of the matched value, else `-1`.
  12269. */
  12270. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  12271. var length = array.length,
  12272. index = fromIndex + (fromRight ? 1 : -1);
  12273. while (fromRight ? index-- : ++index < length) {
  12274. if (predicate(array[index], index, array)) {
  12275. return index;
  12276. }
  12277. }
  12278. return -1;
  12279. }
  12280. /**
  12281. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  12282. *
  12283. * @private
  12284. * @param {Array} array The array to inspect.
  12285. * @param {*} value The value to search for.
  12286. * @param {number} fromIndex The index to search from.
  12287. * @returns {number} Returns the index of the matched value, else `-1`.
  12288. */
  12289. function baseIndexOf(array, value, fromIndex) {
  12290. if (value !== value) {
  12291. return baseFindIndex(array, baseIsNaN, fromIndex);
  12292. }
  12293. var index = fromIndex - 1,
  12294. length = array.length;
  12295. while (++index < length) {
  12296. if (array[index] === value) {
  12297. return index;
  12298. }
  12299. }
  12300. return -1;
  12301. }
  12302. /**
  12303. * The base implementation of `_.isNaN` without support for number objects.
  12304. *
  12305. * @private
  12306. * @param {*} value The value to check.
  12307. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  12308. */
  12309. function baseIsNaN(value) {
  12310. return value !== value;
  12311. }
  12312. /**
  12313. * The base implementation of `_.property` without support for deep paths.
  12314. *
  12315. * @private
  12316. * @param {string} key The key of the property to get.
  12317. * @returns {Function} Returns the new accessor function.
  12318. */
  12319. function baseProperty(key) {
  12320. return function (object) {
  12321. return object == null ? undefined : object[key];
  12322. };
  12323. }
  12324. /**
  12325. * The base implementation of `_.times` without support for iteratee shorthands
  12326. * or max array length checks.
  12327. *
  12328. * @private
  12329. * @param {number} n The number of times to invoke `iteratee`.
  12330. * @param {Function} iteratee The function invoked per iteration.
  12331. * @returns {Array} Returns the array of results.
  12332. */
  12333. function baseTimes(n, iteratee) {
  12334. var index = -1,
  12335. result = Array(n);
  12336. while (++index < n) {
  12337. result[index] = iteratee(index);
  12338. }
  12339. return result;
  12340. }
  12341. /**
  12342. * The base implementation of `_.unary` without support for storing metadata.
  12343. *
  12344. * @private
  12345. * @param {Function} func The function to cap arguments for.
  12346. * @returns {Function} Returns the new capped function.
  12347. */
  12348. function baseUnary(func) {
  12349. return function (value) {
  12350. return func(value);
  12351. };
  12352. }
  12353. /**
  12354. * Checks if a cache value for `key` exists.
  12355. *
  12356. * @private
  12357. * @param {Object} cache The cache to query.
  12358. * @param {string} key The key of the entry to check.
  12359. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12360. */
  12361. function cacheHas(cache, key) {
  12362. return cache.has(key);
  12363. }
  12364. /**
  12365. * Gets the value at `key` of `object`.
  12366. *
  12367. * @private
  12368. * @param {Object} [object] The object to query.
  12369. * @param {string} key The key of the property to get.
  12370. * @returns {*} Returns the property value.
  12371. */
  12372. function getValue(object, key) {
  12373. return object == null ? undefined : object[key];
  12374. }
  12375. /**
  12376. * Checks if `value` is a host object in IE < 9.
  12377. *
  12378. * @private
  12379. * @param {*} value The value to check.
  12380. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  12381. */
  12382. function isHostObject(value) {
  12383. // Many host objects are `Object` objects that can coerce to strings
  12384. // despite having improperly defined `toString` methods.
  12385. var result = false;
  12386. if (value != null && typeof value.toString != 'function') {
  12387. try {
  12388. result = !!(value + '');
  12389. } catch (e) {}
  12390. }
  12391. return result;
  12392. }
  12393. /**
  12394. * Converts `map` to its key-value pairs.
  12395. *
  12396. * @private
  12397. * @param {Object} map The map to convert.
  12398. * @returns {Array} Returns the key-value pairs.
  12399. */
  12400. function mapToArray(map) {
  12401. var index = -1,
  12402. result = Array(map.size);
  12403. map.forEach(function (value, key) {
  12404. result[++index] = [key, value];
  12405. });
  12406. return result;
  12407. }
  12408. /**
  12409. * Creates a unary function that invokes `func` with its argument transformed.
  12410. *
  12411. * @private
  12412. * @param {Function} func The function to wrap.
  12413. * @param {Function} transform The argument transform.
  12414. * @returns {Function} Returns the new function.
  12415. */
  12416. function overArg(func, transform) {
  12417. return function (arg) {
  12418. return func(transform(arg));
  12419. };
  12420. }
  12421. /**
  12422. * Converts `set` to an array of its values.
  12423. *
  12424. * @private
  12425. * @param {Object} set The set to convert.
  12426. * @returns {Array} Returns the values.
  12427. */
  12428. function setToArray(set) {
  12429. var index = -1,
  12430. result = Array(set.size);
  12431. set.forEach(function (value) {
  12432. result[++index] = value;
  12433. });
  12434. return result;
  12435. }
  12436. /** Used for built-in method references. */
  12437. var arrayProto = Array.prototype,
  12438. funcProto = Function.prototype,
  12439. objectProto = Object.prototype;
  12440. /** Used to detect overreaching core-js shims. */
  12441. var coreJsData = root['__core-js_shared__'];
  12442. /** Used to detect methods masquerading as native. */
  12443. var maskSrcKey = function () {
  12444. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  12445. return uid ? 'Symbol(src)_1.' + uid : '';
  12446. }();
  12447. /** Used to resolve the decompiled source of functions. */
  12448. var funcToString = funcProto.toString;
  12449. /** Used to check objects for own properties. */
  12450. var hasOwnProperty = objectProto.hasOwnProperty;
  12451. /**
  12452. * Used to resolve the
  12453. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  12454. * of values.
  12455. */
  12456. var objectToString = objectProto.toString;
  12457. /** Used to detect if a method is native. */
  12458. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  12459. /** Built-in value references. */
  12460. var Symbol = root.Symbol,
  12461. Uint8Array = root.Uint8Array,
  12462. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  12463. splice = arrayProto.splice;
  12464. /* Built-in method references for those with the same name as other `lodash` methods. */
  12465. var nativeKeys = overArg(Object.keys, Object);
  12466. /* Built-in method references that are verified to be native. */
  12467. var DataView = getNative(root, 'DataView'),
  12468. Map = getNative(root, 'Map'),
  12469. Promise = getNative(root, 'Promise'),
  12470. Set = getNative(root, 'Set'),
  12471. WeakMap = getNative(root, 'WeakMap'),
  12472. nativeCreate = getNative(Object, 'create');
  12473. /** Used to detect maps, sets, and weakmaps. */
  12474. var dataViewCtorString = toSource(DataView),
  12475. mapCtorString = toSource(Map),
  12476. promiseCtorString = toSource(Promise),
  12477. setCtorString = toSource(Set),
  12478. weakMapCtorString = toSource(WeakMap);
  12479. /** Used to convert symbols to primitives and strings. */
  12480. var symbolProto = Symbol ? Symbol.prototype : undefined,
  12481. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  12482. symbolToString = symbolProto ? symbolProto.toString : undefined;
  12483. /**
  12484. * Creates a hash object.
  12485. *
  12486. * @private
  12487. * @constructor
  12488. * @param {Array} [entries] The key-value pairs to cache.
  12489. */
  12490. function Hash(entries) {
  12491. var index = -1,
  12492. length = entries ? entries.length : 0;
  12493. this.clear();
  12494. while (++index < length) {
  12495. var entry = entries[index];
  12496. this.set(entry[0], entry[1]);
  12497. }
  12498. }
  12499. /**
  12500. * Removes all key-value entries from the hash.
  12501. *
  12502. * @private
  12503. * @name clear
  12504. * @memberOf Hash
  12505. */
  12506. function hashClear() {
  12507. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  12508. }
  12509. /**
  12510. * Removes `key` and its value from the hash.
  12511. *
  12512. * @private
  12513. * @name delete
  12514. * @memberOf Hash
  12515. * @param {Object} hash The hash to modify.
  12516. * @param {string} key The key of the value to remove.
  12517. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12518. */
  12519. function hashDelete(key) {
  12520. return this.has(key) && delete this.__data__[key];
  12521. }
  12522. /**
  12523. * Gets the hash value for `key`.
  12524. *
  12525. * @private
  12526. * @name get
  12527. * @memberOf Hash
  12528. * @param {string} key The key of the value to get.
  12529. * @returns {*} Returns the entry value.
  12530. */
  12531. function hashGet(key) {
  12532. var data = this.__data__;
  12533. if (nativeCreate) {
  12534. var result = data[key];
  12535. return result === HASH_UNDEFINED ? undefined : result;
  12536. }
  12537. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  12538. }
  12539. /**
  12540. * Checks if a hash value for `key` exists.
  12541. *
  12542. * @private
  12543. * @name has
  12544. * @memberOf Hash
  12545. * @param {string} key The key of the entry to check.
  12546. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12547. */
  12548. function hashHas(key) {
  12549. var data = this.__data__;
  12550. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  12551. }
  12552. /**
  12553. * Sets the hash `key` to `value`.
  12554. *
  12555. * @private
  12556. * @name set
  12557. * @memberOf Hash
  12558. * @param {string} key The key of the value to set.
  12559. * @param {*} value The value to set.
  12560. * @returns {Object} Returns the hash instance.
  12561. */
  12562. function hashSet(key, value) {
  12563. var data = this.__data__;
  12564. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  12565. return this;
  12566. } // Add methods to `Hash`.
  12567. Hash.prototype.clear = hashClear;
  12568. Hash.prototype['delete'] = hashDelete;
  12569. Hash.prototype.get = hashGet;
  12570. Hash.prototype.has = hashHas;
  12571. Hash.prototype.set = hashSet;
  12572. /**
  12573. * Creates an list cache object.
  12574. *
  12575. * @private
  12576. * @constructor
  12577. * @param {Array} [entries] The key-value pairs to cache.
  12578. */
  12579. function ListCache(entries) {
  12580. var index = -1,
  12581. length = entries ? entries.length : 0;
  12582. this.clear();
  12583. while (++index < length) {
  12584. var entry = entries[index];
  12585. this.set(entry[0], entry[1]);
  12586. }
  12587. }
  12588. /**
  12589. * Removes all key-value entries from the list cache.
  12590. *
  12591. * @private
  12592. * @name clear
  12593. * @memberOf ListCache
  12594. */
  12595. function listCacheClear() {
  12596. this.__data__ = [];
  12597. }
  12598. /**
  12599. * Removes `key` and its value from the list cache.
  12600. *
  12601. * @private
  12602. * @name delete
  12603. * @memberOf ListCache
  12604. * @param {string} key The key of the value to remove.
  12605. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12606. */
  12607. function listCacheDelete(key) {
  12608. var data = this.__data__,
  12609. index = assocIndexOf(data, key);
  12610. if (index < 0) {
  12611. return false;
  12612. }
  12613. var lastIndex = data.length - 1;
  12614. if (index == lastIndex) {
  12615. data.pop();
  12616. } else {
  12617. splice.call(data, index, 1);
  12618. }
  12619. return true;
  12620. }
  12621. /**
  12622. * Gets the list cache value for `key`.
  12623. *
  12624. * @private
  12625. * @name get
  12626. * @memberOf ListCache
  12627. * @param {string} key The key of the value to get.
  12628. * @returns {*} Returns the entry value.
  12629. */
  12630. function listCacheGet(key) {
  12631. var data = this.__data__,
  12632. index = assocIndexOf(data, key);
  12633. return index < 0 ? undefined : data[index][1];
  12634. }
  12635. /**
  12636. * Checks if a list cache value for `key` exists.
  12637. *
  12638. * @private
  12639. * @name has
  12640. * @memberOf ListCache
  12641. * @param {string} key The key of the entry to check.
  12642. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12643. */
  12644. function listCacheHas(key) {
  12645. return assocIndexOf(this.__data__, key) > -1;
  12646. }
  12647. /**
  12648. * Sets the list cache `key` to `value`.
  12649. *
  12650. * @private
  12651. * @name set
  12652. * @memberOf ListCache
  12653. * @param {string} key The key of the value to set.
  12654. * @param {*} value The value to set.
  12655. * @returns {Object} Returns the list cache instance.
  12656. */
  12657. function listCacheSet(key, value) {
  12658. var data = this.__data__,
  12659. index = assocIndexOf(data, key);
  12660. if (index < 0) {
  12661. data.push([key, value]);
  12662. } else {
  12663. data[index][1] = value;
  12664. }
  12665. return this;
  12666. } // Add methods to `ListCache`.
  12667. ListCache.prototype.clear = listCacheClear;
  12668. ListCache.prototype['delete'] = listCacheDelete;
  12669. ListCache.prototype.get = listCacheGet;
  12670. ListCache.prototype.has = listCacheHas;
  12671. ListCache.prototype.set = listCacheSet;
  12672. /**
  12673. * Creates a map cache object to store key-value pairs.
  12674. *
  12675. * @private
  12676. * @constructor
  12677. * @param {Array} [entries] The key-value pairs to cache.
  12678. */
  12679. function MapCache(entries) {
  12680. var index = -1,
  12681. length = entries ? entries.length : 0;
  12682. this.clear();
  12683. while (++index < length) {
  12684. var entry = entries[index];
  12685. this.set(entry[0], entry[1]);
  12686. }
  12687. }
  12688. /**
  12689. * Removes all key-value entries from the map.
  12690. *
  12691. * @private
  12692. * @name clear
  12693. * @memberOf MapCache
  12694. */
  12695. function mapCacheClear() {
  12696. this.__data__ = {
  12697. 'hash': new Hash(),
  12698. 'map': new (Map || ListCache)(),
  12699. 'string': new Hash()
  12700. };
  12701. }
  12702. /**
  12703. * Removes `key` and its value from the map.
  12704. *
  12705. * @private
  12706. * @name delete
  12707. * @memberOf MapCache
  12708. * @param {string} key The key of the value to remove.
  12709. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12710. */
  12711. function mapCacheDelete(key) {
  12712. return getMapData(this, key)['delete'](key);
  12713. }
  12714. /**
  12715. * Gets the map value for `key`.
  12716. *
  12717. * @private
  12718. * @name get
  12719. * @memberOf MapCache
  12720. * @param {string} key The key of the value to get.
  12721. * @returns {*} Returns the entry value.
  12722. */
  12723. function mapCacheGet(key) {
  12724. return getMapData(this, key).get(key);
  12725. }
  12726. /**
  12727. * Checks if a map value for `key` exists.
  12728. *
  12729. * @private
  12730. * @name has
  12731. * @memberOf MapCache
  12732. * @param {string} key The key of the entry to check.
  12733. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12734. */
  12735. function mapCacheHas(key) {
  12736. return getMapData(this, key).has(key);
  12737. }
  12738. /**
  12739. * Sets the map `key` to `value`.
  12740. *
  12741. * @private
  12742. * @name set
  12743. * @memberOf MapCache
  12744. * @param {string} key The key of the value to set.
  12745. * @param {*} value The value to set.
  12746. * @returns {Object} Returns the map cache instance.
  12747. */
  12748. function mapCacheSet(key, value) {
  12749. getMapData(this, key).set(key, value);
  12750. return this;
  12751. } // Add methods to `MapCache`.
  12752. MapCache.prototype.clear = mapCacheClear;
  12753. MapCache.prototype['delete'] = mapCacheDelete;
  12754. MapCache.prototype.get = mapCacheGet;
  12755. MapCache.prototype.has = mapCacheHas;
  12756. MapCache.prototype.set = mapCacheSet;
  12757. /**
  12758. *
  12759. * Creates an array cache object to store unique values.
  12760. *
  12761. * @private
  12762. * @constructor
  12763. * @param {Array} [values] The values to cache.
  12764. */
  12765. function SetCache(values) {
  12766. var index = -1,
  12767. length = values ? values.length : 0;
  12768. this.__data__ = new MapCache();
  12769. while (++index < length) {
  12770. this.add(values[index]);
  12771. }
  12772. }
  12773. /**
  12774. * Adds `value` to the array cache.
  12775. *
  12776. * @private
  12777. * @name add
  12778. * @memberOf SetCache
  12779. * @alias push
  12780. * @param {*} value The value to cache.
  12781. * @returns {Object} Returns the cache instance.
  12782. */
  12783. function setCacheAdd(value) {
  12784. this.__data__.set(value, HASH_UNDEFINED);
  12785. return this;
  12786. }
  12787. /**
  12788. * Checks if `value` is in the array cache.
  12789. *
  12790. * @private
  12791. * @name has
  12792. * @memberOf SetCache
  12793. * @param {*} value The value to search for.
  12794. * @returns {number} Returns `true` if `value` is found, else `false`.
  12795. */
  12796. function setCacheHas(value) {
  12797. return this.__data__.has(value);
  12798. } // Add methods to `SetCache`.
  12799. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  12800. SetCache.prototype.has = setCacheHas;
  12801. /**
  12802. * Creates a stack cache object to store key-value pairs.
  12803. *
  12804. * @private
  12805. * @constructor
  12806. * @param {Array} [entries] The key-value pairs to cache.
  12807. */
  12808. function Stack(entries) {
  12809. this.__data__ = new ListCache(entries);
  12810. }
  12811. /**
  12812. * Removes all key-value entries from the stack.
  12813. *
  12814. * @private
  12815. * @name clear
  12816. * @memberOf Stack
  12817. */
  12818. function stackClear() {
  12819. this.__data__ = new ListCache();
  12820. }
  12821. /**
  12822. * Removes `key` and its value from the stack.
  12823. *
  12824. * @private
  12825. * @name delete
  12826. * @memberOf Stack
  12827. * @param {string} key The key of the value to remove.
  12828. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12829. */
  12830. function stackDelete(key) {
  12831. return this.__data__['delete'](key);
  12832. }
  12833. /**
  12834. * Gets the stack value for `key`.
  12835. *
  12836. * @private
  12837. * @name get
  12838. * @memberOf Stack
  12839. * @param {string} key The key of the value to get.
  12840. * @returns {*} Returns the entry value.
  12841. */
  12842. function stackGet(key) {
  12843. return this.__data__.get(key);
  12844. }
  12845. /**
  12846. * Checks if a stack value for `key` exists.
  12847. *
  12848. * @private
  12849. * @name has
  12850. * @memberOf Stack
  12851. * @param {string} key The key of the entry to check.
  12852. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12853. */
  12854. function stackHas(key) {
  12855. return this.__data__.has(key);
  12856. }
  12857. /**
  12858. * Sets the stack `key` to `value`.
  12859. *
  12860. * @private
  12861. * @name set
  12862. * @memberOf Stack
  12863. * @param {string} key The key of the value to set.
  12864. * @param {*} value The value to set.
  12865. * @returns {Object} Returns the stack cache instance.
  12866. */
  12867. function stackSet(key, value) {
  12868. var cache = this.__data__;
  12869. if (cache instanceof ListCache) {
  12870. var pairs = cache.__data__;
  12871. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  12872. pairs.push([key, value]);
  12873. return this;
  12874. }
  12875. cache = this.__data__ = new MapCache(pairs);
  12876. }
  12877. cache.set(key, value);
  12878. return this;
  12879. } // Add methods to `Stack`.
  12880. Stack.prototype.clear = stackClear;
  12881. Stack.prototype['delete'] = stackDelete;
  12882. Stack.prototype.get = stackGet;
  12883. Stack.prototype.has = stackHas;
  12884. Stack.prototype.set = stackSet;
  12885. /**
  12886. * Creates an array of the enumerable property names of the array-like `value`.
  12887. *
  12888. * @private
  12889. * @param {*} value The value to query.
  12890. * @param {boolean} inherited Specify returning inherited property names.
  12891. * @returns {Array} Returns the array of property names.
  12892. */
  12893. function arrayLikeKeys(value, inherited) {
  12894. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  12895. // Safari 9 makes `arguments.length` enumerable in strict mode.
  12896. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  12897. var length = result.length,
  12898. skipIndexes = !!length;
  12899. for (var key in value) {
  12900. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  12901. result.push(key);
  12902. }
  12903. }
  12904. return result;
  12905. }
  12906. /**
  12907. * Gets the index at which the `key` is found in `array` of key-value pairs.
  12908. *
  12909. * @private
  12910. * @param {Array} array The array to inspect.
  12911. * @param {*} key The key to search for.
  12912. * @returns {number} Returns the index of the matched value, else `-1`.
  12913. */
  12914. function assocIndexOf(array, key) {
  12915. var length = array.length;
  12916. while (length--) {
  12917. if (eq(array[length][0], key)) {
  12918. return length;
  12919. }
  12920. }
  12921. return -1;
  12922. }
  12923. /**
  12924. * The base implementation of `_.get` without support for default values.
  12925. *
  12926. * @private
  12927. * @param {Object} object The object to query.
  12928. * @param {Array|string} path The path of the property to get.
  12929. * @returns {*} Returns the resolved value.
  12930. */
  12931. function baseGet(object, path$$1) {
  12932. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  12933. var index = 0,
  12934. length = path$$1.length;
  12935. while (object != null && index < length) {
  12936. object = object[toKey(path$$1[index++])];
  12937. }
  12938. return index && index == length ? object : undefined;
  12939. }
  12940. /**
  12941. * The base implementation of `getTag`.
  12942. *
  12943. * @private
  12944. * @param {*} value The value to query.
  12945. * @returns {string} Returns the `toStringTag`.
  12946. */
  12947. function baseGetTag(value) {
  12948. return objectToString.call(value);
  12949. }
  12950. /**
  12951. * The base implementation of `_.hasIn` without support for deep paths.
  12952. *
  12953. * @private
  12954. * @param {Object} [object] The object to query.
  12955. * @param {Array|string} key The key to check.
  12956. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  12957. */
  12958. function baseHasIn(object, key) {
  12959. return object != null && key in Object(object);
  12960. }
  12961. /**
  12962. * The base implementation of `_.isEqual` which supports partial comparisons
  12963. * and tracks traversed objects.
  12964. *
  12965. * @private
  12966. * @param {*} value The value to compare.
  12967. * @param {*} other The other value to compare.
  12968. * @param {Function} [customizer] The function to customize comparisons.
  12969. * @param {boolean} [bitmask] The bitmask of comparison flags.
  12970. * The bitmask may be composed of the following flags:
  12971. * 1 - Unordered comparison
  12972. * 2 - Partial comparison
  12973. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  12974. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  12975. */
  12976. function baseIsEqual(value, other, customizer, bitmask, stack) {
  12977. if (value === other) {
  12978. return true;
  12979. }
  12980. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  12981. return value !== value && other !== other;
  12982. }
  12983. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  12984. }
  12985. /**
  12986. * A specialized version of `baseIsEqual` for arrays and objects which performs
  12987. * deep comparisons and tracks traversed objects enabling objects with circular
  12988. * references to be compared.
  12989. *
  12990. * @private
  12991. * @param {Object} object The object to compare.
  12992. * @param {Object} other The other object to compare.
  12993. * @param {Function} equalFunc The function to determine equivalents of values.
  12994. * @param {Function} [customizer] The function to customize comparisons.
  12995. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  12996. * for more details.
  12997. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  12998. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  12999. */
  13000. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  13001. var objIsArr = isArray(object),
  13002. othIsArr = isArray(other),
  13003. objTag = arrayTag,
  13004. othTag = arrayTag;
  13005. if (!objIsArr) {
  13006. objTag = getTag(object);
  13007. objTag = objTag == argsTag ? objectTag : objTag;
  13008. }
  13009. if (!othIsArr) {
  13010. othTag = getTag(other);
  13011. othTag = othTag == argsTag ? objectTag : othTag;
  13012. }
  13013. var objIsObj = objTag == objectTag && !isHostObject(object),
  13014. othIsObj = othTag == objectTag && !isHostObject(other),
  13015. isSameTag = objTag == othTag;
  13016. if (isSameTag && !objIsObj) {
  13017. stack || (stack = new Stack());
  13018. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  13019. }
  13020. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  13021. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  13022. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  13023. if (objIsWrapped || othIsWrapped) {
  13024. var objUnwrapped = objIsWrapped ? object.value() : object,
  13025. othUnwrapped = othIsWrapped ? other.value() : other;
  13026. stack || (stack = new Stack());
  13027. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  13028. }
  13029. }
  13030. if (!isSameTag) {
  13031. return false;
  13032. }
  13033. stack || (stack = new Stack());
  13034. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  13035. }
  13036. /**
  13037. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  13038. *
  13039. * @private
  13040. * @param {Object} object The object to inspect.
  13041. * @param {Object} source The object of property values to match.
  13042. * @param {Array} matchData The property names, values, and compare flags to match.
  13043. * @param {Function} [customizer] The function to customize comparisons.
  13044. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  13045. */
  13046. function baseIsMatch(object, source, matchData, customizer) {
  13047. var index = matchData.length,
  13048. length = index,
  13049. noCustomizer = !customizer;
  13050. if (object == null) {
  13051. return !length;
  13052. }
  13053. object = Object(object);
  13054. while (index--) {
  13055. var data = matchData[index];
  13056. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  13057. return false;
  13058. }
  13059. }
  13060. while (++index < length) {
  13061. data = matchData[index];
  13062. var key = data[0],
  13063. objValue = object[key],
  13064. srcValue = data[1];
  13065. if (noCustomizer && data[2]) {
  13066. if (objValue === undefined && !(key in object)) {
  13067. return false;
  13068. }
  13069. } else {
  13070. var stack = new Stack();
  13071. if (customizer) {
  13072. var result = customizer(objValue, srcValue, key, object, source, stack);
  13073. }
  13074. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  13075. return false;
  13076. }
  13077. }
  13078. }
  13079. return true;
  13080. }
  13081. /**
  13082. * The base implementation of `_.isNative` without bad shim checks.
  13083. *
  13084. * @private
  13085. * @param {*} value The value to check.
  13086. * @returns {boolean} Returns `true` if `value` is a native function,
  13087. * else `false`.
  13088. */
  13089. function baseIsNative(value) {
  13090. if (!isObject(value) || isMasked(value)) {
  13091. return false;
  13092. }
  13093. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  13094. return pattern.test(toSource(value));
  13095. }
  13096. /**
  13097. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  13098. *
  13099. * @private
  13100. * @param {*} value The value to check.
  13101. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  13102. */
  13103. function baseIsTypedArray(value) {
  13104. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  13105. }
  13106. /**
  13107. * The base implementation of `_.iteratee`.
  13108. *
  13109. * @private
  13110. * @param {*} [value=_.identity] The value to convert to an iteratee.
  13111. * @returns {Function} Returns the iteratee.
  13112. */
  13113. function baseIteratee(value) {
  13114. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  13115. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  13116. if (typeof value == 'function') {
  13117. return value;
  13118. }
  13119. if (value == null) {
  13120. return identity;
  13121. }
  13122. if (typeof value == 'object') {
  13123. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  13124. }
  13125. return property(value);
  13126. }
  13127. /**
  13128. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  13129. *
  13130. * @private
  13131. * @param {Object} object The object to query.
  13132. * @returns {Array} Returns the array of property names.
  13133. */
  13134. function baseKeys(object) {
  13135. if (!isPrototype(object)) {
  13136. return nativeKeys(object);
  13137. }
  13138. var result = [];
  13139. for (var key in Object(object)) {
  13140. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  13141. result.push(key);
  13142. }
  13143. }
  13144. return result;
  13145. }
  13146. /**
  13147. * The base implementation of `_.matches` which doesn't clone `source`.
  13148. *
  13149. * @private
  13150. * @param {Object} source The object of property values to match.
  13151. * @returns {Function} Returns the new spec function.
  13152. */
  13153. function baseMatches(source) {
  13154. var matchData = getMatchData(source);
  13155. if (matchData.length == 1 && matchData[0][2]) {
  13156. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  13157. }
  13158. return function (object) {
  13159. return object === source || baseIsMatch(object, source, matchData);
  13160. };
  13161. }
  13162. /**
  13163. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  13164. *
  13165. * @private
  13166. * @param {string} path The path of the property to get.
  13167. * @param {*} srcValue The value to match.
  13168. * @returns {Function} Returns the new spec function.
  13169. */
  13170. function baseMatchesProperty(path$$1, srcValue) {
  13171. if (isKey(path$$1) && isStrictComparable(srcValue)) {
  13172. return matchesStrictComparable(toKey(path$$1), srcValue);
  13173. }
  13174. return function (object) {
  13175. var objValue = get(object, path$$1);
  13176. return objValue === undefined && objValue === srcValue ? hasIn(object, path$$1) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  13177. };
  13178. }
  13179. /**
  13180. * A specialized version of `baseProperty` which supports deep paths.
  13181. *
  13182. * @private
  13183. * @param {Array|string} path The path of the property to get.
  13184. * @returns {Function} Returns the new accessor function.
  13185. */
  13186. function basePropertyDeep(path$$1) {
  13187. return function (object) {
  13188. return baseGet(object, path$$1);
  13189. };
  13190. }
  13191. /**
  13192. * The base implementation of `_.toString` which doesn't convert nullish
  13193. * values to empty strings.
  13194. *
  13195. * @private
  13196. * @param {*} value The value to process.
  13197. * @returns {string} Returns the string.
  13198. */
  13199. function baseToString(value) {
  13200. // Exit early for strings to avoid a performance hit in some environments.
  13201. if (typeof value == 'string') {
  13202. return value;
  13203. }
  13204. if (isSymbol(value)) {
  13205. return symbolToString ? symbolToString.call(value) : '';
  13206. }
  13207. var result = value + '';
  13208. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  13209. }
  13210. /**
  13211. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  13212. *
  13213. * @private
  13214. * @param {Array} array The array to inspect.
  13215. * @param {Function} [iteratee] The iteratee invoked per element.
  13216. * @param {Function} [comparator] The comparator invoked per element.
  13217. * @returns {Array} Returns the new duplicate free array.
  13218. */
  13219. function baseUniq(array, iteratee, comparator) {
  13220. var index = -1,
  13221. includes = arrayIncludes,
  13222. length = array.length,
  13223. isCommon = true,
  13224. result = [],
  13225. seen = result;
  13226. if (comparator) {
  13227. isCommon = false;
  13228. includes = arrayIncludesWith;
  13229. } else if (length >= LARGE_ARRAY_SIZE) {
  13230. var set = iteratee ? null : createSet(array);
  13231. if (set) {
  13232. return setToArray(set);
  13233. }
  13234. isCommon = false;
  13235. includes = cacheHas;
  13236. seen = new SetCache();
  13237. } else {
  13238. seen = iteratee ? [] : result;
  13239. }
  13240. outer: while (++index < length) {
  13241. var value = array[index],
  13242. computed = iteratee ? iteratee(value) : value;
  13243. value = comparator || value !== 0 ? value : 0;
  13244. if (isCommon && computed === computed) {
  13245. var seenIndex = seen.length;
  13246. while (seenIndex--) {
  13247. if (seen[seenIndex] === computed) {
  13248. continue outer;
  13249. }
  13250. }
  13251. if (iteratee) {
  13252. seen.push(computed);
  13253. }
  13254. result.push(value);
  13255. } else if (!includes(seen, computed, comparator)) {
  13256. if (seen !== result) {
  13257. seen.push(computed);
  13258. }
  13259. result.push(value);
  13260. }
  13261. }
  13262. return result;
  13263. }
  13264. /**
  13265. * Casts `value` to a path array if it's not one.
  13266. *
  13267. * @private
  13268. * @param {*} value The value to inspect.
  13269. * @returns {Array} Returns the cast property path array.
  13270. */
  13271. function castPath(value) {
  13272. return isArray(value) ? value : stringToPath(value);
  13273. }
  13274. /**
  13275. * Creates a set object of `values`.
  13276. *
  13277. * @private
  13278. * @param {Array} values The values to add to the set.
  13279. * @returns {Object} Returns the new set.
  13280. */
  13281. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  13282. return new Set(values);
  13283. };
  13284. /**
  13285. * A specialized version of `baseIsEqualDeep` for arrays with support for
  13286. * partial deep comparisons.
  13287. *
  13288. * @private
  13289. * @param {Array} array The array to compare.
  13290. * @param {Array} other The other array to compare.
  13291. * @param {Function} equalFunc The function to determine equivalents of values.
  13292. * @param {Function} customizer The function to customize comparisons.
  13293. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  13294. * for more details.
  13295. * @param {Object} stack Tracks traversed `array` and `other` objects.
  13296. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  13297. */
  13298. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  13299. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  13300. arrLength = array.length,
  13301. othLength = other.length;
  13302. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  13303. return false;
  13304. } // Assume cyclic values are equal.
  13305. var stacked = stack.get(array);
  13306. if (stacked && stack.get(other)) {
  13307. return stacked == other;
  13308. }
  13309. var index = -1,
  13310. result = true,
  13311. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  13312. stack.set(array, other);
  13313. stack.set(other, array); // Ignore non-index properties.
  13314. while (++index < arrLength) {
  13315. var arrValue = array[index],
  13316. othValue = other[index];
  13317. if (customizer) {
  13318. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  13319. }
  13320. if (compared !== undefined) {
  13321. if (compared) {
  13322. continue;
  13323. }
  13324. result = false;
  13325. break;
  13326. } // Recursively compare arrays (susceptible to call stack limits).
  13327. if (seen) {
  13328. if (!arraySome(other, function (othValue, othIndex) {
  13329. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  13330. return seen.add(othIndex);
  13331. }
  13332. })) {
  13333. result = false;
  13334. break;
  13335. }
  13336. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  13337. result = false;
  13338. break;
  13339. }
  13340. }
  13341. stack['delete'](array);
  13342. stack['delete'](other);
  13343. return result;
  13344. }
  13345. /**
  13346. * A specialized version of `baseIsEqualDeep` for comparing objects of
  13347. * the same `toStringTag`.
  13348. *
  13349. * **Note:** This function only supports comparing values with tags of
  13350. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  13351. *
  13352. * @private
  13353. * @param {Object} object The object to compare.
  13354. * @param {Object} other The other object to compare.
  13355. * @param {string} tag The `toStringTag` of the objects to compare.
  13356. * @param {Function} equalFunc The function to determine equivalents of values.
  13357. * @param {Function} customizer The function to customize comparisons.
  13358. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  13359. * for more details.
  13360. * @param {Object} stack Tracks traversed `object` and `other` objects.
  13361. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  13362. */
  13363. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  13364. switch (tag) {
  13365. case dataViewTag:
  13366. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  13367. return false;
  13368. }
  13369. object = object.buffer;
  13370. other = other.buffer;
  13371. case arrayBufferTag:
  13372. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  13373. return false;
  13374. }
  13375. return true;
  13376. case boolTag:
  13377. case dateTag:
  13378. case numberTag:
  13379. // Coerce booleans to `1` or `0` and dates to milliseconds.
  13380. // Invalid dates are coerced to `NaN`.
  13381. return eq(+object, +other);
  13382. case errorTag:
  13383. return object.name == other.name && object.message == other.message;
  13384. case regexpTag:
  13385. case stringTag:
  13386. // Coerce regexes to strings and treat strings, primitives and objects,
  13387. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  13388. // for more details.
  13389. return object == other + '';
  13390. case mapTag:
  13391. var convert = mapToArray;
  13392. case setTag:
  13393. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  13394. convert || (convert = setToArray);
  13395. if (object.size != other.size && !isPartial) {
  13396. return false;
  13397. } // Assume cyclic values are equal.
  13398. var stacked = stack.get(object);
  13399. if (stacked) {
  13400. return stacked == other;
  13401. }
  13402. bitmask |= UNORDERED_COMPARE_FLAG; // Recursively compare objects (susceptible to call stack limits).
  13403. stack.set(object, other);
  13404. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  13405. stack['delete'](object);
  13406. return result;
  13407. case symbolTag:
  13408. if (symbolValueOf) {
  13409. return symbolValueOf.call(object) == symbolValueOf.call(other);
  13410. }
  13411. }
  13412. return false;
  13413. }
  13414. /**
  13415. * A specialized version of `baseIsEqualDeep` for objects with support for
  13416. * partial deep comparisons.
  13417. *
  13418. * @private
  13419. * @param {Object} object The object to compare.
  13420. * @param {Object} other The other object to compare.
  13421. * @param {Function} equalFunc The function to determine equivalents of values.
  13422. * @param {Function} customizer The function to customize comparisons.
  13423. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  13424. * for more details.
  13425. * @param {Object} stack Tracks traversed `object` and `other` objects.
  13426. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  13427. */
  13428. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  13429. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  13430. objProps = keys(object),
  13431. objLength = objProps.length,
  13432. othProps = keys(other),
  13433. othLength = othProps.length;
  13434. if (objLength != othLength && !isPartial) {
  13435. return false;
  13436. }
  13437. var index = objLength;
  13438. while (index--) {
  13439. var key = objProps[index];
  13440. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  13441. return false;
  13442. }
  13443. } // Assume cyclic values are equal.
  13444. var stacked = stack.get(object);
  13445. if (stacked && stack.get(other)) {
  13446. return stacked == other;
  13447. }
  13448. var result = true;
  13449. stack.set(object, other);
  13450. stack.set(other, object);
  13451. var skipCtor = isPartial;
  13452. while (++index < objLength) {
  13453. key = objProps[index];
  13454. var objValue = object[key],
  13455. othValue = other[key];
  13456. if (customizer) {
  13457. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  13458. } // Recursively compare objects (susceptible to call stack limits).
  13459. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  13460. result = false;
  13461. break;
  13462. }
  13463. skipCtor || (skipCtor = key == 'constructor');
  13464. }
  13465. if (result && !skipCtor) {
  13466. var objCtor = object.constructor,
  13467. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  13468. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  13469. result = false;
  13470. }
  13471. }
  13472. stack['delete'](object);
  13473. stack['delete'](other);
  13474. return result;
  13475. }
  13476. /**
  13477. * Gets the data for `map`.
  13478. *
  13479. * @private
  13480. * @param {Object} map The map to query.
  13481. * @param {string} key The reference key.
  13482. * @returns {*} Returns the map data.
  13483. */
  13484. function getMapData(map, key) {
  13485. var data = map.__data__;
  13486. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  13487. }
  13488. /**
  13489. * Gets the property names, values, and compare flags of `object`.
  13490. *
  13491. * @private
  13492. * @param {Object} object The object to query.
  13493. * @returns {Array} Returns the match data of `object`.
  13494. */
  13495. function getMatchData(object) {
  13496. var result = keys(object),
  13497. length = result.length;
  13498. while (length--) {
  13499. var key = result[length],
  13500. value = object[key];
  13501. result[length] = [key, value, isStrictComparable(value)];
  13502. }
  13503. return result;
  13504. }
  13505. /**
  13506. * Gets the native function at `key` of `object`.
  13507. *
  13508. * @private
  13509. * @param {Object} object The object to query.
  13510. * @param {string} key The key of the method to get.
  13511. * @returns {*} Returns the function if it's native, else `undefined`.
  13512. */
  13513. function getNative(object, key) {
  13514. var value = getValue(object, key);
  13515. return baseIsNative(value) ? value : undefined;
  13516. }
  13517. /**
  13518. * Gets the `toStringTag` of `value`.
  13519. *
  13520. * @private
  13521. * @param {*} value The value to query.
  13522. * @returns {string} Returns the `toStringTag`.
  13523. */
  13524. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11,
  13525. // for data views in Edge < 14, and promises in Node.js.
  13526. 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) {
  13527. getTag = function getTag(value) {
  13528. var result = objectToString.call(value),
  13529. Ctor = result == objectTag ? value.constructor : undefined,
  13530. ctorString = Ctor ? toSource(Ctor) : undefined;
  13531. if (ctorString) {
  13532. switch (ctorString) {
  13533. case dataViewCtorString:
  13534. return dataViewTag;
  13535. case mapCtorString:
  13536. return mapTag;
  13537. case promiseCtorString:
  13538. return promiseTag;
  13539. case setCtorString:
  13540. return setTag;
  13541. case weakMapCtorString:
  13542. return weakMapTag;
  13543. }
  13544. }
  13545. return result;
  13546. };
  13547. }
  13548. /**
  13549. * Checks if `path` exists on `object`.
  13550. *
  13551. * @private
  13552. * @param {Object} object The object to query.
  13553. * @param {Array|string} path The path to check.
  13554. * @param {Function} hasFunc The function to check properties.
  13555. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13556. */
  13557. function hasPath(object, path$$1, hasFunc) {
  13558. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  13559. var result,
  13560. index = -1,
  13561. length = path$$1.length;
  13562. while (++index < length) {
  13563. var key = toKey(path$$1[index]);
  13564. if (!(result = object != null && hasFunc(object, key))) {
  13565. break;
  13566. }
  13567. object = object[key];
  13568. }
  13569. if (result) {
  13570. return result;
  13571. }
  13572. var length = object ? object.length : 0;
  13573. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  13574. }
  13575. /**
  13576. * Checks if `value` is a valid array-like index.
  13577. *
  13578. * @private
  13579. * @param {*} value The value to check.
  13580. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  13581. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  13582. */
  13583. function isIndex(value, length) {
  13584. length = length == null ? MAX_SAFE_INTEGER : length;
  13585. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  13586. }
  13587. /**
  13588. * Checks if `value` is a property name and not a property path.
  13589. *
  13590. * @private
  13591. * @param {*} value The value to check.
  13592. * @param {Object} [object] The object to query keys on.
  13593. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  13594. */
  13595. function isKey(value, object) {
  13596. if (isArray(value)) {
  13597. return false;
  13598. }
  13599. var type = typeof value;
  13600. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  13601. return true;
  13602. }
  13603. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  13604. }
  13605. /**
  13606. * Checks if `value` is suitable for use as unique object key.
  13607. *
  13608. * @private
  13609. * @param {*} value The value to check.
  13610. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  13611. */
  13612. function isKeyable(value) {
  13613. var type = typeof value;
  13614. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  13615. }
  13616. /**
  13617. * Checks if `func` has its source masked.
  13618. *
  13619. * @private
  13620. * @param {Function} func The function to check.
  13621. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  13622. */
  13623. function isMasked(func) {
  13624. return !!maskSrcKey && maskSrcKey in func;
  13625. }
  13626. /**
  13627. * Checks if `value` is likely a prototype object.
  13628. *
  13629. * @private
  13630. * @param {*} value The value to check.
  13631. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  13632. */
  13633. function isPrototype(value) {
  13634. var Ctor = value && value.constructor,
  13635. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  13636. return value === proto;
  13637. }
  13638. /**
  13639. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  13640. *
  13641. * @private
  13642. * @param {*} value The value to check.
  13643. * @returns {boolean} Returns `true` if `value` if suitable for strict
  13644. * equality comparisons, else `false`.
  13645. */
  13646. function isStrictComparable(value) {
  13647. return value === value && !isObject(value);
  13648. }
  13649. /**
  13650. * A specialized version of `matchesProperty` for source values suitable
  13651. * for strict equality comparisons, i.e. `===`.
  13652. *
  13653. * @private
  13654. * @param {string} key The key of the property to get.
  13655. * @param {*} srcValue The value to match.
  13656. * @returns {Function} Returns the new spec function.
  13657. */
  13658. function matchesStrictComparable(key, srcValue) {
  13659. return function (object) {
  13660. if (object == null) {
  13661. return false;
  13662. }
  13663. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  13664. };
  13665. }
  13666. /**
  13667. * Converts `string` to a property path array.
  13668. *
  13669. * @private
  13670. * @param {string} string The string to convert.
  13671. * @returns {Array} Returns the property path array.
  13672. */
  13673. var stringToPath = memoize(function (string) {
  13674. string = toString(string);
  13675. var result = [];
  13676. if (reLeadingDot.test(string)) {
  13677. result.push('');
  13678. }
  13679. string.replace(rePropName, function (match, number, quote, string) {
  13680. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  13681. });
  13682. return result;
  13683. });
  13684. /**
  13685. * Converts `value` to a string key if it's not a string or symbol.
  13686. *
  13687. * @private
  13688. * @param {*} value The value to inspect.
  13689. * @returns {string|symbol} Returns the key.
  13690. */
  13691. function toKey(value) {
  13692. if (typeof value == 'string' || isSymbol(value)) {
  13693. return value;
  13694. }
  13695. var result = value + '';
  13696. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  13697. }
  13698. /**
  13699. * Converts `func` to its source code.
  13700. *
  13701. * @private
  13702. * @param {Function} func The function to process.
  13703. * @returns {string} Returns the source code.
  13704. */
  13705. function toSource(func) {
  13706. if (func != null) {
  13707. try {
  13708. return funcToString.call(func);
  13709. } catch (e) {}
  13710. try {
  13711. return func + '';
  13712. } catch (e) {}
  13713. }
  13714. return '';
  13715. }
  13716. /**
  13717. * This method is like `_.uniq` except that it accepts `iteratee` which is
  13718. * invoked for each element in `array` to generate the criterion by which
  13719. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  13720. *
  13721. * @static
  13722. * @memberOf _
  13723. * @since 4.0.0
  13724. * @category Array
  13725. * @param {Array} array The array to inspect.
  13726. * @param {Function} [iteratee=_.identity]
  13727. * The iteratee invoked per element.
  13728. * @returns {Array} Returns the new duplicate free array.
  13729. * @example
  13730. *
  13731. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  13732. * // => [2.1, 1.2]
  13733. *
  13734. * // The `_.property` iteratee shorthand.
  13735. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  13736. * // => [{ 'x': 1 }, { 'x': 2 }]
  13737. */
  13738. function uniqBy(array, iteratee) {
  13739. return array && array.length ? baseUniq(array, baseIteratee(iteratee, 2)) : [];
  13740. }
  13741. /**
  13742. * Creates a function that memoizes the result of `func`. If `resolver` is
  13743. * provided, it determines the cache key for storing the result based on the
  13744. * arguments provided to the memoized function. By default, the first argument
  13745. * provided to the memoized function is used as the map cache key. The `func`
  13746. * is invoked with the `this` binding of the memoized function.
  13747. *
  13748. * **Note:** The cache is exposed as the `cache` property on the memoized
  13749. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  13750. * constructor with one whose instances implement the
  13751. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  13752. * method interface of `delete`, `get`, `has`, and `set`.
  13753. *
  13754. * @static
  13755. * @memberOf _
  13756. * @since 0.1.0
  13757. * @category Function
  13758. * @param {Function} func The function to have its output memoized.
  13759. * @param {Function} [resolver] The function to resolve the cache key.
  13760. * @returns {Function} Returns the new memoized function.
  13761. * @example
  13762. *
  13763. * var object = { 'a': 1, 'b': 2 };
  13764. * var other = { 'c': 3, 'd': 4 };
  13765. *
  13766. * var values = _.memoize(_.values);
  13767. * values(object);
  13768. * // => [1, 2]
  13769. *
  13770. * values(other);
  13771. * // => [3, 4]
  13772. *
  13773. * object.a = 2;
  13774. * values(object);
  13775. * // => [1, 2]
  13776. *
  13777. * // Modify the result cache.
  13778. * values.cache.set(object, ['a', 'b']);
  13779. * values(object);
  13780. * // => ['a', 'b']
  13781. *
  13782. * // Replace `_.memoize.Cache`.
  13783. * _.memoize.Cache = WeakMap;
  13784. */
  13785. function memoize(func, resolver) {
  13786. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  13787. throw new TypeError(FUNC_ERROR_TEXT);
  13788. }
  13789. var memoized = function memoized() {
  13790. var args = arguments,
  13791. key = resolver ? resolver.apply(this, args) : args[0],
  13792. cache = memoized.cache;
  13793. if (cache.has(key)) {
  13794. return cache.get(key);
  13795. }
  13796. var result = func.apply(this, args);
  13797. memoized.cache = cache.set(key, result);
  13798. return result;
  13799. };
  13800. memoized.cache = new (memoize.Cache || MapCache)();
  13801. return memoized;
  13802. } // Assign cache to `_.memoize`.
  13803. memoize.Cache = MapCache;
  13804. /**
  13805. * Performs a
  13806. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  13807. * comparison between two values to determine if they are equivalent.
  13808. *
  13809. * @static
  13810. * @memberOf _
  13811. * @since 4.0.0
  13812. * @category Lang
  13813. * @param {*} value The value to compare.
  13814. * @param {*} other The other value to compare.
  13815. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  13816. * @example
  13817. *
  13818. * var object = { 'a': 1 };
  13819. * var other = { 'a': 1 };
  13820. *
  13821. * _.eq(object, object);
  13822. * // => true
  13823. *
  13824. * _.eq(object, other);
  13825. * // => false
  13826. *
  13827. * _.eq('a', 'a');
  13828. * // => true
  13829. *
  13830. * _.eq('a', Object('a'));
  13831. * // => false
  13832. *
  13833. * _.eq(NaN, NaN);
  13834. * // => true
  13835. */
  13836. function eq(value, other) {
  13837. return value === other || value !== value && other !== other;
  13838. }
  13839. /**
  13840. * Checks if `value` is likely an `arguments` object.
  13841. *
  13842. * @static
  13843. * @memberOf _
  13844. * @since 0.1.0
  13845. * @category Lang
  13846. * @param {*} value The value to check.
  13847. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  13848. * else `false`.
  13849. * @example
  13850. *
  13851. * _.isArguments(function() { return arguments; }());
  13852. * // => true
  13853. *
  13854. * _.isArguments([1, 2, 3]);
  13855. * // => false
  13856. */
  13857. function isArguments(value) {
  13858. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  13859. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  13860. }
  13861. /**
  13862. * Checks if `value` is classified as an `Array` object.
  13863. *
  13864. * @static
  13865. * @memberOf _
  13866. * @since 0.1.0
  13867. * @category Lang
  13868. * @param {*} value The value to check.
  13869. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  13870. * @example
  13871. *
  13872. * _.isArray([1, 2, 3]);
  13873. * // => true
  13874. *
  13875. * _.isArray(document.body.children);
  13876. * // => false
  13877. *
  13878. * _.isArray('abc');
  13879. * // => false
  13880. *
  13881. * _.isArray(_.noop);
  13882. * // => false
  13883. */
  13884. var isArray = Array.isArray;
  13885. /**
  13886. * Checks if `value` is array-like. A value is considered array-like if it's
  13887. * not a function and has a `value.length` that's an integer greater than or
  13888. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  13889. *
  13890. * @static
  13891. * @memberOf _
  13892. * @since 4.0.0
  13893. * @category Lang
  13894. * @param {*} value The value to check.
  13895. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  13896. * @example
  13897. *
  13898. * _.isArrayLike([1, 2, 3]);
  13899. * // => true
  13900. *
  13901. * _.isArrayLike(document.body.children);
  13902. * // => true
  13903. *
  13904. * _.isArrayLike('abc');
  13905. * // => true
  13906. *
  13907. * _.isArrayLike(_.noop);
  13908. * // => false
  13909. */
  13910. function isArrayLike(value) {
  13911. return value != null && isLength(value.length) && !isFunction(value);
  13912. }
  13913. /**
  13914. * This method is like `_.isArrayLike` except that it also checks if `value`
  13915. * is an object.
  13916. *
  13917. * @static
  13918. * @memberOf _
  13919. * @since 4.0.0
  13920. * @category Lang
  13921. * @param {*} value The value to check.
  13922. * @returns {boolean} Returns `true` if `value` is an array-like object,
  13923. * else `false`.
  13924. * @example
  13925. *
  13926. * _.isArrayLikeObject([1, 2, 3]);
  13927. * // => true
  13928. *
  13929. * _.isArrayLikeObject(document.body.children);
  13930. * // => true
  13931. *
  13932. * _.isArrayLikeObject('abc');
  13933. * // => false
  13934. *
  13935. * _.isArrayLikeObject(_.noop);
  13936. * // => false
  13937. */
  13938. function isArrayLikeObject(value) {
  13939. return isObjectLike(value) && isArrayLike(value);
  13940. }
  13941. /**
  13942. * Checks if `value` is classified as a `Function` object.
  13943. *
  13944. * @static
  13945. * @memberOf _
  13946. * @since 0.1.0
  13947. * @category Lang
  13948. * @param {*} value The value to check.
  13949. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  13950. * @example
  13951. *
  13952. * _.isFunction(_);
  13953. * // => true
  13954. *
  13955. * _.isFunction(/abc/);
  13956. * // => false
  13957. */
  13958. function isFunction(value) {
  13959. // The use of `Object#toString` avoids issues with the `typeof` operator
  13960. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  13961. var tag = isObject(value) ? objectToString.call(value) : '';
  13962. return tag == funcTag || tag == genTag;
  13963. }
  13964. /**
  13965. * Checks if `value` is a valid array-like length.
  13966. *
  13967. * **Note:** This method is loosely based on
  13968. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  13969. *
  13970. * @static
  13971. * @memberOf _
  13972. * @since 4.0.0
  13973. * @category Lang
  13974. * @param {*} value The value to check.
  13975. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  13976. * @example
  13977. *
  13978. * _.isLength(3);
  13979. * // => true
  13980. *
  13981. * _.isLength(Number.MIN_VALUE);
  13982. * // => false
  13983. *
  13984. * _.isLength(Infinity);
  13985. * // => false
  13986. *
  13987. * _.isLength('3');
  13988. * // => false
  13989. */
  13990. function isLength(value) {
  13991. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  13992. }
  13993. /**
  13994. * Checks if `value` is the
  13995. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  13996. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  13997. *
  13998. * @static
  13999. * @memberOf _
  14000. * @since 0.1.0
  14001. * @category Lang
  14002. * @param {*} value The value to check.
  14003. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  14004. * @example
  14005. *
  14006. * _.isObject({});
  14007. * // => true
  14008. *
  14009. * _.isObject([1, 2, 3]);
  14010. * // => true
  14011. *
  14012. * _.isObject(_.noop);
  14013. * // => true
  14014. *
  14015. * _.isObject(null);
  14016. * // => false
  14017. */
  14018. function isObject(value) {
  14019. var type = typeof value;
  14020. return !!value && (type == 'object' || type == 'function');
  14021. }
  14022. /**
  14023. * Checks if `value` is object-like. A value is object-like if it's not `null`
  14024. * and has a `typeof` result of "object".
  14025. *
  14026. * @static
  14027. * @memberOf _
  14028. * @since 4.0.0
  14029. * @category Lang
  14030. * @param {*} value The value to check.
  14031. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  14032. * @example
  14033. *
  14034. * _.isObjectLike({});
  14035. * // => true
  14036. *
  14037. * _.isObjectLike([1, 2, 3]);
  14038. * // => true
  14039. *
  14040. * _.isObjectLike(_.noop);
  14041. * // => false
  14042. *
  14043. * _.isObjectLike(null);
  14044. * // => false
  14045. */
  14046. function isObjectLike(value) {
  14047. return !!value && typeof value == 'object';
  14048. }
  14049. /**
  14050. * Checks if `value` is classified as a `Symbol` primitive or object.
  14051. *
  14052. * @static
  14053. * @memberOf _
  14054. * @since 4.0.0
  14055. * @category Lang
  14056. * @param {*} value The value to check.
  14057. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  14058. * @example
  14059. *
  14060. * _.isSymbol(Symbol.iterator);
  14061. * // => true
  14062. *
  14063. * _.isSymbol('abc');
  14064. * // => false
  14065. */
  14066. function isSymbol(value) {
  14067. return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  14068. }
  14069. /**
  14070. * Checks if `value` is classified as a typed array.
  14071. *
  14072. * @static
  14073. * @memberOf _
  14074. * @since 3.0.0
  14075. * @category Lang
  14076. * @param {*} value The value to check.
  14077. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  14078. * @example
  14079. *
  14080. * _.isTypedArray(new Uint8Array);
  14081. * // => true
  14082. *
  14083. * _.isTypedArray([]);
  14084. * // => false
  14085. */
  14086. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  14087. /**
  14088. * Converts `value` to a string. An empty string is returned for `null`
  14089. * and `undefined` values. The sign of `-0` is preserved.
  14090. *
  14091. * @static
  14092. * @memberOf _
  14093. * @since 4.0.0
  14094. * @category Lang
  14095. * @param {*} value The value to process.
  14096. * @returns {string} Returns the string.
  14097. * @example
  14098. *
  14099. * _.toString(null);
  14100. * // => ''
  14101. *
  14102. * _.toString(-0);
  14103. * // => '-0'
  14104. *
  14105. * _.toString([1, 2, 3]);
  14106. * // => '1,2,3'
  14107. */
  14108. function toString(value) {
  14109. return value == null ? '' : baseToString(value);
  14110. }
  14111. /**
  14112. * Gets the value at `path` of `object`. If the resolved value is
  14113. * `undefined`, the `defaultValue` is returned in its place.
  14114. *
  14115. * @static
  14116. * @memberOf _
  14117. * @since 3.7.0
  14118. * @category Object
  14119. * @param {Object} object The object to query.
  14120. * @param {Array|string} path The path of the property to get.
  14121. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  14122. * @returns {*} Returns the resolved value.
  14123. * @example
  14124. *
  14125. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  14126. *
  14127. * _.get(object, 'a[0].b.c');
  14128. * // => 3
  14129. *
  14130. * _.get(object, ['a', '0', 'b', 'c']);
  14131. * // => 3
  14132. *
  14133. * _.get(object, 'a.b.c', 'default');
  14134. * // => 'default'
  14135. */
  14136. function get(object, path$$1, defaultValue) {
  14137. var result = object == null ? undefined : baseGet(object, path$$1);
  14138. return result === undefined ? defaultValue : result;
  14139. }
  14140. /**
  14141. * Checks if `path` is a direct or inherited property of `object`.
  14142. *
  14143. * @static
  14144. * @memberOf _
  14145. * @since 4.0.0
  14146. * @category Object
  14147. * @param {Object} object The object to query.
  14148. * @param {Array|string} path The path to check.
  14149. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  14150. * @example
  14151. *
  14152. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  14153. *
  14154. * _.hasIn(object, 'a');
  14155. * // => true
  14156. *
  14157. * _.hasIn(object, 'a.b');
  14158. * // => true
  14159. *
  14160. * _.hasIn(object, ['a', 'b']);
  14161. * // => true
  14162. *
  14163. * _.hasIn(object, 'b');
  14164. * // => false
  14165. */
  14166. function hasIn(object, path$$1) {
  14167. return object != null && hasPath(object, path$$1, baseHasIn);
  14168. }
  14169. /**
  14170. * Creates an array of the own enumerable property names of `object`.
  14171. *
  14172. * **Note:** Non-object values are coerced to objects. See the
  14173. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  14174. * for more details.
  14175. *
  14176. * @static
  14177. * @since 0.1.0
  14178. * @memberOf _
  14179. * @category Object
  14180. * @param {Object} object The object to query.
  14181. * @returns {Array} Returns the array of property names.
  14182. * @example
  14183. *
  14184. * function Foo() {
  14185. * this.a = 1;
  14186. * this.b = 2;
  14187. * }
  14188. *
  14189. * Foo.prototype.c = 3;
  14190. *
  14191. * _.keys(new Foo);
  14192. * // => ['a', 'b'] (iteration order is not guaranteed)
  14193. *
  14194. * _.keys('hi');
  14195. * // => ['0', '1']
  14196. */
  14197. function keys(object) {
  14198. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  14199. }
  14200. /**
  14201. * This method returns the first argument it receives.
  14202. *
  14203. * @static
  14204. * @since 0.1.0
  14205. * @memberOf _
  14206. * @category Util
  14207. * @param {*} value Any value.
  14208. * @returns {*} Returns `value`.
  14209. * @example
  14210. *
  14211. * var object = { 'a': 1 };
  14212. *
  14213. * console.log(_.identity(object) === object);
  14214. * // => true
  14215. */
  14216. function identity(value) {
  14217. return value;
  14218. }
  14219. /**
  14220. * This method returns `undefined`.
  14221. *
  14222. * @static
  14223. * @memberOf _
  14224. * @since 2.3.0
  14225. * @category Util
  14226. * @example
  14227. *
  14228. * _.times(2, _.noop);
  14229. * // => [undefined, undefined]
  14230. */
  14231. function noop() {} // No operation performed.
  14232. /**
  14233. * Creates a function that returns the value at `path` of a given object.
  14234. *
  14235. * @static
  14236. * @memberOf _
  14237. * @since 2.4.0
  14238. * @category Util
  14239. * @param {Array|string} path The path of the property to get.
  14240. * @returns {Function} Returns the new accessor function.
  14241. * @example
  14242. *
  14243. * var objects = [
  14244. * { 'a': { 'b': 2 } },
  14245. * { 'a': { 'b': 1 } }
  14246. * ];
  14247. *
  14248. * _.map(objects, _.property('a.b'));
  14249. * // => [2, 1]
  14250. *
  14251. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14252. * // => [1, 2]
  14253. */
  14254. function property(path$$1) {
  14255. return isKey(path$$1) ? baseProperty(toKey(path$$1)) : basePropertyDeep(path$$1);
  14256. }
  14257. module.exports = uniqBy;
  14258. });
  14259. var PENDING = 'pending';
  14260. var SETTLED = 'settled';
  14261. var FULFILLED = 'fulfilled';
  14262. var REJECTED = 'rejected';
  14263. var NOOP = function NOOP() {};
  14264. var isNode = typeof global !== 'undefined' && typeof global.process !== 'undefined' && typeof global.process.emit === 'function';
  14265. var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
  14266. var asyncQueue = [];
  14267. var asyncTimer;
  14268. function asyncFlush() {
  14269. // run promise callbacks
  14270. for (var i = 0; i < asyncQueue.length; i++) {
  14271. asyncQueue[i][0](asyncQueue[i][1]);
  14272. } // reset async asyncQueue
  14273. asyncQueue = [];
  14274. asyncTimer = false;
  14275. }
  14276. function asyncCall(callback, arg) {
  14277. asyncQueue.push([callback, arg]);
  14278. if (!asyncTimer) {
  14279. asyncTimer = true;
  14280. asyncSetTimer(asyncFlush, 0);
  14281. }
  14282. }
  14283. function invokeResolver(resolver, promise) {
  14284. function resolvePromise(value) {
  14285. resolve(promise, value);
  14286. }
  14287. function rejectPromise(reason) {
  14288. reject(promise, reason);
  14289. }
  14290. try {
  14291. resolver(resolvePromise, rejectPromise);
  14292. } catch (e) {
  14293. rejectPromise(e);
  14294. }
  14295. }
  14296. function invokeCallback(subscriber) {
  14297. var owner = subscriber.owner;
  14298. var settled = owner._state;
  14299. var value = owner._data;
  14300. var callback = subscriber[settled];
  14301. var promise = subscriber.then;
  14302. if (typeof callback === 'function') {
  14303. settled = FULFILLED;
  14304. try {
  14305. value = callback(value);
  14306. } catch (e) {
  14307. reject(promise, e);
  14308. }
  14309. }
  14310. if (!handleThenable(promise, value)) {
  14311. if (settled === FULFILLED) {
  14312. resolve(promise, value);
  14313. }
  14314. if (settled === REJECTED) {
  14315. reject(promise, value);
  14316. }
  14317. }
  14318. }
  14319. function handleThenable(promise, value) {
  14320. var resolved;
  14321. try {
  14322. if (promise === value) {
  14323. throw new TypeError('A promises callback cannot return that same promise.');
  14324. }
  14325. if (value && (typeof value === 'function' || typeof value === 'object')) {
  14326. // then should be retrieved only once
  14327. var then = value.then;
  14328. if (typeof then === 'function') {
  14329. then.call(value, function (val) {
  14330. if (!resolved) {
  14331. resolved = true;
  14332. if (value === val) {
  14333. fulfill(promise, val);
  14334. } else {
  14335. resolve(promise, val);
  14336. }
  14337. }
  14338. }, function (reason) {
  14339. if (!resolved) {
  14340. resolved = true;
  14341. reject(promise, reason);
  14342. }
  14343. });
  14344. return true;
  14345. }
  14346. }
  14347. } catch (e) {
  14348. if (!resolved) {
  14349. reject(promise, e);
  14350. }
  14351. return true;
  14352. }
  14353. return false;
  14354. }
  14355. function resolve(promise, value) {
  14356. if (promise === value || !handleThenable(promise, value)) {
  14357. fulfill(promise, value);
  14358. }
  14359. }
  14360. function fulfill(promise, value) {
  14361. if (promise._state === PENDING) {
  14362. promise._state = SETTLED;
  14363. promise._data = value;
  14364. asyncCall(publishFulfillment, promise);
  14365. }
  14366. }
  14367. function reject(promise, reason) {
  14368. if (promise._state === PENDING) {
  14369. promise._state = SETTLED;
  14370. promise._data = reason;
  14371. asyncCall(publishRejection, promise);
  14372. }
  14373. }
  14374. function publish(promise) {
  14375. promise._then = promise._then.forEach(invokeCallback);
  14376. }
  14377. function publishFulfillment(promise) {
  14378. promise._state = FULFILLED;
  14379. publish(promise);
  14380. }
  14381. function publishRejection(promise) {
  14382. promise._state = REJECTED;
  14383. publish(promise);
  14384. if (!promise._handled && isNode) {
  14385. global.process.emit('unhandledRejection', promise._data, promise);
  14386. }
  14387. }
  14388. function notifyRejectionHandled(promise) {
  14389. global.process.emit('rejectionHandled', promise);
  14390. }
  14391. /**
  14392. * @class
  14393. */
  14394. function Promise$1(resolver) {
  14395. if (typeof resolver !== 'function') {
  14396. throw new TypeError('Promise resolver ' + resolver + ' is not a function');
  14397. }
  14398. if (this instanceof Promise$1 === false) {
  14399. throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
  14400. }
  14401. this._then = [];
  14402. invokeResolver(resolver, this);
  14403. }
  14404. Promise$1.prototype = {
  14405. constructor: Promise$1,
  14406. _state: PENDING,
  14407. _then: null,
  14408. _data: undefined,
  14409. _handled: false,
  14410. then: function then(onFulfillment, onRejection) {
  14411. var subscriber = {
  14412. owner: this,
  14413. then: new this.constructor(NOOP),
  14414. fulfilled: onFulfillment,
  14415. rejected: onRejection
  14416. };
  14417. if ((onRejection || onFulfillment) && !this._handled) {
  14418. this._handled = true;
  14419. if (this._state === REJECTED && isNode) {
  14420. asyncCall(notifyRejectionHandled, this);
  14421. }
  14422. }
  14423. if (this._state === FULFILLED || this._state === REJECTED) {
  14424. // already resolved, call callback async
  14425. asyncCall(invokeCallback, subscriber);
  14426. } else {
  14427. // subscribe
  14428. this._then.push(subscriber);
  14429. }
  14430. return subscriber.then;
  14431. },
  14432. catch: function _catch(onRejection) {
  14433. return this.then(null, onRejection);
  14434. }
  14435. };
  14436. Promise$1.all = function (promises) {
  14437. if (!Array.isArray(promises)) {
  14438. throw new TypeError('You must pass an array to Promise.all().');
  14439. }
  14440. return new Promise$1(function (resolve, reject) {
  14441. var results = [];
  14442. var remaining = 0;
  14443. function resolver(index) {
  14444. remaining++;
  14445. return function (value) {
  14446. results[index] = value;
  14447. if (! --remaining) {
  14448. resolve(results);
  14449. }
  14450. };
  14451. }
  14452. for (var i = 0, promise; i < promises.length; i++) {
  14453. promise = promises[i];
  14454. if (promise && typeof promise.then === 'function') {
  14455. promise.then(resolver(i), reject);
  14456. } else {
  14457. results[i] = promise;
  14458. }
  14459. }
  14460. if (!remaining) {
  14461. resolve(results);
  14462. }
  14463. });
  14464. };
  14465. Promise$1.race = function (promises) {
  14466. if (!Array.isArray(promises)) {
  14467. throw new TypeError('You must pass an array to Promise.race().');
  14468. }
  14469. return new Promise$1(function (resolve, reject) {
  14470. for (var i = 0, promise; i < promises.length; i++) {
  14471. promise = promises[i];
  14472. if (promise && typeof promise.then === 'function') {
  14473. promise.then(resolve, reject);
  14474. } else {
  14475. resolve(promise);
  14476. }
  14477. }
  14478. });
  14479. };
  14480. Promise$1.resolve = function (value) {
  14481. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  14482. return value;
  14483. }
  14484. return new Promise$1(function (resolve) {
  14485. resolve(value);
  14486. });
  14487. };
  14488. Promise$1.reject = function (reason) {
  14489. return new Promise$1(function (resolve, reject) {
  14490. reject(reason);
  14491. });
  14492. };
  14493. var pinkie = Promise$1;
  14494. var pinkiePromise = typeof Promise === 'function' ? Promise : pinkie;
  14495. var arrayUniq = createCommonjsModule(function (module) {
  14496. 'use strict'; // there's 3 implementations written in increasing order of efficiency
  14497. // 1 - no Set type is defined
  14498. function uniqNoSet(arr) {
  14499. var ret = [];
  14500. for (var i = 0; i < arr.length; i++) {
  14501. if (ret.indexOf(arr[i]) === -1) {
  14502. ret.push(arr[i]);
  14503. }
  14504. }
  14505. return ret;
  14506. } // 2 - a simple Set type is defined
  14507. function uniqSet(arr) {
  14508. var seen = new Set();
  14509. return arr.filter(function (el) {
  14510. if (!seen.has(el)) {
  14511. seen.add(el);
  14512. return true;
  14513. }
  14514. return false;
  14515. });
  14516. } // 3 - a standard Set type is defined and it has a forEach method
  14517. function uniqSetWithForEach(arr) {
  14518. var ret = [];
  14519. new Set(arr).forEach(function (el) {
  14520. ret.push(el);
  14521. });
  14522. return ret;
  14523. } // V8 currently has a broken implementation
  14524. // https://github.com/joyent/node/issues/8449
  14525. function doesForEachActuallyWork() {
  14526. var ret = false;
  14527. new Set([true]).forEach(function (el) {
  14528. ret = el;
  14529. });
  14530. return ret === true;
  14531. }
  14532. if ('Set' in global) {
  14533. if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) {
  14534. module.exports = uniqSetWithForEach;
  14535. } else {
  14536. module.exports = uniqSet;
  14537. }
  14538. } else {
  14539. module.exports = uniqNoSet;
  14540. }
  14541. });
  14542. var arrayUnion = function arrayUnion() {
  14543. return arrayUniq([].concat.apply([], arguments));
  14544. };
  14545. /*
  14546. object-assign
  14547. (c) Sindre Sorhus
  14548. @license MIT
  14549. */
  14550. /* eslint-disable no-unused-vars */
  14551. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  14552. var hasOwnProperty = Object.prototype.hasOwnProperty;
  14553. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  14554. function toObject(val) {
  14555. if (val === null || val === undefined) {
  14556. throw new TypeError('Object.assign cannot be called with null or undefined');
  14557. }
  14558. return Object(val);
  14559. }
  14560. function shouldUseNative() {
  14561. try {
  14562. if (!Object.assign) {
  14563. return false;
  14564. } // Detect buggy property enumeration order in older V8 versions.
  14565. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  14566. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  14567. test1[5] = 'de';
  14568. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  14569. return false;
  14570. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  14571. var test2 = {};
  14572. for (var i = 0; i < 10; i++) {
  14573. test2['_' + String.fromCharCode(i)] = i;
  14574. }
  14575. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  14576. return test2[n];
  14577. });
  14578. if (order2.join('') !== '0123456789') {
  14579. return false;
  14580. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  14581. var test3 = {};
  14582. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  14583. test3[letter] = letter;
  14584. });
  14585. if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
  14586. return false;
  14587. }
  14588. return true;
  14589. } catch (err) {
  14590. // We don't expect any of the above to throw, but better to be safe.
  14591. return false;
  14592. }
  14593. }
  14594. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  14595. var from;
  14596. var to = toObject(target);
  14597. var symbols;
  14598. for (var s = 1; s < arguments.length; s++) {
  14599. from = Object(arguments[s]);
  14600. for (var key in from) {
  14601. if (hasOwnProperty.call(from, key)) {
  14602. to[key] = from[key];
  14603. }
  14604. }
  14605. if (getOwnPropertySymbols) {
  14606. symbols = getOwnPropertySymbols(from);
  14607. for (var i = 0; i < symbols.length; i++) {
  14608. if (propIsEnumerable.call(from, symbols[i])) {
  14609. to[symbols[i]] = from[symbols[i]];
  14610. }
  14611. }
  14612. }
  14613. }
  14614. return to;
  14615. };
  14616. //
  14617. // Permission is hereby granted, free of charge, to any person obtaining a
  14618. // copy of this software and associated documentation files (the
  14619. // "Software"), to deal in the Software without restriction, including
  14620. // without limitation the rights to use, copy, modify, merge, publish,
  14621. // distribute, sublicense, and/or sell copies of the Software, and to permit
  14622. // persons to whom the Software is furnished to do so, subject to the
  14623. // following conditions:
  14624. //
  14625. // The above copyright notice and this permission notice shall be included
  14626. // in all copies or substantial portions of the Software.
  14627. //
  14628. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14629. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14630. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  14631. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  14632. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  14633. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  14634. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  14635. var isWindows = process.platform === 'win32'; // JavaScript implementation of realpath, ported from node pre-v6
  14636. var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
  14637. function rethrow() {
  14638. // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
  14639. // is fairly slow to generate.
  14640. var callback;
  14641. if (DEBUG) {
  14642. var backtrace = new Error();
  14643. callback = debugCallback;
  14644. } else callback = missingCallback;
  14645. return callback;
  14646. function debugCallback(err) {
  14647. if (err) {
  14648. backtrace.message = err.message;
  14649. err = backtrace;
  14650. missingCallback(err);
  14651. }
  14652. }
  14653. function missingCallback(err) {
  14654. if (err) {
  14655. if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
  14656. else if (!process.noDeprecation) {
  14657. var msg = 'fs: missing callback ' + (err.stack || err.message);
  14658. if (process.traceDeprecation) console.trace(msg);else console.error(msg);
  14659. }
  14660. }
  14661. }
  14662. }
  14663. function maybeCallback(cb) {
  14664. return typeof cb === 'function' ? cb : rethrow();
  14665. }
  14666. // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
  14667. if (isWindows) {
  14668. var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
  14669. } else {
  14670. var nextPartRe = /(.*?)(?:[\/]+|$)/g;
  14671. } // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
  14672. if (isWindows) {
  14673. var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
  14674. } else {
  14675. var splitRootRe = /^[\/]*/;
  14676. }
  14677. var realpathSync$1 = function realpathSync(p, cache) {
  14678. // make p is absolute
  14679. p = path.resolve(p);
  14680. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  14681. return cache[p];
  14682. }
  14683. var original = p,
  14684. seenLinks = {},
  14685. knownHard = {}; // current character position in p
  14686. var pos; // the partial path so far, including a trailing slash if any
  14687. var current; // the partial path without a trailing slash (except when pointing at a root)
  14688. var base; // the partial path scanned in the previous round, with slash
  14689. var previous;
  14690. start();
  14691. function start() {
  14692. // Skip over roots
  14693. var m = splitRootRe.exec(p);
  14694. pos = m[0].length;
  14695. current = m[0];
  14696. base = m[0];
  14697. previous = ''; // On windows, check that the root exists. On unix there is no need.
  14698. if (isWindows && !knownHard[base]) {
  14699. fs.lstatSync(base);
  14700. knownHard[base] = true;
  14701. }
  14702. } // walk down the path, swapping out linked pathparts for their real
  14703. // values
  14704. // NB: p.length changes.
  14705. while (pos < p.length) {
  14706. // find the next part
  14707. nextPartRe.lastIndex = pos;
  14708. var result = nextPartRe.exec(p);
  14709. previous = current;
  14710. current += result[0];
  14711. base = previous + result[1];
  14712. pos = nextPartRe.lastIndex; // continue if not a symlink
  14713. if (knownHard[base] || cache && cache[base] === base) {
  14714. continue;
  14715. }
  14716. var resolvedLink;
  14717. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  14718. // some known symbolic link. no need to stat again.
  14719. resolvedLink = cache[base];
  14720. } else {
  14721. var stat = fs.lstatSync(base);
  14722. if (!stat.isSymbolicLink()) {
  14723. knownHard[base] = true;
  14724. if (cache) cache[base] = base;
  14725. continue;
  14726. } // read the link if it wasn't read before
  14727. // dev/ino always return 0 on windows, so skip the check.
  14728. var linkTarget = null;
  14729. if (!isWindows) {
  14730. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  14731. if (seenLinks.hasOwnProperty(id)) {
  14732. linkTarget = seenLinks[id];
  14733. }
  14734. }
  14735. if (linkTarget === null) {
  14736. fs.statSync(base);
  14737. linkTarget = fs.readlinkSync(base);
  14738. }
  14739. resolvedLink = path.resolve(previous, linkTarget); // track this, if given a cache.
  14740. if (cache) cache[base] = resolvedLink;
  14741. if (!isWindows) seenLinks[id] = linkTarget;
  14742. } // resolve the link, then start over
  14743. p = path.resolve(resolvedLink, p.slice(pos));
  14744. start();
  14745. }
  14746. if (cache) cache[original] = p;
  14747. return p;
  14748. };
  14749. var realpath$1 = function realpath(p, cache, cb) {
  14750. if (typeof cb !== 'function') {
  14751. cb = maybeCallback(cache);
  14752. cache = null;
  14753. } // make p is absolute
  14754. p = path.resolve(p);
  14755. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  14756. return process.nextTick(cb.bind(null, null, cache[p]));
  14757. }
  14758. var original = p,
  14759. seenLinks = {},
  14760. knownHard = {}; // current character position in p
  14761. var pos; // the partial path so far, including a trailing slash if any
  14762. var current; // the partial path without a trailing slash (except when pointing at a root)
  14763. var base; // the partial path scanned in the previous round, with slash
  14764. var previous;
  14765. start();
  14766. function start() {
  14767. // Skip over roots
  14768. var m = splitRootRe.exec(p);
  14769. pos = m[0].length;
  14770. current = m[0];
  14771. base = m[0];
  14772. previous = ''; // On windows, check that the root exists. On unix there is no need.
  14773. if (isWindows && !knownHard[base]) {
  14774. fs.lstat(base, function (err) {
  14775. if (err) return cb(err);
  14776. knownHard[base] = true;
  14777. LOOP();
  14778. });
  14779. } else {
  14780. process.nextTick(LOOP);
  14781. }
  14782. } // walk down the path, swapping out linked pathparts for their real
  14783. // values
  14784. function LOOP() {
  14785. // stop if scanned past end of path
  14786. if (pos >= p.length) {
  14787. if (cache) cache[original] = p;
  14788. return cb(null, p);
  14789. } // find the next part
  14790. nextPartRe.lastIndex = pos;
  14791. var result = nextPartRe.exec(p);
  14792. previous = current;
  14793. current += result[0];
  14794. base = previous + result[1];
  14795. pos = nextPartRe.lastIndex; // continue if not a symlink
  14796. if (knownHard[base] || cache && cache[base] === base) {
  14797. return process.nextTick(LOOP);
  14798. }
  14799. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  14800. // known symbolic link. no need to stat again.
  14801. return gotResolvedLink(cache[base]);
  14802. }
  14803. return fs.lstat(base, gotStat);
  14804. }
  14805. function gotStat(err, stat) {
  14806. if (err) return cb(err); // if not a symlink, skip to the next path part
  14807. if (!stat.isSymbolicLink()) {
  14808. knownHard[base] = true;
  14809. if (cache) cache[base] = base;
  14810. return process.nextTick(LOOP);
  14811. } // stat & read the link if not read before
  14812. // call gotTarget as soon as the link target is known
  14813. // dev/ino always return 0 on windows, so skip the check.
  14814. if (!isWindows) {
  14815. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  14816. if (seenLinks.hasOwnProperty(id)) {
  14817. return gotTarget(null, seenLinks[id], base);
  14818. }
  14819. }
  14820. fs.stat(base, function (err) {
  14821. if (err) return cb(err);
  14822. fs.readlink(base, function (err, target) {
  14823. if (!isWindows) seenLinks[id] = target;
  14824. gotTarget(err, target);
  14825. });
  14826. });
  14827. }
  14828. function gotTarget(err, target, base) {
  14829. if (err) return cb(err);
  14830. var resolvedLink = path.resolve(previous, target);
  14831. if (cache) cache[base] = resolvedLink;
  14832. gotResolvedLink(resolvedLink);
  14833. }
  14834. function gotResolvedLink(resolvedLink) {
  14835. // resolve the link, then start over
  14836. p = path.resolve(resolvedLink, p.slice(pos));
  14837. start();
  14838. }
  14839. };
  14840. var old = {
  14841. realpathSync: realpathSync$1,
  14842. realpath: realpath$1
  14843. };
  14844. var fs_realpath = realpath;
  14845. realpath.realpath = realpath;
  14846. realpath.sync = realpathSync;
  14847. realpath.realpathSync = realpathSync;
  14848. realpath.monkeypatch = monkeypatch;
  14849. realpath.unmonkeypatch = unmonkeypatch;
  14850. var origRealpath = fs.realpath;
  14851. var origRealpathSync = fs.realpathSync;
  14852. var version$2 = process.version;
  14853. var ok = /^v[0-5]\./.test(version$2);
  14854. function newError(er) {
  14855. return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
  14856. }
  14857. function realpath(p, cache, cb) {
  14858. if (ok) {
  14859. return origRealpath(p, cache, cb);
  14860. }
  14861. if (typeof cache === 'function') {
  14862. cb = cache;
  14863. cache = null;
  14864. }
  14865. origRealpath(p, cache, function (er, result) {
  14866. if (newError(er)) {
  14867. old.realpath(p, cache, cb);
  14868. } else {
  14869. cb(er, result);
  14870. }
  14871. });
  14872. }
  14873. function realpathSync(p, cache) {
  14874. if (ok) {
  14875. return origRealpathSync(p, cache);
  14876. }
  14877. try {
  14878. return origRealpathSync(p, cache);
  14879. } catch (er) {
  14880. if (newError(er)) {
  14881. return old.realpathSync(p, cache);
  14882. } else {
  14883. throw er;
  14884. }
  14885. }
  14886. }
  14887. function monkeypatch() {
  14888. fs.realpath = realpath;
  14889. fs.realpathSync = realpathSync;
  14890. }
  14891. function unmonkeypatch() {
  14892. fs.realpath = origRealpath;
  14893. fs.realpathSync = origRealpathSync;
  14894. }
  14895. var concatMap = function concatMap(xs, fn) {
  14896. var res = [];
  14897. for (var i = 0; i < xs.length; i++) {
  14898. var x = fn(xs[i], i);
  14899. if (isArray(x)) res.push.apply(res, x);else res.push(x);
  14900. }
  14901. return res;
  14902. };
  14903. var isArray = Array.isArray || function (xs) {
  14904. return Object.prototype.toString.call(xs) === '[object Array]';
  14905. };
  14906. var balancedMatch = balanced;
  14907. function balanced(a, b, str) {
  14908. if (a instanceof RegExp) a = maybeMatch(a, str);
  14909. if (b instanceof RegExp) b = maybeMatch(b, str);
  14910. var r = range(a, b, str);
  14911. return r && {
  14912. start: r[0],
  14913. end: r[1],
  14914. pre: str.slice(0, r[0]),
  14915. body: str.slice(r[0] + a.length, r[1]),
  14916. post: str.slice(r[1] + b.length)
  14917. };
  14918. }
  14919. function maybeMatch(reg, str) {
  14920. var m = str.match(reg);
  14921. return m ? m[0] : null;
  14922. }
  14923. balanced.range = range;
  14924. function range(a, b, str) {
  14925. var begs, beg, left, right, result;
  14926. var ai = str.indexOf(a);
  14927. var bi = str.indexOf(b, ai + 1);
  14928. var i = ai;
  14929. if (ai >= 0 && bi > 0) {
  14930. begs = [];
  14931. left = str.length;
  14932. while (i >= 0 && !result) {
  14933. if (i == ai) {
  14934. begs.push(i);
  14935. ai = str.indexOf(a, i + 1);
  14936. } else if (begs.length == 1) {
  14937. result = [begs.pop(), bi];
  14938. } else {
  14939. beg = begs.pop();
  14940. if (beg < left) {
  14941. left = beg;
  14942. right = bi;
  14943. }
  14944. bi = str.indexOf(b, i + 1);
  14945. }
  14946. i = ai < bi && ai >= 0 ? ai : bi;
  14947. }
  14948. if (begs.length) {
  14949. result = [left, right];
  14950. }
  14951. }
  14952. return result;
  14953. }
  14954. var braceExpansion = expandTop;
  14955. var escSlash = '\0SLASH' + Math.random() + '\0';
  14956. var escOpen = '\0OPEN' + Math.random() + '\0';
  14957. var escClose = '\0CLOSE' + Math.random() + '\0';
  14958. var escComma = '\0COMMA' + Math.random() + '\0';
  14959. var escPeriod = '\0PERIOD' + Math.random() + '\0';
  14960. function numeric(str) {
  14961. return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
  14962. }
  14963. function escapeBraces(str) {
  14964. return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
  14965. }
  14966. function unescapeBraces(str) {
  14967. return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
  14968. } // Basically just str.split(","), but handling cases
  14969. // where we have nested braced sections, which should be
  14970. // treated as individual members, like {a,{b,c},d}
  14971. function parseCommaParts(str) {
  14972. if (!str) return [''];
  14973. var parts = [];
  14974. var m = balancedMatch('{', '}', str);
  14975. if (!m) return str.split(',');
  14976. var pre = m.pre;
  14977. var body = m.body;
  14978. var post = m.post;
  14979. var p = pre.split(',');
  14980. p[p.length - 1] += '{' + body + '}';
  14981. var postParts = parseCommaParts(post);
  14982. if (post.length) {
  14983. p[p.length - 1] += postParts.shift();
  14984. p.push.apply(p, postParts);
  14985. }
  14986. parts.push.apply(parts, p);
  14987. return parts;
  14988. }
  14989. function expandTop(str) {
  14990. if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
  14991. // Anything starting with {} will have the first two bytes preserved
  14992. // but *only* at the top level, so {},a}b will not expand to anything,
  14993. // but a{},b}c will be expanded to [a}c,abc].
  14994. // One could argue that this is a bug in Bash, but since the goal of
  14995. // this module is to match Bash's rules, we escape a leading {}
  14996. if (str.substr(0, 2) === '{}') {
  14997. str = '\\{\\}' + str.substr(2);
  14998. }
  14999. return expand(escapeBraces(str), true).map(unescapeBraces);
  15000. }
  15001. function embrace(str) {
  15002. return '{' + str + '}';
  15003. }
  15004. function isPadded(el) {
  15005. return /^-?0\d/.test(el);
  15006. }
  15007. function lte(i, y) {
  15008. return i <= y;
  15009. }
  15010. function gte(i, y) {
  15011. return i >= y;
  15012. }
  15013. function expand(str, isTop) {
  15014. var expansions = [];
  15015. var m = balancedMatch('{', '}', str);
  15016. if (!m || /\$$/.test(m.pre)) return [str];
  15017. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  15018. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  15019. var isSequence = isNumericSequence || isAlphaSequence;
  15020. var isOptions = m.body.indexOf(',') >= 0;
  15021. if (!isSequence && !isOptions) {
  15022. // {a},b}
  15023. if (m.post.match(/,.*\}/)) {
  15024. str = m.pre + '{' + m.body + escClose + m.post;
  15025. return expand(str);
  15026. }
  15027. return [str];
  15028. }
  15029. var n;
  15030. if (isSequence) {
  15031. n = m.body.split(/\.\./);
  15032. } else {
  15033. n = parseCommaParts(m.body);
  15034. if (n.length === 1) {
  15035. // x{{a,b}}y ==> x{a}y x{b}y
  15036. n = expand(n[0], false).map(embrace);
  15037. if (n.length === 1) {
  15038. var post = m.post.length ? expand(m.post, false) : [''];
  15039. return post.map(function (p) {
  15040. return m.pre + n[0] + p;
  15041. });
  15042. }
  15043. }
  15044. } // at this point, n is the parts, and we know it's not a comma set
  15045. // with a single entry.
  15046. // no need to expand pre, since it is guaranteed to be free of brace-sets
  15047. var pre = m.pre;
  15048. var post = m.post.length ? expand(m.post, false) : [''];
  15049. var N;
  15050. if (isSequence) {
  15051. var x = numeric(n[0]);
  15052. var y = numeric(n[1]);
  15053. var width = Math.max(n[0].length, n[1].length);
  15054. var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
  15055. var test = lte;
  15056. var reverse = y < x;
  15057. if (reverse) {
  15058. incr *= -1;
  15059. test = gte;
  15060. }
  15061. var pad = n.some(isPadded);
  15062. N = [];
  15063. for (var i = x; test(i, y); i += incr) {
  15064. var c;
  15065. if (isAlphaSequence) {
  15066. c = String.fromCharCode(i);
  15067. if (c === '\\') c = '';
  15068. } else {
  15069. c = String(i);
  15070. if (pad) {
  15071. var need = width - c.length;
  15072. if (need > 0) {
  15073. var z = new Array(need + 1).join('0');
  15074. if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
  15075. }
  15076. }
  15077. }
  15078. N.push(c);
  15079. }
  15080. } else {
  15081. N = concatMap(n, function (el) {
  15082. return expand(el, false);
  15083. });
  15084. }
  15085. for (var j = 0; j < N.length; j++) {
  15086. for (var k = 0; k < post.length; k++) {
  15087. var expansion = pre + N[j] + post[k];
  15088. if (!isTop || isSequence || expansion) expansions.push(expansion);
  15089. }
  15090. }
  15091. return expansions;
  15092. }
  15093. var minimatch_1 = minimatch;
  15094. minimatch.Minimatch = Minimatch$1;
  15095. var path$2 = {
  15096. sep: '/'
  15097. };
  15098. try {
  15099. path$2 = path;
  15100. } catch (er) {}
  15101. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch$1.GLOBSTAR = {};
  15102. var plTypes = {
  15103. '!': {
  15104. open: '(?:(?!(?:',
  15105. close: '))[^/]*?)'
  15106. },
  15107. '?': {
  15108. open: '(?:',
  15109. close: ')?'
  15110. },
  15111. '+': {
  15112. open: '(?:',
  15113. close: ')+'
  15114. },
  15115. '*': {
  15116. open: '(?:',
  15117. close: ')*'
  15118. },
  15119. '@': {
  15120. open: '(?:',
  15121. close: ')'
  15122. } // any single thing other than /
  15123. // don't need to escape / when using new RegExp()
  15124. };
  15125. var qmark = '[^/]'; // * => any number of characters
  15126. var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
  15127. // not (^ or / followed by one or two dots followed by $ or /),
  15128. // followed by anything, any number of times.
  15129. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
  15130. // followed by anything, any number of times.
  15131. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
  15132. var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
  15133. function charSet(s) {
  15134. return s.split('').reduce(function (set, c) {
  15135. set[c] = true;
  15136. return set;
  15137. }, {});
  15138. } // normalizes slashes.
  15139. var slashSplit = /\/+/;
  15140. minimatch.filter = filter;
  15141. function filter(pattern, options) {
  15142. options = options || {};
  15143. return function (p, i, list) {
  15144. return minimatch(p, pattern, options);
  15145. };
  15146. }
  15147. function ext(a, b) {
  15148. a = a || {};
  15149. b = b || {};
  15150. var t = {};
  15151. Object.keys(b).forEach(function (k) {
  15152. t[k] = b[k];
  15153. });
  15154. Object.keys(a).forEach(function (k) {
  15155. t[k] = a[k];
  15156. });
  15157. return t;
  15158. }
  15159. minimatch.defaults = function (def) {
  15160. if (!def || !Object.keys(def).length) return minimatch;
  15161. var orig = minimatch;
  15162. var m = function minimatch(p, pattern, options) {
  15163. return orig.minimatch(p, pattern, ext(def, options));
  15164. };
  15165. m.Minimatch = function Minimatch(pattern, options) {
  15166. return new orig.Minimatch(pattern, ext(def, options));
  15167. };
  15168. return m;
  15169. };
  15170. Minimatch$1.defaults = function (def) {
  15171. if (!def || !Object.keys(def).length) return Minimatch$1;
  15172. return minimatch.defaults(def).Minimatch;
  15173. };
  15174. function minimatch(p, pattern, options) {
  15175. if (typeof pattern !== 'string') {
  15176. throw new TypeError('glob pattern string required');
  15177. }
  15178. if (!options) options = {}; // shortcut: comments match nothing.
  15179. if (!options.nocomment && pattern.charAt(0) === '#') {
  15180. return false;
  15181. } // "" only matches ""
  15182. if (pattern.trim() === '') return p === '';
  15183. return new Minimatch$1(pattern, options).match(p);
  15184. }
  15185. function Minimatch$1(pattern, options) {
  15186. if (!(this instanceof Minimatch$1)) {
  15187. return new Minimatch$1(pattern, options);
  15188. }
  15189. if (typeof pattern !== 'string') {
  15190. throw new TypeError('glob pattern string required');
  15191. }
  15192. if (!options) options = {};
  15193. pattern = pattern.trim(); // windows support: need to use /, not \
  15194. if (path$2.sep !== '/') {
  15195. pattern = pattern.split(path$2.sep).join('/');
  15196. }
  15197. this.options = options;
  15198. this.set = [];
  15199. this.pattern = pattern;
  15200. this.regexp = null;
  15201. this.negate = false;
  15202. this.comment = false;
  15203. this.empty = false; // make the set of regexps etc.
  15204. this.make();
  15205. }
  15206. Minimatch$1.prototype.debug = function () {};
  15207. Minimatch$1.prototype.make = make;
  15208. function make() {
  15209. // don't do it more than once.
  15210. if (this._made) return;
  15211. var pattern = this.pattern;
  15212. var options = this.options; // empty patterns and comments match nothing.
  15213. if (!options.nocomment && pattern.charAt(0) === '#') {
  15214. this.comment = true;
  15215. return;
  15216. }
  15217. if (!pattern) {
  15218. this.empty = true;
  15219. return;
  15220. } // step 1: figure out negation, etc.
  15221. this.parseNegate(); // step 2: expand braces
  15222. var set = this.globSet = this.braceExpand();
  15223. if (options.debug) this.debug = console.error;
  15224. this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  15225. // matching patterns.
  15226. // These will be regexps, except in the case of "**", which is
  15227. // set to the GLOBSTAR object for globstar behavior,
  15228. // and will not contain any / characters
  15229. set = this.globParts = set.map(function (s) {
  15230. return s.split(slashSplit);
  15231. });
  15232. this.debug(this.pattern, set); // glob --> regexps
  15233. set = set.map(function (s, si, set) {
  15234. return s.map(this.parse, this);
  15235. }, this);
  15236. this.debug(this.pattern, set); // filter out everything that didn't compile properly.
  15237. set = set.filter(function (s) {
  15238. return s.indexOf(false) === -1;
  15239. });
  15240. this.debug(this.pattern, set);
  15241. this.set = set;
  15242. }
  15243. Minimatch$1.prototype.parseNegate = parseNegate;
  15244. function parseNegate() {
  15245. var pattern = this.pattern;
  15246. var negate = false;
  15247. var options = this.options;
  15248. var negateOffset = 0;
  15249. if (options.nonegate) return;
  15250. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
  15251. negate = !negate;
  15252. negateOffset++;
  15253. }
  15254. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  15255. this.negate = negate;
  15256. } // Brace expansion:
  15257. // a{b,c}d -> abd acd
  15258. // a{b,}c -> abc ac
  15259. // a{0..3}d -> a0d a1d a2d a3d
  15260. // a{b,c{d,e}f}g -> abg acdfg acefg
  15261. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  15262. //
  15263. // Invalid sets are not expanded.
  15264. // a{2..}b -> a{2..}b
  15265. // a{b}c -> a{b}c
  15266. minimatch.braceExpand = function (pattern, options) {
  15267. return braceExpand(pattern, options);
  15268. };
  15269. Minimatch$1.prototype.braceExpand = braceExpand;
  15270. function braceExpand(pattern, options) {
  15271. if (!options) {
  15272. if (this instanceof Minimatch$1) {
  15273. options = this.options;
  15274. } else {
  15275. options = {};
  15276. }
  15277. }
  15278. pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
  15279. if (typeof pattern === 'undefined') {
  15280. throw new TypeError('undefined pattern');
  15281. }
  15282. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  15283. // shortcut. no need to expand.
  15284. return [pattern];
  15285. }
  15286. return braceExpansion(pattern);
  15287. } // parse a component of the expanded set.
  15288. // At this point, no pattern may contain "/" in it
  15289. // so we're going to return a 2d array, where each entry is the full
  15290. // pattern, split on '/', and then turned into a regular expression.
  15291. // A regexp is made at the end which joins each array with an
  15292. // escaped /, and another full one which joins each regexp with |.
  15293. //
  15294. // Following the lead of Bash 4.1, note that "**" only has special meaning
  15295. // when it is the *only* thing in a path portion. Otherwise, any series
  15296. // of * is equivalent to a single *. Globstar behavior is enabled by
  15297. // default, and can be disabled by setting options.noglobstar.
  15298. Minimatch$1.prototype.parse = parse$3;
  15299. var SUBPARSE = {};
  15300. function parse$3(pattern, isSub) {
  15301. if (pattern.length > 1024 * 64) {
  15302. throw new TypeError('pattern is too long');
  15303. }
  15304. var options = this.options; // shortcuts
  15305. if (!options.noglobstar && pattern === '**') return GLOBSTAR;
  15306. if (pattern === '') return '';
  15307. var re = '';
  15308. var hasMagic = !!options.nocase;
  15309. var escaping = false; // ? => one single character
  15310. var patternListStack = [];
  15311. var negativeLists = [];
  15312. var stateChar;
  15313. var inClass = false;
  15314. var reClassStart = -1;
  15315. var classStart = -1; // . and .. never match anything that doesn't start with .,
  15316. // even when options.dot is set.
  15317. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  15318. // not (start or / followed by . or .. followed by / or end)
  15319. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
  15320. var self = this;
  15321. function clearStateChar() {
  15322. if (stateChar) {
  15323. // we had some state-tracking character
  15324. // that wasn't consumed by this pass.
  15325. switch (stateChar) {
  15326. case '*':
  15327. re += star;
  15328. hasMagic = true;
  15329. break;
  15330. case '?':
  15331. re += qmark;
  15332. hasMagic = true;
  15333. break;
  15334. default:
  15335. re += '\\' + stateChar;
  15336. break;
  15337. }
  15338. self.debug('clearStateChar %j %j', stateChar, re);
  15339. stateChar = false;
  15340. }
  15341. }
  15342. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  15343. this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
  15344. if (escaping && reSpecials[c]) {
  15345. re += '\\' + c;
  15346. escaping = false;
  15347. continue;
  15348. }
  15349. switch (c) {
  15350. case '/':
  15351. // completely not allowed, even escaped.
  15352. // Should already be path-split by now.
  15353. return false;
  15354. case '\\':
  15355. clearStateChar();
  15356. escaping = true;
  15357. continue;
  15358. // the various stateChar values
  15359. // for the "extglob" stuff.
  15360. case '?':
  15361. case '*':
  15362. case '+':
  15363. case '@':
  15364. case '!':
  15365. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
  15366. // the glob [!a] means [^a] in regexp
  15367. if (inClass) {
  15368. this.debug(' in class');
  15369. if (c === '!' && i === classStart + 1) c = '^';
  15370. re += c;
  15371. continue;
  15372. } // if we already have a stateChar, then it means
  15373. // that there was something like ** or +? in there.
  15374. // Handle the stateChar, then proceed with this one.
  15375. self.debug('call clearStateChar %j', stateChar);
  15376. clearStateChar();
  15377. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  15378. // just clear the statechar *now*, rather than even diving into
  15379. // the patternList stuff.
  15380. if (options.noext) clearStateChar();
  15381. continue;
  15382. case '(':
  15383. if (inClass) {
  15384. re += '(';
  15385. continue;
  15386. }
  15387. if (!stateChar) {
  15388. re += '\\(';
  15389. continue;
  15390. }
  15391. patternListStack.push({
  15392. type: stateChar,
  15393. start: i - 1,
  15394. reStart: re.length,
  15395. open: plTypes[stateChar].open,
  15396. close: plTypes[stateChar].close
  15397. }); // negation is (?:(?!js)[^/]*)
  15398. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  15399. this.debug('plType %j %j', stateChar, re);
  15400. stateChar = false;
  15401. continue;
  15402. case ')':
  15403. if (inClass || !patternListStack.length) {
  15404. re += '\\)';
  15405. continue;
  15406. }
  15407. clearStateChar();
  15408. hasMagic = true;
  15409. var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
  15410. // The others are (?:<pattern>)<type>
  15411. re += pl.close;
  15412. if (pl.type === '!') {
  15413. negativeLists.push(pl);
  15414. }
  15415. pl.reEnd = re.length;
  15416. continue;
  15417. case '|':
  15418. if (inClass || !patternListStack.length || escaping) {
  15419. re += '\\|';
  15420. escaping = false;
  15421. continue;
  15422. }
  15423. clearStateChar();
  15424. re += '|';
  15425. continue;
  15426. // these are mostly the same in regexp and glob
  15427. case '[':
  15428. // swallow any state-tracking char before the [
  15429. clearStateChar();
  15430. if (inClass) {
  15431. re += '\\' + c;
  15432. continue;
  15433. }
  15434. inClass = true;
  15435. classStart = i;
  15436. reClassStart = re.length;
  15437. re += c;
  15438. continue;
  15439. case ']':
  15440. // a right bracket shall lose its special
  15441. // meaning and represent itself in
  15442. // a bracket expression if it occurs
  15443. // first in the list. -- POSIX.2 2.8.3.2
  15444. if (i === classStart + 1 || !inClass) {
  15445. re += '\\' + c;
  15446. escaping = false;
  15447. continue;
  15448. } // handle the case where we left a class open.
  15449. // "[z-a]" is valid, equivalent to "\[z-a\]"
  15450. if (inClass) {
  15451. // split where the last [ was, make sure we don't have
  15452. // an invalid re. if so, re-walk the contents of the
  15453. // would-be class to re-translate any characters that
  15454. // were passed through as-is
  15455. // TODO: It would probably be faster to determine this
  15456. // without a try/catch and a new RegExp, but it's tricky
  15457. // to do safely. For now, this is safe and works.
  15458. var cs = pattern.substring(classStart + 1, i);
  15459. try {
  15460. RegExp('[' + cs + ']');
  15461. } catch (er) {
  15462. // not a valid class!
  15463. var sp = this.parse(cs, SUBPARSE);
  15464. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  15465. hasMagic = hasMagic || sp[1];
  15466. inClass = false;
  15467. continue;
  15468. }
  15469. } // finish up the class.
  15470. hasMagic = true;
  15471. inClass = false;
  15472. re += c;
  15473. continue;
  15474. default:
  15475. // swallow any state char that wasn't consumed
  15476. clearStateChar();
  15477. if (escaping) {
  15478. // no need
  15479. escaping = false;
  15480. } else if (reSpecials[c] && !(c === '^' && inClass)) {
  15481. re += '\\';
  15482. }
  15483. re += c;
  15484. } // switch
  15485. } // for
  15486. // handle the case where we left a class open.
  15487. // "[abc" is valid, equivalent to "\[abc"
  15488. if (inClass) {
  15489. // split where the last [ was, and escape it
  15490. // this is a huge pita. We now have to re-walk
  15491. // the contents of the would-be class to re-translate
  15492. // any characters that were passed through as-is
  15493. cs = pattern.substr(classStart + 1);
  15494. sp = this.parse(cs, SUBPARSE);
  15495. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  15496. hasMagic = hasMagic || sp[1];
  15497. } // handle the case where we had a +( thing at the *end*
  15498. // of the pattern.
  15499. // each pattern list stack adds 3 chars, and we need to go through
  15500. // and escape any | chars that were passed through as-is for the regexp.
  15501. // Go through and escape them, taking care not to double-escape any
  15502. // | chars that were already escaped.
  15503. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  15504. var tail = re.slice(pl.reStart + pl.open.length);
  15505. this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
  15506. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  15507. if (!$2) {
  15508. // the | isn't already escaped, so escape it.
  15509. $2 = '\\';
  15510. } // need to escape all those slashes *again*, without escaping the
  15511. // one that we need for escaping the | character. As it works out,
  15512. // escaping an even number of slashes can be done by simply repeating
  15513. // it exactly after itself. That's why this trick works.
  15514. //
  15515. // I am sorry that you have to see this.
  15516. return $1 + $1 + $2 + '|';
  15517. });
  15518. this.debug('tail=%j\n %s', tail, tail, pl, re);
  15519. var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
  15520. hasMagic = true;
  15521. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  15522. } // handle trailing things that only matter at the very end.
  15523. clearStateChar();
  15524. if (escaping) {
  15525. // trailing \\
  15526. re += '\\\\';
  15527. } // only need to apply the nodot start if the re starts with
  15528. // something that could conceivably capture a dot
  15529. var addPatternStart = false;
  15530. switch (re.charAt(0)) {
  15531. case '.':
  15532. case '[':
  15533. case '(':
  15534. addPatternStart = true;
  15535. } // Hack to work around lack of negative lookbehind in JS
  15536. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  15537. // like 'a.xyz.yz' doesn't match. So, the first negative
  15538. // lookahead, has to look ALL the way ahead, to the end of
  15539. // the pattern.
  15540. for (var n = negativeLists.length - 1; n > -1; n--) {
  15541. var nl = negativeLists[n];
  15542. var nlBefore = re.slice(0, nl.reStart);
  15543. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  15544. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  15545. var nlAfter = re.slice(nl.reEnd);
  15546. nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
  15547. // mean that we should *not* include the ) in the bit that is considered
  15548. // "after" the negated section.
  15549. var openParensBefore = nlBefore.split('(').length - 1;
  15550. var cleanAfter = nlAfter;
  15551. for (i = 0; i < openParensBefore; i++) {
  15552. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  15553. }
  15554. nlAfter = cleanAfter;
  15555. var dollar = '';
  15556. if (nlAfter === '' && isSub !== SUBPARSE) {
  15557. dollar = '$';
  15558. }
  15559. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  15560. re = newRe;
  15561. } // if the re is not "" at this point, then we need to make sure
  15562. // it doesn't match against an empty path part.
  15563. // Otherwise a/* will match a/, which it should not.
  15564. if (re !== '' && hasMagic) {
  15565. re = '(?=.)' + re;
  15566. }
  15567. if (addPatternStart) {
  15568. re = patternStart + re;
  15569. } // parsing just a piece of a larger pattern.
  15570. if (isSub === SUBPARSE) {
  15571. return [re, hasMagic];
  15572. } // skip the regexp for non-magical patterns
  15573. // unescape anything in it, though, so that it'll be
  15574. // an exact match against a file etc.
  15575. if (!hasMagic) {
  15576. return globUnescape(pattern);
  15577. }
  15578. var flags = options.nocase ? 'i' : '';
  15579. try {
  15580. var regExp = new RegExp('^' + re + '$', flags);
  15581. } catch (er) {
  15582. // If it was an invalid regular expression, then it can't match
  15583. // anything. This trick looks for a character after the end of
  15584. // the string, which is of course impossible, except in multi-line
  15585. // mode, but it's not a /m regex.
  15586. return new RegExp('$.');
  15587. }
  15588. regExp._glob = pattern;
  15589. regExp._src = re;
  15590. return regExp;
  15591. }
  15592. minimatch.makeRe = function (pattern, options) {
  15593. return new Minimatch$1(pattern, options || {}).makeRe();
  15594. };
  15595. Minimatch$1.prototype.makeRe = makeRe;
  15596. function makeRe() {
  15597. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  15598. // pattern strings, or "**".
  15599. //
  15600. // It's better to use .match(). This function shouldn't
  15601. // be used, really, but it's pretty convenient sometimes,
  15602. // when you just want to work with a regex.
  15603. var set = this.set;
  15604. if (!set.length) {
  15605. this.regexp = false;
  15606. return this.regexp;
  15607. }
  15608. var options = this.options;
  15609. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
  15610. var flags = options.nocase ? 'i' : '';
  15611. var re = set.map(function (pattern) {
  15612. return pattern.map(function (p) {
  15613. return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
  15614. }).join('\\\/');
  15615. }).join('|'); // must match entire pattern
  15616. // ending in a * or ** will make it less strict.
  15617. re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
  15618. if (this.negate) re = '^(?!' + re + ').*$';
  15619. try {
  15620. this.regexp = new RegExp(re, flags);
  15621. } catch (ex) {
  15622. this.regexp = false;
  15623. }
  15624. return this.regexp;
  15625. }
  15626. minimatch.match = function (list, pattern, options) {
  15627. options = options || {};
  15628. var mm = new Minimatch$1(pattern, options);
  15629. list = list.filter(function (f) {
  15630. return mm.match(f);
  15631. });
  15632. if (mm.options.nonull && !list.length) {
  15633. list.push(pattern);
  15634. }
  15635. return list;
  15636. };
  15637. Minimatch$1.prototype.match = match;
  15638. function match(f, partial) {
  15639. this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
  15640. // comments, etc.
  15641. if (this.comment) return false;
  15642. if (this.empty) return f === '';
  15643. if (f === '/' && partial) return true;
  15644. var options = this.options; // windows: need to use /, not \
  15645. if (path$2.sep !== '/') {
  15646. f = f.split(path$2.sep).join('/');
  15647. } // treat the test path as a set of pathparts.
  15648. f = f.split(slashSplit);
  15649. this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
  15650. // in order for it to be valid. If negating, then just one
  15651. // match means that we have failed.
  15652. // Either way, return on the first hit.
  15653. var set = this.set;
  15654. this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
  15655. var filename;
  15656. var i;
  15657. for (i = f.length - 1; i >= 0; i--) {
  15658. filename = f[i];
  15659. if (filename) break;
  15660. }
  15661. for (i = 0; i < set.length; i++) {
  15662. var pattern = set[i];
  15663. var file = f;
  15664. if (options.matchBase && pattern.length === 1) {
  15665. file = [filename];
  15666. }
  15667. var hit = this.matchOne(file, pattern, partial);
  15668. if (hit) {
  15669. if (options.flipNegate) return true;
  15670. return !this.negate;
  15671. }
  15672. } // didn't get any hits. this is success if it's a negative
  15673. // pattern, failure otherwise.
  15674. if (options.flipNegate) return false;
  15675. return this.negate;
  15676. } // set partial to true to test if, for example,
  15677. // "/a/b" matches the start of "/*/b/*/d"
  15678. // Partial means, if you run out of file before you run
  15679. // out of pattern, then that's fine, as long as all
  15680. // the parts match.
  15681. Minimatch$1.prototype.matchOne = function (file, pattern, partial) {
  15682. var options = this.options;
  15683. this.debug('matchOne', {
  15684. 'this': this,
  15685. file: file,
  15686. pattern: pattern
  15687. });
  15688. this.debug('matchOne', file.length, pattern.length);
  15689. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  15690. this.debug('matchOne loop');
  15691. var p = pattern[pi];
  15692. var f = file[fi];
  15693. this.debug(pattern, p, f); // should be impossible.
  15694. // some invalid regexp stuff in the set.
  15695. if (p === false) return false;
  15696. if (p === GLOBSTAR) {
  15697. this.debug('GLOBSTAR', [pattern, p, f]); // "**"
  15698. // a/**/b/**/c would match the following:
  15699. // a/b/x/y/z/c
  15700. // a/x/y/z/b/c
  15701. // a/b/x/b/x/c
  15702. // a/b/c
  15703. // To do this, take the rest of the pattern after
  15704. // the **, and see if it would match the file remainder.
  15705. // If so, return success.
  15706. // If not, the ** "swallows" a segment, and try again.
  15707. // This is recursively awful.
  15708. //
  15709. // a/**/b/**/c matching a/b/x/y/z/c
  15710. // - a matches a
  15711. // - doublestar
  15712. // - matchOne(b/x/y/z/c, b/**/c)
  15713. // - b matches b
  15714. // - doublestar
  15715. // - matchOne(x/y/z/c, c) -> no
  15716. // - matchOne(y/z/c, c) -> no
  15717. // - matchOne(z/c, c) -> no
  15718. // - matchOne(c, c) yes, hit
  15719. var fr = fi;
  15720. var pr = pi + 1;
  15721. if (pr === pl) {
  15722. this.debug('** at the end'); // a ** at the end will just swallow the rest.
  15723. // We have found a match.
  15724. // however, it will not swallow /.x, unless
  15725. // options.dot is set.
  15726. // . and .. are *never* matched by **, for explosively
  15727. // exponential reasons.
  15728. for (; fi < fl; fi++) {
  15729. if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
  15730. }
  15731. return true;
  15732. } // ok, let's see if we can swallow whatever we can.
  15733. while (fr < fl) {
  15734. var swallowee = file[fr];
  15735. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
  15736. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  15737. this.debug('globstar found match!', fr, fl, swallowee); // found a match.
  15738. return true;
  15739. } else {
  15740. // can't swallow "." or ".." ever.
  15741. // can only swallow ".foo" when explicitly asked.
  15742. if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
  15743. this.debug('dot detected!', file, fr, pattern, pr);
  15744. break;
  15745. } // ** swallows a segment, and continue.
  15746. this.debug('globstar swallow a segment, and continue');
  15747. fr++;
  15748. }
  15749. } // no match was found.
  15750. // However, in partial mode, we can't say this is necessarily over.
  15751. // If there's more *pattern* left, then
  15752. if (partial) {
  15753. // ran out of file
  15754. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  15755. if (fr === fl) return true;
  15756. }
  15757. return false;
  15758. } // something other than **
  15759. // non-magic patterns just have to match exactly
  15760. // patterns with magic have been turned into regexps.
  15761. var hit;
  15762. if (typeof p === 'string') {
  15763. if (options.nocase) {
  15764. hit = f.toLowerCase() === p.toLowerCase();
  15765. } else {
  15766. hit = f === p;
  15767. }
  15768. this.debug('string match', p, f, hit);
  15769. } else {
  15770. hit = f.match(p);
  15771. this.debug('pattern match', p, f, hit);
  15772. }
  15773. if (!hit) return false;
  15774. } // Note: ending in / means that we'll get a final ""
  15775. // at the end of the pattern. This can only match a
  15776. // corresponding "" at the end of the file.
  15777. // If the file ends in /, then it can only match a
  15778. // a pattern that ends in /, unless the pattern just
  15779. // doesn't have any more for it. But, a/b/ should *not*
  15780. // match "a/b/*", even though "" matches against the
  15781. // [^/]*? pattern, except in partial mode, where it might
  15782. // simply not be reached yet.
  15783. // However, a/b/ should still satisfy a/*
  15784. // now either we fell off the end of the pattern, or we're done.
  15785. if (fi === fl && pi === pl) {
  15786. // ran out of pattern and filename at the same time.
  15787. // an exact hit!
  15788. return true;
  15789. } else if (fi === fl) {
  15790. // ran out of file, but still had pattern left.
  15791. // this is ok if we're doing the match as part of
  15792. // a glob fs traversal.
  15793. return partial;
  15794. } else if (pi === pl) {
  15795. // ran out of pattern, still have file left.
  15796. // this is only acceptable if we're on the very last
  15797. // empty segment of a file with a trailing slash.
  15798. // a/* should match a/b/
  15799. var emptyFileEnd = fi === fl - 1 && file[fi] === '';
  15800. return emptyFileEnd;
  15801. } // should be unreachable.
  15802. throw new Error('wtf?');
  15803. }; // replace stuff like \* with *
  15804. function globUnescape(s) {
  15805. return s.replace(/\\(.)/g, '$1');
  15806. }
  15807. function regExpEscape(s) {
  15808. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
  15809. }
  15810. var inherits_browser = createCommonjsModule(function (module) {
  15811. if (typeof Object.create === 'function') {
  15812. // implementation from standard node.js 'util' module
  15813. module.exports = function inherits(ctor, superCtor) {
  15814. ctor.super_ = superCtor;
  15815. ctor.prototype = Object.create(superCtor.prototype, {
  15816. constructor: {
  15817. value: ctor,
  15818. enumerable: false,
  15819. writable: true,
  15820. configurable: true
  15821. }
  15822. });
  15823. };
  15824. } else {
  15825. // old school shim for old browsers
  15826. module.exports = function inherits(ctor, superCtor) {
  15827. ctor.super_ = superCtor;
  15828. var TempCtor = function TempCtor() {};
  15829. TempCtor.prototype = superCtor.prototype;
  15830. ctor.prototype = new TempCtor();
  15831. ctor.prototype.constructor = ctor;
  15832. };
  15833. }
  15834. });
  15835. var inherits = createCommonjsModule(function (module) {
  15836. try {
  15837. var util$$1 = util;
  15838. if (typeof util$$1.inherits !== 'function') throw '';
  15839. module.exports = util$$1.inherits;
  15840. } catch (e) {
  15841. module.exports = inherits_browser;
  15842. }
  15843. });
  15844. function posix(path$$1) {
  15845. return path$$1.charAt(0) === '/';
  15846. }
  15847. function win32(path$$1) {
  15848. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  15849. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  15850. var result = splitDeviceRe.exec(path$$1);
  15851. var device = result[1] || '';
  15852. var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
  15853. return Boolean(result[2] || isUnc);
  15854. }
  15855. var pathIsAbsolute = process.platform === 'win32' ? win32 : posix;
  15856. var posix_1 = posix;
  15857. var win32_1 = win32;
  15858. pathIsAbsolute.posix = posix_1;
  15859. pathIsAbsolute.win32 = win32_1;
  15860. var alphasort_1 = alphasort$2;
  15861. var alphasorti_1 = alphasorti$2;
  15862. var setopts_1 = setopts$2;
  15863. var ownProp_1 = ownProp$2;
  15864. var makeAbs_1 = makeAbs;
  15865. var finish_1 = finish;
  15866. var mark_1 = mark;
  15867. var isIgnored_1 = isIgnored$2;
  15868. var childrenIgnored_1 = childrenIgnored$2;
  15869. function ownProp$2(obj, field) {
  15870. return Object.prototype.hasOwnProperty.call(obj, field);
  15871. }
  15872. var Minimatch$3 = minimatch_1.Minimatch;
  15873. function alphasorti$2(a, b) {
  15874. return a.toLowerCase().localeCompare(b.toLowerCase());
  15875. }
  15876. function alphasort$2(a, b) {
  15877. return a.localeCompare(b);
  15878. }
  15879. function setupIgnores(self, options) {
  15880. self.ignore = options.ignore || [];
  15881. if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
  15882. if (self.ignore.length) {
  15883. self.ignore = self.ignore.map(ignoreMap);
  15884. }
  15885. } // ignore patterns are always in dot:true mode.
  15886. function ignoreMap(pattern) {
  15887. var gmatcher = null;
  15888. if (pattern.slice(-3) === '/**') {
  15889. var gpattern = pattern.replace(/(\/\*\*)+$/, '');
  15890. gmatcher = new Minimatch$3(gpattern, {
  15891. dot: true
  15892. });
  15893. }
  15894. return {
  15895. matcher: new Minimatch$3(pattern, {
  15896. dot: true
  15897. }),
  15898. gmatcher: gmatcher
  15899. };
  15900. }
  15901. function setopts$2(self, pattern, options) {
  15902. if (!options) options = {}; // base-matching: just use globstar for that.
  15903. if (options.matchBase && -1 === pattern.indexOf("/")) {
  15904. if (options.noglobstar) {
  15905. throw new Error("base matching requires globstar");
  15906. }
  15907. pattern = "**/" + pattern;
  15908. }
  15909. self.silent = !!options.silent;
  15910. self.pattern = pattern;
  15911. self.strict = options.strict !== false;
  15912. self.realpath = !!options.realpath;
  15913. self.realpathCache = options.realpathCache || Object.create(null);
  15914. self.follow = !!options.follow;
  15915. self.dot = !!options.dot;
  15916. self.mark = !!options.mark;
  15917. self.nodir = !!options.nodir;
  15918. if (self.nodir) self.mark = true;
  15919. self.sync = !!options.sync;
  15920. self.nounique = !!options.nounique;
  15921. self.nonull = !!options.nonull;
  15922. self.nosort = !!options.nosort;
  15923. self.nocase = !!options.nocase;
  15924. self.stat = !!options.stat;
  15925. self.noprocess = !!options.noprocess;
  15926. self.absolute = !!options.absolute;
  15927. self.maxLength = options.maxLength || Infinity;
  15928. self.cache = options.cache || Object.create(null);
  15929. self.statCache = options.statCache || Object.create(null);
  15930. self.symlinks = options.symlinks || Object.create(null);
  15931. setupIgnores(self, options);
  15932. self.changedCwd = false;
  15933. var cwd = process.cwd();
  15934. if (!ownProp$2(options, "cwd")) self.cwd = cwd;else {
  15935. self.cwd = path.resolve(options.cwd);
  15936. self.changedCwd = self.cwd !== cwd;
  15937. }
  15938. self.root = options.root || path.resolve(self.cwd, "/");
  15939. self.root = path.resolve(self.root);
  15940. if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  15941. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  15942. self.cwdAbs = pathIsAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
  15943. if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
  15944. self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
  15945. // Note that they are not supported in Glob itself anyway.
  15946. options.nonegate = true;
  15947. options.nocomment = true;
  15948. self.minimatch = new Minimatch$3(pattern, options);
  15949. self.options = self.minimatch.options;
  15950. }
  15951. function finish(self) {
  15952. var nou = self.nounique;
  15953. var all = nou ? [] : Object.create(null);
  15954. for (var i = 0, l = self.matches.length; i < l; i++) {
  15955. var matches = self.matches[i];
  15956. if (!matches || Object.keys(matches).length === 0) {
  15957. if (self.nonull) {
  15958. // do like the shell, and spit out the literal glob
  15959. var literal = self.minimatch.globSet[i];
  15960. if (nou) all.push(literal);else all[literal] = true;
  15961. }
  15962. } else {
  15963. // had matches
  15964. var m = Object.keys(matches);
  15965. if (nou) all.push.apply(all, m);else m.forEach(function (m) {
  15966. all[m] = true;
  15967. });
  15968. }
  15969. }
  15970. if (!nou) all = Object.keys(all);
  15971. if (!self.nosort) all = all.sort(self.nocase ? alphasorti$2 : alphasort$2); // at *some* point we statted all of these
  15972. if (self.mark) {
  15973. for (var i = 0; i < all.length; i++) {
  15974. all[i] = self._mark(all[i]);
  15975. }
  15976. if (self.nodir) {
  15977. all = all.filter(function (e) {
  15978. var notDir = !/\/$/.test(e);
  15979. var c = self.cache[e] || self.cache[makeAbs(self, e)];
  15980. if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
  15981. return notDir;
  15982. });
  15983. }
  15984. }
  15985. if (self.ignore.length) all = all.filter(function (m) {
  15986. return !isIgnored$2(self, m);
  15987. });
  15988. self.found = all;
  15989. }
  15990. function mark(self, p) {
  15991. var abs = makeAbs(self, p);
  15992. var c = self.cache[abs];
  15993. var m = p;
  15994. if (c) {
  15995. var isDir = c === 'DIR' || Array.isArray(c);
  15996. var slash = p.slice(-1) === '/';
  15997. if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
  15998. if (m !== p) {
  15999. var mabs = makeAbs(self, m);
  16000. self.statCache[mabs] = self.statCache[abs];
  16001. self.cache[mabs] = self.cache[abs];
  16002. }
  16003. }
  16004. return m;
  16005. } // lotta situps...
  16006. function makeAbs(self, f) {
  16007. var abs = f;
  16008. if (f.charAt(0) === '/') {
  16009. abs = path.join(self.root, f);
  16010. } else if (pathIsAbsolute(f) || f === '') {
  16011. abs = f;
  16012. } else if (self.changedCwd) {
  16013. abs = path.resolve(self.cwd, f);
  16014. } else {
  16015. abs = path.resolve(f);
  16016. }
  16017. if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
  16018. return abs;
  16019. } // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  16020. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  16021. function isIgnored$2(self, path$$2) {
  16022. if (!self.ignore.length) return false;
  16023. return self.ignore.some(function (item) {
  16024. return item.matcher.match(path$$2) || !!(item.gmatcher && item.gmatcher.match(path$$2));
  16025. });
  16026. }
  16027. function childrenIgnored$2(self, path$$2) {
  16028. if (!self.ignore.length) return false;
  16029. return self.ignore.some(function (item) {
  16030. return !!(item.gmatcher && item.gmatcher.match(path$$2));
  16031. });
  16032. }
  16033. var common$4 = {
  16034. alphasort: alphasort_1,
  16035. alphasorti: alphasorti_1,
  16036. setopts: setopts_1,
  16037. ownProp: ownProp_1,
  16038. makeAbs: makeAbs_1,
  16039. finish: finish_1,
  16040. mark: mark_1,
  16041. isIgnored: isIgnored_1,
  16042. childrenIgnored: childrenIgnored_1
  16043. };
  16044. var sync$1 = globSync;
  16045. globSync.GlobSync = GlobSync$1;
  16046. var setopts$1 = common$4.setopts;
  16047. var ownProp$1 = common$4.ownProp;
  16048. var childrenIgnored$1 = common$4.childrenIgnored;
  16049. var isIgnored$1 = common$4.isIgnored;
  16050. function globSync(pattern, options) {
  16051. 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');
  16052. return new GlobSync$1(pattern, options).found;
  16053. }
  16054. function GlobSync$1(pattern, options) {
  16055. if (!pattern) throw new Error('must provide pattern');
  16056. 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');
  16057. if (!(this instanceof GlobSync$1)) return new GlobSync$1(pattern, options);
  16058. setopts$1(this, pattern, options);
  16059. if (this.noprocess) return this;
  16060. var n = this.minimatch.set.length;
  16061. this.matches = new Array(n);
  16062. for (var i = 0; i < n; i++) {
  16063. this._process(this.minimatch.set[i], i, false);
  16064. }
  16065. this._finish();
  16066. }
  16067. GlobSync$1.prototype._finish = function () {
  16068. assert(this instanceof GlobSync$1);
  16069. if (this.realpath) {
  16070. var self = this;
  16071. this.matches.forEach(function (matchset, index) {
  16072. var set = self.matches[index] = Object.create(null);
  16073. for (var p in matchset) {
  16074. try {
  16075. p = self._makeAbs(p);
  16076. var real = fs_realpath.realpathSync(p, self.realpathCache);
  16077. set[real] = true;
  16078. } catch (er) {
  16079. if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
  16080. }
  16081. }
  16082. });
  16083. }
  16084. common$4.finish(this);
  16085. };
  16086. GlobSync$1.prototype._process = function (pattern, index, inGlobStar) {
  16087. assert(this instanceof GlobSync$1); // Get the first [n] parts of pattern that are all strings.
  16088. var n = 0;
  16089. while (typeof pattern[n] === 'string') {
  16090. n++;
  16091. } // now n is the index of the first one that is *not* a string.
  16092. // See if there's anything else
  16093. var prefix;
  16094. switch (n) {
  16095. // if not, then this is rather simple
  16096. case pattern.length:
  16097. this._processSimple(pattern.join('/'), index);
  16098. return;
  16099. case 0:
  16100. // pattern *starts* with some non-trivial item.
  16101. // going to readdir(cwd), but not include the prefix in matches.
  16102. prefix = null;
  16103. break;
  16104. default:
  16105. // pattern has some string bits in the front.
  16106. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  16107. // or 'relative' like '../baz'
  16108. prefix = pattern.slice(0, n).join('/');
  16109. break;
  16110. }
  16111. var remain = pattern.slice(n); // get the list of entries.
  16112. var read;
  16113. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  16114. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  16115. read = prefix;
  16116. } else read = prefix;
  16117. var abs = this._makeAbs(read); //if ignored, skip processing
  16118. if (childrenIgnored$1(this, read)) return;
  16119. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  16120. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
  16121. };
  16122. GlobSync$1.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  16123. var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
  16124. if (!entries) return; // It will only match dot entries if it starts with a dot, or if
  16125. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  16126. var pn = remain[0];
  16127. var negate = !!this.minimatch.negate;
  16128. var rawGlob = pn._glob;
  16129. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  16130. var matchedEntries = [];
  16131. for (var i = 0; i < entries.length; i++) {
  16132. var e = entries[i];
  16133. if (e.charAt(0) !== '.' || dotOk) {
  16134. var m;
  16135. if (negate && !prefix) {
  16136. m = !e.match(pn);
  16137. } else {
  16138. m = e.match(pn);
  16139. }
  16140. if (m) matchedEntries.push(e);
  16141. }
  16142. }
  16143. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  16144. if (len === 0) return; // if this is the last remaining pattern bit, then no need for
  16145. // an additional stat *unless* the user has specified mark or
  16146. // stat explicitly. We know they exist, since readdir returned
  16147. // them.
  16148. if (remain.length === 1 && !this.mark && !this.stat) {
  16149. if (!this.matches[index]) this.matches[index] = Object.create(null);
  16150. for (var i = 0; i < len; i++) {
  16151. var e = matchedEntries[i];
  16152. if (prefix) {
  16153. if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
  16154. }
  16155. if (e.charAt(0) === '/' && !this.nomount) {
  16156. e = path.join(this.root, e);
  16157. }
  16158. this._emitMatch(index, e);
  16159. } // This was the last one, and no stats were needed
  16160. return;
  16161. } // now test all matched entries as stand-ins for that part
  16162. // of the pattern.
  16163. remain.shift();
  16164. for (var i = 0; i < len; i++) {
  16165. var e = matchedEntries[i];
  16166. var newPattern;
  16167. if (prefix) newPattern = [prefix, e];else newPattern = [e];
  16168. this._process(newPattern.concat(remain), index, inGlobStar);
  16169. }
  16170. };
  16171. GlobSync$1.prototype._emitMatch = function (index, e) {
  16172. if (isIgnored$1(this, e)) return;
  16173. var abs = this._makeAbs(e);
  16174. if (this.mark) e = this._mark(e);
  16175. if (this.absolute) {
  16176. e = abs;
  16177. }
  16178. if (this.matches[index][e]) return;
  16179. if (this.nodir) {
  16180. var c = this.cache[abs];
  16181. if (c === 'DIR' || Array.isArray(c)) return;
  16182. }
  16183. this.matches[index][e] = true;
  16184. if (this.stat) this._stat(e);
  16185. };
  16186. GlobSync$1.prototype._readdirInGlobStar = function (abs) {
  16187. // follow all symlinked directories forever
  16188. // just proceed as if this is a non-globstar situation
  16189. if (this.follow) return this._readdir(abs, false);
  16190. var entries;
  16191. var lstat;
  16192. var stat;
  16193. try {
  16194. lstat = fs.lstatSync(abs);
  16195. } catch (er) {
  16196. if (er.code === 'ENOENT') {
  16197. // lstat failed, doesn't exist
  16198. return null;
  16199. }
  16200. }
  16201. var isSym = lstat && lstat.isSymbolicLink();
  16202. this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  16203. // don't bother doing a readdir in that case.
  16204. if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
  16205. return entries;
  16206. };
  16207. GlobSync$1.prototype._readdir = function (abs, inGlobStar) {
  16208. var entries;
  16209. if (inGlobStar && !ownProp$1(this.symlinks, abs)) return this._readdirInGlobStar(abs);
  16210. if (ownProp$1(this.cache, abs)) {
  16211. var c = this.cache[abs];
  16212. if (!c || c === 'FILE') return null;
  16213. if (Array.isArray(c)) return c;
  16214. }
  16215. try {
  16216. return this._readdirEntries(abs, fs.readdirSync(abs));
  16217. } catch (er) {
  16218. this._readdirError(abs, er);
  16219. return null;
  16220. }
  16221. };
  16222. GlobSync$1.prototype._readdirEntries = function (abs, entries) {
  16223. // if we haven't asked to stat everything, then just
  16224. // assume that everything in there exists, so we can avoid
  16225. // having to stat it a second time.
  16226. if (!this.mark && !this.stat) {
  16227. for (var i = 0; i < entries.length; i++) {
  16228. var e = entries[i];
  16229. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  16230. this.cache[e] = true;
  16231. }
  16232. }
  16233. this.cache[abs] = entries; // mark and cache dir-ness
  16234. return entries;
  16235. };
  16236. GlobSync$1.prototype._readdirError = function (f, er) {
  16237. // handle errors, and cache the information
  16238. switch (er.code) {
  16239. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  16240. case 'ENOTDIR':
  16241. // totally normal. means it *does* exist.
  16242. var abs = this._makeAbs(f);
  16243. this.cache[abs] = 'FILE';
  16244. if (abs === this.cwdAbs) {
  16245. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  16246. error.path = this.cwd;
  16247. error.code = er.code;
  16248. throw error;
  16249. }
  16250. break;
  16251. case 'ENOENT': // not terribly unusual
  16252. case 'ELOOP':
  16253. case 'ENAMETOOLONG':
  16254. case 'UNKNOWN':
  16255. this.cache[this._makeAbs(f)] = false;
  16256. break;
  16257. default:
  16258. // some unusual error. Treat as failure.
  16259. this.cache[this._makeAbs(f)] = false;
  16260. if (this.strict) throw er;
  16261. if (!this.silent) console.error('glob error', er);
  16262. break;
  16263. }
  16264. };
  16265. GlobSync$1.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  16266. var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
  16267. // foo.txt/** doesn't match foo.txt
  16268. if (!entries) return; // test without the globstar, and with every child both below
  16269. // and replacing the globstar.
  16270. var remainWithoutGlobStar = remain.slice(1);
  16271. var gspref = prefix ? [prefix] : [];
  16272. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  16273. this._process(noGlobStar, index, false);
  16274. var len = entries.length;
  16275. var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
  16276. if (isSym && inGlobStar) return;
  16277. for (var i = 0; i < len; i++) {
  16278. var e = entries[i];
  16279. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  16280. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  16281. this._process(instead, index, true);
  16282. var below = gspref.concat(entries[i], remain);
  16283. this._process(below, index, true);
  16284. }
  16285. };
  16286. GlobSync$1.prototype._processSimple = function (prefix, index) {
  16287. // XXX review this. Shouldn't it be doing the mounting etc
  16288. // before doing stat? kinda weird?
  16289. var exists = this._stat(prefix);
  16290. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  16291. if (!exists) return;
  16292. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  16293. var trail = /[\/\\]$/.test(prefix);
  16294. if (prefix.charAt(0) === '/') {
  16295. prefix = path.join(this.root, prefix);
  16296. } else {
  16297. prefix = path.resolve(this.root, prefix);
  16298. if (trail) prefix += '/';
  16299. }
  16300. }
  16301. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  16302. this._emitMatch(index, prefix);
  16303. }; // Returns either 'DIR', 'FILE', or false
  16304. GlobSync$1.prototype._stat = function (f) {
  16305. var abs = this._makeAbs(f);
  16306. var needDir = f.slice(-1) === '/';
  16307. if (f.length > this.maxLength) return false;
  16308. if (!this.stat && ownProp$1(this.cache, abs)) {
  16309. var c = this.cache[abs];
  16310. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  16311. if (!needDir || c === 'DIR') return c;
  16312. if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
  16313. // if we know it exists, but not what it is.
  16314. }
  16315. var exists;
  16316. var stat = this.statCache[abs];
  16317. if (!stat) {
  16318. var lstat;
  16319. try {
  16320. lstat = fs.lstatSync(abs);
  16321. } catch (er) {
  16322. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  16323. this.statCache[abs] = false;
  16324. return false;
  16325. }
  16326. }
  16327. if (lstat && lstat.isSymbolicLink()) {
  16328. try {
  16329. stat = fs.statSync(abs);
  16330. } catch (er) {
  16331. stat = lstat;
  16332. }
  16333. } else {
  16334. stat = lstat;
  16335. }
  16336. }
  16337. this.statCache[abs] = stat;
  16338. var c = true;
  16339. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  16340. this.cache[abs] = this.cache[abs] || c;
  16341. if (needDir && c === 'FILE') return false;
  16342. return c;
  16343. };
  16344. GlobSync$1.prototype._mark = function (p) {
  16345. return common$4.mark(this, p);
  16346. };
  16347. GlobSync$1.prototype._makeAbs = function (f) {
  16348. return common$4.makeAbs(this, f);
  16349. };
  16350. // Returns a wrapper function that returns a wrapped callback
  16351. // The wrapper function should do some stuff, and return a
  16352. // presumably different callback function.
  16353. // This makes sure that own properties are retained, so that
  16354. // decorations and such are not lost along the way.
  16355. var wrappy_1 = wrappy;
  16356. function wrappy(fn, cb) {
  16357. if (fn && cb) return wrappy(fn)(cb);
  16358. if (typeof fn !== 'function') throw new TypeError('need wrapper function');
  16359. Object.keys(fn).forEach(function (k) {
  16360. wrapper[k] = fn[k];
  16361. });
  16362. return wrapper;
  16363. function wrapper() {
  16364. var args = new Array(arguments.length);
  16365. for (var i = 0; i < args.length; i++) {
  16366. args[i] = arguments[i];
  16367. }
  16368. var ret = fn.apply(this, args);
  16369. var cb = args[args.length - 1];
  16370. if (typeof ret === 'function' && ret !== cb) {
  16371. Object.keys(cb).forEach(function (k) {
  16372. ret[k] = cb[k];
  16373. });
  16374. }
  16375. return ret;
  16376. }
  16377. }
  16378. var once_1 = wrappy_1(once);
  16379. var strict = wrappy_1(onceStrict);
  16380. once.proto = once(function () {
  16381. Object.defineProperty(Function.prototype, 'once', {
  16382. value: function value() {
  16383. return once(this);
  16384. },
  16385. configurable: true
  16386. });
  16387. Object.defineProperty(Function.prototype, 'onceStrict', {
  16388. value: function value() {
  16389. return onceStrict(this);
  16390. },
  16391. configurable: true
  16392. });
  16393. });
  16394. function once(fn) {
  16395. var f = function f() {
  16396. if (f.called) return f.value;
  16397. f.called = true;
  16398. return f.value = fn.apply(this, arguments);
  16399. };
  16400. f.called = false;
  16401. return f;
  16402. }
  16403. function onceStrict(fn) {
  16404. var f = function f() {
  16405. if (f.called) throw new Error(f.onceError);
  16406. f.called = true;
  16407. return f.value = fn.apply(this, arguments);
  16408. };
  16409. var name = fn.name || 'Function wrapped with `once`';
  16410. f.onceError = name + " shouldn't be called more than once";
  16411. f.called = false;
  16412. return f;
  16413. }
  16414. once_1.strict = strict;
  16415. var reqs = Object.create(null);
  16416. var inflight_1 = wrappy_1(inflight);
  16417. function inflight(key, cb) {
  16418. if (reqs[key]) {
  16419. reqs[key].push(cb);
  16420. return null;
  16421. } else {
  16422. reqs[key] = [cb];
  16423. return makeres(key);
  16424. }
  16425. }
  16426. function makeres(key) {
  16427. return once_1(function RES() {
  16428. var cbs = reqs[key];
  16429. var len = cbs.length;
  16430. var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
  16431. // pass should be queued for later execution if something in the
  16432. // list of callbacks throws, or if it should just be discarded.
  16433. // However, it's such an edge case that it hardly matters, and either
  16434. // choice is likely as surprising as the other.
  16435. // As it happens, we do go ahead and schedule it for later execution.
  16436. try {
  16437. for (var i = 0; i < len; i++) {
  16438. cbs[i].apply(null, args);
  16439. }
  16440. } finally {
  16441. if (cbs.length > len) {
  16442. // added more in the interim.
  16443. // de-zalgo, just in case, but don't call again.
  16444. cbs.splice(0, len);
  16445. process.nextTick(function () {
  16446. RES.apply(null, args);
  16447. });
  16448. } else {
  16449. delete reqs[key];
  16450. }
  16451. }
  16452. });
  16453. }
  16454. function slice(args) {
  16455. var length = args.length;
  16456. var array = [];
  16457. for (var i = 0; i < length; i++) {
  16458. array[i] = args[i];
  16459. }
  16460. return array;
  16461. }
  16462. //
  16463. // 1. Get the minimatch set
  16464. // 2. For each pattern in the set, PROCESS(pattern, false)
  16465. // 3. Store matches per-set, then uniq them
  16466. //
  16467. // PROCESS(pattern, inGlobStar)
  16468. // Get the first [n] items from pattern that are all strings
  16469. // Join these together. This is PREFIX.
  16470. // If there is no more remaining, then stat(PREFIX) and
  16471. // add to matches if it succeeds. END.
  16472. //
  16473. // If inGlobStar and PREFIX is symlink and points to dir
  16474. // set ENTRIES = []
  16475. // else readdir(PREFIX) as ENTRIES
  16476. // If fail, END
  16477. //
  16478. // with ENTRIES
  16479. // If pattern[n] is GLOBSTAR
  16480. // // handle the case where the globstar match is empty
  16481. // // by pruning it out, and testing the resulting pattern
  16482. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  16483. // // handle other cases.
  16484. // for ENTRY in ENTRIES (not dotfiles)
  16485. // // attach globstar + tail onto the entry
  16486. // // Mark that this entry is a globstar match
  16487. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  16488. //
  16489. // else // not globstar
  16490. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  16491. // Test ENTRY against pattern[n]
  16492. // If fails, continue
  16493. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  16494. //
  16495. // Caveat:
  16496. // Cache all stats and readdirs results to minimize syscall. Since all
  16497. // we ever care about is existence and directory-ness, we can just keep
  16498. // `true` for files, and [children,...] for directories, or `false` for
  16499. // things that don't exist.
  16500. var glob_1 = glob;
  16501. var EE = events.EventEmitter;
  16502. var setopts = common$4.setopts;
  16503. var ownProp = common$4.ownProp;
  16504. var childrenIgnored = common$4.childrenIgnored;
  16505. var isIgnored = common$4.isIgnored;
  16506. function glob(pattern, options, cb) {
  16507. if (typeof options === 'function') cb = options, options = {};
  16508. if (!options) options = {};
  16509. if (options.sync) {
  16510. if (cb) throw new TypeError('callback provided to sync glob');
  16511. return sync$1(pattern, options);
  16512. }
  16513. return new Glob(pattern, options, cb);
  16514. }
  16515. glob.sync = sync$1;
  16516. var GlobSync = glob.GlobSync = sync$1.GlobSync; // old api surface
  16517. glob.glob = glob;
  16518. function extend(origin, add) {
  16519. if (add === null || typeof add !== 'object') {
  16520. return origin;
  16521. }
  16522. var keys = Object.keys(add);
  16523. var i = keys.length;
  16524. while (i--) {
  16525. origin[keys[i]] = add[keys[i]];
  16526. }
  16527. return origin;
  16528. }
  16529. glob.hasMagic = function (pattern, options_) {
  16530. var options = extend({}, options_);
  16531. options.noprocess = true;
  16532. var g = new Glob(pattern, options);
  16533. var set = g.minimatch.set;
  16534. if (!pattern) return false;
  16535. if (set.length > 1) return true;
  16536. for (var j = 0; j < set[0].length; j++) {
  16537. if (typeof set[0][j] !== 'string') return true;
  16538. }
  16539. return false;
  16540. };
  16541. glob.Glob = Glob;
  16542. inherits(Glob, EE);
  16543. function Glob(pattern, options, cb) {
  16544. if (typeof options === 'function') {
  16545. cb = options;
  16546. options = null;
  16547. }
  16548. if (options && options.sync) {
  16549. if (cb) throw new TypeError('callback provided to sync glob');
  16550. return new GlobSync(pattern, options);
  16551. }
  16552. if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
  16553. setopts(this, pattern, options);
  16554. this._didRealPath = false; // process each pattern in the minimatch set
  16555. var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
  16556. // duplicates are automagically pruned.
  16557. // Later, we do an Object.keys() on these.
  16558. // Keep them as a list so we can fill in when nonull is set.
  16559. this.matches = new Array(n);
  16560. if (typeof cb === 'function') {
  16561. cb = once_1(cb);
  16562. this.on('error', cb);
  16563. this.on('end', function (matches) {
  16564. cb(null, matches);
  16565. });
  16566. }
  16567. var self = this;
  16568. this._processing = 0;
  16569. this._emitQueue = [];
  16570. this._processQueue = [];
  16571. this.paused = false;
  16572. if (this.noprocess) return this;
  16573. if (n === 0) return done();
  16574. var sync = true;
  16575. for (var i = 0; i < n; i++) {
  16576. this._process(this.minimatch.set[i], i, false, done);
  16577. }
  16578. sync = false;
  16579. function done() {
  16580. --self._processing;
  16581. if (self._processing <= 0) {
  16582. if (sync) {
  16583. process.nextTick(function () {
  16584. self._finish();
  16585. });
  16586. } else {
  16587. self._finish();
  16588. }
  16589. }
  16590. }
  16591. }
  16592. Glob.prototype._finish = function () {
  16593. assert(this instanceof Glob);
  16594. if (this.aborted) return;
  16595. if (this.realpath && !this._didRealpath) return this._realpath();
  16596. common$4.finish(this);
  16597. this.emit('end', this.found);
  16598. };
  16599. Glob.prototype._realpath = function () {
  16600. if (this._didRealpath) return;
  16601. this._didRealpath = true;
  16602. var n = this.matches.length;
  16603. if (n === 0) return this._finish();
  16604. var self = this;
  16605. for (var i = 0; i < this.matches.length; i++) {
  16606. this._realpathSet(i, next);
  16607. }
  16608. function next() {
  16609. if (--n === 0) self._finish();
  16610. }
  16611. };
  16612. Glob.prototype._realpathSet = function (index, cb) {
  16613. var matchset = this.matches[index];
  16614. if (!matchset) return cb();
  16615. var found = Object.keys(matchset);
  16616. var self = this;
  16617. var n = found.length;
  16618. if (n === 0) return cb();
  16619. var set = this.matches[index] = Object.create(null);
  16620. found.forEach(function (p, i) {
  16621. // If there's a problem with the stat, then it means that
  16622. // one or more of the links in the realpath couldn't be
  16623. // resolved. just return the abs value in that case.
  16624. p = self._makeAbs(p);
  16625. fs_realpath.realpath(p, self.realpathCache, function (er, real) {
  16626. if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
  16627. if (--n === 0) {
  16628. self.matches[index] = set;
  16629. cb();
  16630. }
  16631. });
  16632. });
  16633. };
  16634. Glob.prototype._mark = function (p) {
  16635. return common$4.mark(this, p);
  16636. };
  16637. Glob.prototype._makeAbs = function (f) {
  16638. return common$4.makeAbs(this, f);
  16639. };
  16640. Glob.prototype.abort = function () {
  16641. this.aborted = true;
  16642. this.emit('abort');
  16643. };
  16644. Glob.prototype.pause = function () {
  16645. if (!this.paused) {
  16646. this.paused = true;
  16647. this.emit('pause');
  16648. }
  16649. };
  16650. Glob.prototype.resume = function () {
  16651. if (this.paused) {
  16652. this.emit('resume');
  16653. this.paused = false;
  16654. if (this._emitQueue.length) {
  16655. var eq = this._emitQueue.slice(0);
  16656. this._emitQueue.length = 0;
  16657. for (var i = 0; i < eq.length; i++) {
  16658. var e = eq[i];
  16659. this._emitMatch(e[0], e[1]);
  16660. }
  16661. }
  16662. if (this._processQueue.length) {
  16663. var pq = this._processQueue.slice(0);
  16664. this._processQueue.length = 0;
  16665. for (var i = 0; i < pq.length; i++) {
  16666. var p = pq[i];
  16667. this._processing--;
  16668. this._process(p[0], p[1], p[2], p[3]);
  16669. }
  16670. }
  16671. }
  16672. };
  16673. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  16674. assert(this instanceof Glob);
  16675. assert(typeof cb === 'function');
  16676. if (this.aborted) return;
  16677. this._processing++;
  16678. if (this.paused) {
  16679. this._processQueue.push([pattern, index, inGlobStar, cb]);
  16680. return;
  16681. } //console.error('PROCESS %d', this._processing, pattern)
  16682. // Get the first [n] parts of pattern that are all strings.
  16683. var n = 0;
  16684. while (typeof pattern[n] === 'string') {
  16685. n++;
  16686. } // now n is the index of the first one that is *not* a string.
  16687. // see if there's anything else
  16688. var prefix;
  16689. switch (n) {
  16690. // if not, then this is rather simple
  16691. case pattern.length:
  16692. this._processSimple(pattern.join('/'), index, cb);
  16693. return;
  16694. case 0:
  16695. // pattern *starts* with some non-trivial item.
  16696. // going to readdir(cwd), but not include the prefix in matches.
  16697. prefix = null;
  16698. break;
  16699. default:
  16700. // pattern has some string bits in the front.
  16701. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  16702. // or 'relative' like '../baz'
  16703. prefix = pattern.slice(0, n).join('/');
  16704. break;
  16705. }
  16706. var remain = pattern.slice(n); // get the list of entries.
  16707. var read;
  16708. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  16709. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  16710. read = prefix;
  16711. } else read = prefix;
  16712. var abs = this._makeAbs(read); //if ignored, skip _processing
  16713. if (childrenIgnored(this, read)) return cb();
  16714. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  16715. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
  16716. };
  16717. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  16718. var self = this;
  16719. this._readdir(abs, inGlobStar, function (er, entries) {
  16720. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  16721. });
  16722. };
  16723. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  16724. // if the abs isn't a dir, then nothing can match!
  16725. if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
  16726. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  16727. var pn = remain[0];
  16728. var negate = !!this.minimatch.negate;
  16729. var rawGlob = pn._glob;
  16730. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  16731. var matchedEntries = [];
  16732. for (var i = 0; i < entries.length; i++) {
  16733. var e = entries[i];
  16734. if (e.charAt(0) !== '.' || dotOk) {
  16735. var m;
  16736. if (negate && !prefix) {
  16737. m = !e.match(pn);
  16738. } else {
  16739. m = e.match(pn);
  16740. }
  16741. if (m) matchedEntries.push(e);
  16742. }
  16743. } //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  16744. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  16745. if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
  16746. // an additional stat *unless* the user has specified mark or
  16747. // stat explicitly. We know they exist, since readdir returned
  16748. // them.
  16749. if (remain.length === 1 && !this.mark && !this.stat) {
  16750. if (!this.matches[index]) this.matches[index] = Object.create(null);
  16751. for (var i = 0; i < len; i++) {
  16752. var e = matchedEntries[i];
  16753. if (prefix) {
  16754. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  16755. }
  16756. if (e.charAt(0) === '/' && !this.nomount) {
  16757. e = path.join(this.root, e);
  16758. }
  16759. this._emitMatch(index, e);
  16760. } // This was the last one, and no stats were needed
  16761. return cb();
  16762. } // now test all matched entries as stand-ins for that part
  16763. // of the pattern.
  16764. remain.shift();
  16765. for (var i = 0; i < len; i++) {
  16766. var e = matchedEntries[i];
  16767. var newPattern;
  16768. if (prefix) {
  16769. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  16770. }
  16771. this._process([e].concat(remain), index, inGlobStar, cb);
  16772. }
  16773. cb();
  16774. };
  16775. Glob.prototype._emitMatch = function (index, e) {
  16776. if (this.aborted) return;
  16777. if (isIgnored(this, e)) return;
  16778. if (this.paused) {
  16779. this._emitQueue.push([index, e]);
  16780. return;
  16781. }
  16782. var abs = pathIsAbsolute(e) ? e : this._makeAbs(e);
  16783. if (this.mark) e = this._mark(e);
  16784. if (this.absolute) e = abs;
  16785. if (this.matches[index][e]) return;
  16786. if (this.nodir) {
  16787. var c = this.cache[abs];
  16788. if (c === 'DIR' || Array.isArray(c)) return;
  16789. }
  16790. this.matches[index][e] = true;
  16791. var st = this.statCache[abs];
  16792. if (st) this.emit('stat', e, st);
  16793. this.emit('match', e);
  16794. };
  16795. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  16796. if (this.aborted) return; // follow all symlinked directories forever
  16797. // just proceed as if this is a non-globstar situation
  16798. if (this.follow) return this._readdir(abs, false, cb);
  16799. var lstatkey = 'lstat\0' + abs;
  16800. var self = this;
  16801. var lstatcb = inflight_1(lstatkey, lstatcb_);
  16802. if (lstatcb) fs.lstat(abs, lstatcb);
  16803. function lstatcb_(er, lstat) {
  16804. if (er && er.code === 'ENOENT') return cb();
  16805. var isSym = lstat && lstat.isSymbolicLink();
  16806. self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  16807. // don't bother doing a readdir in that case.
  16808. if (!isSym && lstat && !lstat.isDirectory()) {
  16809. self.cache[abs] = 'FILE';
  16810. cb();
  16811. } else self._readdir(abs, false, cb);
  16812. }
  16813. };
  16814. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  16815. if (this.aborted) return;
  16816. cb = inflight_1('readdir\0' + abs + '\0' + inGlobStar, cb);
  16817. if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
  16818. if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
  16819. if (ownProp(this.cache, abs)) {
  16820. var c = this.cache[abs];
  16821. if (!c || c === 'FILE') return cb();
  16822. if (Array.isArray(c)) return cb(null, c);
  16823. }
  16824. var self = this;
  16825. fs.readdir(abs, readdirCb(this, abs, cb));
  16826. };
  16827. function readdirCb(self, abs, cb) {
  16828. return function (er, entries) {
  16829. if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
  16830. };
  16831. }
  16832. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  16833. if (this.aborted) return; // if we haven't asked to stat everything, then just
  16834. // assume that everything in there exists, so we can avoid
  16835. // having to stat it a second time.
  16836. if (!this.mark && !this.stat) {
  16837. for (var i = 0; i < entries.length; i++) {
  16838. var e = entries[i];
  16839. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  16840. this.cache[e] = true;
  16841. }
  16842. }
  16843. this.cache[abs] = entries;
  16844. return cb(null, entries);
  16845. };
  16846. Glob.prototype._readdirError = function (f, er, cb) {
  16847. if (this.aborted) return; // handle errors, and cache the information
  16848. switch (er.code) {
  16849. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  16850. case 'ENOTDIR':
  16851. // totally normal. means it *does* exist.
  16852. var abs = this._makeAbs(f);
  16853. this.cache[abs] = 'FILE';
  16854. if (abs === this.cwdAbs) {
  16855. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  16856. error.path = this.cwd;
  16857. error.code = er.code;
  16858. this.emit('error', error);
  16859. this.abort();
  16860. }
  16861. break;
  16862. case 'ENOENT': // not terribly unusual
  16863. case 'ELOOP':
  16864. case 'ENAMETOOLONG':
  16865. case 'UNKNOWN':
  16866. this.cache[this._makeAbs(f)] = false;
  16867. break;
  16868. default:
  16869. // some unusual error. Treat as failure.
  16870. this.cache[this._makeAbs(f)] = false;
  16871. if (this.strict) {
  16872. this.emit('error', er); // If the error is handled, then we abort
  16873. // if not, we threw out of here
  16874. this.abort();
  16875. }
  16876. if (!this.silent) console.error('glob error', er);
  16877. break;
  16878. }
  16879. return cb();
  16880. };
  16881. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  16882. var self = this;
  16883. this._readdir(abs, inGlobStar, function (er, entries) {
  16884. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  16885. });
  16886. };
  16887. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  16888. //console.error('pgs2', prefix, remain[0], entries)
  16889. // no entries means not a dir, so it can never have matches
  16890. // foo.txt/** doesn't match foo.txt
  16891. if (!entries) return cb(); // test without the globstar, and with every child both below
  16892. // and replacing the globstar.
  16893. var remainWithoutGlobStar = remain.slice(1);
  16894. var gspref = prefix ? [prefix] : [];
  16895. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  16896. this._process(noGlobStar, index, false, cb);
  16897. var isSym = this.symlinks[abs];
  16898. var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
  16899. if (isSym && inGlobStar) return cb();
  16900. for (var i = 0; i < len; i++) {
  16901. var e = entries[i];
  16902. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  16903. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  16904. this._process(instead, index, true, cb);
  16905. var below = gspref.concat(entries[i], remain);
  16906. this._process(below, index, true, cb);
  16907. }
  16908. cb();
  16909. };
  16910. Glob.prototype._processSimple = function (prefix, index, cb) {
  16911. // XXX review this. Shouldn't it be doing the mounting etc
  16912. // before doing stat? kinda weird?
  16913. var self = this;
  16914. this._stat(prefix, function (er, exists) {
  16915. self._processSimple2(prefix, index, er, exists, cb);
  16916. });
  16917. };
  16918. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  16919. //console.error('ps2', prefix, exists)
  16920. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  16921. if (!exists) return cb();
  16922. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  16923. var trail = /[\/\\]$/.test(prefix);
  16924. if (prefix.charAt(0) === '/') {
  16925. prefix = path.join(this.root, prefix);
  16926. } else {
  16927. prefix = path.resolve(this.root, prefix);
  16928. if (trail) prefix += '/';
  16929. }
  16930. }
  16931. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  16932. this._emitMatch(index, prefix);
  16933. cb();
  16934. }; // Returns either 'DIR', 'FILE', or false
  16935. Glob.prototype._stat = function (f, cb) {
  16936. var abs = this._makeAbs(f);
  16937. var needDir = f.slice(-1) === '/';
  16938. if (f.length > this.maxLength) return cb();
  16939. if (!this.stat && ownProp(this.cache, abs)) {
  16940. var c = this.cache[abs];
  16941. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  16942. if (!needDir || c === 'DIR') return cb(null, c);
  16943. if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
  16944. // if we know it exists, but not what it is.
  16945. }
  16946. var exists;
  16947. var stat = this.statCache[abs];
  16948. if (stat !== undefined) {
  16949. if (stat === false) return cb(null, stat);else {
  16950. var type = stat.isDirectory() ? 'DIR' : 'FILE';
  16951. if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
  16952. }
  16953. }
  16954. var self = this;
  16955. var statcb = inflight_1('stat\0' + abs, lstatcb_);
  16956. if (statcb) fs.lstat(abs, statcb);
  16957. function lstatcb_(er, lstat) {
  16958. if (lstat && lstat.isSymbolicLink()) {
  16959. // If it's a symlink, then treat it as the target, unless
  16960. // the target does not exist, then treat it as a file.
  16961. return fs.stat(abs, function (er, stat) {
  16962. if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
  16963. });
  16964. } else {
  16965. self._stat2(f, abs, er, lstat, cb);
  16966. }
  16967. }
  16968. };
  16969. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  16970. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  16971. this.statCache[abs] = false;
  16972. return cb();
  16973. }
  16974. var needDir = f.slice(-1) === '/';
  16975. this.statCache[abs] = stat;
  16976. if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
  16977. var c = true;
  16978. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  16979. this.cache[abs] = this.cache[abs] || c;
  16980. if (needDir && c === 'FILE') return cb();
  16981. return cb(null, c, stat);
  16982. };
  16983. var pify_1 = createCommonjsModule(function (module) {
  16984. 'use strict';
  16985. var processFn = function processFn(fn, P, opts) {
  16986. return function () {
  16987. var that = this;
  16988. var args = new Array(arguments.length);
  16989. for (var i = 0; i < arguments.length; i++) {
  16990. args[i] = arguments[i];
  16991. }
  16992. return new P(function (resolve, reject) {
  16993. args.push(function (err, result) {
  16994. if (err) {
  16995. reject(err);
  16996. } else if (opts.multiArgs) {
  16997. var results = new Array(arguments.length - 1);
  16998. for (var i = 1; i < arguments.length; i++) {
  16999. results[i - 1] = arguments[i];
  17000. }
  17001. resolve(results);
  17002. } else {
  17003. resolve(result);
  17004. }
  17005. });
  17006. fn.apply(that, args);
  17007. });
  17008. };
  17009. };
  17010. var pify = module.exports = function (obj, P, opts) {
  17011. if (typeof P !== 'function') {
  17012. opts = P;
  17013. P = Promise;
  17014. }
  17015. opts = opts || {};
  17016. opts.exclude = opts.exclude || [/.+Sync$/];
  17017. var filter = function filter(key) {
  17018. var match = function match(pattern) {
  17019. return typeof pattern === 'string' ? key === pattern : pattern.test(key);
  17020. };
  17021. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  17022. };
  17023. var ret = typeof obj === 'function' ? function () {
  17024. if (opts.excludeMain) {
  17025. return obj.apply(this, arguments);
  17026. }
  17027. return processFn(obj, P, opts).apply(this, arguments);
  17028. } : {};
  17029. return Object.keys(obj).reduce(function (ret, key) {
  17030. var x = obj[key];
  17031. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
  17032. return ret;
  17033. }, ret);
  17034. };
  17035. pify.all = pify;
  17036. });
  17037. var globP = pify_1(glob_1, pinkiePromise).bind(glob_1);
  17038. function isNegative(pattern) {
  17039. return pattern[0] === '!';
  17040. }
  17041. function isString(value) {
  17042. return typeof value === 'string';
  17043. }
  17044. function assertPatternsInput(patterns) {
  17045. if (!patterns.every(isString)) {
  17046. throw new TypeError('patterns must be a string or an array of strings');
  17047. }
  17048. }
  17049. function generateGlobTasks(patterns, opts) {
  17050. patterns = [].concat(patterns);
  17051. assertPatternsInput(patterns);
  17052. var globTasks = [];
  17053. opts = objectAssign({
  17054. cache: Object.create(null),
  17055. statCache: Object.create(null),
  17056. realpathCache: Object.create(null),
  17057. symlinks: Object.create(null),
  17058. ignore: []
  17059. }, opts);
  17060. patterns.forEach(function (pattern, i) {
  17061. if (isNegative(pattern)) {
  17062. return;
  17063. }
  17064. var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) {
  17065. return pattern.slice(1);
  17066. });
  17067. globTasks.push({
  17068. pattern: pattern,
  17069. opts: objectAssign({}, opts, {
  17070. ignore: opts.ignore.concat(ignore)
  17071. })
  17072. });
  17073. });
  17074. return globTasks;
  17075. }
  17076. var globby = function globby(patterns, opts) {
  17077. var globTasks;
  17078. try {
  17079. globTasks = generateGlobTasks(patterns, opts);
  17080. } catch (err) {
  17081. return pinkiePromise.reject(err);
  17082. }
  17083. return pinkiePromise.all(globTasks.map(function (task) {
  17084. return globP(task.pattern, task.opts);
  17085. })).then(function (paths) {
  17086. return arrayUnion.apply(null, paths);
  17087. });
  17088. };
  17089. var sync = function sync(patterns, opts) {
  17090. var globTasks = generateGlobTasks(patterns, opts);
  17091. return globTasks.reduce(function (matches, task) {
  17092. return arrayUnion(matches, glob_1.sync(task.pattern, task.opts));
  17093. }, []);
  17094. };
  17095. var generateGlobTasks_1 = generateGlobTasks;
  17096. var hasMagic = function hasMagic(patterns, opts) {
  17097. return [].concat(patterns).some(function (pattern) {
  17098. return glob_1.hasMagic(pattern, opts);
  17099. });
  17100. };
  17101. globby.sync = sync;
  17102. globby.generateGlobTasks = generateGlobTasks_1;
  17103. globby.hasMagic = hasMagic;
  17104. var assert$2 = true;
  17105. var buffer_ieee754 = "< 0.9.7";
  17106. var buffer = true;
  17107. var child_process = true;
  17108. var cluster = true;
  17109. var console$1 = true;
  17110. var constants = true;
  17111. var crypto = true;
  17112. var _debugger = "< 8";
  17113. var dgram = true;
  17114. var dns = true;
  17115. var domain = true;
  17116. var events$1 = true;
  17117. var freelist = "< 6";
  17118. var fs$2 = true;
  17119. var http = true;
  17120. var http2 = ">= 8.8";
  17121. var https = true;
  17122. var _http_server = ">= 0.11";
  17123. var _linklist = "< 8";
  17124. var module$1 = true;
  17125. var net = true;
  17126. var os$1 = true;
  17127. var path$3 = true;
  17128. var perf_hooks = ">= 8.5";
  17129. var process$1 = ">= 1";
  17130. var punycode = true;
  17131. var querystring = true;
  17132. var readline$1 = true;
  17133. var repl = true;
  17134. var stream = true;
  17135. var string_decoder = true;
  17136. var sys = true;
  17137. var timers = true;
  17138. var tls = true;
  17139. var tty = true;
  17140. var url = true;
  17141. var util$4 = true;
  17142. var v8 = ">= 1";
  17143. var vm = true;
  17144. var zlib = true;
  17145. var core$3 = {
  17146. assert: assert$2,
  17147. buffer_ieee754: buffer_ieee754,
  17148. buffer: buffer,
  17149. child_process: child_process,
  17150. cluster: cluster,
  17151. console: console$1,
  17152. constants: constants,
  17153. crypto: crypto,
  17154. _debugger: _debugger,
  17155. dgram: dgram,
  17156. dns: dns,
  17157. domain: domain,
  17158. events: events$1,
  17159. freelist: freelist,
  17160. fs: fs$2,
  17161. http: http,
  17162. http2: http2,
  17163. https: https,
  17164. _http_server: _http_server,
  17165. _linklist: _linklist,
  17166. module: module$1,
  17167. net: net,
  17168. os: os$1,
  17169. path: path$3,
  17170. perf_hooks: perf_hooks,
  17171. process: process$1,
  17172. punycode: punycode,
  17173. querystring: querystring,
  17174. readline: readline$1,
  17175. repl: repl,
  17176. stream: stream,
  17177. string_decoder: string_decoder,
  17178. sys: sys,
  17179. timers: timers,
  17180. tls: tls,
  17181. tty: tty,
  17182. url: url,
  17183. util: util$4,
  17184. v8: v8,
  17185. vm: vm,
  17186. zlib: zlib
  17187. };
  17188. var core$4 = Object.freeze({
  17189. assert: assert$2,
  17190. buffer_ieee754: buffer_ieee754,
  17191. buffer: buffer,
  17192. child_process: child_process,
  17193. cluster: cluster,
  17194. console: console$1,
  17195. constants: constants,
  17196. crypto: crypto,
  17197. _debugger: _debugger,
  17198. dgram: dgram,
  17199. dns: dns,
  17200. domain: domain,
  17201. events: events$1,
  17202. freelist: freelist,
  17203. fs: fs$2,
  17204. http: http,
  17205. http2: http2,
  17206. https: https,
  17207. _http_server: _http_server,
  17208. _linklist: _linklist,
  17209. module: module$1,
  17210. net: net,
  17211. os: os$1,
  17212. path: path$3,
  17213. perf_hooks: perf_hooks,
  17214. process: process$1,
  17215. punycode: punycode,
  17216. querystring: querystring,
  17217. readline: readline$1,
  17218. repl: repl,
  17219. stream: stream,
  17220. string_decoder: string_decoder,
  17221. sys: sys,
  17222. timers: timers,
  17223. tls: tls,
  17224. tty: tty,
  17225. url: url,
  17226. util: util$4,
  17227. v8: v8,
  17228. vm: vm,
  17229. zlib: zlib,
  17230. default: core$3
  17231. });
  17232. var data = ( core$4 && core$3 ) || core$4;
  17233. var current = process.versions && process.versions.node && process.versions.node.split('.') || [];
  17234. function versionIncluded(specifier) {
  17235. if (specifier === true) {
  17236. return true;
  17237. }
  17238. var parts = specifier.split(' ');
  17239. var op = parts[0];
  17240. var versionParts = parts[1].split('.');
  17241. for (var i = 0; i < 3; ++i) {
  17242. var cur = Number(current[i] || 0);
  17243. var ver = Number(versionParts[i] || 0);
  17244. if (cur === ver) {
  17245. continue; // eslint-disable-line no-restricted-syntax, no-continue
  17246. }
  17247. if (op === '<') {
  17248. return cur < ver;
  17249. } else if (op === '>=') {
  17250. return cur >= ver;
  17251. } else {
  17252. return false;
  17253. }
  17254. }
  17255. return false;
  17256. }
  17257. var core$2 = {};
  17258. for (var mod in data) {
  17259. // eslint-disable-line no-restricted-syntax
  17260. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  17261. core$2[mod] = versionIncluded(data[mod]);
  17262. }
  17263. }
  17264. var core_1 = core$2;
  17265. var caller = function caller() {
  17266. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  17267. var origPrepareStackTrace = Error.prepareStackTrace;
  17268. Error.prepareStackTrace = function (_, stack) {
  17269. return stack;
  17270. };
  17271. var stack = new Error().stack;
  17272. Error.prepareStackTrace = origPrepareStackTrace;
  17273. return stack[2].getFileName();
  17274. };
  17275. var pathParse = createCommonjsModule(function (module) {
  17276. 'use strict';
  17277. var isWindows = process.platform === 'win32'; // Regex to split a windows path into three parts: [*, device, slash,
  17278. // tail] windows-only
  17279. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; // Regex to split the tail part of the above into [*, dir, basename, ext]
  17280. var splitTailRe = /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  17281. var win32 = {}; // Function to split a filename into [root, dir, basename, ext]
  17282. function win32SplitPath(filename) {
  17283. // Separate device+slash from tail
  17284. var result = splitDeviceRe.exec(filename),
  17285. device = (result[1] || '') + (result[2] || ''),
  17286. tail = result[3] || ''; // Split the tail into dir, basename and extension
  17287. var result2 = splitTailRe.exec(tail),
  17288. dir = result2[1],
  17289. basename = result2[2],
  17290. ext = result2[3];
  17291. return [device, dir, basename, ext];
  17292. }
  17293. win32.parse = function (pathString) {
  17294. if (typeof pathString !== 'string') {
  17295. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  17296. }
  17297. var allParts = win32SplitPath(pathString);
  17298. if (!allParts || allParts.length !== 4) {
  17299. throw new TypeError("Invalid path '" + pathString + "'");
  17300. }
  17301. return {
  17302. root: allParts[0],
  17303. dir: allParts[0] + allParts[1].slice(0, -1),
  17304. base: allParts[2],
  17305. ext: allParts[3],
  17306. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  17307. };
  17308. }; // Split a filename into [root, dir, basename, ext], unix version
  17309. // 'root' is just a slash, or nothing.
  17310. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  17311. var posix = {};
  17312. function posixSplitPath(filename) {
  17313. return splitPathRe.exec(filename).slice(1);
  17314. }
  17315. posix.parse = function (pathString) {
  17316. if (typeof pathString !== 'string') {
  17317. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  17318. }
  17319. var allParts = posixSplitPath(pathString);
  17320. if (!allParts || allParts.length !== 4) {
  17321. throw new TypeError("Invalid path '" + pathString + "'");
  17322. }
  17323. allParts[1] = allParts[1] || '';
  17324. allParts[2] = allParts[2] || '';
  17325. allParts[3] = allParts[3] || '';
  17326. return {
  17327. root: allParts[0],
  17328. dir: allParts[0] + allParts[1].slice(0, -1),
  17329. base: allParts[2],
  17330. ext: allParts[3],
  17331. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  17332. };
  17333. };
  17334. if (isWindows) module.exports = win32.parse;else
  17335. /* posix */
  17336. module.exports = posix.parse;
  17337. module.exports.posix = posix.parse;
  17338. module.exports.win32 = win32.parse;
  17339. });
  17340. var parse$4 = path.parse || pathParse;
  17341. var nodeModulesPaths = function nodeModulesPaths(start, opts) {
  17342. var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules']; // ensure that `start` is an absolute path at this point,
  17343. // resolving against the process' current working directory
  17344. var absoluteStart = path.resolve(start);
  17345. if (opts && opts.preserveSymlinks === false) {
  17346. try {
  17347. absoluteStart = fs.realpathSync(absoluteStart);
  17348. } catch (err) {
  17349. if (err.code !== 'ENOENT') {
  17350. throw err;
  17351. }
  17352. }
  17353. }
  17354. var prefix = '/';
  17355. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  17356. prefix = '';
  17357. } else if (/^\\\\/.test(absoluteStart)) {
  17358. prefix = '\\\\';
  17359. }
  17360. var paths = [absoluteStart];
  17361. var parsed = parse$4(absoluteStart);
  17362. while (parsed.dir !== paths[paths.length - 1]) {
  17363. paths.push(parsed.dir);
  17364. parsed = parse$4(parsed.dir);
  17365. }
  17366. var dirs = paths.reduce(function (dirs, aPath) {
  17367. return dirs.concat(modules.map(function (moduleDir) {
  17368. return path.join(prefix, aPath, moduleDir);
  17369. }));
  17370. }, []);
  17371. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  17372. };
  17373. var async = function resolve(x, options, callback) {
  17374. var cb = callback;
  17375. var opts = options || {};
  17376. if (typeof opts === 'function') {
  17377. cb = opts;
  17378. opts = {};
  17379. }
  17380. if (typeof x !== 'string') {
  17381. var err = new TypeError('Path must be a string.');
  17382. return process.nextTick(function () {
  17383. cb(err);
  17384. });
  17385. }
  17386. var isFile = opts.isFile || function (file, cb) {
  17387. fs.stat(file, function (err, stat) {
  17388. if (!err) {
  17389. return cb(null, stat.isFile() || stat.isFIFO());
  17390. }
  17391. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  17392. return cb(err);
  17393. });
  17394. };
  17395. var readFile = opts.readFile || fs.readFile;
  17396. var extensions = opts.extensions || ['.js'];
  17397. var y = opts.basedir || path.dirname(caller());
  17398. opts.paths = opts.paths || [];
  17399. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  17400. var res = path.resolve(y, x);
  17401. if (x === '..' || x.slice(-1) === '/') res += '/';
  17402. if (/\/$/.test(x) && res === y) {
  17403. loadAsDirectory(res, opts.package, onfile);
  17404. } else loadAsFile(res, opts.package, onfile);
  17405. } else loadNodeModules(x, y, function (err, n, pkg) {
  17406. if (err) cb(err);else if (n) cb(null, n, pkg);else if (core_1[x]) return cb(null, x);else {
  17407. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  17408. moduleError.code = 'MODULE_NOT_FOUND';
  17409. cb(moduleError);
  17410. }
  17411. });
  17412. function onfile(err, m, pkg) {
  17413. if (err) cb(err);else if (m) cb(null, m, pkg);else loadAsDirectory(res, function (err, d, pkg) {
  17414. if (err) cb(err);else if (d) cb(null, d, pkg);else {
  17415. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  17416. moduleError.code = 'MODULE_NOT_FOUND';
  17417. cb(moduleError);
  17418. }
  17419. });
  17420. }
  17421. function loadAsFile(x, thePackage, callback) {
  17422. var loadAsFilePackage = thePackage;
  17423. var cb = callback;
  17424. if (typeof loadAsFilePackage === 'function') {
  17425. cb = loadAsFilePackage;
  17426. loadAsFilePackage = undefined;
  17427. }
  17428. var exts = [''].concat(extensions);
  17429. load(exts, x, loadAsFilePackage);
  17430. function load(exts, x, loadPackage) {
  17431. if (exts.length === 0) return cb(null, undefined, loadPackage);
  17432. var file = x + exts[0];
  17433. var pkg = loadPackage;
  17434. if (pkg) onpkg(null, pkg);else loadpkg(path.dirname(file), onpkg);
  17435. function onpkg(err, pkg_, dir) {
  17436. pkg = pkg_;
  17437. if (err) return cb(err);
  17438. if (dir && pkg && opts.pathFilter) {
  17439. var rfile = path.relative(dir, file);
  17440. var rel = rfile.slice(0, rfile.length - exts[0].length);
  17441. var r = opts.pathFilter(pkg, x, rel);
  17442. if (r) return load([''].concat(extensions.slice()), path.resolve(dir, r), pkg);
  17443. }
  17444. isFile(file, onex);
  17445. }
  17446. function onex(err, ex) {
  17447. if (err) return cb(err);
  17448. if (ex) return cb(null, file, pkg);
  17449. load(exts.slice(1), x, pkg);
  17450. }
  17451. }
  17452. }
  17453. function loadpkg(dir, cb) {
  17454. if (dir === '' || dir === '/') return cb(null);
  17455. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  17456. return cb(null);
  17457. }
  17458. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  17459. var pkgfile = path.join(dir, 'package.json');
  17460. isFile(pkgfile, function (err, ex) {
  17461. // on err, ex is false
  17462. if (!ex) return loadpkg(path.dirname(dir), cb);
  17463. readFile(pkgfile, function (err, body) {
  17464. if (err) cb(err);
  17465. try {
  17466. var pkg = JSON.parse(body);
  17467. } catch (jsonErr) {}
  17468. if (pkg && opts.packageFilter) {
  17469. pkg = opts.packageFilter(pkg, pkgfile);
  17470. }
  17471. cb(null, pkg, dir);
  17472. });
  17473. });
  17474. }
  17475. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  17476. var cb = callback;
  17477. var fpkg = loadAsDirectoryPackage;
  17478. if (typeof fpkg === 'function') {
  17479. cb = fpkg;
  17480. fpkg = opts.package;
  17481. }
  17482. var pkgfile = path.join(x, 'package.json');
  17483. isFile(pkgfile, function (err, ex) {
  17484. if (err) return cb(err);
  17485. if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb);
  17486. readFile(pkgfile, function (err, body) {
  17487. if (err) return cb(err);
  17488. try {
  17489. var pkg = JSON.parse(body);
  17490. } catch (jsonErr) {}
  17491. if (opts.packageFilter) {
  17492. pkg = opts.packageFilter(pkg, pkgfile);
  17493. }
  17494. if (pkg.main) {
  17495. if (pkg.main === '.' || pkg.main === './') {
  17496. pkg.main = 'index';
  17497. }
  17498. loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
  17499. if (err) return cb(err);
  17500. if (m) return cb(null, m, pkg);
  17501. if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb);
  17502. var dir = path.resolve(x, pkg.main);
  17503. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  17504. if (err) return cb(err);
  17505. if (n) return cb(null, n, pkg);
  17506. loadAsFile(path.join(x, 'index'), pkg, cb);
  17507. });
  17508. });
  17509. return;
  17510. }
  17511. loadAsFile(path.join(x, '/index'), pkg, cb);
  17512. });
  17513. });
  17514. }
  17515. function processDirs(cb, dirs) {
  17516. if (dirs.length === 0) return cb(null, undefined);
  17517. var dir = dirs[0];
  17518. var file = path.join(dir, x);
  17519. loadAsFile(file, undefined, onfile);
  17520. function onfile(err, m, pkg) {
  17521. if (err) return cb(err);
  17522. if (m) return cb(null, m, pkg);
  17523. loadAsDirectory(path.join(dir, x), undefined, ondir);
  17524. }
  17525. function ondir(err, n, pkg) {
  17526. if (err) return cb(err);
  17527. if (n) return cb(null, n, pkg);
  17528. processDirs(cb, dirs.slice(1));
  17529. }
  17530. }
  17531. function loadNodeModules(x, start, cb) {
  17532. processDirs(cb, nodeModulesPaths(start, opts));
  17533. }
  17534. };
  17535. var sync$3 = function sync(x, options) {
  17536. if (typeof x !== 'string') {
  17537. throw new TypeError('Path must be a string.');
  17538. }
  17539. var opts = options || {};
  17540. var isFile = opts.isFile || function (file) {
  17541. try {
  17542. var stat = fs.statSync(file);
  17543. } catch (e) {
  17544. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  17545. throw e;
  17546. }
  17547. return stat.isFile() || stat.isFIFO();
  17548. };
  17549. var readFileSync = opts.readFileSync || fs.readFileSync;
  17550. var extensions = opts.extensions || ['.js'];
  17551. var y = opts.basedir || path.dirname(caller());
  17552. opts.paths = opts.paths || [];
  17553. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  17554. var res = path.resolve(y, x);
  17555. if (x === '..' || x.slice(-1) === '/') res += '/';
  17556. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  17557. if (m) return m;
  17558. } else {
  17559. var n = loadNodeModulesSync(x, y);
  17560. if (n) return n;
  17561. }
  17562. if (core_1[x]) return x;
  17563. var err = new Error("Cannot find module '" + x + "' from '" + y + "'");
  17564. err.code = 'MODULE_NOT_FOUND';
  17565. throw err;
  17566. function loadAsFileSync(x) {
  17567. if (isFile(x)) {
  17568. return x;
  17569. }
  17570. for (var i = 0; i < extensions.length; i++) {
  17571. var file = x + extensions[i];
  17572. if (isFile(file)) {
  17573. return file;
  17574. }
  17575. }
  17576. }
  17577. function loadAsDirectorySync(x) {
  17578. var pkgfile = path.join(x, '/package.json');
  17579. if (isFile(pkgfile)) {
  17580. try {
  17581. var body = readFileSync(pkgfile, 'UTF8');
  17582. var pkg = JSON.parse(body);
  17583. if (opts.packageFilter) {
  17584. pkg = opts.packageFilter(pkg, x);
  17585. }
  17586. if (pkg.main) {
  17587. if (pkg.main === '.' || pkg.main === './') {
  17588. pkg.main = 'index';
  17589. }
  17590. var m = loadAsFileSync(path.resolve(x, pkg.main));
  17591. if (m) return m;
  17592. var n = loadAsDirectorySync(path.resolve(x, pkg.main));
  17593. if (n) return n;
  17594. }
  17595. } catch (e) {}
  17596. }
  17597. return loadAsFileSync(path.join(x, '/index'));
  17598. }
  17599. function loadNodeModulesSync(x, start) {
  17600. var dirs = nodeModulesPaths(start, opts);
  17601. for (var i = 0; i < dirs.length; i++) {
  17602. var dir = dirs[i];
  17603. var m = loadAsFileSync(path.join(dir, '/', x));
  17604. if (m) return m;
  17605. var n = loadAsDirectorySync(path.join(dir, '/', x));
  17606. if (n) return n;
  17607. }
  17608. }
  17609. };
  17610. var resolve$1 = createCommonjsModule(function (module, exports) {
  17611. async.core = core_1;
  17612. async.isCore = function isCore(x) {
  17613. return core_1[x];
  17614. };
  17615. async.sync = sync$3;
  17616. exports = async;
  17617. module.exports = async;
  17618. });
  17619. var addLeadingComment$2 = utilShared.addLeadingComment;
  17620. var addTrailingComment$2 = utilShared.addTrailingComment;
  17621. var addDanglingComment$2 = utilShared.addDanglingComment;
  17622. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  17623. var precedingNode = comment.precedingNode,
  17624. enclosingNode = comment.enclosingNode,
  17625. followingNode = comment.followingNode;
  17626. if (handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleMemberExpressionComments(enclosingNode, followingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleImportSpecifierComments(enclosingNode, comment) || handleForComments(enclosingNode, precedingNode, comment) || handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) || handleAssignmentPatternComments(enclosingNode, comment) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options)) {
  17627. return true;
  17628. }
  17629. return false;
  17630. }
  17631. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  17632. var precedingNode = comment.precedingNode,
  17633. enclosingNode = comment.enclosingNode,
  17634. followingNode = comment.followingNode;
  17635. if (handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) || handleImportSpecifierComments(enclosingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleLabeledStatementComments(enclosingNode, comment) || handleCallExpressionComments(precedingNode, enclosingNode, comment) || handlePropertyComments(enclosingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleTypeAliasComments(enclosingNode, followingNode, comment) || handleVariableDeclaratorComments(enclosingNode, followingNode, comment)) {
  17636. return true;
  17637. }
  17638. return false;
  17639. }
  17640. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  17641. var precedingNode = comment.precedingNode,
  17642. enclosingNode = comment.enclosingNode,
  17643. followingNode = comment.followingNode;
  17644. if (handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) || handleCommentInEmptyParens(text, enclosingNode, comment, options) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleCommentAfterArrowParams(text, enclosingNode, comment, options) || handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) || handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) || handleBreakAndContinueStatementComments(enclosingNode, comment)) {
  17645. return true;
  17646. }
  17647. return false;
  17648. }
  17649. function addBlockStatementFirstComment(node, comment) {
  17650. var body = node.body.filter(function (n) {
  17651. return n.type !== "EmptyStatement";
  17652. });
  17653. if (body.length === 0) {
  17654. addDanglingComment$2(node, comment);
  17655. } else {
  17656. addLeadingComment$2(body[0], comment);
  17657. }
  17658. }
  17659. function addBlockOrNotComment(node, comment) {
  17660. if (node.type === "BlockStatement") {
  17661. addBlockStatementFirstComment(node, comment);
  17662. } else {
  17663. addLeadingComment$2(node, comment);
  17664. }
  17665. } // There are often comments before the else clause of if statements like
  17666. //
  17667. // if (1) { ... }
  17668. // // comment
  17669. // else { ... }
  17670. //
  17671. // They are being attached as leading comments of the BlockExpression which
  17672. // is not well printed. What we want is to instead move the comment inside
  17673. // of the block and make it leadingComment of the first element of the block
  17674. // or dangling comment of the block if there is nothing inside
  17675. //
  17676. // if (1) { ... }
  17677. // else {
  17678. // // comment
  17679. // ...
  17680. // }
  17681. function handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  17682. if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) {
  17683. return false;
  17684. } // We unfortunately have no way using the AST or location of nodes to know
  17685. // if the comment is positioned before the condition parenthesis:
  17686. // if (a /* comment */) {}
  17687. // The only workaround I found is to look at the next character to see if
  17688. // it is a ).
  17689. var nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  17690. if (nextCharacter === ")") {
  17691. addTrailingComment$2(precedingNode, comment);
  17692. return true;
  17693. } // Comments before `else`:
  17694. // - treat as trailing comments of the consequent, if it's a BlockStatement
  17695. // - treat as a dangling comment otherwise
  17696. if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
  17697. if (precedingNode.type === "BlockStatement") {
  17698. addTrailingComment$2(precedingNode, comment);
  17699. } else {
  17700. addDanglingComment$2(enclosingNode, comment);
  17701. }
  17702. return true;
  17703. }
  17704. if (followingNode.type === "BlockStatement") {
  17705. addBlockStatementFirstComment(followingNode, comment);
  17706. return true;
  17707. }
  17708. if (followingNode.type === "IfStatement") {
  17709. addBlockOrNotComment(followingNode.consequent, comment);
  17710. return true;
  17711. } // For comments positioned after the condition parenthesis in an if statement
  17712. // before the consequent without brackets on, such as
  17713. // if (a) /* comment */ true,
  17714. // we look at the next character to see if the following node
  17715. // is the consequent for the if statement
  17716. if (enclosingNode.consequent === followingNode) {
  17717. addLeadingComment$2(followingNode, comment);
  17718. return true;
  17719. }
  17720. return false;
  17721. }
  17722. function handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  17723. if (!enclosingNode || enclosingNode.type !== "WhileStatement" || !followingNode) {
  17724. return false;
  17725. } // We unfortunately have no way using the AST or location of nodes to know
  17726. // if the comment is positioned before the condition parenthesis:
  17727. // while (a /* comment */) {}
  17728. // The only workaround I found is to look at the next character to see if
  17729. // it is a ).
  17730. var nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  17731. if (nextCharacter === ")") {
  17732. addTrailingComment$2(precedingNode, comment);
  17733. return true;
  17734. }
  17735. if (followingNode.type === "BlockStatement") {
  17736. addBlockStatementFirstComment(followingNode, comment);
  17737. return true;
  17738. }
  17739. return false;
  17740. } // Same as IfStatement but for TryStatement
  17741. function handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) {
  17742. if (!enclosingNode || enclosingNode.type !== "TryStatement" && enclosingNode.type !== "CatchClause" || !followingNode) {
  17743. return false;
  17744. }
  17745. if (enclosingNode.type === "CatchClause" && precedingNode) {
  17746. addTrailingComment$2(precedingNode, comment);
  17747. return true;
  17748. }
  17749. if (followingNode.type === "BlockStatement") {
  17750. addBlockStatementFirstComment(followingNode, comment);
  17751. return true;
  17752. }
  17753. if (followingNode.type === "TryStatement") {
  17754. addBlockOrNotComment(followingNode.finalizer, comment);
  17755. return true;
  17756. }
  17757. if (followingNode.type === "CatchClause") {
  17758. addBlockOrNotComment(followingNode.body, comment);
  17759. return true;
  17760. }
  17761. return false;
  17762. }
  17763. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  17764. if (enclosingNode && enclosingNode.type === "MemberExpression" && followingNode && followingNode.type === "Identifier") {
  17765. addLeadingComment$2(enclosingNode, comment);
  17766. return true;
  17767. }
  17768. return false;
  17769. }
  17770. function handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) {
  17771. var isSameLineAsPrecedingNode = precedingNode && !util$1.hasNewlineInRange(text, options.locEnd(precedingNode), options.locStart(comment));
  17772. if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && enclosingNode.type === "ConditionalExpression" && followingNode) {
  17773. addLeadingComment$2(followingNode, comment);
  17774. return true;
  17775. }
  17776. return false;
  17777. }
  17778. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  17779. if (enclosingNode && (enclosingNode.type === "ObjectProperty" || enclosingNode.type === "Property") && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === "AssignmentPattern") {
  17780. addTrailingComment$2(enclosingNode.value.left, comment);
  17781. return true;
  17782. }
  17783. return false;
  17784. }
  17785. function handleClassComments(enclosingNode, precedingNode, followingNode, comment) {
  17786. if (enclosingNode && (enclosingNode.type === "ClassDeclaration" || enclosingNode.type === "ClassExpression") && enclosingNode.decorators && enclosingNode.decorators.length > 0 && !(followingNode && followingNode.type === "Decorator")) {
  17787. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  17788. addLeadingComment$2(enclosingNode, comment);
  17789. } else {
  17790. addTrailingComment$2(enclosingNode.decorators[enclosingNode.decorators.length - 1], comment);
  17791. }
  17792. return true;
  17793. }
  17794. return false;
  17795. }
  17796. function handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) {
  17797. // This is only needed for estree parsers (flow, typescript) to attach
  17798. // after a method name:
  17799. // obj = { fn /*comment*/() {} };
  17800. if (enclosingNode && precedingNode && (enclosingNode.type === "Property" || enclosingNode.type === "MethodDefinition") && precedingNode.type === "Identifier" && enclosingNode.key === precedingNode && // special Property case: { key: /*comment*/(value) };
  17801. // comment should be attached to value instead of key
  17802. util$1.getNextNonSpaceNonCommentCharacter(text, precedingNode, options.locEnd) !== ":") {
  17803. addTrailingComment$2(precedingNode, comment);
  17804. return true;
  17805. } // Print comments between decorators and class methods as a trailing comment
  17806. // on the decorator node instead of the method node
  17807. if (precedingNode && enclosingNode && precedingNode.type === "Decorator" && (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "TSAbstractClassProperty" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "MethodDefinition")) {
  17808. addTrailingComment$2(precedingNode, comment);
  17809. return true;
  17810. }
  17811. return false;
  17812. }
  17813. function handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) {
  17814. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== "(") {
  17815. return false;
  17816. }
  17817. if (precedingNode && enclosingNode && (enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "MethodDefinition" || enclosingNode.type === "ObjectMethod")) {
  17818. addTrailingComment$2(precedingNode, comment);
  17819. return true;
  17820. }
  17821. return false;
  17822. }
  17823. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  17824. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  17825. return false;
  17826. }
  17827. var index = utilShared.getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
  17828. if (text.substr(index, 2) === "=>") {
  17829. addDanglingComment$2(enclosingNode, comment);
  17830. return true;
  17831. }
  17832. return false;
  17833. }
  17834. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  17835. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== ")") {
  17836. return false;
  17837. } // Only add dangling comments to fix the case when no params are present,
  17838. // i.e. a function without any argument.
  17839. if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || (enclosingNode.type === "CallExpression" || enclosingNode.type === "NewExpression") && enclosingNode.arguments.length === 0)) {
  17840. addDanglingComment$2(enclosingNode, comment);
  17841. return true;
  17842. }
  17843. if (enclosingNode && enclosingNode.type === "MethodDefinition" && enclosingNode.value.params.length === 0) {
  17844. addDanglingComment$2(enclosingNode.value, comment);
  17845. return true;
  17846. }
  17847. return false;
  17848. }
  17849. function handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  17850. // Type definitions functions
  17851. if (precedingNode && precedingNode.type === "FunctionTypeParam" && enclosingNode && enclosingNode.type === "FunctionTypeAnnotation" && followingNode && followingNode.type !== "FunctionTypeParam") {
  17852. addTrailingComment$2(precedingNode, comment);
  17853. return true;
  17854. } // Real functions
  17855. 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) === ")") {
  17856. addTrailingComment$2(precedingNode, comment);
  17857. return true;
  17858. }
  17859. if (enclosingNode && enclosingNode.type === "FunctionDeclaration" && followingNode && followingNode.type === "BlockStatement") {
  17860. var functionParamRightParenIndex = function () {
  17861. if (enclosingNode.params.length !== 0) {
  17862. return util$1.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(util$1.getLast(enclosingNode.params)));
  17863. }
  17864. var functionParamLeftParenIndex = util$1.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(enclosingNode.id));
  17865. return util$1.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, functionParamLeftParenIndex + 1);
  17866. }();
  17867. if (options.locStart(comment) > functionParamRightParenIndex) {
  17868. addBlockStatementFirstComment(followingNode, comment);
  17869. return true;
  17870. }
  17871. }
  17872. return false;
  17873. }
  17874. function handleImportSpecifierComments(enclosingNode, comment) {
  17875. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  17876. addLeadingComment$2(enclosingNode, comment);
  17877. return true;
  17878. }
  17879. return false;
  17880. }
  17881. function handleLabeledStatementComments(enclosingNode, comment) {
  17882. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  17883. addLeadingComment$2(enclosingNode, comment);
  17884. return true;
  17885. }
  17886. return false;
  17887. }
  17888. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  17889. if (enclosingNode && (enclosingNode.type === "ContinueStatement" || enclosingNode.type === "BreakStatement") && !enclosingNode.label) {
  17890. addTrailingComment$2(enclosingNode, comment);
  17891. return true;
  17892. }
  17893. return false;
  17894. }
  17895. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  17896. if (enclosingNode && enclosingNode.type === "CallExpression" && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
  17897. addLeadingComment$2(enclosingNode.arguments[0], comment);
  17898. return true;
  17899. }
  17900. return false;
  17901. }
  17902. function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
  17903. if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
  17904. addTrailingComment$2(precedingNode, comment);
  17905. return true;
  17906. }
  17907. return false;
  17908. }
  17909. function handlePropertyComments(enclosingNode, comment) {
  17910. if (enclosingNode && (enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty")) {
  17911. addLeadingComment$2(enclosingNode, comment);
  17912. return true;
  17913. }
  17914. return false;
  17915. }
  17916. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  17917. // With Flow the enclosingNode is undefined so use the AST instead.
  17918. if (ast && ast.body && ast.body.length === 0) {
  17919. if (isLastComment) {
  17920. addDanglingComment$2(ast, comment);
  17921. } else {
  17922. addLeadingComment$2(ast, comment);
  17923. }
  17924. return true;
  17925. } else if (enclosingNode && enclosingNode.type === "Program" && enclosingNode.body.length === 0 && enclosingNode.directives && enclosingNode.directives.length === 0) {
  17926. if (isLastComment) {
  17927. addDanglingComment$2(enclosingNode, comment);
  17928. } else {
  17929. addLeadingComment$2(enclosingNode, comment);
  17930. }
  17931. return true;
  17932. }
  17933. return false;
  17934. }
  17935. function handleForComments(enclosingNode, precedingNode, comment) {
  17936. if (enclosingNode && (enclosingNode.type === "ForInStatement" || enclosingNode.type === "ForOfStatement")) {
  17937. addLeadingComment$2(enclosingNode, comment);
  17938. return true;
  17939. }
  17940. return false;
  17941. }
  17942. function handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) {
  17943. if (precedingNode && precedingNode.type === "ImportSpecifier" && enclosingNode && enclosingNode.type === "ImportDeclaration" && util$1.hasNewline(text, options.locEnd(comment))) {
  17944. addTrailingComment$2(precedingNode, comment);
  17945. return true;
  17946. }
  17947. return false;
  17948. }
  17949. function handleAssignmentPatternComments(enclosingNode, comment) {
  17950. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  17951. addLeadingComment$2(enclosingNode, comment);
  17952. return true;
  17953. }
  17954. return false;
  17955. }
  17956. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  17957. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  17958. addLeadingComment$2(enclosingNode, comment);
  17959. return true;
  17960. }
  17961. return false;
  17962. }
  17963. function handleVariableDeclaratorComments(enclosingNode, followingNode, comment) {
  17964. if (enclosingNode && (enclosingNode.type === "VariableDeclarator" || enclosingNode.type === "AssignmentExpression") && followingNode && (followingNode.type === "ObjectExpression" || followingNode.type === "ArrayExpression" || followingNode.type === "TemplateLiteral" || followingNode.type === "TaggedTemplateExpression")) {
  17965. addLeadingComment$2(followingNode, comment);
  17966. return true;
  17967. }
  17968. return false;
  17969. }
  17970. function handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) {
  17971. if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
  17972. return false;
  17973. }
  17974. if (followingNode && followingNode.type === "TSTypeParameter" && followingNode.name) {
  17975. addLeadingComment$2(followingNode.name, comment);
  17976. return true;
  17977. }
  17978. if (precedingNode && precedingNode.type === "TSTypeParameter" && precedingNode.constraint) {
  17979. addTrailingComment$2(precedingNode.constraint, comment);
  17980. return true;
  17981. }
  17982. return false;
  17983. }
  17984. function isBlockComment$1(comment) {
  17985. return comment.type === "Block" || comment.type === "CommentBlock";
  17986. }
  17987. function hasLeadingComment$2(node) {
  17988. var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  17989. return true;
  17990. };
  17991. if (node.leadingComments) {
  17992. return node.leadingComments.some(fn);
  17993. }
  17994. if (node.comments) {
  17995. return node.comments.some(function (comment) {
  17996. return comment.leading && fn(comment);
  17997. });
  17998. }
  17999. return false;
  18000. }
  18001. var comments$3 = {
  18002. handleOwnLineComment,
  18003. handleEndOfLineComment,
  18004. handleRemainingComment,
  18005. hasLeadingComment: hasLeadingComment$2,
  18006. isBlockComment: isBlockComment$1
  18007. };
  18008. var isBlockComment = comments$3.isBlockComment;
  18009. var hasLeadingComment$1 = comments$3.hasLeadingComment;
  18010. var _require$$1$builders = doc.builders;
  18011. var indent$3 = _require$$1$builders.indent;
  18012. var join$3 = _require$$1$builders.join;
  18013. var hardline$4 = _require$$1$builders.hardline;
  18014. var softline$2 = _require$$1$builders.softline;
  18015. var literalline$2 = _require$$1$builders.literalline;
  18016. var concat$5 = _require$$1$builders.concat;
  18017. var group$2 = _require$$1$builders.group;
  18018. var dedentToRoot$1 = _require$$1$builders.dedentToRoot;
  18019. var _require$$1$utils = doc.utils;
  18020. var mapDoc$3 = _require$$1$utils.mapDoc;
  18021. var stripTrailingHardline$1 = _require$$1$utils.stripTrailingHardline;
  18022. function embed(path$$1, print, textToDoc, options) {
  18023. var node = path$$1.getValue();
  18024. var parent = path$$1.getParentNode();
  18025. var parentParent = path$$1.getParentNode(1);
  18026. switch (node.type) {
  18027. case "TemplateLiteral":
  18028. {
  18029. var isCss = [isStyledJsx, isStyledComponents, isCssProp, isAngularComponentStyles].some(function (isIt) {
  18030. return isIt(path$$1);
  18031. });
  18032. if (isCss) {
  18033. // Get full template literal with expressions replaced by placeholders
  18034. var rawQuasis = node.quasis.map(function (q) {
  18035. return q.value.raw;
  18036. });
  18037. var placeholderID = 0;
  18038. var text = rawQuasis.reduce(function (prevVal, currVal, idx) {
  18039. return idx == 0 ? currVal : prevVal + "@prettier-placeholder-" + placeholderID++ + "-id" + currVal;
  18040. }, "");
  18041. var doc$$2 = textToDoc(text, {
  18042. parser: "css"
  18043. });
  18044. return transformCssDoc(doc$$2, path$$1, print);
  18045. }
  18046. /*
  18047. * react-relay and graphql-tag
  18048. * graphql`...`
  18049. * graphql.experimental`...`
  18050. * gql`...`
  18051. *
  18052. * This intentionally excludes Relay Classic tags, as Prettier does not
  18053. * support Relay Classic formatting.
  18054. */
  18055. if (isGraphQL(path$$1)) {
  18056. var expressionDocs = node.expressions ? path$$1.map(print, "expressions") : [];
  18057. var numQuasis = node.quasis.length;
  18058. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  18059. return "``";
  18060. }
  18061. var parts = [];
  18062. for (var i = 0; i < numQuasis; i++) {
  18063. var templateElement = node.quasis[i];
  18064. var isFirst = i === 0;
  18065. var isLast = i === numQuasis - 1;
  18066. var _text = templateElement.value.cooked; // Bail out if any of the quasis have an invalid escape sequence
  18067. // (which would make the `cooked` value be `null` or `undefined`)
  18068. if (typeof _text !== "string") {
  18069. return null;
  18070. }
  18071. var lines = _text.split("\n");
  18072. var numLines = lines.length;
  18073. var expressionDoc = expressionDocs[i];
  18074. var startsWithBlankLine = numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  18075. var endsWithBlankLine = numLines > 2 && lines[numLines - 1].trim() === "" && lines[numLines - 2].trim() === "";
  18076. var commentsAndWhitespaceOnly = lines.every(function (line) {
  18077. return /^\s*(?:#[^\r\n]*)?$/.test(line);
  18078. }); // Bail out if an interpolation occurs within a comment.
  18079. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  18080. return null;
  18081. }
  18082. var _doc = null;
  18083. if (commentsAndWhitespaceOnly) {
  18084. _doc = printGraphqlComments(lines);
  18085. } else {
  18086. _doc = stripTrailingHardline$1(textToDoc(_text, {
  18087. parser: "graphql"
  18088. }));
  18089. }
  18090. if (_doc) {
  18091. _doc = escapeTemplateCharacters(_doc, false);
  18092. if (!isFirst && startsWithBlankLine) {
  18093. parts.push("");
  18094. }
  18095. parts.push(_doc);
  18096. if (!isLast && endsWithBlankLine) {
  18097. parts.push("");
  18098. }
  18099. } else if (!isFirst && !isLast && startsWithBlankLine) {
  18100. parts.push("");
  18101. }
  18102. if (expressionDoc) {
  18103. parts.push(concat$5(["${", expressionDoc, "}"]));
  18104. }
  18105. }
  18106. return concat$5(["`", indent$3(concat$5([hardline$4, join$3(hardline$4, parts)])), hardline$4, "`"]);
  18107. }
  18108. var htmlParser = isHtml(path$$1) ? "html" : isAngularComponentTemplate(path$$1) ? "angular" : undefined;
  18109. if (htmlParser) {
  18110. return printHtmlTemplateLiteral(path$$1, print, textToDoc, htmlParser, options.embeddedInHtml);
  18111. }
  18112. break;
  18113. }
  18114. case "TemplateElement":
  18115. {
  18116. /**
  18117. * md`...`
  18118. * markdown`...`
  18119. */
  18120. if (parentParent && parentParent.type === "TaggedTemplateExpression" && parent.quasis.length === 1 && parentParent.tag.type === "Identifier" && (parentParent.tag.name === "md" || parentParent.tag.name === "markdown")) {
  18121. var _text2 = parent.quasis[0].value.raw.replace(/((?:\\\\)*)\\`/g, function (_, backslashes) {
  18122. return "\\".repeat(backslashes.length / 2) + "`";
  18123. });
  18124. var indentation = getIndentation(_text2);
  18125. var hasIndent = indentation !== "";
  18126. 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]);
  18127. }
  18128. break;
  18129. }
  18130. }
  18131. function printMarkdown(text) {
  18132. var doc$$2 = textToDoc(text, {
  18133. parser: "markdown",
  18134. __inJsTemplate: true
  18135. });
  18136. return stripTrailingHardline$1(escapeTemplateCharacters(doc$$2, true));
  18137. }
  18138. }
  18139. function getIndentation(str) {
  18140. var firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  18141. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  18142. }
  18143. function uncook(cookedValue) {
  18144. return cookedValue.replace(/([\\`]|\$\{)/g, "\\$1");
  18145. }
  18146. function escapeTemplateCharacters(doc$$2, raw) {
  18147. return mapDoc$3(doc$$2, function (currentDoc) {
  18148. if (!currentDoc.parts) {
  18149. return currentDoc;
  18150. }
  18151. var parts = [];
  18152. currentDoc.parts.forEach(function (part) {
  18153. if (typeof part === "string") {
  18154. parts.push(raw ? part.replace(/(\\*)`/g, "$1$1\\`") : uncook(part));
  18155. } else {
  18156. parts.push(part);
  18157. }
  18158. });
  18159. return Object.assign({}, currentDoc, {
  18160. parts
  18161. });
  18162. });
  18163. }
  18164. function transformCssDoc(quasisDoc, path$$1, print) {
  18165. var parentNode = path$$1.getValue();
  18166. var isEmpty = parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  18167. if (isEmpty) {
  18168. return "``";
  18169. }
  18170. var expressionDocs = parentNode.expressions ? path$$1.map(print, "expressions") : [];
  18171. var newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  18172. /* istanbul ignore if */
  18173. if (!newDoc) {
  18174. throw new Error("Couldn't insert all the expressions");
  18175. }
  18176. return concat$5(["`", indent$3(concat$5([hardline$4, stripTrailingHardline$1(newDoc)])), softline$2, "`"]);
  18177. } // Search all the placeholders in the quasisDoc tree
  18178. // and replace them with the expression docs one by one
  18179. // returns a new doc with all the placeholders replaced,
  18180. // or null if it couldn't replace any expression
  18181. function replacePlaceholders(quasisDoc, expressionDocs) {
  18182. if (!expressionDocs || !expressionDocs.length) {
  18183. return quasisDoc;
  18184. }
  18185. var expressions = expressionDocs.slice();
  18186. var replaceCounter = 0;
  18187. var newDoc = mapDoc$3(quasisDoc, function (doc$$2) {
  18188. if (!doc$$2 || !doc$$2.parts || !doc$$2.parts.length) {
  18189. return doc$$2;
  18190. }
  18191. var parts = doc$$2.parts;
  18192. var atIndex = parts.indexOf("@");
  18193. var placeholderIndex = atIndex + 1;
  18194. if (atIndex > -1 && typeof parts[placeholderIndex] === "string" && parts[placeholderIndex].startsWith("prettier-placeholder")) {
  18195. // If placeholder is split, join it
  18196. var at = parts[atIndex];
  18197. var placeholder = parts[placeholderIndex];
  18198. var rest = parts.slice(placeholderIndex + 1);
  18199. parts = parts.slice(0, atIndex).concat([at + placeholder]).concat(rest);
  18200. }
  18201. var atPlaceholderIndex = parts.findIndex(function (part) {
  18202. return typeof part === "string" && part.startsWith("@prettier-placeholder");
  18203. });
  18204. if (atPlaceholderIndex > -1) {
  18205. var _placeholder = parts[atPlaceholderIndex];
  18206. var _rest = parts.slice(atPlaceholderIndex + 1);
  18207. var placeholderMatch = _placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
  18208. var placeholderID = placeholderMatch[1]; // When the expression has a suffix appended, like:
  18209. // animation: linear ${time}s ease-out;
  18210. var suffix = placeholderMatch[2];
  18211. var expression = expressions[placeholderID];
  18212. replaceCounter++;
  18213. parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(_rest);
  18214. }
  18215. return Object.assign({}, doc$$2, {
  18216. parts: parts
  18217. });
  18218. });
  18219. return expressions.length === replaceCounter ? newDoc : null;
  18220. }
  18221. function printGraphqlComments(lines) {
  18222. var parts = [];
  18223. var seenComment = false;
  18224. lines.map(function (textLine) {
  18225. return textLine.trim();
  18226. }).forEach(function (textLine, i, array) {
  18227. // Lines are either whitespace only, or a comment (with poential whitespace
  18228. // around it). Drop whitespace-only lines.
  18229. if (textLine === "") {
  18230. return;
  18231. }
  18232. if (array[i - 1] === "" && seenComment) {
  18233. // If a non-first comment is preceded by a blank (whitespace only) line,
  18234. // add in a blank line.
  18235. parts.push(concat$5([hardline$4, textLine]));
  18236. } else {
  18237. parts.push(textLine);
  18238. }
  18239. seenComment = true;
  18240. }); // If `lines` was whitespace only, return `null`.
  18241. return parts.length === 0 ? null : join$3(hardline$4, parts);
  18242. }
  18243. /**
  18244. * Template literal in these contexts:
  18245. * <style jsx>{`div{color:red}`}</style>
  18246. * css``
  18247. * css.global``
  18248. * css.resolve``
  18249. */
  18250. function isStyledJsx(path$$1) {
  18251. var node = path$$1.getValue();
  18252. var parent = path$$1.getParentNode();
  18253. var parentParent = path$$1.getParentNode(1);
  18254. return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(function (attribute) {
  18255. return attribute.name.name === "jsx";
  18256. }) || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "Identifier" && parent.tag.name === "css" || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "MemberExpression" && parent.tag.object.name === "css" && (parent.tag.property.name === "global" || parent.tag.property.name === "resolve");
  18257. }
  18258. /**
  18259. * Angular Components can have:
  18260. * - Inline HTML template
  18261. * - Inline CSS styles
  18262. *
  18263. * ...which are both within template literals somewhere
  18264. * inside of the Component decorator factory.
  18265. *
  18266. * E.g.
  18267. * @Component({
  18268. * template: `<div>...</div>`,
  18269. * styles: [`h1 { color: blue; }`]
  18270. * })
  18271. */
  18272. function isAngularComponentStyles(path$$1) {
  18273. return isPathMatch(path$$1, [function (node) {
  18274. return node.type === "TemplateLiteral";
  18275. }, function (node, name) {
  18276. return node.type === "ArrayExpression" && name === "elements";
  18277. }, function (node, name) {
  18278. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "styles" && name === "value";
  18279. }].concat(getAngularComponentObjectExpressionPredicates()));
  18280. }
  18281. function isAngularComponentTemplate(path$$1) {
  18282. return isPathMatch(path$$1, [function (node) {
  18283. return node.type === "TemplateLiteral";
  18284. }, function (node, name) {
  18285. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "template" && name === "value";
  18286. }].concat(getAngularComponentObjectExpressionPredicates()));
  18287. }
  18288. function getAngularComponentObjectExpressionPredicates() {
  18289. return [function (node, name) {
  18290. return node.type === "ObjectExpression" && name === "properties";
  18291. }, function (node, name) {
  18292. return node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "Component" && name === "arguments";
  18293. }, function (node, name) {
  18294. return node.type === "Decorator" && name === "expression";
  18295. }];
  18296. }
  18297. /**
  18298. * styled-components template literals
  18299. */
  18300. function isStyledComponents(path$$1) {
  18301. var parent = path$$1.getParentNode();
  18302. if (!parent || parent.type !== "TaggedTemplateExpression") {
  18303. return false;
  18304. }
  18305. var tag = parent.tag;
  18306. switch (tag.type) {
  18307. case "MemberExpression":
  18308. return (// styled.foo``
  18309. isStyledIdentifier(tag.object) || // Component.extend``
  18310. isStyledExtend(tag)
  18311. );
  18312. case "CallExpression":
  18313. return (// styled(Component)``
  18314. isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attrs({})``
  18315. isStyledIdentifier(tag.callee.object.object) || // Component.extend.attrs({})``
  18316. isStyledExtend(tag.callee.object)) || // styled(Component).attrs({})``
  18317. tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
  18318. );
  18319. case "Identifier":
  18320. // css``
  18321. return tag.name === "css";
  18322. default:
  18323. return false;
  18324. }
  18325. }
  18326. /**
  18327. * JSX element with CSS prop
  18328. */
  18329. function isCssProp(path$$1) {
  18330. var parent = path$$1.getParentNode();
  18331. var parentParent = path$$1.getParentNode(1);
  18332. return parentParent && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" && parentParent.name.type === "JSXIdentifier" && parentParent.name.name === "css";
  18333. }
  18334. function isStyledIdentifier(node) {
  18335. return node.type === "Identifier" && node.name === "styled";
  18336. }
  18337. function isStyledExtend(node) {
  18338. return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
  18339. }
  18340. /*
  18341. * react-relay and graphql-tag
  18342. * graphql`...`
  18343. * graphql.experimental`...`
  18344. * gql`...`
  18345. * GraphQL comment block
  18346. *
  18347. * This intentionally excludes Relay Classic tags, as Prettier does not
  18348. * support Relay Classic formatting.
  18349. */
  18350. function isGraphQL(path$$1) {
  18351. var node = path$$1.getValue();
  18352. var parent = path$$1.getParentNode();
  18353. return hasLanguageComment(node, "GraphQL") || parent && (parent.type === "TaggedTemplateExpression" && (parent.tag.type === "MemberExpression" && parent.tag.object.name === "graphql" && parent.tag.property.name === "experimental" || parent.tag.type === "Identifier" && (parent.tag.name === "gql" || parent.tag.name === "graphql")) || parent.type === "CallExpression" && parent.callee.type === "Identifier" && parent.callee.name === "graphql");
  18354. }
  18355. function hasLanguageComment(node, languageName) {
  18356. // This checks for a leading comment that is exactly `/* GraphQL */`
  18357. // In order to be in line with other implementations of this comment tag
  18358. // we will not trim the comment value and we will expect exactly one space on
  18359. // either side of the GraphQL string
  18360. // Also see ./clean.js
  18361. return hasLeadingComment$1(node, function (comment) {
  18362. return isBlockComment(comment) && comment.value === ` ${languageName} `;
  18363. });
  18364. }
  18365. function isPathMatch(path$$1, predicateStack) {
  18366. var stack = path$$1.stack.slice();
  18367. var name = null;
  18368. var node = stack.pop();
  18369. var _iteratorNormalCompletion = true;
  18370. var _didIteratorError = false;
  18371. var _iteratorError = undefined;
  18372. try {
  18373. for (var _iterator = predicateStack[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  18374. var predicate = _step.value;
  18375. if (node === undefined) {
  18376. return false;
  18377. } // skip index/array
  18378. if (typeof name === "number") {
  18379. name = stack.pop();
  18380. node = stack.pop();
  18381. }
  18382. if (!predicate(node, name)) {
  18383. return false;
  18384. }
  18385. name = stack.pop();
  18386. node = stack.pop();
  18387. }
  18388. } catch (err) {
  18389. _didIteratorError = true;
  18390. _iteratorError = err;
  18391. } finally {
  18392. try {
  18393. if (!_iteratorNormalCompletion && _iterator.return != null) {
  18394. _iterator.return();
  18395. }
  18396. } finally {
  18397. if (_didIteratorError) {
  18398. throw _iteratorError;
  18399. }
  18400. }
  18401. }
  18402. return true;
  18403. }
  18404. /**
  18405. * - html`...`
  18406. * - HTML comment block
  18407. */
  18408. function isHtml(path$$1) {
  18409. var node = path$$1.getValue();
  18410. return hasLanguageComment(node, "HTML") || isPathMatch(path$$1, [function (node) {
  18411. return node.type === "TemplateLiteral";
  18412. }, function (node, name) {
  18413. return node.type === "TaggedTemplateExpression" && node.tag.type === "Identifier" && node.tag.name === "html" && name === "quasi";
  18414. }]);
  18415. } // The counter is needed to distinguish nested embeds.
  18416. var htmlTemplateLiteralCounter = 0;
  18417. function printHtmlTemplateLiteral(path$$1, print, textToDoc, parser, escapeClosingScriptTag) {
  18418. var node = path$$1.getValue();
  18419. var counter = htmlTemplateLiteralCounter;
  18420. htmlTemplateLiteralCounter = htmlTemplateLiteralCounter + 1 >>> 0;
  18421. var composePlaceholder = function composePlaceholder(index) {
  18422. return `PRETTIER_HTML_PLACEHOLDER_${index}_${counter}_IN_JS`;
  18423. };
  18424. var text = node.quasis.map(function (quasi, index, quasis) {
  18425. return index === quasis.length - 1 ? quasi.value.cooked : quasi.value.cooked + composePlaceholder(index);
  18426. }).join("");
  18427. var expressionDocs = path$$1.map(print, "expressions");
  18428. if (expressionDocs.length === 0 && text.trim().length === 0) {
  18429. return "``";
  18430. }
  18431. var placeholderRegex = RegExp(composePlaceholder("(\\d+)"), "g");
  18432. var contentDoc = mapDoc$3(stripTrailingHardline$1(textToDoc(text, {
  18433. parser
  18434. })), function (doc$$2) {
  18435. if (typeof doc$$2 !== "string") {
  18436. return doc$$2;
  18437. }
  18438. var parts = [];
  18439. var components = doc$$2.split(placeholderRegex);
  18440. for (var i = 0; i < components.length; i++) {
  18441. var component = components[i];
  18442. if (i % 2 === 0) {
  18443. if (component) {
  18444. component = uncook(component);
  18445. if (escapeClosingScriptTag) {
  18446. component = component.replace(/<\/(script)\b/gi, "<\\/$1");
  18447. }
  18448. parts.push(component);
  18449. }
  18450. continue;
  18451. }
  18452. var placeholderIndex = +component;
  18453. parts.push(concat$5(["${", group$2(expressionDocs[placeholderIndex]), "}"]));
  18454. }
  18455. return concat$5(parts);
  18456. });
  18457. return group$2(concat$5(["`", indent$3(concat$5([hardline$4, group$2(contentDoc)])), softline$2, "`"]));
  18458. }
  18459. var embed_1 = embed;
  18460. function clean(ast, newObj, parent) {
  18461. ["range", "raw", "comments", "leadingComments", "trailingComments", "extra", "start", "end", "flags"].forEach(function (name) {
  18462. delete newObj[name];
  18463. });
  18464. if (ast.type === "BigIntLiteral") {
  18465. newObj.value = newObj.value.toLowerCase();
  18466. } // We remove extra `;` and add them when needed
  18467. if (ast.type === "EmptyStatement") {
  18468. return null;
  18469. } // We move text around, including whitespaces and add {" "}
  18470. if (ast.type === "JSXText") {
  18471. return null;
  18472. }
  18473. if (ast.type === "JSXExpressionContainer" && ast.expression.type === "Literal" && ast.expression.value === " ") {
  18474. return null;
  18475. } // (TypeScript) Ignore `static` in `constructor(static p) {}`
  18476. // and `export` in `constructor(export p) {}`
  18477. if (ast.type === "TSParameterProperty" && ast.accessibility === null && !ast.readonly) {
  18478. return {
  18479. type: "Identifier",
  18480. name: ast.parameter.name,
  18481. typeAnnotation: newObj.parameter.typeAnnotation,
  18482. decorators: newObj.decorators
  18483. };
  18484. } // (TypeScript) ignore empty `specifiers` array
  18485. if (ast.type === "TSNamespaceExportDeclaration" && ast.specifiers && ast.specifiers.length === 0) {
  18486. delete newObj.specifiers;
  18487. } // (TypeScript) bypass TSParenthesizedType
  18488. if (ast.type === "TSParenthesizedType") {
  18489. return newObj.typeAnnotation;
  18490. } // We convert <div></div> to <div />
  18491. if (ast.type === "JSXOpeningElement") {
  18492. delete newObj.selfClosing;
  18493. }
  18494. if (ast.type === "JSXElement") {
  18495. delete newObj.closingElement;
  18496. } // We change {'key': value} into {key: value}
  18497. 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")) {
  18498. delete newObj.key;
  18499. }
  18500. if (ast.type === "OptionalMemberExpression" && ast.optional === false) {
  18501. newObj.type = "MemberExpression";
  18502. delete newObj.optional;
  18503. } // Remove raw and cooked values from TemplateElement when it's CSS
  18504. // styled-jsx
  18505. if (ast.type === "JSXElement" && ast.openingElement.name.name === "style" && ast.openingElement.attributes.some(function (attr) {
  18506. return attr.name.name === "jsx";
  18507. })) {
  18508. var templateLiterals = newObj.children.filter(function (child) {
  18509. return child.type === "JSXExpressionContainer" && child.expression.type === "TemplateLiteral";
  18510. }).map(function (container) {
  18511. return container.expression;
  18512. });
  18513. var quasis = templateLiterals.reduce(function (quasis, templateLiteral) {
  18514. return quasis.concat(templateLiteral.quasis);
  18515. }, []);
  18516. quasis.forEach(function (q) {
  18517. return delete q.value;
  18518. });
  18519. } // CSS template literals in css prop
  18520. if (ast.type === "JSXAttribute" && ast.name.name === "css" && ast.value.type === "JSXExpressionContainer" && ast.value.expression.type === "TemplateLiteral") {
  18521. newObj.value.expression.quasis.forEach(function (q) {
  18522. return delete q.value;
  18523. });
  18524. } // Angular Components: Inline HTML template and Inline CSS styles
  18525. var expression = ast.expression || ast.callee;
  18526. if (ast.type === "Decorator" && expression.type === "CallExpression" && expression.callee.name === "Component" && expression.arguments.length === 1) {
  18527. var astProps = ast.expression.arguments[0].properties;
  18528. newObj.expression.arguments[0].properties.forEach(function (prop, index) {
  18529. var templateLiteral = null;
  18530. switch (astProps[index].key.name) {
  18531. case "styles":
  18532. if (prop.value.type === "ArrayExpression") {
  18533. templateLiteral = prop.value.elements[0];
  18534. }
  18535. break;
  18536. case "template":
  18537. if (prop.value.type === "TemplateLiteral") {
  18538. templateLiteral = prop.value;
  18539. }
  18540. break;
  18541. }
  18542. if (templateLiteral) {
  18543. templateLiteral.quasis.forEach(function (q) {
  18544. return delete q.value;
  18545. });
  18546. }
  18547. });
  18548. } // styled-components, graphql, markdown
  18549. if (ast.type === "TaggedTemplateExpression" && (ast.tag.type === "MemberExpression" || ast.tag.type === "Identifier" && (ast.tag.name === "gql" || ast.tag.name === "graphql" || ast.tag.name === "css" || ast.tag.name === "md" || ast.tag.name === "markdown" || ast.tag.name === "html") || ast.tag.type === "CallExpression")) {
  18550. newObj.quasi.quasis.forEach(function (quasi) {
  18551. return delete quasi.value;
  18552. });
  18553. }
  18554. if (ast.type === "TemplateLiteral") {
  18555. // This checks for a leading comment that is exactly `/* GraphQL */`
  18556. // In order to be in line with other implementations of this comment tag
  18557. // we will not trim the comment value and we will expect exactly one space on
  18558. // either side of the GraphQL string
  18559. // Also see ./embed.js
  18560. var hasLanguageComment = ast.leadingComments && ast.leadingComments.some(function (comment) {
  18561. return comment.type === "CommentBlock" && ["GraphQL", "HTML"].some(function (languageName) {
  18562. return comment.value === ` ${languageName} `;
  18563. });
  18564. });
  18565. if (hasLanguageComment || parent.type === "CallExpression" && parent.callee.name === "graphql") {
  18566. newObj.quasis.forEach(function (quasi) {
  18567. return delete quasi.value;
  18568. });
  18569. }
  18570. }
  18571. }
  18572. var clean_1 = clean;
  18573. var detectNewline = createCommonjsModule(function (module) {
  18574. 'use strict';
  18575. module.exports = function (str) {
  18576. if (typeof str !== 'string') {
  18577. throw new TypeError('Expected a string');
  18578. }
  18579. var newlines = str.match(/(?:\r?\n)/g) || [];
  18580. if (newlines.length === 0) {
  18581. return null;
  18582. }
  18583. var crlf = newlines.filter(function (el) {
  18584. return el === '\r\n';
  18585. }).length;
  18586. var lf = newlines.length - crlf;
  18587. return crlf > lf ? '\r\n' : '\n';
  18588. };
  18589. module.exports.graceful = function (str) {
  18590. return module.exports(str) || '\n';
  18591. };
  18592. });
  18593. var build$1 = createCommonjsModule(function (module, exports) {
  18594. 'use strict';
  18595. Object.defineProperty(exports, '__esModule', {
  18596. value: true
  18597. });
  18598. exports.extract = extract;
  18599. exports.strip = strip;
  18600. exports.parse = parse;
  18601. exports.parseWithComments = parseWithComments;
  18602. exports.print = print;
  18603. var _detectNewline;
  18604. function _load_detectNewline() {
  18605. return _detectNewline = _interopRequireDefault(detectNewline);
  18606. }
  18607. var _os;
  18608. function _load_os() {
  18609. return _os = os;
  18610. }
  18611. function _interopRequireDefault(obj) {
  18612. return obj && obj.__esModule ? obj : {
  18613. default: obj
  18614. };
  18615. }
  18616. /**
  18617. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  18618. *
  18619. * This source code is licensed under the MIT license found in the
  18620. * LICENSE file in the root directory of this source tree.
  18621. *
  18622. *
  18623. */
  18624. var commentEndRe = /\*\/$/;
  18625. var commentStartRe = /^\/\*\*/;
  18626. var docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
  18627. var lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
  18628. var ltrimNewlineRe = /^(\r?\n)+/;
  18629. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  18630. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  18631. var stringStartRe = /(\r?\n|^) *\* ?/g;
  18632. function extract(contents) {
  18633. var match = contents.match(docblockRe);
  18634. return match ? match[0].trimLeft() : '';
  18635. }
  18636. function strip(contents) {
  18637. var match = contents.match(docblockRe);
  18638. return match && match[0] ? contents.substring(match[0].length) : contents;
  18639. }
  18640. function parse(docblock) {
  18641. return parseWithComments(docblock).pragmas;
  18642. }
  18643. function parseWithComments(docblock) {
  18644. var line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL;
  18645. docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  18646. var prev = '';
  18647. while (prev !== docblock) {
  18648. prev = docblock;
  18649. docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);
  18650. }
  18651. docblock = docblock.replace(ltrimNewlineRe, '').trimRight();
  18652. var result = Object.create(null);
  18653. var comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').trimRight();
  18654. var match;
  18655. while (match = propertyRe.exec(docblock)) {
  18656. // strip linecomments from pragmas
  18657. var nextPragma = match[2].replace(lineCommentRe, '');
  18658. if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
  18659. result[match[1]] = [].concat(result[match[1]], nextPragma);
  18660. } else {
  18661. result[match[1]] = nextPragma;
  18662. }
  18663. }
  18664. return {
  18665. comments,
  18666. pragmas: result
  18667. };
  18668. }
  18669. function print(_ref) {
  18670. var _ref$comments = _ref.comments;
  18671. var comments = _ref$comments === undefined ? '' : _ref$comments;
  18672. var _ref$pragmas = _ref.pragmas;
  18673. var pragmas = _ref$pragmas === undefined ? {} : _ref$pragmas;
  18674. var line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL;
  18675. var head = '/**';
  18676. var start = ' *';
  18677. var tail = ' */';
  18678. var keys = Object.keys(pragmas);
  18679. var printedObject = keys.map(function (key) {
  18680. return printKeyValues(key, pragmas[key]);
  18681. }).reduce(function (arr, next) {
  18682. return arr.concat(next);
  18683. }, []).map(function (keyValue) {
  18684. return start + ' ' + keyValue + line;
  18685. }).join('');
  18686. if (!comments) {
  18687. if (keys.length === 0) {
  18688. return '';
  18689. }
  18690. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  18691. var value = pragmas[keys[0]];
  18692. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  18693. }
  18694. }
  18695. var printedComments = comments.split(line).map(function (textLine) {
  18696. return `${start} ${textLine}`;
  18697. }).join(line) + line;
  18698. return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail;
  18699. }
  18700. function printKeyValues(key, valueOrArray) {
  18701. return [].concat(valueOrArray).map(function (value) {
  18702. return `@${key} ${value}`.trim();
  18703. });
  18704. }
  18705. });
  18706. unwrapExports(build$1);
  18707. function hasPragma(text) {
  18708. var pragmas = Object.keys(build$1.parse(build$1.extract(text)));
  18709. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  18710. }
  18711. function insertPragma$1(text) {
  18712. var parsedDocblock = build$1.parseWithComments(build$1.extract(text));
  18713. var pragmas = Object.assign({
  18714. format: ""
  18715. }, parsedDocblock.pragmas);
  18716. var newDocblock = build$1.print({
  18717. pragmas,
  18718. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  18719. }).replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
  18720. var strippedText = build$1.strip(text);
  18721. var separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  18722. return newDocblock + separatingNewlines + strippedText;
  18723. }
  18724. var pragma = {
  18725. hasPragma,
  18726. insertPragma: insertPragma$1
  18727. };
  18728. // Flow annotation comments cannot be split across lines. For example:
  18729. //
  18730. // (this /*
  18731. // : any */).foo = 5;
  18732. //
  18733. // is not picked up by Flow (see https://github.com/facebook/flow/issues/7050), so
  18734. // removing the newline would create a type annotation that the user did not intend
  18735. // to create.
  18736. var NON_LINE_TERMINATING_WHITE_SPACE = "(?:(?=.)\\s)";
  18737. var FLOW_SHORTHAND_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*:`);
  18738. var FLOW_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*::`);
  18739. function hasFlowShorthandAnnotationComment$2(node) {
  18740. // https://flow.org/en/docs/types/comments/
  18741. // Syntax example: const r = new (window.Request /*: Class<Request> */)("");
  18742. return node.extra && node.extra.parenthesized && node.trailingComments && node.trailingComments[0].value.match(FLOW_SHORTHAND_ANNOTATION);
  18743. }
  18744. function hasFlowAnnotationComment$1(comments) {
  18745. return comments && comments[0].value.match(FLOW_ANNOTATION);
  18746. }
  18747. function hasNode$1(node, fn) {
  18748. if (!node || typeof node !== "object") {
  18749. return false;
  18750. }
  18751. if (Array.isArray(node)) {
  18752. return node.some(function (value) {
  18753. return hasNode$1(value, fn);
  18754. });
  18755. }
  18756. var result = fn(node);
  18757. return typeof result === "boolean" ? result : Object.keys(node).some(function (key) {
  18758. return hasNode$1(node[key], fn);
  18759. });
  18760. }
  18761. function hasNakedLeftSide$2(node) {
  18762. return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression" || node.type === "ConditionalExpression" || node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || node.type === "UpdateExpression" && !node.prefix || node.type === "TSAsExpression" || node.type === "TSNonNullExpression";
  18763. }
  18764. function getLeftSide$1(node) {
  18765. if (node.expressions) {
  18766. return node.expressions[0];
  18767. }
  18768. return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
  18769. }
  18770. function getLeftSidePathName$2(path$$1, node) {
  18771. if (node.expressions) {
  18772. return ["expressions", 0];
  18773. }
  18774. if (node.left) {
  18775. return ["left"];
  18776. }
  18777. if (node.test) {
  18778. return ["test"];
  18779. }
  18780. if (node.object) {
  18781. return ["object"];
  18782. }
  18783. if (node.callee) {
  18784. return ["callee"];
  18785. }
  18786. if (node.tag) {
  18787. return ["tag"];
  18788. }
  18789. if (node.argument) {
  18790. return ["argument"];
  18791. }
  18792. if (node.expression) {
  18793. return ["expression"];
  18794. }
  18795. throw new Error("Unexpected node has no left side", node);
  18796. }
  18797. var utils$4 = {
  18798. getLeftSide: getLeftSide$1,
  18799. getLeftSidePathName: getLeftSidePathName$2,
  18800. hasNakedLeftSide: hasNakedLeftSide$2,
  18801. hasNode: hasNode$1,
  18802. hasFlowShorthandAnnotationComment: hasFlowShorthandAnnotationComment$2,
  18803. hasFlowAnnotationComment: hasFlowAnnotationComment$1
  18804. };
  18805. var getLeftSidePathName$1 = utils$4.getLeftSidePathName;
  18806. var hasNakedLeftSide$1 = utils$4.hasNakedLeftSide;
  18807. var hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment;
  18808. function hasClosureCompilerTypeCastComment(text, path$$1) {
  18809. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  18810. // Syntax example: var x = /** @type {string} */ (fruit);
  18811. var n = path$$1.getValue();
  18812. return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
  18813. function hasAncestorTypeCastComment(index) {
  18814. var ancestor = path$$1.getParentNode(index);
  18815. return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
  18816. }
  18817. function hasTypeCastComment(node) {
  18818. return node.comments && node.comments.some(function (comment) {
  18819. return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
  18820. });
  18821. }
  18822. function isParenthesized(node) {
  18823. // Closure typecast comments only really make sense when _not_ using
  18824. // typescript or flow parsers, so we take advantage of the babel parser's
  18825. // parenthesized expressions.
  18826. return node.extra && node.extra.parenthesized;
  18827. }
  18828. function isTypeCastComment(comment) {
  18829. var cleaned = comment.trim().split("\n").map(function (line) {
  18830. return line.replace(/^[\s*]+/, "");
  18831. }).join(" ").trim();
  18832. if (!/^@type\s*\{[^]+\}$/.test(cleaned)) {
  18833. return false;
  18834. }
  18835. var isCompletelyClosed = false;
  18836. var unpairedBracketCount = 0;
  18837. var _iteratorNormalCompletion = true;
  18838. var _didIteratorError = false;
  18839. var _iteratorError = undefined;
  18840. try {
  18841. for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  18842. var char = _step.value;
  18843. if (char === "{") {
  18844. if (isCompletelyClosed) {
  18845. return false;
  18846. }
  18847. unpairedBracketCount++;
  18848. } else if (char === "}") {
  18849. if (unpairedBracketCount === 0) {
  18850. return false;
  18851. }
  18852. unpairedBracketCount--;
  18853. if (unpairedBracketCount === 0) {
  18854. isCompletelyClosed = true;
  18855. }
  18856. }
  18857. }
  18858. } catch (err) {
  18859. _didIteratorError = true;
  18860. _iteratorError = err;
  18861. } finally {
  18862. try {
  18863. if (!_iteratorNormalCompletion && _iterator.return != null) {
  18864. _iterator.return();
  18865. }
  18866. } finally {
  18867. if (_didIteratorError) {
  18868. throw _iteratorError;
  18869. }
  18870. }
  18871. }
  18872. return unpairedBracketCount === 0;
  18873. }
  18874. }
  18875. function needsParens(path$$1, options) {
  18876. var parent = path$$1.getParentNode();
  18877. if (!parent) {
  18878. return false;
  18879. }
  18880. var name = path$$1.getName();
  18881. var node = path$$1.getNode(); // If the value of this path is some child of a Node and not a Node
  18882. // itself, then it doesn't need parentheses. Only Node objects (in
  18883. // fact, only Expression nodes) need parentheses.
  18884. if (path$$1.getValue() !== node) {
  18885. return false;
  18886. } // to avoid unexpected `}}` in HTML interpolations
  18887. if (options.__isInHtmlInterpolation && !options.bracketSpacing && endsWithRightBracket(node) && isFollowedByRightBracket(path$$1)) {
  18888. return true;
  18889. } // Only statements don't need parentheses.
  18890. if (isStatement(node)) {
  18891. return false;
  18892. } // Closure compiler requires that type casted expressions to be surrounded by
  18893. // parentheses.
  18894. if (hasClosureCompilerTypeCastComment(options.originalText, path$$1)) {
  18895. return true;
  18896. }
  18897. if ( // Preserve parens if we have a Flow annotation comment, unless we're using the Flow
  18898. // parser. The Flow parser turns Flow comments into type annotation nodes in its
  18899. // AST, which we handle separately.
  18900. options.parser !== "flow" && hasFlowShorthandAnnotationComment$1(path$$1.getValue())) {
  18901. return true;
  18902. } // Identifiers never need parentheses.
  18903. if (node.type === "Identifier") {
  18904. // ...unless those identifiers are embed placeholders. They might be substituted by complex
  18905. // expressions, so the parens around them should not be dropped. Example (JS-in-HTML-in-JS):
  18906. // let tpl = html`<script> f((${expr}) / 2); </script>`;
  18907. // If the inner JS formatter removes the parens, the expression might change its meaning:
  18908. // f((a + b) / 2) vs f(a + b / 2)
  18909. if (node.extra && node.extra.parenthesized && /^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(node.name)) {
  18910. return true;
  18911. }
  18912. return false;
  18913. }
  18914. if (parent.type === "ParenthesizedExpression") {
  18915. return false;
  18916. } // Add parens around the extends clause of a class. It is needed for almost
  18917. // all expressions.
  18918. 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")) {
  18919. return true;
  18920. } // `export default function` or `export default class` can't be followed by
  18921. // anything after. So an expression like `export default (function(){}).toString()`
  18922. // needs to be followed by a parentheses
  18923. if (parent.type === "ExportDefaultDeclaration") {
  18924. return shouldWrapFunctionForExportDefault(path$$1, options);
  18925. }
  18926. if (parent.type === "Decorator" && parent.expression === node) {
  18927. var hasCallExpression = false;
  18928. var hasMemberExpression = false;
  18929. var current = node;
  18930. while (current) {
  18931. switch (current.type) {
  18932. case "MemberExpression":
  18933. hasMemberExpression = true;
  18934. current = current.object;
  18935. break;
  18936. case "CallExpression":
  18937. if (
  18938. /** @(x().y) */
  18939. hasMemberExpression ||
  18940. /** @(x().y()) */
  18941. hasCallExpression) {
  18942. return true;
  18943. }
  18944. hasCallExpression = true;
  18945. current = current.callee;
  18946. break;
  18947. case "Identifier":
  18948. return false;
  18949. default:
  18950. return true;
  18951. }
  18952. }
  18953. return true;
  18954. }
  18955. if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
  18956. util$1.startsWithNoLookaheadToken(node,
  18957. /* forbidFunctionClassAndDoExpr */
  18958. false) || parent.type === "ExpressionStatement" && util$1.startsWithNoLookaheadToken(node,
  18959. /* forbidFunctionClassAndDoExpr */
  18960. true)) {
  18961. return true;
  18962. }
  18963. switch (node.type) {
  18964. case "CallExpression":
  18965. {
  18966. var firstParentNotMemberExpression = parent;
  18967. var i = 0; // tagged templates are basically member expressions from a grammar perspective
  18968. // see https://tc39.github.io/ecma262/#prod-MemberExpression
  18969. // so are typescript's non-null assertions, though there's no grammar to point to
  18970. while (firstParentNotMemberExpression && (firstParentNotMemberExpression.type === "MemberExpression" && firstParentNotMemberExpression.object === path$$1.getParentNode(i - 1) || firstParentNotMemberExpression.type === "TaggedTemplateExpression" || firstParentNotMemberExpression.type === "TSNonNullExpression")) {
  18971. firstParentNotMemberExpression = path$$1.getParentNode(++i);
  18972. }
  18973. if (firstParentNotMemberExpression.type === "NewExpression" && firstParentNotMemberExpression.callee === path$$1.getParentNode(i - 1)) {
  18974. return true;
  18975. }
  18976. if (parent.type === "BindExpression" && parent.callee === node) {
  18977. return true;
  18978. }
  18979. return false;
  18980. }
  18981. case "SpreadElement":
  18982. case "SpreadProperty":
  18983. return parent.type === "MemberExpression" && name === "object" && parent.object === node;
  18984. case "UpdateExpression":
  18985. if (parent.type === "UnaryExpression") {
  18986. return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-");
  18987. }
  18988. // else fallthrough
  18989. case "UnaryExpression":
  18990. switch (parent.type) {
  18991. case "UnaryExpression":
  18992. return node.operator === parent.operator && (node.operator === "+" || node.operator === "-");
  18993. case "BindExpression":
  18994. return true;
  18995. case "MemberExpression":
  18996. return name === "object" && parent.object === node;
  18997. case "TaggedTemplateExpression":
  18998. return true;
  18999. case "NewExpression":
  19000. case "CallExpression":
  19001. return name === "callee" && parent.callee === node;
  19002. case "BinaryExpression":
  19003. return parent.operator === "**" && name === "left";
  19004. case "TSNonNullExpression":
  19005. return true;
  19006. default:
  19007. return false;
  19008. }
  19009. case "BinaryExpression":
  19010. {
  19011. if (parent.type === "UpdateExpression") {
  19012. return true;
  19013. }
  19014. var isLeftOfAForStatement = function isLeftOfAForStatement(node) {
  19015. var i = 0;
  19016. while (node) {
  19017. var _parent = path$$1.getParentNode(i++);
  19018. if (!_parent) {
  19019. return false;
  19020. }
  19021. if (_parent.type === "ForStatement" && _parent.init === node) {
  19022. return true;
  19023. }
  19024. node = _parent;
  19025. }
  19026. return false;
  19027. };
  19028. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  19029. return true;
  19030. }
  19031. }
  19032. // fallthrough
  19033. case "TSTypeAssertion":
  19034. case "TSAsExpression":
  19035. case "LogicalExpression":
  19036. switch (parent.type) {
  19037. case "ConditionalExpression":
  19038. return node.type === "TSAsExpression";
  19039. case "CallExpression":
  19040. case "NewExpression":
  19041. return name === "callee" && parent.callee === node;
  19042. case "ClassExpression":
  19043. case "ClassDeclaration":
  19044. return name === "superClass" && parent.superClass === node;
  19045. case "TSTypeAssertion":
  19046. case "TaggedTemplateExpression":
  19047. case "UnaryExpression":
  19048. case "JSXSpreadAttribute":
  19049. case "SpreadElement":
  19050. case "SpreadProperty":
  19051. case "BindExpression":
  19052. case "AwaitExpression":
  19053. case "TSAsExpression":
  19054. case "TSNonNullExpression":
  19055. case "UpdateExpression":
  19056. return true;
  19057. case "MemberExpression":
  19058. case "OptionalMemberExpression":
  19059. return name === "object" && parent.object === node;
  19060. case "AssignmentExpression":
  19061. return parent.left === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression");
  19062. case "BinaryExpression":
  19063. case "LogicalExpression":
  19064. {
  19065. if (!node.operator && node.type !== "TSTypeAssertion") {
  19066. return true;
  19067. }
  19068. var po = parent.operator;
  19069. var pp = util$1.getPrecedence(po);
  19070. var no = node.operator;
  19071. var np = util$1.getPrecedence(no);
  19072. if (pp > np) {
  19073. return true;
  19074. }
  19075. if ((po === "||" || po === "??") && no === "&&") {
  19076. return true;
  19077. }
  19078. if (pp === np && name === "right") {
  19079. assert.strictEqual(parent.right, node);
  19080. return true;
  19081. }
  19082. if (pp === np && !util$1.shouldFlatten(po, no)) {
  19083. return true;
  19084. }
  19085. if (pp < np && no === "%") {
  19086. return po === "+" || po === "-";
  19087. } // Add parenthesis when working with bitwise operators
  19088. // It's not stricly needed but helps with code understanding
  19089. if (util$1.isBitwiseOperator(po)) {
  19090. return true;
  19091. }
  19092. return false;
  19093. }
  19094. default:
  19095. return false;
  19096. }
  19097. case "TSParenthesizedType":
  19098. {
  19099. var grandParent = path$$1.getParentNode(1);
  19100. /**
  19101. * const foo = (): (() => void) => (): void => null;
  19102. * ^ ^
  19103. */
  19104. if (getUnparenthesizedNode(node).type === "TSFunctionType" && parent.type === "TSTypeAnnotation" && grandParent.type === "ArrowFunctionExpression" && grandParent.returnType === parent) {
  19105. return true;
  19106. }
  19107. if ((parent.type === "TSTypeParameter" || parent.type === "TypeParameter" || parent.type === "TSTypeAliasDeclaration" || parent.type === "TSTypeAnnotation" || parent.type === "TSParenthesizedType" || parent.type === "TSTypeParameterInstantiation") && grandParent.type !== "TSTypeOperator" && grandParent.type !== "TSOptionalType") {
  19108. return false;
  19109. } // Delegate to inner TSParenthesizedType
  19110. if (node.typeAnnotation.type === "TSParenthesizedType" && parent.type !== "TSArrayType") {
  19111. return false;
  19112. }
  19113. return true;
  19114. }
  19115. case "SequenceExpression":
  19116. switch (parent.type) {
  19117. case "ReturnStatement":
  19118. return false;
  19119. case "ForStatement":
  19120. // Although parentheses wouldn't hurt around sequence
  19121. // expressions in the head of for loops, traditional style
  19122. // dictates that e.g. i++, j++ should not be wrapped with
  19123. // parentheses.
  19124. return false;
  19125. case "ExpressionStatement":
  19126. return name !== "expression";
  19127. case "ArrowFunctionExpression":
  19128. // We do need parentheses, but SequenceExpressions are handled
  19129. // specially when printing bodies of arrow functions.
  19130. return name !== "body";
  19131. default:
  19132. // Otherwise err on the side of overparenthesization, adding
  19133. // explicit exceptions above if this proves overzealous.
  19134. return true;
  19135. }
  19136. case "YieldExpression":
  19137. if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") {
  19138. return true;
  19139. }
  19140. // else fallthrough
  19141. case "AwaitExpression":
  19142. switch (parent.type) {
  19143. case "TaggedTemplateExpression":
  19144. case "UnaryExpression":
  19145. case "BinaryExpression":
  19146. case "LogicalExpression":
  19147. case "SpreadElement":
  19148. case "SpreadProperty":
  19149. case "TSAsExpression":
  19150. case "TSNonNullExpression":
  19151. case "BindExpression":
  19152. case "OptionalMemberExpression":
  19153. return true;
  19154. case "MemberExpression":
  19155. return parent.object === node;
  19156. case "NewExpression":
  19157. case "CallExpression":
  19158. return parent.callee === node;
  19159. case "ConditionalExpression":
  19160. return parent.test === node;
  19161. default:
  19162. return false;
  19163. }
  19164. case "ArrayTypeAnnotation":
  19165. return parent.type === "NullableTypeAnnotation";
  19166. case "IntersectionTypeAnnotation":
  19167. case "UnionTypeAnnotation":
  19168. return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation";
  19169. case "NullableTypeAnnotation":
  19170. return parent.type === "ArrayTypeAnnotation";
  19171. case "FunctionTypeAnnotation":
  19172. {
  19173. var ancestor = parent.type === "NullableTypeAnnotation" ? path$$1.getParentNode(1) : parent;
  19174. return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses
  19175. // are really needed, but since ??T doesn't make sense this check
  19176. // will almost never be true.
  19177. ancestor.type === "NullableTypeAnnotation";
  19178. }
  19179. case "StringLiteral":
  19180. case "NumericLiteral":
  19181. case "Literal":
  19182. if (typeof node.value === "string" && parent.type === "ExpressionStatement" && ( // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  19183. // See corresponding workaround in printer.js case: "Literal"
  19184. options.parser !== "typescript" && !parent.directive || options.parser === "typescript" && options.originalText.substr(options.locStart(node) - 1, 1) === "(")) {
  19185. // To avoid becoming a directive
  19186. var _grandParent = path$$1.getParentNode(1);
  19187. return _grandParent.type === "Program" || _grandParent.type === "BlockStatement";
  19188. }
  19189. return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node;
  19190. case "AssignmentExpression":
  19191. {
  19192. var _grandParent2 = path$$1.getParentNode(1);
  19193. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  19194. return true;
  19195. } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) {
  19196. return false;
  19197. } else if (parent.type === "TSPropertySignature" && parent.name === node) {
  19198. return false;
  19199. } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) {
  19200. return false;
  19201. } else if (parent.type === "ExpressionStatement") {
  19202. return node.left.type === "ObjectPattern";
  19203. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  19204. return false;
  19205. } else if (parent.type === "AssignmentExpression") {
  19206. return false;
  19207. } else if (parent.type === "SequenceExpression" && _grandParent2 && _grandParent2.type === "ForStatement" && (_grandParent2.init === parent || _grandParent2.update === parent)) {
  19208. return false;
  19209. } else if (parent.type === "Property" && parent.value === node) {
  19210. return false;
  19211. } else if (parent.type === "NGChainedExpression") {
  19212. return false;
  19213. }
  19214. return true;
  19215. }
  19216. case "ConditionalExpression":
  19217. switch (parent.type) {
  19218. case "TaggedTemplateExpression":
  19219. case "UnaryExpression":
  19220. case "SpreadElement":
  19221. case "SpreadProperty":
  19222. case "BinaryExpression":
  19223. case "LogicalExpression":
  19224. case "NGPipeExpression":
  19225. case "ExportDefaultDeclaration":
  19226. case "AwaitExpression":
  19227. case "JSXSpreadAttribute":
  19228. case "TSTypeAssertion":
  19229. case "TypeCastExpression":
  19230. case "TSAsExpression":
  19231. case "TSNonNullExpression":
  19232. case "OptionalMemberExpression":
  19233. return true;
  19234. case "NewExpression":
  19235. case "CallExpression":
  19236. return name === "callee" && parent.callee === node;
  19237. case "ConditionalExpression":
  19238. return name === "test" && parent.test === node;
  19239. case "MemberExpression":
  19240. return name === "object" && parent.object === node;
  19241. default:
  19242. return false;
  19243. }
  19244. case "FunctionExpression":
  19245. switch (parent.type) {
  19246. case "NewExpression":
  19247. case "CallExpression":
  19248. return name === "callee";
  19249. // Not strictly necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  19250. case "TaggedTemplateExpression":
  19251. return true;
  19252. // This is basically a kind of IIFE.
  19253. default:
  19254. return false;
  19255. }
  19256. case "ArrowFunctionExpression":
  19257. switch (parent.type) {
  19258. case "CallExpression":
  19259. return name === "callee";
  19260. case "NewExpression":
  19261. return name === "callee";
  19262. case "MemberExpression":
  19263. return name === "object";
  19264. case "TSAsExpression":
  19265. case "BindExpression":
  19266. case "TaggedTemplateExpression":
  19267. case "UnaryExpression":
  19268. case "LogicalExpression":
  19269. case "BinaryExpression":
  19270. case "AwaitExpression":
  19271. case "TSTypeAssertion":
  19272. return true;
  19273. case "ConditionalExpression":
  19274. return name === "test";
  19275. default:
  19276. return false;
  19277. }
  19278. case "ClassExpression":
  19279. switch (parent.type) {
  19280. case "NewExpression":
  19281. return name === "callee" && parent.callee === node;
  19282. default:
  19283. return false;
  19284. }
  19285. case "OptionalMemberExpression":
  19286. return parent.type === "MemberExpression";
  19287. case "MemberExpression":
  19288. if (parent.type === "BindExpression" && name === "callee" && parent.callee === node) {
  19289. var object = node.object;
  19290. while (object) {
  19291. if (object.type === "CallExpression") {
  19292. return true;
  19293. }
  19294. if (object.type !== "MemberExpression" && object.type !== "BindExpression") {
  19295. break;
  19296. }
  19297. object = object.object;
  19298. }
  19299. }
  19300. return false;
  19301. case "BindExpression":
  19302. if (parent.type === "BindExpression" && name === "callee" && parent.callee === node || parent.type === "MemberExpression" && name === "object" && parent.object === node || parent.type === "NewExpression" && name === "callee" && parent.callee === node) {
  19303. return true;
  19304. }
  19305. return false;
  19306. case "NGPipeExpression":
  19307. if (parent.type === "NGRoot" || parent.type === "NGMicrosyntaxExpression" || parent.type === "ObjectProperty" || parent.type === "ArrayExpression" || (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && parent.arguments[name] === node || parent.type === "NGPipeExpression" && name === "right" || parent.type === "MemberExpression" && name === "property" || parent.type === "AssignmentExpression") {
  19308. return false;
  19309. }
  19310. return true;
  19311. }
  19312. return false;
  19313. }
  19314. function isStatement(node) {
  19315. 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 === "TSDeclareFunction" || node.type === "TSEnumDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSModuleDeclaration" || node.type === "TSNamespaceExportDeclaration" || node.type === "TypeAlias" || node.type === "VariableDeclaration" || node.type === "WhileStatement" || node.type === "WithStatement";
  19316. }
  19317. function getUnparenthesizedNode(node) {
  19318. return node.type === "TSParenthesizedType" ? getUnparenthesizedNode(node.typeAnnotation) : node;
  19319. }
  19320. function endsWithRightBracket(node) {
  19321. switch (node.type) {
  19322. case "ObjectExpression":
  19323. return true;
  19324. default:
  19325. return false;
  19326. }
  19327. }
  19328. function isFollowedByRightBracket(path$$1) {
  19329. var node = path$$1.getValue();
  19330. var parent = path$$1.getParentNode();
  19331. var name = path$$1.getName();
  19332. switch (parent.type) {
  19333. case "NGPipeExpression":
  19334. if (typeof name === "number" && parent.arguments[name] === node && parent.arguments.length - 1 === name) {
  19335. return path$$1.callParent(isFollowedByRightBracket);
  19336. }
  19337. break;
  19338. case "ObjectProperty":
  19339. if (name === "value") {
  19340. var parentParent = path$$1.getParentNode(1);
  19341. return parentParent.properties[parentParent.properties.length - 1] === parent;
  19342. }
  19343. break;
  19344. case "BinaryExpression":
  19345. case "LogicalExpression":
  19346. if (name === "right") {
  19347. return path$$1.callParent(isFollowedByRightBracket);
  19348. }
  19349. break;
  19350. case "ConditionalExpression":
  19351. if (name === "alternate") {
  19352. return path$$1.callParent(isFollowedByRightBracket);
  19353. }
  19354. break;
  19355. case "UnaryExpression":
  19356. if (parent.prefix) {
  19357. return path$$1.callParent(isFollowedByRightBracket);
  19358. }
  19359. break;
  19360. }
  19361. return false;
  19362. }
  19363. function shouldWrapFunctionForExportDefault(path$$1, options) {
  19364. var node = path$$1.getValue();
  19365. var parent = path$$1.getParentNode();
  19366. if (node.type === "FunctionExpression" || node.type === "ClassExpression") {
  19367. return parent.type === "ExportDefaultDeclaration" || // in some cases the function is already wrapped
  19368. // (e.g. `export default (function() {})();`)
  19369. // in this case we don't need to add extra parens
  19370. !needsParens(path$$1, options);
  19371. }
  19372. if (!hasNakedLeftSide$1(node) || parent.type !== "ExportDefaultDeclaration" && needsParens(path$$1, options)) {
  19373. return false;
  19374. }
  19375. return path$$1.call.apply(path$$1, [function (childPath) {
  19376. return shouldWrapFunctionForExportDefault(childPath, options);
  19377. }].concat(getLeftSidePathName$1(path$$1, node)));
  19378. }
  19379. var needsParens_1 = needsParens;
  19380. var _require$$0$builders$1 = doc.builders;
  19381. var concat$6 = _require$$0$builders$1.concat;
  19382. var join$4 = _require$$0$builders$1.join;
  19383. var line$4 = _require$$0$builders$1.line;
  19384. function printHtmlBinding$1(path$$1, options, print) {
  19385. var node = path$$1.getValue();
  19386. if (options.__onHtmlBindingRoot && path$$1.getName() === null) {
  19387. options.__onHtmlBindingRoot(node);
  19388. }
  19389. if (node.type !== "File") {
  19390. return;
  19391. }
  19392. if (options.__isVueForBindingLeft) {
  19393. return path$$1.call(function (functionDeclarationPath) {
  19394. var _functionDeclarationP = functionDeclarationPath.getValue(),
  19395. params = _functionDeclarationP.params;
  19396. return concat$6([params.length > 1 ? "(" : "", join$4(concat$6([",", line$4]), functionDeclarationPath.map(print, "params")), params.length > 1 ? ")" : ""]);
  19397. }, "program", "body", 0);
  19398. }
  19399. if (options.__isVueSlotScope) {
  19400. return path$$1.call(function (functionDeclarationPath) {
  19401. return join$4(concat$6([",", line$4]), functionDeclarationPath.map(print, "params"));
  19402. }, "program", "body", 0);
  19403. }
  19404. } // based on https://github.com/prettier/prettier/blob/master/src/language-html/syntax-vue.js isVueEventBindingExpression()
  19405. function isVueEventBindingExpression$1(node) {
  19406. switch (node.type) {
  19407. case "MemberExpression":
  19408. switch (node.property.type) {
  19409. case "Identifier":
  19410. case "NumericLiteral":
  19411. case "StringLiteral":
  19412. return isVueEventBindingExpression$1(node.object);
  19413. }
  19414. return false;
  19415. case "Identifier":
  19416. return true;
  19417. default:
  19418. return false;
  19419. }
  19420. }
  19421. var htmlBinding = {
  19422. isVueEventBindingExpression: isVueEventBindingExpression$1,
  19423. printHtmlBinding: printHtmlBinding$1
  19424. };
  19425. function preprocess(ast, options) {
  19426. switch (options.parser) {
  19427. case "json":
  19428. case "json5":
  19429. case "json-stringify":
  19430. case "__js_expression":
  19431. case "__vue_expression":
  19432. return Object.assign({}, ast, {
  19433. type: options.parser.startsWith("__") ? "JsExpressionRoot" : "JsonRoot",
  19434. node: ast,
  19435. comments: []
  19436. });
  19437. default:
  19438. return ast;
  19439. }
  19440. }
  19441. var preprocess_1 = preprocess;
  19442. var getParentExportDeclaration$1 = util$1.getParentExportDeclaration;
  19443. var isExportDeclaration$1 = util$1.isExportDeclaration;
  19444. var shouldFlatten$1 = util$1.shouldFlatten;
  19445. var getNextNonSpaceNonCommentCharacter$1 = util$1.getNextNonSpaceNonCommentCharacter;
  19446. var hasNewline$2 = util$1.hasNewline;
  19447. var hasNewlineInRange$1 = util$1.hasNewlineInRange;
  19448. var getLast$3 = util$1.getLast;
  19449. var getStringWidth$2 = util$1.getStringWidth;
  19450. var printString$1 = util$1.printString;
  19451. var printNumber$1 = util$1.printNumber;
  19452. var hasIgnoreComment$1 = util$1.hasIgnoreComment;
  19453. var skipWhitespace$1 = util$1.skipWhitespace;
  19454. var hasNodeIgnoreComment$1 = util$1.hasNodeIgnoreComment;
  19455. var getPenultimate$1 = util$1.getPenultimate;
  19456. var startsWithNoLookaheadToken$1 = util$1.startsWithNoLookaheadToken;
  19457. var getIndentSize$1 = util$1.getIndentSize;
  19458. var matchAncestorTypes$1 = util$1.matchAncestorTypes;
  19459. var getPreferredQuote$1 = util$1.getPreferredQuote;
  19460. var isNextLineEmpty$2 = utilShared.isNextLineEmpty;
  19461. var isNextLineEmptyAfterIndex$1 = utilShared.isNextLineEmptyAfterIndex;
  19462. var getNextNonSpaceNonCommentCharacterIndex$2 = utilShared.getNextNonSpaceNonCommentCharacterIndex;
  19463. var isIdentifierName = utils$2.keyword.isIdentifierNameES5;
  19464. var insertPragma = pragma.insertPragma;
  19465. var printHtmlBinding = htmlBinding.printHtmlBinding;
  19466. var isVueEventBindingExpression = htmlBinding.isVueEventBindingExpression;
  19467. var getLeftSide = utils$4.getLeftSide;
  19468. var getLeftSidePathName = utils$4.getLeftSidePathName;
  19469. var hasNakedLeftSide = utils$4.hasNakedLeftSide;
  19470. var hasNode = utils$4.hasNode;
  19471. var hasFlowAnnotationComment = utils$4.hasFlowAnnotationComment;
  19472. var hasFlowShorthandAnnotationComment = utils$4.hasFlowShorthandAnnotationComment;
  19473. var needsQuoteProps = new WeakMap();
  19474. var _require$$6$builders = doc.builders;
  19475. var concat$4 = _require$$6$builders.concat;
  19476. var join$2 = _require$$6$builders.join;
  19477. var line$3 = _require$$6$builders.line;
  19478. var hardline$3 = _require$$6$builders.hardline;
  19479. var softline$1 = _require$$6$builders.softline;
  19480. var literalline$1 = _require$$6$builders.literalline;
  19481. var group$1 = _require$$6$builders.group;
  19482. var indent$2 = _require$$6$builders.indent;
  19483. var align$1 = _require$$6$builders.align;
  19484. var conditionalGroup$1 = _require$$6$builders.conditionalGroup;
  19485. var fill$2 = _require$$6$builders.fill;
  19486. var ifBreak$1 = _require$$6$builders.ifBreak;
  19487. var breakParent$2 = _require$$6$builders.breakParent;
  19488. var lineSuffixBoundary$1 = _require$$6$builders.lineSuffixBoundary;
  19489. var addAlignmentToDoc$2 = _require$$6$builders.addAlignmentToDoc;
  19490. var dedent$2 = _require$$6$builders.dedent;
  19491. var _require$$6$utils = doc.utils;
  19492. var willBreak$1 = _require$$6$utils.willBreak;
  19493. var isLineNext$1 = _require$$6$utils.isLineNext;
  19494. var isEmpty$1 = _require$$6$utils.isEmpty;
  19495. var removeLines$1 = _require$$6$utils.removeLines;
  19496. var printDocToString$2 = doc.printer.printDocToString;
  19497. var uid = 0;
  19498. function shouldPrintComma(options, level) {
  19499. level = level || "es5";
  19500. switch (options.trailingComma) {
  19501. case "all":
  19502. if (level === "all") {
  19503. return true;
  19504. }
  19505. // fallthrough
  19506. case "es5":
  19507. if (level === "es5") {
  19508. return true;
  19509. }
  19510. // fallthrough
  19511. case "none":
  19512. default:
  19513. return false;
  19514. }
  19515. }
  19516. function genericPrint(path$$1, options, printPath, args) {
  19517. var node = path$$1.getValue();
  19518. var needsParens = false;
  19519. var linesWithoutParens = printPathNoParens(path$$1, options, printPath, args);
  19520. if (!node || isEmpty$1(linesWithoutParens)) {
  19521. return linesWithoutParens;
  19522. }
  19523. var parentExportDecl = getParentExportDeclaration$1(path$$1);
  19524. var decorators = [];
  19525. if (node.type === "ClassMethod" || node.type === "ClassPrivateMethod" || node.type === "ClassProperty" || node.type === "TSAbstractClassProperty" || node.type === "ClassPrivateProperty" || node.type === "MethodDefinition" || node.type === "TSAbstractMethodDefinition") {// their decorators are handled themselves
  19526. } else if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration and the decorator
  19527. // was written before the export, the export will be responsible
  19528. // for printing the decorators.
  19529. !(parentExportDecl && options.locStart(parentExportDecl, {
  19530. ignoreDecorators: true
  19531. }) > options.locStart(node.decorators[0]))) {
  19532. var shouldBreak = node.type === "ClassExpression" || node.type === "ClassDeclaration" || hasNewlineBetweenOrAfterDecorators(node, options);
  19533. var separator = shouldBreak ? hardline$3 : line$3;
  19534. path$$1.each(function (decoratorPath) {
  19535. var decorator = decoratorPath.getValue();
  19536. if (decorator.expression) {
  19537. decorator = decorator.expression;
  19538. } else {
  19539. decorator = decorator.callee;
  19540. }
  19541. decorators.push(printPath(decoratorPath), separator);
  19542. }, "decorators");
  19543. if (parentExportDecl) {
  19544. decorators.unshift(hardline$3);
  19545. }
  19546. } else if (isExportDeclaration$1(node) && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0 && // Only print decorators here if they were written before the export,
  19547. // otherwise they are printed by the node.declaration
  19548. options.locStart(node, {
  19549. ignoreDecorators: true
  19550. }) > options.locStart(node.declaration.decorators[0])) {
  19551. // Export declarations are responsible for printing any decorators
  19552. // that logically apply to node.declaration.
  19553. path$$1.each(function (decoratorPath) {
  19554. var decorator = decoratorPath.getValue();
  19555. var prefix = decorator.type === "Decorator" ? "" : "@";
  19556. decorators.push(prefix, printPath(decoratorPath), hardline$3);
  19557. }, "declaration", "decorators");
  19558. } else {
  19559. // Nodes with decorators can't have parentheses, so we can avoid
  19560. // computing pathNeedsParens() except in this case.
  19561. needsParens = needsParens_1(path$$1, options);
  19562. }
  19563. var parts = [];
  19564. if (needsParens) {
  19565. parts.unshift("(");
  19566. }
  19567. parts.push(linesWithoutParens);
  19568. if (needsParens) {
  19569. var _node = path$$1.getValue();
  19570. if (hasFlowShorthandAnnotationComment(_node)) {
  19571. parts.push(" /*");
  19572. parts.push(_node.trailingComments[0].value.trimLeft());
  19573. parts.push("*/");
  19574. _node.trailingComments[0].printed = true;
  19575. }
  19576. parts.push(")");
  19577. }
  19578. if (decorators.length > 0) {
  19579. return group$1(concat$4(decorators.concat(parts)));
  19580. }
  19581. return concat$4(parts);
  19582. }
  19583. function hasNewlineBetweenOrAfterDecorators(node, options) {
  19584. return hasNewlineInRange$1(options.originalText, options.locStart(node.decorators[0]), options.locEnd(getLast$3(node.decorators))) || hasNewline$2(options.originalText, options.locEnd(getLast$3(node.decorators)));
  19585. }
  19586. function printDecorators(path$$1, options, print) {
  19587. var node = path$$1.getValue();
  19588. return group$1(concat$4([join$2(line$3, path$$1.map(print, "decorators")), hasNewlineBetweenOrAfterDecorators(node, options) ? hardline$3 : line$3]));
  19589. }
  19590. function hasPrettierIgnore(path$$1) {
  19591. return hasIgnoreComment$1(path$$1) || hasJsxIgnoreComment(path$$1);
  19592. }
  19593. function hasJsxIgnoreComment(path$$1) {
  19594. var node = path$$1.getValue();
  19595. var parent = path$$1.getParentNode();
  19596. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  19597. return false;
  19598. } // Lookup the previous sibling, ignoring any empty JSXText elements
  19599. var index = parent.children.indexOf(node);
  19600. var prevSibling = null;
  19601. for (var i = index; i > 0; i--) {
  19602. var candidate = parent.children[i - 1];
  19603. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  19604. continue;
  19605. }
  19606. prevSibling = candidate;
  19607. break;
  19608. }
  19609. return prevSibling && prevSibling.type === "JSXExpressionContainer" && prevSibling.expression.type === "JSXEmptyExpression" && prevSibling.expression.comments && prevSibling.expression.comments.find(function (comment) {
  19610. return comment.value.trim() === "prettier-ignore";
  19611. });
  19612. }
  19613. /**
  19614. * The following is the shared logic for
  19615. * ternary operators, namely ConditionalExpression
  19616. * and TSConditionalType
  19617. * @typedef {Object} OperatorOptions
  19618. * @property {() => Array<string | Doc>} beforeParts - Parts to print before the `?`.
  19619. * @property {(breakClosingParen: boolean) => Array<string | Doc>} afterParts - Parts to print after the conditional expression.
  19620. * @property {boolean} shouldCheckJsx - Whether to check for and print in JSX mode.
  19621. * @property {string} conditionalNodeType - The type of the conditional expression node, ie "ConditionalExpression" or "TSConditionalType".
  19622. * @property {string} consequentNodePropertyName - The property at which the consequent node can be found on the main node, eg "consequent".
  19623. * @property {string} alternateNodePropertyName - The property at which the alternate node can be found on the main node, eg "alternate".
  19624. * @property {string} testNodePropertyName - The property at which the test node can be found on the main node, eg "test".
  19625. * @property {boolean} breakNested - Whether to break all nested ternaries when one breaks.
  19626. * @param {FastPath} path - The path to the ConditionalExpression/TSConditionalType node.
  19627. * @param {Options} options - Prettier options
  19628. * @param {Function} print - Print function to call recursively
  19629. * @param {OperatorOptions} operatorOptions
  19630. * @returns Doc
  19631. */
  19632. function printTernaryOperator(path$$1, options, print, operatorOptions) {
  19633. var node = path$$1.getValue();
  19634. var testNode = node[operatorOptions.testNodePropertyName];
  19635. var consequentNode = node[operatorOptions.consequentNodePropertyName];
  19636. var alternateNode = node[operatorOptions.alternateNodePropertyName];
  19637. var parts = []; // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  19638. // See tests/jsx/conditional-expression.js for more info.
  19639. var jsxMode = false;
  19640. var parent = path$$1.getParentNode();
  19641. var forceNoIndent = parent.type === operatorOptions.conditionalNodeType; // Find the outermost non-ConditionalExpression parent, and the outermost
  19642. // ConditionalExpression parent. We'll use these to determine if we should
  19643. // print in JSX mode.
  19644. var currentParent;
  19645. var previousParent;
  19646. var i = 0;
  19647. do {
  19648. previousParent = currentParent || node;
  19649. currentParent = path$$1.getParentNode(i);
  19650. i++;
  19651. } while (currentParent && currentParent.type === operatorOptions.conditionalNodeType);
  19652. var firstNonConditionalParent = currentParent || parent;
  19653. var lastConditionalParent = previousParent;
  19654. if (operatorOptions.shouldCheckJsx && (isJSXNode(testNode) || isJSXNode(consequentNode) || isJSXNode(alternateNode) || conditionalExpressionChainContainsJSX(lastConditionalParent))) {
  19655. jsxMode = true;
  19656. forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in
  19657. // parens when using ?: within JSX, because the parens are analogous to
  19658. // curly braces in an if statement.
  19659. var wrap = function wrap(doc$$2) {
  19660. return concat$4([ifBreak$1("(", ""), indent$2(concat$4([softline$1, doc$$2])), softline$1, ifBreak$1(")", "")]);
  19661. }; // The only things we don't wrap are:
  19662. // * Nested conditional expressions in alternates
  19663. // * null
  19664. var isNull = function isNull(node) {
  19665. return node.type === "NullLiteral" || node.type === "Literal" && node.value === null;
  19666. };
  19667. parts.push(" ? ", isNull(consequentNode) ? path$$1.call(print, operatorOptions.consequentNodePropertyName) : wrap(path$$1.call(print, operatorOptions.consequentNodePropertyName)), " : ", alternateNode.type === operatorOptions.conditionalNodeType || isNull(alternateNode) ? path$$1.call(print, operatorOptions.alternateNodePropertyName) : wrap(path$$1.call(print, operatorOptions.alternateNodePropertyName)));
  19668. } else {
  19669. // normal mode
  19670. var part = concat$4([line$3, "? ", consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$1("", "(") : "", align$1(2, path$$1.call(print, operatorOptions.consequentNodePropertyName)), consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$1("", ")") : "", line$3, ": ", alternateNode.type === operatorOptions.conditionalNodeType ? path$$1.call(print, operatorOptions.alternateNodePropertyName) : align$1(2, path$$1.call(print, operatorOptions.alternateNodePropertyName))]);
  19671. parts.push(parent.type !== operatorOptions.conditionalNodeType || parent[operatorOptions.alternateNodePropertyName] === node ? part : options.useTabs ? dedent$2(indent$2(part)) : align$1(Math.max(0, options.tabWidth - 2), part));
  19672. } // We want a whole chain of ConditionalExpressions to all
  19673. // break if any of them break. That means we should only group around the
  19674. // outer-most ConditionalExpression.
  19675. var maybeGroup = function maybeGroup(doc$$2) {
  19676. return operatorOptions.breakNested ? parent === firstNonConditionalParent ? group$1(doc$$2) : doc$$2 : group$1(doc$$2);
  19677. }; // Break the closing paren to keep the chain right after it:
  19678. // (a
  19679. // ? b
  19680. // : c
  19681. // ).call()
  19682. var breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && !parent.computed;
  19683. return maybeGroup(concat$4([].concat(function (testDoc) {
  19684. return (
  19685. /**
  19686. * a
  19687. * ? b
  19688. * : multiline
  19689. * test
  19690. * node
  19691. * ^^ align(2)
  19692. * ? d
  19693. * : e
  19694. */
  19695. parent.type === operatorOptions.conditionalNodeType && parent[operatorOptions.alternateNodePropertyName] === node ? align$1(2, testDoc) : testDoc
  19696. );
  19697. }(concat$4(operatorOptions.beforeParts())), forceNoIndent ? concat$4(parts) : indent$2(concat$4(parts)), operatorOptions.afterParts(breakClosingParen))));
  19698. }
  19699. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  19700. if (tokenNode === "+") {
  19701. return "+" + keyword;
  19702. } else if (tokenNode === "-") {
  19703. return "-" + keyword;
  19704. }
  19705. return keyword;
  19706. }
  19707. function printPathNoParens(path$$1, options, print, args) {
  19708. var n = path$$1.getValue();
  19709. var semi = options.semi ? ";" : "";
  19710. if (!n) {
  19711. return "";
  19712. }
  19713. if (typeof n === "string") {
  19714. return n;
  19715. }
  19716. var htmlBinding$$1 = printHtmlBinding(path$$1, options, print);
  19717. if (htmlBinding$$1) {
  19718. return htmlBinding$$1;
  19719. }
  19720. var parts = [];
  19721. switch (n.type) {
  19722. case "JsExpressionRoot":
  19723. return path$$1.call(print, "node");
  19724. case "JsonRoot":
  19725. return concat$4([path$$1.call(print, "node"), hardline$3]);
  19726. case "File":
  19727. // Print @babel/parser's InterpreterDirective here so that
  19728. // leading comments on the `Program` node get printed after the hashbang.
  19729. if (n.program && n.program.interpreter) {
  19730. parts.push(path$$1.call(function (programPath) {
  19731. return programPath.call(print, "interpreter");
  19732. }, "program"));
  19733. }
  19734. parts.push(path$$1.call(print, "program"));
  19735. return concat$4(parts);
  19736. case "Program":
  19737. // Babel 6
  19738. if (n.directives) {
  19739. path$$1.each(function (childPath) {
  19740. parts.push(print(childPath), semi, hardline$3);
  19741. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  19742. parts.push(hardline$3);
  19743. }
  19744. }, "directives");
  19745. }
  19746. parts.push(path$$1.call(function (bodyPath) {
  19747. return printStatementSequence(bodyPath, options, print);
  19748. }, "body"));
  19749. parts.push(comments.printDanglingComments(path$$1, options,
  19750. /* sameIndent */
  19751. true)); // Only force a trailing newline if there were any contents.
  19752. if (n.body.length || n.comments) {
  19753. parts.push(hardline$3);
  19754. }
  19755. return concat$4(parts);
  19756. // Babel extension.
  19757. case "EmptyStatement":
  19758. return "";
  19759. case "ExpressionStatement":
  19760. // Detect Flow-parsed directives
  19761. if (n.directive) {
  19762. return concat$4([nodeStr(n.expression, options, true), semi]);
  19763. }
  19764. if (options.parser === "__vue_event_binding") {
  19765. var parent = path$$1.getParentNode();
  19766. if (parent.type === "Program" && parent.body.length === 1 && parent.body[0] === n) {
  19767. return concat$4([path$$1.call(print, "expression"), isVueEventBindingExpression(n.expression) ? ";" : ""]);
  19768. }
  19769. } // Do not append semicolon after the only JSX element in a program
  19770. return concat$4([path$$1.call(print, "expression"), isTheOnlyJSXElementInMarkdown(options, path$$1) ? "" : semi]);
  19771. // Babel extension.
  19772. case "ParenthesizedExpression":
  19773. return concat$4(["(", path$$1.call(print, "expression"), ")"]);
  19774. case "AssignmentExpression":
  19775. return printAssignment(n.left, path$$1.call(print, "left"), concat$4([" ", n.operator]), n.right, path$$1.call(print, "right"), options);
  19776. case "BinaryExpression":
  19777. case "LogicalExpression":
  19778. case "NGPipeExpression":
  19779. {
  19780. var _parent = path$$1.getParentNode();
  19781. var parentParent = path$$1.getParentNode(1);
  19782. var isInsideParenthesis = n !== _parent.body && (_parent.type === "IfStatement" || _parent.type === "WhileStatement" || _parent.type === "DoWhileStatement");
  19783. var _parts = printBinaryishExpressions(path$$1, print, options,
  19784. /* isNested */
  19785. false, isInsideParenthesis); // if (
  19786. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  19787. // ) {
  19788. //
  19789. // looks super weird, we want to break the children if the parent breaks
  19790. //
  19791. // if (
  19792. // this.hasPlugin("dynamicImports") &&
  19793. // this.lookahead().type === tt.parenLeft
  19794. // ) {
  19795. if (isInsideParenthesis) {
  19796. return concat$4(_parts);
  19797. } // Break between the parens in unaries or in a member expression, i.e.
  19798. //
  19799. // (
  19800. // a &&
  19801. // b &&
  19802. // c
  19803. // ).call()
  19804. if (_parent.type === "UnaryExpression" || (_parent.type === "MemberExpression" || _parent.type === "OptionalMemberExpression") && !_parent.computed) {
  19805. return group$1(concat$4([indent$2(concat$4([softline$1, concat$4(_parts)])), softline$1]));
  19806. } // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  19807. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  19808. var shouldNotIndent = _parent.type === "ReturnStatement" || _parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n.type !== "NGPipeExpression" && (_parent.type === "NGRoot" && options.parser === "__ng_binding" || _parent.type === "NGMicrosyntaxExpression" && parentParent.type === "NGMicrosyntax" && parentParent.body.length === 1) || n === _parent.body && _parent.type === "ArrowFunctionExpression" || n !== _parent.body && _parent.type === "ForStatement" || _parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement" && parentParent.type !== "CallExpression";
  19809. var shouldIndentIfInlining = _parent.type === "AssignmentExpression" || _parent.type === "VariableDeclarator" || _parent.type === "ClassProperty" || _parent.type === "TSAbstractClassProperty" || _parent.type === "ClassPrivateProperty" || _parent.type === "ObjectProperty" || _parent.type === "Property";
  19810. var samePrecedenceSubExpression = isBinaryish(n.left) && shouldFlatten$1(n.operator, n.left.operator);
  19811. if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
  19812. return group$1(concat$4(_parts));
  19813. }
  19814. if (_parts.length === 0) {
  19815. return "";
  19816. } // If the right part is a JSX node, we include it in a separate group to
  19817. // prevent it breaking the whole chain, so we can print the expression like:
  19818. //
  19819. // foo && bar && (
  19820. // <Foo>
  19821. // <Bar />
  19822. // </Foo>
  19823. // )
  19824. var hasJSX = isJSXNode(n.right);
  19825. var rest = concat$4(hasJSX ? _parts.slice(1, -1) : _parts.slice(1));
  19826. var groupId = Symbol("logicalChain-" + ++uid);
  19827. var chain = group$1(concat$4([// Don't include the initial expression in the indentation
  19828. // level. The first item is guaranteed to be the first
  19829. // left-most expression.
  19830. _parts.length > 0 ? _parts[0] : "", indent$2(rest)]), {
  19831. id: groupId
  19832. });
  19833. if (!hasJSX) {
  19834. return chain;
  19835. }
  19836. var jsxPart = getLast$3(_parts);
  19837. return group$1(concat$4([chain, ifBreak$1(indent$2(jsxPart), jsxPart, {
  19838. groupId
  19839. })]));
  19840. }
  19841. case "AssignmentPattern":
  19842. return concat$4([path$$1.call(print, "left"), " = ", path$$1.call(print, "right")]);
  19843. case "TSTypeAssertion":
  19844. {
  19845. var shouldBreakAfterCast = !(n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression");
  19846. var castGroup = group$1(concat$4(["<", indent$2(concat$4([softline$1, path$$1.call(print, "typeAnnotation")])), softline$1, ">"]));
  19847. var exprContents = concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, ifBreak$1(")")]);
  19848. if (shouldBreakAfterCast) {
  19849. return conditionalGroup$1([concat$4([castGroup, path$$1.call(print, "expression")]), concat$4([castGroup, group$1(exprContents, {
  19850. shouldBreak: true
  19851. })]), concat$4([castGroup, path$$1.call(print, "expression")])]);
  19852. }
  19853. return group$1(concat$4([castGroup, path$$1.call(print, "expression")]));
  19854. }
  19855. case "OptionalMemberExpression":
  19856. case "MemberExpression":
  19857. {
  19858. var _parent2 = path$$1.getParentNode();
  19859. var firstNonMemberParent;
  19860. var i = 0;
  19861. do {
  19862. firstNonMemberParent = path$$1.getParentNode(i);
  19863. i++;
  19864. } while (firstNonMemberParent && (firstNonMemberParent.type === "MemberExpression" || firstNonMemberParent.type === "OptionalMemberExpression" || firstNonMemberParent.type === "TSNonNullExpression"));
  19865. var shouldInline = firstNonMemberParent && (firstNonMemberParent.type === "NewExpression" || firstNonMemberParent.type === "BindExpression" || firstNonMemberParent.type === "VariableDeclarator" && firstNonMemberParent.id.type !== "Identifier" || firstNonMemberParent.type === "AssignmentExpression" && firstNonMemberParent.left.type !== "Identifier") || n.computed || n.object.type === "Identifier" && n.property.type === "Identifier" && _parent2.type !== "MemberExpression" && _parent2.type !== "OptionalMemberExpression";
  19866. 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)])))]);
  19867. }
  19868. case "MetaProperty":
  19869. return concat$4([path$$1.call(print, "meta"), ".", path$$1.call(print, "property")]);
  19870. case "BindExpression":
  19871. if (n.object) {
  19872. parts.push(path$$1.call(print, "object"));
  19873. }
  19874. parts.push(group$1(indent$2(concat$4([softline$1, printBindExpressionCallee(path$$1, options, print)]))));
  19875. return concat$4(parts);
  19876. case "Identifier":
  19877. {
  19878. return concat$4([n.name, printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print)]);
  19879. }
  19880. case "SpreadElement":
  19881. case "SpreadElementPattern":
  19882. case "RestProperty":
  19883. case "SpreadProperty":
  19884. case "SpreadPropertyPattern":
  19885. case "RestElement":
  19886. case "ObjectTypeSpreadProperty":
  19887. return concat$4(["...", path$$1.call(print, "argument"), printTypeAnnotation(path$$1, options, print)]);
  19888. case "FunctionDeclaration":
  19889. case "FunctionExpression":
  19890. parts.push(printFunctionDeclaration(path$$1, print, options));
  19891. if (!n.body) {
  19892. parts.push(semi);
  19893. }
  19894. return concat$4(parts);
  19895. case "ArrowFunctionExpression":
  19896. {
  19897. if (n.async) {
  19898. parts.push("async ");
  19899. }
  19900. if (shouldPrintParamsWithoutParens(path$$1, options)) {
  19901. parts.push(path$$1.call(print, "params", 0));
  19902. } else {
  19903. parts.push(group$1(concat$4([printFunctionParams(path$$1, print, options,
  19904. /* expandLast */
  19905. args && (args.expandLastArg || args.expandFirstArg),
  19906. /* printTypeParams */
  19907. true), printReturnType(path$$1, print, options)])));
  19908. }
  19909. var dangling = comments.printDanglingComments(path$$1, options,
  19910. /* sameIndent */
  19911. true, function (comment) {
  19912. var nextCharacter = getNextNonSpaceNonCommentCharacterIndex$2(options.originalText, comment, options);
  19913. return options.originalText.substr(nextCharacter, 2) === "=>";
  19914. });
  19915. if (dangling) {
  19916. parts.push(" ", dangling);
  19917. }
  19918. parts.push(" =>");
  19919. var body = path$$1.call(function (bodyPath) {
  19920. return print(bodyPath, args);
  19921. }, "body"); // We want to always keep these types of nodes on the same line
  19922. // as the arrow.
  19923. 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")) {
  19924. return group$1(concat$4([concat$4(parts), " ", body]));
  19925. } // We handle sequence expressions as the body of arrows specially,
  19926. // so that the required parentheses end up on their own lines.
  19927. if (n.body.type === "SequenceExpression") {
  19928. return group$1(concat$4([concat$4(parts), group$1(concat$4([" (", indent$2(concat$4([softline$1, body])), softline$1, ")"]))]));
  19929. } // if the arrow function is expanded as last argument, we are adding a
  19930. // level of indentation and need to add a softline to align the closing )
  19931. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  19932. // we should align the expression's closing } with the line with the opening {.
  19933. var shouldAddSoftLine = (args && args.expandLastArg || path$$1.getParentNode().type === "JSXExpressionContainer") && !(n.comments && n.comments.length);
  19934. var printTrailingComma = args && args.expandLastArg && shouldPrintComma(options, "all"); // In order to avoid confusion between
  19935. // a => a ? a : a
  19936. // a <= a ? a : a
  19937. var shouldAddParens = n.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken$1(n.body,
  19938. /* forbidFunctionAndClass */
  19939. false);
  19940. 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]) : ""]))]));
  19941. }
  19942. case "MethodDefinition":
  19943. case "TSAbstractMethodDefinition":
  19944. if (n.decorators && n.decorators.length !== 0) {
  19945. parts.push(printDecorators(path$$1, options, print));
  19946. }
  19947. if (n.accessibility) {
  19948. parts.push(n.accessibility + " ");
  19949. }
  19950. if (n.static) {
  19951. parts.push("static ");
  19952. }
  19953. if (n.type === "TSAbstractMethodDefinition") {
  19954. parts.push("abstract ");
  19955. }
  19956. parts.push(printMethod(path$$1, options, print));
  19957. return concat$4(parts);
  19958. case "YieldExpression":
  19959. parts.push("yield");
  19960. if (n.delegate) {
  19961. parts.push("*");
  19962. }
  19963. if (n.argument) {
  19964. parts.push(" ", path$$1.call(print, "argument"));
  19965. }
  19966. return concat$4(parts);
  19967. case "AwaitExpression":
  19968. return concat$4(["await ", path$$1.call(print, "argument")]);
  19969. case "ImportSpecifier":
  19970. if (n.importKind) {
  19971. parts.push(path$$1.call(print, "importKind"), " ");
  19972. }
  19973. parts.push(path$$1.call(print, "imported"));
  19974. if (n.local && n.local.name !== n.imported.name) {
  19975. parts.push(" as ", path$$1.call(print, "local"));
  19976. }
  19977. return concat$4(parts);
  19978. case "ExportSpecifier":
  19979. parts.push(path$$1.call(print, "local"));
  19980. if (n.exported && n.exported.name !== n.local.name) {
  19981. parts.push(" as ", path$$1.call(print, "exported"));
  19982. }
  19983. return concat$4(parts);
  19984. case "ImportNamespaceSpecifier":
  19985. parts.push("* as ");
  19986. parts.push(path$$1.call(print, "local"));
  19987. return concat$4(parts);
  19988. case "ImportDefaultSpecifier":
  19989. return path$$1.call(print, "local");
  19990. case "TSExportAssignment":
  19991. return concat$4(["export = ", path$$1.call(print, "expression"), semi]);
  19992. case "ExportDefaultDeclaration":
  19993. case "ExportNamedDeclaration":
  19994. return printExportDeclaration(path$$1, options, print);
  19995. case "ExportAllDeclaration":
  19996. parts.push("export ");
  19997. if (n.exportKind === "type") {
  19998. parts.push("type ");
  19999. }
  20000. parts.push("* from ", path$$1.call(print, "source"), semi);
  20001. return concat$4(parts);
  20002. case "ExportNamespaceSpecifier":
  20003. case "ExportDefaultSpecifier":
  20004. return path$$1.call(print, "exported");
  20005. case "ImportDeclaration":
  20006. {
  20007. parts.push("import ");
  20008. if (n.importKind && n.importKind !== "value") {
  20009. parts.push(n.importKind + " ");
  20010. }
  20011. var standalones = [];
  20012. var grouped = [];
  20013. if (n.specifiers && n.specifiers.length > 0) {
  20014. path$$1.each(function (specifierPath) {
  20015. var value = specifierPath.getValue();
  20016. if (value.type === "ImportDefaultSpecifier" || value.type === "ImportNamespaceSpecifier") {
  20017. standalones.push(print(specifierPath));
  20018. } else {
  20019. grouped.push(print(specifierPath));
  20020. }
  20021. }, "specifiers");
  20022. if (standalones.length > 0) {
  20023. parts.push(join$2(", ", standalones));
  20024. }
  20025. if (standalones.length > 0 && grouped.length > 0) {
  20026. parts.push(", ");
  20027. }
  20028. if (grouped.length === 1 && standalones.length === 0 && n.specifiers && !n.specifiers.some(function (node) {
  20029. return node.comments;
  20030. })) {
  20031. parts.push(concat$4(["{", options.bracketSpacing ? " " : "", concat$4(grouped), options.bracketSpacing ? " " : "", "}"]));
  20032. } else if (grouped.length >= 1) {
  20033. 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, "}"])));
  20034. }
  20035. parts.push(" from ");
  20036. } else if (n.importKind && n.importKind === "type" || // import {} from 'x'
  20037. /{\s*}/.test(options.originalText.slice(options.locStart(n), options.locStart(n.source)))) {
  20038. parts.push("{} from ");
  20039. }
  20040. parts.push(path$$1.call(print, "source"), semi);
  20041. return concat$4(parts);
  20042. }
  20043. case "Import":
  20044. return "import";
  20045. case "TSModuleBlock":
  20046. case "BlockStatement":
  20047. {
  20048. var naked = path$$1.call(function (bodyPath) {
  20049. return printStatementSequence(bodyPath, options, print);
  20050. }, "body");
  20051. var hasContent = n.body.find(function (node) {
  20052. return node.type !== "EmptyStatement";
  20053. });
  20054. var hasDirectives = n.directives && n.directives.length > 0;
  20055. var _parent3 = path$$1.getParentNode();
  20056. var _parentParent = path$$1.getParentNode(1);
  20057. if (!hasContent && !hasDirectives && !hasDanglingComments(n) && (_parent3.type === "ArrowFunctionExpression" || _parent3.type === "FunctionExpression" || _parent3.type === "FunctionDeclaration" || _parent3.type === "ObjectMethod" || _parent3.type === "ClassMethod" || _parent3.type === "ClassPrivateMethod" || _parent3.type === "ForStatement" || _parent3.type === "WhileStatement" || _parent3.type === "DoWhileStatement" || _parent3.type === "DoExpression" || _parent3.type === "CatchClause" && !_parentParent.finalizer || _parent3.type === "TSModuleDeclaration")) {
  20058. return "{}";
  20059. }
  20060. parts.push("{"); // Babel 6
  20061. if (hasDirectives) {
  20062. path$$1.each(function (childPath) {
  20063. parts.push(indent$2(concat$4([hardline$3, print(childPath), semi])));
  20064. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  20065. parts.push(hardline$3);
  20066. }
  20067. }, "directives");
  20068. }
  20069. if (hasContent) {
  20070. parts.push(indent$2(concat$4([hardline$3, naked])));
  20071. }
  20072. parts.push(comments.printDanglingComments(path$$1, options));
  20073. parts.push(hardline$3, "}");
  20074. return concat$4(parts);
  20075. }
  20076. case "ReturnStatement":
  20077. parts.push("return");
  20078. if (n.argument) {
  20079. if (returnArgumentHasLeadingComment(options, n.argument)) {
  20080. parts.push(concat$4([" (", indent$2(concat$4([hardline$3, path$$1.call(print, "argument")])), hardline$3, ")"]));
  20081. } else if (n.argument.type === "LogicalExpression" || n.argument.type === "BinaryExpression" || n.argument.type === "SequenceExpression") {
  20082. parts.push(group$1(concat$4([ifBreak$1(" (", " "), indent$2(concat$4([softline$1, path$$1.call(print, "argument")])), softline$1, ifBreak$1(")")])));
  20083. } else {
  20084. parts.push(" ", path$$1.call(print, "argument"));
  20085. }
  20086. }
  20087. if (hasDanglingComments(n)) {
  20088. parts.push(" ", comments.printDanglingComments(path$$1, options,
  20089. /* sameIndent */
  20090. true));
  20091. }
  20092. parts.push(semi);
  20093. return concat$4(parts);
  20094. case "NewExpression":
  20095. case "OptionalCallExpression":
  20096. case "CallExpression":
  20097. {
  20098. var isNew = n.type === "NewExpression";
  20099. var optional = printOptionalToken(path$$1);
  20100. if ( // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  20101. // define calls, as a unit.
  20102. // e.g. `define(["some/lib", (lib) => {`
  20103. !isNew && n.callee.type === "Identifier" && (n.callee.name === "require" || n.callee.name === "define") || // Template literals as single arguments
  20104. n.arguments.length === 1 && isTemplateOnItsOwnLine(n.arguments[0], options.originalText, options) || // Keep test declarations on a single line
  20105. // e.g. `it('long name', () => {`
  20106. !isNew && isTestCall(n, path$$1.getParentNode())) {
  20107. 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")), ")"])]);
  20108. } // Inline Flow annotation comments following Identifiers in Call nodes need to
  20109. // stay with the Identifier. For example:
  20110. //
  20111. // foo /*:: <SomeGeneric> */(bar);
  20112. //
  20113. // Here, we ensure that such comments stay between the Identifier and the Callee.
  20114. var isIdentifierWithFlowAnnotation = n.callee.type === "Identifier" && hasFlowAnnotationComment(n.callee.trailingComments);
  20115. if (isIdentifierWithFlowAnnotation) {
  20116. n.callee.trailingComments[0].printed = true;
  20117. } // We detect calls on member lookups and possibly print them in a
  20118. // special chain format. See `printMemberChain` for more info.
  20119. if (!isNew && isMemberish(n.callee)) {
  20120. return printMemberChain(path$$1, options, print);
  20121. }
  20122. return concat$4([isNew ? "new " : "", path$$1.call(print, "callee"), optional, isIdentifierWithFlowAnnotation ? `/*:: ${n.callee.trailingComments[0].value.substring(2).trim()} */` : "", printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
  20123. }
  20124. case "TSInterfaceDeclaration":
  20125. if (isNodeStartingWithDeclare(n, options)) {
  20126. parts.push("declare ");
  20127. }
  20128. parts.push(n.abstract ? "abstract " : "", printTypeScriptModifiers(path$$1, options, print), "interface ", path$$1.call(print, "id"), n.typeParameters ? path$$1.call(print, "typeParameters") : "", " ");
  20129. if (n.extends && n.extends.length) {
  20130. parts.push(group$1(indent$2(concat$4([softline$1, "extends ", (n.extends.length === 1 ? identity$1 : indent$2)(join$2(concat$4([",", line$3]), path$$1.map(print, "extends"))), " "]))));
  20131. }
  20132. parts.push(path$$1.call(print, "body"));
  20133. return concat$4(parts);
  20134. case "ObjectTypeInternalSlot":
  20135. return concat$4([n.static ? "static " : "", "[[", path$$1.call(print, "id"), "]]", printOptionalToken(path$$1), n.method ? "" : ": ", path$$1.call(print, "value")]);
  20136. case "ObjectExpression":
  20137. case "ObjectPattern":
  20138. case "ObjectTypeAnnotation":
  20139. case "TSInterfaceBody":
  20140. case "TSTypeLiteral":
  20141. {
  20142. var propertiesField;
  20143. if (n.type === "TSTypeLiteral") {
  20144. propertiesField = "members";
  20145. } else if (n.type === "TSInterfaceBody") {
  20146. propertiesField = "body";
  20147. } else {
  20148. propertiesField = "properties";
  20149. }
  20150. var isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  20151. var fields = [];
  20152. if (isTypeAnnotation) {
  20153. fields.push("indexers", "callProperties", "internalSlots");
  20154. }
  20155. fields.push(propertiesField);
  20156. var firstProperty = fields.map(function (field) {
  20157. return n[field][0];
  20158. }).sort(function (a, b) {
  20159. return options.locStart(a) - options.locStart(b);
  20160. })[0];
  20161. var _parent4 = path$$1.getParentNode(0);
  20162. var isFlowInterfaceLikeBody = isTypeAnnotation && _parent4 && (_parent4.type === "InterfaceDeclaration" || _parent4.type === "DeclareInterface" || _parent4.type === "DeclareClass") && path$$1.getName() === "body";
  20163. var shouldBreak = n.type === "TSInterfaceBody" || isFlowInterfaceLikeBody || n.type === "ObjectPattern" && _parent4.type !== "FunctionDeclaration" && _parent4.type !== "FunctionExpression" && _parent4.type !== "ArrowFunctionExpression" && _parent4.type !== "AssignmentPattern" && _parent4.type !== "CatchClause" && n.properties.some(function (property) {
  20164. return property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern");
  20165. }) || n.type !== "ObjectPattern" && firstProperty && hasNewlineInRange$1(options.originalText, options.locStart(n), options.locStart(firstProperty));
  20166. var separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" ? ifBreak$1(semi, ";") : ",";
  20167. var leftBrace = n.exact ? "{|" : "{";
  20168. var rightBrace = n.exact ? "|}" : "}"; // Unfortunately, things are grouped together in the ast can be
  20169. // interleaved in the source code. So we need to reorder them before
  20170. // printing them.
  20171. var propsAndLoc = [];
  20172. fields.forEach(function (field) {
  20173. path$$1.each(function (childPath) {
  20174. var node = childPath.getValue();
  20175. propsAndLoc.push({
  20176. node: node,
  20177. printed: print(childPath),
  20178. loc: options.locStart(node)
  20179. });
  20180. }, field);
  20181. });
  20182. var separatorParts = [];
  20183. var props = propsAndLoc.sort(function (a, b) {
  20184. return a.loc - b.loc;
  20185. }).map(function (prop) {
  20186. var result = concat$4(separatorParts.concat(group$1(prop.printed)));
  20187. separatorParts = [separator, line$3];
  20188. if ((prop.node.type === "TSPropertySignature" || prop.node.type === "TSMethodSignature" || prop.node.type === "TSConstructSignatureDeclaration") && hasNodeIgnoreComment$1(prop.node)) {
  20189. separatorParts.shift();
  20190. }
  20191. if (isNextLineEmpty$2(options.originalText, prop.node, options)) {
  20192. separatorParts.push(hardline$3);
  20193. }
  20194. return result;
  20195. });
  20196. if (n.inexact) {
  20197. props.push(concat$4(separatorParts.concat(group$1("..."))));
  20198. }
  20199. var lastElem = getLast$3(n[propertiesField]);
  20200. var canHaveTrailingSeparator = !(lastElem && (lastElem.type === "RestProperty" || lastElem.type === "RestElement" || hasNodeIgnoreComment$1(lastElem) || n.inexact));
  20201. var content;
  20202. if (props.length === 0 && !n.typeAnnotation) {
  20203. if (!hasDanglingComments(n)) {
  20204. return concat$4([leftBrace, rightBrace]);
  20205. }
  20206. content = group$1(concat$4([leftBrace, comments.printDanglingComments(path$$1, options), softline$1, rightBrace, printOptionalToken(path$$1)]));
  20207. } else {
  20208. 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)]);
  20209. } // If we inline the object as first argument of the parent, we don't want
  20210. // to create another group so that the object breaks before the return
  20211. // type
  20212. var parentParentParent = path$$1.getParentNode(2);
  20213. if (n.type === "ObjectPattern" && _parent4 && shouldHugArguments(_parent4) && _parent4.params[0] === n || shouldHugType(n) && parentParentParent && shouldHugArguments(parentParentParent) && parentParentParent.params[0].typeAnnotation && parentParentParent.params[0].typeAnnotation.typeAnnotation === n) {
  20214. return content;
  20215. }
  20216. return group$1(content, {
  20217. shouldBreak
  20218. });
  20219. }
  20220. // Babel 6
  20221. case "ObjectProperty": // Non-standard AST node type.
  20222. case "Property":
  20223. if (n.method || n.kind === "get" || n.kind === "set") {
  20224. return printMethod(path$$1, options, print);
  20225. }
  20226. if (n.shorthand) {
  20227. parts.push(path$$1.call(print, "value"));
  20228. } else {
  20229. var printedLeft;
  20230. if (n.computed) {
  20231. printedLeft = concat$4(["[", path$$1.call(print, "key"), "]"]);
  20232. } else {
  20233. printedLeft = printPropertyKey(path$$1, options, print);
  20234. }
  20235. parts.push(printAssignment(n.key, printedLeft, ":", n.value, path$$1.call(print, "value"), options));
  20236. }
  20237. return concat$4(parts);
  20238. // Babel 6
  20239. case "ClassMethod":
  20240. case "ClassPrivateMethod":
  20241. if (n.decorators && n.decorators.length !== 0) {
  20242. parts.push(printDecorators(path$$1, options, print));
  20243. }
  20244. if (n.static) {
  20245. parts.push("static ");
  20246. }
  20247. parts = parts.concat(printObjectMethod(path$$1, options, print));
  20248. return concat$4(parts);
  20249. // Babel 6
  20250. case "ObjectMethod":
  20251. return printObjectMethod(path$$1, options, print);
  20252. case "Decorator":
  20253. return concat$4(["@", path$$1.call(print, "expression"), path$$1.call(print, "callee")]);
  20254. case "ArrayExpression":
  20255. case "ArrayPattern":
  20256. if (n.elements.length === 0) {
  20257. if (!hasDanglingComments(n)) {
  20258. parts.push("[]");
  20259. } else {
  20260. parts.push(group$1(concat$4(["[", comments.printDanglingComments(path$$1, options), softline$1, "]"])));
  20261. }
  20262. } else {
  20263. var _lastElem = getLast$3(n.elements);
  20264. var canHaveTrailingComma = !(_lastElem && _lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which
  20265. // changes its length based on the number of commas. The algorithm
  20266. // is that if the last argument is null, we need to force insert
  20267. // a comma to ensure JavaScript recognizes it.
  20268. // [,].length === 1
  20269. // [1,].length === 1
  20270. // [1,,].length === 2
  20271. //
  20272. // Note that getLast returns null if the array is empty, but
  20273. // we already check for an empty array just above so we are safe
  20274. var needsForcedTrailingComma = canHaveTrailingComma && _lastElem === null;
  20275. 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,
  20276. /* sameIndent */
  20277. true), softline$1, "]"])));
  20278. }
  20279. parts.push(printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print));
  20280. return concat$4(parts);
  20281. case "SequenceExpression":
  20282. {
  20283. var _parent5 = path$$1.getParentNode(0);
  20284. if (_parent5.type === "ExpressionStatement" || _parent5.type === "ForStatement") {
  20285. // For ExpressionStatements and for-loop heads, which are among
  20286. // the few places a SequenceExpression appears unparenthesized, we want
  20287. // to indent expressions after the first.
  20288. var _parts2 = [];
  20289. path$$1.each(function (p) {
  20290. if (p.getName() === 0) {
  20291. _parts2.push(print(p));
  20292. } else {
  20293. _parts2.push(",", indent$2(concat$4([line$3, print(p)])));
  20294. }
  20295. }, "expressions");
  20296. return group$1(concat$4(_parts2));
  20297. }
  20298. return group$1(concat$4([join$2(concat$4([",", line$3]), path$$1.map(print, "expressions"))]));
  20299. }
  20300. case "ThisExpression":
  20301. return "this";
  20302. case "Super":
  20303. return "super";
  20304. case "NullLiteral":
  20305. // Babel 6 Literal split
  20306. return "null";
  20307. case "RegExpLiteral":
  20308. // Babel 6 Literal split
  20309. return printRegex(n);
  20310. case "NumericLiteral":
  20311. // Babel 6 Literal split
  20312. return printNumber$1(n.extra.raw);
  20313. case "BigIntLiteral":
  20314. return concat$4([printNumber$1(n.extra ? n.extra.rawValue : // TypeScript
  20315. n.value), "n"]);
  20316. case "BooleanLiteral": // Babel 6 Literal split
  20317. case "StringLiteral": // Babel 6 Literal split
  20318. case "Literal":
  20319. {
  20320. if (n.regex) {
  20321. return printRegex(n.regex);
  20322. }
  20323. if (typeof n.value === "number") {
  20324. return printNumber$1(n.raw);
  20325. }
  20326. if (typeof n.value !== "string") {
  20327. return "" + n.value;
  20328. } // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  20329. // See corresponding workaround in needs-parens.js
  20330. var grandParent = path$$1.getParentNode(1);
  20331. var isTypeScriptDirective = options.parser === "typescript" && typeof n.value === "string" && grandParent && (grandParent.type === "Program" || grandParent.type === "BlockStatement");
  20332. return nodeStr(n, options, isTypeScriptDirective);
  20333. }
  20334. case "Directive":
  20335. return path$$1.call(print, "value");
  20336. // Babel 6
  20337. case "DirectiveLiteral":
  20338. return nodeStr(n, options);
  20339. case "UnaryExpression":
  20340. parts.push(n.operator);
  20341. if (/[a-z]$/.test(n.operator)) {
  20342. parts.push(" ");
  20343. }
  20344. parts.push(path$$1.call(print, "argument"));
  20345. return concat$4(parts);
  20346. case "UpdateExpression":
  20347. parts.push(path$$1.call(print, "argument"), n.operator);
  20348. if (n.prefix) {
  20349. parts.reverse();
  20350. }
  20351. return concat$4(parts);
  20352. case "ConditionalExpression":
  20353. return printTernaryOperator(path$$1, options, print, {
  20354. beforeParts: function beforeParts() {
  20355. return [path$$1.call(print, "test")];
  20356. },
  20357. afterParts: function afterParts(breakClosingParen) {
  20358. return [breakClosingParen ? softline$1 : ""];
  20359. },
  20360. shouldCheckJsx: true,
  20361. conditionalNodeType: "ConditionalExpression",
  20362. consequentNodePropertyName: "consequent",
  20363. alternateNodePropertyName: "alternate",
  20364. testNodePropertyName: "test",
  20365. breakNested: true
  20366. });
  20367. case "VariableDeclaration":
  20368. {
  20369. var printed = path$$1.map(function (childPath) {
  20370. return print(childPath);
  20371. }, "declarations"); // We generally want to terminate all variable declarations with a
  20372. // semicolon, except when they in the () part of for loops.
  20373. var parentNode = path$$1.getParentNode();
  20374. var isParentForLoop = parentNode.type === "ForStatement" || parentNode.type === "ForInStatement" || parentNode.type === "ForOfStatement" || parentNode.type === "ForAwaitStatement";
  20375. var hasValue = n.declarations.some(function (decl) {
  20376. return decl.init;
  20377. });
  20378. var firstVariable;
  20379. if (printed.length === 1 && !n.declarations[0].comments) {
  20380. firstVariable = printed[0];
  20381. } else if (printed.length > 0) {
  20382. // Indent first var to comply with eslint one-var rule
  20383. firstVariable = indent$2(printed[0]);
  20384. }
  20385. parts = [isNodeStartingWithDeclare(n, options) ? "declare " : "", n.kind, firstVariable ? concat$4([" ", firstVariable]) : "", indent$2(concat$4(printed.slice(1).map(function (p) {
  20386. return concat$4([",", hasValue && !isParentForLoop ? hardline$3 : line$3, p]);
  20387. })))];
  20388. if (!(isParentForLoop && parentNode.body !== n)) {
  20389. parts.push(semi);
  20390. }
  20391. return group$1(concat$4(parts));
  20392. }
  20393. case "TSTypeAliasDeclaration":
  20394. {
  20395. if (n.declare) {
  20396. parts.push("declare ");
  20397. }
  20398. var _printed = printAssignmentRight(n.id, n.typeAnnotation, n.typeAnnotation && path$$1.call(print, "typeAnnotation"), options);
  20399. parts.push("type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"), " =", _printed, semi);
  20400. return group$1(concat$4(parts));
  20401. }
  20402. case "VariableDeclarator":
  20403. return printAssignment(n.id, path$$1.call(print, "id"), " =", n.init, n.init && path$$1.call(print, "init"), options);
  20404. case "WithStatement":
  20405. return group$1(concat$4(["with (", path$$1.call(print, "object"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  20406. case "IfStatement":
  20407. {
  20408. var con = adjustClause(n.consequent, path$$1.call(print, "consequent"));
  20409. 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]));
  20410. parts.push(opening);
  20411. if (n.alternate) {
  20412. var commentOnOwnLine = hasTrailingComment(n.consequent) && n.consequent.comments.some(function (comment) {
  20413. return comment.trailing && !comments$3.isBlockComment(comment);
  20414. }) || needsHardlineAfterDanglingComment(n);
  20415. var elseOnSameLine = n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  20416. parts.push(elseOnSameLine ? " " : hardline$3);
  20417. if (hasDanglingComments(n)) {
  20418. parts.push(comments.printDanglingComments(path$$1, options, true), commentOnOwnLine ? hardline$3 : " ");
  20419. }
  20420. parts.push("else", group$1(adjustClause(n.alternate, path$$1.call(print, "alternate"), n.alternate.type === "IfStatement")));
  20421. }
  20422. return concat$4(parts);
  20423. }
  20424. case "ForStatement":
  20425. {
  20426. var _body = adjustClause(n.body, path$$1.call(print, "body")); // We want to keep dangling comments above the loop to stay consistent.
  20427. // Any comment positioned between the for statement and the parentheses
  20428. // is going to be printed before the statement.
  20429. var _dangling = comments.printDanglingComments(path$$1, options,
  20430. /* sameLine */
  20431. true);
  20432. var printedComments = _dangling ? concat$4([_dangling, softline$1]) : "";
  20433. if (!n.init && !n.test && !n.update) {
  20434. return concat$4([printedComments, group$1(concat$4(["for (;;)", _body]))]);
  20435. }
  20436. 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]))]);
  20437. }
  20438. case "WhileStatement":
  20439. 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"))]));
  20440. case "ForInStatement":
  20441. // Note: esprima can't actually parse "for each (".
  20442. 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"))]));
  20443. case "ForOfStatement":
  20444. case "ForAwaitStatement":
  20445. {
  20446. // Babel 7 removed ForAwaitStatement in favor of ForOfStatement
  20447. // with `"await": true`:
  20448. // https://github.com/estree/estree/pull/138
  20449. var isAwait = n.type === "ForAwaitStatement" || n.await;
  20450. 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"))]));
  20451. }
  20452. case "DoWhileStatement":
  20453. {
  20454. var clause = adjustClause(n.body, path$$1.call(print, "body"));
  20455. var doBody = group$1(concat$4(["do", clause]));
  20456. parts = [doBody];
  20457. if (n.body.type === "BlockStatement") {
  20458. parts.push(" ");
  20459. } else {
  20460. parts.push(hardline$3);
  20461. }
  20462. parts.push("while (");
  20463. parts.push(group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", semi);
  20464. return concat$4(parts);
  20465. }
  20466. case "DoExpression":
  20467. return concat$4(["do ", path$$1.call(print, "body")]);
  20468. case "BreakStatement":
  20469. parts.push("break");
  20470. if (n.label) {
  20471. parts.push(" ", path$$1.call(print, "label"));
  20472. }
  20473. parts.push(semi);
  20474. return concat$4(parts);
  20475. case "ContinueStatement":
  20476. parts.push("continue");
  20477. if (n.label) {
  20478. parts.push(" ", path$$1.call(print, "label"));
  20479. }
  20480. parts.push(semi);
  20481. return concat$4(parts);
  20482. case "LabeledStatement":
  20483. if (n.body.type === "EmptyStatement") {
  20484. return concat$4([path$$1.call(print, "label"), ":;"]);
  20485. }
  20486. return concat$4([path$$1.call(print, "label"), ": ", path$$1.call(print, "body")]);
  20487. case "TryStatement":
  20488. 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")]) : ""]);
  20489. case "CatchClause":
  20490. if (n.param) {
  20491. var hasComments = n.param.comments && n.param.comments.some(function (comment) {
  20492. return !comments$3.isBlockComment(comment) || comment.leading && hasNewline$2(options.originalText, options.locEnd(comment)) || comment.trailing && hasNewline$2(options.originalText, options.locStart(comment), {
  20493. backwards: true
  20494. });
  20495. });
  20496. var param = path$$1.call(print, "param");
  20497. return concat$4(["catch ", hasComments ? concat$4(["(", indent$2(concat$4([softline$1, param])), softline$1, ") "]) : concat$4(["(", param, ") "]), path$$1.call(print, "body")]);
  20498. }
  20499. return concat$4(["catch ", path$$1.call(print, "body")]);
  20500. case "ThrowStatement":
  20501. return concat$4(["throw ", path$$1.call(print, "argument"), semi]);
  20502. // Note: ignoring n.lexical because it has no printing consequences.
  20503. case "SwitchStatement":
  20504. 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) {
  20505. var caseNode = casePath.getValue();
  20506. return concat$4([casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && isNextLineEmpty$2(options.originalText, caseNode, options) ? hardline$3 : ""]);
  20507. }, "cases"))])) : "", hardline$3, "}"]);
  20508. case "SwitchCase":
  20509. {
  20510. if (n.test) {
  20511. parts.push("case ", path$$1.call(print, "test"), ":");
  20512. } else {
  20513. parts.push("default:");
  20514. }
  20515. var consequent = n.consequent.filter(function (node) {
  20516. return node.type !== "EmptyStatement";
  20517. });
  20518. if (consequent.length > 0) {
  20519. var cons = path$$1.call(function (consequentPath) {
  20520. return printStatementSequence(consequentPath, options, print);
  20521. }, "consequent");
  20522. parts.push(consequent.length === 1 && consequent[0].type === "BlockStatement" ? concat$4([" ", cons]) : indent$2(concat$4([hardline$3, cons])));
  20523. }
  20524. return concat$4(parts);
  20525. }
  20526. // JSX extensions below.
  20527. case "DebuggerStatement":
  20528. return concat$4(["debugger", semi]);
  20529. case "JSXAttribute":
  20530. parts.push(path$$1.call(print, "name"));
  20531. if (n.value) {
  20532. var res;
  20533. if (isStringLiteral(n.value)) {
  20534. var raw = rawText(n.value); // Unescape all quotes so we get an accurate preferred quote
  20535. var final = raw.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  20536. var quote = getPreferredQuote$1(final, options.jsxSingleQuote ? "'" : '"');
  20537. var _escape = quote === "'" ? "&apos;" : "&quot;";
  20538. final = final.slice(1, -1).replace(new RegExp(quote, "g"), _escape);
  20539. res = concat$4([quote, final, quote]);
  20540. } else {
  20541. res = path$$1.call(print, "value");
  20542. }
  20543. parts.push("=", res);
  20544. }
  20545. return concat$4(parts);
  20546. case "JSXIdentifier":
  20547. return "" + n.name;
  20548. case "JSXNamespacedName":
  20549. return join$2(":", [path$$1.call(print, "namespace"), path$$1.call(print, "name")]);
  20550. case "JSXMemberExpression":
  20551. return join$2(".", [path$$1.call(print, "object"), path$$1.call(print, "property")]);
  20552. case "TSQualifiedName":
  20553. return join$2(".", [path$$1.call(print, "left"), path$$1.call(print, "right")]);
  20554. case "JSXSpreadAttribute":
  20555. case "JSXSpreadChild":
  20556. {
  20557. return concat$4(["{", path$$1.call(function (p) {
  20558. var printed = concat$4(["...", print(p)]);
  20559. var n = p.getValue();
  20560. if (!n.comments || !n.comments.length) {
  20561. return printed;
  20562. }
  20563. return concat$4([indent$2(concat$4([softline$1, comments.printComments(p, function () {
  20564. return printed;
  20565. }, options)])), softline$1]);
  20566. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), "}"]);
  20567. }
  20568. case "JSXExpressionContainer":
  20569. {
  20570. var _parent6 = path$$1.getParentNode(0);
  20571. var preventInline = _parent6.type === "JSXAttribute" && n.expression.comments && n.expression.comments.length > 0;
  20572. 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(_parent6) && (n.expression.type === "ConditionalExpression" || isBinaryish(n.expression)));
  20573. if (_shouldInline) {
  20574. return group$1(concat$4(["{", path$$1.call(print, "expression"), lineSuffixBoundary$1, "}"]));
  20575. }
  20576. return group$1(concat$4(["{", indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, lineSuffixBoundary$1, "}"]));
  20577. }
  20578. case "JSXFragment":
  20579. case "JSXElement":
  20580. {
  20581. var elem = comments.printComments(path$$1, function () {
  20582. return printJSXElement(path$$1, options, print);
  20583. }, options);
  20584. return maybeWrapJSXElementInParens(path$$1, elem);
  20585. }
  20586. case "JSXOpeningElement":
  20587. {
  20588. var _n = path$$1.getValue();
  20589. var nameHasComments = _n.name && _n.name.comments && _n.name.comments.length > 0; // Don't break self-closing elements with no attributes and no comments
  20590. if (_n.selfClosing && !_n.attributes.length && !nameHasComments) {
  20591. return concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " />"]);
  20592. } // don't break up opening elements with a single long text attribute
  20593. 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:
  20594. // <div
  20595. // // comment
  20596. // attr="value"
  20597. // >
  20598. // <div
  20599. // attr="value"
  20600. // // comment
  20601. // >
  20602. !nameHasComments && (!_n.attributes[0].comments || !_n.attributes[0].comments.length)) {
  20603. return group$1(concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " ", concat$4(path$$1.map(print, "attributes")), _n.selfClosing ? " />" : ">"]));
  20604. }
  20605. var lastAttrHasTrailingComments = _n.attributes.length && hasTrailingComment(getLast$3(_n.attributes));
  20606. var bracketSameLine = // Simple tags (no attributes and no comment in tag name) should be
  20607. // kept unbroken regardless of `jsxBracketSameLine`
  20608. !_n.attributes.length && !nameHasComments || options.jsxBracketSameLine && ( // We should print the bracket in a new line for the following cases:
  20609. // <div
  20610. // // comment
  20611. // >
  20612. // <div
  20613. // attr // comment
  20614. // >
  20615. !nameHasComments || _n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
  20616. // string literal with newlines
  20617. var _shouldBreak = _n.attributes && _n.attributes.some(function (attr) {
  20618. return attr.value && isStringLiteral(attr.value) && attr.value.value.includes("\n");
  20619. });
  20620. 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) {
  20621. return concat$4([line$3, print(attr)]);
  20622. }, "attributes"))), _n.selfClosing ? line$3 : bracketSameLine ? ">" : softline$1]), _n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
  20623. shouldBreak: _shouldBreak
  20624. });
  20625. }
  20626. case "JSXClosingElement":
  20627. return concat$4(["</", path$$1.call(print, "name"), ">"]);
  20628. case "JSXOpeningFragment":
  20629. case "JSXClosingFragment":
  20630. {
  20631. var hasComment = n.comments && n.comments.length;
  20632. var hasOwnLineComment = hasComment && !n.comments.every(comments$3.isBlockComment);
  20633. var isOpeningFragment = n.type === "JSXOpeningFragment";
  20634. return concat$4([isOpeningFragment ? "<" : "</", indent$2(concat$4([hasOwnLineComment ? hardline$3 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path$$1, options, true)])), hasOwnLineComment ? hardline$3 : "", ">"]);
  20635. }
  20636. case "JSXText":
  20637. /* istanbul ignore next */
  20638. throw new Error("JSXTest should be handled by JSXElement");
  20639. case "JSXEmptyExpression":
  20640. {
  20641. var requiresHardline = n.comments && !n.comments.every(comments$3.isBlockComment);
  20642. return concat$4([comments.printDanglingComments(path$$1, options,
  20643. /* sameIndent */
  20644. !requiresHardline), requiresHardline ? hardline$3 : ""]);
  20645. }
  20646. case "ClassBody":
  20647. if (!n.comments && n.body.length === 0) {
  20648. return "{}";
  20649. }
  20650. return concat$4(["{", n.body.length > 0 ? indent$2(concat$4([hardline$3, path$$1.call(function (bodyPath) {
  20651. return printStatementSequence(bodyPath, options, print);
  20652. }, "body")])) : comments.printDanglingComments(path$$1, options), hardline$3, "}"]);
  20653. case "ClassProperty":
  20654. case "TSAbstractClassProperty":
  20655. case "ClassPrivateProperty":
  20656. {
  20657. if (n.decorators && n.decorators.length !== 0) {
  20658. parts.push(printDecorators(path$$1, options, print));
  20659. }
  20660. if (n.accessibility) {
  20661. parts.push(n.accessibility + " ");
  20662. }
  20663. if (n.static) {
  20664. parts.push("static ");
  20665. }
  20666. if (n.type === "TSAbstractClassProperty") {
  20667. parts.push("abstract ");
  20668. }
  20669. if (n.readonly) {
  20670. parts.push("readonly ");
  20671. }
  20672. var variance = getFlowVariance(n);
  20673. if (variance) {
  20674. parts.push(variance);
  20675. }
  20676. if (n.computed) {
  20677. parts.push("[", path$$1.call(print, "key"), "]");
  20678. } else {
  20679. parts.push(printPropertyKey(path$$1, options, print));
  20680. }
  20681. parts.push(printOptionalToken(path$$1));
  20682. parts.push(printTypeAnnotation(path$$1, options, print));
  20683. if (n.value) {
  20684. parts.push(" =", printAssignmentRight(n.key, n.value, path$$1.call(print, "value"), options));
  20685. }
  20686. parts.push(semi);
  20687. return group$1(concat$4(parts));
  20688. }
  20689. case "ClassDeclaration":
  20690. case "ClassExpression":
  20691. if (isNodeStartingWithDeclare(n, options)) {
  20692. parts.push("declare ");
  20693. }
  20694. parts.push(concat$4(printClass(path$$1, options, print)));
  20695. return concat$4(parts);
  20696. case "TSInterfaceHeritage":
  20697. parts.push(path$$1.call(print, "expression"));
  20698. if (n.typeParameters) {
  20699. parts.push(path$$1.call(print, "typeParameters"));
  20700. }
  20701. return concat$4(parts);
  20702. case "TemplateElement":
  20703. return join$2(literalline$1, n.value.raw.split(/\r?\n/g));
  20704. case "TemplateLiteral":
  20705. {
  20706. var expressions = path$$1.map(print, "expressions");
  20707. var _parentNode = path$$1.getParentNode();
  20708. if (isJestEachTemplateLiteral(n, _parentNode)) {
  20709. var _printed2 = printJestEachTemplateLiteral(n, expressions, options);
  20710. if (_printed2) {
  20711. return _printed2;
  20712. }
  20713. }
  20714. var isSimple = isSimpleTemplateLiteral(n);
  20715. if (isSimple) {
  20716. expressions = expressions.map(function (doc$$2) {
  20717. return printDocToString$2(doc$$2, Object.assign({}, options, {
  20718. printWidth: Infinity
  20719. })).formatted;
  20720. });
  20721. }
  20722. parts.push("`");
  20723. path$$1.each(function (childPath) {
  20724. var i = childPath.getName();
  20725. parts.push(print(childPath));
  20726. if (i < expressions.length) {
  20727. // For a template literal of the following form:
  20728. // `someQuery {
  20729. // ${call({
  20730. // a,
  20731. // b,
  20732. // })}
  20733. // }`
  20734. // the expression is on its own line (there is a \n in the previous
  20735. // quasi literal), therefore we want to indent the JavaScript
  20736. // expression inside at the beginning of ${ instead of the beginning
  20737. // of the `.
  20738. var tabWidth = options.tabWidth;
  20739. var quasi = childPath.getValue();
  20740. var indentSize = getIndentSize$1(quasi.value.raw, tabWidth);
  20741. var _printed3 = expressions[i];
  20742. if (!isSimple) {
  20743. // Breaks at the template element boundaries (${ and }) are preferred to breaking
  20744. // in the middle of a MemberExpression
  20745. 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") {
  20746. _printed3 = concat$4([indent$2(concat$4([softline$1, _printed3])), softline$1]);
  20747. }
  20748. }
  20749. var aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$1(-Infinity, _printed3) : addAlignmentToDoc$2(_printed3, indentSize, tabWidth);
  20750. parts.push(group$1(concat$4(["${", aligned, lineSuffixBoundary$1, "}"])));
  20751. }
  20752. }, "quasis");
  20753. parts.push("`");
  20754. return concat$4(parts);
  20755. }
  20756. // These types are unprintable because they serve as abstract
  20757. // supertypes for other (printable) types.
  20758. case "TaggedTemplateExpression":
  20759. return concat$4([path$$1.call(print, "tag"), path$$1.call(print, "typeParameters"), path$$1.call(print, "quasi")]);
  20760. case "Node":
  20761. case "Printable":
  20762. case "SourceLocation":
  20763. case "Position":
  20764. case "Statement":
  20765. case "Function":
  20766. case "Pattern":
  20767. case "Expression":
  20768. case "Declaration":
  20769. case "Specifier":
  20770. case "NamedSpecifier":
  20771. case "Comment":
  20772. case "MemberTypeAnnotation": // Flow
  20773. case "Type":
  20774. /* istanbul ignore next */
  20775. throw new Error("unprintable type: " + JSON.stringify(n.type));
  20776. // Type Annotations for Facebook Flow, typically stripped out or
  20777. // transformed away before printing.
  20778. case "TypeAnnotation":
  20779. case "TSTypeAnnotation":
  20780. if (n.typeAnnotation) {
  20781. return path$$1.call(print, "typeAnnotation");
  20782. }
  20783. /* istanbul ignore next */
  20784. return "";
  20785. case "TSTupleType":
  20786. case "TupleTypeAnnotation":
  20787. {
  20788. var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  20789. return group$1(concat$4(["[", indent$2(concat$4([softline$1, printArrayItems(path$$1, options, typesField, print)])), ifBreak$1(shouldPrintComma(options, "all") ? "," : ""), comments.printDanglingComments(path$$1, options,
  20790. /* sameIndent */
  20791. true), softline$1, "]"]));
  20792. }
  20793. case "ExistsTypeAnnotation":
  20794. return "*";
  20795. case "EmptyTypeAnnotation":
  20796. return "empty";
  20797. case "AnyTypeAnnotation":
  20798. return "any";
  20799. case "MixedTypeAnnotation":
  20800. return "mixed";
  20801. case "ArrayTypeAnnotation":
  20802. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  20803. case "BooleanTypeAnnotation":
  20804. return "boolean";
  20805. case "BooleanLiteralTypeAnnotation":
  20806. return "" + n.value;
  20807. case "DeclareClass":
  20808. return printFlowDeclaration(path$$1, printClass(path$$1, options, print));
  20809. case "TSDeclareFunction":
  20810. // For TypeScript the TSDeclareFunction node shares the AST
  20811. // structure with FunctionDeclaration
  20812. return concat$4([n.declare ? "declare " : "", printFunctionDeclaration(path$$1, print, options), semi]);
  20813. case "DeclareFunction":
  20814. return printFlowDeclaration(path$$1, ["function ", path$$1.call(print, "id"), n.predicate ? " " : "", path$$1.call(print, "predicate"), semi]);
  20815. case "DeclareModule":
  20816. return printFlowDeclaration(path$$1, ["module ", path$$1.call(print, "id"), " ", path$$1.call(print, "body")]);
  20817. case "DeclareModuleExports":
  20818. return printFlowDeclaration(path$$1, ["module.exports", ": ", path$$1.call(print, "typeAnnotation"), semi]);
  20819. case "DeclareVariable":
  20820. return printFlowDeclaration(path$$1, ["var ", path$$1.call(print, "id"), semi]);
  20821. case "DeclareExportAllDeclaration":
  20822. return concat$4(["declare export * from ", path$$1.call(print, "source")]);
  20823. case "DeclareExportDeclaration":
  20824. return concat$4(["declare ", printExportDeclaration(path$$1, options, print)]);
  20825. case "DeclareOpaqueType":
  20826. case "OpaqueType":
  20827. {
  20828. parts.push("opaque type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  20829. if (n.supertype) {
  20830. parts.push(": ", path$$1.call(print, "supertype"));
  20831. }
  20832. if (n.impltype) {
  20833. parts.push(" = ", path$$1.call(print, "impltype"));
  20834. }
  20835. parts.push(semi);
  20836. if (n.type === "DeclareOpaqueType") {
  20837. return printFlowDeclaration(path$$1, parts);
  20838. }
  20839. return concat$4(parts);
  20840. }
  20841. case "FunctionTypeAnnotation":
  20842. case "TSFunctionType":
  20843. {
  20844. // FunctionTypeAnnotation is ambiguous:
  20845. // declare function foo(a: B): void; OR
  20846. // var A: (a: B) => void;
  20847. var _parent7 = path$$1.getParentNode(0);
  20848. var _parentParent2 = path$$1.getParentNode(1);
  20849. var _parentParentParent = path$$1.getParentNode(2);
  20850. var isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || !((_parent7.type === "ObjectTypeProperty" || _parent7.type === "ObjectTypeInternalSlot") && !getFlowVariance(_parent7) && !_parent7.optional && options.locStart(_parent7) === options.locStart(n) || _parent7.type === "ObjectTypeCallProperty" || _parentParentParent && _parentParentParent.type === "DeclareFunction");
  20851. var needsColon = isArrowFunctionTypeAnnotation && (_parent7.type === "TypeAnnotation" || _parent7.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
  20852. // printing ":" as part of the expression and it would put parenthesis
  20853. // around :(
  20854. var needsParens = needsColon && isArrowFunctionTypeAnnotation && (_parent7.type === "TypeAnnotation" || _parent7.type === "TSTypeAnnotation") && _parentParent2.type === "ArrowFunctionExpression";
  20855. if (isObjectTypePropertyAFunction(_parent7, options)) {
  20856. isArrowFunctionTypeAnnotation = true;
  20857. needsColon = true;
  20858. }
  20859. if (needsParens) {
  20860. parts.push("(");
  20861. }
  20862. parts.push(printFunctionParams(path$$1, print, options,
  20863. /* expandArg */
  20864. false,
  20865. /* printTypeParams */
  20866. true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
  20867. // needs to be added separately.
  20868. if (n.returnType || n.predicate || n.typeAnnotation) {
  20869. parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path$$1.call(print, "returnType"), path$$1.call(print, "predicate"), path$$1.call(print, "typeAnnotation"));
  20870. }
  20871. if (needsParens) {
  20872. parts.push(")");
  20873. }
  20874. return group$1(concat$4(parts));
  20875. }
  20876. case "TSRestType":
  20877. return concat$4(["...", path$$1.call(print, "typeAnnotation")]);
  20878. case "TSOptionalType":
  20879. return concat$4([path$$1.call(print, "typeAnnotation"), "?"]);
  20880. case "FunctionTypeParam":
  20881. return concat$4([path$$1.call(print, "name"), printOptionalToken(path$$1), n.name ? ": " : "", path$$1.call(print, "typeAnnotation")]);
  20882. case "GenericTypeAnnotation":
  20883. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  20884. case "DeclareInterface":
  20885. case "InterfaceDeclaration":
  20886. case "InterfaceTypeAnnotation":
  20887. {
  20888. if (n.type === "DeclareInterface" || isNodeStartingWithDeclare(n, options)) {
  20889. parts.push("declare ");
  20890. }
  20891. parts.push("interface");
  20892. if (n.type === "DeclareInterface" || n.type === "InterfaceDeclaration") {
  20893. parts.push(" ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  20894. }
  20895. if (n["extends"].length > 0) {
  20896. parts.push(group$1(indent$2(concat$4([line$3, "extends ", (n.extends.length === 1 ? identity$1 : indent$2)(join$2(concat$4([",", line$3]), path$$1.map(print, "extends")))]))));
  20897. }
  20898. parts.push(" ", path$$1.call(print, "body"));
  20899. return group$1(concat$4(parts));
  20900. }
  20901. case "ClassImplements":
  20902. case "InterfaceExtends":
  20903. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  20904. case "TSClassImplements":
  20905. return concat$4([path$$1.call(print, "expression"), path$$1.call(print, "typeParameters")]);
  20906. case "TSIntersectionType":
  20907. case "IntersectionTypeAnnotation":
  20908. {
  20909. var types = path$$1.map(print, "types");
  20910. var result = [];
  20911. var wasIndented = false;
  20912. for (var _i = 0; _i < types.length; ++_i) {
  20913. if (_i === 0) {
  20914. result.push(types[_i]);
  20915. } else if (isObjectType(n.types[_i - 1]) && isObjectType(n.types[_i])) {
  20916. // If both are objects, don't indent
  20917. result.push(concat$4([" & ", wasIndented ? indent$2(types[_i]) : types[_i]]));
  20918. } else if (!isObjectType(n.types[_i - 1]) && !isObjectType(n.types[_i])) {
  20919. // If no object is involved, go to the next line if it breaks
  20920. result.push(indent$2(concat$4([" &", line$3, types[_i]])));
  20921. } else {
  20922. // If you go from object to non-object or vis-versa, then inline it
  20923. if (_i > 1) {
  20924. wasIndented = true;
  20925. }
  20926. result.push(" & ", _i > 1 ? indent$2(types[_i]) : types[_i]);
  20927. }
  20928. }
  20929. return group$1(concat$4(result));
  20930. }
  20931. case "TSUnionType":
  20932. case "UnionTypeAnnotation":
  20933. {
  20934. // single-line variation
  20935. // A | B | C
  20936. // multi-line variation
  20937. // | A
  20938. // | B
  20939. // | C
  20940. var _parent8 = path$$1.getParentNode(); // If there's a leading comment, the parent is doing the indentation
  20941. var shouldIndent = _parent8.type !== "TypeParameterInstantiation" && _parent8.type !== "TSTypeParameterInstantiation" && _parent8.type !== "GenericTypeAnnotation" && _parent8.type !== "TSTypeReference" && _parent8.type !== "TSTypeAssertion" && !(_parent8.type === "FunctionTypeParam" && !_parent8.name) && !((_parent8.type === "TypeAlias" || _parent8.type === "VariableDeclarator" || _parent8.type === "TSTypeAliasDeclaration") && hasLeadingOwnLineComment(options.originalText, n, options)); // {
  20942. // a: string
  20943. // } | null | void
  20944. // should be inlined and not be printed in the multi-line variant
  20945. var shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
  20946. // | child1
  20947. // // comment
  20948. // | child2
  20949. var _printed4 = path$$1.map(function (typePath) {
  20950. var printedType = typePath.call(print);
  20951. if (!shouldHug) {
  20952. printedType = align$1(2, printedType);
  20953. }
  20954. return comments.printComments(typePath, function () {
  20955. return printedType;
  20956. }, options);
  20957. }, "types");
  20958. if (shouldHug) {
  20959. return join$2(" | ", _printed4);
  20960. }
  20961. var shouldAddStartLine = shouldIndent && !hasLeadingOwnLineComment(options.originalText, n, options);
  20962. var code = concat$4([ifBreak$1(concat$4([shouldAddStartLine ? line$3 : "", "| "])), join$2(concat$4([line$3, "| "]), _printed4)]);
  20963. var hasParens;
  20964. if (n.type === "TSUnionType") {
  20965. var greatGrandParent = path$$1.getParentNode(2);
  20966. var greatGreatGrandParent = path$$1.getParentNode(3);
  20967. hasParens = greatGrandParent && greatGrandParent.type === "TSParenthesizedType" && greatGreatGrandParent && (greatGreatGrandParent.type === "TSUnionType" || greatGreatGrandParent.type === "TSIntersectionType");
  20968. } else {
  20969. hasParens = needsParens_1(path$$1, options);
  20970. }
  20971. if (hasParens) {
  20972. return group$1(concat$4([indent$2(code), softline$1]));
  20973. }
  20974. return group$1(shouldIndent ? indent$2(code) : code);
  20975. }
  20976. case "NullableTypeAnnotation":
  20977. return concat$4(["?", path$$1.call(print, "typeAnnotation")]);
  20978. case "TSNullKeyword":
  20979. case "NullLiteralTypeAnnotation":
  20980. return "null";
  20981. case "ThisTypeAnnotation":
  20982. return "this";
  20983. case "NumberTypeAnnotation":
  20984. return "number";
  20985. case "ObjectTypeCallProperty":
  20986. if (n.static) {
  20987. parts.push("static ");
  20988. }
  20989. parts.push(path$$1.call(print, "value"));
  20990. return concat$4(parts);
  20991. case "ObjectTypeIndexer":
  20992. {
  20993. var _variance = getFlowVariance(n);
  20994. return concat$4([_variance || "", "[", path$$1.call(print, "id"), n.id ? ": " : "", path$$1.call(print, "key"), "]: ", path$$1.call(print, "value")]);
  20995. }
  20996. case "ObjectTypeProperty":
  20997. {
  20998. var _variance2 = getFlowVariance(n);
  20999. var modifier = "";
  21000. if (n.proto) {
  21001. modifier = "proto ";
  21002. } else if (n.static) {
  21003. modifier = "static ";
  21004. }
  21005. 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")]);
  21006. }
  21007. case "QualifiedTypeIdentifier":
  21008. return concat$4([path$$1.call(print, "qualification"), ".", path$$1.call(print, "id")]);
  21009. case "StringLiteralTypeAnnotation":
  21010. return nodeStr(n, options);
  21011. case "NumberLiteralTypeAnnotation":
  21012. assert.strictEqual(typeof n.value, "number");
  21013. if (n.extra != null) {
  21014. return printNumber$1(n.extra.raw);
  21015. }
  21016. return printNumber$1(n.raw);
  21017. case "StringTypeAnnotation":
  21018. return "string";
  21019. case "DeclareTypeAlias":
  21020. case "TypeAlias":
  21021. {
  21022. if (n.type === "DeclareTypeAlias" || isNodeStartingWithDeclare(n, options)) {
  21023. parts.push("declare ");
  21024. }
  21025. var _printed5 = printAssignmentRight(n.id, n.right, path$$1.call(print, "right"), options);
  21026. parts.push("type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"), " =", _printed5, semi);
  21027. return group$1(concat$4(parts));
  21028. }
  21029. case "TypeCastExpression":
  21030. {
  21031. var value = path$$1.getValue(); // Flow supports a comment syntax for specifying type annotations: https://flow.org/en/docs/types/comments/.
  21032. // Unfortunately, its parser doesn't differentiate between comment annotations and regular
  21033. // annotations when producing an AST. So to preserve parentheses around type casts that use
  21034. // the comment syntax, we need to hackily read the source itself to see if the code contains
  21035. // a type annotation comment.
  21036. //
  21037. // Note that we're able to use the normal whitespace regex here because the Flow parser has
  21038. // already deemed this AST node to be a type cast. Only the Babel parser needs the
  21039. // non-line-break whitespace regex, which is why hasFlowShorthandAnnotationComment() is
  21040. // implemented differently.
  21041. var commentSyntax = value && value.typeAnnotation && value.typeAnnotation.range && options.originalText.substring(value.typeAnnotation.range[0]).match(/^\/\*\s*:/);
  21042. return concat$4(["(", path$$1.call(print, "expression"), commentSyntax ? " /*" : "", ": ", path$$1.call(print, "typeAnnotation"), commentSyntax ? " */" : "", ")"]);
  21043. }
  21044. case "TypeParameterDeclaration":
  21045. case "TypeParameterInstantiation":
  21046. {
  21047. var _value = path$$1.getValue();
  21048. var commentStart = _value.range ? options.originalText.substring(0, _value.range[0]).lastIndexOf("/*") : -1; // As noted in the TypeCastExpression comments above, we're able to use a normal whitespace regex here
  21049. // because we know for sure that this is a type definition.
  21050. var _commentSyntax = commentStart >= 0 && options.originalText.substring(commentStart).match(/^\/\*\s*::/);
  21051. if (_commentSyntax) {
  21052. return concat$4(["/*:: ", printTypeParameters(path$$1, options, print, "params"), " */"]);
  21053. }
  21054. return printTypeParameters(path$$1, options, print, "params");
  21055. }
  21056. case "TSTypeParameterDeclaration":
  21057. case "TSTypeParameterInstantiation":
  21058. return printTypeParameters(path$$1, options, print, "params");
  21059. case "TSTypeParameter":
  21060. case "TypeParameter":
  21061. {
  21062. var _parent9 = path$$1.getParentNode();
  21063. if (_parent9.type === "TSMappedType") {
  21064. parts.push("[", path$$1.call(print, "name"));
  21065. if (n.constraint) {
  21066. parts.push(" in ", path$$1.call(print, "constraint"));
  21067. }
  21068. parts.push("]");
  21069. return concat$4(parts);
  21070. }
  21071. var _variance3 = getFlowVariance(n);
  21072. if (_variance3) {
  21073. parts.push(_variance3);
  21074. }
  21075. parts.push(path$$1.call(print, "name"));
  21076. if (n.bound) {
  21077. parts.push(": ");
  21078. parts.push(path$$1.call(print, "bound"));
  21079. }
  21080. if (n.constraint) {
  21081. parts.push(" extends ", path$$1.call(print, "constraint"));
  21082. }
  21083. if (n["default"]) {
  21084. parts.push(" = ", path$$1.call(print, "default"));
  21085. } // Keep comma if the file extension is .tsx and
  21086. // has one type parameter that isn't extend with any types.
  21087. // Because, otherwise formatted result will be invalid as tsx.
  21088. var _grandParent = path$$1.getNode(2);
  21089. if (_parent9.params && _parent9.params.length === 1 && options.filepath && /\.tsx$/i.test(options.filepath) && !n.constraint && _grandParent.type === "ArrowFunctionExpression") {
  21090. parts.push(",");
  21091. }
  21092. return concat$4(parts);
  21093. }
  21094. case "TypeofTypeAnnotation":
  21095. return concat$4(["typeof ", path$$1.call(print, "argument")]);
  21096. case "VoidTypeAnnotation":
  21097. return "void";
  21098. case "InferredPredicate":
  21099. return "%checks";
  21100. // Unhandled types below. If encountered, nodes of these types should
  21101. // be either left alone or desugared into AST types that are fully
  21102. // supported by the pretty-printer.
  21103. case "DeclaredPredicate":
  21104. return concat$4(["%checks(", path$$1.call(print, "value"), ")"]);
  21105. case "TSAbstractKeyword":
  21106. return "abstract";
  21107. case "TSAnyKeyword":
  21108. return "any";
  21109. case "TSAsyncKeyword":
  21110. return "async";
  21111. case "TSBooleanKeyword":
  21112. return "boolean";
  21113. case "TSBigIntKeyword":
  21114. return "bigint";
  21115. case "TSConstKeyword":
  21116. return "const";
  21117. case "TSDeclareKeyword":
  21118. return "declare";
  21119. case "TSExportKeyword":
  21120. return "export";
  21121. case "TSNeverKeyword":
  21122. return "never";
  21123. case "TSNumberKeyword":
  21124. return "number";
  21125. case "TSObjectKeyword":
  21126. return "object";
  21127. case "TSProtectedKeyword":
  21128. return "protected";
  21129. case "TSPrivateKeyword":
  21130. return "private";
  21131. case "TSPublicKeyword":
  21132. return "public";
  21133. case "TSReadonlyKeyword":
  21134. return "readonly";
  21135. case "TSSymbolKeyword":
  21136. return "symbol";
  21137. case "TSStaticKeyword":
  21138. return "static";
  21139. case "TSStringKeyword":
  21140. return "string";
  21141. case "TSUndefinedKeyword":
  21142. return "undefined";
  21143. case "TSUnknownKeyword":
  21144. return "unknown";
  21145. case "TSVoidKeyword":
  21146. return "void";
  21147. case "TSAsExpression":
  21148. return concat$4([path$$1.call(print, "expression"), " as ", path$$1.call(print, "typeAnnotation")]);
  21149. case "TSArrayType":
  21150. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  21151. case "TSPropertySignature":
  21152. {
  21153. if (n.export) {
  21154. parts.push("export ");
  21155. }
  21156. if (n.accessibility) {
  21157. parts.push(n.accessibility + " ");
  21158. }
  21159. if (n.static) {
  21160. parts.push("static ");
  21161. }
  21162. if (n.readonly) {
  21163. parts.push("readonly ");
  21164. }
  21165. if (n.computed) {
  21166. parts.push("[");
  21167. }
  21168. parts.push(printPropertyKey(path$$1, options, print));
  21169. if (n.computed) {
  21170. parts.push("]");
  21171. }
  21172. parts.push(printOptionalToken(path$$1));
  21173. if (n.typeAnnotation) {
  21174. parts.push(": ");
  21175. parts.push(path$$1.call(print, "typeAnnotation"));
  21176. } // This isn't valid semantically, but it's in the AST so we can print it.
  21177. if (n.initializer) {
  21178. parts.push(" = ", path$$1.call(print, "initializer"));
  21179. }
  21180. return concat$4(parts);
  21181. }
  21182. case "TSParameterProperty":
  21183. if (n.accessibility) {
  21184. parts.push(n.accessibility + " ");
  21185. }
  21186. if (n.export) {
  21187. parts.push("export ");
  21188. }
  21189. if (n.static) {
  21190. parts.push("static ");
  21191. }
  21192. if (n.readonly) {
  21193. parts.push("readonly ");
  21194. }
  21195. parts.push(path$$1.call(print, "parameter"));
  21196. return concat$4(parts);
  21197. case "TSTypeReference":
  21198. return concat$4([path$$1.call(print, "typeName"), printTypeParameters(path$$1, options, print, "typeParameters")]);
  21199. case "TSTypeQuery":
  21200. return concat$4(["typeof ", path$$1.call(print, "exprName")]);
  21201. case "TSParenthesizedType":
  21202. {
  21203. return path$$1.call(print, "typeAnnotation");
  21204. }
  21205. case "TSIndexSignature":
  21206. {
  21207. var _parent10 = path$$1.getParentNode();
  21208. return concat$4([n.export ? "export " : "", n.accessibility ? concat$4([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", n.parameters ? concat$4(path$$1.map(print, "parameters")) : "", "]: ", path$$1.call(print, "typeAnnotation"), _parent10.type === "ClassBody" ? semi : ""]);
  21209. }
  21210. case "TSTypePredicate":
  21211. return concat$4([path$$1.call(print, "parameterName"), " is ", path$$1.call(print, "typeAnnotation")]);
  21212. case "TSNonNullExpression":
  21213. return concat$4([path$$1.call(print, "expression"), "!"]);
  21214. case "TSThisType":
  21215. return "this";
  21216. case "TSImportType":
  21217. return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path$$1.call(print, "parameter"), ")", !n.qualifier ? "" : concat$4([".", path$$1.call(print, "qualifier")]), printTypeParameters(path$$1, options, print, "typeParameters")]);
  21218. case "TSLiteralType":
  21219. return path$$1.call(print, "literal");
  21220. case "TSIndexedAccessType":
  21221. return concat$4([path$$1.call(print, "objectType"), "[", path$$1.call(print, "indexType"), "]"]);
  21222. case "TSConstructSignatureDeclaration":
  21223. case "TSCallSignatureDeclaration":
  21224. case "TSConstructorType":
  21225. {
  21226. if (n.type !== "TSCallSignatureDeclaration") {
  21227. parts.push("new ");
  21228. }
  21229. parts.push(group$1(printFunctionParams(path$$1, print, options,
  21230. /* expandArg */
  21231. false,
  21232. /* printTypeParams */
  21233. true)));
  21234. if (n.returnType) {
  21235. var isType = n.type === "TSConstructorType";
  21236. parts.push(isType ? " => " : ": ", path$$1.call(print, "returnType"));
  21237. }
  21238. return concat$4(parts);
  21239. }
  21240. case "TSTypeOperator":
  21241. return concat$4([n.operator, " ", path$$1.call(print, "typeAnnotation")]);
  21242. case "TSMappedType":
  21243. {
  21244. var _shouldBreak2 = hasNewlineInRange$1(options.originalText, options.locStart(n), options.locEnd(n));
  21245. return group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, n.readonly ? concat$4([getTypeScriptMappedTypeModifier(n.readonly, "readonly"), " "]) : "", printTypeScriptModifiers(path$$1, options, print), path$$1.call(print, "typeParameter"), n.optional ? getTypeScriptMappedTypeModifier(n.optional, "?") : "", ": ", path$$1.call(print, "typeAnnotation"), _shouldBreak2 && options.semi ? ";" : ""])), comments.printDanglingComments(path$$1, options,
  21246. /* sameIndent */
  21247. true), options.bracketSpacing ? line$3 : softline$1, "}"]), {
  21248. shouldBreak: _shouldBreak2
  21249. });
  21250. }
  21251. case "TSMethodSignature":
  21252. 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,
  21253. /* expandArg */
  21254. false,
  21255. /* printTypeParams */
  21256. true));
  21257. if (n.returnType) {
  21258. parts.push(": ", path$$1.call(print, "returnType"));
  21259. }
  21260. return group$1(concat$4(parts));
  21261. case "TSNamespaceExportDeclaration":
  21262. parts.push("export as namespace ", path$$1.call(print, "id"));
  21263. if (options.semi) {
  21264. parts.push(";");
  21265. }
  21266. return group$1(concat$4(parts));
  21267. case "TSEnumDeclaration":
  21268. if (isNodeStartingWithDeclare(n, options)) {
  21269. parts.push("declare ");
  21270. }
  21271. if (n.modifiers) {
  21272. parts.push(printTypeScriptModifiers(path$$1, options, print));
  21273. }
  21274. if (n.const) {
  21275. parts.push("const ");
  21276. }
  21277. parts.push("enum ", path$$1.call(print, "id"), " ");
  21278. if (n.members.length === 0) {
  21279. parts.push(group$1(concat$4(["{", comments.printDanglingComments(path$$1, options), softline$1, "}"])));
  21280. } else {
  21281. 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,
  21282. /* sameIndent */
  21283. true), hardline$3, "}"])));
  21284. }
  21285. return concat$4(parts);
  21286. case "TSEnumMember":
  21287. parts.push(path$$1.call(print, "id"));
  21288. if (n.initializer) {
  21289. parts.push(" = ", path$$1.call(print, "initializer"));
  21290. }
  21291. return concat$4(parts);
  21292. case "TSImportEqualsDeclaration":
  21293. if (n.isExport) {
  21294. parts.push("export ");
  21295. }
  21296. parts.push("import ", path$$1.call(print, "id"), " = ", path$$1.call(print, "moduleReference"));
  21297. if (options.semi) {
  21298. parts.push(";");
  21299. }
  21300. return group$1(concat$4(parts));
  21301. case "TSExternalModuleReference":
  21302. return concat$4(["require(", path$$1.call(print, "expression"), ")"]);
  21303. case "TSModuleDeclaration":
  21304. {
  21305. var _parent11 = path$$1.getParentNode();
  21306. var isExternalModule = isLiteral(n.id);
  21307. var parentIsDeclaration = _parent11.type === "TSModuleDeclaration";
  21308. var bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  21309. if (parentIsDeclaration) {
  21310. parts.push(".");
  21311. } else {
  21312. if (n.declare === true) {
  21313. parts.push("declare ");
  21314. }
  21315. parts.push(printTypeScriptModifiers(path$$1, options, print));
  21316. var textBetweenNodeAndItsId = options.originalText.slice(options.locStart(n), options.locStart(n.id)); // Global declaration looks like this:
  21317. // (declare)? global { ... }
  21318. var isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(textBetweenNodeAndItsId);
  21319. if (!isGlobalDeclaration) {
  21320. parts.push(isExternalModule || /(^|\s)module(\s|$)/.test(textBetweenNodeAndItsId) ? "module " : "namespace ");
  21321. }
  21322. }
  21323. parts.push(path$$1.call(print, "id"));
  21324. if (bodyIsDeclaration) {
  21325. parts.push(path$$1.call(print, "body"));
  21326. } else if (n.body) {
  21327. parts.push(" ", group$1(path$$1.call(print, "body")));
  21328. } else {
  21329. parts.push(semi);
  21330. }
  21331. return concat$4(parts);
  21332. }
  21333. case "PrivateName":
  21334. return concat$4(["#", path$$1.call(print, "id")]);
  21335. case "TSConditionalType":
  21336. return printTernaryOperator(path$$1, options, print, {
  21337. beforeParts: function beforeParts() {
  21338. return [path$$1.call(print, "checkType"), " ", "extends", " ", path$$1.call(print, "extendsType")];
  21339. },
  21340. afterParts: function afterParts() {
  21341. return [];
  21342. },
  21343. shouldCheckJsx: false,
  21344. conditionalNodeType: "TSConditionalType",
  21345. consequentNodePropertyName: "trueType",
  21346. alternateNodePropertyName: "falseType",
  21347. testNodePropertyName: "checkType",
  21348. breakNested: true
  21349. });
  21350. case "TSInferType":
  21351. return concat$4(["infer", " ", path$$1.call(print, "typeParameter")]);
  21352. case "InterpreterDirective":
  21353. parts.push("#!", n.value, hardline$3);
  21354. if (isNextLineEmpty$2(options.originalText, n, options)) {
  21355. parts.push(hardline$3);
  21356. }
  21357. return concat$4(parts);
  21358. case "NGRoot":
  21359. return concat$4([].concat(path$$1.call(print, "node"), !n.node.comments || n.node.comments.length === 0 ? [] : concat$4([" //", n.node.comments[0].value.trimRight()])));
  21360. case "NGChainedExpression":
  21361. return group$1(join$2(concat$4([";", line$3]), path$$1.map(function (childPath) {
  21362. return hasNgSideEffect(childPath) ? print(childPath) : concat$4(["(", print(childPath), ")"]);
  21363. }, "expressions")));
  21364. case "NGEmptyExpression":
  21365. return "";
  21366. case "NGQuotedExpression":
  21367. return concat$4([n.prefix, ":", n.value]);
  21368. case "NGMicrosyntax":
  21369. return concat$4(path$$1.map(function (childPath, index) {
  21370. return concat$4([index === 0 ? "" : isNgForOf(childPath.getValue(), index, n) ? " " : concat$4([";", line$3]), print(childPath)]);
  21371. }, "body"));
  21372. case "NGMicrosyntaxKey":
  21373. return /^[a-z_$][a-z0-9_$]*(-[a-z_$][a-z0-9_$])*$/i.test(n.name) ? n.name : JSON.stringify(n.name);
  21374. case "NGMicrosyntaxExpression":
  21375. return concat$4([path$$1.call(print, "expression"), n.alias === null ? "" : concat$4([" as ", path$$1.call(print, "alias")])]);
  21376. case "NGMicrosyntaxKeyedExpression":
  21377. {
  21378. var index = path$$1.getName();
  21379. var _parentNode2 = path$$1.getParentNode();
  21380. var shouldNotPrintColon = isNgForOf(n, index, _parentNode2) || (index === 1 && (n.key.name === "then" || n.key.name === "else") || index === 2 && n.key.name === "else" && _parentNode2.body[index - 1].type === "NGMicrosyntaxKeyedExpression" && _parentNode2.body[index - 1].key.name === "then") && _parentNode2.body[0].type === "NGMicrosyntaxExpression";
  21381. return concat$4([path$$1.call(print, "key"), shouldNotPrintColon ? " " : ": ", path$$1.call(print, "expression")]);
  21382. }
  21383. case "NGMicrosyntaxLet":
  21384. return concat$4(["let ", path$$1.call(print, "key"), n.value === null ? "" : concat$4([" = ", path$$1.call(print, "value")])]);
  21385. case "NGMicrosyntaxAs":
  21386. return concat$4([path$$1.call(print, "key"), " as ", path$$1.call(print, "alias")]);
  21387. default:
  21388. /* istanbul ignore next */
  21389. throw new Error("unknown type: " + JSON.stringify(n.type));
  21390. }
  21391. }
  21392. function isNgForOf(node, index, parentNode) {
  21393. return node.type === "NGMicrosyntaxKeyedExpression" && node.key.name === "of" && index === 1 && parentNode.body[0].type === "NGMicrosyntaxLet" && parentNode.body[0].value === null;
  21394. }
  21395. /** identify if an angular expression seems to have side effects */
  21396. function hasNgSideEffect(path$$1) {
  21397. return hasNode(path$$1.getValue(), function (node) {
  21398. switch (node.type) {
  21399. case undefined:
  21400. return false;
  21401. case "CallExpression":
  21402. case "OptionalCallExpression":
  21403. case "AssignmentExpression":
  21404. return true;
  21405. }
  21406. });
  21407. }
  21408. function printStatementSequence(path$$1, options, print) {
  21409. var printed = [];
  21410. var bodyNode = path$$1.getNode();
  21411. var isClass = bodyNode.type === "ClassBody";
  21412. path$$1.map(function (stmtPath, i) {
  21413. var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
  21414. // "statements," it's safer simply to skip them.
  21415. /* istanbul ignore if */
  21416. if (!stmt) {
  21417. return;
  21418. } // Skip printing EmptyStatement nodes to avoid leaving stray
  21419. // semicolons lying around.
  21420. if (stmt.type === "EmptyStatement") {
  21421. return;
  21422. }
  21423. var stmtPrinted = print(stmtPath);
  21424. var text = options.originalText;
  21425. var parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
  21426. // don't prepend the only JSX element in a program with semicolon
  21427. if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
  21428. if (stmt.comments && stmt.comments.some(function (comment) {
  21429. return comment.leading;
  21430. })) {
  21431. parts.push(print(stmtPath, {
  21432. needsSemi: true
  21433. }));
  21434. } else {
  21435. parts.push(";", stmtPrinted);
  21436. }
  21437. } else {
  21438. parts.push(stmtPrinted);
  21439. }
  21440. if (!options.semi && isClass) {
  21441. if (classPropMayCauseASIProblems(stmtPath)) {
  21442. parts.push(";");
  21443. } else if (stmt.type === "ClassProperty") {
  21444. var nextChild = bodyNode.body[i + 1];
  21445. if (classChildNeedsASIProtection(nextChild)) {
  21446. parts.push(";");
  21447. }
  21448. }
  21449. }
  21450. if (isNextLineEmpty$2(text, stmt, options) && !isLastStatement(stmtPath)) {
  21451. parts.push(hardline$3);
  21452. }
  21453. printed.push(concat$4(parts));
  21454. });
  21455. return join$2(hardline$3, printed);
  21456. }
  21457. function printPropertyKey(path$$1, options, print) {
  21458. var node = path$$1.getNode();
  21459. var parent = path$$1.getParentNode();
  21460. var key = node.key;
  21461. if (options.quoteProps === "consistent" && !needsQuoteProps.has(parent)) {
  21462. var objectHasStringProp = (parent.properties || parent.body || parent.members).some(function (prop) {
  21463. return !prop.computed && prop.key && isStringLiteral(prop.key) && !isStringPropSafeToCoerceToIdentifier(prop, options);
  21464. });
  21465. needsQuoteProps.set(parent, objectHasStringProp);
  21466. }
  21467. if (key.type === "Identifier" && !node.computed && (options.parser === "json" || options.quoteProps === "consistent" && needsQuoteProps.get(parent))) {
  21468. // a -> "a"
  21469. var prop = printString$1(JSON.stringify(key.name), options);
  21470. return path$$1.call(function (keyPath) {
  21471. return comments.printComments(keyPath, function () {
  21472. return prop;
  21473. }, options);
  21474. }, "key");
  21475. }
  21476. if (!node.computed && isStringPropSafeToCoerceToIdentifier(node, options) && (options.quoteProps === "as-needed" || options.quoteProps === "consistent" && !needsQuoteProps.get(parent))) {
  21477. // 'a' -> a
  21478. return path$$1.call(function (keyPath) {
  21479. return comments.printComments(keyPath, function () {
  21480. return key.value;
  21481. }, options);
  21482. }, "key");
  21483. }
  21484. return path$$1.call(print, "key");
  21485. }
  21486. function printMethod(path$$1, options, print) {
  21487. var node = path$$1.getNode();
  21488. var semi = options.semi ? ";" : "";
  21489. var kind = node.kind;
  21490. var parts = [];
  21491. if (node.type === "ObjectMethod" || node.type === "ClassMethod" || node.type === "ClassPrivateMethod") {
  21492. node.value = node;
  21493. }
  21494. if (node.value.async) {
  21495. parts.push("async ");
  21496. }
  21497. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  21498. if (node.value.generator) {
  21499. parts.push("*");
  21500. }
  21501. } else {
  21502. assert.ok(kind === "get" || kind === "set");
  21503. parts.push(kind, " ");
  21504. }
  21505. var key = printPropertyKey(path$$1, options, print);
  21506. if (node.computed) {
  21507. key = concat$4(["[", key, "]"]);
  21508. }
  21509. parts.push(key, concat$4(path$$1.call(function (valuePath) {
  21510. return [printFunctionTypeParameters(valuePath, options, print), group$1(concat$4([printFunctionParams(valuePath, print, options), printReturnType(valuePath, print, options)]))];
  21511. }, "value")));
  21512. if (!node.value.body || node.value.body.length === 0) {
  21513. parts.push(semi);
  21514. } else {
  21515. parts.push(" ", path$$1.call(print, "value", "body"));
  21516. }
  21517. return concat$4(parts);
  21518. }
  21519. function couldGroupArg(arg) {
  21520. return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertion" || arg.type === "TSAsExpression" || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && ( // we want to avoid breaking inside composite return types but not simple keywords
  21521. // https://github.com/prettier/prettier/issues/4070
  21522. // export class Thing implements OtherThing {
  21523. // do: (type: Type) => Provider<Prop> = memoize(
  21524. // (type: ObjectType): Provider<Opts> => {}
  21525. // );
  21526. // }
  21527. // https://github.com/prettier/prettier/issues/6099
  21528. // app.get("/", (req, res): void => {
  21529. // res.send("Hello World!");
  21530. // });
  21531. !arg.returnType || !arg.returnType.typeAnnotation || arg.returnType.typeAnnotation.type !== "TSTypeReference") && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode(arg.body));
  21532. }
  21533. function shouldGroupLastArg(args) {
  21534. var lastArg = getLast$3(args);
  21535. var penultimateArg = getPenultimate$1(args);
  21536. return !hasLeadingComment(lastArg) && !hasTrailingComment(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
  21537. // disable last element expansion.
  21538. !penultimateArg || penultimateArg.type !== lastArg.type);
  21539. }
  21540. function shouldGroupFirstArg(args) {
  21541. if (args.length !== 2) {
  21542. return false;
  21543. }
  21544. var firstArg = args[0];
  21545. var secondArg = args[1];
  21546. return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && secondArg.type !== "FunctionExpression" && secondArg.type !== "ArrowFunctionExpression" && secondArg.type !== "ConditionalExpression" && !couldGroupArg(secondArg);
  21547. }
  21548. function isSimpleFlowType(node) {
  21549. var flowTypeAnnotations = ["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"];
  21550. return node && flowTypeAnnotations.indexOf(node.type) !== -1 && !(node.type === "GenericTypeAnnotation" && node.typeParameters);
  21551. }
  21552. function isJestEachTemplateLiteral(node, parentNode) {
  21553. /**
  21554. * describe.each`table`(name, fn)
  21555. * describe.only.each`table`(name, fn)
  21556. * describe.skip.each`table`(name, fn)
  21557. * test.each`table`(name, fn)
  21558. * test.only.each`table`(name, fn)
  21559. * test.skip.each`table`(name, fn)
  21560. *
  21561. * Ref: https://github.com/facebook/jest/pull/6102
  21562. */
  21563. var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
  21564. return parentNode.type === "TaggedTemplateExpression" && parentNode.quasi === node && parentNode.tag.type === "MemberExpression" && parentNode.tag.property.type === "Identifier" && parentNode.tag.property.name === "each" && (parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.name) || parentNode.tag.object.type === "MemberExpression" && parentNode.tag.object.property.type === "Identifier" && (parentNode.tag.object.property.name === "only" || parentNode.tag.object.property.name === "skip") && parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.object.name));
  21565. }
  21566. function printJestEachTemplateLiteral(node, expressions, options) {
  21567. /**
  21568. * a | b | expected
  21569. * ${1} | ${1} | ${2}
  21570. * ${1} | ${2} | ${3}
  21571. * ${2} | ${1} | ${3}
  21572. */
  21573. var headerNames = node.quasis[0].value.raw.trim().split(/\s*\|\s*/);
  21574. if (headerNames.length > 1 || headerNames.some(function (headerName) {
  21575. return headerName.length !== 0;
  21576. })) {
  21577. var parts = [];
  21578. var stringifiedExpressions = expressions.map(function (doc$$2) {
  21579. return "${" + printDocToString$2(doc$$2, Object.assign({}, options, {
  21580. printWidth: Infinity,
  21581. endOfLine: "lf"
  21582. })).formatted + "}";
  21583. });
  21584. var tableBody = [{
  21585. hasLineBreak: false,
  21586. cells: []
  21587. }];
  21588. for (var i = 1; i < node.quasis.length; i++) {
  21589. var row = tableBody[tableBody.length - 1];
  21590. var correspondingExpression = stringifiedExpressions[i - 1];
  21591. row.cells.push(correspondingExpression);
  21592. if (correspondingExpression.indexOf("\n") !== -1) {
  21593. row.hasLineBreak = true;
  21594. }
  21595. if (node.quasis[i].value.raw.indexOf("\n") !== -1) {
  21596. tableBody.push({
  21597. hasLineBreak: false,
  21598. cells: []
  21599. });
  21600. }
  21601. }
  21602. var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
  21603. return Math.max(maxColumnCount, row.cells.length);
  21604. }, headerNames.length);
  21605. var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
  21606. return 0;
  21607. });
  21608. var table = [{
  21609. cells: headerNames
  21610. }].concat(tableBody.filter(function (row) {
  21611. return row.cells.length !== 0;
  21612. }));
  21613. table.filter(function (row) {
  21614. return !row.hasLineBreak;
  21615. }).forEach(function (row) {
  21616. row.cells.forEach(function (cell, index) {
  21617. maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$2(cell));
  21618. });
  21619. });
  21620. parts.push("`", indent$2(concat$4([hardline$3, join$2(hardline$3, table.map(function (row) {
  21621. return join$2(" | ", row.cells.map(function (cell, index) {
  21622. return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$2(cell));
  21623. }));
  21624. }))])), hardline$3, "`");
  21625. return concat$4(parts);
  21626. }
  21627. }
  21628. /** @param node {import("estree").TemplateLiteral} */
  21629. function isSimpleTemplateLiteral(node) {
  21630. if (node.expressions.length === 0) {
  21631. return false;
  21632. }
  21633. return node.expressions.every(function (expr) {
  21634. // Disallow comments since printDocToString can't print them here
  21635. if (expr.comments) {
  21636. return false;
  21637. } // Allow `x` and `this`
  21638. if (expr.type === "Identifier" || expr.type === "ThisExpression") {
  21639. return true;
  21640. } // Allow `a.b.c`, `a.b[c]`, and `this.x.y`
  21641. if ((expr.type === "MemberExpression" || expr.type === "OptionalMemberExpression") && (expr.property.type === "Identifier" || expr.property.type === "Literal")) {
  21642. var ancestor = expr;
  21643. while (ancestor.type === "MemberExpression" || ancestor.type === "OptionalMemberExpression") {
  21644. ancestor = ancestor.object;
  21645. if (ancestor.comments) {
  21646. return false;
  21647. }
  21648. }
  21649. if (ancestor.type === "Identifier" || ancestor.type === "ThisExpression") {
  21650. return true;
  21651. }
  21652. return false;
  21653. }
  21654. return false;
  21655. });
  21656. }
  21657. var functionCompositionFunctionNames = new Set(["pipe", // RxJS, Ramda
  21658. "pipeP", // Ramda
  21659. "pipeK", // Ramda
  21660. "compose", // Ramda, Redux
  21661. "composeFlipped", // Not from any library, but common in Haskell, so supported
  21662. "composeP", // Ramda
  21663. "composeK", // Ramda
  21664. "flow", // Lodash
  21665. "flowRight", // Lodash
  21666. "connect", // Redux
  21667. "createSelector" // Reselect
  21668. ]);
  21669. var ordinaryMethodNames = new Set(["connect" // GObject, MongoDB
  21670. ]);
  21671. function isFunctionCompositionFunction(node) {
  21672. switch (node.type) {
  21673. case "OptionalMemberExpression":
  21674. case "MemberExpression":
  21675. {
  21676. return isFunctionCompositionFunction(node.property) && !ordinaryMethodNames.has(node.property.name);
  21677. }
  21678. case "Identifier":
  21679. {
  21680. return functionCompositionFunctionNames.has(node.name);
  21681. }
  21682. case "StringLiteral":
  21683. case "Literal":
  21684. {
  21685. return functionCompositionFunctionNames.has(node.value);
  21686. }
  21687. }
  21688. }
  21689. function printArgumentsList(path$$1, options, print) {
  21690. var node = path$$1.getValue();
  21691. var args = node.arguments;
  21692. if (args.length === 0) {
  21693. return concat$4(["(", comments.printDanglingComments(path$$1, options,
  21694. /* sameIndent */
  21695. true), ")"]);
  21696. } // useEffect(() => { ... }, [foo, bar, baz])
  21697. if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].params.length === 0 && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.find(function (arg) {
  21698. return arg.leadingComments || arg.trailingComments;
  21699. })) {
  21700. return concat$4(["(", path$$1.call(print, "arguments", 0), ", ", path$$1.call(print, "arguments", 1), ")"]);
  21701. }
  21702. var anyArgEmptyLine = false;
  21703. var hasEmptyLineFollowingFirstArg = false;
  21704. var lastArgIndex = args.length - 1;
  21705. var printedArguments = path$$1.map(function (argPath, index) {
  21706. var arg = argPath.getNode();
  21707. var parts = [print(argPath)];
  21708. if (index === lastArgIndex) {// do nothing
  21709. } else if (isNextLineEmpty$2(options.originalText, arg, options)) {
  21710. if (index === 0) {
  21711. hasEmptyLineFollowingFirstArg = true;
  21712. }
  21713. anyArgEmptyLine = true;
  21714. parts.push(",", hardline$3, hardline$3);
  21715. } else {
  21716. parts.push(",", line$3);
  21717. }
  21718. return concat$4(parts);
  21719. }, "arguments");
  21720. var maybeTrailingComma = // Dynamic imports cannot have trailing commas
  21721. !(node.callee && node.callee.type === "Import") && shouldPrintComma(options, "all") ? "," : "";
  21722. function allArgsBrokenOut() {
  21723. return group$1(concat$4(["(", indent$2(concat$4([line$3, concat$4(printedArguments)])), maybeTrailingComma, line$3, ")"]), {
  21724. shouldBreak: true
  21725. });
  21726. } // We want to get
  21727. // pipe(
  21728. // x => x + 1,
  21729. // x => x - 1
  21730. // )
  21731. // here, but not
  21732. // process.stdout.pipe(socket)
  21733. if (isFunctionCompositionFunction(node.callee) && args.length > 1) {
  21734. return allArgsBrokenOut();
  21735. }
  21736. var shouldGroupFirst = shouldGroupFirstArg(args);
  21737. var shouldGroupLast = shouldGroupLastArg(args);
  21738. if (shouldGroupFirst || shouldGroupLast) {
  21739. 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
  21740. var printedExpanded;
  21741. var i = 0;
  21742. path$$1.each(function (argPath) {
  21743. if (shouldGroupFirst && i === 0) {
  21744. printedExpanded = [concat$4([argPath.call(function (p) {
  21745. return print(p, {
  21746. expandFirstArg: true
  21747. });
  21748. }), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$3 : line$3, hasEmptyLineFollowingFirstArg ? hardline$3 : ""])].concat(printedArguments.slice(1));
  21749. }
  21750. if (shouldGroupLast && i === args.length - 1) {
  21751. printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(function (p) {
  21752. return print(p, {
  21753. expandLastArg: true
  21754. });
  21755. }));
  21756. }
  21757. i++;
  21758. }, "arguments");
  21759. var somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  21760. 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], {
  21761. shouldBreak: true
  21762. }), concat$4(printedExpanded.slice(1)), ")"]) : concat$4(["(", concat$4(printedArguments.slice(0, -1)), group$1(getLast$3(printedExpanded), {
  21763. shouldBreak: true
  21764. }), ")"]), allArgsBrokenOut()], {
  21765. shouldBreak
  21766. })]);
  21767. }
  21768. return group$1(concat$4(["(", indent$2(concat$4([softline$1, concat$4(printedArguments)])), ifBreak$1(maybeTrailingComma), softline$1, ")"]), {
  21769. shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
  21770. });
  21771. }
  21772. function printTypeAnnotation(path$$1, options, print) {
  21773. var node = path$$1.getValue();
  21774. if (!node.typeAnnotation) {
  21775. return "";
  21776. }
  21777. var parentNode = path$$1.getParentNode();
  21778. var isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
  21779. var isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
  21780. if (isFlowAnnotationComment(options.originalText, node.typeAnnotation, options)) {
  21781. return concat$4([" /*: ", path$$1.call(print, "typeAnnotation"), " */"]);
  21782. }
  21783. return concat$4([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path$$1.call(print, "typeAnnotation")]);
  21784. }
  21785. function printFunctionTypeParameters(path$$1, options, print) {
  21786. var fun = path$$1.getValue();
  21787. if (fun.typeArguments) {
  21788. return path$$1.call(print, "typeArguments");
  21789. }
  21790. if (fun.typeParameters) {
  21791. return path$$1.call(print, "typeParameters");
  21792. }
  21793. return "";
  21794. }
  21795. function printFunctionParams(path$$1, print, options, expandArg, printTypeParams) {
  21796. var fun = path$$1.getValue();
  21797. var parent = path$$1.getParentNode();
  21798. var paramsField = fun.parameters ? "parameters" : "params";
  21799. var isParametersInTestCall = isTestCall(parent);
  21800. var shouldHugParameters = shouldHugArguments(fun);
  21801. var shouldExpandParameters = expandArg && !(fun[paramsField] && fun[paramsField].some(function (n) {
  21802. return n.comments;
  21803. }));
  21804. var typeParams = printTypeParams ? printFunctionTypeParameters(path$$1, options, print) : "";
  21805. var printed = [];
  21806. if (fun[paramsField]) {
  21807. var lastArgIndex = fun[paramsField].length - 1;
  21808. printed = path$$1.map(function (childPath, index) {
  21809. var parts = [];
  21810. var param = childPath.getValue();
  21811. parts.push(print(childPath));
  21812. if (index === lastArgIndex) {
  21813. if (fun.rest) {
  21814. parts.push(",", line$3);
  21815. }
  21816. } else if (isParametersInTestCall || shouldHugParameters || shouldExpandParameters) {
  21817. parts.push(", ");
  21818. } else if (isNextLineEmpty$2(options.originalText, param, options)) {
  21819. parts.push(",", hardline$3, hardline$3);
  21820. } else {
  21821. parts.push(",", line$3);
  21822. }
  21823. return concat$4(parts);
  21824. }, paramsField);
  21825. }
  21826. if (fun.rest) {
  21827. printed.push(concat$4(["...", path$$1.call(print, "rest")]));
  21828. }
  21829. if (printed.length === 0) {
  21830. return concat$4([typeParams, "(", comments.printDanglingComments(path$$1, options,
  21831. /* sameIndent */
  21832. true, function (comment) {
  21833. return getNextNonSpaceNonCommentCharacter$1(options.originalText, comment, options.locEnd) === ")";
  21834. }), ")"]);
  21835. }
  21836. var lastParam = getLast$3(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
  21837. // params of the first/last argument, we dont want the arguments to break and instead
  21838. // want the whole expression to be on a new line.
  21839. //
  21840. // Good: Bad:
  21841. // verylongcall( verylongcall((
  21842. // (a, b) => { a,
  21843. // } b,
  21844. // }) ) => {
  21845. // })
  21846. if (shouldExpandParameters) {
  21847. return group$1(concat$4([removeLines$1(typeParams), "(", concat$4(printed.map(removeLines$1)), ")"]));
  21848. } // Single object destructuring should hug
  21849. //
  21850. // function({
  21851. // a,
  21852. // b,
  21853. // c
  21854. // }) {}
  21855. if (shouldHugParameters) {
  21856. return concat$4([typeParams, "(", concat$4(printed), ")"]);
  21857. } // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  21858. if (isParametersInTestCall) {
  21859. return concat$4([typeParams, "(", concat$4(printed), ")"]);
  21860. }
  21861. 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 && isSimpleFlowType(fun[paramsField][0].typeAnnotation) && !fun.rest;
  21862. if (isFlowShorthandWithOneArg) {
  21863. if (options.arrowParens === "always") {
  21864. return concat$4(["(", concat$4(printed), ")"]);
  21865. }
  21866. return concat$4(printed);
  21867. }
  21868. var canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  21869. return concat$4([typeParams, "(", indent$2(concat$4([softline$1, concat$4(printed)])), ifBreak$1(canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]);
  21870. }
  21871. function shouldPrintParamsWithoutParens(path$$1, options) {
  21872. if (options.arrowParens === "always") {
  21873. return false;
  21874. }
  21875. if (options.arrowParens === "avoid") {
  21876. var node = path$$1.getValue();
  21877. return canPrintParamsWithoutParens(node);
  21878. } // Fallback default; should be unreachable
  21879. return false;
  21880. }
  21881. function canPrintParamsWithoutParens(node) {
  21882. 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;
  21883. }
  21884. function printFunctionDeclaration(path$$1, print, options) {
  21885. var n = path$$1.getValue();
  21886. var parts = [];
  21887. if (n.async) {
  21888. parts.push("async ");
  21889. }
  21890. parts.push("function");
  21891. if (n.generator) {
  21892. parts.push("*");
  21893. }
  21894. if (n.id) {
  21895. parts.push(" ", path$$1.call(print, "id"));
  21896. }
  21897. 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"));
  21898. return concat$4(parts);
  21899. }
  21900. function printObjectMethod(path$$1, options, print) {
  21901. var objMethod = path$$1.getValue();
  21902. var parts = [];
  21903. if (objMethod.async) {
  21904. parts.push("async ");
  21905. }
  21906. if (objMethod.generator) {
  21907. parts.push("*");
  21908. }
  21909. if (objMethod.method || objMethod.kind === "get" || objMethod.kind === "set") {
  21910. return printMethod(path$$1, options, print);
  21911. }
  21912. var key = printPropertyKey(path$$1, options, print);
  21913. if (objMethod.computed) {
  21914. parts.push("[", key, "]");
  21915. } else {
  21916. parts.push(key);
  21917. }
  21918. 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"));
  21919. return concat$4(parts);
  21920. }
  21921. function printReturnType(path$$1, print, options) {
  21922. var n = path$$1.getValue();
  21923. var returnType = path$$1.call(print, "returnType");
  21924. if (n.returnType && isFlowAnnotationComment(options.originalText, n.returnType, options)) {
  21925. return concat$4([" /*: ", returnType, " */"]);
  21926. }
  21927. var parts = [returnType]; // prepend colon to TypeScript type annotation
  21928. if (n.returnType && n.returnType.typeAnnotation) {
  21929. parts.unshift(": ");
  21930. }
  21931. if (n.predicate) {
  21932. // The return type will already add the colon, but otherwise we
  21933. // need to do it ourselves
  21934. parts.push(n.returnType ? " " : ": ", path$$1.call(print, "predicate"));
  21935. }
  21936. return concat$4(parts);
  21937. }
  21938. function printExportDeclaration(path$$1, options, print) {
  21939. var decl = path$$1.getValue();
  21940. var semi = options.semi ? ";" : "";
  21941. var parts = ["export "];
  21942. var isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  21943. if (isDefault) {
  21944. parts.push("default ");
  21945. }
  21946. parts.push(comments.printDanglingComments(path$$1, options,
  21947. /* sameIndent */
  21948. true));
  21949. if (needsHardlineAfterDanglingComment(decl)) {
  21950. parts.push(hardline$3);
  21951. }
  21952. if (decl.declaration) {
  21953. parts.push(path$$1.call(print, "declaration"));
  21954. if (isDefault && decl.declaration.type !== "ClassDeclaration" && decl.declaration.type !== "FunctionDeclaration" && decl.declaration.type !== "TSInterfaceDeclaration" && decl.declaration.type !== "DeclareClass" && decl.declaration.type !== "DeclareFunction" && decl.declaration.type !== "TSDeclareFunction") {
  21955. parts.push(semi);
  21956. }
  21957. } else {
  21958. if (decl.specifiers && decl.specifiers.length > 0) {
  21959. var specifiers = [];
  21960. var defaultSpecifiers = [];
  21961. var namespaceSpecifiers = [];
  21962. path$$1.each(function (specifierPath) {
  21963. var specifierType = path$$1.getValue().type;
  21964. if (specifierType === "ExportSpecifier") {
  21965. specifiers.push(print(specifierPath));
  21966. } else if (specifierType === "ExportDefaultSpecifier") {
  21967. defaultSpecifiers.push(print(specifierPath));
  21968. } else if (specifierType === "ExportNamespaceSpecifier") {
  21969. namespaceSpecifiers.push(concat$4(["* as ", print(specifierPath)]));
  21970. }
  21971. }, "specifiers");
  21972. var isNamespaceFollowed = namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  21973. var isDefaultFollowed = defaultSpecifiers.length !== 0 && (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  21974. 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, "}"])) : "");
  21975. } else {
  21976. parts.push("{}");
  21977. }
  21978. if (decl.source) {
  21979. parts.push(" from ", path$$1.call(print, "source"));
  21980. }
  21981. parts.push(semi);
  21982. }
  21983. return concat$4(parts);
  21984. }
  21985. function printFlowDeclaration(path$$1, parts) {
  21986. var parentExportDecl = getParentExportDeclaration$1(path$$1);
  21987. if (parentExportDecl) {
  21988. assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  21989. } else {
  21990. // If the parent node has type DeclareExportDeclaration, then it
  21991. // will be responsible for printing the "declare" token. Otherwise
  21992. // it needs to be printed with this non-exported declaration node.
  21993. parts.unshift("declare ");
  21994. }
  21995. return concat$4(parts);
  21996. }
  21997. function getFlowVariance(path$$1) {
  21998. if (!path$$1.variance) {
  21999. return null;
  22000. } // Babel 7.0 currently uses variance node type, and flow should
  22001. // follow suit soon:
  22002. // https://github.com/babel/babel/issues/4722
  22003. var variance = path$$1.variance.kind || path$$1.variance;
  22004. switch (variance) {
  22005. case "plus":
  22006. return "+";
  22007. case "minus":
  22008. return "-";
  22009. default:
  22010. /* istanbul ignore next */
  22011. return variance;
  22012. }
  22013. }
  22014. function printTypeScriptModifiers(path$$1, options, print) {
  22015. var n = path$$1.getValue();
  22016. if (!n.modifiers || !n.modifiers.length) {
  22017. return "";
  22018. }
  22019. return concat$4([join$2(" ", path$$1.map(print, "modifiers")), " "]);
  22020. }
  22021. function printTypeParameters(path$$1, options, print, paramsKey) {
  22022. var n = path$$1.getValue();
  22023. if (!n[paramsKey]) {
  22024. return "";
  22025. } // for TypeParameterDeclaration typeParameters is a single node
  22026. if (!Array.isArray(n[paramsKey])) {
  22027. return path$$1.call(print, paramsKey);
  22028. }
  22029. var grandparent = path$$1.getNode(2);
  22030. var isParameterInTestCall = grandparent != null && isTestCall(grandparent);
  22031. 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");
  22032. if (shouldInline) {
  22033. return concat$4(["<", join$2(", ", path$$1.map(print, paramsKey)), ">"]);
  22034. }
  22035. 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, ">"]));
  22036. }
  22037. function printClass(path$$1, options, print) {
  22038. var n = path$$1.getValue();
  22039. var parts = [];
  22040. if (n.abstract) {
  22041. parts.push("abstract ");
  22042. }
  22043. parts.push("class");
  22044. if (n.id) {
  22045. parts.push(" ", path$$1.call(print, "id"));
  22046. }
  22047. parts.push(path$$1.call(print, "typeParameters"));
  22048. var partsGroup = [];
  22049. if (n.superClass) {
  22050. var printed = concat$4(["extends ", path$$1.call(print, "superClass"), path$$1.call(print, "superTypeParameters")]); // Keep old behaviour of extends in same line
  22051. // If there is only on extends and there are not comments
  22052. if ((!n.implements || n.implements.length === 0) && (!n.superClass.comments || n.superClass.comments.length === 0)) {
  22053. parts.push(concat$4([" ", path$$1.call(function (superClass) {
  22054. return comments.printComments(superClass, function () {
  22055. return printed;
  22056. }, options);
  22057. }, "superClass")]));
  22058. } else {
  22059. partsGroup.push(group$1(concat$4([line$3, path$$1.call(function (superClass) {
  22060. return comments.printComments(superClass, function () {
  22061. return printed;
  22062. }, options);
  22063. }, "superClass")])));
  22064. }
  22065. } else if (n.extends && n.extends.length > 0) {
  22066. parts.push(" extends ", join$2(", ", path$$1.map(print, "extends")));
  22067. }
  22068. if (n["mixins"] && n["mixins"].length > 0) {
  22069. partsGroup.push(line$3, "mixins ", group$1(indent$2(join$2(concat$4([",", line$3]), path$$1.map(print, "mixins")))));
  22070. }
  22071. if (n["implements"] && n["implements"].length > 0) {
  22072. partsGroup.push(line$3, "implements", group$1(indent$2(concat$4([line$3, join$2(concat$4([",", line$3]), path$$1.map(print, "implements"))]))));
  22073. }
  22074. if (partsGroup.length > 0) {
  22075. parts.push(group$1(indent$2(concat$4(partsGroup))));
  22076. }
  22077. if (n.body && n.body.comments && hasLeadingOwnLineComment(options.originalText, n.body, options)) {
  22078. parts.push(hardline$3);
  22079. } else {
  22080. parts.push(" ");
  22081. }
  22082. parts.push(path$$1.call(print, "body"));
  22083. return parts;
  22084. }
  22085. function printOptionalToken(path$$1) {
  22086. var node = path$$1.getValue();
  22087. if (!node.optional) {
  22088. return "";
  22089. }
  22090. if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
  22091. return "?.";
  22092. }
  22093. return "?";
  22094. }
  22095. function printMemberLookup(path$$1, options, print) {
  22096. var property = path$$1.call(print, "property");
  22097. var n = path$$1.getValue();
  22098. var optional = printOptionalToken(path$$1);
  22099. if (!n.computed) {
  22100. return concat$4([optional, ".", property]);
  22101. }
  22102. if (!n.property || isNumericLiteral(n.property)) {
  22103. return concat$4([optional, "[", property, "]"]);
  22104. }
  22105. return group$1(concat$4([optional, "[", indent$2(concat$4([softline$1, property])), softline$1, "]"]));
  22106. }
  22107. function printBindExpressionCallee(path$$1, options, print) {
  22108. return concat$4(["::", path$$1.call(print, "callee")]);
  22109. } // We detect calls on member expressions specially to format a
  22110. // common pattern better. The pattern we are looking for is this:
  22111. //
  22112. // arr
  22113. // .map(x => x + 1)
  22114. // .filter(x => x > 10)
  22115. // .some(x => x % 2)
  22116. //
  22117. // The way it is structured in the AST is via a nested sequence of
  22118. // MemberExpression and CallExpression. We need to traverse the AST
  22119. // and make groups out of it to print it in the desired way.
  22120. function printMemberChain(path$$1, options, print) {
  22121. // The first phase is to linearize the AST by traversing it down.
  22122. //
  22123. // a().b()
  22124. // has the following AST structure:
  22125. // CallExpression(MemberExpression(CallExpression(Identifier)))
  22126. // and we transform it into
  22127. // [Identifier, CallExpression, MemberExpression, CallExpression]
  22128. var printedNodes = []; // Here we try to retain one typed empty line after each call expression or
  22129. // the first group whether it is in parentheses or not
  22130. function shouldInsertEmptyLineAfter(node) {
  22131. var originalText = options.originalText;
  22132. var nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$2(originalText, node, options);
  22133. var nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
  22134. // line after that parenthesis
  22135. if (nextChar == ")") {
  22136. return isNextLineEmptyAfterIndex$1(originalText, nextCharIndex + 1, options);
  22137. }
  22138. return isNextLineEmpty$2(originalText, node, options);
  22139. }
  22140. function rec(path$$1) {
  22141. var node = path$$1.getValue();
  22142. if ((node.type === "CallExpression" || node.type === "OptionalCallExpression") && (isMemberish(node.callee) || node.callee.type === "CallExpression" || node.callee.type === "OptionalCallExpression")) {
  22143. printedNodes.unshift({
  22144. node: node,
  22145. printed: concat$4([comments.printComments(path$$1, function () {
  22146. return concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
  22147. }, options), shouldInsertEmptyLineAfter(node) ? hardline$3 : ""])
  22148. });
  22149. path$$1.call(function (callee) {
  22150. return rec(callee);
  22151. }, "callee");
  22152. } else if (isMemberish(node)) {
  22153. printedNodes.unshift({
  22154. node: node,
  22155. needsParens: needsParens_1(path$$1, options),
  22156. printed: comments.printComments(path$$1, function () {
  22157. return node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup(path$$1, options, print) : printBindExpressionCallee(path$$1, options, print);
  22158. }, options)
  22159. });
  22160. path$$1.call(function (object) {
  22161. return rec(object);
  22162. }, "object");
  22163. } else if (node.type === "TSNonNullExpression") {
  22164. printedNodes.unshift({
  22165. node: node,
  22166. printed: comments.printComments(path$$1, function () {
  22167. return "!";
  22168. }, options)
  22169. });
  22170. path$$1.call(function (expression) {
  22171. return rec(expression);
  22172. }, "expression");
  22173. } else {
  22174. printedNodes.unshift({
  22175. node: node,
  22176. printed: path$$1.call(print)
  22177. });
  22178. }
  22179. } // Note: the comments of the root node have already been printed, so we
  22180. // need to extract this first call without printing them as they would
  22181. // if handled inside of the recursive call.
  22182. var node = path$$1.getValue();
  22183. printedNodes.unshift({
  22184. node,
  22185. printed: concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)])
  22186. });
  22187. path$$1.call(function (callee) {
  22188. return rec(callee);
  22189. }, "callee"); // Once we have a linear list of printed nodes, we want to create groups out
  22190. // of it.
  22191. //
  22192. // a().b.c().d().e
  22193. // will be grouped as
  22194. // [
  22195. // [Identifier, CallExpression],
  22196. // [MemberExpression, MemberExpression, CallExpression],
  22197. // [MemberExpression, CallExpression],
  22198. // [MemberExpression],
  22199. // ]
  22200. // so that we can print it as
  22201. // a()
  22202. // .b.c()
  22203. // .d()
  22204. // .e
  22205. // The first group is the first node followed by
  22206. // - as many CallExpression as possible
  22207. // < fn()()() >.something()
  22208. // - as many array acessors as possible
  22209. // < fn()[0][1][2] >.something()
  22210. // - then, as many MemberExpression as possible but the last one
  22211. // < this.items >.something()
  22212. var groups = [];
  22213. var currentGroup = [printedNodes[0]];
  22214. var i = 1;
  22215. for (; i < printedNodes.length; ++i) {
  22216. 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)) {
  22217. currentGroup.push(printedNodes[i]);
  22218. } else {
  22219. break;
  22220. }
  22221. }
  22222. if (printedNodes[0].node.type !== "CallExpression" && printedNodes[0].node.type !== "OptionalCallExpression") {
  22223. for (; i + 1 < printedNodes.length; ++i) {
  22224. if (isMemberish(printedNodes[i].node) && isMemberish(printedNodes[i + 1].node)) {
  22225. currentGroup.push(printedNodes[i]);
  22226. } else {
  22227. break;
  22228. }
  22229. }
  22230. }
  22231. groups.push(currentGroup);
  22232. currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
  22233. // a sequence of CallExpression. To compute it, we keep adding things to the
  22234. // group until we has seen a CallExpression in the past and reach a
  22235. // MemberExpression
  22236. var hasSeenCallExpression = false;
  22237. for (; i < printedNodes.length; ++i) {
  22238. if (hasSeenCallExpression && isMemberish(printedNodes[i].node)) {
  22239. // [0] should be appended at the end of the group instead of the
  22240. // beginning of the next one
  22241. if (printedNodes[i].node.computed && isNumericLiteral(printedNodes[i].node.property)) {
  22242. currentGroup.push(printedNodes[i]);
  22243. continue;
  22244. }
  22245. groups.push(currentGroup);
  22246. currentGroup = [];
  22247. hasSeenCallExpression = false;
  22248. }
  22249. if (printedNodes[i].node.type === "CallExpression" || printedNodes[i].node.type === "OptionalCallExpression") {
  22250. hasSeenCallExpression = true;
  22251. }
  22252. currentGroup.push(printedNodes[i]);
  22253. if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(function (comment) {
  22254. return comment.trailing;
  22255. })) {
  22256. groups.push(currentGroup);
  22257. currentGroup = [];
  22258. hasSeenCallExpression = false;
  22259. }
  22260. }
  22261. if (currentGroup.length > 0) {
  22262. groups.push(currentGroup);
  22263. } // There are cases like Object.keys(), Observable.of(), _.values() where
  22264. // they are the subject of all the chained calls and therefore should
  22265. // be kept on the same line:
  22266. //
  22267. // Object.keys(items)
  22268. // .filter(x => x)
  22269. // .map(x => x)
  22270. //
  22271. // In order to detect those cases, we use an heuristic: if the first
  22272. // node is an identifier with the name starting with a capital
  22273. // letter or just a sequence of _$. The rationale is that they are
  22274. // likely to be factories.
  22275. function isFactory(name) {
  22276. return /^[A-Z]|^[_$]+$/.test(name);
  22277. } // In case the Identifier is shorter than tab width, we can keep the
  22278. // first call in a single line, if it's an ExpressionStatement.
  22279. //
  22280. // d3.scaleLinear()
  22281. // .domain([0, 100])
  22282. // .range([0, width]);
  22283. //
  22284. function isShort(name) {
  22285. return name.length <= options.tabWidth;
  22286. }
  22287. function shouldNotWrap(groups) {
  22288. var parent = path$$1.getParentNode();
  22289. var isExpression = parent && parent.type === "ExpressionStatement";
  22290. var hasComputed = groups[1].length && groups[1][0].node.computed;
  22291. if (groups[0].length === 1) {
  22292. var firstNode = groups[0][0].node;
  22293. return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpression && isShort(firstNode.name) || hasComputed);
  22294. }
  22295. var lastNode = getLast$3(groups[0]).node;
  22296. return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
  22297. }
  22298. var shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
  22299. function printGroup(printedGroup) {
  22300. var printed = printedGroup.map(function (tuple) {
  22301. return tuple.printed;
  22302. }); // Checks if the last node (i.e. the parent node) needs parens and print
  22303. // accordingly
  22304. if (printedGroup.length > 0 && printedGroup[printedGroup.length - 1].needsParens) {
  22305. return concat$4(["("].concat(_toConsumableArray(printed), [")"]));
  22306. }
  22307. return concat$4(printed);
  22308. }
  22309. function printIndentedGroup(groups) {
  22310. if (groups.length === 0) {
  22311. return "";
  22312. }
  22313. return indent$2(group$1(concat$4([hardline$3, join$2(hardline$3, groups.map(printGroup))])));
  22314. }
  22315. var printedGroups = groups.map(printGroup);
  22316. var oneLine = concat$4(printedGroups);
  22317. var cutoff = shouldMerge ? 3 : 2;
  22318. var flatGroups = groups.slice(0, cutoff).reduce(function (res, group) {
  22319. return res.concat(group);
  22320. }, []);
  22321. var hasComment = flatGroups.slice(1, -1).some(function (node) {
  22322. return hasLeadingComment(node.node);
  22323. }) || flatGroups.slice(0, -1).some(function (node) {
  22324. return hasTrailingComment(node.node);
  22325. }) || groups[cutoff] && hasLeadingComment(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
  22326. // render everything concatenated together.
  22327. if (groups.length <= cutoff && !hasComment) {
  22328. return group$1(oneLine);
  22329. } // Find out the last node in the first group and check if it has an
  22330. // empty line after
  22331. var lastNodeBeforeIndent = getLast$3(shouldMerge ? groups.slice(1, 2)[0] : groups[0]).node;
  22332. var shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "CallExpression" && lastNodeBeforeIndent.type !== "OptionalCallExpression" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  22333. 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))]);
  22334. var callExpressions = printedNodes.map(function (_ref) {
  22335. var node = _ref.node;
  22336. return node;
  22337. }).filter(isCallOrOptionalCallExpression); // We don't want to print in one line if there's:
  22338. // * A comment.
  22339. // * 3 or more chained calls.
  22340. // * Any group but the last one has a hard line.
  22341. // If the last group is a function it's okay to inline if it fits.
  22342. if (hasComment || callExpressions.length >= 3 || printedGroups.slice(0, -1).some(willBreak$1) ||
  22343. /**
  22344. * scopes.filter(scope => scope.value !== '').map((scope, i) => {
  22345. * // multi line content
  22346. * })
  22347. */
  22348. function (lastGroupDoc, lastGroupNode) {
  22349. return isCallOrOptionalCallExpression(lastGroupNode) && willBreak$1(lastGroupDoc);
  22350. }(getLast$3(printedGroups), getLast$3(getLast$3(groups)).node) && callExpressions.slice(0, -1).some(function (n) {
  22351. return n.arguments.some(isFunctionOrArrowExpression);
  22352. })) {
  22353. return group$1(expanded);
  22354. }
  22355. return concat$4([// We only need to check `oneLine` because if `expanded` is chosen
  22356. // that means that the parent group has already been broken
  22357. // naturally
  22358. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$2 : "", conditionalGroup$1([oneLine, expanded])]);
  22359. }
  22360. function isCallOrOptionalCallExpression(node) {
  22361. return node.type === "CallExpression" || node.type === "OptionalCallExpression";
  22362. }
  22363. function isJSXNode(node) {
  22364. return node.type === "JSXElement" || node.type === "JSXFragment";
  22365. }
  22366. function isEmptyJSXElement(node) {
  22367. if (node.children.length === 0) {
  22368. return true;
  22369. }
  22370. if (node.children.length > 1) {
  22371. return false;
  22372. } // if there is one text child and does not contain any meaningful text
  22373. // we can treat the element as empty.
  22374. var child = node.children[0];
  22375. return isLiteral(child) && !isMeaningfulJSXText(child);
  22376. } // Only space, newline, carriage return, and tab are treated as whitespace
  22377. // inside JSX.
  22378. var jsxWhitespaceChars = " \n\r\t";
  22379. var containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]");
  22380. var matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)"); // Meaningful if it contains non-whitespace characters,
  22381. // or it contains whitespace without a new line.
  22382. function isMeaningfulJSXText(node) {
  22383. return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
  22384. }
  22385. function conditionalExpressionChainContainsJSX(node) {
  22386. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  22387. } // If we have nested conditional expressions, we want to print them in JSX mode
  22388. // if there's at least one JSXElement somewhere in the tree.
  22389. //
  22390. // A conditional expression chain like this should be printed in normal mode,
  22391. // because there aren't JSXElements anywhere in it:
  22392. //
  22393. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  22394. //
  22395. // But a conditional expression chain like this should be printed in JSX mode,
  22396. // because there is a JSXElement in the last ConditionalExpression:
  22397. //
  22398. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  22399. //
  22400. // This type of ConditionalExpression chain is structured like this in the AST:
  22401. //
  22402. // ConditionalExpression {
  22403. // test: ...,
  22404. // consequent: ...,
  22405. // alternate: ConditionalExpression {
  22406. // test: ...,
  22407. // consequent: ...,
  22408. // alternate: ConditionalExpression {
  22409. // test: ...,
  22410. // consequent: ...,
  22411. // alternate: ...,
  22412. // }
  22413. // }
  22414. // }
  22415. //
  22416. // We want to traverse over that shape and convert it into a flat structure so
  22417. // that we can find if there's a JSXElement somewhere inside.
  22418. function getConditionalChainContents(node) {
  22419. // Given this code:
  22420. //
  22421. // // Using a ConditionalExpression as the consequent is uncommon, but should
  22422. // // be handled.
  22423. // A ? B : C ? D : E ? F ? G : H : I
  22424. //
  22425. // which has this AST:
  22426. //
  22427. // ConditionalExpression {
  22428. // test: Identifier(A),
  22429. // consequent: Identifier(B),
  22430. // alternate: ConditionalExpression {
  22431. // test: Identifier(C),
  22432. // consequent: Identifier(D),
  22433. // alternate: ConditionalExpression {
  22434. // test: Identifier(E),
  22435. // consequent: ConditionalExpression {
  22436. // test: Identifier(F),
  22437. // consequent: Identifier(G),
  22438. // alternate: Identifier(H),
  22439. // },
  22440. // alternate: Identifier(I),
  22441. // }
  22442. // }
  22443. // }
  22444. //
  22445. // we should return this Array:
  22446. //
  22447. // [
  22448. // Identifier(A),
  22449. // Identifier(B),
  22450. // Identifier(C),
  22451. // Identifier(D),
  22452. // Identifier(E),
  22453. // Identifier(F),
  22454. // Identifier(G),
  22455. // Identifier(H),
  22456. // Identifier(I)
  22457. // ];
  22458. //
  22459. // This loses the information about whether each node was the test,
  22460. // consequent, or alternate, but we don't care about that here- we are only
  22461. // flattening this structure to find if there's any JSXElements inside.
  22462. var nonConditionalExpressions = [];
  22463. function recurse(node) {
  22464. if (node.type === "ConditionalExpression") {
  22465. recurse(node.test);
  22466. recurse(node.consequent);
  22467. recurse(node.alternate);
  22468. } else {
  22469. nonConditionalExpressions.push(node);
  22470. }
  22471. }
  22472. recurse(node);
  22473. return nonConditionalExpressions;
  22474. } // Detect an expression node representing `{" "}`
  22475. function isJSXWhitespaceExpression(node) {
  22476. return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
  22477. }
  22478. function separatorNoWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  22479. if (isFacebookTranslationTag) {
  22480. return "";
  22481. }
  22482. if (childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement) {
  22483. return child.length === 1 ? softline$1 : hardline$3;
  22484. }
  22485. return softline$1;
  22486. }
  22487. function separatorWithWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  22488. if (isFacebookTranslationTag) {
  22489. return hardline$3;
  22490. }
  22491. if (child.length === 1) {
  22492. return childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement ? hardline$3 : softline$1;
  22493. }
  22494. return hardline$3;
  22495. } // JSX Children are strange, mostly for two reasons:
  22496. // 1. JSX reads newlines into string values, instead of skipping them like JS
  22497. // 2. up to one whitespace between elements within a line is significant,
  22498. // but not between lines.
  22499. //
  22500. // Leading, trailing, and lone whitespace all need to
  22501. // turn themselves into the rather ugly `{' '}` when breaking.
  22502. //
  22503. // We print JSX using the `fill` doc primitive.
  22504. // This requires that we give it an array of alternating
  22505. // content and whitespace elements.
  22506. // To ensure this we add dummy `""` content elements as needed.
  22507. function printJSXChildren(path$$1, options, print, jsxWhitespace, isFacebookTranslationTag) {
  22508. var n = path$$1.getValue();
  22509. var children = []; // using `map` instead of `each` because it provides `i`
  22510. path$$1.map(function (childPath, i) {
  22511. var child = childPath.getValue();
  22512. if (isLiteral(child)) {
  22513. var text = rawText(child); // Contains a non-whitespace character
  22514. if (isMeaningfulJSXText(child)) {
  22515. var words = text.split(matchJsxWhitespaceRegex); // Starts with whitespace
  22516. if (words[0] === "") {
  22517. children.push("");
  22518. words.shift();
  22519. if (/\n/.test(words[0])) {
  22520. var next = n.children[i + 1];
  22521. children.push(separatorWithWhitespace(isFacebookTranslationTag, words[1], child, next));
  22522. } else {
  22523. children.push(jsxWhitespace);
  22524. }
  22525. words.shift();
  22526. }
  22527. var endWhitespace; // Ends with whitespace
  22528. if (getLast$3(words) === "") {
  22529. words.pop();
  22530. endWhitespace = words.pop();
  22531. } // This was whitespace only without a new line.
  22532. if (words.length === 0) {
  22533. return;
  22534. }
  22535. words.forEach(function (word, i) {
  22536. if (i % 2 === 1) {
  22537. children.push(line$3);
  22538. } else {
  22539. children.push(word);
  22540. }
  22541. });
  22542. if (endWhitespace !== undefined) {
  22543. if (/\n/.test(endWhitespace)) {
  22544. var _next = n.children[i + 1];
  22545. children.push(separatorWithWhitespace(isFacebookTranslationTag, getLast$3(children), child, _next));
  22546. } else {
  22547. children.push(jsxWhitespace);
  22548. }
  22549. } else {
  22550. var _next2 = n.children[i + 1];
  22551. children.push(separatorNoWhitespace(isFacebookTranslationTag, getLast$3(children), child, _next2));
  22552. }
  22553. } else if (/\n/.test(text)) {
  22554. // Keep (up to one) blank line between tags/expressions/text.
  22555. // Note: We don't keep blank lines between text elements.
  22556. if (text.match(/\n/g).length > 1) {
  22557. children.push("");
  22558. children.push(hardline$3);
  22559. }
  22560. } else {
  22561. children.push("");
  22562. children.push(jsxWhitespace);
  22563. }
  22564. } else {
  22565. var printedChild = print(childPath);
  22566. children.push(printedChild);
  22567. var _next3 = n.children[i + 1];
  22568. var directlyFollowedByMeaningfulText = _next3 && isMeaningfulJSXText(_next3);
  22569. if (directlyFollowedByMeaningfulText) {
  22570. var firstWord = rawText(_next3).trim().split(matchJsxWhitespaceRegex)[0];
  22571. children.push(separatorNoWhitespace(isFacebookTranslationTag, firstWord, child, _next3));
  22572. } else {
  22573. children.push(hardline$3);
  22574. }
  22575. }
  22576. }, "children");
  22577. return children;
  22578. } // JSX expands children from the inside-out, instead of the outside-in.
  22579. // This is both to break children before attributes,
  22580. // and to ensure that when children break, their parents do as well.
  22581. //
  22582. // Any element that is written without any newlines and fits on a single line
  22583. // is left that way.
  22584. // Not only that, any user-written-line containing multiple JSX siblings
  22585. // should also be kept on one line if possible,
  22586. // so each user-written-line is wrapped in its own group.
  22587. //
  22588. // Elements that contain newlines or don't fit on a single line (recursively)
  22589. // are fully-split, using hardline and shouldBreak: true.
  22590. //
  22591. // To support that case properly, all leading and trailing spaces
  22592. // are stripped from the list of children, and replaced with a single hardline.
  22593. function printJSXElement(path$$1, options, print) {
  22594. var n = path$$1.getValue();
  22595. if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
  22596. return concat$4([path$$1.call(print, "openingElement"), path$$1.call(print, "closingElement")]);
  22597. }
  22598. var openingLines = n.type === "JSXElement" ? path$$1.call(print, "openingElement") : path$$1.call(print, "openingFragment");
  22599. var closingLines = n.type === "JSXElement" ? path$$1.call(print, "closingElement") : path$$1.call(print, "closingFragment");
  22600. if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
  22601. return concat$4([openingLines, concat$4(path$$1.map(print, "children")), closingLines]);
  22602. } // Convert `{" "}` to text nodes containing a space.
  22603. // This makes it easy to turn them into `jsxWhitespace` which
  22604. // can then print as either a space or `{" "}` when breaking.
  22605. n.children = n.children.map(function (child) {
  22606. if (isJSXWhitespaceExpression(child)) {
  22607. return {
  22608. type: "JSXText",
  22609. value: " ",
  22610. raw: " "
  22611. };
  22612. }
  22613. return child;
  22614. });
  22615. var containsTag = n.children.filter(isJSXNode).length > 0;
  22616. var containsMultipleExpressions = n.children.filter(function (child) {
  22617. return child.type === "JSXExpressionContainer";
  22618. }).length > 1;
  22619. var containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
  22620. var forcedBreak = willBreak$1(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
  22621. var rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  22622. var jsxWhitespace = ifBreak$1(concat$4([rawJsxWhitespace, softline$1]), " ");
  22623. var isFacebookTranslationTag = n.openingElement && n.openingElement.name && n.openingElement.name.name === "fbt";
  22624. var children = printJSXChildren(path$$1, options, print, jsxWhitespace, isFacebookTranslationTag);
  22625. var containsText = n.children.filter(function (child) {
  22626. return isMeaningfulJSXText(child);
  22627. }).length > 0; // We can end up we multiple whitespace elements with empty string
  22628. // content between them.
  22629. // We need to remove empty whitespace and softlines before JSX whitespace
  22630. // to get the correct output.
  22631. for (var i = children.length - 2; i >= 0; i--) {
  22632. var isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  22633. var isPairOfHardlines = children[i] === hardline$3 && children[i + 1] === "" && children[i + 2] === hardline$3;
  22634. var isLineFollowedByJSXWhitespace = (children[i] === softline$1 || children[i] === hardline$3) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  22635. var isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$1 || children[i + 2] === hardline$3);
  22636. var isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  22637. var isPairOfHardOrSoftLines = children[i] === softline$1 && children[i + 1] === "" && children[i + 2] === hardline$3 || children[i] === hardline$3 && children[i + 1] === "" && children[i + 2] === softline$1;
  22638. if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace || isPairOfHardOrSoftLines) {
  22639. children.splice(i, 2);
  22640. } else if (isJSXWhitespaceFollowedByLine) {
  22641. children.splice(i + 1, 2);
  22642. }
  22643. } // Trim trailing lines (or empty strings)
  22644. while (children.length && (isLineNext$1(getLast$3(children)) || isEmpty$1(getLast$3(children)))) {
  22645. children.pop();
  22646. } // Trim leading lines (or empty strings)
  22647. while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
  22648. children.shift();
  22649. children.shift();
  22650. } // Tweak how we format children if outputting this element over multiple lines.
  22651. // Also detect whether we will force this element to output over multiple lines.
  22652. var multilineChildren = [];
  22653. children.forEach(function (child, i) {
  22654. // There are a number of situations where we need to ensure we display
  22655. // whitespace as `{" "}` when outputting this element over multiple lines.
  22656. if (child === jsxWhitespace) {
  22657. if (i === 1 && children[i - 1] === "") {
  22658. if (children.length === 2) {
  22659. // Solitary whitespace
  22660. multilineChildren.push(rawJsxWhitespace);
  22661. return;
  22662. } // Leading whitespace
  22663. multilineChildren.push(concat$4([rawJsxWhitespace, hardline$3]));
  22664. return;
  22665. } else if (i === children.length - 1) {
  22666. // Trailing whitespace
  22667. multilineChildren.push(rawJsxWhitespace);
  22668. return;
  22669. } else if (children[i - 1] === "" && children[i - 2] === hardline$3) {
  22670. // Whitespace after line break
  22671. multilineChildren.push(rawJsxWhitespace);
  22672. return;
  22673. }
  22674. }
  22675. multilineChildren.push(child);
  22676. if (willBreak$1(child)) {
  22677. forcedBreak = true;
  22678. }
  22679. }); // If there is text we use `fill` to fit as much onto each line as possible.
  22680. // When there is no text (just tags and expressions) we use `group`
  22681. // to output each on a separate line.
  22682. var content = containsText ? fill$2(multilineChildren) : group$1(concat$4(multilineChildren), {
  22683. shouldBreak: true
  22684. });
  22685. var multiLineElem = group$1(concat$4([openingLines, indent$2(concat$4([hardline$3, content])), hardline$3, closingLines]));
  22686. if (forcedBreak) {
  22687. return multiLineElem;
  22688. }
  22689. return conditionalGroup$1([group$1(concat$4([openingLines, concat$4(children), closingLines])), multiLineElem]);
  22690. }
  22691. function maybeWrapJSXElementInParens(path$$1, elem) {
  22692. var parent = path$$1.getParentNode();
  22693. if (!parent) {
  22694. return elem;
  22695. }
  22696. var NO_WRAP_PARENTS = {
  22697. ArrayExpression: true,
  22698. JSXAttribute: true,
  22699. JSXElement: true,
  22700. JSXExpressionContainer: true,
  22701. JSXFragment: true,
  22702. ExpressionStatement: true,
  22703. CallExpression: true,
  22704. OptionalCallExpression: true,
  22705. ConditionalExpression: true,
  22706. JsExpressionRoot: true
  22707. };
  22708. if (NO_WRAP_PARENTS[parent.type]) {
  22709. return elem;
  22710. }
  22711. var shouldBreak = matchAncestorTypes$1(path$$1, ["ArrowFunctionExpression", "CallExpression", "JSXExpressionContainer"]);
  22712. return group$1(concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, elem])), softline$1, ifBreak$1(")")]), {
  22713. shouldBreak
  22714. });
  22715. }
  22716. function isBinaryish(node) {
  22717. return node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression";
  22718. }
  22719. function isMemberish(node) {
  22720. return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && node.object;
  22721. }
  22722. function shouldInlineLogicalExpression(node) {
  22723. if (node.type !== "LogicalExpression") {
  22724. return false;
  22725. }
  22726. if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
  22727. return true;
  22728. }
  22729. if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
  22730. return true;
  22731. }
  22732. if (isJSXNode(node.right)) {
  22733. return true;
  22734. }
  22735. return false;
  22736. } // For binary expressions to be consistent, we need to group
  22737. // subsequent operators with the same precedence level under a single
  22738. // group. Otherwise they will be nested such that some of them break
  22739. // onto new lines but not all. Operators with the same precedence
  22740. // level should either all break or not. Because we group them by
  22741. // precedence level and the AST is structured based on precedence
  22742. // level, things are naturally broken up correctly, i.e. `&&` is
  22743. // broken before `+`.
  22744. function printBinaryishExpressions(path$$1, print, options, isNested, isInsideParenthesis) {
  22745. var parts = [];
  22746. var node = path$$1.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
  22747. if (isBinaryish(node)) {
  22748. // Put all operators with the same precedence level in the same
  22749. // group. The reason we only need to do this with the `left`
  22750. // expression is because given an expression like `1 + 2 - 3`, it
  22751. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  22752. // is where the rest of the expression will exist. Binary
  22753. // expressions on the right side mean they have a difference
  22754. // precedence level and should be treated as a separate group, so
  22755. // print them normally. (This doesn't hold for the `**` operator,
  22756. // which is unique in that it is right-associative.)
  22757. if (shouldFlatten$1(node.operator, node.left.operator)) {
  22758. // Flatten them out by recursively calling this function.
  22759. parts = parts.concat(path$$1.call(function (left) {
  22760. return printBinaryishExpressions(left, print, options,
  22761. /* isNested */
  22762. true, isInsideParenthesis);
  22763. }, "left"));
  22764. } else {
  22765. parts.push(path$$1.call(print, "left"));
  22766. }
  22767. var shouldInline = shouldInlineLogicalExpression(node);
  22768. var lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment(options.originalText, node.right, options);
  22769. var operator = node.type === "NGPipeExpression" ? "|" : node.operator;
  22770. var rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$1(indent$2(concat$4([softline$1, ": ", join$2(concat$4([softline$1, ":", ifBreak$1(" ")]), path$$1.map(print, "arguments").map(function (arg) {
  22771. return align$1(2, group$1(arg));
  22772. }))]))) : "";
  22773. var right = shouldInline ? concat$4([operator, " ", path$$1.call(print, "right"), rightSuffix]) : concat$4([lineBeforeOperator ? softline$1 : "", operator, lineBeforeOperator ? " " : line$3, path$$1.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
  22774. // in order to avoid having a small right part like -1 be on its own line.
  22775. var parent = path$$1.getParentNode();
  22776. var shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
  22777. parts.push(" ", shouldGroup ? group$1(right) : right); // The root comments are already printed, but we need to manually print
  22778. // the other ones since we don't call the normal print on BinaryExpression,
  22779. // only for the left and right parts
  22780. if (isNested && node.comments) {
  22781. parts = comments.printComments(path$$1, function () {
  22782. return concat$4(parts);
  22783. }, options);
  22784. }
  22785. } else {
  22786. // Our stopping case. Simply print the node normally.
  22787. parts.push(path$$1.call(print));
  22788. }
  22789. return parts;
  22790. }
  22791. function printAssignmentRight(leftNode, rightNode, printedRight, options) {
  22792. if (hasLeadingOwnLineComment(options.originalText, rightNode, options)) {
  22793. return indent$2(concat$4([hardline$3, printedRight]));
  22794. }
  22795. var canBreak = isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode) || rightNode.type === "ConditionalExpression" && isBinaryish(rightNode.test) && !shouldInlineLogicalExpression(rightNode.test) || rightNode.type === "StringLiteralTypeAnnotation" || rightNode.type === "ClassExpression" && rightNode.decorators && rightNode.decorators.length || (leftNode.type === "Identifier" || isStringLiteral(leftNode) || leftNode.type === "MemberExpression") && (isStringLiteral(rightNode) || isMemberExpressionChain(rightNode)) && // do not put values on a separate line from the key in json
  22796. options.parser !== "json" && options.parser !== "json5" || rightNode.type === "SequenceExpression";
  22797. if (canBreak) {
  22798. return group$1(indent$2(concat$4([line$3, printedRight])));
  22799. }
  22800. return concat$4([" ", printedRight]);
  22801. }
  22802. function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
  22803. if (!rightNode) {
  22804. return printedLeft;
  22805. }
  22806. var printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
  22807. return group$1(concat$4([printedLeft, operator, printed]));
  22808. }
  22809. function adjustClause(node, clause, forceSpace) {
  22810. if (node.type === "EmptyStatement") {
  22811. return ";";
  22812. }
  22813. if (node.type === "BlockStatement" || forceSpace) {
  22814. return concat$4([" ", clause]);
  22815. }
  22816. return indent$2(concat$4([line$3, clause]));
  22817. }
  22818. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  22819. var raw = rawText(node);
  22820. var isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  22821. return printString$1(raw, options, isDirectiveLiteral);
  22822. }
  22823. function printRegex(node) {
  22824. var flags = node.flags.split("").sort().join("");
  22825. return `/${node.pattern}/${flags}`;
  22826. }
  22827. function isLastStatement(path$$1) {
  22828. var parent = path$$1.getParentNode();
  22829. if (!parent) {
  22830. return true;
  22831. }
  22832. var node = path$$1.getValue();
  22833. var body = (parent.body || parent.consequent).filter(function (stmt) {
  22834. return stmt.type !== "EmptyStatement";
  22835. });
  22836. return body && body[body.length - 1] === node;
  22837. }
  22838. function hasLeadingComment(node) {
  22839. return node.comments && node.comments.some(function (comment) {
  22840. return comment.leading;
  22841. });
  22842. }
  22843. function hasTrailingComment(node) {
  22844. return node.comments && node.comments.some(function (comment) {
  22845. return comment.trailing;
  22846. });
  22847. }
  22848. function hasLeadingOwnLineComment(text, node, options) {
  22849. if (isJSXNode(node)) {
  22850. return hasNodeIgnoreComment$1(node);
  22851. }
  22852. var res = node.comments && node.comments.some(function (comment) {
  22853. return comment.leading && hasNewline$2(text, options.locEnd(comment));
  22854. });
  22855. return res;
  22856. }
  22857. function isFlowAnnotationComment(text, typeAnnotation, options) {
  22858. var start = options.locStart(typeAnnotation);
  22859. var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
  22860. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  22861. }
  22862. function exprNeedsASIProtection(path$$1, options) {
  22863. var node = path$$1.getValue();
  22864. 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.object || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
  22865. if (maybeASIProblem) {
  22866. return true;
  22867. }
  22868. if (!hasNakedLeftSide(node)) {
  22869. return false;
  22870. }
  22871. return path$$1.call.apply(path$$1, [function (childPath) {
  22872. return exprNeedsASIProtection(childPath, options);
  22873. }].concat(getLeftSidePathName(path$$1, node)));
  22874. }
  22875. function stmtNeedsASIProtection(path$$1, options) {
  22876. var node = path$$1.getNode();
  22877. if (node.type !== "ExpressionStatement") {
  22878. return false;
  22879. }
  22880. return path$$1.call(function (childPath) {
  22881. return exprNeedsASIProtection(childPath, options);
  22882. }, "expression");
  22883. }
  22884. function classPropMayCauseASIProblems(path$$1) {
  22885. var node = path$$1.getNode();
  22886. if (node.type !== "ClassProperty") {
  22887. return false;
  22888. }
  22889. var name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
  22890. // so isn't properly tested yet.
  22891. if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
  22892. return true;
  22893. }
  22894. }
  22895. function classChildNeedsASIProtection(node) {
  22896. if (!node) {
  22897. return;
  22898. }
  22899. if (node.static || node.accessibility // TypeScript
  22900. ) {
  22901. return false;
  22902. }
  22903. if (!node.computed) {
  22904. var name = node.key && node.key.name;
  22905. if (name === "in" || name === "instanceof") {
  22906. return true;
  22907. }
  22908. }
  22909. switch (node.type) {
  22910. case "ClassProperty":
  22911. case "TSAbstractClassProperty":
  22912. return node.computed;
  22913. case "MethodDefinition": // Flow
  22914. case "TSAbstractMethodDefinition": // TypeScript
  22915. case "ClassMethod":
  22916. case "ClassPrivateMethod":
  22917. {
  22918. // Babel
  22919. var isAsync = node.value ? node.value.async : node.async;
  22920. var isGenerator = node.value ? node.value.generator : node.generator;
  22921. if (isAsync || node.kind === "get" || node.kind === "set") {
  22922. return false;
  22923. }
  22924. if (node.computed || isGenerator) {
  22925. return true;
  22926. }
  22927. return false;
  22928. }
  22929. default:
  22930. /* istanbul ignore next */
  22931. return false;
  22932. }
  22933. } // This recurses the return argument, looking for the first token
  22934. // (the leftmost leaf node) and, if it (or its parents) has any
  22935. // leadingComments, returns true (so it can be wrapped in parens).
  22936. function returnArgumentHasLeadingComment(options, argument) {
  22937. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  22938. return true;
  22939. }
  22940. if (hasNakedLeftSide(argument)) {
  22941. var leftMost = argument;
  22942. var newLeftMost;
  22943. while (newLeftMost = getLeftSide(leftMost)) {
  22944. leftMost = newLeftMost;
  22945. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  22946. return true;
  22947. }
  22948. }
  22949. }
  22950. return false;
  22951. }
  22952. function isMemberExpressionChain(node) {
  22953. if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
  22954. return false;
  22955. }
  22956. if (node.object.type === "Identifier") {
  22957. return true;
  22958. }
  22959. return isMemberExpressionChain(node.object);
  22960. } // Hack to differentiate between the following two which have the same ast
  22961. // type T = { method: () => void };
  22962. // type T = { method(): void };
  22963. function isObjectTypePropertyAFunction(node, options) {
  22964. return (node.type === "ObjectTypeProperty" || node.type === "ObjectTypeInternalSlot") && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
  22965. } // TODO: This is a bad hack and we need a better way to distinguish between
  22966. // arrow functions and otherwise
  22967. function isFunctionNotation(node, options) {
  22968. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  22969. }
  22970. function isGetterOrSetter(node) {
  22971. return node.kind === "get" || node.kind === "set";
  22972. }
  22973. function sameLocStart(nodeA, nodeB, options) {
  22974. return options.locStart(nodeA) === options.locStart(nodeB);
  22975. } // Hack to differentiate between the following two which have the same ast
  22976. // declare function f(a): void;
  22977. // var f: (a) => void;
  22978. function isTypeAnnotationAFunction(node, options) {
  22979. return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
  22980. }
  22981. function isNodeStartingWithDeclare(node, options) {
  22982. if (!(options.parser === "flow" || options.parser === "typescript")) {
  22983. return false;
  22984. }
  22985. return options.originalText.slice(0, options.locStart(node)).match(/declare[ \t]*$/) || options.originalText.slice(node.range[0], node.range[1]).startsWith("declare ");
  22986. }
  22987. function shouldHugType(node) {
  22988. if (isSimpleFlowType(node) || isObjectType(node)) {
  22989. return true;
  22990. }
  22991. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  22992. var voidCount = node.types.filter(function (n) {
  22993. return n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword";
  22994. }).length;
  22995. var objectCount = node.types.filter(function (n) {
  22996. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
  22997. n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference";
  22998. }).length;
  22999. if (node.types.length - 1 === voidCount && objectCount > 0) {
  23000. return true;
  23001. }
  23002. }
  23003. return false;
  23004. }
  23005. function shouldHugArguments(fun) {
  23006. 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;
  23007. }
  23008. function templateLiteralHasNewLines(template) {
  23009. return template.quasis.some(function (quasi) {
  23010. return quasi.value.raw.includes("\n");
  23011. });
  23012. }
  23013. function isTemplateOnItsOwnLine(n, text, options) {
  23014. return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$2(text, options.locStart(n), {
  23015. backwards: true
  23016. });
  23017. }
  23018. function printArrayItems(path$$1, options, printPath, print) {
  23019. var printedElements = [];
  23020. var separatorParts = [];
  23021. path$$1.each(function (childPath) {
  23022. printedElements.push(concat$4(separatorParts));
  23023. printedElements.push(group$1(print(childPath)));
  23024. separatorParts = [",", line$3];
  23025. if (childPath.getValue() && isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  23026. separatorParts.push(softline$1);
  23027. }
  23028. }, printPath);
  23029. return concat$4(printedElements);
  23030. }
  23031. function hasDanglingComments(node) {
  23032. return node.comments && node.comments.some(function (comment) {
  23033. return !comment.leading && !comment.trailing;
  23034. });
  23035. }
  23036. function needsHardlineAfterDanglingComment(node) {
  23037. if (!node.comments) {
  23038. return false;
  23039. }
  23040. var lastDanglingComment = getLast$3(node.comments.filter(function (comment) {
  23041. return !comment.leading && !comment.trailing;
  23042. }));
  23043. return lastDanglingComment && !comments$3.isBlockComment(lastDanglingComment);
  23044. }
  23045. function isLiteral(node) {
  23046. 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";
  23047. }
  23048. function isStringPropSafeToCoerceToIdentifier(node, options) {
  23049. return isStringLiteral(node.key) && isIdentifierName(node.key.value) && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty");
  23050. }
  23051. function isNumericLiteral(node) {
  23052. return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
  23053. }
  23054. function isStringLiteral(node) {
  23055. return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
  23056. }
  23057. function isObjectType(n) {
  23058. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  23059. }
  23060. var unitTestRe = /^(skip|[fx]?(it|describe|test))$/; // eg; `describe("some string", (done) => {})`
  23061. function isTestCall(n, parent) {
  23062. if (n.type !== "CallExpression") {
  23063. return false;
  23064. }
  23065. if (n.arguments.length === 1) {
  23066. if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
  23067. return isFunctionOrArrowExpression(n.arguments[0]);
  23068. }
  23069. if (isUnitTestSetUp(n)) {
  23070. return isAngularTestWrapper(n.arguments[0]);
  23071. }
  23072. } else if (n.arguments.length === 2 || n.arguments.length === 3) {
  23073. if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
  23074. // it("name", () => { ... }, 2500)
  23075. if (n.arguments[2] && !isNumericLiteral(n.arguments[2])) {
  23076. return false;
  23077. }
  23078. return (n.arguments.length === 2 ? isFunctionOrArrowExpression(n.arguments[1]) : isFunctionOrArrowExpressionWithBody(n.arguments[1]) && n.arguments[1].params.length <= 1) || isAngularTestWrapper(n.arguments[1]);
  23079. }
  23080. }
  23081. return false;
  23082. }
  23083. function isSkipOrOnlyBlock(node) {
  23084. 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");
  23085. }
  23086. function isTemplateLiteral(node) {
  23087. return node.type === "TemplateLiteral";
  23088. } // `inject` is used in AngularJS 1.x, `async` in Angular 2+
  23089. // example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
  23090. function isAngularTestWrapper(node) {
  23091. return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject" || node.callee.name === "fakeAsync");
  23092. }
  23093. function isFunctionOrArrowExpression(node) {
  23094. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
  23095. }
  23096. function isFunctionOrArrowExpressionWithBody(node) {
  23097. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement";
  23098. }
  23099. function isUnitTestSetUp(n) {
  23100. var unitTestSetUpRe = /^(before|after)(Each|All)$/;
  23101. return n.callee.type === "Identifier" && unitTestSetUpRe.test(n.callee.name) && n.arguments.length === 1;
  23102. }
  23103. function isTheOnlyJSXElementInMarkdown(options, path$$1) {
  23104. if (options.parentParser !== "markdown" && options.parentParser !== "mdx") {
  23105. return false;
  23106. }
  23107. var node = path$$1.getNode();
  23108. if (!node.expression || !isJSXNode(node.expression)) {
  23109. return false;
  23110. }
  23111. var parent = path$$1.getParentNode();
  23112. return parent.type === "Program" && parent.body.length == 1;
  23113. }
  23114. function willPrintOwnComments(path$$1
  23115. /*, options */
  23116. ) {
  23117. var node = path$$1.getValue();
  23118. var parent = path$$1.getParentNode();
  23119. return (node && (isJSXNode(node) || hasFlowShorthandAnnotationComment(node) || parent && parent.type === "CallExpression" && (hasFlowAnnotationComment(node.leadingComments) || hasFlowAnnotationComment(node.trailingComments))) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && !hasIgnoreComment$1(path$$1);
  23120. }
  23121. function canAttachComment(node) {
  23122. return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import";
  23123. }
  23124. function printComment$1(commentPath, options) {
  23125. var comment = commentPath.getValue();
  23126. switch (comment.type) {
  23127. case "CommentBlock":
  23128. case "Block":
  23129. {
  23130. if (isIndentableBlockComment(comment)) {
  23131. var printed = printIndentableBlockComment(comment); // We need to prevent an edge case of a previous trailing comment
  23132. // printed as a `lineSuffix` which causes the comments to be
  23133. // interleaved. See https://github.com/prettier/prettier/issues/4412
  23134. if (comment.trailing && !hasNewline$2(options.originalText, options.locStart(comment), {
  23135. backwards: true
  23136. })) {
  23137. return concat$4([hardline$3, printed]);
  23138. }
  23139. return printed;
  23140. }
  23141. var isInsideFlowComment = options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  23142. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  23143. }
  23144. case "CommentLine":
  23145. case "Line":
  23146. // Print shebangs with the proper comment characters
  23147. if (options.originalText.slice(options.locStart(comment)).startsWith("#!")) {
  23148. return "#!" + comment.value.trimRight();
  23149. }
  23150. return "//" + comment.value.trimRight();
  23151. default:
  23152. throw new Error("Not a comment: " + JSON.stringify(comment));
  23153. }
  23154. }
  23155. function isIndentableBlockComment(comment) {
  23156. // If the comment has multiple lines and every line starts with a star
  23157. // we can fix the indentation of each line. The stars in the `/*` and
  23158. // `*/` delimiters are not included in the comment value, so add them
  23159. // back first.
  23160. var lines = `*${comment.value}*`.split("\n");
  23161. return lines.length > 1 && lines.every(function (line) {
  23162. return line.trim()[0] === "*";
  23163. });
  23164. }
  23165. function printIndentableBlockComment(comment) {
  23166. var lines = comment.value.split("\n");
  23167. return concat$4(["/*", join$2(hardline$3, lines.map(function (line, index) {
  23168. return index === 0 ? line.trimRight() : " " + (index < lines.length - 1 ? line.trim() : line.trimLeft());
  23169. })), "*/"]);
  23170. }
  23171. function rawText(node) {
  23172. return node.extra ? node.extra.raw : node.raw;
  23173. }
  23174. function identity$1(x) {
  23175. return x;
  23176. }
  23177. var printerEstree = {
  23178. preprocess: preprocess_1,
  23179. print: genericPrint,
  23180. embed: embed_1,
  23181. insertPragma,
  23182. massageAstNode: clean_1,
  23183. hasPrettierIgnore,
  23184. willPrintOwnComments,
  23185. canAttachComment,
  23186. printComment: printComment$1,
  23187. isBlockComment: comments$3.isBlockComment,
  23188. handleComments: {
  23189. ownLine: comments$3.handleOwnLineComment,
  23190. endOfLine: comments$3.handleEndOfLineComment,
  23191. remaining: comments$3.handleRemainingComment
  23192. }
  23193. };
  23194. var _require$$0$builders$2 = doc.builders;
  23195. var concat$7 = _require$$0$builders$2.concat;
  23196. var hardline$5 = _require$$0$builders$2.hardline;
  23197. var indent$4 = _require$$0$builders$2.indent;
  23198. var join$5 = _require$$0$builders$2.join;
  23199. function genericPrint$1(path$$1, options, print) {
  23200. var node = path$$1.getValue();
  23201. switch (node.type) {
  23202. case "JsonRoot":
  23203. return concat$7([path$$1.call(print, "node"), hardline$5]);
  23204. case "ArrayExpression":
  23205. return node.elements.length === 0 ? "[]" : concat$7(["[", indent$4(concat$7([hardline$5, join$5(concat$7([",", hardline$5]), path$$1.map(print, "elements"))])), hardline$5, "]"]);
  23206. case "ObjectExpression":
  23207. return node.properties.length === 0 ? "{}" : concat$7(["{", indent$4(concat$7([hardline$5, join$5(concat$7([",", hardline$5]), path$$1.map(print, "properties"))])), hardline$5, "}"]);
  23208. case "ObjectProperty":
  23209. return concat$7([path$$1.call(print, "key"), ": ", path$$1.call(print, "value")]);
  23210. case "UnaryExpression":
  23211. return concat$7([node.operator === "+" ? "" : node.operator, path$$1.call(print, "argument")]);
  23212. case "NullLiteral":
  23213. return "null";
  23214. case "BooleanLiteral":
  23215. return node.value ? "true" : "false";
  23216. case "StringLiteral":
  23217. case "NumericLiteral":
  23218. return JSON.stringify(node.value);
  23219. case "Identifier":
  23220. return JSON.stringify(node.name);
  23221. default:
  23222. /* istanbul ignore next */
  23223. throw new Error("unknown type: " + JSON.stringify(node.type));
  23224. }
  23225. }
  23226. function clean$2(node, newNode
  23227. /*, parent*/
  23228. ) {
  23229. delete newNode.start;
  23230. delete newNode.end;
  23231. delete newNode.extra;
  23232. delete newNode.loc;
  23233. delete newNode.comments;
  23234. if (node.type === "Identifier") {
  23235. return {
  23236. type: "StringLiteral",
  23237. value: node.name
  23238. };
  23239. }
  23240. if (node.type === "UnaryExpression" && node.operator === "+") {
  23241. return newNode.argument;
  23242. }
  23243. }
  23244. var printerEstreeJson = {
  23245. preprocess: preprocess_1,
  23246. print: genericPrint$1,
  23247. massageAstNode: clean$2
  23248. };
  23249. var CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  23250. var commonOptions = {
  23251. bracketSpacing: {
  23252. since: "0.0.0",
  23253. category: CATEGORY_COMMON,
  23254. type: "boolean",
  23255. default: true,
  23256. description: "Print spaces between brackets.",
  23257. oppositeDescription: "Do not print spaces between brackets."
  23258. },
  23259. singleQuote: {
  23260. since: "0.0.0",
  23261. category: CATEGORY_COMMON,
  23262. type: "boolean",
  23263. default: false,
  23264. description: "Use single quotes instead of double quotes."
  23265. },
  23266. proseWrap: {
  23267. since: "1.8.2",
  23268. category: CATEGORY_COMMON,
  23269. type: "choice",
  23270. default: [{
  23271. since: "1.8.2",
  23272. value: true
  23273. }, {
  23274. since: "1.9.0",
  23275. value: "preserve"
  23276. }],
  23277. description: "How to wrap prose.",
  23278. choices: [{
  23279. since: "1.9.0",
  23280. value: "always",
  23281. description: "Wrap prose if it exceeds the print width."
  23282. }, {
  23283. since: "1.9.0",
  23284. value: "never",
  23285. description: "Do not wrap prose."
  23286. }, {
  23287. since: "1.9.0",
  23288. value: "preserve",
  23289. description: "Wrap prose as-is."
  23290. }, {
  23291. value: false,
  23292. deprecated: "1.9.0",
  23293. redirect: "never"
  23294. }, {
  23295. value: true,
  23296. deprecated: "1.9.0",
  23297. redirect: "always"
  23298. }]
  23299. }
  23300. };
  23301. var CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  23302. var options$3 = {
  23303. arrowParens: {
  23304. since: "1.9.0",
  23305. category: CATEGORY_JAVASCRIPT,
  23306. type: "choice",
  23307. default: "avoid",
  23308. description: "Include parentheses around a sole arrow function parameter.",
  23309. choices: [{
  23310. value: "avoid",
  23311. description: "Omit parens when possible. Example: `x => x`"
  23312. }, {
  23313. value: "always",
  23314. description: "Always include parens. Example: `(x) => x`"
  23315. }]
  23316. },
  23317. bracketSpacing: commonOptions.bracketSpacing,
  23318. jsxBracketSameLine: {
  23319. since: "0.17.0",
  23320. category: CATEGORY_JAVASCRIPT,
  23321. type: "boolean",
  23322. default: false,
  23323. description: "Put > on the last line instead of at a new line."
  23324. },
  23325. semi: {
  23326. since: "1.0.0",
  23327. category: CATEGORY_JAVASCRIPT,
  23328. type: "boolean",
  23329. default: true,
  23330. description: "Print semicolons.",
  23331. oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
  23332. },
  23333. singleQuote: commonOptions.singleQuote,
  23334. jsxSingleQuote: {
  23335. since: "1.15.0",
  23336. category: CATEGORY_JAVASCRIPT,
  23337. type: "boolean",
  23338. default: false,
  23339. description: "Use single quotes in JSX."
  23340. },
  23341. quoteProps: {
  23342. since: "1.17.0",
  23343. category: CATEGORY_JAVASCRIPT,
  23344. type: "choice",
  23345. default: "as-needed",
  23346. description: "Change when properties in objects are quoted.",
  23347. choices: [{
  23348. value: "as-needed",
  23349. description: "Only add quotes around object properties where required."
  23350. }, {
  23351. value: "consistent",
  23352. description: "If at least one property in an object requires quotes, quote all properties."
  23353. }, {
  23354. value: "preserve",
  23355. description: "Respect the input use of quotes in object properties."
  23356. }]
  23357. },
  23358. trailingComma: {
  23359. since: "0.0.0",
  23360. category: CATEGORY_JAVASCRIPT,
  23361. type: "choice",
  23362. default: [{
  23363. since: "0.0.0",
  23364. value: false
  23365. }, {
  23366. since: "0.19.0",
  23367. value: "none"
  23368. }],
  23369. description: "Print trailing commas wherever possible when multi-line.",
  23370. choices: [{
  23371. value: "none",
  23372. description: "No trailing commas."
  23373. }, {
  23374. value: "es5",
  23375. description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  23376. }, {
  23377. value: "all",
  23378. description: "Trailing commas wherever possible (including function arguments)."
  23379. }, {
  23380. value: true,
  23381. deprecated: "0.19.0",
  23382. redirect: "es5"
  23383. }, {
  23384. value: false,
  23385. deprecated: "0.19.0",
  23386. redirect: "none"
  23387. }]
  23388. }
  23389. };
  23390. var createLanguage = function createLanguage(linguistData, _ref) {
  23391. var extend = _ref.extend,
  23392. override = _ref.override;
  23393. var language = {};
  23394. for (var key in linguistData) {
  23395. var newKey = key === "languageId" ? "linguistLanguageId" : key;
  23396. language[newKey] = linguistData[key];
  23397. }
  23398. if (extend) {
  23399. for (var _key in extend) {
  23400. language[_key] = (language[_key] || []).concat(extend[_key]);
  23401. }
  23402. }
  23403. for (var _key2 in override) {
  23404. language[_key2] = override[_key2];
  23405. }
  23406. return language;
  23407. };
  23408. var name$1 = "JavaScript";
  23409. var type = "programming";
  23410. var tmScope = "source.js";
  23411. var aceMode = "javascript";
  23412. var codemirrorMode = "javascript";
  23413. var codemirrorMimeType = "text/javascript";
  23414. var color = "#f1e05a";
  23415. var aliases = ["js", "node"];
  23416. var extensions = [".js", "._js", ".bones", ".es", ".es6", ".frag", ".gs", ".jake", ".jsb", ".jscad", ".jsfl", ".jsm", ".jss", ".mjs", ".njs", ".pac", ".sjs", ".ssjs", ".xsjs", ".xsjslib"];
  23417. var filenames = ["Jakefile"];
  23418. var interpreters = ["node"];
  23419. var languageId = 183;
  23420. var javascript = {
  23421. name: name$1,
  23422. type: type,
  23423. tmScope: tmScope,
  23424. aceMode: aceMode,
  23425. codemirrorMode: codemirrorMode,
  23426. codemirrorMimeType: codemirrorMimeType,
  23427. color: color,
  23428. aliases: aliases,
  23429. extensions: extensions,
  23430. filenames: filenames,
  23431. interpreters: interpreters,
  23432. languageId: languageId
  23433. };
  23434. var javascript$1 = Object.freeze({
  23435. name: name$1,
  23436. type: type,
  23437. tmScope: tmScope,
  23438. aceMode: aceMode,
  23439. codemirrorMode: codemirrorMode,
  23440. codemirrorMimeType: codemirrorMimeType,
  23441. color: color,
  23442. aliases: aliases,
  23443. extensions: extensions,
  23444. filenames: filenames,
  23445. interpreters: interpreters,
  23446. languageId: languageId,
  23447. default: javascript
  23448. });
  23449. var name$2 = "JSX";
  23450. var type$1 = "programming";
  23451. var group$3 = "JavaScript";
  23452. var extensions$1 = [".jsx"];
  23453. var tmScope$1 = "source.js.jsx";
  23454. var aceMode$1 = "javascript";
  23455. var codemirrorMode$1 = "jsx";
  23456. var codemirrorMimeType$1 = "text/jsx";
  23457. var languageId$1 = 178;
  23458. var jsx = {
  23459. name: name$2,
  23460. type: type$1,
  23461. group: group$3,
  23462. extensions: extensions$1,
  23463. tmScope: tmScope$1,
  23464. aceMode: aceMode$1,
  23465. codemirrorMode: codemirrorMode$1,
  23466. codemirrorMimeType: codemirrorMimeType$1,
  23467. languageId: languageId$1
  23468. };
  23469. var jsx$1 = Object.freeze({
  23470. name: name$2,
  23471. type: type$1,
  23472. group: group$3,
  23473. extensions: extensions$1,
  23474. tmScope: tmScope$1,
  23475. aceMode: aceMode$1,
  23476. codemirrorMode: codemirrorMode$1,
  23477. codemirrorMimeType: codemirrorMimeType$1,
  23478. languageId: languageId$1,
  23479. default: jsx
  23480. });
  23481. var name$3 = "TypeScript";
  23482. var type$2 = "programming";
  23483. var color$1 = "#2b7489";
  23484. var aliases$1 = ["ts"];
  23485. var extensions$2 = [".ts", ".tsx"];
  23486. var tmScope$2 = "source.ts";
  23487. var aceMode$2 = "typescript";
  23488. var codemirrorMode$2 = "javascript";
  23489. var codemirrorMimeType$2 = "application/typescript";
  23490. var languageId$2 = 378;
  23491. var typescript = {
  23492. name: name$3,
  23493. type: type$2,
  23494. color: color$1,
  23495. aliases: aliases$1,
  23496. extensions: extensions$2,
  23497. tmScope: tmScope$2,
  23498. aceMode: aceMode$2,
  23499. codemirrorMode: codemirrorMode$2,
  23500. codemirrorMimeType: codemirrorMimeType$2,
  23501. languageId: languageId$2
  23502. };
  23503. var typescript$1 = Object.freeze({
  23504. name: name$3,
  23505. type: type$2,
  23506. color: color$1,
  23507. aliases: aliases$1,
  23508. extensions: extensions$2,
  23509. tmScope: tmScope$2,
  23510. aceMode: aceMode$2,
  23511. codemirrorMode: codemirrorMode$2,
  23512. codemirrorMimeType: codemirrorMimeType$2,
  23513. languageId: languageId$2,
  23514. default: typescript
  23515. });
  23516. var name$4 = "JSON";
  23517. var type$3 = "data";
  23518. var tmScope$3 = "source.json";
  23519. var group$4 = "JavaScript";
  23520. var aceMode$3 = "json";
  23521. var codemirrorMode$3 = "javascript";
  23522. var codemirrorMimeType$3 = "application/json";
  23523. var searchable = false;
  23524. var extensions$3 = [".json", ".avsc", ".geojson", ".gltf", ".JSON-tmLanguage", ".jsonl", ".tfstate", ".tfstate.backup", ".topojson", ".webapp", ".webmanifest"];
  23525. var filenames$1 = [".arcconfig", ".htmlhintrc", ".tern-config", ".tern-project", "composer.lock", "mcmod.info"];
  23526. var languageId$3 = 174;
  23527. var json$2 = {
  23528. name: name$4,
  23529. type: type$3,
  23530. tmScope: tmScope$3,
  23531. group: group$4,
  23532. aceMode: aceMode$3,
  23533. codemirrorMode: codemirrorMode$3,
  23534. codemirrorMimeType: codemirrorMimeType$3,
  23535. searchable: searchable,
  23536. extensions: extensions$3,
  23537. filenames: filenames$1,
  23538. languageId: languageId$3
  23539. };
  23540. var json$3 = Object.freeze({
  23541. name: name$4,
  23542. type: type$3,
  23543. tmScope: tmScope$3,
  23544. group: group$4,
  23545. aceMode: aceMode$3,
  23546. codemirrorMode: codemirrorMode$3,
  23547. codemirrorMimeType: codemirrorMimeType$3,
  23548. searchable: searchable,
  23549. extensions: extensions$3,
  23550. filenames: filenames$1,
  23551. languageId: languageId$3,
  23552. default: json$2
  23553. });
  23554. var name$5 = "JSON with Comments";
  23555. var type$4 = "data";
  23556. var group$5 = "JSON";
  23557. var tmScope$4 = "source.js";
  23558. var aceMode$4 = "javascript";
  23559. var codemirrorMode$4 = "javascript";
  23560. var codemirrorMimeType$4 = "text/javascript";
  23561. var aliases$2 = ["jsonc"];
  23562. var extensions$4 = [".sublime-build", ".sublime-commands", ".sublime-completions", ".sublime-keymap", ".sublime-macro", ".sublime-menu", ".sublime-mousemap", ".sublime-project", ".sublime-settings", ".sublime-theme", ".sublime-workspace", ".sublime_metrics", ".sublime_session"];
  23563. var filenames$2 = [".babelrc", ".eslintrc.json", ".jscsrc", ".jshintrc", ".jslintrc", "tsconfig.json"];
  23564. var languageId$4 = 423;
  23565. var jsonWithComments = {
  23566. name: name$5,
  23567. type: type$4,
  23568. group: group$5,
  23569. tmScope: tmScope$4,
  23570. aceMode: aceMode$4,
  23571. codemirrorMode: codemirrorMode$4,
  23572. codemirrorMimeType: codemirrorMimeType$4,
  23573. aliases: aliases$2,
  23574. extensions: extensions$4,
  23575. filenames: filenames$2,
  23576. languageId: languageId$4
  23577. };
  23578. var jsonWithComments$1 = Object.freeze({
  23579. name: name$5,
  23580. type: type$4,
  23581. group: group$5,
  23582. tmScope: tmScope$4,
  23583. aceMode: aceMode$4,
  23584. codemirrorMode: codemirrorMode$4,
  23585. codemirrorMimeType: codemirrorMimeType$4,
  23586. aliases: aliases$2,
  23587. extensions: extensions$4,
  23588. filenames: filenames$2,
  23589. languageId: languageId$4,
  23590. default: jsonWithComments
  23591. });
  23592. var name$6 = "JSON5";
  23593. var type$5 = "data";
  23594. var extensions$5 = [".json5"];
  23595. var tmScope$5 = "source.js";
  23596. var aceMode$5 = "javascript";
  23597. var codemirrorMode$5 = "javascript";
  23598. var codemirrorMimeType$5 = "application/json";
  23599. var languageId$5 = 175;
  23600. var json5 = {
  23601. name: name$6,
  23602. type: type$5,
  23603. extensions: extensions$5,
  23604. tmScope: tmScope$5,
  23605. aceMode: aceMode$5,
  23606. codemirrorMode: codemirrorMode$5,
  23607. codemirrorMimeType: codemirrorMimeType$5,
  23608. languageId: languageId$5
  23609. };
  23610. var json5$1 = Object.freeze({
  23611. name: name$6,
  23612. type: type$5,
  23613. extensions: extensions$5,
  23614. tmScope: tmScope$5,
  23615. aceMode: aceMode$5,
  23616. codemirrorMode: codemirrorMode$5,
  23617. codemirrorMimeType: codemirrorMimeType$5,
  23618. languageId: languageId$5,
  23619. default: json5
  23620. });
  23621. var require$$0$21 = ( javascript$1 && javascript ) || javascript$1;
  23622. var require$$1$8 = ( jsx$1 && jsx ) || jsx$1;
  23623. var require$$2$10 = ( typescript$1 && typescript ) || typescript$1;
  23624. var require$$3$3 = ( json$3 && json$2 ) || json$3;
  23625. var require$$4$2 = ( jsonWithComments$1 && jsonWithComments ) || jsonWithComments$1;
  23626. var require$$5$1 = ( json5$1 && json5 ) || json5$1;
  23627. var languages = [createLanguage(require$$0$21, {
  23628. override: {
  23629. since: "0.0.0",
  23630. parsers: ["babel", "flow"],
  23631. vscodeLanguageIds: ["javascript"]
  23632. },
  23633. extend: {
  23634. interpreters: ["nodejs"]
  23635. }
  23636. }), createLanguage(require$$0$21, {
  23637. override: {
  23638. name: "Flow",
  23639. since: "0.0.0",
  23640. parsers: ["babel", "flow"],
  23641. vscodeLanguageIds: ["javascript"],
  23642. aliases: [],
  23643. filenames: [],
  23644. extensions: [".js.flow"]
  23645. }
  23646. }), createLanguage(require$$1$8, {
  23647. override: {
  23648. since: "0.0.0",
  23649. parsers: ["babel", "flow"],
  23650. vscodeLanguageIds: ["javascriptreact"]
  23651. }
  23652. }), createLanguage(require$$2$10, {
  23653. override: {
  23654. since: "1.4.0",
  23655. parsers: ["typescript"],
  23656. vscodeLanguageIds: ["typescript", "typescriptreact"]
  23657. }
  23658. }), createLanguage(require$$3$3, {
  23659. override: {
  23660. name: "JSON.stringify",
  23661. since: "1.13.0",
  23662. parsers: ["json-stringify"],
  23663. vscodeLanguageIds: ["json"],
  23664. extensions: [],
  23665. // .json file defaults to json instead of json-stringify
  23666. filenames: ["package.json", "package-lock.json", "composer.json"]
  23667. }
  23668. }), createLanguage(require$$3$3, {
  23669. override: {
  23670. since: "1.5.0",
  23671. parsers: ["json"],
  23672. vscodeLanguageIds: ["json"]
  23673. },
  23674. extend: {
  23675. filenames: [".prettierrc"]
  23676. }
  23677. }), createLanguage(require$$4$2, {
  23678. override: {
  23679. since: "1.5.0",
  23680. parsers: ["json"],
  23681. vscodeLanguageIds: ["jsonc"]
  23682. },
  23683. extend: {
  23684. filenames: [".eslintrc"]
  23685. }
  23686. }), createLanguage(require$$5$1, {
  23687. override: {
  23688. since: "1.13.0",
  23689. parsers: ["json5"],
  23690. vscodeLanguageIds: ["json5"]
  23691. }
  23692. })];
  23693. var printers = {
  23694. estree: printerEstree,
  23695. "estree-json": printerEstreeJson
  23696. };
  23697. var languageJs = {
  23698. languages,
  23699. options: options$3,
  23700. printers
  23701. };
  23702. var index$12 = ["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"];
  23703. var htmlTagNames = Object.freeze({
  23704. default: index$12
  23705. });
  23706. var htmlTagNames$1 = ( htmlTagNames && index$12 ) || htmlTagNames;
  23707. function clean$3(ast, newObj, parent) {
  23708. ["raw", // front-matter
  23709. "raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(function (name) {
  23710. delete newObj[name];
  23711. });
  23712. if (ast.type === "yaml") {
  23713. delete newObj.value;
  23714. } // --insert-pragma
  23715. if (ast.type === "css-comment" && parent.type === "css-root" && parent.nodes.length !== 0 && ( // first non-front-matter comment
  23716. parent.nodes[0] === ast || (parent.nodes[0].type === "yaml" || parent.nodes[0].type === "toml") && parent.nodes[1] === ast)) {
  23717. /**
  23718. * something
  23719. *
  23720. * @format
  23721. */
  23722. delete newObj.text; // standalone pragma
  23723. if (/^\*\s*@(format|prettier)\s*$/.test(ast.text)) {
  23724. return null;
  23725. }
  23726. }
  23727. if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
  23728. delete newObj.value;
  23729. }
  23730. if (ast.type === "css-rule") {
  23731. delete newObj.params;
  23732. }
  23733. if (ast.type === "selector-combinator") {
  23734. newObj.value = newObj.value.replace(/\s+/g, " ");
  23735. }
  23736. if (ast.type === "media-feature") {
  23737. newObj.value = newObj.value.replace(/ /g, "");
  23738. }
  23739. 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") {
  23740. newObj.value = newObj.value.toLowerCase();
  23741. }
  23742. if (ast.type === "css-decl") {
  23743. newObj.prop = newObj.prop.toLowerCase();
  23744. }
  23745. if (ast.type === "css-atrule" || ast.type === "css-import") {
  23746. newObj.name = newObj.name.toLowerCase();
  23747. }
  23748. if (ast.type === "value-number") {
  23749. newObj.unit = newObj.unit.toLowerCase();
  23750. }
  23751. 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) {
  23752. newObj.value = cleanCSSStrings(newObj.value);
  23753. }
  23754. if (ast.type === "selector-attribute") {
  23755. newObj.attribute = newObj.attribute.trim();
  23756. if (newObj.namespace) {
  23757. if (typeof newObj.namespace === "string") {
  23758. newObj.namespace = newObj.namespace.trim();
  23759. if (newObj.namespace.length === 0) {
  23760. newObj.namespace = true;
  23761. }
  23762. }
  23763. }
  23764. if (newObj.value) {
  23765. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  23766. delete newObj.quoted;
  23767. }
  23768. }
  23769. 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) {
  23770. newObj.value = newObj.value.replace(/([\d.eE+-]+)([a-zA-Z]*)/g, function (match, numStr, unit) {
  23771. var num = Number(numStr);
  23772. return isNaN(num) ? match : num + unit.toLowerCase();
  23773. });
  23774. }
  23775. if (ast.type === "selector-tag") {
  23776. var lowercasedValue = ast.value.toLowerCase();
  23777. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  23778. newObj.value = lowercasedValue;
  23779. }
  23780. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  23781. newObj.value = lowercasedValue;
  23782. }
  23783. } // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
  23784. if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
  23785. delete newObj.value;
  23786. } // Workaround for SCSS nested properties
  23787. if (ast.type === "selector-unknown") {
  23788. delete newObj.value;
  23789. }
  23790. }
  23791. function cleanCSSStrings(value) {
  23792. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  23793. }
  23794. var clean_1$2 = clean$3;
  23795. var _require$$0$builders$3 = doc.builders;
  23796. var hardline$7 = _require$$0$builders$3.hardline;
  23797. var literalline$3 = _require$$0$builders$3.literalline;
  23798. var concat$9 = _require$$0$builders$3.concat;
  23799. var markAsRoot$1 = _require$$0$builders$3.markAsRoot;
  23800. var mapDoc$4 = doc.utils.mapDoc;
  23801. function embed$2(path$$1, print, textToDoc
  23802. /*, options */
  23803. ) {
  23804. var node = path$$1.getValue();
  23805. if (node.type === "yaml") {
  23806. return markAsRoot$1(concat$9(["---", hardline$7, node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  23807. parser: "yaml"
  23808. })) : "", "---", hardline$7]));
  23809. }
  23810. return null;
  23811. function replaceNewlinesWithLiterallines(doc$$2) {
  23812. return mapDoc$4(doc$$2, function (currentDoc) {
  23813. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$9(currentDoc.split(/(\n)/g).map(function (v, i) {
  23814. return i % 2 === 0 ? v : literalline$3;
  23815. })) : currentDoc;
  23816. });
  23817. }
  23818. }
  23819. var embed_1$2 = embed$2;
  23820. var DELIMITER_MAP = {
  23821. "---": "yaml",
  23822. "+++": "toml"
  23823. };
  23824. function parse$5(text) {
  23825. var delimiterRegex = Object.keys(DELIMITER_MAP).map(escapeStringRegexp).join("|");
  23826. var match = text.match( // trailing spaces after delimiters are allowed
  23827. new RegExp(`^(${delimiterRegex})[^\\n\\S]*\\n(?:([\\s\\S]*?)\\n)?\\1[^\\n\\S]*(\\n|$)`));
  23828. if (match === null) {
  23829. return {
  23830. frontMatter: null,
  23831. content: text
  23832. };
  23833. }
  23834. var raw = match[0].replace(/\n$/, "");
  23835. var delimiter = match[1];
  23836. var value = match[2];
  23837. return {
  23838. frontMatter: {
  23839. type: DELIMITER_MAP[delimiter],
  23840. value,
  23841. raw
  23842. },
  23843. content: match[0].replace(/[^\n]/g, " ") + text.slice(match[0].length)
  23844. };
  23845. }
  23846. var frontMatter = parse$5;
  23847. function hasPragma$1(text) {
  23848. return pragma.hasPragma(frontMatter(text).content);
  23849. }
  23850. function insertPragma$3(text) {
  23851. var _parseFrontMatter = frontMatter(text),
  23852. frontMatter$$1 = _parseFrontMatter.frontMatter,
  23853. content = _parseFrontMatter.content;
  23854. return (frontMatter$$1 ? frontMatter$$1.raw + "\n\n" : "") + pragma.insertPragma(content);
  23855. }
  23856. var pragma$2 = {
  23857. hasPragma: hasPragma$1,
  23858. insertPragma: insertPragma$3
  23859. };
  23860. 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"];
  23861. function getAncestorCounter(path$$1, typeOrTypes) {
  23862. var types = [].concat(typeOrTypes);
  23863. var counter = -1;
  23864. var ancestorNode;
  23865. while (ancestorNode = path$$1.getParentNode(++counter)) {
  23866. if (types.indexOf(ancestorNode.type) !== -1) {
  23867. return counter;
  23868. }
  23869. }
  23870. return -1;
  23871. }
  23872. function getAncestorNode$1(path$$1, typeOrTypes) {
  23873. var counter = getAncestorCounter(path$$1, typeOrTypes);
  23874. return counter === -1 ? null : path$$1.getParentNode(counter);
  23875. }
  23876. function getPropOfDeclNode$1(path$$1) {
  23877. var declAncestorNode = getAncestorNode$1(path$$1, "css-decl");
  23878. return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
  23879. }
  23880. function isSCSS$1(parser, text) {
  23881. var hasExplicitParserChoice = parser === "less" || parser === "scss";
  23882. var IS_POSSIBLY_SCSS = /(\w\s*: [^}:]+|#){|@import[^\n]+(url|,)/;
  23883. return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
  23884. }
  23885. function isWideKeywords$1(value) {
  23886. return ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== -1;
  23887. }
  23888. function isKeyframeAtRuleKeywords$1(path$$1, value) {
  23889. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  23890. return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].indexOf(value.toLowerCase()) !== -1;
  23891. }
  23892. function maybeToLowerCase$1(value) {
  23893. return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
  23894. }
  23895. function insideValueFunctionNode$1(path$$1, functionName) {
  23896. var funcAncestorNode = getAncestorNode$1(path$$1, "value-func");
  23897. return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
  23898. }
  23899. function insideICSSRuleNode$1(path$$1) {
  23900. var ruleAncestorNode = getAncestorNode$1(path$$1, "css-rule");
  23901. return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
  23902. }
  23903. function insideAtRuleNode$1(path$$1, atRuleNameOrAtRuleNames) {
  23904. var atRuleNames = [].concat(atRuleNameOrAtRuleNames);
  23905. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  23906. return atRuleAncestorNode && atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1;
  23907. }
  23908. function insideURLFunctionInImportAtRuleNode$1(path$$1) {
  23909. var node = path$$1.getValue();
  23910. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  23911. return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
  23912. }
  23913. function isURLFunctionNode$1(node) {
  23914. return node.type === "value-func" && node.value.toLowerCase() === "url";
  23915. }
  23916. function isLastNode$1(path$$1, node) {
  23917. var parentNode = path$$1.getParentNode();
  23918. if (!parentNode) {
  23919. return false;
  23920. }
  23921. var nodes = parentNode.nodes;
  23922. return nodes && nodes.indexOf(node) === nodes.length - 1;
  23923. }
  23924. function isHTMLTag$1(value) {
  23925. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  23926. }
  23927. function isDetachedRulesetDeclarationNode$1(node) {
  23928. // If a Less file ends up being parsed with the SCSS parser, Less
  23929. // variable declarations will be parsed as atrules with names ending
  23930. // with a colon, so keep the original case then.
  23931. if (!node.selector) {
  23932. return false;
  23933. }
  23934. return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
  23935. }
  23936. function isForKeywordNode$1(node) {
  23937. return node.type === "value-word" && ["from", "through", "end"].indexOf(node.value) !== -1;
  23938. }
  23939. function isIfElseKeywordNode$1(node) {
  23940. return node.type === "value-word" && ["and", "or", "not"].indexOf(node.value) !== -1;
  23941. }
  23942. function isEachKeywordNode$1(node) {
  23943. return node.type === "value-word" && node.value === "in";
  23944. }
  23945. function isMultiplicationNode$1(node) {
  23946. return node.type === "value-operator" && node.value === "*";
  23947. }
  23948. function isDivisionNode$1(node) {
  23949. return node.type === "value-operator" && node.value === "/";
  23950. }
  23951. function isAdditionNode$1(node) {
  23952. return node.type === "value-operator" && node.value === "+";
  23953. }
  23954. function isSubtractionNode$1(node) {
  23955. return node.type === "value-operator" && node.value === "-";
  23956. }
  23957. function isModuloNode(node) {
  23958. return node.type === "value-operator" && node.value === "%";
  23959. }
  23960. function isMathOperatorNode$1(node) {
  23961. return isMultiplicationNode$1(node) || isDivisionNode$1(node) || isAdditionNode$1(node) || isSubtractionNode$1(node) || isModuloNode(node);
  23962. }
  23963. function isEqualityOperatorNode$1(node) {
  23964. return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1;
  23965. }
  23966. function isRelationalOperatorNode$1(node) {
  23967. return node.type === "value-word" && ["<", ">", "<=", ">="].indexOf(node.value) !== -1;
  23968. }
  23969. function isSCSSControlDirectiveNode$1(node) {
  23970. return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1;
  23971. }
  23972. function isSCSSNestedPropertyNode(node) {
  23973. if (!node.selector) {
  23974. return false;
  23975. }
  23976. return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
  23977. }
  23978. function isDetachedRulesetCallNode$1(node) {
  23979. return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
  23980. }
  23981. function isTemplatePlaceholderNode$1(node) {
  23982. return node.name.startsWith("prettier-placeholder");
  23983. }
  23984. function isTemplatePropNode$1(node) {
  23985. return node.prop.startsWith("@prettier-placeholder");
  23986. }
  23987. function isPostcssSimpleVarNode$1(currentNode, nextNode) {
  23988. return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
  23989. }
  23990. function hasComposesNode$1(node) {
  23991. return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
  23992. }
  23993. function hasParensAroundNode$1(node) {
  23994. 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;
  23995. }
  23996. function hasEmptyRawBefore$1(node) {
  23997. return node.raws && node.raws.before === "";
  23998. }
  23999. function isKeyValuePairNode$1(node) {
  24000. return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
  24001. }
  24002. function isKeyValuePairInParenGroupNode(node) {
  24003. return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode$1(node.groups[0]);
  24004. }
  24005. function isSCSSMapItemNode$1(path$$1) {
  24006. var node = path$$1.getValue(); // Ignore empty item (i.e. `$key: ()`)
  24007. if (node.groups.length === 0) {
  24008. return false;
  24009. }
  24010. var parentParentNode = path$$1.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
  24011. if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
  24012. return false;
  24013. }
  24014. var declNode = getAncestorNode$1(path$$1, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
  24015. if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
  24016. return true;
  24017. } // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
  24018. if (isKeyValuePairInParenGroupNode(parentParentNode)) {
  24019. return true;
  24020. } // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
  24021. if (parentParentNode.type === "value-func") {
  24022. return true;
  24023. }
  24024. return false;
  24025. }
  24026. function isInlineValueCommentNode$1(node) {
  24027. return node.type === "value-comment" && node.inline;
  24028. }
  24029. function isHashNode$1(node) {
  24030. return node.type === "value-word" && node.value === "#";
  24031. }
  24032. function isLeftCurlyBraceNode$1(node) {
  24033. return node.type === "value-word" && node.value === "{";
  24034. }
  24035. function isRightCurlyBraceNode$1(node) {
  24036. return node.type === "value-word" && node.value === "}";
  24037. }
  24038. function isWordNode$1(node) {
  24039. return ["value-word", "value-atword"].indexOf(node.type) !== -1;
  24040. }
  24041. function isColonNode$1(node) {
  24042. return node.type === "value-colon";
  24043. }
  24044. function isMediaAndSupportsKeywords$1(node) {
  24045. return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
  24046. }
  24047. function isColorAdjusterFuncNode$1(node) {
  24048. if (node.type !== "value-func") {
  24049. return false;
  24050. }
  24051. return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
  24052. }
  24053. var utils$6 = {
  24054. getAncestorCounter,
  24055. getAncestorNode: getAncestorNode$1,
  24056. getPropOfDeclNode: getPropOfDeclNode$1,
  24057. maybeToLowerCase: maybeToLowerCase$1,
  24058. insideValueFunctionNode: insideValueFunctionNode$1,
  24059. insideICSSRuleNode: insideICSSRuleNode$1,
  24060. insideAtRuleNode: insideAtRuleNode$1,
  24061. insideURLFunctionInImportAtRuleNode: insideURLFunctionInImportAtRuleNode$1,
  24062. isKeyframeAtRuleKeywords: isKeyframeAtRuleKeywords$1,
  24063. isHTMLTag: isHTMLTag$1,
  24064. isWideKeywords: isWideKeywords$1,
  24065. isSCSS: isSCSS$1,
  24066. isLastNode: isLastNode$1,
  24067. isSCSSControlDirectiveNode: isSCSSControlDirectiveNode$1,
  24068. isDetachedRulesetDeclarationNode: isDetachedRulesetDeclarationNode$1,
  24069. isRelationalOperatorNode: isRelationalOperatorNode$1,
  24070. isEqualityOperatorNode: isEqualityOperatorNode$1,
  24071. isMultiplicationNode: isMultiplicationNode$1,
  24072. isDivisionNode: isDivisionNode$1,
  24073. isAdditionNode: isAdditionNode$1,
  24074. isSubtractionNode: isSubtractionNode$1,
  24075. isModuloNode,
  24076. isMathOperatorNode: isMathOperatorNode$1,
  24077. isEachKeywordNode: isEachKeywordNode$1,
  24078. isForKeywordNode: isForKeywordNode$1,
  24079. isURLFunctionNode: isURLFunctionNode$1,
  24080. isIfElseKeywordNode: isIfElseKeywordNode$1,
  24081. hasComposesNode: hasComposesNode$1,
  24082. hasParensAroundNode: hasParensAroundNode$1,
  24083. hasEmptyRawBefore: hasEmptyRawBefore$1,
  24084. isSCSSNestedPropertyNode,
  24085. isDetachedRulesetCallNode: isDetachedRulesetCallNode$1,
  24086. isTemplatePlaceholderNode: isTemplatePlaceholderNode$1,
  24087. isTemplatePropNode: isTemplatePropNode$1,
  24088. isPostcssSimpleVarNode: isPostcssSimpleVarNode$1,
  24089. isKeyValuePairNode: isKeyValuePairNode$1,
  24090. isKeyValuePairInParenGroupNode,
  24091. isSCSSMapItemNode: isSCSSMapItemNode$1,
  24092. isInlineValueCommentNode: isInlineValueCommentNode$1,
  24093. isHashNode: isHashNode$1,
  24094. isLeftCurlyBraceNode: isLeftCurlyBraceNode$1,
  24095. isRightCurlyBraceNode: isRightCurlyBraceNode$1,
  24096. isWordNode: isWordNode$1,
  24097. isColonNode: isColonNode$1,
  24098. isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1,
  24099. isColorAdjusterFuncNode: isColorAdjusterFuncNode$1
  24100. };
  24101. var insertPragma$2 = pragma$2.insertPragma;
  24102. var printNumber$2 = util$1.printNumber;
  24103. var printString$2 = util$1.printString;
  24104. var hasIgnoreComment$2 = util$1.hasIgnoreComment;
  24105. var hasNewline$3 = util$1.hasNewline;
  24106. var isNextLineEmpty$3 = utilShared.isNextLineEmpty;
  24107. var _require$$3$builders = doc.builders;
  24108. var concat$8 = _require$$3$builders.concat;
  24109. var join$6 = _require$$3$builders.join;
  24110. var line$5 = _require$$3$builders.line;
  24111. var hardline$6 = _require$$3$builders.hardline;
  24112. var softline$3 = _require$$3$builders.softline;
  24113. var group$6 = _require$$3$builders.group;
  24114. var fill$3 = _require$$3$builders.fill;
  24115. var indent$5 = _require$$3$builders.indent;
  24116. var dedent$3 = _require$$3$builders.dedent;
  24117. var ifBreak$2 = _require$$3$builders.ifBreak;
  24118. var removeLines$2 = doc.utils.removeLines;
  24119. var getAncestorNode = utils$6.getAncestorNode;
  24120. var getPropOfDeclNode = utils$6.getPropOfDeclNode;
  24121. var maybeToLowerCase = utils$6.maybeToLowerCase;
  24122. var insideValueFunctionNode = utils$6.insideValueFunctionNode;
  24123. var insideICSSRuleNode = utils$6.insideICSSRuleNode;
  24124. var insideAtRuleNode = utils$6.insideAtRuleNode;
  24125. var insideURLFunctionInImportAtRuleNode = utils$6.insideURLFunctionInImportAtRuleNode;
  24126. var isKeyframeAtRuleKeywords = utils$6.isKeyframeAtRuleKeywords;
  24127. var isHTMLTag = utils$6.isHTMLTag;
  24128. var isWideKeywords = utils$6.isWideKeywords;
  24129. var isSCSS = utils$6.isSCSS;
  24130. var isLastNode = utils$6.isLastNode;
  24131. var isSCSSControlDirectiveNode = utils$6.isSCSSControlDirectiveNode;
  24132. var isDetachedRulesetDeclarationNode = utils$6.isDetachedRulesetDeclarationNode;
  24133. var isRelationalOperatorNode = utils$6.isRelationalOperatorNode;
  24134. var isEqualityOperatorNode = utils$6.isEqualityOperatorNode;
  24135. var isMultiplicationNode = utils$6.isMultiplicationNode;
  24136. var isDivisionNode = utils$6.isDivisionNode;
  24137. var isAdditionNode = utils$6.isAdditionNode;
  24138. var isSubtractionNode = utils$6.isSubtractionNode;
  24139. var isMathOperatorNode = utils$6.isMathOperatorNode;
  24140. var isEachKeywordNode = utils$6.isEachKeywordNode;
  24141. var isForKeywordNode = utils$6.isForKeywordNode;
  24142. var isURLFunctionNode = utils$6.isURLFunctionNode;
  24143. var isIfElseKeywordNode = utils$6.isIfElseKeywordNode;
  24144. var hasComposesNode = utils$6.hasComposesNode;
  24145. var hasParensAroundNode = utils$6.hasParensAroundNode;
  24146. var hasEmptyRawBefore = utils$6.hasEmptyRawBefore;
  24147. var isKeyValuePairNode = utils$6.isKeyValuePairNode;
  24148. var isDetachedRulesetCallNode = utils$6.isDetachedRulesetCallNode;
  24149. var isTemplatePlaceholderNode = utils$6.isTemplatePlaceholderNode;
  24150. var isTemplatePropNode = utils$6.isTemplatePropNode;
  24151. var isPostcssSimpleVarNode = utils$6.isPostcssSimpleVarNode;
  24152. var isSCSSMapItemNode = utils$6.isSCSSMapItemNode;
  24153. var isInlineValueCommentNode = utils$6.isInlineValueCommentNode;
  24154. var isHashNode = utils$6.isHashNode;
  24155. var isLeftCurlyBraceNode = utils$6.isLeftCurlyBraceNode;
  24156. var isRightCurlyBraceNode = utils$6.isRightCurlyBraceNode;
  24157. var isWordNode = utils$6.isWordNode;
  24158. var isColonNode = utils$6.isColonNode;
  24159. var isMediaAndSupportsKeywords = utils$6.isMediaAndSupportsKeywords;
  24160. var isColorAdjusterFuncNode = utils$6.isColorAdjusterFuncNode;
  24161. function shouldPrintComma$1(options) {
  24162. switch (options.trailingComma) {
  24163. case "all":
  24164. case "es5":
  24165. return true;
  24166. case "none":
  24167. default:
  24168. return false;
  24169. }
  24170. }
  24171. function genericPrint$2(path$$1, options, print) {
  24172. var node = path$$1.getValue();
  24173. /* istanbul ignore if */
  24174. if (!node) {
  24175. return "";
  24176. }
  24177. if (typeof node === "string") {
  24178. return node;
  24179. }
  24180. switch (node.type) {
  24181. case "yaml":
  24182. case "toml":
  24183. return concat$8([node.raw, hardline$6]);
  24184. case "css-root":
  24185. {
  24186. var nodes = printNodeSequence(path$$1, options, print);
  24187. if (nodes.parts.length) {
  24188. return concat$8([nodes, hardline$6]);
  24189. }
  24190. return nodes;
  24191. }
  24192. case "css-comment":
  24193. {
  24194. if (node.raws.content) {
  24195. return node.raws.content;
  24196. }
  24197. var text = options.originalText.slice(options.locStart(node), options.locEnd(node));
  24198. var rawText = node.raws.text || node.text; // Workaround a bug where the location is off.
  24199. // https://github.com/postcss/postcss-scss/issues/63
  24200. if (text.indexOf(rawText) === -1) {
  24201. if (node.raws.inline) {
  24202. return concat$8(["// ", rawText]);
  24203. }
  24204. return concat$8(["/* ", rawText, " */"]);
  24205. }
  24206. return text;
  24207. }
  24208. case "css-rule":
  24209. {
  24210. return concat$8([path$$1.call(print, "selector"), node.important ? " !important" : "", node.nodes ? concat$8([" {", node.nodes.length > 0 ? indent$5(concat$8([hardline$6, printNodeSequence(path$$1, options, print)])) : "", hardline$6, "}", isDetachedRulesetDeclarationNode(node) ? ";" : ""]) : ";"]);
  24211. }
  24212. case "css-decl":
  24213. {
  24214. var parentNode = path$$1.getParentNode();
  24215. return concat$8([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$8([" {", indent$5(concat$8([softline$3, printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : isTemplatePropNode(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
  24216. }
  24217. case "css-atrule":
  24218. {
  24219. var _parentNode = path$$1.getParentNode();
  24220. return concat$8(["@", // If a Less file ends up being parsed with the SCSS parser, Less
  24221. // variable declarations will be parsed as at-rules with names ending
  24222. // with a colon, so keep the original case then.
  24223. isDetachedRulesetCallNode(node) || node.name.endsWith(":") ? node.name : maybeToLowerCase(node.name), node.params ? concat$8([isDetachedRulesetCallNode(node) ? "" : isTemplatePlaceholderNode(node) && /^\s*\n/.test(node.raws.afterName) ? /^\s*\n\s*\n/.test(node.raws.afterName) ? concat$8([hardline$6, hardline$6]) : hardline$6 : " ", path$$1.call(print, "params")]) : "", node.selector ? indent$5(concat$8([" ", path$$1.call(print, "selector")])) : "", node.value ? group$6(concat$8([" ", path$$1.call(print, "value"), isSCSSControlDirectiveNode(node) ? hasParensAroundNode(node) ? " " : line$5 : ""])) : node.name === "else" ? " " : "", node.nodes ? concat$8([isSCSSControlDirectiveNode(node) ? "" : " ", "{", indent$5(concat$8([node.nodes.length > 0 ? softline$3 : "", printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : isTemplatePlaceholderNode(node) && !_parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
  24224. }
  24225. // postcss-media-query-parser
  24226. case "media-query-list":
  24227. {
  24228. var parts = [];
  24229. path$$1.each(function (childPath) {
  24230. var node = childPath.getValue();
  24231. if (node.type === "media-query" && node.value === "") {
  24232. return;
  24233. }
  24234. parts.push(childPath.call(print));
  24235. }, "nodes");
  24236. return group$6(indent$5(join$6(line$5, parts)));
  24237. }
  24238. case "media-query":
  24239. {
  24240. return concat$8([join$6(" ", path$$1.map(print, "nodes")), isLastNode(path$$1, node) ? "" : ","]);
  24241. }
  24242. case "media-type":
  24243. {
  24244. return adjustNumbers(adjustStrings(node.value, options));
  24245. }
  24246. case "media-feature-expression":
  24247. {
  24248. if (!node.nodes) {
  24249. return node.value;
  24250. }
  24251. return concat$8(["(", concat$8(path$$1.map(print, "nodes")), ")"]);
  24252. }
  24253. case "media-feature":
  24254. {
  24255. return maybeToLowerCase(adjustStrings(node.value.replace(/ +/g, " "), options));
  24256. }
  24257. case "media-colon":
  24258. {
  24259. return concat$8([node.value, " "]);
  24260. }
  24261. case "media-value":
  24262. {
  24263. return adjustNumbers(adjustStrings(node.value, options));
  24264. }
  24265. case "media-keyword":
  24266. {
  24267. return adjustStrings(node.value, options);
  24268. }
  24269. case "media-url":
  24270. {
  24271. return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
  24272. }
  24273. case "media-unknown":
  24274. {
  24275. return node.value;
  24276. }
  24277. // postcss-selector-parser
  24278. case "selector-root":
  24279. {
  24280. return group$6(concat$8([insideAtRuleNode(path$$1, "custom-selector") ? concat$8([getAncestorNode(path$$1, "css-atrule").customSelector, line$5]) : "", join$6(concat$8([",", insideAtRuleNode(path$$1, ["extend", "custom-selector", "nest"]) ? line$5 : hardline$6]), path$$1.map(print, "nodes"))]));
  24281. }
  24282. case "selector-selector":
  24283. {
  24284. return group$6(indent$5(concat$8(path$$1.map(print, "nodes"))));
  24285. }
  24286. case "selector-comment":
  24287. {
  24288. return node.value;
  24289. }
  24290. case "selector-string":
  24291. {
  24292. return adjustStrings(node.value, options);
  24293. }
  24294. case "selector-tag":
  24295. {
  24296. var _parentNode2 = path$$1.getParentNode();
  24297. var index = _parentNode2 && _parentNode2.nodes.indexOf(node);
  24298. var prevNode = index && _parentNode2.nodes[index - 1];
  24299. return concat$8([node.namespace ? concat$8([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)]);
  24300. }
  24301. case "selector-id":
  24302. {
  24303. return concat$8(["#", node.value]);
  24304. }
  24305. case "selector-class":
  24306. {
  24307. return concat$8([".", adjustNumbers(adjustStrings(node.value, options))]);
  24308. }
  24309. case "selector-attribute":
  24310. {
  24311. return concat$8(["[", node.namespace ? concat$8([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" : "", "]"]);
  24312. }
  24313. case "selector-combinator":
  24314. {
  24315. if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
  24316. var _parentNode3 = path$$1.getParentNode();
  24317. var _leading = _parentNode3.type === "selector-selector" && _parentNode3.nodes[0] === node ? "" : line$5;
  24318. return concat$8([_leading, node.value, isLastNode(path$$1, node) ? "" : " "]);
  24319. }
  24320. var leading = node.value.trim().startsWith("(") ? line$5 : "";
  24321. var value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$5;
  24322. return concat$8([leading, value]);
  24323. }
  24324. case "selector-universal":
  24325. {
  24326. return concat$8([node.namespace ? concat$8([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.value]);
  24327. }
  24328. case "selector-pseudo":
  24329. {
  24330. return concat$8([maybeToLowerCase(node.value), node.nodes && node.nodes.length > 0 ? concat$8(["(", join$6(", ", path$$1.map(print, "nodes")), ")"]) : ""]);
  24331. }
  24332. case "selector-nesting":
  24333. {
  24334. return node.value;
  24335. }
  24336. case "selector-unknown":
  24337. {
  24338. var ruleAncestorNode = getAncestorNode(path$$1, "css-rule"); // Nested SCSS property
  24339. if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
  24340. return adjustNumbers(adjustStrings(maybeToLowerCase(node.value), options));
  24341. }
  24342. return node.value;
  24343. }
  24344. // postcss-values-parser
  24345. case "value-value":
  24346. case "value-root":
  24347. {
  24348. return path$$1.call(print, "group");
  24349. }
  24350. case "value-comment":
  24351. {
  24352. return concat$8([node.inline ? "//" : "/*", node.value, node.inline ? "" : "*/"]);
  24353. }
  24354. case "value-comma_group":
  24355. {
  24356. var _parentNode4 = path$$1.getParentNode();
  24357. var parentParentNode = path$$1.getParentNode(1);
  24358. var declAncestorProp = getPropOfDeclNode(path$$1);
  24359. var isGridValue = declAncestorProp && _parentNode4.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
  24360. var atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  24361. var isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode(atRuleAncestorNode);
  24362. var printed = path$$1.map(print, "groups");
  24363. var _parts = [];
  24364. var insideURLFunction = insideValueFunctionNode(path$$1, "url");
  24365. var insideSCSSInterpolationInString = false;
  24366. var didBreak = false;
  24367. for (var i = 0; i < node.groups.length; ++i) {
  24368. _parts.push(printed[i]); // Ignore value inside `url()`
  24369. if (insideURLFunction) {
  24370. continue;
  24371. }
  24372. var iPrevNode = node.groups[i - 1];
  24373. var iNode = node.groups[i];
  24374. var iNextNode = node.groups[i + 1];
  24375. var iNextNextNode = node.groups[i + 2]; // Ignore after latest node (i.e. before semicolon)
  24376. if (!iNextNode) {
  24377. continue;
  24378. } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
  24379. var isStartSCSSinterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
  24380. var isEndingSCSSinterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
  24381. if (isStartSCSSinterpolationInString || isEndingSCSSinterpolationInString) {
  24382. insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
  24383. continue;
  24384. }
  24385. if (insideSCSSInterpolationInString) {
  24386. continue;
  24387. } // Ignore colon (i.e. `:`)
  24388. if (isColonNode(iNode) || isColonNode(iNextNode)) {
  24389. continue;
  24390. } // Ignore `@` in Less (i.e. `@@var;`)
  24391. if (iNode.type === "value-atword" && iNode.value === "") {
  24392. continue;
  24393. } // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  24394. if (iNode.value === "~") {
  24395. continue;
  24396. } // Ignore escape `\`
  24397. if (iNode.value && iNode.value.indexOf("\\") !== -1 && iNextNode && iNextNode.type !== "value-comment") {
  24398. continue;
  24399. } // Ignore escaped `/`
  24400. if (iPrevNode && iPrevNode.value && iPrevNode.value.indexOf("\\") === iPrevNode.value.length - 1 && iNode.type === "value-operator" && iNode.value === "/") {
  24401. continue;
  24402. } // Ignore `\` (i.e. `$variable: \@small;`)
  24403. if (iNode.value === "\\") {
  24404. continue;
  24405. } // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
  24406. if (isPostcssSimpleVarNode(iNode, iNextNode)) {
  24407. continue;
  24408. } // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
  24409. if (isHashNode(iNode) || isLeftCurlyBraceNode(iNode) || isRightCurlyBraceNode(iNextNode) || isLeftCurlyBraceNode(iNextNode) && hasEmptyRawBefore(iNextNode) || isRightCurlyBraceNode(iNode) && hasEmptyRawBefore(iNextNode)) {
  24410. continue;
  24411. } // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
  24412. if (iNode.value === "--" && isHashNode(iNextNode)) {
  24413. continue;
  24414. } // Formatting math operations
  24415. var isMathOperator = isMathOperatorNode(iNode);
  24416. var isNextMathOperator = isMathOperatorNode(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
  24417. // (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
  24418. // (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
  24419. if ((isMathOperator && isHashNode(iNextNode) || isNextMathOperator && isRightCurlyBraceNode(iNode)) && hasEmptyRawBefore(iNextNode)) {
  24420. continue;
  24421. } // Print spaces before and after addition and subtraction math operators as is in `calc` function
  24422. // due to the fact that it is not valid syntax
  24423. // (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
  24424. if (insideValueFunctionNode(path$$1, "calc") && (isAdditionNode(iNode) || isAdditionNode(iNextNode) || isSubtractionNode(iNode) || isSubtractionNode(iNextNode)) && hasEmptyRawBefore(iNextNode)) {
  24425. continue;
  24426. } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
  24427. // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
  24428. var isColorAdjusterNode = (isAdditionNode(iNode) || isSubtractionNode(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode(parentParentNode) && !hasEmptyRawBefore(iNextNode);
  24429. var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode(iNextNextNode) || iNode.type === "value-func" || isWordNode(iNode);
  24430. var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode(iPrevNode); // Formatting `/`, `+`, `-` sign
  24431. 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)))) {
  24432. continue;
  24433. } // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
  24434. if (isInlineValueCommentNode(iNode)) {
  24435. _parts.push(hardline$6);
  24436. continue;
  24437. } // Handle keywords in SCSS control directive
  24438. if (isControlDirective && (isEqualityOperatorNode(iNextNode) || isRelationalOperatorNode(iNextNode) || isIfElseKeywordNode(iNextNode) || isEachKeywordNode(iNode) || isForKeywordNode(iNode))) {
  24439. _parts.push(" ");
  24440. continue;
  24441. } // At-rule `namespace` should be in one line
  24442. if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
  24443. _parts.push(" ");
  24444. continue;
  24445. } // Formatting `grid` property
  24446. if (isGridValue) {
  24447. if (iNode.source && iNextNode.source && iNode.source.start.line !== iNextNode.source.start.line) {
  24448. _parts.push(hardline$6);
  24449. didBreak = true;
  24450. } else {
  24451. _parts.push(" ");
  24452. }
  24453. continue;
  24454. } // Add `space` before next math operation
  24455. // Note: `grip` property have `/` delimiter and it is not math operation, so
  24456. // `grid` property handles above
  24457. if (isNextMathOperator) {
  24458. _parts.push(" ");
  24459. continue;
  24460. } // Be default all values go through `line`
  24461. _parts.push(line$5);
  24462. }
  24463. if (didBreak) {
  24464. _parts.unshift(hardline$6);
  24465. }
  24466. if (isControlDirective) {
  24467. return group$6(indent$5(concat$8(_parts)));
  24468. } // Indent is not needed for import url when url is very long
  24469. // and node has two groups
  24470. // when type is value-comma_group
  24471. // example @import url("verylongurl") projection,tv
  24472. if (insideURLFunctionInImportAtRuleNode(path$$1)) {
  24473. return group$6(fill$3(_parts));
  24474. }
  24475. return group$6(indent$5(fill$3(_parts)));
  24476. }
  24477. case "value-paren_group":
  24478. {
  24479. var _parentNode5 = path$$1.getParentNode();
  24480. if (_parentNode5 && isURLFunctionNode(_parentNode5) && (node.groups.length === 1 || node.groups.length > 0 && node.groups[0].type === "value-comma_group" && node.groups[0].groups.length > 0 && node.groups[0].groups[0].type === "value-word" && node.groups[0].groups[0].value.startsWith("data:"))) {
  24481. return concat$8([node.open ? path$$1.call(print, "open") : "", join$6(",", path$$1.map(print, "groups")), node.close ? path$$1.call(print, "close") : ""]);
  24482. }
  24483. if (!node.open) {
  24484. var _printed = path$$1.map(print, "groups");
  24485. var res = [];
  24486. for (var _i = 0; _i < _printed.length; _i++) {
  24487. if (_i !== 0) {
  24488. res.push(concat$8([",", line$5]));
  24489. }
  24490. res.push(_printed[_i]);
  24491. }
  24492. return group$6(indent$5(fill$3(res)));
  24493. }
  24494. var isSCSSMapItem = isSCSSMapItemNode(path$$1);
  24495. return group$6(concat$8([node.open ? path$$1.call(print, "open") : "", indent$5(concat$8([softline$3, join$6(concat$8([",", line$5]), path$$1.map(function (childPath) {
  24496. var node = childPath.getValue();
  24497. var printed = print(childPath); // Key/Value pair in open paren already indented
  24498. if (isKeyValuePairNode(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
  24499. printed.contents.contents.parts[1] = group$6(printed.contents.contents.parts[1]);
  24500. return group$6(dedent$3(printed));
  24501. }
  24502. return printed;
  24503. }, "groups"))])), ifBreak$2(isSCSS(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma$1(options) ? "," : ""), softline$3, node.close ? path$$1.call(print, "close") : ""]), {
  24504. shouldBreak: isSCSSMapItem
  24505. });
  24506. }
  24507. case "value-func":
  24508. {
  24509. return concat$8([node.value, insideAtRuleNode(path$$1, "supports") && isMediaAndSupportsKeywords(node) ? " " : "", path$$1.call(print, "group")]);
  24510. }
  24511. case "value-paren":
  24512. {
  24513. return node.value;
  24514. }
  24515. case "value-number":
  24516. {
  24517. return concat$8([printCssNumber(node.value), maybeToLowerCase(node.unit)]);
  24518. }
  24519. case "value-operator":
  24520. {
  24521. return node.value;
  24522. }
  24523. case "value-word":
  24524. {
  24525. if (node.isColor && node.isHex || isWideKeywords(node.value)) {
  24526. return node.value.toLowerCase();
  24527. }
  24528. return node.value;
  24529. }
  24530. case "value-colon":
  24531. {
  24532. return concat$8([node.value, // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
  24533. insideValueFunctionNode(path$$1, "url") ? "" : line$5]);
  24534. }
  24535. case "value-comma":
  24536. {
  24537. return concat$8([node.value, " "]);
  24538. }
  24539. case "value-string":
  24540. {
  24541. return printString$2(node.raws.quote + node.value + node.raws.quote, options);
  24542. }
  24543. case "value-atword":
  24544. {
  24545. return concat$8(["@", node.value]);
  24546. }
  24547. case "value-unicode-range":
  24548. {
  24549. return node.value;
  24550. }
  24551. case "value-unknown":
  24552. {
  24553. return node.value;
  24554. }
  24555. default:
  24556. /* istanbul ignore next */
  24557. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  24558. }
  24559. }
  24560. function printNodeSequence(path$$1, options, print) {
  24561. var node = path$$1.getValue();
  24562. var parts = [];
  24563. var i = 0;
  24564. path$$1.map(function (pathChild) {
  24565. var prevNode = node.nodes[i - 1];
  24566. if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
  24567. var childNode = pathChild.getValue();
  24568. parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
  24569. } else {
  24570. parts.push(pathChild.call(print));
  24571. }
  24572. if (i !== node.nodes.length - 1) {
  24573. if (node.nodes[i + 1].type === "css-comment" && !hasNewline$3(options.originalText, options.locStart(node.nodes[i + 1]), {
  24574. backwards: true
  24575. }) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml" || node.nodes[i + 1].type === "css-atrule" && node.nodes[i + 1].name === "else" && node.nodes[i].type !== "css-comment") {
  24576. parts.push(" ");
  24577. } else {
  24578. parts.push(hardline$6);
  24579. if (isNextLineEmpty$3(options.originalText, pathChild.getValue(), options) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml") {
  24580. parts.push(hardline$6);
  24581. }
  24582. }
  24583. }
  24584. i++;
  24585. }, "nodes");
  24586. return concat$8(parts);
  24587. }
  24588. var STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  24589. var NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  24590. var STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  24591. var WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  24592. var ADJUST_NUMBERS_REGEX = RegExp(STRING_REGEX.source + `|` + `(${WORD_PART_REGEX.source})?` + `(${NUMBER_REGEX.source})` + `(${STANDARD_UNIT_REGEX.source})?`, "g");
  24593. function adjustStrings(value, options) {
  24594. return value.replace(STRING_REGEX, function (match) {
  24595. return printString$2(match, options);
  24596. });
  24597. }
  24598. function quoteAttributeValue(value, options) {
  24599. var quote = options.singleQuote ? "'" : '"';
  24600. return value.includes('"') || value.includes("'") ? value : quote + value + quote;
  24601. }
  24602. function adjustNumbers(value) {
  24603. return value.replace(ADJUST_NUMBERS_REGEX, function (match, quote, wordPart, number, unit) {
  24604. return !wordPart && number ? (wordPart || "") + printCssNumber(number) + maybeToLowerCase(unit || "") : match;
  24605. });
  24606. }
  24607. function printCssNumber(rawNumber) {
  24608. return printNumber$2(rawNumber) // Remove trailing `.0`.
  24609. .replace(/\.0(?=$|e)/, "");
  24610. }
  24611. var printerPostcss = {
  24612. print: genericPrint$2,
  24613. embed: embed_1$2,
  24614. insertPragma: insertPragma$2,
  24615. hasPrettierIgnore: hasIgnoreComment$2,
  24616. massageAstNode: clean_1$2
  24617. };
  24618. var options$6 = {
  24619. singleQuote: commonOptions.singleQuote
  24620. };
  24621. var name$7 = "CSS";
  24622. var type$6 = "markup";
  24623. var tmScope$6 = "source.css";
  24624. var aceMode$6 = "css";
  24625. var codemirrorMode$6 = "css";
  24626. var codemirrorMimeType$6 = "text/css";
  24627. var color$2 = "#563d7c";
  24628. var extensions$6 = [".css"];
  24629. var languageId$6 = 50;
  24630. var css$2 = {
  24631. name: name$7,
  24632. type: type$6,
  24633. tmScope: tmScope$6,
  24634. aceMode: aceMode$6,
  24635. codemirrorMode: codemirrorMode$6,
  24636. codemirrorMimeType: codemirrorMimeType$6,
  24637. color: color$2,
  24638. extensions: extensions$6,
  24639. languageId: languageId$6
  24640. };
  24641. var css$3 = Object.freeze({
  24642. name: name$7,
  24643. type: type$6,
  24644. tmScope: tmScope$6,
  24645. aceMode: aceMode$6,
  24646. codemirrorMode: codemirrorMode$6,
  24647. codemirrorMimeType: codemirrorMimeType$6,
  24648. color: color$2,
  24649. extensions: extensions$6,
  24650. languageId: languageId$6,
  24651. default: css$2
  24652. });
  24653. var name$8 = "PostCSS";
  24654. var type$7 = "markup";
  24655. var tmScope$7 = "source.postcss";
  24656. var group$7 = "CSS";
  24657. var extensions$7 = [".pcss"];
  24658. var aceMode$7 = "text";
  24659. var languageId$7 = 262764437;
  24660. var postcss = {
  24661. name: name$8,
  24662. type: type$7,
  24663. tmScope: tmScope$7,
  24664. group: group$7,
  24665. extensions: extensions$7,
  24666. aceMode: aceMode$7,
  24667. languageId: languageId$7
  24668. };
  24669. var postcss$1 = Object.freeze({
  24670. name: name$8,
  24671. type: type$7,
  24672. tmScope: tmScope$7,
  24673. group: group$7,
  24674. extensions: extensions$7,
  24675. aceMode: aceMode$7,
  24676. languageId: languageId$7,
  24677. default: postcss
  24678. });
  24679. var name$9 = "Less";
  24680. var type$8 = "markup";
  24681. var group$8 = "CSS";
  24682. var extensions$8 = [".less"];
  24683. var tmScope$8 = "source.css.less";
  24684. var aceMode$8 = "less";
  24685. var codemirrorMode$7 = "css";
  24686. var codemirrorMimeType$7 = "text/css";
  24687. var languageId$8 = 198;
  24688. var less = {
  24689. name: name$9,
  24690. type: type$8,
  24691. group: group$8,
  24692. extensions: extensions$8,
  24693. tmScope: tmScope$8,
  24694. aceMode: aceMode$8,
  24695. codemirrorMode: codemirrorMode$7,
  24696. codemirrorMimeType: codemirrorMimeType$7,
  24697. languageId: languageId$8
  24698. };
  24699. var less$1 = Object.freeze({
  24700. name: name$9,
  24701. type: type$8,
  24702. group: group$8,
  24703. extensions: extensions$8,
  24704. tmScope: tmScope$8,
  24705. aceMode: aceMode$8,
  24706. codemirrorMode: codemirrorMode$7,
  24707. codemirrorMimeType: codemirrorMimeType$7,
  24708. languageId: languageId$8,
  24709. default: less
  24710. });
  24711. var name$10 = "SCSS";
  24712. var type$9 = "markup";
  24713. var tmScope$9 = "source.scss";
  24714. var group$9 = "CSS";
  24715. var aceMode$9 = "scss";
  24716. var codemirrorMode$8 = "css";
  24717. var codemirrorMimeType$8 = "text/x-scss";
  24718. var extensions$9 = [".scss"];
  24719. var languageId$9 = 329;
  24720. var scss = {
  24721. name: name$10,
  24722. type: type$9,
  24723. tmScope: tmScope$9,
  24724. group: group$9,
  24725. aceMode: aceMode$9,
  24726. codemirrorMode: codemirrorMode$8,
  24727. codemirrorMimeType: codemirrorMimeType$8,
  24728. extensions: extensions$9,
  24729. languageId: languageId$9
  24730. };
  24731. var scss$1 = Object.freeze({
  24732. name: name$10,
  24733. type: type$9,
  24734. tmScope: tmScope$9,
  24735. group: group$9,
  24736. aceMode: aceMode$9,
  24737. codemirrorMode: codemirrorMode$8,
  24738. codemirrorMimeType: codemirrorMimeType$8,
  24739. extensions: extensions$9,
  24740. languageId: languageId$9,
  24741. default: scss
  24742. });
  24743. var require$$0$23 = ( css$3 && css$2 ) || css$3;
  24744. var require$$1$9 = ( postcss$1 && postcss ) || postcss$1;
  24745. var require$$2$11 = ( less$1 && less ) || less$1;
  24746. var require$$3$4 = ( scss$1 && scss ) || scss$1;
  24747. var languages$1 = [createLanguage(require$$0$23, {
  24748. override: {
  24749. since: "1.4.0",
  24750. parsers: ["css"],
  24751. vscodeLanguageIds: ["css"]
  24752. }
  24753. }), createLanguage(require$$1$9, {
  24754. override: {
  24755. since: "1.4.0",
  24756. parsers: ["css"],
  24757. vscodeLanguageIds: ["postcss"]
  24758. },
  24759. extend: {
  24760. extensions: [".postcss"]
  24761. }
  24762. }), createLanguage(require$$2$11, {
  24763. override: {
  24764. since: "1.4.0",
  24765. parsers: ["less"],
  24766. vscodeLanguageIds: ["less"]
  24767. }
  24768. }), createLanguage(require$$3$4, {
  24769. override: {
  24770. since: "1.4.0",
  24771. parsers: ["scss"],
  24772. vscodeLanguageIds: ["scss"]
  24773. }
  24774. })];
  24775. var printers$1 = {
  24776. postcss: printerPostcss
  24777. };
  24778. var languageCss = {
  24779. languages: languages$1,
  24780. options: options$6,
  24781. printers: printers$1
  24782. };
  24783. var _require$$0$builders$4 = doc.builders;
  24784. var concat$10 = _require$$0$builders$4.concat;
  24785. var join$7 = _require$$0$builders$4.join;
  24786. var softline$4 = _require$$0$builders$4.softline;
  24787. var hardline$8 = _require$$0$builders$4.hardline;
  24788. var line$6 = _require$$0$builders$4.line;
  24789. var group$10 = _require$$0$builders$4.group;
  24790. var indent$6 = _require$$0$builders$4.indent;
  24791. var ifBreak$3 = _require$$0$builders$4.ifBreak; // http://w3c.github.io/html/single-page.html#void-elements
  24792. 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:
  24793. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  24794. function print(path$$1, options, print) {
  24795. var n = path$$1.getValue();
  24796. /* istanbul ignore if*/
  24797. if (!n) {
  24798. return "";
  24799. }
  24800. switch (n.type) {
  24801. case "Program":
  24802. {
  24803. return group$10(join$7(softline$4, path$$1.map(print, "body").filter(function (text) {
  24804. return text !== "";
  24805. })));
  24806. }
  24807. case "ElementNode":
  24808. {
  24809. var tagFirstChar = n.tag[0];
  24810. var isLocal = n.tag.indexOf(".") !== -1;
  24811. var isGlimmerComponent = tagFirstChar.toUpperCase() === tagFirstChar || isLocal;
  24812. var hasChildren = n.children.length > 0;
  24813. var isVoid = isGlimmerComponent && !hasChildren || voidTags.indexOf(n.tag) !== -1;
  24814. var closeTagForNoBreak = isVoid ? concat$10([" />", softline$4]) : ">";
  24815. var closeTagForBreak = isVoid ? "/>" : ">";
  24816. var _getParams = function _getParams(path$$1, print) {
  24817. return indent$6(concat$10([n.attributes.length ? line$6 : "", join$7(line$6, path$$1.map(print, "attributes")), n.modifiers.length ? line$6 : "", join$7(line$6, path$$1.map(print, "modifiers")), n.comments.length ? line$6 : "", join$7(line$6, path$$1.map(print, "comments"))]));
  24818. };
  24819. return concat$10([group$10(concat$10(["<", n.tag, _getParams(path$$1, print), n.blockParams.length ? ` as |${n.blockParams.join(" ")}|` : "", ifBreak$3(softline$4, ""), ifBreak$3(closeTagForBreak, closeTagForNoBreak)])), group$10(concat$10([indent$6(join$7(softline$4, [""].concat(path$$1.map(print, "children")))), ifBreak$3(hasChildren ? hardline$8 : "", ""), !isVoid ? concat$10(["</", n.tag, ">"]) : ""]))]);
  24820. }
  24821. case "BlockStatement":
  24822. {
  24823. var pp = path$$1.getParentNode(1);
  24824. var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
  24825. var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
  24826. var indentElse = hasElseIf ? function (a) {
  24827. return a;
  24828. } : indent$6;
  24829. if (n.inverse) {
  24830. return concat$10([isElseIf ? concat$10(["{{else ", printPathParams(path$$1, print), "}}"]) : printOpenBlock(path$$1, print), indent$6(concat$10([hardline$8, path$$1.call(print, "program")])), n.inverse && !hasElseIf ? concat$10([hardline$8, "{{else}}"]) : "", n.inverse ? indentElse(concat$10([hardline$8, path$$1.call(print, "inverse")])) : "", isElseIf ? "" : concat$10([hardline$8, printCloseBlock(path$$1, print)])]);
  24831. } else if (isElseIf) {
  24832. return concat$10([concat$10(["{{else ", printPathParams(path$$1, print), "}}"]), indent$6(concat$10([hardline$8, path$$1.call(print, "program")]))]);
  24833. }
  24834. /**
  24835. * I want this boolean to be: if params are going to cause a break,
  24836. * not that it has params.
  24837. */
  24838. var hasParams = n.params.length > 0 || n.hash.pairs.length > 0;
  24839. var _hasChildren = n.program.body.length > 0;
  24840. return concat$10([printOpenBlock(path$$1, print), group$10(concat$10([indent$6(concat$10([softline$4, path$$1.call(print, "program")])), hasParams && _hasChildren ? hardline$8 : softline$4, printCloseBlock(path$$1, print)]))]);
  24841. }
  24842. case "ElementModifierStatement":
  24843. case "MustacheStatement":
  24844. {
  24845. var _pp = path$$1.getParentNode(1);
  24846. var isConcat = _pp && _pp.type === "ConcatStatement";
  24847. return group$10(concat$10([n.escaped === false ? "{{{" : "{{", printPathParams(path$$1, print), isConcat ? "" : softline$4, n.escaped === false ? "}}}" : "}}"]));
  24848. }
  24849. case "SubExpression":
  24850. {
  24851. var params = getParams(path$$1, print);
  24852. var printedParams = params.length > 0 ? indent$6(concat$10([line$6, group$10(join$7(line$6, params))])) : "";
  24853. return group$10(concat$10(["(", printPath(path$$1, print), printedParams, softline$4, ")"]));
  24854. }
  24855. case "AttrNode":
  24856. {
  24857. var isText = n.value.type === "TextNode";
  24858. if (isText && n.value.loc.start.column === n.value.loc.end.column) {
  24859. return concat$10([n.name]);
  24860. }
  24861. var quote = isText ? '"' : "";
  24862. return concat$10([n.name, "=", quote, path$$1.call(print, "value"), quote]);
  24863. }
  24864. case "ConcatStatement":
  24865. {
  24866. return concat$10(['"', group$10(indent$6(join$7(softline$4, path$$1.map(function (partPath) {
  24867. return print(partPath);
  24868. }, "parts").filter(function (a) {
  24869. return a !== "";
  24870. })))), '"']);
  24871. }
  24872. case "Hash":
  24873. {
  24874. return concat$10([join$7(line$6, path$$1.map(print, "pairs"))]);
  24875. }
  24876. case "HashPair":
  24877. {
  24878. return concat$10([n.key, "=", path$$1.call(print, "value")]);
  24879. }
  24880. case "TextNode":
  24881. {
  24882. var leadingSpace = "";
  24883. var trailingSpace = ""; // preserve a space inside of an attribute node where whitespace present, when next to mustache statement.
  24884. var inAttrNode = path$$1.stack.indexOf("attributes") >= 0;
  24885. if (inAttrNode) {
  24886. var parentNode = path$$1.getParentNode(0);
  24887. var _isConcat = parentNode.type === "ConcatStatement";
  24888. if (_isConcat) {
  24889. var parts = parentNode.parts;
  24890. var partIndex = parts.indexOf(n);
  24891. if (partIndex > 0) {
  24892. var partType = parts[partIndex - 1].type;
  24893. var isMustache = partType === "MustacheStatement";
  24894. if (isMustache) {
  24895. leadingSpace = " ";
  24896. }
  24897. }
  24898. if (partIndex < parts.length - 1) {
  24899. var _partType = parts[partIndex + 1].type;
  24900. var _isMustache = _partType === "MustacheStatement";
  24901. if (_isMustache) {
  24902. trailingSpace = " ";
  24903. }
  24904. }
  24905. }
  24906. }
  24907. return n.chars.replace(/^\s+/, leadingSpace).replace(/\s+$/, trailingSpace);
  24908. }
  24909. case "MustacheCommentStatement":
  24910. {
  24911. var dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  24912. return concat$10(["{{!", dashes, n.value, dashes, "}}"]);
  24913. }
  24914. case "PathExpression":
  24915. {
  24916. return n.original;
  24917. }
  24918. case "BooleanLiteral":
  24919. {
  24920. return String(n.value);
  24921. }
  24922. case "CommentStatement":
  24923. {
  24924. return concat$10(["<!--", n.value, "-->"]);
  24925. }
  24926. case "StringLiteral":
  24927. {
  24928. return printStringLiteral(n.value, options);
  24929. }
  24930. case "NumberLiteral":
  24931. {
  24932. return String(n.value);
  24933. }
  24934. case "UndefinedLiteral":
  24935. {
  24936. return "undefined";
  24937. }
  24938. case "NullLiteral":
  24939. {
  24940. return "null";
  24941. }
  24942. /* istanbul ignore next */
  24943. default:
  24944. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  24945. }
  24946. }
  24947. /**
  24948. * Prints a string literal with the correct surrounding quotes based on
  24949. * `options.singleQuote` and the number of escaped quotes contained in
  24950. * the string literal. This function is the glimmer equivalent of `printString`
  24951. * in `common/util`, but has differences because of the way escaped characters
  24952. * are treated in hbs string literals.
  24953. * @param {string} stringLiteral - the string literal value
  24954. * @param {object} options - the prettier options object
  24955. */
  24956. function printStringLiteral(stringLiteral, options) {
  24957. var double = {
  24958. quote: '"',
  24959. regex: /"/g
  24960. };
  24961. var single = {
  24962. quote: "'",
  24963. regex: /'/g
  24964. };
  24965. var preferred = options.singleQuote ? single : double;
  24966. var alternate = preferred === single ? double : single;
  24967. var shouldUseAlternateQuote = false; // If `stringLiteral` contains at least one of the quote preferred for
  24968. // enclosing the string, we might want to enclose with the alternate quote
  24969. // instead, to minimize the number of escaped quotes.
  24970. if (stringLiteral.includes(preferred.quote) || stringLiteral.includes(alternate.quote)) {
  24971. var numPreferredQuotes = (stringLiteral.match(preferred.regex) || []).length;
  24972. var numAlternateQuotes = (stringLiteral.match(alternate.regex) || []).length;
  24973. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  24974. }
  24975. var enclosingQuote = shouldUseAlternateQuote ? alternate : preferred;
  24976. var escapedStringLiteral = stringLiteral.replace(enclosingQuote.regex, `\\${enclosingQuote.quote}`);
  24977. return `${enclosingQuote.quote}${escapedStringLiteral}${enclosingQuote.quote}`;
  24978. }
  24979. function printPath(path$$1, print) {
  24980. return path$$1.call(print, "path");
  24981. }
  24982. function getParams(path$$1, print) {
  24983. var node = path$$1.getValue();
  24984. var parts = [];
  24985. if (node.params.length > 0) {
  24986. parts = parts.concat(path$$1.map(print, "params"));
  24987. }
  24988. if (node.hash && node.hash.pairs.length > 0) {
  24989. parts.push(path$$1.call(print, "hash"));
  24990. }
  24991. return parts;
  24992. }
  24993. function printPathParams(path$$1, print) {
  24994. var parts = [];
  24995. parts.push(printPath(path$$1, print));
  24996. parts = parts.concat(getParams(path$$1, print));
  24997. return indent$6(group$10(join$7(line$6, parts)));
  24998. }
  24999. function printBlockParams(path$$1) {
  25000. var block = path$$1.getValue();
  25001. if (!block.program || !block.program.blockParams.length) {
  25002. return "";
  25003. }
  25004. return concat$10([" as |", block.program.blockParams.join(" "), "|"]);
  25005. }
  25006. function printOpenBlock(path$$1, print) {
  25007. return group$10(concat$10(["{{#", printPathParams(path$$1, print), printBlockParams(path$$1), softline$4, "}}"]));
  25008. }
  25009. function printCloseBlock(path$$1, print) {
  25010. return concat$10(["{{/", path$$1.call(print, "path"), "}}"]);
  25011. }
  25012. function clean$5(ast, newObj) {
  25013. delete newObj.loc; // (Glimmer/HTML) ignore TextNode whitespace
  25014. if (ast.type === "TextNode") {
  25015. if (ast.chars.replace(/\s+/, "") === "") {
  25016. return null;
  25017. }
  25018. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  25019. }
  25020. }
  25021. var printerGlimmer = {
  25022. print,
  25023. massageAstNode: clean$5
  25024. };
  25025. var name$11 = "Handlebars";
  25026. var type$10 = "markup";
  25027. var group$11 = "HTML";
  25028. var aliases$3 = ["hbs", "htmlbars"];
  25029. var extensions$10 = [".handlebars", ".hbs"];
  25030. var tmScope$10 = "text.html.handlebars";
  25031. var aceMode$10 = "handlebars";
  25032. var languageId$10 = 155;
  25033. var handlebars = {
  25034. name: name$11,
  25035. type: type$10,
  25036. group: group$11,
  25037. aliases: aliases$3,
  25038. extensions: extensions$10,
  25039. tmScope: tmScope$10,
  25040. aceMode: aceMode$10,
  25041. languageId: languageId$10
  25042. };
  25043. var handlebars$1 = Object.freeze({
  25044. name: name$11,
  25045. type: type$10,
  25046. group: group$11,
  25047. aliases: aliases$3,
  25048. extensions: extensions$10,
  25049. tmScope: tmScope$10,
  25050. aceMode: aceMode$10,
  25051. languageId: languageId$10,
  25052. default: handlebars
  25053. });
  25054. var require$$0$24 = ( handlebars$1 && handlebars ) || handlebars$1;
  25055. var languages$2 = [createLanguage(require$$0$24, {
  25056. override: {
  25057. since: null,
  25058. // unreleased
  25059. parsers: ["glimmer"],
  25060. vscodeLanguageIds: ["handlebars"]
  25061. }
  25062. })];
  25063. var printers$2 = {
  25064. glimmer: printerGlimmer
  25065. };
  25066. var languageHandlebars = {
  25067. languages: languages$2,
  25068. printers: printers$2
  25069. };
  25070. function hasPragma$2(text) {
  25071. return /^\s*#[^\n\S]*@(format|prettier)\s*(\n|$)/.test(text);
  25072. }
  25073. function insertPragma$5(text) {
  25074. return "# @format\n\n" + text;
  25075. }
  25076. var pragma$4 = {
  25077. hasPragma: hasPragma$2,
  25078. insertPragma: insertPragma$5
  25079. };
  25080. var _require$$0$builders$5 = doc.builders;
  25081. var concat$11 = _require$$0$builders$5.concat;
  25082. var join$8 = _require$$0$builders$5.join;
  25083. var hardline$9 = _require$$0$builders$5.hardline;
  25084. var line$7 = _require$$0$builders$5.line;
  25085. var softline$5 = _require$$0$builders$5.softline;
  25086. var group$12 = _require$$0$builders$5.group;
  25087. var indent$7 = _require$$0$builders$5.indent;
  25088. var ifBreak$4 = _require$$0$builders$5.ifBreak;
  25089. var hasIgnoreComment$3 = util$1.hasIgnoreComment;
  25090. var isNextLineEmpty$4 = utilShared.isNextLineEmpty;
  25091. var insertPragma$4 = pragma$4.insertPragma;
  25092. function genericPrint$3(path$$1, options, print) {
  25093. var n = path$$1.getValue();
  25094. if (!n) {
  25095. return "";
  25096. }
  25097. if (typeof n === "string") {
  25098. return n;
  25099. }
  25100. switch (n.kind) {
  25101. case "Document":
  25102. {
  25103. var parts = [];
  25104. path$$1.map(function (pathChild, index) {
  25105. parts.push(concat$11([pathChild.call(print)]));
  25106. if (index !== n.definitions.length - 1) {
  25107. parts.push(hardline$9);
  25108. if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
  25109. parts.push(hardline$9);
  25110. }
  25111. }
  25112. }, "definitions");
  25113. return concat$11([concat$11(parts), hardline$9]);
  25114. }
  25115. case "OperationDefinition":
  25116. {
  25117. var hasOperation = options.originalText[options.locStart(n)] !== "{";
  25118. var hasName = !!n.name;
  25119. return concat$11([hasOperation ? n.operation : "", hasOperation && hasName ? concat$11([" ", path$$1.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([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")]);
  25120. }
  25121. case "FragmentDefinition":
  25122. {
  25123. return concat$11(["fragment ", path$$1.call(print, "name"), n.variableDefinitions && n.variableDefinitions.length ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "variableDefinitions"))])), softline$5, ")"])) : "", " on ", path$$1.call(print, "typeCondition"), printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  25124. }
  25125. case "SelectionSet":
  25126. {
  25127. return concat$11(["{", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (selectionsPath) {
  25128. return printSequence(selectionsPath, options, print);
  25129. }, "selections"))])), hardline$9, "}"]);
  25130. }
  25131. case "Field":
  25132. {
  25133. return group$12(concat$11([n.alias ? concat$11([path$$1.call(print, "alias"), ": "]) : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  25134. return printSequence(argsPath, options, print);
  25135. }, "arguments"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? " " : "", path$$1.call(print, "selectionSet")]));
  25136. }
  25137. case "Name":
  25138. {
  25139. return n.value;
  25140. }
  25141. case "StringValue":
  25142. {
  25143. if (n.block) {
  25144. return concat$11(['"""', hardline$9, join$8(hardline$9, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$9, '"""']);
  25145. }
  25146. return concat$11(['"', n.value.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\n"), '"']);
  25147. }
  25148. case "IntValue":
  25149. case "FloatValue":
  25150. case "EnumValue":
  25151. {
  25152. return n.value;
  25153. }
  25154. case "BooleanValue":
  25155. {
  25156. return n.value ? "true" : "false";
  25157. }
  25158. case "NullValue":
  25159. {
  25160. return "null";
  25161. }
  25162. case "Variable":
  25163. {
  25164. return concat$11(["$", path$$1.call(print, "name")]);
  25165. }
  25166. case "ListValue":
  25167. {
  25168. return group$12(concat$11(["[", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "values"))])), softline$5, "]"]));
  25169. }
  25170. case "ObjectValue":
  25171. {
  25172. return group$12(concat$11(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "fields"))])), softline$5, ifBreak$4("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"]));
  25173. }
  25174. case "ObjectField":
  25175. case "Argument":
  25176. {
  25177. return concat$11([path$$1.call(print, "name"), ": ", path$$1.call(print, "value")]);
  25178. }
  25179. case "Directive":
  25180. {
  25181. return concat$11(["@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  25182. return printSequence(argsPath, options, print);
  25183. }, "arguments"))])), softline$5, ")"])) : ""]);
  25184. }
  25185. case "NamedType":
  25186. {
  25187. return path$$1.call(print, "name");
  25188. }
  25189. case "VariableDefinition":
  25190. {
  25191. return concat$11([path$$1.call(print, "variable"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$11([" = ", path$$1.call(print, "defaultValue")]) : "", printDirectives(path$$1, print, n)]);
  25192. }
  25193. case "TypeExtensionDefinition":
  25194. {
  25195. return concat$11(["extend ", path$$1.call(print, "definition")]);
  25196. }
  25197. case "ObjectTypeExtension":
  25198. case "ObjectTypeDefinition":
  25199. {
  25200. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path$$1.call(print, "name"), n.interfaces.length > 0 ? concat$11([" implements ", join$8(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$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (fieldsPath) {
  25201. return printSequence(fieldsPath, options, print);
  25202. }, "fields"))])), hardline$9, "}"]) : ""]);
  25203. }
  25204. case "FieldDefinition":
  25205. {
  25206. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  25207. return printSequence(argsPath, options, print);
  25208. }, "arguments"))])), softline$5, ")"])) : "", ": ", path$$1.call(print, "type"), printDirectives(path$$1, print, n)]);
  25209. }
  25210. case "DirectiveDefinition":
  25211. {
  25212. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", "directive ", "@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$12(concat$11(["(", indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  25213. return printSequence(argsPath, options, print);
  25214. }, "arguments"))])), softline$5, ")"])) : "", concat$11([" on ", join$8(" | ", path$$1.map(print, "locations"))])]);
  25215. }
  25216. case "EnumTypeExtension":
  25217. case "EnumTypeDefinition":
  25218. {
  25219. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.values.length > 0 ? concat$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (valuesPath) {
  25220. return printSequence(valuesPath, options, print);
  25221. }, "values"))])), hardline$9, "}"]) : ""]);
  25222. }
  25223. case "EnumValueDefinition":
  25224. {
  25225. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  25226. }
  25227. case "InputValueDefinition":
  25228. {
  25229. return concat$11([path$$1.call(print, "description"), n.description ? n.description.block ? hardline$9 : line$7 : "", path$$1.call(print, "name"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$11([" = ", path$$1.call(print, "defaultValue")]) : "", printDirectives(path$$1, print, n)]);
  25230. }
  25231. case "InputObjectTypeExtension":
  25232. case "InputObjectTypeDefinition":
  25233. {
  25234. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (fieldsPath) {
  25235. return printSequence(fieldsPath, options, print);
  25236. }, "fields"))])), hardline$9, "}"]) : ""]);
  25237. }
  25238. case "SchemaDefinition":
  25239. {
  25240. return concat$11(["schema", printDirectives(path$$1, print, n), " {", n.operationTypes.length > 0 ? indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (opsPath) {
  25241. return printSequence(opsPath, options, print);
  25242. }, "operationTypes"))])) : "", hardline$9, "}"]);
  25243. }
  25244. case "OperationTypeDefinition":
  25245. {
  25246. return concat$11([path$$1.call(print, "operation"), ": ", path$$1.call(print, "type")]);
  25247. }
  25248. case "InterfaceTypeExtension":
  25249. case "InterfaceTypeDefinition":
  25250. {
  25251. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$11([" {", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (fieldsPath) {
  25252. return printSequence(fieldsPath, options, print);
  25253. }, "fields"))])), hardline$9, "}"]) : ""]);
  25254. }
  25255. case "FragmentSpread":
  25256. {
  25257. return concat$11(["...", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  25258. }
  25259. case "InlineFragment":
  25260. {
  25261. return concat$11(["...", n.typeCondition ? concat$11([" on ", path$$1.call(print, "typeCondition")]) : "", printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  25262. }
  25263. case "UnionTypeExtension":
  25264. case "UnionTypeDefinition":
  25265. {
  25266. return group$12(concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", group$12(concat$11([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.types.length > 0 ? concat$11([" =", ifBreak$4("", " "), indent$7(concat$11([ifBreak$4(concat$11([line$7, " "])), join$8(concat$11([line$7, "| "]), path$$1.map(print, "types"))]))]) : ""]))]));
  25267. }
  25268. case "ScalarTypeExtension":
  25269. case "ScalarTypeDefinition":
  25270. {
  25271. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  25272. }
  25273. case "NonNullType":
  25274. {
  25275. return concat$11([path$$1.call(print, "type"), "!"]);
  25276. }
  25277. case "ListType":
  25278. {
  25279. return concat$11(["[", path$$1.call(print, "type"), "]"]);
  25280. }
  25281. default:
  25282. /* istanbul ignore next */
  25283. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  25284. }
  25285. }
  25286. function printDirectives(path$$1, print, n) {
  25287. if (n.directives.length === 0) {
  25288. return "";
  25289. }
  25290. return concat$11([" ", group$12(indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", " "), softline$5]), path$$1.map(print, "directives"))])))]);
  25291. }
  25292. function printSequence(sequencePath, options, print) {
  25293. var count = sequencePath.getValue().length;
  25294. return sequencePath.map(function (path$$1, i) {
  25295. var printed = print(path$$1);
  25296. if (isNextLineEmpty$4(options.originalText, path$$1.getValue(), options) && i < count - 1) {
  25297. return concat$11([printed, hardline$9]);
  25298. }
  25299. return printed;
  25300. });
  25301. }
  25302. function canAttachComment$1(node) {
  25303. return node.kind && node.kind !== "Comment";
  25304. }
  25305. function printComment$2(commentPath) {
  25306. var comment = commentPath.getValue();
  25307. if (comment.kind === "Comment") {
  25308. return "#" + comment.value.trimRight();
  25309. }
  25310. throw new Error("Not a comment: " + JSON.stringify(comment));
  25311. }
  25312. function determineInterfaceSeparator(originalSource) {
  25313. var start = originalSource.indexOf("implements");
  25314. if (start === -1) {
  25315. throw new Error("Must implement interfaces: " + originalSource);
  25316. }
  25317. var end = originalSource.indexOf("{");
  25318. if (end === -1) {
  25319. end = originalSource.length;
  25320. }
  25321. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  25322. }
  25323. function clean$6(node, newNode
  25324. /*, parent*/
  25325. ) {
  25326. delete newNode.loc;
  25327. delete newNode.comments;
  25328. }
  25329. var printerGraphql = {
  25330. print: genericPrint$3,
  25331. massageAstNode: clean$6,
  25332. hasPrettierIgnore: hasIgnoreComment$3,
  25333. insertPragma: insertPragma$4,
  25334. printComment: printComment$2,
  25335. canAttachComment: canAttachComment$1
  25336. };
  25337. var options$9 = {
  25338. bracketSpacing: commonOptions.bracketSpacing
  25339. };
  25340. var name$12 = "GraphQL";
  25341. var type$11 = "data";
  25342. var extensions$11 = [".graphql", ".gql"];
  25343. var tmScope$11 = "source.graphql";
  25344. var aceMode$11 = "text";
  25345. var languageId$11 = 139;
  25346. var graphql = {
  25347. name: name$12,
  25348. type: type$11,
  25349. extensions: extensions$11,
  25350. tmScope: tmScope$11,
  25351. aceMode: aceMode$11,
  25352. languageId: languageId$11
  25353. };
  25354. var graphql$1 = Object.freeze({
  25355. name: name$12,
  25356. type: type$11,
  25357. extensions: extensions$11,
  25358. tmScope: tmScope$11,
  25359. aceMode: aceMode$11,
  25360. languageId: languageId$11,
  25361. default: graphql
  25362. });
  25363. var require$$0$25 = ( graphql$1 && graphql ) || graphql$1;
  25364. var languages$3 = [createLanguage(require$$0$25, {
  25365. override: {
  25366. since: "1.5.0",
  25367. parsers: ["graphql"],
  25368. vscodeLanguageIds: ["graphql"]
  25369. }
  25370. })];
  25371. var printers$3 = {
  25372. graphql: printerGraphql
  25373. };
  25374. var languageGraphql = {
  25375. languages: languages$3,
  25376. options: options$9,
  25377. printers: printers$3
  25378. };
  25379. var json$6 = {"cjkPattern":"[\\u02ea-\\u02eb\\u1100-\\u11ff\\u2e80-\\u2e99\\u2e9b-\\u2ef3\\u2f00-\\u2fd5\\u3000-\\u303f\\u3041-\\u3096\\u3099-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312e\\u3131-\\u318e\\u3190-\\u3191\\u3196-\\u31ba\\u31c0-\\u31e3\\u31f0-\\u321e\\u322a-\\u3247\\u3260-\\u327e\\u328a-\\u32b0\\u32c0-\\u32cb\\u32d0-\\u32fe\\u3300-\\u3370\\u337b-\\u337f\\u33e0-\\u33fe\\u3400-\\u4db5\\u4e00-\\u9fea\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufe10-\\ufe1f\\ufe30-\\ufe6f\\uff00-\\uffef]|[\\ud840-\\ud868\\ud86a-\\ud86c\\ud86f-\\ud872\\ud874-\\ud879][\\udc00-\\udfff]|\\ud82c[\\udc00-\\udd1e]|\\ud83c[\\ude00\\ude50-\\ude51]|\\ud869[\\udc00-\\uded6\\udf00-\\udfff]|\\ud86d[\\udc00-\\udf34\\udf40-\\udfff]|\\ud86e[\\udc00-\\udc1d\\udc20-\\udfff]|\\ud873[\\udc00-\\udea1\\udeb0-\\udfff]|\\ud87a[\\udc00-\\udfe0]|\\ud87e[\\udc00-\\ude1d]","kPattern":"[\\u1100-\\u11ff\\u3001-\\u3003\\u3008-\\u3011\\u3013-\\u301f\\u302e-\\u3030\\u3037\\u30fb\\u3131-\\u318e\\u3200-\\u321e\\u3260-\\u327e\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\ufe45-\\ufe46\\uff61-\\uff65\\uffa0-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc]","punctuationPattern":"[\\u0021-\\u002f\\u003a-\\u0040\\u005b-\\u0060\\u007b-\\u007e\\u00a1\\u00a7\\u00ab\\u00b6-\\u00b7\\u00bb\\u00bf\\u037e\\u0387\\u055a-\\u055f\\u0589-\\u058a\\u05be\\u05c0\\u05c3\\u05c6\\u05f3-\\u05f4\\u0609-\\u060a\\u060c-\\u060d\\u061b\\u061e-\\u061f\\u066a-\\u066d\\u06d4\\u0700-\\u070d\\u07f7-\\u07f9\\u0830-\\u083e\\u085e\\u0964-\\u0965\\u0970\\u09fd\\u0af0\\u0df4\\u0e4f\\u0e5a-\\u0e5b\\u0f04-\\u0f12\\u0f14\\u0f3a-\\u0f3d\\u0f85\\u0fd0-\\u0fd4\\u0fd9-\\u0fda\\u104a-\\u104f\\u10fb\\u1360-\\u1368\\u1400\\u166d-\\u166e\\u169b-\\u169c\\u16eb-\\u16ed\\u1735-\\u1736\\u17d4-\\u17d6\\u17d8-\\u17da\\u1800-\\u180a\\u1944-\\u1945\\u1a1e-\\u1a1f\\u1aa0-\\u1aa6\\u1aa8-\\u1aad\\u1b5a-\\u1b60\\u1bfc-\\u1bff\\u1c3b-\\u1c3f\\u1c7e-\\u1c7f\\u1cc0-\\u1cc7\\u1cd3\\u2010-\\u2027\\u2030-\\u2043\\u2045-\\u2051\\u2053-\\u205e\\u207d-\\u207e\\u208d-\\u208e\\u2308-\\u230b\\u2329-\\u232a\\u2768-\\u2775\\u27c5-\\u27c6\\u27e6-\\u27ef\\u2983-\\u2998\\u29d8-\\u29db\\u29fc-\\u29fd\\u2cf9-\\u2cfc\\u2cfe-\\u2cff\\u2d70\\u2e00-\\u2e2e\\u2e30-\\u2e49\\u3001-\\u3003\\u3008-\\u3011\\u3014-\\u301f\\u3030\\u303d\\u30a0\\u30fb\\ua4fe-\\ua4ff\\ua60d-\\ua60f\\ua673\\ua67e\\ua6f2-\\ua6f7\\ua874-\\ua877\\ua8ce-\\ua8cf\\ua8f8-\\ua8fa\\ua8fc\\ua92e-\\ua92f\\ua95f\\ua9c1-\\ua9cd\\ua9de-\\ua9df\\uaa5c-\\uaa5f\\uaade-\\uaadf\\uaaf0-\\uaaf1\\uabeb\\ufd3e-\\ufd3f\\ufe10-\\ufe19\\ufe30-\\ufe52\\ufe54-\\ufe61\\ufe63\\ufe68\\ufe6a-\\ufe6b\\uff01-\\uff03\\uff05-\\uff0a\\uff0c-\\uff0f\\uff1a-\\uff1b\\uff1f-\\uff20\\uff3b-\\uff3d\\uff3f\\uff5b\\uff5d\\uff5f-\\uff65]|\\ud800[\\udd00-\\udd02\\udf9f\\udfd0]|\\ud801[\\udd6f]|\\ud802[\\udc57\\udd1f\\udd3f\\ude50-\\ude58\\ude7f\\udef0-\\udef6\\udf39-\\udf3f\\udf99-\\udf9c]|\\ud804[\\udc47-\\udc4d\\udcbb-\\udcbc\\udcbe-\\udcc1\\udd40-\\udd43\\udd74-\\udd75\\uddc5-\\uddc9\\uddcd\\udddb\\udddd-\\udddf\\ude38-\\ude3d\\udea9]|\\ud805[\\udc4b-\\udc4f\\udc5b\\udc5d\\udcc6\\uddc1-\\uddd7\\ude41-\\ude43\\ude60-\\ude6c\\udf3c-\\udf3e]|\\ud806[\\ude3f-\\ude46\\ude9a-\\ude9c\\ude9e-\\udea2]|\\ud807[\\udc41-\\udc45\\udc70-\\udc71]|\\ud809[\\udc70-\\udc74]|\\ud81a[\\ude6e-\\ude6f\\udef5\\udf37-\\udf3b\\udf44]|\\ud82f[\\udc9f]|\\ud836[\\ude87-\\ude8b]|\\ud83a[\\udd5e-\\udd5f]"};
  25380. var cjkPattern = json$6.cjkPattern;
  25381. var kPattern = json$6.kPattern;
  25382. var punctuationPattern$1 = json$6.punctuationPattern;
  25383. var getLast$4 = util$1.getLast;
  25384. var INLINE_NODE_TYPES$1 = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
  25385. var INLINE_NODE_WRAPPER_TYPES$1 = INLINE_NODE_TYPES$1.concat(["tableCell", "paragraph", "heading"]);
  25386. var kRegex = new RegExp(kPattern);
  25387. var punctuationRegex = new RegExp(punctuationPattern$1);
  25388. /**
  25389. * split text into whitespaces and words
  25390. * @param {string} text
  25391. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  25392. */
  25393. function splitText$1(text, options) {
  25394. var KIND_NON_CJK = "non-cjk";
  25395. var KIND_CJ_LETTER = "cj-letter";
  25396. var KIND_K_LETTER = "k-letter";
  25397. var KIND_CJK_PUNCTUATION = "cjk-punctuation";
  25398. var nodes = [];
  25399. (options.proseWrap === "preserve" ? text : text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")).split(/([ \t\n]+)/).forEach(function (token, index, tokens) {
  25400. // whitespace
  25401. if (index % 2 === 1) {
  25402. nodes.push({
  25403. type: "whitespace",
  25404. value: /\n/.test(token) ? "\n" : " "
  25405. });
  25406. return;
  25407. } // word separated by whitespace
  25408. if ((index === 0 || index === tokens.length - 1) && token === "") {
  25409. return;
  25410. }
  25411. token.split(new RegExp(`(${cjkPattern})`)).forEach(function (innerToken, innerIndex, innerTokens) {
  25412. if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
  25413. return;
  25414. } // non-CJK word
  25415. if (innerIndex % 2 === 0) {
  25416. if (innerToken !== "") {
  25417. appendNode({
  25418. type: "word",
  25419. value: innerToken,
  25420. kind: KIND_NON_CJK,
  25421. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  25422. hasTrailingPunctuation: punctuationRegex.test(getLast$4(innerToken))
  25423. });
  25424. }
  25425. return;
  25426. } // CJK character
  25427. appendNode(punctuationRegex.test(innerToken) ? {
  25428. type: "word",
  25429. value: innerToken,
  25430. kind: KIND_CJK_PUNCTUATION,
  25431. hasLeadingPunctuation: true,
  25432. hasTrailingPunctuation: true
  25433. } : {
  25434. type: "word",
  25435. value: innerToken,
  25436. kind: kRegex.test(innerToken) ? KIND_K_LETTER : KIND_CJ_LETTER,
  25437. hasLeadingPunctuation: false,
  25438. hasTrailingPunctuation: false
  25439. });
  25440. });
  25441. });
  25442. return nodes;
  25443. function appendNode(node) {
  25444. var lastNode = getLast$4(nodes);
  25445. if (lastNode && lastNode.type === "word") {
  25446. if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJ_LETTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJ_LETTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) {
  25447. nodes.push({
  25448. type: "whitespace",
  25449. value: " "
  25450. });
  25451. } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
  25452. ![lastNode.value, node.value].some(function (value) {
  25453. return /\u3000/.test(value);
  25454. })) {
  25455. nodes.push({
  25456. type: "whitespace",
  25457. value: ""
  25458. });
  25459. }
  25460. }
  25461. nodes.push(node);
  25462. function isBetween(kind1, kind2) {
  25463. return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
  25464. }
  25465. }
  25466. }
  25467. function getOrderedListItemInfo$1(orderListItem, originalText) {
  25468. var _originalText$slice$m = originalText.slice(orderListItem.position.start.offset, orderListItem.position.end.offset).match(/^\s*(\d+)(\.|\))(\s*)/),
  25469. _originalText$slice$m2 = _slicedToArray(_originalText$slice$m, 4),
  25470. numberText = _originalText$slice$m2[1],
  25471. marker = _originalText$slice$m2[2],
  25472. leadingSpaces = _originalText$slice$m2[3];
  25473. return {
  25474. numberText,
  25475. marker,
  25476. leadingSpaces
  25477. };
  25478. } // workaround for https://github.com/remarkjs/remark/issues/351
  25479. // leading and trailing newlines are stripped by remark
  25480. function getFencedCodeBlockValue$2(node, originalText) {
  25481. var text = originalText.slice(node.position.start.offset, node.position.end.offset);
  25482. var leadingSpaceCount = text.match(/^\s*/)[0].length;
  25483. var replaceRegex = new RegExp(`^\\s{0,${leadingSpaceCount}}`);
  25484. var lineContents = text.split("\n");
  25485. var markerStyle = text[leadingSpaceCount]; // ` or ~
  25486. var marker = text.slice(leadingSpaceCount).match(new RegExp(`^[${markerStyle}]+`))[0]; // https://spec.commonmark.org/0.28/#example-104: Closing fences may be indented by 0-3 spaces
  25487. // https://spec.commonmark.org/0.28/#example-93: The closing code fence must be at least as long as the opening fence
  25488. var hasEndMarker = new RegExp(`^\\s{0,3}${marker}`).test(lineContents[lineContents.length - 1].slice(getIndent(lineContents.length - 1)));
  25489. return lineContents.slice(1, hasEndMarker ? -1 : undefined).map(function (x, i) {
  25490. return x.slice(getIndent(i + 1)).replace(replaceRegex, "");
  25491. }).join("\n");
  25492. function getIndent(lineIndex) {
  25493. return node.position.indent[lineIndex - 1] - 1;
  25494. }
  25495. }
  25496. function mapAst(ast, handler) {
  25497. return function preorder(node, index, parentStack) {
  25498. parentStack = parentStack || [];
  25499. var newNode = Object.assign({}, handler(node, index, parentStack));
  25500. if (newNode.children) {
  25501. newNode.children = newNode.children.map(function (child, index) {
  25502. return preorder(child, index, [newNode].concat(parentStack));
  25503. });
  25504. }
  25505. return newNode;
  25506. }(ast, null, null);
  25507. }
  25508. var utils$8 = {
  25509. mapAst,
  25510. splitText: splitText$1,
  25511. punctuationPattern: punctuationPattern$1,
  25512. getFencedCodeBlockValue: getFencedCodeBlockValue$2,
  25513. getOrderedListItemInfo: getOrderedListItemInfo$1,
  25514. INLINE_NODE_TYPES: INLINE_NODE_TYPES$1,
  25515. INLINE_NODE_WRAPPER_TYPES: INLINE_NODE_WRAPPER_TYPES$1
  25516. };
  25517. var _require$$0$builders$7 = doc.builders;
  25518. var hardline$11 = _require$$0$builders$7.hardline;
  25519. var literalline$5 = _require$$0$builders$7.literalline;
  25520. var concat$13 = _require$$0$builders$7.concat;
  25521. var markAsRoot$3 = _require$$0$builders$7.markAsRoot;
  25522. var mapDoc$6 = doc.utils.mapDoc;
  25523. var getFencedCodeBlockValue$1 = utils$8.getFencedCodeBlockValue;
  25524. function embed$4(path$$1, print, textToDoc, options) {
  25525. var node = path$$1.getValue();
  25526. if (node.type === "code" && node.lang !== null) {
  25527. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  25528. var langMatch = node.lang.match(/^[A-Za-z0-9_-]+/);
  25529. var lang = langMatch ? langMatch[0] : "";
  25530. var parser = getParserName(lang);
  25531. if (parser) {
  25532. var styleUnit = options.__inJsTemplate ? "~" : "`";
  25533. var style = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  25534. var doc$$2 = textToDoc(getFencedCodeBlockValue$1(node, options.originalText), {
  25535. parser
  25536. });
  25537. return markAsRoot$3(concat$13([style, node.lang, hardline$11, replaceNewlinesWithLiterallines(doc$$2), style]));
  25538. }
  25539. }
  25540. if (node.type === "yaml") {
  25541. return markAsRoot$3(concat$13(["---", hardline$11, node.value && node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  25542. parser: "yaml"
  25543. })) : "", "---"]));
  25544. } // MDX
  25545. switch (node.type) {
  25546. case "importExport":
  25547. return textToDoc(node.value, {
  25548. parser: "babel"
  25549. });
  25550. case "jsx":
  25551. return textToDoc(node.value, {
  25552. parser: "__js_expression"
  25553. });
  25554. }
  25555. return null;
  25556. function getParserName(lang) {
  25557. var supportInfo = support.getSupportInfo(null, {
  25558. plugins: options.plugins
  25559. });
  25560. var language = supportInfo.languages.find(function (language) {
  25561. return language.name.toLowerCase() === lang || language.aliases && language.aliases.indexOf(lang) !== -1 || language.extensions && language.extensions.find(function (ext) {
  25562. return ext.substring(1) === lang;
  25563. });
  25564. });
  25565. if (language) {
  25566. return language.parsers[0];
  25567. }
  25568. return null;
  25569. }
  25570. function replaceNewlinesWithLiterallines(doc$$2) {
  25571. return mapDoc$6(doc$$2, function (currentDoc) {
  25572. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$13(currentDoc.split(/(\n)/g).map(function (v, i) {
  25573. return i % 2 === 0 ? v : literalline$5;
  25574. })) : currentDoc;
  25575. });
  25576. }
  25577. }
  25578. var embed_1$4 = embed$4;
  25579. var pragma$6 = createCommonjsModule(function (module) {
  25580. "use strict";
  25581. var pragmas = ["format", "prettier"];
  25582. function startWithPragma(text) {
  25583. var pragma = `@(${pragmas.join("|")})`;
  25584. var regex = new RegExp([`<!--\\s*${pragma}\\s*-->`, `<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`].join("|"), "m");
  25585. var matched = text.match(regex);
  25586. return matched && matched.index === 0;
  25587. }
  25588. module.exports = {
  25589. startWithPragma,
  25590. hasPragma: function hasPragma(text) {
  25591. return startWithPragma(frontMatter(text).content.trimLeft());
  25592. },
  25593. insertPragma: function insertPragma(text) {
  25594. var extracted = frontMatter(text);
  25595. var pragma = `<!-- @${pragmas[0]} -->`;
  25596. return extracted.frontMatter ? `${extracted.frontMatter.raw}\n\n${pragma}\n\n${extracted.content}` : `${pragma}\n\n${extracted.content}`;
  25597. }
  25598. };
  25599. });
  25600. var getOrderedListItemInfo$2 = utils$8.getOrderedListItemInfo;
  25601. var mapAst$1 = utils$8.mapAst;
  25602. var splitText$2 = utils$8.splitText; // 0x0 ~ 0x10ffff
  25603. var isSingleCharRegex = /^([\u0000-\uffff]|[\ud800-\udbff][\udc00-\udfff])$/;
  25604. function preprocess$2(ast, options) {
  25605. ast = restoreUnescapedCharacter(ast, options);
  25606. ast = mergeContinuousTexts(ast);
  25607. ast = transformInlineCode(ast);
  25608. ast = transformIndentedCodeblockAndMarkItsParentList(ast, options);
  25609. ast = markAlignedList(ast, options);
  25610. ast = splitTextIntoSentences(ast, options);
  25611. ast = transformImportExport(ast);
  25612. ast = mergeContinuousImportExport(ast);
  25613. return ast;
  25614. }
  25615. function transformImportExport(ast) {
  25616. return mapAst$1(ast, function (node) {
  25617. if (node.type !== "import" && node.type !== "export") {
  25618. return node;
  25619. }
  25620. return Object.assign({}, node, {
  25621. type: "importExport"
  25622. });
  25623. });
  25624. }
  25625. function transformInlineCode(ast) {
  25626. return mapAst$1(ast, function (node) {
  25627. if (node.type !== "inlineCode") {
  25628. return node;
  25629. }
  25630. return Object.assign({}, node, {
  25631. value: node.value.replace(/\s+/g, " ")
  25632. });
  25633. });
  25634. }
  25635. function restoreUnescapedCharacter(ast, options) {
  25636. return mapAst$1(ast, function (node) {
  25637. return node.type !== "text" ? node : Object.assign({}, node, {
  25638. value: node.value !== "*" && node.value !== "_" && node.value !== "$" && // handle these cases in printer
  25639. isSingleCharRegex.test(node.value) && node.position.end.offset - node.position.start.offset !== node.value.length ? options.originalText.slice(node.position.start.offset, node.position.end.offset) : node.value
  25640. });
  25641. });
  25642. }
  25643. function mergeContinuousImportExport(ast) {
  25644. return mergeChildren(ast, function (prevNode, node) {
  25645. return prevNode.type === "importExport" && node.type === "importExport";
  25646. }, function (prevNode, node) {
  25647. return {
  25648. type: "importExport",
  25649. value: prevNode.value + "\n\n" + node.value,
  25650. position: {
  25651. start: prevNode.position.start,
  25652. end: node.position.end
  25653. }
  25654. };
  25655. });
  25656. }
  25657. function mergeChildren(ast, shouldMerge, mergeNode) {
  25658. return mapAst$1(ast, function (node) {
  25659. if (!node.children) {
  25660. return node;
  25661. }
  25662. var children = node.children.reduce(function (current, child) {
  25663. var lastChild = current[current.length - 1];
  25664. if (lastChild && shouldMerge(lastChild, child)) {
  25665. current.splice(-1, 1, mergeNode(lastChild, child));
  25666. } else {
  25667. current.push(child);
  25668. }
  25669. return current;
  25670. }, []);
  25671. return Object.assign({}, node, {
  25672. children
  25673. });
  25674. });
  25675. }
  25676. function mergeContinuousTexts(ast) {
  25677. return mergeChildren(ast, function (prevNode, node) {
  25678. return prevNode.type === "text" && node.type === "text";
  25679. }, function (prevNode, node) {
  25680. return {
  25681. type: "text",
  25682. value: prevNode.value + node.value,
  25683. position: {
  25684. start: prevNode.position.start,
  25685. end: node.position.end
  25686. }
  25687. };
  25688. });
  25689. }
  25690. function splitTextIntoSentences(ast, options) {
  25691. return mapAst$1(ast, function (node, index, _ref) {
  25692. var _ref2 = _slicedToArray(_ref, 1),
  25693. parentNode = _ref2[0];
  25694. if (node.type !== "text") {
  25695. return node;
  25696. }
  25697. var value = node.value;
  25698. if (parentNode.type === "paragraph") {
  25699. if (index === 0) {
  25700. value = value.trimLeft();
  25701. }
  25702. if (index === parentNode.children.length - 1) {
  25703. value = value.trimRight();
  25704. }
  25705. }
  25706. return {
  25707. type: "sentence",
  25708. position: node.position,
  25709. children: splitText$2(value, options)
  25710. };
  25711. });
  25712. }
  25713. function transformIndentedCodeblockAndMarkItsParentList(ast, options) {
  25714. return mapAst$1(ast, function (node, index, parentStack) {
  25715. if (node.type === "code") {
  25716. // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  25717. var isIndented = /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset));
  25718. node.isIndented = isIndented;
  25719. if (isIndented) {
  25720. for (var i = 0; i < parentStack.length; i++) {
  25721. var parent = parentStack[i]; // no need to check checked items
  25722. if (parent.hasIndentedCodeblock) {
  25723. break;
  25724. }
  25725. if (parent.type === "list") {
  25726. parent.hasIndentedCodeblock = true;
  25727. }
  25728. }
  25729. }
  25730. }
  25731. return node;
  25732. });
  25733. }
  25734. function markAlignedList(ast, options) {
  25735. return mapAst$1(ast, function (node, index, parentStack) {
  25736. if (node.type === "list" && node.children.length !== 0) {
  25737. // if one of its parents is not aligned, it's not possible to be aligned in sub-lists
  25738. for (var i = 0; i < parentStack.length; i++) {
  25739. var parent = parentStack[i];
  25740. if (parent.type === "list" && !parent.isAligned) {
  25741. node.isAligned = false;
  25742. return node;
  25743. }
  25744. }
  25745. node.isAligned = isAligned(node);
  25746. }
  25747. return node;
  25748. });
  25749. function getListItemStart(listItem) {
  25750. return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1;
  25751. }
  25752. function isAligned(list) {
  25753. if (!list.ordered) {
  25754. /**
  25755. * - 123
  25756. * - 123
  25757. */
  25758. return true;
  25759. }
  25760. var _list$children = _slicedToArray(list.children, 2),
  25761. firstItem = _list$children[0],
  25762. secondItem = _list$children[1];
  25763. var firstInfo = getOrderedListItemInfo$2(firstItem, options.originalText);
  25764. if (firstInfo.leadingSpaces.length > 1) {
  25765. /**
  25766. * 1. 123
  25767. *
  25768. * 1. 123
  25769. * 1. 123
  25770. */
  25771. return true;
  25772. }
  25773. var firstStart = getListItemStart(firstItem);
  25774. if (firstStart === -1) {
  25775. /**
  25776. * 1.
  25777. *
  25778. * 1.
  25779. * 1.
  25780. */
  25781. return false;
  25782. }
  25783. if (list.children.length === 1) {
  25784. /**
  25785. * aligned:
  25786. *
  25787. * 11. 123
  25788. *
  25789. * not aligned:
  25790. *
  25791. * 1. 123
  25792. */
  25793. return firstStart % options.tabWidth === 0;
  25794. }
  25795. var secondStart = getListItemStart(secondItem);
  25796. if (firstStart !== secondStart) {
  25797. /**
  25798. * 11. 123
  25799. * 1. 123
  25800. *
  25801. * 1. 123
  25802. * 11. 123
  25803. */
  25804. return false;
  25805. }
  25806. if (firstStart % options.tabWidth === 0) {
  25807. /**
  25808. * 11. 123
  25809. * 12. 123
  25810. */
  25811. return true;
  25812. }
  25813. /**
  25814. * aligned:
  25815. *
  25816. * 11. 123
  25817. * 1. 123
  25818. *
  25819. * not aligned:
  25820. *
  25821. * 1. 123
  25822. * 2. 123
  25823. */
  25824. var secondInfo = getOrderedListItemInfo$2(secondItem, options.originalText);
  25825. return secondInfo.leadingSpaces.length > 1;
  25826. }
  25827. }
  25828. var preprocess_1$2 = preprocess$2;
  25829. var _require$$0$builders$6 = doc.builders;
  25830. var breakParent$3 = _require$$0$builders$6.breakParent;
  25831. var concat$12 = _require$$0$builders$6.concat;
  25832. var join$9 = _require$$0$builders$6.join;
  25833. var line$8 = _require$$0$builders$6.line;
  25834. var literalline$4 = _require$$0$builders$6.literalline;
  25835. var markAsRoot$2 = _require$$0$builders$6.markAsRoot;
  25836. var hardline$10 = _require$$0$builders$6.hardline;
  25837. var softline$6 = _require$$0$builders$6.softline;
  25838. var ifBreak$5 = _require$$0$builders$6.ifBreak;
  25839. var fill$4 = _require$$0$builders$6.fill;
  25840. var align$2 = _require$$0$builders$6.align;
  25841. var indent$8 = _require$$0$builders$6.indent;
  25842. var group$13 = _require$$0$builders$6.group;
  25843. var mapDoc$5 = doc.utils.mapDoc;
  25844. var printDocToString$3 = doc.printer.printDocToString;
  25845. var getFencedCodeBlockValue = utils$8.getFencedCodeBlockValue;
  25846. var getOrderedListItemInfo = utils$8.getOrderedListItemInfo;
  25847. var splitText = utils$8.splitText;
  25848. var punctuationPattern = utils$8.punctuationPattern;
  25849. var INLINE_NODE_TYPES = utils$8.INLINE_NODE_TYPES;
  25850. var INLINE_NODE_WRAPPER_TYPES = utils$8.INLINE_NODE_WRAPPER_TYPES;
  25851. var replaceEndOfLineWith$1 = util$1.replaceEndOfLineWith;
  25852. var TRAILING_HARDLINE_NODES = ["importExport"];
  25853. var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  25854. var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
  25855. function genericPrint$4(path$$1, options, print) {
  25856. var node = path$$1.getValue();
  25857. if (shouldRemainTheSameContent(path$$1)) {
  25858. return concat$12(splitText(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(function (node) {
  25859. return node.type === "word" ? node.value : node.value === "" ? "" : printLine(path$$1, node.value, options);
  25860. }));
  25861. }
  25862. switch (node.type) {
  25863. case "root":
  25864. if (node.children.length === 0) {
  25865. return "";
  25866. }
  25867. return concat$12([normalizeDoc(printRoot(path$$1, options, print)), TRAILING_HARDLINE_NODES.indexOf(getLastDescendantNode(node).type) === -1 ? hardline$10 : ""]);
  25868. case "paragraph":
  25869. return printChildren(path$$1, options, print, {
  25870. postprocessor: fill$4
  25871. });
  25872. case "sentence":
  25873. return printChildren(path$$1, options, print);
  25874. case "word":
  25875. return node.value.replace(/[*$]/g, "\\$&") // escape all `*` and `$` (math)
  25876. .replace(new RegExp([`(^|${punctuationPattern})(_+)`, `(_+)(${punctuationPattern}|$)`].join("|"), "g"), function (_, text1, underscore1, underscore2, text2) {
  25877. return (underscore1 ? `${text1}${underscore1}` : `${underscore2}${text2}`).replace(/_/g, "\\_");
  25878. });
  25879. // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  25880. case "whitespace":
  25881. {
  25882. var parentNode = path$$1.getParentNode();
  25883. var index = parentNode.children.indexOf(node);
  25884. var nextNode = parentNode.children[index + 1];
  25885. var proseWrap = // leading char that may cause different syntax
  25886. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value) ? "never" : options.proseWrap;
  25887. return printLine(path$$1, node.value, {
  25888. proseWrap
  25889. });
  25890. }
  25891. case "emphasis":
  25892. {
  25893. var _parentNode = path$$1.getParentNode();
  25894. var _index = _parentNode.children.indexOf(node);
  25895. var prevNode = _parentNode.children[_index - 1];
  25896. var _nextNode = _parentNode.children[_index + 1];
  25897. var hasPrevOrNextWord = // `1*2*3` is considered emphais but `1_2_3` is not
  25898. 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;
  25899. var style = hasPrevOrNextWord || getAncestorNode$2(path$$1, "emphasis") ? "*" : "_";
  25900. return concat$12([style, printChildren(path$$1, options, print), style]);
  25901. }
  25902. case "strong":
  25903. return concat$12(["**", printChildren(path$$1, options, print), "**"]);
  25904. case "delete":
  25905. return concat$12(["~~", printChildren(path$$1, options, print), "~~"]);
  25906. case "inlineCode":
  25907. {
  25908. var backtickCount = util$1.getMinNotPresentContinuousCount(node.value, "`");
  25909. var _style = "`".repeat(backtickCount || 1);
  25910. var gap = backtickCount ? " " : "";
  25911. return concat$12([_style, gap, node.value, gap, _style]);
  25912. }
  25913. case "link":
  25914. switch (options.originalText[node.position.start.offset]) {
  25915. case "<":
  25916. {
  25917. var mailto = "mailto:";
  25918. var url = // <hello@example.com> is parsed as { url: "mailto:hello@example.com" }
  25919. node.url.startsWith(mailto) && options.originalText.slice(node.position.start.offset + 1, node.position.start.offset + 1 + mailto.length) !== mailto ? node.url.slice(mailto.length) : node.url;
  25920. return concat$12(["<", url, ">"]);
  25921. }
  25922. case "[":
  25923. return concat$12(["[", printChildren(path$$1, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  25924. default:
  25925. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  25926. }
  25927. case "image":
  25928. return concat$12(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  25929. case "blockquote":
  25930. return concat$12(["> ", align$2("> ", printChildren(path$$1, options, print))]);
  25931. case "heading":
  25932. return concat$12(["#".repeat(node.depth) + " ", printChildren(path$$1, options, print)]);
  25933. case "code":
  25934. {
  25935. if (node.isIndented) {
  25936. // indented code block
  25937. var alignment = " ".repeat(4);
  25938. return align$2(alignment, concat$12([alignment, concat$12(replaceEndOfLineWith$1(node.value, hardline$10))]));
  25939. } // fenced code block
  25940. var styleUnit = options.__inJsTemplate ? "~" : "`";
  25941. var _style2 = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  25942. return concat$12([_style2, node.lang || "", hardline$10, concat$12(replaceEndOfLineWith$1(getFencedCodeBlockValue(node, options.originalText), hardline$10)), hardline$10, _style2]);
  25943. }
  25944. case "yaml":
  25945. case "toml":
  25946. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  25947. case "html":
  25948. {
  25949. var _parentNode2 = path$$1.getParentNode();
  25950. var value = _parentNode2.type === "root" && util$1.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
  25951. var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
  25952. return concat$12(replaceEndOfLineWith$1(value, isHtmlComment ? hardline$10 : markAsRoot$2(literalline$4)));
  25953. }
  25954. case "list":
  25955. {
  25956. var nthSiblingIndex = getNthListSiblingIndex(node, path$$1.getParentNode());
  25957. var isGitDiffFriendlyOrderedList = node.ordered && node.children.length > 1 && +getOrderedListItemInfo(node.children[1], options.originalText).numberText === 1;
  25958. return printChildren(path$$1, options, print, {
  25959. processor: function processor(childPath, index) {
  25960. var prefix = getPrefix();
  25961. return concat$12([prefix, align$2(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
  25962. function getPrefix() {
  25963. var rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* ";
  25964. return node.isAligned ||
  25965. /* workaround for https://github.com/remarkjs/remark/issues/315 */
  25966. node.hasIndentedCodeblock ? alignListPrefix(rawPrefix, options) : rawPrefix;
  25967. }
  25968. }
  25969. });
  25970. }
  25971. case "thematicBreak":
  25972. {
  25973. var counter = getAncestorCounter$1(path$$1, "list");
  25974. if (counter === -1) {
  25975. return "---";
  25976. }
  25977. var _nthSiblingIndex = getNthListSiblingIndex(path$$1.getParentNode(counter), path$$1.getParentNode(counter + 1));
  25978. return _nthSiblingIndex % 2 === 0 ? "***" : "---";
  25979. }
  25980. case "linkReference":
  25981. return concat$12(["[", printChildren(path$$1, options, print), "]", node.referenceType === "full" ? concat$12(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
  25982. case "imageReference":
  25983. switch (node.referenceType) {
  25984. case "full":
  25985. return concat$12(["![", node.alt || "", "][", node.identifier, "]"]);
  25986. default:
  25987. return concat$12(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
  25988. }
  25989. case "definition":
  25990. {
  25991. var lineOrSpace = options.proseWrap === "always" ? line$8 : " ";
  25992. return group$13(concat$12([concat$12(["[", node.identifier, "]:"]), indent$8(concat$12([lineOrSpace, printUrl(node.url), node.title === null ? "" : concat$12([lineOrSpace, printTitle(node.title, options, false)])]))]));
  25993. }
  25994. case "footnote":
  25995. return concat$12(["[^", printChildren(path$$1, options, print), "]"]);
  25996. case "footnoteReference":
  25997. return concat$12(["[^", node.identifier, "]"]);
  25998. case "footnoteDefinition":
  25999. {
  26000. var _nextNode2 = path$$1.getParentNode().children[path$$1.getName() + 1];
  26001. var shouldInlineFootnote = node.children.length === 1 && node.children[0].type === "paragraph" && (options.proseWrap === "never" || options.proseWrap === "preserve" && node.children[0].position.start.line === node.children[0].position.end.line);
  26002. return concat$12(["[^", node.identifier, "]: ", shouldInlineFootnote ? printChildren(path$$1, options, print) : group$13(concat$12([align$2(" ".repeat(options.tabWidth), printChildren(path$$1, options, print, {
  26003. processor: function processor(childPath, index) {
  26004. return index === 0 ? group$13(concat$12([softline$6, softline$6, childPath.call(print)])) : childPath.call(print);
  26005. }
  26006. })), _nextNode2 && _nextNode2.type === "footnoteDefinition" ? softline$6 : ""]))]);
  26007. }
  26008. case "table":
  26009. return printTable(path$$1, options, print);
  26010. case "tableCell":
  26011. return printChildren(path$$1, options, print);
  26012. case "break":
  26013. return /\s/.test(options.originalText[node.position.start.offset]) ? concat$12([" ", markAsRoot$2(literalline$4)]) : concat$12(["\\", hardline$10]);
  26014. case "liquidNode":
  26015. return concat$12(replaceEndOfLineWith$1(node.value, hardline$10));
  26016. // MDX
  26017. case "importExport":
  26018. case "jsx":
  26019. return node.value;
  26020. // fallback to the original text if multiparser failed
  26021. case "math":
  26022. return concat$12(["$$", hardline$10, node.value ? concat$12([concat$12(replaceEndOfLineWith$1(node.value, hardline$10)), hardline$10]) : "", "$$"]);
  26023. case "inlineMath":
  26024. {
  26025. // remark-math trims content but we don't want to remove whitespaces
  26026. // since it's very possible that it's recognized as math accidentally
  26027. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  26028. }
  26029. case "tableRow": // handled in "table"
  26030. case "listItem": // handled in "list"
  26031. default:
  26032. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  26033. }
  26034. }
  26035. function printListItem(path$$1, options, print, listPrefix) {
  26036. var node = path$$1.getValue();
  26037. var prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  26038. return concat$12([prefix, printChildren(path$$1, options, print, {
  26039. processor: function processor(childPath, index) {
  26040. if (index === 0 && childPath.getValue().type !== "list") {
  26041. return align$2(" ".repeat(prefix.length), childPath.call(print));
  26042. }
  26043. var alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  26044. );
  26045. return concat$12([alignment, align$2(alignment, childPath.call(print))]);
  26046. }
  26047. })]);
  26048. }
  26049. function alignListPrefix(prefix, options) {
  26050. var additionalSpaces = getAdditionalSpaces();
  26051. return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  26052. );
  26053. function getAdditionalSpaces() {
  26054. var restSpaces = prefix.length % options.tabWidth;
  26055. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  26056. }
  26057. }
  26058. function getNthListSiblingIndex(node, parentNode) {
  26059. return getNthSiblingIndex(node, parentNode, function (siblingNode) {
  26060. return siblingNode.ordered === node.ordered;
  26061. });
  26062. }
  26063. function getNthSiblingIndex(node, parentNode, condition) {
  26064. condition = condition || function () {
  26065. return true;
  26066. };
  26067. var index = -1;
  26068. var _iteratorNormalCompletion = true;
  26069. var _didIteratorError = false;
  26070. var _iteratorError = undefined;
  26071. try {
  26072. for (var _iterator = parentNode.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  26073. var childNode = _step.value;
  26074. if (childNode.type === node.type && condition(childNode)) {
  26075. index++;
  26076. } else {
  26077. index = -1;
  26078. }
  26079. if (childNode === node) {
  26080. return index;
  26081. }
  26082. }
  26083. } catch (err) {
  26084. _didIteratorError = true;
  26085. _iteratorError = err;
  26086. } finally {
  26087. try {
  26088. if (!_iteratorNormalCompletion && _iterator.return != null) {
  26089. _iterator.return();
  26090. }
  26091. } finally {
  26092. if (_didIteratorError) {
  26093. throw _iteratorError;
  26094. }
  26095. }
  26096. }
  26097. }
  26098. function getAncestorCounter$1(path$$1, typeOrTypes) {
  26099. var types = [].concat(typeOrTypes);
  26100. var counter = -1;
  26101. var ancestorNode;
  26102. while (ancestorNode = path$$1.getParentNode(++counter)) {
  26103. if (types.indexOf(ancestorNode.type) !== -1) {
  26104. return counter;
  26105. }
  26106. }
  26107. return -1;
  26108. }
  26109. function getAncestorNode$2(path$$1, typeOrTypes) {
  26110. var counter = getAncestorCounter$1(path$$1, typeOrTypes);
  26111. return counter === -1 ? null : path$$1.getParentNode(counter);
  26112. }
  26113. function printLine(path$$1, value, options) {
  26114. if (options.proseWrap === "preserve" && value === "\n") {
  26115. return hardline$10;
  26116. }
  26117. var isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path$$1, SINGLE_LINE_NODE_TYPES);
  26118. return value !== "" ? isBreakable ? line$8 : " " : isBreakable ? softline$6 : "";
  26119. }
  26120. function printTable(path$$1, options, print) {
  26121. var hardlineWithoutBreakParent = hardline$10.parts[0];
  26122. var node = path$$1.getValue();
  26123. var contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  26124. path$$1.map(function (rowPath) {
  26125. var rowContents = [];
  26126. rowPath.map(function (cellPath) {
  26127. rowContents.push(printDocToString$3(cellPath.call(print), options).formatted);
  26128. }, "children");
  26129. contents.push(rowContents);
  26130. }, "children"); // Get the width of each column
  26131. var columnMaxWidths = contents.reduce(function (currentWidths, rowContents) {
  26132. return currentWidths.map(function (width, columnIndex) {
  26133. return Math.max(width, util$1.getStringWidth(rowContents[columnIndex]));
  26134. });
  26135. }, contents[0].map(function () {
  26136. return 3;
  26137. }) // minimum width = 3 (---, :--, :-:, --:)
  26138. );
  26139. var alignedTable = join$9(hardlineWithoutBreakParent, [printRow(contents[0]), printSeparator(), join$9(hardlineWithoutBreakParent, contents.slice(1).map(function (rowContents) {
  26140. return printRow(rowContents);
  26141. }))]);
  26142. if (options.proseWrap !== "never") {
  26143. return concat$12([breakParent$3, alignedTable]);
  26144. } // Only if the --prose-wrap never is set and it exceeds the print width.
  26145. var compactTable = join$9(hardlineWithoutBreakParent, [printRow(contents[0],
  26146. /* isCompact */
  26147. true), printSeparator(
  26148. /* isCompact */
  26149. true), join$9(hardlineWithoutBreakParent, contents.slice(1).map(function (rowContents) {
  26150. return printRow(rowContents,
  26151. /* isCompact */
  26152. true);
  26153. }))]);
  26154. return concat$12([breakParent$3, group$13(ifBreak$5(compactTable, alignedTable))]);
  26155. function printSeparator(isCompact) {
  26156. return concat$12(["| ", join$9(" | ", columnMaxWidths.map(function (width, index) {
  26157. var spaces = isCompact ? 3 : width;
  26158. switch (node.align[index]) {
  26159. case "left":
  26160. return ":" + "-".repeat(spaces - 1);
  26161. case "right":
  26162. return "-".repeat(spaces - 1) + ":";
  26163. case "center":
  26164. return ":" + "-".repeat(spaces - 2) + ":";
  26165. default:
  26166. return "-".repeat(spaces);
  26167. }
  26168. })), " |"]);
  26169. }
  26170. function printRow(rowContents, isCompact) {
  26171. return concat$12(["| ", join$9(" | ", isCompact ? rowContents : rowContents.map(function (rowContent, columnIndex) {
  26172. switch (node.align[columnIndex]) {
  26173. case "right":
  26174. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  26175. case "center":
  26176. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  26177. default:
  26178. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  26179. }
  26180. })), " |"]);
  26181. }
  26182. function alignLeft(text, width) {
  26183. var spaces = width - util$1.getStringWidth(text);
  26184. return concat$12([text, " ".repeat(spaces)]);
  26185. }
  26186. function alignRight(text, width) {
  26187. var spaces = width - util$1.getStringWidth(text);
  26188. return concat$12([" ".repeat(spaces), text]);
  26189. }
  26190. function alignCenter(text, width) {
  26191. var spaces = width - util$1.getStringWidth(text);
  26192. var left = Math.floor(spaces / 2);
  26193. var right = spaces - left;
  26194. return concat$12([" ".repeat(left), text, " ".repeat(right)]);
  26195. }
  26196. }
  26197. function printRoot(path$$1, options, print) {
  26198. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  26199. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  26200. var ignoreRanges = [];
  26201. /** @type {IgnorePosition | null} */
  26202. var ignoreStart = null;
  26203. var children = path$$1.getValue().children;
  26204. children.forEach(function (childNode, index) {
  26205. switch (isPrettierIgnore(childNode)) {
  26206. case "start":
  26207. if (ignoreStart === null) {
  26208. ignoreStart = {
  26209. index,
  26210. offset: childNode.position.end.offset
  26211. };
  26212. }
  26213. break;
  26214. case "end":
  26215. if (ignoreStart !== null) {
  26216. ignoreRanges.push({
  26217. start: ignoreStart,
  26218. end: {
  26219. index,
  26220. offset: childNode.position.start.offset
  26221. }
  26222. });
  26223. ignoreStart = null;
  26224. }
  26225. break;
  26226. default:
  26227. // do nothing
  26228. break;
  26229. }
  26230. });
  26231. return printChildren(path$$1, options, print, {
  26232. processor: function processor(childPath, index) {
  26233. if (ignoreRanges.length !== 0) {
  26234. var ignoreRange = ignoreRanges[0];
  26235. if (index === ignoreRange.start.index) {
  26236. return concat$12([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
  26237. }
  26238. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  26239. return false;
  26240. }
  26241. if (index === ignoreRange.end.index) {
  26242. ignoreRanges.shift();
  26243. return false;
  26244. }
  26245. }
  26246. return childPath.call(print);
  26247. }
  26248. });
  26249. }
  26250. function printChildren(path$$1, options, print, events$$1) {
  26251. events$$1 = events$$1 || {};
  26252. var postprocessor = events$$1.postprocessor || concat$12;
  26253. var processor = events$$1.processor || function (childPath) {
  26254. return childPath.call(print);
  26255. };
  26256. var node = path$$1.getValue();
  26257. var parts = [];
  26258. var lastChildNode;
  26259. path$$1.map(function (childPath, index) {
  26260. var childNode = childPath.getValue();
  26261. var result = processor(childPath, index);
  26262. if (result !== false) {
  26263. var data = {
  26264. parts,
  26265. prevNode: lastChildNode,
  26266. parentNode: node,
  26267. options
  26268. };
  26269. if (!shouldNotPrePrintHardline(childNode, data)) {
  26270. parts.push(hardline$10);
  26271. if (lastChildNode && TRAILING_HARDLINE_NODES.indexOf(lastChildNode.type) !== -1) {
  26272. if (shouldPrePrintTripleHardline(childNode, data)) {
  26273. parts.push(hardline$10);
  26274. }
  26275. } else {
  26276. if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
  26277. parts.push(hardline$10);
  26278. }
  26279. if (shouldPrePrintTripleHardline(childNode, data)) {
  26280. parts.push(hardline$10);
  26281. }
  26282. }
  26283. }
  26284. parts.push(result);
  26285. lastChildNode = childNode;
  26286. }
  26287. }, "children");
  26288. return postprocessor(parts);
  26289. }
  26290. function getLastDescendantNode(node) {
  26291. var current = node;
  26292. while (current.children && current.children.length !== 0) {
  26293. current = current.children[current.children.length - 1];
  26294. }
  26295. return current;
  26296. }
  26297. /** @return {false | 'next' | 'start' | 'end'} */
  26298. function isPrettierIgnore(node) {
  26299. if (node.type !== "html") {
  26300. return false;
  26301. }
  26302. var match = node.value.match(/^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/);
  26303. return match === null ? false : match[1] ? match[1] : "next";
  26304. }
  26305. function shouldNotPrePrintHardline(node, data) {
  26306. var isFirstNode = data.parts.length === 0;
  26307. var isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1;
  26308. var isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1;
  26309. return isFirstNode || isInlineNode || isInlineHTML;
  26310. }
  26311. function shouldPrePrintDoubleHardline(node, data) {
  26312. var isSequence = (data.prevNode && data.prevNode.type) === node.type;
  26313. var isSiblingNode = isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1;
  26314. var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
  26315. var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
  26316. var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
  26317. var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
  26318. return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
  26319. }
  26320. function shouldPrePrintTripleHardline(node, data) {
  26321. var isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  26322. var isIndentedCode = node.type === "code" && node.isIndented;
  26323. return isPrevNodeList && isIndentedCode;
  26324. }
  26325. function shouldRemainTheSameContent(path$$1) {
  26326. var ancestorNode = getAncestorNode$2(path$$1, ["linkReference", "imageReference"]);
  26327. return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
  26328. }
  26329. function normalizeDoc(doc$$2) {
  26330. return mapDoc$5(doc$$2, function (currentDoc) {
  26331. if (!currentDoc.parts) {
  26332. return currentDoc;
  26333. }
  26334. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  26335. return currentDoc.parts[0];
  26336. }
  26337. var parts = [];
  26338. currentDoc.parts.forEach(function (part) {
  26339. if (part.type === "concat") {
  26340. parts.push.apply(parts, part.parts);
  26341. } else if (part !== "") {
  26342. parts.push(part);
  26343. }
  26344. });
  26345. return Object.assign({}, currentDoc, {
  26346. parts: normalizeParts(parts)
  26347. });
  26348. });
  26349. }
  26350. function printUrl(url, dangerousCharOrChars) {
  26351. var dangerousChars = [" "].concat(dangerousCharOrChars || []);
  26352. return new RegExp(dangerousChars.map(function (x) {
  26353. return `\\${x}`;
  26354. }).join("|")).test(url) ? `<${url}>` : url;
  26355. }
  26356. function printTitle(title, options, printSpace) {
  26357. if (printSpace == null) {
  26358. printSpace = true;
  26359. }
  26360. if (!title) {
  26361. return "";
  26362. }
  26363. if (printSpace) {
  26364. return " " + printTitle(title, options, false);
  26365. }
  26366. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  26367. return `(${title})`; // avoid escaped quotes
  26368. } // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  26369. var singleCount = title.split("'").length - 1;
  26370. var doubleCount = title.split('"').length - 1;
  26371. var quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
  26372. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  26373. return `${quote}${title}${quote}`;
  26374. }
  26375. function normalizeParts(parts) {
  26376. return parts.reduce(function (current, part) {
  26377. var lastPart = util$1.getLast(current);
  26378. if (typeof lastPart === "string" && typeof part === "string") {
  26379. current.splice(-1, 1, lastPart + part);
  26380. } else {
  26381. current.push(part);
  26382. }
  26383. return current;
  26384. }, []);
  26385. }
  26386. function clamp(value, min, max) {
  26387. return value < min ? min : value > max ? max : value;
  26388. }
  26389. function clean$7(ast, newObj, parent) {
  26390. delete newObj.position;
  26391. delete newObj.raw; // front-matter
  26392. // for codeblock
  26393. if (ast.type === "code" || ast.type === "yaml" || ast.type === "import" || ast.type === "export" || ast.type === "jsx") {
  26394. delete newObj.value;
  26395. }
  26396. if (ast.type === "list") {
  26397. delete newObj.isAligned;
  26398. } // texts can be splitted or merged
  26399. if (ast.type === "text") {
  26400. return null;
  26401. }
  26402. if (ast.type === "inlineCode") {
  26403. newObj.value = ast.value.replace(/[ \t\n]+/g, " ");
  26404. } // for insert pragma
  26405. if (parent && parent.type === "root" && parent.children.length > 0 && (parent.children[0] === ast || (parent.children[0].type === "yaml" || parent.children[0].type === "toml") && parent.children[1] === ast) && ast.type === "html" && pragma$6.startWithPragma(ast.value)) {
  26406. return null;
  26407. }
  26408. }
  26409. function hasPrettierIgnore$1(path$$1) {
  26410. var index = +path$$1.getName();
  26411. if (index === 0) {
  26412. return false;
  26413. }
  26414. var prevNode = path$$1.getParentNode().children[index - 1];
  26415. return isPrettierIgnore(prevNode) === "next";
  26416. }
  26417. var printerMarkdown = {
  26418. preprocess: preprocess_1$2,
  26419. print: genericPrint$4,
  26420. embed: embed_1$4,
  26421. massageAstNode: clean$7,
  26422. hasPrettierIgnore: hasPrettierIgnore$1,
  26423. insertPragma: pragma$6.insertPragma
  26424. };
  26425. var options$12 = {
  26426. proseWrap: commonOptions.proseWrap,
  26427. singleQuote: commonOptions.singleQuote
  26428. };
  26429. var name$13 = "Markdown";
  26430. var type$12 = "prose";
  26431. var aliases$4 = ["pandoc"];
  26432. var aceMode$12 = "markdown";
  26433. var codemirrorMode$9 = "gfm";
  26434. var codemirrorMimeType$9 = "text/x-gfm";
  26435. var wrap = true;
  26436. var extensions$12 = [".md", ".markdown", ".mdown", ".mdwn", ".mkd", ".mkdn", ".mkdown", ".ronn", ".workbook"];
  26437. var tmScope$12 = "source.gfm";
  26438. var languageId$12 = 222;
  26439. var markdown = {
  26440. name: name$13,
  26441. type: type$12,
  26442. aliases: aliases$4,
  26443. aceMode: aceMode$12,
  26444. codemirrorMode: codemirrorMode$9,
  26445. codemirrorMimeType: codemirrorMimeType$9,
  26446. wrap: wrap,
  26447. extensions: extensions$12,
  26448. tmScope: tmScope$12,
  26449. languageId: languageId$12
  26450. };
  26451. var markdown$1 = Object.freeze({
  26452. name: name$13,
  26453. type: type$12,
  26454. aliases: aliases$4,
  26455. aceMode: aceMode$12,
  26456. codemirrorMode: codemirrorMode$9,
  26457. codemirrorMimeType: codemirrorMimeType$9,
  26458. wrap: wrap,
  26459. extensions: extensions$12,
  26460. tmScope: tmScope$12,
  26461. languageId: languageId$12,
  26462. default: markdown
  26463. });
  26464. var require$$0$28 = ( markdown$1 && markdown ) || markdown$1;
  26465. var languages$4 = [createLanguage(require$$0$28, {
  26466. override: {
  26467. since: "1.8.0",
  26468. parsers: ["remark"],
  26469. vscodeLanguageIds: ["markdown"]
  26470. },
  26471. extend: {
  26472. filenames: ["README"]
  26473. }
  26474. }), createLanguage({
  26475. name: "MDX",
  26476. extensions: [".mdx"]
  26477. }, // TODO: use linguist data
  26478. {
  26479. override: {
  26480. since: "1.15.0",
  26481. parsers: ["mdx"],
  26482. vscodeLanguageIds: ["mdx"]
  26483. }
  26484. })];
  26485. var printers$4 = {
  26486. mdast: printerMarkdown
  26487. };
  26488. var languageMarkdown = {
  26489. languages: languages$4,
  26490. options: options$12,
  26491. printers: printers$4
  26492. };
  26493. var clean$8 = function clean(ast, newNode) {
  26494. delete newNode.sourceSpan;
  26495. delete newNode.startSourceSpan;
  26496. delete newNode.endSourceSpan;
  26497. delete newNode.nameSpan;
  26498. delete newNode.valueSpan;
  26499. if (ast.type === "text" || ast.type === "comment") {
  26500. return null;
  26501. } // may be formatted by multiparser
  26502. if (ast.type === "yaml" || ast.type === "toml") {
  26503. return null;
  26504. }
  26505. if (ast.type === "attribute") {
  26506. delete newNode.value;
  26507. }
  26508. if (ast.type === "docType") {
  26509. delete newNode.value;
  26510. }
  26511. };
  26512. var a = ["accesskey", "charset", "coords", "download", "href", "hreflang", "name", "ping", "referrerpolicy", "rel", "rev", "shape", "tabindex", "target", "type"];
  26513. var abbr = ["title"];
  26514. var applet = ["align", "alt", "archive", "code", "codebase", "height", "hspace", "name", "object", "vspace", "width"];
  26515. var area = ["accesskey", "alt", "coords", "download", "href", "hreflang", "nohref", "ping", "referrerpolicy", "rel", "shape", "tabindex", "target", "type"];
  26516. var audio = ["autoplay", "controls", "crossorigin", "loop", "muted", "preload", "src"];
  26517. var base$2 = ["href", "target"];
  26518. var basefont = ["color", "face", "size"];
  26519. var bdo = ["dir"];
  26520. var blockquote = ["cite"];
  26521. var body = ["alink", "background", "bgcolor", "link", "text", "vlink"];
  26522. var br = ["clear"];
  26523. var button = ["accesskey", "autofocus", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "name", "tabindex", "type", "value"];
  26524. var canvas = ["height", "width"];
  26525. var caption = ["align"];
  26526. var col = ["align", "char", "charoff", "span", "valign", "width"];
  26527. var colgroup = ["align", "char", "charoff", "span", "valign", "width"];
  26528. var data$1 = ["value"];
  26529. var del = ["cite", "datetime"];
  26530. var details = ["open"];
  26531. var dfn = ["title"];
  26532. var dialog = ["open"];
  26533. var dir = ["compact"];
  26534. var div = ["align"];
  26535. var dl = ["compact"];
  26536. var embed$7 = ["height", "src", "type", "width"];
  26537. var fieldset = ["disabled", "form", "name"];
  26538. var font = ["color", "face", "size"];
  26539. var form = ["accept", "accept-charset", "action", "autocomplete", "enctype", "method", "name", "novalidate", "target"];
  26540. var frame = ["frameborder", "longdesc", "marginheight", "marginwidth", "name", "noresize", "scrolling", "src"];
  26541. var frameset = ["cols", "rows"];
  26542. var h1 = ["align"];
  26543. var h2 = ["align"];
  26544. var h3 = ["align"];
  26545. var h4 = ["align"];
  26546. var h5 = ["align"];
  26547. var h6 = ["align"];
  26548. var head = ["profile"];
  26549. var hr = ["align", "noshade", "size", "width"];
  26550. var html = ["manifest", "version"];
  26551. var iframe = ["align", "allowfullscreen", "allowpaymentrequest", "allowusermedia", "frameborder", "height", "longdesc", "marginheight", "marginwidth", "name", "referrerpolicy", "sandbox", "scrolling", "src", "srcdoc", "width"];
  26552. var img = ["align", "alt", "border", "crossorigin", "decoding", "height", "hspace", "ismap", "longdesc", "name", "referrerpolicy", "sizes", "src", "srcset", "usemap", "vspace", "width"];
  26553. var input = ["accept", "accesskey", "align", "alt", "autocomplete", "autofocus", "checked", "dirname", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "height", "ismap", "list", "max", "maxlength", "min", "minlength", "multiple", "name", "pattern", "placeholder", "readonly", "required", "size", "src", "step", "tabindex", "title", "type", "usemap", "value", "width"];
  26554. var ins = ["cite", "datetime"];
  26555. var isindex = ["prompt"];
  26556. var label = ["accesskey", "for", "form"];
  26557. var legend = ["accesskey", "align"];
  26558. var li = ["type", "value"];
  26559. var link$1 = ["as", "charset", "color", "crossorigin", "href", "hreflang", "integrity", "media", "nonce", "referrerpolicy", "rel", "rev", "sizes", "target", "title", "type"];
  26560. var map = ["name"];
  26561. var menu = ["compact"];
  26562. var meta = ["charset", "content", "http-equiv", "name", "scheme"];
  26563. var meter = ["high", "low", "max", "min", "optimum", "value"];
  26564. var object = ["align", "archive", "border", "classid", "codebase", "codetype", "data", "declare", "form", "height", "hspace", "name", "standby", "tabindex", "type", "typemustmatch", "usemap", "vspace", "width"];
  26565. var ol = ["compact", "reversed", "start", "type"];
  26566. var optgroup = ["disabled", "label"];
  26567. var option = ["disabled", "label", "selected", "value"];
  26568. var output = ["for", "form", "name"];
  26569. var p = ["align"];
  26570. var param = ["name", "type", "value", "valuetype"];
  26571. var pre = ["width"];
  26572. var progress = ["max", "value"];
  26573. var q = ["cite"];
  26574. var script = ["async", "charset", "crossorigin", "defer", "integrity", "language", "nomodule", "nonce", "referrerpolicy", "src", "type"];
  26575. var select = ["autocomplete", "autofocus", "disabled", "form", "multiple", "name", "required", "size", "tabindex"];
  26576. var slot = ["name"];
  26577. var source = ["media", "sizes", "src", "srcset", "type"];
  26578. var style = ["media", "nonce", "title", "type"];
  26579. var table = ["align", "bgcolor", "border", "cellpadding", "cellspacing", "frame", "rules", "summary", "width"];
  26580. var tbody = ["align", "char", "charoff", "valign"];
  26581. var td = ["abbr", "align", "axis", "bgcolor", "char", "charoff", "colspan", "headers", "height", "nowrap", "rowspan", "scope", "valign", "width"];
  26582. var textarea = ["accesskey", "autocomplete", "autofocus", "cols", "dirname", "disabled", "form", "maxlength", "minlength", "name", "placeholder", "readonly", "required", "rows", "tabindex", "wrap"];
  26583. var tfoot = ["align", "char", "charoff", "valign"];
  26584. var th = ["abbr", "align", "axis", "bgcolor", "char", "charoff", "colspan", "headers", "height", "nowrap", "rowspan", "scope", "valign", "width"];
  26585. var thead = ["align", "char", "charoff", "valign"];
  26586. var time = ["datetime"];
  26587. var tr = ["align", "bgcolor", "char", "charoff", "valign"];
  26588. var track = ["default", "kind", "label", "src", "srclang"];
  26589. var ul = ["compact", "type"];
  26590. var video = ["autoplay", "controls", "crossorigin", "height", "loop", "muted", "playsinline", "poster", "preload", "src", "width"];
  26591. var index$13 = {
  26592. a: a,
  26593. abbr: abbr,
  26594. applet: applet,
  26595. area: area,
  26596. audio: audio,
  26597. base: base$2,
  26598. basefont: basefont,
  26599. bdo: bdo,
  26600. blockquote: blockquote,
  26601. body: body,
  26602. br: br,
  26603. button: button,
  26604. canvas: canvas,
  26605. caption: caption,
  26606. col: col,
  26607. colgroup: colgroup,
  26608. data: data$1,
  26609. del: del,
  26610. details: details,
  26611. dfn: dfn,
  26612. dialog: dialog,
  26613. dir: dir,
  26614. div: div,
  26615. dl: dl,
  26616. embed: embed$7,
  26617. fieldset: fieldset,
  26618. font: font,
  26619. form: form,
  26620. frame: frame,
  26621. frameset: frameset,
  26622. h1: h1,
  26623. h2: h2,
  26624. h3: h3,
  26625. h4: h4,
  26626. h5: h5,
  26627. h6: h6,
  26628. head: head,
  26629. hr: hr,
  26630. html: html,
  26631. iframe: iframe,
  26632. img: img,
  26633. input: input,
  26634. ins: ins,
  26635. isindex: isindex,
  26636. label: label,
  26637. legend: legend,
  26638. li: li,
  26639. link: link$1,
  26640. map: map,
  26641. menu: menu,
  26642. meta: meta,
  26643. meter: meter,
  26644. object: object,
  26645. ol: ol,
  26646. optgroup: optgroup,
  26647. option: option,
  26648. output: output,
  26649. p: p,
  26650. param: param,
  26651. pre: pre,
  26652. progress: progress,
  26653. q: q,
  26654. script: script,
  26655. select: select,
  26656. slot: slot,
  26657. source: source,
  26658. style: style,
  26659. table: table,
  26660. tbody: tbody,
  26661. td: td,
  26662. textarea: textarea,
  26663. tfoot: tfoot,
  26664. th: th,
  26665. thead: thead,
  26666. time: time,
  26667. tr: tr,
  26668. track: track,
  26669. ul: ul,
  26670. video: video,
  26671. "*": ["accesskey", "autocapitalize", "class", "contenteditable", "dir", "draggable", "hidden", "id", "inputmode", "is", "itemid", "itemprop", "itemref", "itemscope", "itemtype", "lang", "nonce", "slot", "spellcheck", "style", "tabindex", "title", "translate"]
  26672. };
  26673. var htmlElementAttributes = Object.freeze({
  26674. a: a,
  26675. abbr: abbr,
  26676. applet: applet,
  26677. area: area,
  26678. audio: audio,
  26679. base: base$2,
  26680. basefont: basefont,
  26681. bdo: bdo,
  26682. blockquote: blockquote,
  26683. body: body,
  26684. br: br,
  26685. button: button,
  26686. canvas: canvas,
  26687. caption: caption,
  26688. col: col,
  26689. colgroup: colgroup,
  26690. data: data$1,
  26691. del: del,
  26692. details: details,
  26693. dfn: dfn,
  26694. dialog: dialog,
  26695. dir: dir,
  26696. div: div,
  26697. dl: dl,
  26698. embed: embed$7,
  26699. fieldset: fieldset,
  26700. font: font,
  26701. form: form,
  26702. frame: frame,
  26703. frameset: frameset,
  26704. h1: h1,
  26705. h2: h2,
  26706. h3: h3,
  26707. h4: h4,
  26708. h5: h5,
  26709. h6: h6,
  26710. head: head,
  26711. hr: hr,
  26712. html: html,
  26713. iframe: iframe,
  26714. img: img,
  26715. input: input,
  26716. ins: ins,
  26717. isindex: isindex,
  26718. label: label,
  26719. legend: legend,
  26720. li: li,
  26721. link: link$1,
  26722. map: map,
  26723. menu: menu,
  26724. meta: meta,
  26725. meter: meter,
  26726. object: object,
  26727. ol: ol,
  26728. optgroup: optgroup,
  26729. option: option,
  26730. output: output,
  26731. p: p,
  26732. param: param,
  26733. pre: pre,
  26734. progress: progress,
  26735. q: q,
  26736. script: script,
  26737. select: select,
  26738. slot: slot,
  26739. source: source,
  26740. style: style,
  26741. table: table,
  26742. tbody: tbody,
  26743. td: td,
  26744. textarea: textarea,
  26745. tfoot: tfoot,
  26746. th: th,
  26747. thead: thead,
  26748. time: time,
  26749. tr: tr,
  26750. track: track,
  26751. ul: ul,
  26752. video: video,
  26753. default: index$13
  26754. });
  26755. var json$9 = {"CSS_DISPLAY_TAGS":{"area":"none","base":"none","basefont":"none","datalist":"none","head":"none","link":"none","meta":"none","noembed":"none","noframes":"none","param":"none","rp":"none","script":"none","source":"block","style":"none","template":"inline","track":"block","title":"none","html":"block","body":"block","address":"block","blockquote":"block","center":"block","div":"block","figure":"block","figcaption":"block","footer":"block","form":"block","header":"block","hr":"block","legend":"block","listing":"block","main":"block","p":"block","plaintext":"block","pre":"block","xmp":"block","slot":"contents","ruby":"ruby","rt":"ruby-text","article":"block","aside":"block","h1":"block","h2":"block","h3":"block","h4":"block","h5":"block","h6":"block","hgroup":"block","nav":"block","section":"block","dir":"block","dd":"block","dl":"block","dt":"block","ol":"block","ul":"block","li":"list-item","table":"table","caption":"table-caption","colgroup":"table-column-group","col":"table-column","thead":"table-header-group","tbody":"table-row-group","tfoot":"table-footer-group","tr":"table-row","td":"table-cell","th":"table-cell","fieldset":"block","button":"inline-block","video":"inline-block","audio":"inline-block"},"CSS_DISPLAY_DEFAULT":"inline","CSS_WHITE_SPACE_TAGS":{"listing":"pre","plaintext":"pre","pre":"pre","xmp":"pre","nobr":"nowrap","table":"initial","textarea":"pre-wrap"},"CSS_WHITE_SPACE_DEFAULT":"normal"};
  26756. var htmlElementAttributes$1 = ( htmlElementAttributes && index$13 ) || htmlElementAttributes;
  26757. var CSS_DISPLAY_TAGS = json$9.CSS_DISPLAY_TAGS;
  26758. var CSS_DISPLAY_DEFAULT = json$9.CSS_DISPLAY_DEFAULT;
  26759. var CSS_WHITE_SPACE_TAGS = json$9.CSS_WHITE_SPACE_TAGS;
  26760. var CSS_WHITE_SPACE_DEFAULT = json$9.CSS_WHITE_SPACE_DEFAULT;
  26761. var HTML_TAGS = arrayToMap(htmlTagNames$1);
  26762. var HTML_ELEMENT_ATTRIBUTES = mapObject(htmlElementAttributes$1, arrayToMap);
  26763. function arrayToMap(array) {
  26764. var map = Object.create(null);
  26765. var _iteratorNormalCompletion = true;
  26766. var _didIteratorError = false;
  26767. var _iteratorError = undefined;
  26768. try {
  26769. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  26770. var value = _step.value;
  26771. map[value] = true;
  26772. }
  26773. } catch (err) {
  26774. _didIteratorError = true;
  26775. _iteratorError = err;
  26776. } finally {
  26777. try {
  26778. if (!_iteratorNormalCompletion && _iterator.return != null) {
  26779. _iterator.return();
  26780. }
  26781. } finally {
  26782. if (_didIteratorError) {
  26783. throw _iteratorError;
  26784. }
  26785. }
  26786. }
  26787. return map;
  26788. }
  26789. function mapObject(object, fn) {
  26790. var newObject = Object.create(null);
  26791. var _arr = Object.keys(object);
  26792. for (var _i = 0; _i < _arr.length; _i++) {
  26793. var key = _arr[_i];
  26794. newObject[key] = fn(object[key], key);
  26795. }
  26796. return newObject;
  26797. }
  26798. function shouldPreserveContent$1(node, options) {
  26799. if (node.type === "element" && node.fullName === "template" && node.attrMap.lang && node.attrMap.lang !== "html") {
  26800. return true;
  26801. } // unterminated node in ie conditional comment
  26802. // e.g. <!--[if lt IE 9]><html><![endif]-->
  26803. if (node.type === "ieConditionalComment" && node.lastChild && !node.lastChild.isSelfClosing && !node.lastChild.endSourceSpan) {
  26804. return true;
  26805. } // incomplete html in ie conditional comment
  26806. // e.g. <!--[if lt IE 9]></div><![endif]-->
  26807. if (node.type === "ieConditionalComment" && !node.complete) {
  26808. return true;
  26809. } // top-level elements (excluding <template>, <style> and <script>) in Vue SFC are considered custom block
  26810. // custom blocks can be written in other languages so we should preserve them to not break the code
  26811. if (options.parser === "vue" && node.type === "element" && node.parent.type === "root" && ["template", "style", "script", // vue parser can be used for vue dom template as well, so we should still format top-level <html>
  26812. "html"].indexOf(node.fullName) === -1) {
  26813. return true;
  26814. } // TODO: handle non-text children in <pre>
  26815. if (isPreLikeNode(node) && node.children.some(function (child) {
  26816. return child.type !== "text" && child.type !== "interpolation";
  26817. })) {
  26818. return true;
  26819. }
  26820. return false;
  26821. }
  26822. function hasPrettierIgnore$3(node) {
  26823. if (node.type === "attribute" || isTextLikeNode$1(node)) {
  26824. return false;
  26825. }
  26826. if (!node.parent) {
  26827. return false;
  26828. }
  26829. if (typeof node.index !== "number" || node.index === 0) {
  26830. return false;
  26831. }
  26832. var prevNode = node.parent.children[node.index - 1];
  26833. return isPrettierIgnore$1(prevNode);
  26834. }
  26835. function isPrettierIgnore$1(node) {
  26836. return node.type === "comment" && node.value.trim() === "prettier-ignore";
  26837. }
  26838. function getPrettierIgnoreAttributeCommentData$1(value) {
  26839. var match = value.trim().match(/^prettier-ignore-attribute(?:\s+([^]+))?$/);
  26840. if (!match) {
  26841. return false;
  26842. }
  26843. if (!match[1]) {
  26844. return true;
  26845. }
  26846. return match[1].split(/\s+/);
  26847. }
  26848. /** there's no opening/closing tag or it's considered not breakable */
  26849. function isTextLikeNode$1(node) {
  26850. return node.type === "text" || node.type === "comment";
  26851. }
  26852. function isScriptLikeTag$1(node) {
  26853. return node.type === "element" && (node.fullName === "script" || node.fullName === "style" || node.fullName === "svg:style");
  26854. }
  26855. function isFrontMatterNode(node) {
  26856. return node.type === "yaml" || node.type === "toml";
  26857. }
  26858. function canHaveInterpolation(node) {
  26859. return node.children && !isScriptLikeTag$1(node);
  26860. }
  26861. function isWhitespaceSensitiveNode(node) {
  26862. return isScriptLikeTag$1(node) || node.type === "interpolation" || isIndentationSensitiveNode(node);
  26863. }
  26864. function isIndentationSensitiveNode(node) {
  26865. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  26866. }
  26867. function isLeadingSpaceSensitiveNode(node) {
  26868. var isLeadingSpaceSensitive = _isLeadingSpaceSensitiveNode();
  26869. if (isLeadingSpaceSensitive && !node.prev && node.parent && node.parent.tagDefinition && node.parent.tagDefinition.ignoreFirstLf) {
  26870. return node.type === "interpolation";
  26871. }
  26872. return isLeadingSpaceSensitive;
  26873. function _isLeadingSpaceSensitiveNode() {
  26874. if (isFrontMatterNode(node)) {
  26875. return false;
  26876. }
  26877. if ((node.type === "text" || node.type === "interpolation") && node.prev && (node.prev.type === "text" || node.prev.type === "interpolation")) {
  26878. return true;
  26879. }
  26880. if (!node.parent || node.parent.cssDisplay === "none") {
  26881. return false;
  26882. }
  26883. if (isPreLikeNode(node.parent)) {
  26884. return true;
  26885. }
  26886. if (!node.prev && (node.parent.type === "root" || isScriptLikeTag$1(node.parent) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  26887. return false;
  26888. }
  26889. if (node.prev && !isNextLeadingSpaceSensitiveCssDisplay(node.prev.cssDisplay)) {
  26890. return false;
  26891. }
  26892. return true;
  26893. }
  26894. }
  26895. function isTrailingSpaceSensitiveNode(node) {
  26896. if (isFrontMatterNode(node)) {
  26897. return false;
  26898. }
  26899. if ((node.type === "text" || node.type === "interpolation") && node.next && (node.next.type === "text" || node.next.type === "interpolation")) {
  26900. return true;
  26901. }
  26902. if (!node.parent || node.parent.cssDisplay === "none") {
  26903. return false;
  26904. }
  26905. if (isPreLikeNode(node.parent)) {
  26906. return true;
  26907. }
  26908. if (!node.next && (node.parent.type === "root" || isScriptLikeTag$1(node.parent) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  26909. return false;
  26910. }
  26911. if (node.next && !isPrevTrailingSpaceSensitiveCssDisplay(node.next.cssDisplay)) {
  26912. return false;
  26913. }
  26914. return true;
  26915. }
  26916. function isDanglingSpaceSensitiveNode(node) {
  26917. return isDanglingSpaceSensitiveCssDisplay(node.cssDisplay) && !isScriptLikeTag$1(node);
  26918. }
  26919. function forceNextEmptyLine$1(node) {
  26920. return isFrontMatterNode(node) || node.next && node.sourceSpan.end.line + 1 < node.next.sourceSpan.start.line;
  26921. }
  26922. /** firstChild leadingSpaces and lastChild trailingSpaces */
  26923. function forceBreakContent$1(node) {
  26924. return forceBreakChildren$1(node) || node.type === "element" && node.children.length !== 0 && (["body", "template", "script", "style"].indexOf(node.name) !== -1 || node.children.some(function (child) {
  26925. return hasNonTextChild(child);
  26926. })) || node.firstChild && node.firstChild === node.lastChild && hasLeadingLineBreak(node.firstChild) && (!node.lastChild.isTrailingSpaceSensitive || hasTrailingLineBreak(node.lastChild));
  26927. }
  26928. /** spaces between children */
  26929. function forceBreakChildren$1(node) {
  26930. return node.type === "element" && node.children.length !== 0 && (["html", "head", "ul", "ol", "select"].indexOf(node.name) !== -1 || node.cssDisplay.startsWith("table") && node.cssDisplay !== "table-cell");
  26931. }
  26932. function preferHardlineAsLeadingSpaces$1(node) {
  26933. return preferHardlineAsSurroundingSpaces(node) || node.prev && preferHardlineAsTrailingSpaces(node.prev) || hasSurroundingLineBreak(node);
  26934. }
  26935. function preferHardlineAsTrailingSpaces(node) {
  26936. return preferHardlineAsSurroundingSpaces(node) || node.type === "element" && node.fullName === "br" || hasSurroundingLineBreak(node);
  26937. }
  26938. function hasSurroundingLineBreak(node) {
  26939. return hasLeadingLineBreak(node) && hasTrailingLineBreak(node);
  26940. }
  26941. function hasLeadingLineBreak(node) {
  26942. return node.hasLeadingSpaces && (node.prev ? node.prev.sourceSpan.end.line < node.sourceSpan.start.line : node.parent.type === "root" || node.parent.startSourceSpan.end.line < node.sourceSpan.start.line);
  26943. }
  26944. function hasTrailingLineBreak(node) {
  26945. return node.hasTrailingSpaces && (node.next ? node.next.sourceSpan.start.line > node.sourceSpan.end.line : node.parent.type === "root" || node.parent.endSourceSpan.start.line > node.sourceSpan.end.line);
  26946. }
  26947. function preferHardlineAsSurroundingSpaces(node) {
  26948. switch (node.type) {
  26949. case "ieConditionalComment":
  26950. case "comment":
  26951. case "directive":
  26952. return true;
  26953. case "element":
  26954. return ["script", "select"].indexOf(node.name) !== -1;
  26955. }
  26956. return false;
  26957. }
  26958. function getLastDescendant$1(node) {
  26959. return node.lastChild ? getLastDescendant$1(node.lastChild) : node;
  26960. }
  26961. function hasNonTextChild(node) {
  26962. return node.children && node.children.some(function (child) {
  26963. return child.type !== "text";
  26964. });
  26965. }
  26966. function inferScriptParser$1(node) {
  26967. if (node.name === "script" && !node.attrMap.src) {
  26968. if (!node.attrMap.lang && !node.attrMap.type || node.attrMap.type === "module" || node.attrMap.type === "text/javascript" || node.attrMap.type === "text/babel" || node.attrMap.type === "application/javascript") {
  26969. return "babel";
  26970. }
  26971. if (node.attrMap.type === "application/x-typescript" || node.attrMap.lang === "ts" || node.attrMap.lang === "tsx") {
  26972. return "typescript";
  26973. }
  26974. if (node.attrMap.type === "text/markdown") {
  26975. return "markdown";
  26976. }
  26977. if (node.attrMap.type === "application/ld+json") {
  26978. return "json";
  26979. }
  26980. }
  26981. if (node.name === "style") {
  26982. if (!node.attrMap.lang || node.attrMap.lang === "postcss") {
  26983. return "css";
  26984. }
  26985. if (node.attrMap.lang === "scss") {
  26986. return "scss";
  26987. }
  26988. if (node.attrMap.lang === "less") {
  26989. return "less";
  26990. }
  26991. }
  26992. return null;
  26993. }
  26994. function isBlockLikeCssDisplay(cssDisplay) {
  26995. return cssDisplay === "block" || cssDisplay === "list-item" || cssDisplay.startsWith("table");
  26996. }
  26997. function isFirstChildLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  26998. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  26999. }
  27000. function isLastChildTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  27001. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  27002. }
  27003. function isPrevTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  27004. return !isBlockLikeCssDisplay(cssDisplay);
  27005. }
  27006. function isNextLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  27007. return !isBlockLikeCssDisplay(cssDisplay);
  27008. }
  27009. function isDanglingSpaceSensitiveCssDisplay(cssDisplay) {
  27010. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  27011. }
  27012. function isPreLikeNode(node) {
  27013. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  27014. }
  27015. function countParents$1(path$$1) {
  27016. var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  27017. return true;
  27018. };
  27019. var counter = 0;
  27020. for (var i = path$$1.stack.length - 1; i >= 0; i--) {
  27021. var value = path$$1.stack[i];
  27022. if (value && typeof value === "object" && !Array.isArray(value) && predicate(value)) {
  27023. counter++;
  27024. }
  27025. }
  27026. return counter;
  27027. }
  27028. function hasParent(node, fn) {
  27029. var current = node;
  27030. while (current) {
  27031. if (fn(current)) {
  27032. return true;
  27033. }
  27034. current = current.parent;
  27035. }
  27036. return false;
  27037. }
  27038. function getNodeCssStyleDisplay(node, options) {
  27039. if (node.prev && node.prev.type === "comment") {
  27040. // <!-- display: block -->
  27041. var match = node.prev.value.match(/^\s*display:\s*([a-z]+)\s*$/);
  27042. if (match) {
  27043. return match[1];
  27044. }
  27045. }
  27046. var isInSvgForeignObject = false;
  27047. if (node.type === "element" && node.namespace === "svg") {
  27048. if (hasParent(node, function (parent) {
  27049. return parent.fullName === "svg:foreignObject";
  27050. })) {
  27051. isInSvgForeignObject = true;
  27052. } else {
  27053. return node.name === "svg" ? "inline-block" : "block";
  27054. }
  27055. }
  27056. switch (options.htmlWhitespaceSensitivity) {
  27057. case "strict":
  27058. return "inline";
  27059. case "ignore":
  27060. return "block";
  27061. default:
  27062. return node.type === "element" && (!node.namespace || isInSvgForeignObject) && CSS_DISPLAY_TAGS[node.name] || CSS_DISPLAY_DEFAULT;
  27063. }
  27064. }
  27065. function getNodeCssStyleWhiteSpace(node) {
  27066. return node.type === "element" && !node.namespace && CSS_WHITE_SPACE_TAGS[node.name] || CSS_WHITE_SPACE_DEFAULT;
  27067. }
  27068. function getMinIndentation(text) {
  27069. var minIndentation = Infinity;
  27070. var _iteratorNormalCompletion2 = true;
  27071. var _didIteratorError2 = false;
  27072. var _iteratorError2 = undefined;
  27073. try {
  27074. for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  27075. var lineText = _step2.value;
  27076. if (lineText.length === 0) {
  27077. continue;
  27078. }
  27079. if (/\S/.test(lineText[0])) {
  27080. return 0;
  27081. }
  27082. var indentation = lineText.match(/^\s*/)[0].length;
  27083. if (lineText.length === indentation) {
  27084. continue;
  27085. }
  27086. if (indentation < minIndentation) {
  27087. minIndentation = indentation;
  27088. }
  27089. }
  27090. } catch (err) {
  27091. _didIteratorError2 = true;
  27092. _iteratorError2 = err;
  27093. } finally {
  27094. try {
  27095. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  27096. _iterator2.return();
  27097. }
  27098. } finally {
  27099. if (_didIteratorError2) {
  27100. throw _iteratorError2;
  27101. }
  27102. }
  27103. }
  27104. return minIndentation === Infinity ? 0 : minIndentation;
  27105. }
  27106. function dedentString$1(text) {
  27107. var minIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getMinIndentation(text);
  27108. return minIndent === 0 ? text : text.split("\n").map(function (lineText) {
  27109. return lineText.slice(minIndent);
  27110. }).join("\n");
  27111. }
  27112. function normalizeParts$2(parts) {
  27113. var newParts = [];
  27114. var restParts = parts.slice();
  27115. while (restParts.length !== 0) {
  27116. var part = restParts.shift();
  27117. if (!part) {
  27118. continue;
  27119. }
  27120. if (part.type === "concat") {
  27121. Array.prototype.unshift.apply(restParts, part.parts);
  27122. continue;
  27123. }
  27124. if (newParts.length !== 0 && typeof newParts[newParts.length - 1] === "string" && typeof part === "string") {
  27125. newParts.push(newParts.pop() + part);
  27126. continue;
  27127. }
  27128. newParts.push(part);
  27129. }
  27130. return newParts;
  27131. }
  27132. function identity$2(x) {
  27133. return x;
  27134. }
  27135. function shouldNotPrintClosingTag$1(node, options) {
  27136. return !node.isSelfClosing && !node.endSourceSpan && (hasPrettierIgnore$3(node) || shouldPreserveContent$1(node.parent, options));
  27137. }
  27138. function countChars$1(text, char) {
  27139. var counter = 0;
  27140. for (var i = 0; i < text.length; i++) {
  27141. if (text[i] === char) {
  27142. counter++;
  27143. }
  27144. }
  27145. return counter;
  27146. }
  27147. function unescapeQuoteEntities$1(text) {
  27148. return text.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  27149. }
  27150. var utils$10 = {
  27151. HTML_ELEMENT_ATTRIBUTES,
  27152. HTML_TAGS,
  27153. canHaveInterpolation,
  27154. countChars: countChars$1,
  27155. countParents: countParents$1,
  27156. dedentString: dedentString$1,
  27157. forceBreakChildren: forceBreakChildren$1,
  27158. forceBreakContent: forceBreakContent$1,
  27159. forceNextEmptyLine: forceNextEmptyLine$1,
  27160. getLastDescendant: getLastDescendant$1,
  27161. getNodeCssStyleDisplay,
  27162. getNodeCssStyleWhiteSpace,
  27163. getPrettierIgnoreAttributeCommentData: getPrettierIgnoreAttributeCommentData$1,
  27164. hasPrettierIgnore: hasPrettierIgnore$3,
  27165. identity: identity$2,
  27166. inferScriptParser: inferScriptParser$1,
  27167. isDanglingSpaceSensitiveNode,
  27168. isFrontMatterNode,
  27169. isIndentationSensitiveNode,
  27170. isLeadingSpaceSensitiveNode,
  27171. isPreLikeNode,
  27172. isScriptLikeTag: isScriptLikeTag$1,
  27173. isTextLikeNode: isTextLikeNode$1,
  27174. isTrailingSpaceSensitiveNode,
  27175. isWhitespaceSensitiveNode,
  27176. normalizeParts: normalizeParts$2,
  27177. preferHardlineAsLeadingSpaces: preferHardlineAsLeadingSpaces$1,
  27178. preferHardlineAsTrailingSpaces,
  27179. shouldNotPrintClosingTag: shouldNotPrintClosingTag$1,
  27180. shouldPreserveContent: shouldPreserveContent$1,
  27181. unescapeQuoteEntities: unescapeQuoteEntities$1
  27182. };
  27183. var canHaveInterpolation$1 = utils$10.canHaveInterpolation;
  27184. var getNodeCssStyleDisplay$1 = utils$10.getNodeCssStyleDisplay;
  27185. var isDanglingSpaceSensitiveNode$1 = utils$10.isDanglingSpaceSensitiveNode;
  27186. var isIndentationSensitiveNode$1 = utils$10.isIndentationSensitiveNode;
  27187. var isLeadingSpaceSensitiveNode$1 = utils$10.isLeadingSpaceSensitiveNode;
  27188. var isTrailingSpaceSensitiveNode$1 = utils$10.isTrailingSpaceSensitiveNode;
  27189. var isWhitespaceSensitiveNode$1 = utils$10.isWhitespaceSensitiveNode;
  27190. var PREPROCESS_PIPELINE = [removeIgnorableFirstLf, mergeIeConditonalStartEndCommentIntoElementOpeningTag, mergeCdataIntoText, extractInterpolation, extractWhitespaces, addCssDisplay, addIsSelfClosing, addHasHtmComponentClosingTag, addIsSpaceSensitive, mergeSimpleElementIntoText];
  27191. function preprocess$4(ast, options) {
  27192. for (var _i = 0; _i < PREPROCESS_PIPELINE.length; _i++) {
  27193. var fn = PREPROCESS_PIPELINE[_i];
  27194. ast = fn(ast, options);
  27195. }
  27196. return ast;
  27197. }
  27198. function removeIgnorableFirstLf(ast
  27199. /*, options */
  27200. ) {
  27201. return ast.map(function (node) {
  27202. if (node.type === "element" && node.tagDefinition.ignoreFirstLf && node.children.length !== 0 && node.children[0].type === "text" && node.children[0].value[0] === "\n") {
  27203. var text = node.children[0];
  27204. return node.clone({
  27205. children: text.value.length === 1 ? node.children.slice(1) : [].concat(text.clone({
  27206. value: text.value.slice(1)
  27207. }), node.children.slice(1))
  27208. });
  27209. }
  27210. return node;
  27211. });
  27212. }
  27213. function mergeIeConditonalStartEndCommentIntoElementOpeningTag(ast
  27214. /*, options */
  27215. ) {
  27216. /**
  27217. * <!--[if ...]><!--><target><!--<![endif]-->
  27218. */
  27219. var isTarget = function isTarget(node) {
  27220. return node.type === "element" && node.prev && node.prev.type === "ieConditionalStartComment" && node.prev.sourceSpan.end.offset === node.startSourceSpan.start.offset && node.firstChild && node.firstChild.type === "ieConditionalEndComment" && node.firstChild.sourceSpan.start.offset === node.startSourceSpan.end.offset;
  27221. };
  27222. return ast.map(function (node) {
  27223. if (node.children) {
  27224. var isTargetResults = node.children.map(isTarget);
  27225. if (isTargetResults.some(Boolean)) {
  27226. var newChildren = [];
  27227. for (var i = 0; i < node.children.length; i++) {
  27228. var child = node.children[i];
  27229. if (isTargetResults[i + 1]) {
  27230. // ieConditionalStartComment
  27231. continue;
  27232. }
  27233. if (isTargetResults[i]) {
  27234. var ieConditionalStartComment = child.prev;
  27235. var ieConditionalEndComment = child.firstChild;
  27236. var ParseSourceSpan = child.sourceSpan.constructor;
  27237. var startSourceSpan = new ParseSourceSpan(ieConditionalStartComment.sourceSpan.start, ieConditionalEndComment.sourceSpan.end);
  27238. var sourceSpan = new ParseSourceSpan(startSourceSpan.start, child.sourceSpan.end);
  27239. newChildren.push(child.clone({
  27240. condition: ieConditionalStartComment.condition,
  27241. sourceSpan,
  27242. startSourceSpan,
  27243. children: child.children.slice(1)
  27244. }));
  27245. continue;
  27246. }
  27247. newChildren.push(child);
  27248. }
  27249. return node.clone({
  27250. children: newChildren
  27251. });
  27252. }
  27253. }
  27254. return node;
  27255. });
  27256. }
  27257. function mergeNodeIntoText(ast, shouldMerge, getValue) {
  27258. return ast.map(function (node) {
  27259. if (node.children) {
  27260. var shouldMergeResults = node.children.map(shouldMerge);
  27261. if (shouldMergeResults.some(Boolean)) {
  27262. var newChildren = [];
  27263. for (var i = 0; i < node.children.length; i++) {
  27264. var child = node.children[i];
  27265. if (child.type !== "text" && !shouldMergeResults[i]) {
  27266. newChildren.push(child);
  27267. continue;
  27268. }
  27269. var newChild = child.type === "text" ? child : child.clone({
  27270. type: "text",
  27271. value: getValue(child)
  27272. });
  27273. if (newChildren.length === 0 || newChildren[newChildren.length - 1].type !== "text") {
  27274. newChildren.push(newChild);
  27275. continue;
  27276. }
  27277. var lastChild = newChildren.pop();
  27278. var ParseSourceSpan = lastChild.sourceSpan.constructor;
  27279. newChildren.push(lastChild.clone({
  27280. value: lastChild.value + newChild.value,
  27281. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, newChild.sourceSpan.end)
  27282. }));
  27283. }
  27284. return node.clone({
  27285. children: newChildren
  27286. });
  27287. }
  27288. }
  27289. return node;
  27290. });
  27291. }
  27292. function mergeCdataIntoText(ast
  27293. /*, options */
  27294. ) {
  27295. return mergeNodeIntoText(ast, function (node) {
  27296. return node.type === "cdata";
  27297. }, function (node) {
  27298. return `<![CDATA[${node.value}]]>`;
  27299. });
  27300. }
  27301. function mergeSimpleElementIntoText(ast
  27302. /*, options */
  27303. ) {
  27304. var isSimpleElement = function isSimpleElement(node) {
  27305. return node.type === "element" && node.attrs.length === 0 && node.children.length === 1 && node.firstChild.type === "text" && // \xA0: non-breaking whitespace
  27306. !/[^\S\xA0]/.test(node.children[0].value) && !node.firstChild.hasLeadingSpaces && !node.firstChild.hasTrailingSpaces && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces && node.prev && node.prev.type === "text" && node.next && node.next.type === "text";
  27307. };
  27308. return ast.map(function (node) {
  27309. if (node.children) {
  27310. var isSimpleElementResults = node.children.map(isSimpleElement);
  27311. if (isSimpleElementResults.some(Boolean)) {
  27312. var newChildren = [];
  27313. for (var i = 0; i < node.children.length; i++) {
  27314. var child = node.children[i];
  27315. if (isSimpleElementResults[i]) {
  27316. var lastChild = newChildren.pop();
  27317. var nextChild = node.children[++i];
  27318. var ParseSourceSpan = node.sourceSpan.constructor;
  27319. var isTrailingSpaceSensitive = nextChild.isTrailingSpaceSensitive,
  27320. hasTrailingSpaces = nextChild.hasTrailingSpaces;
  27321. newChildren.push(lastChild.clone({
  27322. value: lastChild.value + `<${child.rawName}>` + child.firstChild.value + `</${child.rawName}>` + nextChild.value,
  27323. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, nextChild.sourceSpan.end),
  27324. isTrailingSpaceSensitive,
  27325. hasTrailingSpaces
  27326. }));
  27327. } else {
  27328. newChildren.push(child);
  27329. }
  27330. }
  27331. return node.clone({
  27332. children: newChildren
  27333. });
  27334. }
  27335. }
  27336. return node;
  27337. });
  27338. }
  27339. function extractInterpolation(ast, options) {
  27340. if (options.parser === "html") {
  27341. return ast;
  27342. }
  27343. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  27344. return ast.map(function (node) {
  27345. if (!canHaveInterpolation$1(node)) {
  27346. return node;
  27347. }
  27348. var newChildren = [];
  27349. var _iteratorNormalCompletion = true;
  27350. var _didIteratorError = false;
  27351. var _iteratorError = undefined;
  27352. try {
  27353. for (var _iterator = node.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  27354. var child = _step.value;
  27355. if (child.type !== "text") {
  27356. newChildren.push(child);
  27357. continue;
  27358. }
  27359. var ParseSourceSpan = child.sourceSpan.constructor;
  27360. var startSourceSpan = child.sourceSpan.start;
  27361. var endSourceSpan = null;
  27362. var components = child.value.split(interpolationRegex);
  27363. for (var i = 0; i < components.length; i++, startSourceSpan = endSourceSpan) {
  27364. var value = components[i];
  27365. if (i % 2 === 0) {
  27366. endSourceSpan = startSourceSpan.moveBy(value.length);
  27367. if (value.length !== 0) {
  27368. newChildren.push({
  27369. type: "text",
  27370. value,
  27371. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan)
  27372. });
  27373. }
  27374. continue;
  27375. }
  27376. endSourceSpan = startSourceSpan.moveBy(value.length + 4); // `{{` + `}}`
  27377. newChildren.push({
  27378. type: "interpolation",
  27379. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan),
  27380. children: value.length === 0 ? [] : [{
  27381. type: "text",
  27382. value,
  27383. sourceSpan: new ParseSourceSpan(startSourceSpan.moveBy(2), endSourceSpan.moveBy(-2))
  27384. }]
  27385. });
  27386. }
  27387. }
  27388. } catch (err) {
  27389. _didIteratorError = true;
  27390. _iteratorError = err;
  27391. } finally {
  27392. try {
  27393. if (!_iteratorNormalCompletion && _iterator.return != null) {
  27394. _iterator.return();
  27395. }
  27396. } finally {
  27397. if (_didIteratorError) {
  27398. throw _iteratorError;
  27399. }
  27400. }
  27401. }
  27402. return node.clone({
  27403. children: newChildren
  27404. });
  27405. });
  27406. }
  27407. /**
  27408. * - add `hasLeadingSpaces` field
  27409. * - add `hasTrailingSpaces` field
  27410. * - add `hasDanglingSpaces` field for parent nodes
  27411. * - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes
  27412. * - remove insensitive whitespaces
  27413. */
  27414. function extractWhitespaces(ast
  27415. /*, options*/
  27416. ) {
  27417. var TYPE_WHITESPACE = "whitespace";
  27418. return ast.map(function (node) {
  27419. if (!node.children) {
  27420. return node;
  27421. }
  27422. if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "text" && node.children[0].value.trim().length === 0) {
  27423. return node.clone({
  27424. children: [],
  27425. hasDanglingSpaces: node.children.length !== 0
  27426. });
  27427. }
  27428. var isWhitespaceSensitive = isWhitespaceSensitiveNode$1(node);
  27429. var isIndentationSensitive = isIndentationSensitiveNode$1(node);
  27430. return node.clone({
  27431. isWhitespaceSensitive,
  27432. isIndentationSensitive,
  27433. children: node.children // extract whitespace nodes
  27434. .reduce(function (newChildren, child) {
  27435. if (child.type !== "text" || isWhitespaceSensitive) {
  27436. return newChildren.concat(child);
  27437. }
  27438. var localChildren = [];
  27439. var _child$value$match = child.value.match(/^(\s*)([\s\S]*?)(\s*)$/),
  27440. _child$value$match2 = _slicedToArray(_child$value$match, 4),
  27441. leadingSpaces = _child$value$match2[1],
  27442. text = _child$value$match2[2],
  27443. trailingSpaces = _child$value$match2[3];
  27444. if (leadingSpaces) {
  27445. localChildren.push({
  27446. type: TYPE_WHITESPACE
  27447. });
  27448. }
  27449. var ParseSourceSpan = child.sourceSpan.constructor;
  27450. if (text) {
  27451. localChildren.push({
  27452. type: "text",
  27453. value: text,
  27454. sourceSpan: new ParseSourceSpan(child.sourceSpan.start.moveBy(leadingSpaces.length), child.sourceSpan.end.moveBy(-trailingSpaces.length))
  27455. });
  27456. }
  27457. if (trailingSpaces) {
  27458. localChildren.push({
  27459. type: TYPE_WHITESPACE
  27460. });
  27461. }
  27462. return newChildren.concat(localChildren);
  27463. }, []) // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes
  27464. .reduce(function (newChildren, child, i, children) {
  27465. if (child.type === TYPE_WHITESPACE) {
  27466. return newChildren;
  27467. }
  27468. var hasLeadingSpaces = i !== 0 && children[i - 1].type === TYPE_WHITESPACE;
  27469. var hasTrailingSpaces = i !== children.length - 1 && children[i + 1].type === TYPE_WHITESPACE;
  27470. return newChildren.concat(Object.assign({}, child, {
  27471. hasLeadingSpaces,
  27472. hasTrailingSpaces
  27473. }));
  27474. }, [])
  27475. });
  27476. });
  27477. }
  27478. function addIsSelfClosing(ast
  27479. /*, options */
  27480. ) {
  27481. return ast.map(function (node) {
  27482. return Object.assign(node, {
  27483. isSelfClosing: !node.children || node.type === "element" && (node.tagDefinition.isVoid || // self-closing
  27484. node.startSourceSpan === node.endSourceSpan)
  27485. });
  27486. });
  27487. }
  27488. function addHasHtmComponentClosingTag(ast, options) {
  27489. return ast.map(function (node) {
  27490. return node.type !== "element" ? node : Object.assign(node, {
  27491. hasHtmComponentClosingTag: node.endSourceSpan && /^<\s*\/\s*\/\s*>$/.test(options.originalText.slice(node.endSourceSpan.start.offset, node.endSourceSpan.end.offset))
  27492. });
  27493. });
  27494. }
  27495. function addCssDisplay(ast, options) {
  27496. return ast.map(function (node) {
  27497. return Object.assign(node, {
  27498. cssDisplay: getNodeCssStyleDisplay$1(node, options)
  27499. });
  27500. });
  27501. }
  27502. /**
  27503. * - add `isLeadingSpaceSensitive` field
  27504. * - add `isTrailingSpaceSensitive` field
  27505. * - add `isDanglingSpaceSensitive` field for parent nodes
  27506. */
  27507. function addIsSpaceSensitive(ast
  27508. /*, options */
  27509. ) {
  27510. return ast.map(function (node) {
  27511. if (!node.children) {
  27512. return node;
  27513. }
  27514. if (node.children.length === 0) {
  27515. return node.clone({
  27516. isDanglingSpaceSensitive: isDanglingSpaceSensitiveNode$1(node)
  27517. });
  27518. }
  27519. return node.clone({
  27520. children: node.children.map(function (child) {
  27521. return Object.assign({}, child, {
  27522. isLeadingSpaceSensitive: isLeadingSpaceSensitiveNode$1(child),
  27523. isTrailingSpaceSensitive: isTrailingSpaceSensitiveNode$1(child)
  27524. });
  27525. }).map(function (child, index, children) {
  27526. return Object.assign({}, child, {
  27527. isLeadingSpaceSensitive: index === 0 ? child.isLeadingSpaceSensitive : children[index - 1].isTrailingSpaceSensitive && child.isLeadingSpaceSensitive,
  27528. isTrailingSpaceSensitive: index === children.length - 1 ? child.isTrailingSpaceSensitive : children[index + 1].isLeadingSpaceSensitive && child.isTrailingSpaceSensitive
  27529. });
  27530. })
  27531. });
  27532. });
  27533. }
  27534. var preprocess_1$4 = preprocess$4;
  27535. function hasPragma$3(text) {
  27536. return /^\s*<!--\s*@(format|prettier)\s*-->/.test(text);
  27537. }
  27538. function insertPragma$7(text) {
  27539. return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, "");
  27540. }
  27541. var pragma$9 = {
  27542. hasPragma: hasPragma$3,
  27543. insertPragma: insertPragma$7
  27544. };
  27545. var _require$$0$builders$8 = doc.builders;
  27546. var concat$15 = _require$$0$builders$8.concat;
  27547. var group$15 = _require$$0$builders$8.group;
  27548. /**
  27549. * v-for="... in ..."
  27550. * v-for="... of ..."
  27551. * v-for="(..., ...) in ..."
  27552. * v-for="(..., ...) of ..."
  27553. */
  27554. function printVueFor$1(value, textToDoc) {
  27555. var _parseVueFor = parseVueFor(value),
  27556. left = _parseVueFor.left,
  27557. operator = _parseVueFor.operator,
  27558. right = _parseVueFor.right;
  27559. return concat$15([group$15(textToDoc(`function _(${left}) {}`, {
  27560. parser: "babel",
  27561. __isVueForBindingLeft: true
  27562. })), " ", operator, " ", textToDoc(right, {
  27563. parser: "__js_expression"
  27564. })]);
  27565. } // modified from https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/parser/index.js#L370-L387
  27566. function parseVueFor(value) {
  27567. var forAliasRE = /([^]*?)\s+(in|of)\s+([^]*)/;
  27568. var forIteratorRE = /,([^,}\]]*)(?:,([^,}\]]*))?$/;
  27569. var stripParensRE = /^\(|\)$/g;
  27570. var inMatch = value.match(forAliasRE);
  27571. if (!inMatch) {
  27572. return;
  27573. }
  27574. var res = {};
  27575. res.for = inMatch[3].trim();
  27576. var alias = inMatch[1].trim().replace(stripParensRE, "");
  27577. var iteratorMatch = alias.match(forIteratorRE);
  27578. if (iteratorMatch) {
  27579. res.alias = alias.replace(forIteratorRE, "");
  27580. res.iterator1 = iteratorMatch[1].trim();
  27581. if (iteratorMatch[2]) {
  27582. res.iterator2 = iteratorMatch[2].trim();
  27583. }
  27584. } else {
  27585. res.alias = alias;
  27586. }
  27587. return {
  27588. left: `${[res.alias, res.iterator1, res.iterator2].filter(Boolean).join(",")}`,
  27589. operator: inMatch[2],
  27590. right: res.for
  27591. };
  27592. }
  27593. function printVueSlotScope$1(value, textToDoc) {
  27594. return textToDoc(`function _(${value}) {}`, {
  27595. parser: "babel",
  27596. __isVueSlotScope: true
  27597. });
  27598. }
  27599. function isVueEventBindingExpression$3(eventBindingValue) {
  27600. // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/codegen/events.js#L3-L4
  27601. // arrow function or anonymous function
  27602. var fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/; // simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b])
  27603. var simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/; // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104
  27604. var value = eventBindingValue.trim();
  27605. return fnExpRE.test(value) || simplePathRE.test(value);
  27606. }
  27607. var syntaxVue = {
  27608. isVueEventBindingExpression: isVueEventBindingExpression$3,
  27609. printVueFor: printVueFor$1,
  27610. printVueSlotScope: printVueSlotScope$1
  27611. };
  27612. var parseSrcset = createCommonjsModule(function (module) {
  27613. /**
  27614. * Srcset Parser
  27615. *
  27616. * By Alex Bell | MIT License
  27617. *
  27618. * JS Parser for the string value that appears in markup <img srcset="here">
  27619. *
  27620. * @returns Array [{url: _, d: _, w: _, h:_}, ...]
  27621. *
  27622. * Based super duper closely on the reference algorithm at:
  27623. * https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute
  27624. *
  27625. * Most comments are copied in directly from the spec
  27626. * (except for comments in parens).
  27627. */
  27628. (function (root, factory) {
  27629. if (typeof undefined === 'function' && undefined.amd) {
  27630. // AMD. Register as an anonymous module.
  27631. undefined([], factory);
  27632. } else if ('object' === 'object' && module.exports) {
  27633. // Node. Does not work with strict CommonJS, but
  27634. // only CommonJS-like environments that support module.exports,
  27635. // like Node.
  27636. module.exports = factory();
  27637. } else {
  27638. // Browser globals (root is window)
  27639. root.parseSrcset = factory();
  27640. }
  27641. })(this, function () {
  27642. // 1. Let input be the value passed to this algorithm.
  27643. return function (input, options) {
  27644. var logger = options && options.logger || console; // UTILITY FUNCTIONS
  27645. // Manual is faster than RegEx
  27646. // http://bjorn.tipling.com/state-and-regular-expressions-in-javascript
  27647. // http://jsperf.com/whitespace-character/5
  27648. function isSpace(c) {
  27649. return c === "\u0020" || // space
  27650. c === "\u0009" || // horizontal tab
  27651. c === "\u000A" || // new line
  27652. c === "\u000C" || // form feed
  27653. c === "\u000D"; // carriage return
  27654. }
  27655. function collectCharacters(regEx) {
  27656. var chars,
  27657. match = regEx.exec(input.substring(pos));
  27658. if (match) {
  27659. chars = match[0];
  27660. pos += chars.length;
  27661. return chars;
  27662. }
  27663. }
  27664. var inputLength = input.length,
  27665. // (Don't use \s, to avoid matching non-breaking space)
  27666. regexLeadingSpaces = /^[ \t\n\r\u000c]+/,
  27667. regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/,
  27668. regexLeadingNotSpaces = /^[^ \t\n\r\u000c]+/,
  27669. regexTrailingCommas = /[,]+$/,
  27670. regexNonNegativeInteger = /^\d+$/,
  27671. // ( Positive or negative or unsigned integers or decimals, without or without exponents.
  27672. // Must include at least one digit.
  27673. // According to spec tests any decimal point must be followed by a digit.
  27674. // No leading plus sign is allowed.)
  27675. // https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
  27676. regexFloatingPoint = /^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,
  27677. url,
  27678. descriptors,
  27679. currentDescriptor,
  27680. state,
  27681. c,
  27682. // 2. Let position be a pointer into input, initially pointing at the start
  27683. // of the string.
  27684. pos = 0,
  27685. // 3. Let candidates be an initially empty source set.
  27686. candidates = []; // 4. Splitting loop: Collect a sequence of characters that are space
  27687. // characters or U+002C COMMA characters. If any U+002C COMMA characters
  27688. // were collected, that is a parse error.
  27689. while (true) {
  27690. collectCharacters(regexLeadingCommasOrSpaces); // 5. If position is past the end of input, return candidates and abort these steps.
  27691. if (pos >= inputLength) {
  27692. return candidates; // (we're done, this is the sole return path)
  27693. } // 6. Collect a sequence of characters that are not space characters,
  27694. // and let that be url.
  27695. url = collectCharacters(regexLeadingNotSpaces); // 7. Let descriptors be a new empty list.
  27696. descriptors = []; // 8. If url ends with a U+002C COMMA character (,), follow these substeps:
  27697. // (1). Remove all trailing U+002C COMMA characters from url. If this removed
  27698. // more than one character, that is a parse error.
  27699. if (url.slice(-1) === ",") {
  27700. url = url.replace(regexTrailingCommas, ""); // (Jump ahead to step 9 to skip tokenization and just push the candidate).
  27701. parseDescriptors(); // Otherwise, follow these substeps:
  27702. } else {
  27703. tokenize();
  27704. } // (close else of step 8)
  27705. // 16. Return to the step labeled splitting loop.
  27706. } // (Close of big while loop.)
  27707. /**
  27708. * Tokenizes descriptor properties prior to parsing
  27709. * Returns undefined.
  27710. */
  27711. function tokenize() {
  27712. // 8.1. Descriptor tokeniser: Skip whitespace
  27713. collectCharacters(regexLeadingSpaces); // 8.2. Let current descriptor be the empty string.
  27714. currentDescriptor = ""; // 8.3. Let state be in descriptor.
  27715. state = "in descriptor";
  27716. while (true) {
  27717. // 8.4. Let c be the character at position.
  27718. c = input.charAt(pos); // Do the following depending on the value of state.
  27719. // For the purpose of this step, "EOF" is a special character representing
  27720. // that position is past the end of input.
  27721. // In descriptor
  27722. if (state === "in descriptor") {
  27723. // Do the following, depending on the value of c:
  27724. // Space character
  27725. // If current descriptor is not empty, append current descriptor to
  27726. // descriptors and let current descriptor be the empty string.
  27727. // Set state to after descriptor.
  27728. if (isSpace(c)) {
  27729. if (currentDescriptor) {
  27730. descriptors.push(currentDescriptor);
  27731. currentDescriptor = "";
  27732. state = "after descriptor";
  27733. } // U+002C COMMA (,)
  27734. // Advance position to the next character in input. If current descriptor
  27735. // is not empty, append current descriptor to descriptors. Jump to the step
  27736. // labeled descriptor parser.
  27737. } else if (c === ",") {
  27738. pos += 1;
  27739. if (currentDescriptor) {
  27740. descriptors.push(currentDescriptor);
  27741. }
  27742. parseDescriptors();
  27743. return; // U+0028 LEFT PARENTHESIS (()
  27744. // Append c to current descriptor. Set state to in parens.
  27745. } else if (c === "\u0028") {
  27746. currentDescriptor = currentDescriptor + c;
  27747. state = "in parens"; // EOF
  27748. // If current descriptor is not empty, append current descriptor to
  27749. // descriptors. Jump to the step labeled descriptor parser.
  27750. } else if (c === "") {
  27751. if (currentDescriptor) {
  27752. descriptors.push(currentDescriptor);
  27753. }
  27754. parseDescriptors();
  27755. return; // Anything else
  27756. // Append c to current descriptor.
  27757. } else {
  27758. currentDescriptor = currentDescriptor + c;
  27759. } // (end "in descriptor"
  27760. // In parens
  27761. } else if (state === "in parens") {
  27762. // U+0029 RIGHT PARENTHESIS ())
  27763. // Append c to current descriptor. Set state to in descriptor.
  27764. if (c === ")") {
  27765. currentDescriptor = currentDescriptor + c;
  27766. state = "in descriptor"; // EOF
  27767. // Append current descriptor to descriptors. Jump to the step labeled
  27768. // descriptor parser.
  27769. } else if (c === "") {
  27770. descriptors.push(currentDescriptor);
  27771. parseDescriptors();
  27772. return; // Anything else
  27773. // Append c to current descriptor.
  27774. } else {
  27775. currentDescriptor = currentDescriptor + c;
  27776. } // After descriptor
  27777. } else if (state === "after descriptor") {
  27778. // Do the following, depending on the value of c:
  27779. // Space character: Stay in this state.
  27780. if (isSpace(c)) {// EOF: Jump to the step labeled descriptor parser.
  27781. } else if (c === "") {
  27782. parseDescriptors();
  27783. return; // Anything else
  27784. // Set state to in descriptor. Set position to the previous character in input.
  27785. } else {
  27786. state = "in descriptor";
  27787. pos -= 1;
  27788. }
  27789. } // Advance position to the next character in input.
  27790. pos += 1; // Repeat this step.
  27791. } // (close while true loop)
  27792. }
  27793. /**
  27794. * Adds descriptor properties to a candidate, pushes to the candidates array
  27795. * @return undefined
  27796. */
  27797. // Declared outside of the while loop so that it's only created once.
  27798. function parseDescriptors() {
  27799. // 9. Descriptor parser: Let error be no.
  27800. var pError = false,
  27801. // 10. Let width be absent.
  27802. // 11. Let density be absent.
  27803. // 12. Let future-compat-h be absent. (We're implementing it now as h)
  27804. w,
  27805. d,
  27806. h,
  27807. i,
  27808. candidate = {},
  27809. desc,
  27810. lastChar,
  27811. value,
  27812. intVal,
  27813. floatVal; // 13. For each descriptor in descriptors, run the appropriate set of steps
  27814. // from the following list:
  27815. for (i = 0; i < descriptors.length; i++) {
  27816. desc = descriptors[i];
  27817. lastChar = desc[desc.length - 1];
  27818. value = desc.substring(0, desc.length - 1);
  27819. intVal = parseInt(value, 10);
  27820. floatVal = parseFloat(value); // If the descriptor consists of a valid non-negative integer followed by
  27821. // a U+0077 LATIN SMALL LETTER W character
  27822. if (regexNonNegativeInteger.test(value) && lastChar === "w") {
  27823. // If width and density are not both absent, then let error be yes.
  27824. if (w || d) {
  27825. pError = true;
  27826. } // Apply the rules for parsing non-negative integers to the descriptor.
  27827. // If the result is zero, let error be yes.
  27828. // Otherwise, let width be the result.
  27829. if (intVal === 0) {
  27830. pError = true;
  27831. } else {
  27832. w = intVal;
  27833. } // If the descriptor consists of a valid floating-point number followed by
  27834. // a U+0078 LATIN SMALL LETTER X character
  27835. } else if (regexFloatingPoint.test(value) && lastChar === "x") {
  27836. // If width, density and future-compat-h are not all absent, then let error
  27837. // be yes.
  27838. if (w || d || h) {
  27839. pError = true;
  27840. } // Apply the rules for parsing floating-point number values to the descriptor.
  27841. // If the result is less than zero, let error be yes. Otherwise, let density
  27842. // be the result.
  27843. if (floatVal < 0) {
  27844. pError = true;
  27845. } else {
  27846. d = floatVal;
  27847. } // If the descriptor consists of a valid non-negative integer followed by
  27848. // a U+0068 LATIN SMALL LETTER H character
  27849. } else if (regexNonNegativeInteger.test(value) && lastChar === "h") {
  27850. // If height and density are not both absent, then let error be yes.
  27851. if (h || d) {
  27852. pError = true;
  27853. } // Apply the rules for parsing non-negative integers to the descriptor.
  27854. // If the result is zero, let error be yes. Otherwise, let future-compat-h
  27855. // be the result.
  27856. if (intVal === 0) {
  27857. pError = true;
  27858. } else {
  27859. h = intVal;
  27860. } // Anything else, Let error be yes.
  27861. } else {
  27862. pError = true;
  27863. }
  27864. } // (close step 13 for loop)
  27865. // 15. If error is still no, then append a new image source to candidates whose
  27866. // URL is url, associated with a width width if not absent and a pixel
  27867. // density density if not absent. Otherwise, there is a parse error.
  27868. if (!pError) {
  27869. candidate.url = url;
  27870. if (w) {
  27871. candidate.w = w;
  27872. }
  27873. if (d) {
  27874. candidate.d = d;
  27875. }
  27876. if (h) {
  27877. candidate.h = h;
  27878. }
  27879. candidates.push(candidate);
  27880. } else if (logger && logger.error) {
  27881. logger.error("Invalid srcset descriptor found in '" + input + "' at '" + desc + "'.");
  27882. }
  27883. } // (close parseDescriptors fn)
  27884. };
  27885. });
  27886. });
  27887. var _require$$0$builders$9 = doc.builders;
  27888. var concat$16 = _require$$0$builders$9.concat;
  27889. var ifBreak$7 = _require$$0$builders$9.ifBreak;
  27890. var join$11 = _require$$0$builders$9.join;
  27891. var line$10 = _require$$0$builders$9.line;
  27892. function printImgSrcset$1(value) {
  27893. var srcset = parseSrcset(value, {
  27894. logger: {
  27895. error(message) {
  27896. throw new Error(message);
  27897. }
  27898. }
  27899. });
  27900. var hasW = srcset.some(function (src) {
  27901. return src.w;
  27902. });
  27903. var hasH = srcset.some(function (src) {
  27904. return src.h;
  27905. });
  27906. var hasX = srcset.some(function (src) {
  27907. return src.d;
  27908. });
  27909. if (hasW + hasH + hasX !== 1) {
  27910. throw new Error(`Mixed descriptor in srcset is not supported`);
  27911. }
  27912. var key = hasW ? "w" : hasH ? "h" : "d";
  27913. var unit = hasW ? "w" : hasH ? "h" : "x";
  27914. var getMax = function getMax(values) {
  27915. return Math.max.apply(Math, values);
  27916. };
  27917. var urls = srcset.map(function (src) {
  27918. return src.url;
  27919. });
  27920. var maxUrlLength = getMax(urls.map(function (url) {
  27921. return url.length;
  27922. }));
  27923. var descriptors = srcset.map(function (src) {
  27924. return src[key];
  27925. }).map(function (descriptor) {
  27926. return descriptor ? descriptor.toString() : "";
  27927. });
  27928. var descriptorLeftLengths = descriptors.map(function (descriptor) {
  27929. var index = descriptor.indexOf(".");
  27930. return index === -1 ? descriptor.length : index;
  27931. });
  27932. var maxDescriptorLeftLength = getMax(descriptorLeftLengths);
  27933. return join$11(concat$16([",", line$10]), urls.map(function (url, index) {
  27934. var parts = [url];
  27935. var descriptor = descriptors[index];
  27936. if (descriptor) {
  27937. var urlPadding = maxUrlLength - url.length + 1;
  27938. var descriptorPadding = maxDescriptorLeftLength - descriptorLeftLengths[index];
  27939. var alignment = " ".repeat(urlPadding + descriptorPadding);
  27940. parts.push(ifBreak$7(alignment, " "), descriptor + unit);
  27941. }
  27942. return concat$16(parts);
  27943. }));
  27944. }
  27945. var syntaxAttribute = {
  27946. printImgSrcset: printImgSrcset$1
  27947. };
  27948. var builders = doc.builders;
  27949. var _require$$0$utils = doc.utils;
  27950. var stripTrailingHardline$2 = _require$$0$utils.stripTrailingHardline;
  27951. var mapDoc$7 = _require$$0$utils.mapDoc;
  27952. var breakParent$4 = builders.breakParent;
  27953. var dedentToRoot$2 = builders.dedentToRoot;
  27954. var fill$5 = builders.fill;
  27955. var group$14 = builders.group;
  27956. var hardline$12 = builders.hardline;
  27957. var ifBreak$6 = builders.ifBreak;
  27958. var indent$9 = builders.indent;
  27959. var join$10 = builders.join;
  27960. var line$9 = builders.line;
  27961. var literalline$6 = builders.literalline;
  27962. var markAsRoot$4 = builders.markAsRoot;
  27963. var softline$7 = builders.softline;
  27964. var countChars = utils$10.countChars;
  27965. var countParents = utils$10.countParents;
  27966. var dedentString = utils$10.dedentString;
  27967. var forceBreakChildren = utils$10.forceBreakChildren;
  27968. var forceBreakContent = utils$10.forceBreakContent;
  27969. var forceNextEmptyLine = utils$10.forceNextEmptyLine;
  27970. var getLastDescendant = utils$10.getLastDescendant;
  27971. var getPrettierIgnoreAttributeCommentData = utils$10.getPrettierIgnoreAttributeCommentData;
  27972. var hasPrettierIgnore$2 = utils$10.hasPrettierIgnore;
  27973. var inferScriptParser = utils$10.inferScriptParser;
  27974. var isScriptLikeTag = utils$10.isScriptLikeTag;
  27975. var isTextLikeNode = utils$10.isTextLikeNode;
  27976. var normalizeParts$1 = utils$10.normalizeParts;
  27977. var preferHardlineAsLeadingSpaces = utils$10.preferHardlineAsLeadingSpaces;
  27978. var shouldNotPrintClosingTag = utils$10.shouldNotPrintClosingTag;
  27979. var shouldPreserveContent = utils$10.shouldPreserveContent;
  27980. var unescapeQuoteEntities = utils$10.unescapeQuoteEntities;
  27981. var replaceEndOfLineWith$2 = util$1.replaceEndOfLineWith;
  27982. var insertPragma$6 = pragma$9.insertPragma;
  27983. var printVueFor = syntaxVue.printVueFor;
  27984. var printVueSlotScope = syntaxVue.printVueSlotScope;
  27985. var isVueEventBindingExpression$2 = syntaxVue.isVueEventBindingExpression;
  27986. var printImgSrcset = syntaxAttribute.printImgSrcset;
  27987. function concat$14(parts) {
  27988. var newParts = normalizeParts$1(parts);
  27989. return newParts.length === 0 ? "" : newParts.length === 1 ? newParts[0] : builders.concat(newParts);
  27990. }
  27991. function embed$6(path$$1, print, textToDoc, options) {
  27992. var node = path$$1.getValue();
  27993. switch (node.type) {
  27994. case "text":
  27995. {
  27996. if (isScriptLikeTag(node.parent)) {
  27997. var parser = inferScriptParser(node.parent);
  27998. if (parser) {
  27999. var value = parser === "markdown" ? dedentString(node.value.replace(/^[^\S\n]*?\n/, "")) : node.value;
  28000. return builders.concat([concat$14([breakParent$4, printOpeningTagPrefix(node, options), stripTrailingHardline$2(textToDoc(value, {
  28001. parser
  28002. })), printClosingTagSuffix(node, options)])]);
  28003. }
  28004. } else if (node.parent.type === "interpolation") {
  28005. return concat$14([indent$9(concat$14([line$9, textToDoc(node.value, Object.assign({
  28006. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  28007. }, options.parser === "angular" ? {
  28008. parser: "__ng_interpolation",
  28009. trailingComma: "none"
  28010. } : options.parser === "vue" ? {
  28011. parser: "__vue_expression"
  28012. } : {
  28013. parser: "__js_expression"
  28014. }))])), node.parent.next && needsToBorrowPrevClosingTagEndMarker(node.parent.next) ? " " : line$9]);
  28015. }
  28016. break;
  28017. }
  28018. case "attribute":
  28019. {
  28020. if (!node.value) {
  28021. break;
  28022. } // lit-html: html`<my-element obj=${obj}></my-element>`
  28023. if (/^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  28024. return concat$14([node.rawName, "=", node.value]);
  28025. } // lwc: html`<my-element data-for={value}></my-elememt>`
  28026. if (options.parser === "lwc") {
  28027. var interpolationRegex = /^\{[\s\S]*\}$/;
  28028. if (interpolationRegex.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  28029. return concat$14([node.rawName, "=", node.value]);
  28030. }
  28031. }
  28032. var embeddedAttributeValueDoc = printEmbeddedAttributeValue(node, function (code, opts) {
  28033. return (// strictly prefer single quote to avoid unnecessary html entity escape
  28034. textToDoc(code, Object.assign({
  28035. __isInHtmlAttribute: true
  28036. }, opts))
  28037. );
  28038. }, options);
  28039. if (embeddedAttributeValueDoc) {
  28040. return concat$14([node.rawName, '="', group$14(mapDoc$7(embeddedAttributeValueDoc, function (doc$$2) {
  28041. return typeof doc$$2 === "string" ? doc$$2.replace(/"/g, "&quot;") : doc$$2;
  28042. })), '"']);
  28043. }
  28044. break;
  28045. }
  28046. case "yaml":
  28047. return markAsRoot$4(concat$14(["---", hardline$12, node.value.trim().length === 0 ? "" : textToDoc(node.value, {
  28048. parser: "yaml"
  28049. }), "---"]));
  28050. }
  28051. }
  28052. function genericPrint$5(path$$1, options, print) {
  28053. var node = path$$1.getValue();
  28054. switch (node.type) {
  28055. case "root":
  28056. // use original concat to not break stripTrailingHardline
  28057. return builders.concat([group$14(printChildren$1(path$$1, options, print)), hardline$12]);
  28058. case "element":
  28059. case "ieConditionalComment":
  28060. {
  28061. /**
  28062. * do not break:
  28063. *
  28064. * <div>{{
  28065. * ~
  28066. * interpolation
  28067. * }}</div>
  28068. * ~
  28069. *
  28070. * exception: break if the opening tag breaks
  28071. *
  28072. * <div
  28073. * long
  28074. * ~
  28075. * >{{
  28076. * interpolation
  28077. * }}</div
  28078. * ~
  28079. * >
  28080. */
  28081. var shouldHugContent = node.children.length === 1 && node.firstChild.type === "interpolation" && node.firstChild.isLeadingSpaceSensitive && !node.firstChild.hasLeadingSpaces && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces;
  28082. var attrGroupId = Symbol("element-attr-group-id");
  28083. return concat$14([group$14(concat$14([group$14(printOpeningTag(path$$1, options, print), {
  28084. id: attrGroupId
  28085. }), node.children.length === 0 ? node.hasDanglingSpaces && node.isDanglingSpaceSensitive ? line$9 : "" : concat$14([forceBreakContent(node) ? breakParent$4 : "", function (childrenDoc) {
  28086. return shouldHugContent ? ifBreak$6(indent$9(childrenDoc), childrenDoc, {
  28087. groupId: attrGroupId
  28088. }) : isScriptLikeTag(node) && node.parent.type === "root" && options.parser === "vue" ? childrenDoc : indent$9(childrenDoc);
  28089. }(concat$14([shouldHugContent ? ifBreak$6(softline$7, "", {
  28090. groupId: attrGroupId
  28091. }) : node.firstChild.hasLeadingSpaces && node.firstChild.isLeadingSpaceSensitive ? line$9 : node.firstChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive ? dedentToRoot$2(softline$7) : softline$7, printChildren$1(path$$1, options, print)])), (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? " " : "" : shouldHugContent ? ifBreak$6(softline$7, "", {
  28092. groupId: attrGroupId
  28093. }) : node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? line$9 : (node.lastChild.type === "comment" || node.lastChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive) && new RegExp(`\\n\\s{${options.tabWidth * countParents(path$$1, function (n) {
  28094. return n.parent && n.parent.type !== "root";
  28095. })}}$`).test(node.lastChild.value) ?
  28096. /**
  28097. * <div>
  28098. * <pre>
  28099. * something
  28100. * </pre>
  28101. * ~
  28102. * </div>
  28103. */
  28104. "" : softline$7])])), printClosingTag(node, options)]);
  28105. }
  28106. case "ieConditionalStartComment":
  28107. case "ieConditionalEndComment":
  28108. return concat$14([printOpeningTagStart(node), printClosingTagEnd(node)]);
  28109. case "interpolation":
  28110. return concat$14([printOpeningTagStart(node, options), concat$14(path$$1.map(print, "children")), printClosingTagEnd(node, options)]);
  28111. case "text":
  28112. {
  28113. if (node.parent.type === "interpolation") {
  28114. // replace the trailing literalline with hardline for better readability
  28115. var trailingNewlineRegex = /\n[^\S\n]*?$/;
  28116. var hasTrailingNewline = trailingNewlineRegex.test(node.value);
  28117. var value = hasTrailingNewline ? node.value.replace(trailingNewlineRegex, "") : node.value;
  28118. return concat$14([concat$14(replaceEndOfLineWith$2(value, literalline$6)), hasTrailingNewline ? hardline$12 : ""]);
  28119. }
  28120. return fill$5(normalizeParts$1([].concat(printOpeningTagPrefix(node, options), getTextValueParts(node), printClosingTagSuffix(node, options))));
  28121. }
  28122. case "docType":
  28123. return concat$14([group$14(concat$14([printOpeningTagStart(node, options), " ", node.value.replace(/^html\b/i, "html").replace(/\s+/g, " ")])), printClosingTagEnd(node, options)]);
  28124. case "comment":
  28125. {
  28126. return concat$14([printOpeningTagPrefix(node, options), concat$14(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(node), options.locEnd(node)), literalline$6)), printClosingTagSuffix(node, options)]);
  28127. }
  28128. case "attribute":
  28129. {
  28130. if (node.value === null) {
  28131. return node.rawName;
  28132. }
  28133. var _value = unescapeQuoteEntities(node.value);
  28134. var singleQuoteCount = countChars(_value, "'");
  28135. var doubleQuoteCount = countChars(_value, '"');
  28136. var quote = singleQuoteCount < doubleQuoteCount ? "'" : '"';
  28137. return concat$14([node.rawName, concat$14(["=", quote, concat$14(replaceEndOfLineWith$2(quote === '"' ? _value.replace(/"/g, "&quot;") : _value.replace(/'/g, "&apos;"), literalline$6)), quote])]);
  28138. }
  28139. case "yaml":
  28140. case "toml":
  28141. return concat$14(replaceEndOfLineWith$2(node.raw, literalline$6));
  28142. default:
  28143. throw new Error(`Unexpected node type ${node.type}`);
  28144. }
  28145. }
  28146. function printChildren$1(path$$1, options, print) {
  28147. var node = path$$1.getValue();
  28148. if (forceBreakChildren(node)) {
  28149. return concat$14([breakParent$4, concat$14(path$$1.map(function (childPath) {
  28150. var childNode = childPath.getValue();
  28151. var prevBetweenLine = !childNode.prev ? "" : printBetweenLine(childNode.prev, childNode);
  28152. return concat$14([!prevBetweenLine ? "" : concat$14([prevBetweenLine, forceNextEmptyLine(childNode.prev) ? hardline$12 : ""]), printChild(childPath)]);
  28153. }, "children"))]);
  28154. }
  28155. var groupIds = node.children.map(function () {
  28156. return Symbol("");
  28157. });
  28158. return concat$14(path$$1.map(function (childPath, childIndex) {
  28159. var childNode = childPath.getValue();
  28160. if (isTextLikeNode(childNode)) {
  28161. if (childNode.prev && isTextLikeNode(childNode.prev)) {
  28162. var _prevBetweenLine = printBetweenLine(childNode.prev, childNode);
  28163. if (_prevBetweenLine) {
  28164. if (forceNextEmptyLine(childNode.prev)) {
  28165. return concat$14([hardline$12, hardline$12, printChild(childPath)]);
  28166. }
  28167. return concat$14([_prevBetweenLine, printChild(childPath)]);
  28168. }
  28169. }
  28170. return printChild(childPath);
  28171. }
  28172. var prevParts = [];
  28173. var leadingParts = [];
  28174. var trailingParts = [];
  28175. var nextParts = [];
  28176. var prevBetweenLine = childNode.prev ? printBetweenLine(childNode.prev, childNode) : "";
  28177. var nextBetweenLine = childNode.next ? printBetweenLine(childNode, childNode.next) : "";
  28178. if (prevBetweenLine) {
  28179. if (forceNextEmptyLine(childNode.prev)) {
  28180. prevParts.push(hardline$12, hardline$12);
  28181. } else if (prevBetweenLine === hardline$12) {
  28182. prevParts.push(hardline$12);
  28183. } else {
  28184. if (isTextLikeNode(childNode.prev)) {
  28185. leadingParts.push(prevBetweenLine);
  28186. } else {
  28187. leadingParts.push(ifBreak$6("", softline$7, {
  28188. groupId: groupIds[childIndex - 1]
  28189. }));
  28190. }
  28191. }
  28192. }
  28193. if (nextBetweenLine) {
  28194. if (forceNextEmptyLine(childNode)) {
  28195. if (isTextLikeNode(childNode.next)) {
  28196. nextParts.push(hardline$12, hardline$12);
  28197. }
  28198. } else if (nextBetweenLine === hardline$12) {
  28199. if (isTextLikeNode(childNode.next)) {
  28200. nextParts.push(hardline$12);
  28201. }
  28202. } else {
  28203. trailingParts.push(nextBetweenLine);
  28204. }
  28205. }
  28206. return concat$14([].concat(prevParts, group$14(concat$14([concat$14(leadingParts), group$14(concat$14([printChild(childPath), concat$14(trailingParts)]), {
  28207. id: groupIds[childIndex]
  28208. })])), nextParts));
  28209. }, "children"));
  28210. function printChild(childPath) {
  28211. var child = childPath.getValue();
  28212. if (hasPrettierIgnore$2(child)) {
  28213. return concat$14([].concat(printOpeningTagPrefix(child, options), replaceEndOfLineWith$2(options.originalText.slice(options.locStart(child) + (child.prev && needsToBorrowNextOpeningTagStartMarker(child.prev) ? printOpeningTagStartMarker(child).length : 0), options.locEnd(child) - (child.next && needsToBorrowPrevClosingTagEndMarker(child.next) ? printClosingTagEndMarker(child, options).length : 0)), literalline$6), printClosingTagSuffix(child, options)));
  28214. }
  28215. if (shouldPreserveContent(child, options)) {
  28216. return concat$14([].concat(printOpeningTagPrefix(child, options), group$14(printOpeningTag(childPath, options, print)), replaceEndOfLineWith$2(options.originalText.slice(child.startSourceSpan.end.offset + (child.firstChild && needsToBorrowParentOpeningTagEndMarker(child.firstChild) ? -printOpeningTagEndMarker(child).length : 0), child.endSourceSpan.start.offset + (child.lastChild && needsToBorrowParentClosingTagStartMarker(child.lastChild) ? printClosingTagStartMarker(child, options).length : needsToBorrowLastChildClosingTagEndMarker(child) ? -printClosingTagEndMarker(child.lastChild, options).length : 0)), literalline$6), printClosingTag(child, options), printClosingTagSuffix(child, options)));
  28217. }
  28218. return print(childPath);
  28219. }
  28220. function printBetweenLine(prevNode, nextNode) {
  28221. return isTextLikeNode(prevNode) && isTextLikeNode(nextNode) ? prevNode.isTrailingSpaceSensitive ? prevNode.hasTrailingSpaces ? preferHardlineAsLeadingSpaces(nextNode) ? hardline$12 : line$9 : "" : preferHardlineAsLeadingSpaces(nextNode) ? hardline$12 : softline$7 : needsToBorrowNextOpeningTagStartMarker(prevNode) && (
  28222. /**
  28223. * 123<a
  28224. * ~
  28225. * ><b>
  28226. */
  28227. nextNode.firstChild ||
  28228. /**
  28229. * 123<!--
  28230. * ~
  28231. * -->
  28232. */
  28233. nextNode.isSelfClosing ||
  28234. /**
  28235. * 123<span
  28236. * ~
  28237. * attr
  28238. */
  28239. nextNode.type === "element" && nextNode.attrs.length !== 0) ||
  28240. /**
  28241. * <img
  28242. * src="long"
  28243. * ~
  28244. * />123
  28245. */
  28246. prevNode.type === "element" && prevNode.isSelfClosing && needsToBorrowPrevClosingTagEndMarker(nextNode) ? "" : !nextNode.isLeadingSpaceSensitive || preferHardlineAsLeadingSpaces(nextNode) ||
  28247. /**
  28248. * Want to write us a letter? Use our<a
  28249. * ><b><a>mailing address</a></b></a
  28250. * ~
  28251. * >.
  28252. */
  28253. needsToBorrowPrevClosingTagEndMarker(nextNode) && prevNode.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild) && prevNode.lastChild.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild.lastChild) ? hardline$12 : nextNode.hasLeadingSpaces ? line$9 : softline$7;
  28254. }
  28255. }
  28256. function printOpeningTag(path$$1, options, print) {
  28257. var node = path$$1.getValue();
  28258. var forceNotToBreakAttrContent = node.type === "element" && node.fullName === "script" && node.attrs.length === 1 && node.attrs[0].fullName === "src" && node.children.length === 0;
  28259. return concat$14([printOpeningTagStart(node, options), !node.attrs || node.attrs.length === 0 ? node.isSelfClosing ?
  28260. /**
  28261. * <br />
  28262. * ^
  28263. */
  28264. " " : "" : concat$14([indent$9(concat$14([forceNotToBreakAttrContent ? " " : line$9, join$10(line$9, function (ignoreAttributeData) {
  28265. var hasPrettierIgnoreAttribute = typeof ignoreAttributeData === "boolean" ? function () {
  28266. return ignoreAttributeData;
  28267. } : Array.isArray(ignoreAttributeData) ? function (attr) {
  28268. return ignoreAttributeData.indexOf(attr.rawName) !== -1;
  28269. } : function () {
  28270. return false;
  28271. };
  28272. return path$$1.map(function (attrPath) {
  28273. var attr = attrPath.getValue();
  28274. return hasPrettierIgnoreAttribute(attr) ? concat$14(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(attr), options.locEnd(attr)), literalline$6)) : print(attrPath);
  28275. }, "attrs");
  28276. }(node.prev && node.prev.type === "comment" && getPrettierIgnoreAttributeCommentData(node.prev.value)))])),
  28277. /**
  28278. * 123<a
  28279. * attr
  28280. * ~
  28281. * >456
  28282. */
  28283. node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ||
  28284. /**
  28285. * <span
  28286. * >123<meta
  28287. * ~
  28288. * /></span>
  28289. */
  28290. node.isSelfClosing && needsToBorrowLastChildClosingTagEndMarker(node.parent) ? "" : node.isSelfClosing ? forceNotToBreakAttrContent ? " " : line$9 : forceNotToBreakAttrContent ? "" : softline$7]), node.isSelfClosing ? "" : printOpeningTagEnd(node)]);
  28291. }
  28292. function printOpeningTagStart(node, options) {
  28293. return node.prev && needsToBorrowNextOpeningTagStartMarker(node.prev) ? "" : concat$14([printOpeningTagPrefix(node, options), printOpeningTagStartMarker(node)]);
  28294. }
  28295. function printOpeningTagEnd(node) {
  28296. return node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ? "" : printOpeningTagEndMarker(node);
  28297. }
  28298. function printClosingTag(node, options) {
  28299. return concat$14([node.isSelfClosing ? "" : printClosingTagStart(node, options), printClosingTagEnd(node, options)]);
  28300. }
  28301. function printClosingTagStart(node, options) {
  28302. return node.lastChild && needsToBorrowParentClosingTagStartMarker(node.lastChild) ? "" : concat$14([printClosingTagPrefix(node, options), printClosingTagStartMarker(node, options)]);
  28303. }
  28304. function printClosingTagEnd(node, options) {
  28305. return (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? "" : concat$14([printClosingTagEndMarker(node, options), printClosingTagSuffix(node, options)]);
  28306. }
  28307. function needsToBorrowNextOpeningTagStartMarker(node) {
  28308. /**
  28309. * 123<p
  28310. * ^^
  28311. * >
  28312. */
  28313. return node.next && !isTextLikeNode(node.next) && isTextLikeNode(node) && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces;
  28314. }
  28315. function needsToBorrowParentOpeningTagEndMarker(node) {
  28316. /**
  28317. * <p
  28318. * >123
  28319. * ^
  28320. *
  28321. * <p
  28322. * ><a
  28323. * ^
  28324. */
  28325. return !node.prev && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  28326. }
  28327. function needsToBorrowPrevClosingTagEndMarker(node) {
  28328. /**
  28329. * <p></p
  28330. * >123
  28331. * ^
  28332. *
  28333. * <p></p
  28334. * ><a
  28335. * ^
  28336. */
  28337. return node.prev && !isTextLikeNode(node.prev) && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  28338. }
  28339. function needsToBorrowLastChildClosingTagEndMarker(node) {
  28340. /**
  28341. * <p
  28342. * ><a></a
  28343. * ></p
  28344. * ^
  28345. * >
  28346. */
  28347. return node.lastChild && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces && !isTextLikeNode(getLastDescendant(node.lastChild));
  28348. }
  28349. function needsToBorrowParentClosingTagStartMarker(node) {
  28350. /**
  28351. * <p>
  28352. * 123</p
  28353. * ^^^
  28354. * >
  28355. *
  28356. * 123</b
  28357. * ></a
  28358. * ^^^
  28359. * >
  28360. */
  28361. return !node.next && !node.hasTrailingSpaces && node.isTrailingSpaceSensitive && isTextLikeNode(getLastDescendant(node));
  28362. }
  28363. function printOpeningTagPrefix(node, options) {
  28364. return needsToBorrowParentOpeningTagEndMarker(node) ? printOpeningTagEndMarker(node.parent) : needsToBorrowPrevClosingTagEndMarker(node) ? printClosingTagEndMarker(node.prev, options) : "";
  28365. }
  28366. function printClosingTagPrefix(node, options) {
  28367. return needsToBorrowLastChildClosingTagEndMarker(node) ? printClosingTagEndMarker(node.lastChild, options) : "";
  28368. }
  28369. function printClosingTagSuffix(node, options) {
  28370. return needsToBorrowParentClosingTagStartMarker(node) ? printClosingTagStartMarker(node.parent, options) : needsToBorrowNextOpeningTagStartMarker(node) ? printOpeningTagStartMarker(node.next) : "";
  28371. }
  28372. function printOpeningTagStartMarker(node) {
  28373. switch (node.type) {
  28374. case "ieConditionalComment":
  28375. case "ieConditionalStartComment":
  28376. return `<!--[if ${node.condition}`;
  28377. case "ieConditionalEndComment":
  28378. return `<!--<!`;
  28379. case "interpolation":
  28380. return "{{";
  28381. case "docType":
  28382. return "<!DOCTYPE";
  28383. case "element":
  28384. if (node.condition) {
  28385. return `<!--[if ${node.condition}]><!--><${node.rawName}`;
  28386. }
  28387. // fall through
  28388. default:
  28389. return `<${node.rawName}`;
  28390. }
  28391. }
  28392. function printOpeningTagEndMarker(node) {
  28393. assert(!node.isSelfClosing);
  28394. switch (node.type) {
  28395. case "ieConditionalComment":
  28396. return "]>";
  28397. case "element":
  28398. if (node.condition) {
  28399. return `><!--<![endif]-->`;
  28400. }
  28401. // fall through
  28402. default:
  28403. return `>`;
  28404. }
  28405. }
  28406. function printClosingTagStartMarker(node, options) {
  28407. assert(!node.isSelfClosing);
  28408. if (shouldNotPrintClosingTag(node, options)) {
  28409. return "";
  28410. }
  28411. switch (node.type) {
  28412. case "ieConditionalComment":
  28413. return "<!";
  28414. case "element":
  28415. if (node.hasHtmComponentClosingTag) {
  28416. return "<//";
  28417. }
  28418. // fall through
  28419. default:
  28420. return `</${node.rawName}`;
  28421. }
  28422. }
  28423. function printClosingTagEndMarker(node, options) {
  28424. if (shouldNotPrintClosingTag(node, options)) {
  28425. return "";
  28426. }
  28427. switch (node.type) {
  28428. case "ieConditionalComment":
  28429. case "ieConditionalEndComment":
  28430. return `[endif]-->`;
  28431. case "ieConditionalStartComment":
  28432. return `]><!-->`;
  28433. case "interpolation":
  28434. return "}}";
  28435. case "element":
  28436. if (node.isSelfClosing) {
  28437. return "/>";
  28438. }
  28439. // fall through
  28440. default:
  28441. return ">";
  28442. }
  28443. }
  28444. function getTextValueParts(node) {
  28445. var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : node.value;
  28446. return node.parent.isWhitespaceSensitive ? node.parent.isIndentationSensitive ? replaceEndOfLineWith$2(value, literalline$6) : replaceEndOfLineWith$2(dedentString(value.replace(/^\s*?\n|\n\s*?$/g, "")), hardline$12) : // https://infra.spec.whatwg.org/#ascii-whitespace
  28447. join$10(line$9, value.split(/[\t\n\f\r ]+/)).parts;
  28448. }
  28449. function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
  28450. var isKeyMatched = function isKeyMatched(patterns) {
  28451. return new RegExp(patterns.join("|")).test(node.fullName);
  28452. };
  28453. var getValue = function getValue() {
  28454. return unescapeQuoteEntities(node.value);
  28455. };
  28456. var shouldHug = false;
  28457. var __onHtmlBindingRoot = function __onHtmlBindingRoot(root) {
  28458. var rootNode = root.type === "NGRoot" ? root.node.type === "NGMicrosyntax" && root.node.body.length === 1 && root.node.body[0].type === "NGMicrosyntaxExpression" ? root.node.body[0].expression : root.node : root.type === "JsExpressionRoot" ? root.node : root;
  28459. if (rootNode && (rootNode.type === "ObjectExpression" || rootNode.type === "ArrayExpression")) {
  28460. shouldHug = true;
  28461. }
  28462. };
  28463. var printHug = function printHug(doc$$2) {
  28464. return group$14(doc$$2);
  28465. };
  28466. var printExpand = function printExpand(doc$$2) {
  28467. return group$14(concat$14([indent$9(concat$14([softline$7, doc$$2])), softline$7]));
  28468. };
  28469. var printMaybeHug = function printMaybeHug(doc$$2) {
  28470. return shouldHug ? printHug(doc$$2) : printExpand(doc$$2);
  28471. };
  28472. var textToDoc = function textToDoc(code, opts) {
  28473. return originalTextToDoc(code, Object.assign({
  28474. __onHtmlBindingRoot
  28475. }, opts));
  28476. };
  28477. if (node.fullName === "srcset" && (node.parent.fullName === "img" || node.parent.fullName === "source")) {
  28478. return printExpand(printImgSrcset(getValue()));
  28479. }
  28480. if (options.parser === "vue") {
  28481. if (node.fullName === "v-for") {
  28482. return printVueFor(getValue(), textToDoc);
  28483. }
  28484. if (node.fullName === "slot-scope") {
  28485. return printVueSlotScope(getValue(), textToDoc);
  28486. }
  28487. /**
  28488. * @click="jsStatement"
  28489. * @click="jsExpression"
  28490. * v-on:click="jsStatement"
  28491. * v-on:click="jsExpression"
  28492. */
  28493. var vueEventBindingPatterns = ["^@", "^v-on:"];
  28494. /**
  28495. * :class="vueExpression"
  28496. * v-bind:id="vueExpression"
  28497. */
  28498. var vueExpressionBindingPatterns = ["^:", "^v-bind:"];
  28499. /**
  28500. * v-if="jsExpression"
  28501. */
  28502. var jsExpressionBindingPatterns = ["^v-"];
  28503. if (isKeyMatched(vueEventBindingPatterns)) {
  28504. var value = getValue();
  28505. return printMaybeHug(isVueEventBindingExpression$2(value) ? textToDoc(value, {
  28506. parser: "__js_expression"
  28507. }) : stripTrailingHardline$2(textToDoc(value, {
  28508. parser: "__vue_event_binding"
  28509. })));
  28510. }
  28511. if (isKeyMatched(vueExpressionBindingPatterns)) {
  28512. return printMaybeHug(textToDoc(getValue(), {
  28513. parser: "__vue_expression"
  28514. }));
  28515. }
  28516. if (isKeyMatched(jsExpressionBindingPatterns)) {
  28517. return printMaybeHug(textToDoc(getValue(), {
  28518. parser: "__js_expression"
  28519. }));
  28520. }
  28521. }
  28522. if (options.parser === "angular") {
  28523. var ngTextToDoc = function ngTextToDoc(code, opts) {
  28524. return (// angular does not allow trailing comma
  28525. textToDoc(code, Object.assign({
  28526. trailingComma: "none"
  28527. }, opts))
  28528. );
  28529. };
  28530. /**
  28531. * *directive="angularDirective"
  28532. */
  28533. var ngDirectiveBindingPatterns = ["^\\*"];
  28534. /**
  28535. * (click)="angularStatement"
  28536. * on-click="angularStatement"
  28537. */
  28538. var ngStatementBindingPatterns = ["^\\(.+\\)$", "^on-"];
  28539. /**
  28540. * [target]="angularExpression"
  28541. * bind-target="angularExpression"
  28542. * [(target)]="angularExpression"
  28543. * bindon-target="angularExpression"
  28544. */
  28545. var ngExpressionBindingPatterns = ["^\\[.+\\]$", "^bind(on)?-"];
  28546. if (isKeyMatched(ngStatementBindingPatterns)) {
  28547. return printMaybeHug(ngTextToDoc(getValue(), {
  28548. parser: "__ng_action"
  28549. }));
  28550. }
  28551. if (isKeyMatched(ngExpressionBindingPatterns)) {
  28552. return printMaybeHug(ngTextToDoc(getValue(), {
  28553. parser: "__ng_binding"
  28554. }));
  28555. }
  28556. if (isKeyMatched(ngDirectiveBindingPatterns)) {
  28557. return printMaybeHug(ngTextToDoc(getValue(), {
  28558. parser: "__ng_directive"
  28559. }));
  28560. }
  28561. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  28562. var _value2 = getValue();
  28563. if (interpolationRegex.test(_value2)) {
  28564. var parts = [];
  28565. _value2.split(interpolationRegex).forEach(function (part, index) {
  28566. if (index % 2 === 0) {
  28567. parts.push(concat$14(replaceEndOfLineWith$2(part, literalline$6)));
  28568. } else {
  28569. try {
  28570. parts.push(group$14(concat$14(["{{", indent$9(concat$14([line$9, ngTextToDoc(part, {
  28571. parser: "__ng_interpolation",
  28572. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  28573. })])), line$9, "}}"])));
  28574. } catch (e) {
  28575. parts.push("{{", concat$14(replaceEndOfLineWith$2(part, literalline$6)), "}}");
  28576. }
  28577. }
  28578. });
  28579. return group$14(concat$14(parts));
  28580. }
  28581. }
  28582. return null;
  28583. }
  28584. var printerHtml = {
  28585. preprocess: preprocess_1$4,
  28586. print: genericPrint$5,
  28587. insertPragma: insertPragma$6,
  28588. massageAstNode: clean$8,
  28589. embed: embed$6
  28590. };
  28591. var CATEGORY_HTML = "HTML"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  28592. var options$15 = {
  28593. htmlWhitespaceSensitivity: {
  28594. since: "1.15.0",
  28595. category: CATEGORY_HTML,
  28596. type: "choice",
  28597. default: "css",
  28598. description: "How to handle whitespaces in HTML.",
  28599. choices: [{
  28600. value: "css",
  28601. description: "Respect the default value of CSS display property."
  28602. }, {
  28603. value: "strict",
  28604. description: "Whitespaces are considered sensitive."
  28605. }, {
  28606. value: "ignore",
  28607. description: "Whitespaces are considered insensitive."
  28608. }]
  28609. }
  28610. };
  28611. var name$14 = "HTML";
  28612. var type$13 = "markup";
  28613. var tmScope$13 = "text.html.basic";
  28614. var aceMode$13 = "html";
  28615. var codemirrorMode$10 = "htmlmixed";
  28616. var codemirrorMimeType$10 = "text/html";
  28617. var color$3 = "#e34c26";
  28618. var aliases$5 = ["xhtml"];
  28619. var extensions$13 = [".html", ".htm", ".html.hl", ".inc", ".st", ".xht", ".xhtml"];
  28620. var languageId$13 = 146;
  28621. var html$1 = {
  28622. name: name$14,
  28623. type: type$13,
  28624. tmScope: tmScope$13,
  28625. aceMode: aceMode$13,
  28626. codemirrorMode: codemirrorMode$10,
  28627. codemirrorMimeType: codemirrorMimeType$10,
  28628. color: color$3,
  28629. aliases: aliases$5,
  28630. extensions: extensions$13,
  28631. languageId: languageId$13
  28632. };
  28633. var html$2 = Object.freeze({
  28634. name: name$14,
  28635. type: type$13,
  28636. tmScope: tmScope$13,
  28637. aceMode: aceMode$13,
  28638. codemirrorMode: codemirrorMode$10,
  28639. codemirrorMimeType: codemirrorMimeType$10,
  28640. color: color$3,
  28641. aliases: aliases$5,
  28642. extensions: extensions$13,
  28643. languageId: languageId$13,
  28644. default: html$1
  28645. });
  28646. var name$15 = "Vue";
  28647. var type$14 = "markup";
  28648. var color$4 = "#2c3e50";
  28649. var extensions$14 = [".vue"];
  28650. var tmScope$14 = "text.html.vue";
  28651. var aceMode$14 = "html";
  28652. var languageId$14 = 391;
  28653. var vue = {
  28654. name: name$15,
  28655. type: type$14,
  28656. color: color$4,
  28657. extensions: extensions$14,
  28658. tmScope: tmScope$14,
  28659. aceMode: aceMode$14,
  28660. languageId: languageId$14
  28661. };
  28662. var vue$1 = Object.freeze({
  28663. name: name$15,
  28664. type: type$14,
  28665. color: color$4,
  28666. extensions: extensions$14,
  28667. tmScope: tmScope$14,
  28668. aceMode: aceMode$14,
  28669. languageId: languageId$14,
  28670. default: vue
  28671. });
  28672. var require$$0$31 = ( html$2 && html$1 ) || html$2;
  28673. var require$$1$10 = ( vue$1 && vue ) || vue$1;
  28674. var languages$5 = [createLanguage(require$$0$31, {
  28675. override: {
  28676. name: "Angular",
  28677. since: "1.15.0",
  28678. parsers: ["angular"],
  28679. vscodeLanguageIds: ["html"],
  28680. extensions: [".component.html"],
  28681. filenames: []
  28682. }
  28683. }), createLanguage(require$$0$31, {
  28684. override: {
  28685. since: "1.15.0",
  28686. parsers: ["html"],
  28687. vscodeLanguageIds: ["html"]
  28688. },
  28689. extend: {
  28690. extensions: [".mjml" // MJML is considered XML in Linguist but it should be formatted as HTML
  28691. ]
  28692. }
  28693. }), createLanguage(require$$0$31, {
  28694. override: {
  28695. name: "Lightning Web Components",
  28696. since: "1.17.0",
  28697. parsers: ["lwc"],
  28698. vscodeLanguageIds: ["html"],
  28699. extensions: [],
  28700. filenames: []
  28701. }
  28702. }), createLanguage(require$$1$10, {
  28703. override: {
  28704. since: "1.10.0",
  28705. parsers: ["vue"],
  28706. vscodeLanguageIds: ["vue"]
  28707. }
  28708. })];
  28709. var printers$5 = {
  28710. html: printerHtml
  28711. };
  28712. var languageHtml = {
  28713. languages: languages$5,
  28714. printers: printers$5,
  28715. options: options$15
  28716. };
  28717. function isPragma$1(text) {
  28718. return /^\s*@(prettier|format)\s*$/.test(text);
  28719. }
  28720. function hasPragma$4(text) {
  28721. return /^\s*#[^\n\S]*@(prettier|format)\s*?(\n|$)/.test(text);
  28722. }
  28723. function insertPragma$9(text) {
  28724. return `# @format\n\n${text}`;
  28725. }
  28726. var pragma$11 = {
  28727. isPragma: isPragma$1,
  28728. hasPragma: hasPragma$4,
  28729. insertPragma: insertPragma$9
  28730. };
  28731. var getLast$6 = util$1.getLast;
  28732. function getAncestorCount$1(path$$1, filter) {
  28733. var counter = 0;
  28734. var pathStackLength = path$$1.stack.length - 1;
  28735. for (var i = 0; i < pathStackLength; i++) {
  28736. var value = path$$1.stack[i];
  28737. if (isNode$2(value) && filter(value)) {
  28738. counter++;
  28739. }
  28740. }
  28741. return counter;
  28742. }
  28743. /**
  28744. * @param {any} value
  28745. * @param {string[]=} types
  28746. */
  28747. function isNode$2(value, types) {
  28748. return value && typeof value.type === "string" && (!types || types.indexOf(value.type) !== -1);
  28749. }
  28750. function mapNode$1(node, callback, parent) {
  28751. return callback("children" in node ? Object.assign({}, node, {
  28752. children: node.children.map(function (childNode) {
  28753. return mapNode$1(childNode, callback, node);
  28754. })
  28755. }) : node, parent);
  28756. }
  28757. function defineShortcut$1(x, key, getter) {
  28758. Object.defineProperty(x, key, {
  28759. get: getter,
  28760. enumerable: false
  28761. });
  28762. }
  28763. function isNextLineEmpty$6(node, text) {
  28764. var newlineCount = 0;
  28765. var textLength = text.length;
  28766. for (var i = node.position.end.offset - 1; i < textLength; i++) {
  28767. var char = text[i];
  28768. if (char === "\n") {
  28769. newlineCount++;
  28770. }
  28771. if (newlineCount === 1 && /\S/.test(char)) {
  28772. return false;
  28773. }
  28774. if (newlineCount === 2) {
  28775. return true;
  28776. }
  28777. }
  28778. return false;
  28779. }
  28780. function isLastDescendantNode$1(path$$1) {
  28781. var node = path$$1.getValue();
  28782. switch (node.type) {
  28783. case "tag":
  28784. case "anchor":
  28785. case "comment":
  28786. return false;
  28787. }
  28788. var pathStackLength = path$$1.stack.length;
  28789. for (var i = 1; i < pathStackLength; i++) {
  28790. var item = path$$1.stack[i];
  28791. var parentItem = path$$1.stack[i - 1];
  28792. if (Array.isArray(parentItem) && typeof item === "number" && item !== parentItem.length - 1) {
  28793. return false;
  28794. }
  28795. }
  28796. return true;
  28797. }
  28798. function getLastDescendantNode$2(node) {
  28799. return "children" in node && node.children.length !== 0 ? getLastDescendantNode$2(getLast$6(node.children)) : node;
  28800. }
  28801. function isPrettierIgnore$2(comment) {
  28802. return comment.value.trim() === "prettier-ignore";
  28803. }
  28804. function hasPrettierIgnore$5(path$$1) {
  28805. var node = path$$1.getValue();
  28806. if (node.type === "documentBody") {
  28807. var document = path$$1.getParentNode();
  28808. return hasEndComments$1(document.head) && isPrettierIgnore$2(getLast$6(document.head.endComments));
  28809. }
  28810. return hasLeadingComments$1(node) && isPrettierIgnore$2(getLast$6(node.leadingComments));
  28811. }
  28812. function isEmptyNode$1(node) {
  28813. return (!node.children || node.children.length === 0) && !hasComments(node);
  28814. }
  28815. function hasComments(node) {
  28816. return hasLeadingComments$1(node) || hasMiddleComments$1(node) || hasIndicatorComment$1(node) || hasTrailingComment$2(node) || hasEndComments$1(node);
  28817. }
  28818. function hasLeadingComments$1(node) {
  28819. return node && node.leadingComments && node.leadingComments.length !== 0;
  28820. }
  28821. function hasMiddleComments$1(node) {
  28822. return node && node.middleComments && node.middleComments.length !== 0;
  28823. }
  28824. function hasIndicatorComment$1(node) {
  28825. return node && node.indicatorComment;
  28826. }
  28827. function hasTrailingComment$2(node) {
  28828. return node && node.trailingComment;
  28829. }
  28830. function hasEndComments$1(node) {
  28831. return node && node.endComments && node.endComments.length !== 0;
  28832. }
  28833. /**
  28834. * " a b c d e f " -> [" a b", "c d", "e f "]
  28835. */
  28836. function splitWithSingleSpace(text) {
  28837. var parts = [];
  28838. var lastPart = undefined;
  28839. var _iteratorNormalCompletion = true;
  28840. var _didIteratorError = false;
  28841. var _iteratorError = undefined;
  28842. try {
  28843. for (var _iterator = text.split(/( +)/g)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  28844. var part = _step.value;
  28845. if (part !== " ") {
  28846. if (lastPart === " ") {
  28847. parts.push(part);
  28848. } else {
  28849. parts.push((parts.pop() || "") + part);
  28850. }
  28851. } else if (lastPart === undefined) {
  28852. parts.unshift("");
  28853. }
  28854. lastPart = part;
  28855. }
  28856. } catch (err) {
  28857. _didIteratorError = true;
  28858. _iteratorError = err;
  28859. } finally {
  28860. try {
  28861. if (!_iteratorNormalCompletion && _iterator.return != null) {
  28862. _iterator.return();
  28863. }
  28864. } finally {
  28865. if (_didIteratorError) {
  28866. throw _iteratorError;
  28867. }
  28868. }
  28869. }
  28870. if (lastPart === " ") {
  28871. parts.push((parts.pop() || "") + " ");
  28872. }
  28873. if (parts[0] === "") {
  28874. parts.shift();
  28875. parts.unshift(" " + (parts.shift() || ""));
  28876. }
  28877. return parts;
  28878. }
  28879. function getFlowScalarLineContents$1(nodeType, content, options) {
  28880. var rawLineContents = content.split("\n").map(function (lineContent, index, lineContents) {
  28881. return index === 0 && index === lineContents.length - 1 ? lineContent : index !== 0 && index !== lineContents.length - 1 ? lineContent.trim() : index === 0 ? lineContent.trimRight() : lineContent.trimLeft();
  28882. });
  28883. if (options.proseWrap === "preserve") {
  28884. return rawLineContents.map(function (lineContent) {
  28885. return lineContent.length === 0 ? [] : [lineContent];
  28886. });
  28887. }
  28888. return rawLineContents.map(function (lineContent) {
  28889. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  28890. }).reduce(function (reduced, lineContentWords, index) {
  28891. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !( // trailing backslash in quoteDouble should be preserved
  28892. nodeType === "quoteDouble" && getLast$6(getLast$6(reduced)).endsWith("\\")) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  28893. }, []).map(function (lineContentWords) {
  28894. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  28895. });
  28896. }
  28897. function getBlockValueLineContents$1(node, _ref) {
  28898. var parentIndent = _ref.parentIndent,
  28899. isLastDescendant = _ref.isLastDescendant,
  28900. options = _ref.options;
  28901. var content = node.position.start.line === node.position.end.line ? "" : options.originalText.slice(node.position.start.offset, node.position.end.offset) // exclude open line `>` or `|`
  28902. .match(/^[^\n]*?\n([\s\S]*)$/)[1];
  28903. var leadingSpaceCount = node.indent === null ? function (match) {
  28904. return match ? match[1].length : Infinity;
  28905. }(content.match(/^( *)\S/m)) : node.indent - 1 + parentIndent;
  28906. var rawLineContents = content.split("\n").map(function (lineContent) {
  28907. return lineContent.slice(leadingSpaceCount);
  28908. });
  28909. if (options.proseWrap === "preserve" || node.type === "blockLiteral") {
  28910. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  28911. return lineContent.length === 0 ? [] : [lineContent];
  28912. }));
  28913. }
  28914. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  28915. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  28916. }).reduce(function (reduced, lineContentWords, index) {
  28917. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !/^\s/.test(lineContentWords[0]) && !/^\s|\s$/.test(getLast$6(reduced)) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  28918. }, []).map(function (lineContentWords) {
  28919. return lineContentWords.reduce(function (reduced, word) {
  28920. return (// disallow trailing spaces
  28921. reduced.length !== 0 && /\s$/.test(getLast$6(reduced)) ? reduced.concat(reduced.pop() + " " + word) : reduced.concat(word)
  28922. );
  28923. }, []);
  28924. }).map(function (lineContentWords) {
  28925. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  28926. }));
  28927. function removeUnnecessaryTrailingNewlines(lineContents) {
  28928. if (node.chomping === "keep") {
  28929. return getLast$6(lineContents).length === 0 ? lineContents.slice(0, -1) : lineContents;
  28930. }
  28931. var trailingNewlineCount = 0;
  28932. for (var i = lineContents.length - 1; i >= 0; i--) {
  28933. if (lineContents[i].length === 0) {
  28934. trailingNewlineCount++;
  28935. } else {
  28936. break;
  28937. }
  28938. }
  28939. return trailingNewlineCount === 0 ? lineContents : trailingNewlineCount >= 2 && !isLastDescendant ? // next empty line
  28940. lineContents.slice(0, -(trailingNewlineCount - 1)) : lineContents.slice(0, -trailingNewlineCount);
  28941. }
  28942. }
  28943. var utils$12 = {
  28944. getLast: getLast$6,
  28945. getAncestorCount: getAncestorCount$1,
  28946. isNode: isNode$2,
  28947. isEmptyNode: isEmptyNode$1,
  28948. mapNode: mapNode$1,
  28949. defineShortcut: defineShortcut$1,
  28950. isNextLineEmpty: isNextLineEmpty$6,
  28951. isLastDescendantNode: isLastDescendantNode$1,
  28952. getBlockValueLineContents: getBlockValueLineContents$1,
  28953. getFlowScalarLineContents: getFlowScalarLineContents$1,
  28954. getLastDescendantNode: getLastDescendantNode$2,
  28955. hasPrettierIgnore: hasPrettierIgnore$5,
  28956. hasLeadingComments: hasLeadingComments$1,
  28957. hasMiddleComments: hasMiddleComments$1,
  28958. hasIndicatorComment: hasIndicatorComment$1,
  28959. hasTrailingComment: hasTrailingComment$2,
  28960. hasEndComments: hasEndComments$1
  28961. };
  28962. var insertPragma$8 = pragma$11.insertPragma;
  28963. var isPragma = pragma$11.isPragma;
  28964. var getAncestorCount = utils$12.getAncestorCount;
  28965. var getBlockValueLineContents = utils$12.getBlockValueLineContents;
  28966. var getFlowScalarLineContents = utils$12.getFlowScalarLineContents;
  28967. var getLast$5 = utils$12.getLast;
  28968. var getLastDescendantNode$1 = utils$12.getLastDescendantNode;
  28969. var hasLeadingComments = utils$12.hasLeadingComments;
  28970. var hasMiddleComments = utils$12.hasMiddleComments;
  28971. var hasIndicatorComment = utils$12.hasIndicatorComment;
  28972. var hasTrailingComment$1 = utils$12.hasTrailingComment;
  28973. var hasEndComments = utils$12.hasEndComments;
  28974. var hasPrettierIgnore$4 = utils$12.hasPrettierIgnore;
  28975. var isLastDescendantNode = utils$12.isLastDescendantNode;
  28976. var isNextLineEmpty$5 = utils$12.isNextLineEmpty;
  28977. var isNode$1 = utils$12.isNode;
  28978. var isEmptyNode = utils$12.isEmptyNode;
  28979. var defineShortcut = utils$12.defineShortcut;
  28980. var mapNode = utils$12.mapNode;
  28981. var docBuilders$3 = doc.builders;
  28982. var conditionalGroup$2 = docBuilders$3.conditionalGroup;
  28983. var breakParent$5 = docBuilders$3.breakParent;
  28984. var concat$17 = docBuilders$3.concat;
  28985. var dedent$4 = docBuilders$3.dedent;
  28986. var dedentToRoot$3 = docBuilders$3.dedentToRoot;
  28987. var fill$6 = docBuilders$3.fill;
  28988. var group$16 = docBuilders$3.group;
  28989. var hardline$13 = docBuilders$3.hardline;
  28990. var ifBreak$8 = docBuilders$3.ifBreak;
  28991. var join$12 = docBuilders$3.join;
  28992. var line$11 = docBuilders$3.line;
  28993. var lineSuffix$2 = docBuilders$3.lineSuffix;
  28994. var literalline$7 = docBuilders$3.literalline;
  28995. var markAsRoot$5 = docBuilders$3.markAsRoot;
  28996. var softline$8 = docBuilders$3.softline;
  28997. var replaceEndOfLineWith$3 = util$1.replaceEndOfLineWith;
  28998. function preprocess$6(ast) {
  28999. return mapNode(ast, defineShortcuts);
  29000. }
  29001. function defineShortcuts(node) {
  29002. switch (node.type) {
  29003. case "document":
  29004. defineShortcut(node, "head", function () {
  29005. return node.children[0];
  29006. });
  29007. defineShortcut(node, "body", function () {
  29008. return node.children[1];
  29009. });
  29010. break;
  29011. case "documentBody":
  29012. case "sequenceItem":
  29013. case "flowSequenceItem":
  29014. case "mappingKey":
  29015. case "mappingValue":
  29016. defineShortcut(node, "content", function () {
  29017. return node.children[0];
  29018. });
  29019. break;
  29020. case "mappingItem":
  29021. case "flowMappingItem":
  29022. defineShortcut(node, "key", function () {
  29023. return node.children[0];
  29024. });
  29025. defineShortcut(node, "value", function () {
  29026. return node.children[1];
  29027. });
  29028. break;
  29029. }
  29030. return node;
  29031. }
  29032. function genericPrint$6(path$$1, options, print) {
  29033. var node = path$$1.getValue();
  29034. var parentNode = path$$1.getParentNode();
  29035. var tag = !node.tag ? "" : path$$1.call(print, "tag");
  29036. var anchor = !node.anchor ? "" : path$$1.call(print, "anchor");
  29037. var nextEmptyLine = isNode$1(node, ["mapping", "sequence", "comment", "directive", "mappingItem", "sequenceItem"]) && !isLastDescendantNode(path$$1) ? printNextEmptyLine(path$$1, options.originalText) : "";
  29038. return concat$17([node.type !== "mappingValue" && hasLeadingComments(node) ? concat$17([join$12(hardline$13, path$$1.map(print, "leadingComments")), hardline$13]) : "", tag, tag && anchor ? " " : "", anchor, tag || anchor ? isNode$1(node, ["sequence", "mapping"]) && !hasMiddleComments(node) ? hardline$13 : " " : "", hasMiddleComments(node) ? concat$17([node.middleComments.length === 1 ? "" : hardline$13, join$12(hardline$13, path$$1.map(print, "middleComments")), hardline$13]) : "", hasPrettierIgnore$4(path$$1) ? concat$17(replaceEndOfLineWith$3(options.originalText.slice(node.position.start.offset, node.position.end.offset), literalline$7)) : group$16(_print(node, parentNode, path$$1, options, print)), hasTrailingComment$1(node) && !isNode$1(node, ["document", "documentHead"]) ? lineSuffix$2(concat$17([node.type === "mappingValue" && !node.content ? "" : " ", parentNode.type === "mappingKey" && path$$1.getParentNode(2).type === "mapping" && isInlineNode(node) ? "" : breakParent$5, path$$1.call(print, "trailingComment")])) : "", nextEmptyLine, hasEndComments(node) && !isNode$1(node, ["documentHead", "documentBody"]) ? align$3(node.type === "sequenceItem" ? 2 : 0, concat$17([hardline$13, join$12(hardline$13, path$$1.map(print, "endComments"))])) : ""]);
  29039. }
  29040. function _print(node, parentNode, path$$1, options, print) {
  29041. switch (node.type) {
  29042. case "root":
  29043. return concat$17([join$12(hardline$13, path$$1.map(function (childPath, index) {
  29044. var document = node.children[index];
  29045. var nextDocument = node.children[index + 1];
  29046. return concat$17([print(childPath), shouldPrintDocumentEndMarker(document, nextDocument) ? concat$17([hardline$13, "...", hasTrailingComment$1(document) ? concat$17([" ", path$$1.call(print, "trailingComment")]) : ""]) : !nextDocument || hasTrailingComment$1(nextDocument.head) ? "" : concat$17([hardline$13, "---"])]);
  29047. }, "children")), node.children.length === 0 || function (lastDescendantNode) {
  29048. return isNode$1(lastDescendantNode, ["blockLiteral", "blockFolded"]) && lastDescendantNode.chomping === "keep";
  29049. }(getLastDescendantNode$1(node)) ? "" : hardline$13]);
  29050. case "document":
  29051. {
  29052. var nextDocument = parentNode.children[path$$1.getName() + 1];
  29053. return join$12(hardline$13, [shouldPrintDocumentHeadEndMarker(node, nextDocument, parentNode, options) === "head" ? join$12(hardline$13, [node.head.children.length === 0 && node.head.endComments.length === 0 ? "" : path$$1.call(print, "head"), concat$17(["---", hasTrailingComment$1(node.head) ? concat$17([" ", path$$1.call(print, "head", "trailingComment")]) : ""])].filter(Boolean)) : "", shouldPrintDocumentBody(node) ? path$$1.call(print, "body") : ""].filter(Boolean));
  29054. }
  29055. case "documentHead":
  29056. return join$12(hardline$13, [].concat(path$$1.map(print, "children"), path$$1.map(print, "endComments")));
  29057. case "documentBody":
  29058. {
  29059. var children = join$12(hardline$13, path$$1.map(print, "children")).parts;
  29060. var endComments = join$12(hardline$13, path$$1.map(print, "endComments")).parts;
  29061. var separator = children.length === 0 || endComments.length === 0 ? "" : function (lastDescendantNode) {
  29062. return isNode$1(lastDescendantNode, ["blockFolded", "blockLiteral"]) ? lastDescendantNode.chomping === "keep" ? // there's already a newline printed at the end of blockValue (chomping=keep, lastDescendant=true)
  29063. "" : // an extra newline for better readability
  29064. concat$17([hardline$13, hardline$13]) : hardline$13;
  29065. }(getLastDescendantNode$1(node));
  29066. return concat$17([].concat(children, separator, endComments));
  29067. }
  29068. case "directive":
  29069. return concat$17(["%", join$12(" ", [node.name].concat(node.parameters))]);
  29070. case "comment":
  29071. return concat$17(["#", node.value]);
  29072. case "alias":
  29073. return concat$17(["*", node.value]);
  29074. case "tag":
  29075. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  29076. case "anchor":
  29077. return concat$17(["&", node.value]);
  29078. case "plain":
  29079. return printFlowScalarContent(node.type, options.originalText.slice(node.position.start.offset, node.position.end.offset), options);
  29080. case "quoteDouble":
  29081. case "quoteSingle":
  29082. {
  29083. var singleQuote = "'";
  29084. var doubleQuote = '"';
  29085. var raw = options.originalText.slice(node.position.start.offset + 1, node.position.end.offset - 1);
  29086. if (node.type === "quoteSingle" && raw.includes("\\") || node.type === "quoteDouble" && /\\[^"]/.test(raw)) {
  29087. // only quoteDouble can use escape chars
  29088. // and quoteSingle do not need to escape backslashes
  29089. var originalQuote = node.type === "quoteDouble" ? doubleQuote : singleQuote;
  29090. return concat$17([originalQuote, printFlowScalarContent(node.type, raw, options), originalQuote]);
  29091. } else if (raw.includes(doubleQuote)) {
  29092. return concat$17([singleQuote, printFlowScalarContent(node.type, node.type === "quoteDouble" ? raw // double quote needs to be escaped by backslash in quoteDouble
  29093. .replace(/\\"/g, doubleQuote).replace(/'/g, singleQuote.repeat(2)) : raw, options), singleQuote]);
  29094. }
  29095. if (raw.includes(singleQuote)) {
  29096. return concat$17([doubleQuote, printFlowScalarContent(node.type, node.type === "quoteSingle" ? // single quote needs to be escaped by 2 single quotes in quoteSingle
  29097. raw.replace(/''/g, singleQuote) : raw, options), doubleQuote]);
  29098. }
  29099. var quote = options.singleQuote ? singleQuote : doubleQuote;
  29100. return concat$17([quote, printFlowScalarContent(node.type, raw, options), quote]);
  29101. }
  29102. case "blockFolded":
  29103. case "blockLiteral":
  29104. {
  29105. var parentIndent = getAncestorCount(path$$1, function (ancestorNode) {
  29106. return isNode$1(ancestorNode, ["sequence", "mapping"]);
  29107. });
  29108. var isLastDescendant = isLastDescendantNode(path$$1);
  29109. return concat$17([node.type === "blockFolded" ? ">" : "|", node.indent === null ? "" : node.indent.toString(), node.chomping === "clip" ? "" : node.chomping === "keep" ? "+" : "-", hasIndicatorComment(node) ? concat$17([" ", path$$1.call(print, "indicatorComment")]) : "", (node.indent === null ? dedent$4 : dedentToRoot$3)(align$3(node.indent === null ? options.tabWidth : node.indent - 1 + parentIndent, concat$17(getBlockValueLineContents(node, {
  29110. parentIndent,
  29111. isLastDescendant,
  29112. options
  29113. }).reduce(function (reduced, lineWords, index, lineContents) {
  29114. return reduced.concat(index === 0 ? hardline$13 : "", fill$6(join$12(line$11, lineWords).parts), index !== lineContents.length - 1 ? lineWords.length === 0 ? hardline$13 : markAsRoot$5(literalline$7) : node.chomping === "keep" && isLastDescendant ? lineWords.length === 0 ? dedentToRoot$3(hardline$13) : dedentToRoot$3(literalline$7) : "");
  29115. }, []))))]);
  29116. }
  29117. case "sequence":
  29118. return join$12(hardline$13, path$$1.map(print, "children"));
  29119. case "sequenceItem":
  29120. return concat$17(["- ", align$3(2, !node.content ? "" : path$$1.call(print, "content"))]);
  29121. case "mappingKey":
  29122. return !node.content ? "" : path$$1.call(print, "content");
  29123. case "mappingValue":
  29124. return !node.content ? "" : path$$1.call(print, "content");
  29125. case "mapping":
  29126. return join$12(hardline$13, path$$1.map(print, "children"));
  29127. case "mappingItem":
  29128. case "flowMappingItem":
  29129. {
  29130. var isEmptyMappingKey = isEmptyNode(node.key);
  29131. var isEmptyMappingValue = isEmptyNode(node.value);
  29132. if (isEmptyMappingKey && isEmptyMappingValue) {
  29133. return concat$17([": "]);
  29134. }
  29135. var key = path$$1.call(print, "key");
  29136. var value = path$$1.call(print, "value");
  29137. if (isEmptyMappingValue) {
  29138. return node.type === "flowMappingItem" && parentNode.type === "flowMapping" ? key : node.type === "mappingItem" && isAbsolutelyPrintedAsSingleLineNode(node.key.content, options) && !hasTrailingComment$1(node.key.content) && (!parentNode.tag || parentNode.tag.value !== "tag:yaml.org,2002:set") ? concat$17([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ":"]) : concat$17(["? ", align$3(2, key)]);
  29139. }
  29140. if (isEmptyMappingKey) {
  29141. return concat$17([": ", align$3(2, value)]);
  29142. }
  29143. var groupId = Symbol("mappingKey");
  29144. var forceExplicitKey = hasLeadingComments(node.value) || !isInlineNode(node.key.content);
  29145. return forceExplicitKey ? concat$17(["? ", align$3(2, key), hardline$13, join$12("", path$$1.map(print, "value", "leadingComments").map(function (comment) {
  29146. return concat$17([comment, hardline$13]);
  29147. })), ": ", align$3(2, value)]) : // force singleline
  29148. isSingleLineNode(node.key.content) && !hasLeadingComments(node.key.content) && !hasMiddleComments(node.key.content) && !hasTrailingComment$1(node.key.content) && !hasEndComments(node.key) && !hasLeadingComments(node.value.content) && !hasMiddleComments(node.value.content) && !hasEndComments(node.value) && isAbsolutelyPrintedAsSingleLineNode(node.value.content, options) ? concat$17([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ": ", value]) : conditionalGroup$2([concat$17([group$16(concat$17([ifBreak$8("? "), group$16(align$3(2, key), {
  29149. id: groupId
  29150. })])), ifBreak$8(concat$17([hardline$13, ": ", align$3(2, value)]), indent(concat$17([needsSpaceInFrontOfMappingValue(node) ? " " : "", ":", hasLeadingComments(node.value.content) || hasEndComments(node.value) && node.value.content && !isNode$1(node.value.content, ["mapping", "sequence"]) || parentNode.type === "mapping" && hasTrailingComment$1(node.key.content) && isInlineNode(node.value.content) || isNode$1(node.value.content, ["mapping", "sequence"]) && node.value.content.tag === null && node.value.content.anchor === null ? hardline$13 : !node.value.content ? "" : line$11, value])), {
  29151. groupId
  29152. })])]);
  29153. }
  29154. case "flowMapping":
  29155. case "flowSequence":
  29156. {
  29157. var openMarker = node.type === "flowMapping" ? "{" : "[";
  29158. var closeMarker = node.type === "flowMapping" ? "}" : "]";
  29159. var bracketSpacing = node.type === "flowMapping" && node.children.length !== 0 && options.bracketSpacing ? line$11 : softline$8;
  29160. var isLastItemEmptyMappingItem = node.children.length !== 0 && function (lastItem) {
  29161. return lastItem.type === "flowMappingItem" && isEmptyNode(lastItem.key) && isEmptyNode(lastItem.value);
  29162. }(getLast$5(node.children));
  29163. return concat$17([openMarker, indent(concat$17([bracketSpacing, concat$17(path$$1.map(function (childPath, index) {
  29164. return concat$17([print(childPath), index === node.children.length - 1 ? "" : concat$17([",", line$11, node.children[index].position.start.line !== node.children[index + 1].position.start.line ? printNextEmptyLine(childPath, options.originalText) : ""])]);
  29165. }, "children")), ifBreak$8(",", "")])), isLastItemEmptyMappingItem ? "" : bracketSpacing, closeMarker]);
  29166. }
  29167. case "flowSequenceItem":
  29168. return path$$1.call(print, "content");
  29169. // istanbul ignore next
  29170. default:
  29171. throw new Error(`Unexpected node type ${node.type}`);
  29172. }
  29173. function indent(doc$$2) {
  29174. return docBuilders$3.align(" ".repeat(options.tabWidth), doc$$2);
  29175. }
  29176. }
  29177. function align$3(n, doc$$2) {
  29178. return typeof n === "number" && n > 0 ? docBuilders$3.align(" ".repeat(n), doc$$2) : docBuilders$3.align(n, doc$$2);
  29179. }
  29180. function isInlineNode(node) {
  29181. if (!node) {
  29182. return true;
  29183. }
  29184. switch (node.type) {
  29185. case "plain":
  29186. case "quoteDouble":
  29187. case "quoteSingle":
  29188. case "alias":
  29189. case "flowMapping":
  29190. case "flowSequence":
  29191. return true;
  29192. default:
  29193. return false;
  29194. }
  29195. }
  29196. function isSingleLineNode(node) {
  29197. if (!node) {
  29198. return true;
  29199. }
  29200. switch (node.type) {
  29201. case "plain":
  29202. case "quoteDouble":
  29203. case "quoteSingle":
  29204. return node.position.start.line === node.position.end.line;
  29205. case "alias":
  29206. return true;
  29207. default:
  29208. return false;
  29209. }
  29210. }
  29211. function shouldPrintDocumentBody(document) {
  29212. return document.body.children.length !== 0 || hasEndComments(document.body);
  29213. }
  29214. function shouldPrintDocumentEndMarker(document, nextDocument) {
  29215. return (
  29216. /**
  29217. *... # trailingComment
  29218. */
  29219. hasTrailingComment$1(document) || nextDocument && (
  29220. /**
  29221. * ...
  29222. * %DIRECTIVE
  29223. * ---
  29224. */
  29225. nextDocument.head.children.length !== 0 ||
  29226. /**
  29227. * ...
  29228. * # endComment
  29229. * ---
  29230. */
  29231. hasEndComments(nextDocument.head))
  29232. );
  29233. }
  29234. function shouldPrintDocumentHeadEndMarker(document, nextDocument, root, options) {
  29235. if (
  29236. /**
  29237. * ---
  29238. * preserve the first document head end marker
  29239. */
  29240. root.children[0] === document && /---(\s|$)/.test(options.originalText.slice(options.locStart(document), options.locStart(document) + 4)) ||
  29241. /**
  29242. * %DIRECTIVE
  29243. * ---
  29244. */
  29245. document.head.children.length !== 0 ||
  29246. /**
  29247. * # end comment
  29248. * ---
  29249. */
  29250. hasEndComments(document.head) ||
  29251. /**
  29252. * --- # trailing comment
  29253. */
  29254. hasTrailingComment$1(document.head)) {
  29255. return "head";
  29256. }
  29257. if (shouldPrintDocumentEndMarker(document, nextDocument)) {
  29258. return false;
  29259. }
  29260. return nextDocument ? "root" : false;
  29261. }
  29262. function isAbsolutelyPrintedAsSingleLineNode(node, options) {
  29263. if (!node) {
  29264. return true;
  29265. }
  29266. switch (node.type) {
  29267. case "plain":
  29268. case "quoteSingle":
  29269. case "quoteDouble":
  29270. break;
  29271. case "alias":
  29272. return true;
  29273. default:
  29274. return false;
  29275. }
  29276. if (options.proseWrap === "preserve") {
  29277. return node.position.start.line === node.position.end.line;
  29278. }
  29279. if ( // backslash-newline
  29280. /\\$/m.test(options.originalText.slice(node.position.start.offset, node.position.end.offset))) {
  29281. return false;
  29282. }
  29283. switch (options.proseWrap) {
  29284. case "never":
  29285. return node.value.indexOf("\n") === -1;
  29286. case "always":
  29287. return !/[\n ]/.test(node.value);
  29288. // istanbul ignore next
  29289. default:
  29290. return false;
  29291. }
  29292. }
  29293. function needsSpaceInFrontOfMappingValue(node) {
  29294. return node.key.content && node.key.content.type === "alias";
  29295. }
  29296. function printNextEmptyLine(path$$1, originalText) {
  29297. var node = path$$1.getValue();
  29298. var root = path$$1.stack[0];
  29299. root.isNextEmptyLinePrintedChecklist = root.isNextEmptyLinePrintedChecklist || [];
  29300. if (!root.isNextEmptyLinePrintedChecklist[node.position.end.line]) {
  29301. if (isNextLineEmpty$5(node, originalText)) {
  29302. root.isNextEmptyLinePrintedChecklist[node.position.end.line] = true;
  29303. return softline$8;
  29304. }
  29305. }
  29306. return "";
  29307. }
  29308. function printFlowScalarContent(nodeType, content, options) {
  29309. var lineContents = getFlowScalarLineContents(nodeType, content, options);
  29310. return join$12(hardline$13, lineContents.map(function (lineContentWords) {
  29311. return fill$6(join$12(line$11, lineContentWords).parts);
  29312. }));
  29313. }
  29314. function clean$11(node, newNode
  29315. /*, parent */
  29316. ) {
  29317. if (isNode$1(newNode)) {
  29318. delete newNode.position;
  29319. switch (newNode.type) {
  29320. case "comment":
  29321. // insert pragma
  29322. if (isPragma(newNode.value)) {
  29323. return null;
  29324. }
  29325. break;
  29326. case "quoteDouble":
  29327. case "quoteSingle":
  29328. newNode.type = "quote";
  29329. break;
  29330. }
  29331. }
  29332. }
  29333. var printerYaml = {
  29334. preprocess: preprocess$6,
  29335. print: genericPrint$6,
  29336. massageAstNode: clean$11,
  29337. insertPragma: insertPragma$8
  29338. };
  29339. var options$18 = {
  29340. bracketSpacing: commonOptions.bracketSpacing,
  29341. singleQuote: commonOptions.singleQuote,
  29342. proseWrap: commonOptions.proseWrap
  29343. };
  29344. var name$16 = "YAML";
  29345. var type$15 = "data";
  29346. var tmScope$15 = "source.yaml";
  29347. var aliases$6 = ["yml"];
  29348. var extensions$15 = [".yml", ".mir", ".reek", ".rviz", ".sublime-syntax", ".syntax", ".yaml", ".yaml-tmlanguage", ".yml.mysql"];
  29349. var filenames$3 = [".clang-format", ".clang-tidy", ".gemrc", "glide.lock"];
  29350. var aceMode$15 = "yaml";
  29351. var codemirrorMode$11 = "yaml";
  29352. var codemirrorMimeType$11 = "text/x-yaml";
  29353. var languageId$15 = 407;
  29354. var yaml = {
  29355. name: name$16,
  29356. type: type$15,
  29357. tmScope: tmScope$15,
  29358. aliases: aliases$6,
  29359. extensions: extensions$15,
  29360. filenames: filenames$3,
  29361. aceMode: aceMode$15,
  29362. codemirrorMode: codemirrorMode$11,
  29363. codemirrorMimeType: codemirrorMimeType$11,
  29364. languageId: languageId$15
  29365. };
  29366. var yaml$1 = Object.freeze({
  29367. name: name$16,
  29368. type: type$15,
  29369. tmScope: tmScope$15,
  29370. aliases: aliases$6,
  29371. extensions: extensions$15,
  29372. filenames: filenames$3,
  29373. aceMode: aceMode$15,
  29374. codemirrorMode: codemirrorMode$11,
  29375. codemirrorMimeType: codemirrorMimeType$11,
  29376. languageId: languageId$15,
  29377. default: yaml
  29378. });
  29379. var require$$0$33 = ( yaml$1 && yaml ) || yaml$1;
  29380. var languages$6 = [createLanguage(require$$0$33, {
  29381. override: {
  29382. since: "1.14.0",
  29383. parsers: ["yaml"],
  29384. vscodeLanguageIds: ["yaml"]
  29385. }
  29386. })];
  29387. var languageYaml = {
  29388. languages: languages$6,
  29389. printers: {
  29390. yaml: printerYaml
  29391. },
  29392. options: options$18
  29393. };
  29394. // plugin will look for `eval("require")()` and transform to `require()` in the bundle,
  29395. // and rewrite the paths to require from the top-level.
  29396. // We need to list the parsers and getters so we can load them only when necessary.
  29397. var internalPlugins = [// JS
  29398. languageJs, {
  29399. parsers: {
  29400. // JS - Babel
  29401. get babel() {
  29402. return require("./parser-babylon").parsers.babel;
  29403. },
  29404. get "babel-flow"() {
  29405. return require("./parser-babylon").parsers["babel-flow"];
  29406. },
  29407. get babylon() {
  29408. return require("./parser-babylon").parsers.babel;
  29409. },
  29410. get json() {
  29411. return require("./parser-babylon").parsers.json;
  29412. },
  29413. get json5() {
  29414. return require("./parser-babylon").parsers.json5;
  29415. },
  29416. get "json-stringify"() {
  29417. return require("./parser-babylon").parsers["json-stringify"];
  29418. },
  29419. get __js_expression() {
  29420. return require("./parser-babylon").parsers.__js_expression;
  29421. },
  29422. get __vue_expression() {
  29423. return require("./parser-babylon").parsers.__vue_expression;
  29424. },
  29425. get __vue_event_binding() {
  29426. return require("./parser-babylon").parsers.__vue_event_binding;
  29427. },
  29428. // JS - Flow
  29429. get flow() {
  29430. return require("./parser-flow").parsers.flow;
  29431. },
  29432. // JS - TypeScript
  29433. get typescript() {
  29434. return require("./parser-typescript").parsers.typescript;
  29435. },
  29436. /**
  29437. * TODO: Remove this old alias in a major version
  29438. */
  29439. get "typescript-eslint"() {
  29440. return require("./parser-typescript").parsers.typescript;
  29441. },
  29442. // JS - Angular Action
  29443. get __ng_action() {
  29444. return require("./parser-angular").parsers.__ng_action;
  29445. },
  29446. // JS - Angular Binding
  29447. get __ng_binding() {
  29448. return require("./parser-angular").parsers.__ng_binding;
  29449. },
  29450. // JS - Angular Interpolation
  29451. get __ng_interpolation() {
  29452. return require("./parser-angular").parsers.__ng_interpolation;
  29453. },
  29454. // JS - Angular Directive
  29455. get __ng_directive() {
  29456. return require("./parser-angular").parsers.__ng_directive;
  29457. }
  29458. }
  29459. }, // CSS
  29460. languageCss, {
  29461. parsers: {
  29462. // TODO: switch these to just `postcss` and use `language` instead.
  29463. get css() {
  29464. return require("./parser-postcss").parsers.css;
  29465. },
  29466. get less() {
  29467. return require("./parser-postcss").parsers.css;
  29468. },
  29469. get scss() {
  29470. return require("./parser-postcss").parsers.css;
  29471. }
  29472. }
  29473. }, // Handlebars
  29474. languageHandlebars, {
  29475. parsers: {
  29476. get glimmer() {
  29477. return require("./parser-glimmer").parsers.glimmer;
  29478. }
  29479. }
  29480. }, // GraphQL
  29481. languageGraphql, {
  29482. parsers: {
  29483. get graphql() {
  29484. return require("./parser-graphql").parsers.graphql;
  29485. }
  29486. }
  29487. }, // Markdown
  29488. languageMarkdown, {
  29489. parsers: {
  29490. get remark() {
  29491. return require("./parser-markdown").parsers.remark;
  29492. },
  29493. // TODO: Delete this in 2.0
  29494. get markdown() {
  29495. return require("./parser-markdown").parsers.remark;
  29496. },
  29497. get mdx() {
  29498. return require("./parser-markdown").parsers.mdx;
  29499. }
  29500. }
  29501. }, languageHtml, {
  29502. parsers: {
  29503. // HTML
  29504. get html() {
  29505. return require("./parser-html").parsers.html;
  29506. },
  29507. // Vue
  29508. get vue() {
  29509. return require("./parser-html").parsers.vue;
  29510. },
  29511. // Angular
  29512. get angular() {
  29513. return require("./parser-html").parsers.angular;
  29514. },
  29515. // Lightning Web Components
  29516. get lwc() {
  29517. return require("./parser-html").parsers.lwc;
  29518. }
  29519. }
  29520. }, // YAML
  29521. languageYaml, {
  29522. parsers: {
  29523. get yaml() {
  29524. return require("./parser-yaml").parsers.yaml;
  29525. }
  29526. }
  29527. }];
  29528. var partition = function partition(array, fn) {
  29529. var a = [];
  29530. var b = [];
  29531. array.forEach(function (item) {
  29532. if (fn(item)) {
  29533. a.push(item);
  29534. } else {
  29535. b.push(item);
  29536. }
  29537. });
  29538. return [a, b];
  29539. };
  29540. var thirdParty$1 = ( thirdParty && thirdParty__default ) || thirdParty;
  29541. function loadPlugins(plugins, pluginSearchDirs) {
  29542. if (!plugins) {
  29543. plugins = [];
  29544. }
  29545. if (!pluginSearchDirs) {
  29546. pluginSearchDirs = [];
  29547. } // unless pluginSearchDirs are provided, auto-load plugins from node_modules that are parent to Prettier
  29548. if (!pluginSearchDirs.length) {
  29549. var autoLoadDir = thirdParty$1.findParentDir(__dirname, "node_modules");
  29550. if (autoLoadDir) {
  29551. pluginSearchDirs = [autoLoadDir];
  29552. }
  29553. }
  29554. var _partition = partition(plugins, function (plugin) {
  29555. return typeof plugin === "string";
  29556. }),
  29557. _partition2 = _slicedToArray(_partition, 2),
  29558. externalPluginNames = _partition2[0],
  29559. externalPluginInstances = _partition2[1];
  29560. var externalManualLoadPluginInfos = externalPluginNames.map(function (pluginName) {
  29561. var requirePath;
  29562. try {
  29563. // try local files
  29564. requirePath = resolve$1.sync(path.resolve(process.cwd(), pluginName));
  29565. } catch (e) {
  29566. // try node modules
  29567. requirePath = resolve$1.sync(pluginName, {
  29568. basedir: process.cwd()
  29569. });
  29570. }
  29571. return {
  29572. name: pluginName,
  29573. requirePath
  29574. };
  29575. });
  29576. var externalAutoLoadPluginInfos = pluginSearchDirs.map(function (pluginSearchDir) {
  29577. var resolvedPluginSearchDir = path.resolve(process.cwd(), pluginSearchDir);
  29578. var nodeModulesDir = path.resolve(resolvedPluginSearchDir, "node_modules"); // In some fringe cases (ex: files "mounted" as virtual directories), the
  29579. // isDirectory(resolvedPluginSearchDir) check might be false even though
  29580. // the node_modules actually exists.
  29581. if (!isDirectory(nodeModulesDir) && !isDirectory(resolvedPluginSearchDir)) {
  29582. throw new Error(`${pluginSearchDir} does not exist or is not a directory`);
  29583. }
  29584. return findPluginsInNodeModules(nodeModulesDir).map(function (pluginName) {
  29585. return {
  29586. name: pluginName,
  29587. requirePath: resolve$1.sync(pluginName, {
  29588. basedir: resolvedPluginSearchDir
  29589. })
  29590. };
  29591. });
  29592. }).reduce(function (a, b) {
  29593. return a.concat(b);
  29594. }, []);
  29595. var externalPlugins = lodash_uniqby(externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), "requirePath").map(function (externalPluginInfo) {
  29596. return Object.assign({
  29597. name: externalPluginInfo.name
  29598. }, require(externalPluginInfo.requirePath));
  29599. }).concat(externalPluginInstances);
  29600. return internalPlugins.concat(externalPlugins);
  29601. }
  29602. function findPluginsInNodeModules(nodeModulesDir) {
  29603. var pluginPackageJsonPaths = globby.sync(["prettier-plugin-*/package.json", "@*/prettier-plugin-*/package.json", "@prettier/plugin-*/package.json"], {
  29604. cwd: nodeModulesDir
  29605. });
  29606. return pluginPackageJsonPaths.map(path.dirname);
  29607. }
  29608. function isDirectory(dir) {
  29609. try {
  29610. return fs.statSync(dir).isDirectory();
  29611. } catch (e) {
  29612. return false;
  29613. }
  29614. }
  29615. var loadPlugins_1 = loadPlugins;
  29616. var mimicFn = function mimicFn(to, from) {
  29617. // TODO: use `Reflect.ownKeys()` when targeting Node.js 6
  29618. var _iteratorNormalCompletion = true;
  29619. var _didIteratorError = false;
  29620. var _iteratorError = undefined;
  29621. try {
  29622. for (var _iterator = Object.getOwnPropertyNames(from).concat(Object.getOwnPropertySymbols(from))[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  29623. var prop = _step.value;
  29624. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  29625. }
  29626. } catch (err) {
  29627. _didIteratorError = true;
  29628. _iteratorError = err;
  29629. } finally {
  29630. try {
  29631. if (!_iteratorNormalCompletion && _iterator.return != null) {
  29632. _iterator.return();
  29633. }
  29634. } finally {
  29635. if (_didIteratorError) {
  29636. throw _iteratorError;
  29637. }
  29638. }
  29639. }
  29640. };
  29641. var mem = createCommonjsModule(function (module) {
  29642. 'use strict';
  29643. var cacheStore = new WeakMap();
  29644. var defaultCacheKey = function defaultCacheKey(x) {
  29645. if (arguments.length === 1 && (x === null || x === undefined || typeof x !== 'function' && typeof x !== 'object')) {
  29646. return x;
  29647. }
  29648. return JSON.stringify(arguments);
  29649. };
  29650. module.exports = function (fn, opts) {
  29651. opts = Object.assign({
  29652. cacheKey: defaultCacheKey,
  29653. cache: new Map()
  29654. }, opts);
  29655. var memoized = function memoized() {
  29656. var cache = cacheStore.get(memoized);
  29657. var key = opts.cacheKey.apply(null, arguments);
  29658. if (cache.has(key)) {
  29659. var c = cache.get(key);
  29660. if (typeof opts.maxAge !== 'number' || Date.now() < c.maxAge) {
  29661. return c.data;
  29662. }
  29663. }
  29664. var ret = fn.apply(null, arguments);
  29665. cache.set(key, {
  29666. data: ret,
  29667. maxAge: Date.now() + (opts.maxAge || 0)
  29668. });
  29669. return ret;
  29670. };
  29671. mimicFn(memoized, fn);
  29672. cacheStore.set(memoized, opts.cache);
  29673. return memoized;
  29674. };
  29675. module.exports.clear = function (fn) {
  29676. var cache = cacheStore.get(fn);
  29677. if (cache && typeof cache.clear === 'function') {
  29678. cache.clear();
  29679. }
  29680. };
  29681. });
  29682. var semver$3 = createCommonjsModule(function (module, exports) {
  29683. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  29684. /* nomin */
  29685. var debug;
  29686. /* nomin */
  29687. if (typeof process === 'object' &&
  29688. /* nomin */
  29689. process.env &&
  29690. /* nomin */
  29691. process.env.NODE_DEBUG &&
  29692. /* nomin */
  29693. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  29694. /* nomin */
  29695. debug = function debug() {
  29696. /* nomin */
  29697. var args = Array.prototype.slice.call(arguments, 0);
  29698. /* nomin */
  29699. args.unshift('SEMVER');
  29700. /* nomin */
  29701. console.log.apply(console, args);
  29702. /* nomin */
  29703. };
  29704. /* nomin */
  29705. else
  29706. /* nomin */
  29707. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  29708. // Not necessarily the package version of this code.
  29709. exports.SEMVER_SPEC_VERSION = '2.0.0';
  29710. var MAX_LENGTH = 256;
  29711. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // Max safe segment length for coercion.
  29712. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  29713. var re = exports.re = [];
  29714. var src = exports.src = [];
  29715. var R = 0; // The following Regular Expressions can be used for tokenizing,
  29716. // validating, and parsing SemVer version strings.
  29717. // ## Numeric Identifier
  29718. // A single `0`, or a non-zero digit followed by zero or more digits.
  29719. var NUMERICIDENTIFIER = R++;
  29720. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  29721. var NUMERICIDENTIFIERLOOSE = R++;
  29722. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  29723. // Zero or more digits, followed by a letter or hyphen, and then zero or
  29724. // more letters, digits, or hyphens.
  29725. var NONNUMERICIDENTIFIER = R++;
  29726. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  29727. // Three dot-separated numeric identifiers.
  29728. var MAINVERSION = R++;
  29729. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  29730. var MAINVERSIONLOOSE = R++;
  29731. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  29732. // A numeric identifier, or a non-numeric identifier.
  29733. var PRERELEASEIDENTIFIER = R++;
  29734. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  29735. var PRERELEASEIDENTIFIERLOOSE = R++;
  29736. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  29737. // Hyphen, followed by one or more dot-separated pre-release version
  29738. // identifiers.
  29739. var PRERELEASE = R++;
  29740. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  29741. var PRERELEASELOOSE = R++;
  29742. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  29743. // Any combination of digits, letters, or hyphens.
  29744. var BUILDIDENTIFIER = R++;
  29745. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  29746. // Plus sign, followed by one or more period-separated build metadata
  29747. // identifiers.
  29748. var BUILD = R++;
  29749. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  29750. // A main version, followed optionally by a pre-release version and
  29751. // build metadata.
  29752. // Note that the only major, minor, patch, and pre-release sections of
  29753. // the version string are capturing groups. The build metadata is not a
  29754. // capturing group, because it should not ever be used in version
  29755. // comparison.
  29756. var FULL = R++;
  29757. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  29758. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  29759. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  29760. // common in the npm registry.
  29761. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  29762. var LOOSE = R++;
  29763. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  29764. var GTLT = R++;
  29765. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  29766. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  29767. // Only the first item is strictly required.
  29768. var XRANGEIDENTIFIERLOOSE = R++;
  29769. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  29770. var XRANGEIDENTIFIER = R++;
  29771. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  29772. var XRANGEPLAIN = R++;
  29773. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  29774. var XRANGEPLAINLOOSE = R++;
  29775. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  29776. var XRANGE = R++;
  29777. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  29778. var XRANGELOOSE = R++;
  29779. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Coercion.
  29780. // Extract anything that could conceivably be a part of a valid semver
  29781. var COERCE = R++;
  29782. src[COERCE] = '(?:^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])'; // Tilde ranges.
  29783. // Meaning is "reasonably at or greater than"
  29784. var LONETILDE = R++;
  29785. src[LONETILDE] = '(?:~>?)';
  29786. var TILDETRIM = R++;
  29787. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  29788. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  29789. var tildeTrimReplace = '$1~';
  29790. var TILDE = R++;
  29791. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  29792. var TILDELOOSE = R++;
  29793. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  29794. // Meaning is "at least and backwards compatible with"
  29795. var LONECARET = R++;
  29796. src[LONECARET] = '(?:\\^)';
  29797. var CARETTRIM = R++;
  29798. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  29799. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  29800. var caretTrimReplace = '$1^';
  29801. var CARET = R++;
  29802. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  29803. var CARETLOOSE = R++;
  29804. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  29805. var COMPARATORLOOSE = R++;
  29806. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  29807. var COMPARATOR = R++;
  29808. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  29809. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  29810. var COMPARATORTRIM = R++;
  29811. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  29812. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  29813. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  29814. // Note that these all use the loose form, because they'll be
  29815. // checked against either the strict or loose comparator form
  29816. // later.
  29817. var HYPHENRANGE = R++;
  29818. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  29819. var HYPHENRANGELOOSE = R++;
  29820. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  29821. var STAR = R++;
  29822. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  29823. // All are flag-free, unless they were created above with a flag.
  29824. for (var i = 0; i < R; i++) {
  29825. debug(i, src[i]);
  29826. if (!re[i]) re[i] = new RegExp(src[i]);
  29827. }
  29828. exports.parse = parse;
  29829. function parse(version, options) {
  29830. if (!options || typeof options !== 'object') options = {
  29831. loose: !!options,
  29832. includePrerelease: false
  29833. };
  29834. if (version instanceof SemVer) return version;
  29835. if (typeof version !== 'string') return null;
  29836. if (version.length > MAX_LENGTH) return null;
  29837. var r = options.loose ? re[LOOSE] : re[FULL];
  29838. if (!r.test(version)) return null;
  29839. try {
  29840. return new SemVer(version, options);
  29841. } catch (er) {
  29842. return null;
  29843. }
  29844. }
  29845. exports.valid = valid;
  29846. function valid(version, options) {
  29847. var v = parse(version, options);
  29848. return v ? v.version : null;
  29849. }
  29850. exports.clean = clean;
  29851. function clean(version, options) {
  29852. var s = parse(version.trim().replace(/^[=v]+/, ''), options);
  29853. return s ? s.version : null;
  29854. }
  29855. exports.SemVer = SemVer;
  29856. function SemVer(version, options) {
  29857. if (!options || typeof options !== 'object') options = {
  29858. loose: !!options,
  29859. includePrerelease: false
  29860. };
  29861. if (version instanceof SemVer) {
  29862. if (version.loose === options.loose) return version;else version = version.version;
  29863. } else if (typeof version !== 'string') {
  29864. throw new TypeError('Invalid Version: ' + version);
  29865. }
  29866. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  29867. if (!(this instanceof SemVer)) return new SemVer(version, options);
  29868. debug('SemVer', version, options);
  29869. this.options = options;
  29870. this.loose = !!options.loose;
  29871. var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL]);
  29872. if (!m) throw new TypeError('Invalid Version: ' + version);
  29873. this.raw = version; // these are actually numbers
  29874. this.major = +m[1];
  29875. this.minor = +m[2];
  29876. this.patch = +m[3];
  29877. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  29878. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  29879. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  29880. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  29881. if (/^[0-9]+$/.test(id)) {
  29882. var num = +id;
  29883. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  29884. }
  29885. return id;
  29886. });
  29887. this.build = m[5] ? m[5].split('.') : [];
  29888. this.format();
  29889. }
  29890. SemVer.prototype.format = function () {
  29891. this.version = this.major + '.' + this.minor + '.' + this.patch;
  29892. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  29893. return this.version;
  29894. };
  29895. SemVer.prototype.toString = function () {
  29896. return this.version;
  29897. };
  29898. SemVer.prototype.compare = function (other) {
  29899. debug('SemVer.compare', this.version, this.options, other);
  29900. if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
  29901. return this.compareMain(other) || this.comparePre(other);
  29902. };
  29903. SemVer.prototype.compareMain = function (other) {
  29904. if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
  29905. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  29906. };
  29907. SemVer.prototype.comparePre = function (other) {
  29908. if (!(other instanceof SemVer)) other = new SemVer(other, this.options); // NOT having a prerelease is > having one
  29909. 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;
  29910. var i = 0;
  29911. do {
  29912. var a = this.prerelease[i];
  29913. var b = other.prerelease[i];
  29914. debug('prerelease compare', i, a, b);
  29915. 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);
  29916. } while (++i);
  29917. }; // preminor will bump the version up to the next minor release, and immediately
  29918. // down to pre-release. premajor and prepatch work the same way.
  29919. SemVer.prototype.inc = function (release, identifier) {
  29920. switch (release) {
  29921. case 'premajor':
  29922. this.prerelease.length = 0;
  29923. this.patch = 0;
  29924. this.minor = 0;
  29925. this.major++;
  29926. this.inc('pre', identifier);
  29927. break;
  29928. case 'preminor':
  29929. this.prerelease.length = 0;
  29930. this.patch = 0;
  29931. this.minor++;
  29932. this.inc('pre', identifier);
  29933. break;
  29934. case 'prepatch':
  29935. // If this is already a prerelease, it will bump to the next version
  29936. // drop any prereleases that might already exist, since they are not
  29937. // relevant at this point.
  29938. this.prerelease.length = 0;
  29939. this.inc('patch', identifier);
  29940. this.inc('pre', identifier);
  29941. break;
  29942. // If the input is a non-prerelease version, this acts the same as
  29943. // prepatch.
  29944. case 'prerelease':
  29945. if (this.prerelease.length === 0) this.inc('patch', identifier);
  29946. this.inc('pre', identifier);
  29947. break;
  29948. case 'major':
  29949. // If this is a pre-major version, bump up to the same major version.
  29950. // Otherwise increment major.
  29951. // 1.0.0-5 bumps to 1.0.0
  29952. // 1.1.0 bumps to 2.0.0
  29953. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  29954. this.minor = 0;
  29955. this.patch = 0;
  29956. this.prerelease = [];
  29957. break;
  29958. case 'minor':
  29959. // If this is a pre-minor version, bump up to the same minor version.
  29960. // Otherwise increment minor.
  29961. // 1.2.0-5 bumps to 1.2.0
  29962. // 1.2.1 bumps to 1.3.0
  29963. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  29964. this.patch = 0;
  29965. this.prerelease = [];
  29966. break;
  29967. case 'patch':
  29968. // If this is not a pre-release version, it will increment the patch.
  29969. // If it is a pre-release it will bump up to the same patch version.
  29970. // 1.2.0-5 patches to 1.2.0
  29971. // 1.2.0 patches to 1.2.1
  29972. if (this.prerelease.length === 0) this.patch++;
  29973. this.prerelease = [];
  29974. break;
  29975. // This probably shouldn't be used publicly.
  29976. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  29977. case 'pre':
  29978. if (this.prerelease.length === 0) this.prerelease = [0];else {
  29979. var i = this.prerelease.length;
  29980. while (--i >= 0) {
  29981. if (typeof this.prerelease[i] === 'number') {
  29982. this.prerelease[i]++;
  29983. i = -2;
  29984. }
  29985. }
  29986. if (i === -1) // didn't increment anything
  29987. this.prerelease.push(0);
  29988. }
  29989. if (identifier) {
  29990. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  29991. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  29992. if (this.prerelease[0] === identifier) {
  29993. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  29994. } else this.prerelease = [identifier, 0];
  29995. }
  29996. break;
  29997. default:
  29998. throw new Error('invalid increment argument: ' + release);
  29999. }
  30000. this.format();
  30001. this.raw = this.version;
  30002. return this;
  30003. };
  30004. exports.inc = inc;
  30005. function inc(version, release, loose, identifier) {
  30006. if (typeof loose === 'string') {
  30007. identifier = loose;
  30008. loose = undefined;
  30009. }
  30010. try {
  30011. return new SemVer(version, loose).inc(release, identifier).version;
  30012. } catch (er) {
  30013. return null;
  30014. }
  30015. }
  30016. exports.diff = diff;
  30017. function diff(version1, version2) {
  30018. if (eq(version1, version2)) {
  30019. return null;
  30020. } else {
  30021. var v1 = parse(version1);
  30022. var v2 = parse(version2);
  30023. if (v1.prerelease.length || v2.prerelease.length) {
  30024. for (var key in v1) {
  30025. if (key === 'major' || key === 'minor' || key === 'patch') {
  30026. if (v1[key] !== v2[key]) {
  30027. return 'pre' + key;
  30028. }
  30029. }
  30030. }
  30031. return 'prerelease';
  30032. }
  30033. for (var key in v1) {
  30034. if (key === 'major' || key === 'minor' || key === 'patch') {
  30035. if (v1[key] !== v2[key]) {
  30036. return key;
  30037. }
  30038. }
  30039. }
  30040. }
  30041. }
  30042. exports.compareIdentifiers = compareIdentifiers;
  30043. var numeric = /^[0-9]+$/;
  30044. function compareIdentifiers(a, b) {
  30045. var anum = numeric.test(a);
  30046. var bnum = numeric.test(b);
  30047. if (anum && bnum) {
  30048. a = +a;
  30049. b = +b;
  30050. }
  30051. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  30052. }
  30053. exports.rcompareIdentifiers = rcompareIdentifiers;
  30054. function rcompareIdentifiers(a, b) {
  30055. return compareIdentifiers(b, a);
  30056. }
  30057. exports.major = major;
  30058. function major(a, loose) {
  30059. return new SemVer(a, loose).major;
  30060. }
  30061. exports.minor = minor;
  30062. function minor(a, loose) {
  30063. return new SemVer(a, loose).minor;
  30064. }
  30065. exports.patch = patch;
  30066. function patch(a, loose) {
  30067. return new SemVer(a, loose).patch;
  30068. }
  30069. exports.compare = compare;
  30070. function compare(a, b, loose) {
  30071. return new SemVer(a, loose).compare(new SemVer(b, loose));
  30072. }
  30073. exports.compareLoose = compareLoose;
  30074. function compareLoose(a, b) {
  30075. return compare(a, b, true);
  30076. }
  30077. exports.rcompare = rcompare;
  30078. function rcompare(a, b, loose) {
  30079. return compare(b, a, loose);
  30080. }
  30081. exports.sort = sort;
  30082. function sort(list, loose) {
  30083. return list.sort(function (a, b) {
  30084. return exports.compare(a, b, loose);
  30085. });
  30086. }
  30087. exports.rsort = rsort;
  30088. function rsort(list, loose) {
  30089. return list.sort(function (a, b) {
  30090. return exports.rcompare(a, b, loose);
  30091. });
  30092. }
  30093. exports.gt = gt;
  30094. function gt(a, b, loose) {
  30095. return compare(a, b, loose) > 0;
  30096. }
  30097. exports.lt = lt;
  30098. function lt(a, b, loose) {
  30099. return compare(a, b, loose) < 0;
  30100. }
  30101. exports.eq = eq;
  30102. function eq(a, b, loose) {
  30103. return compare(a, b, loose) === 0;
  30104. }
  30105. exports.neq = neq;
  30106. function neq(a, b, loose) {
  30107. return compare(a, b, loose) !== 0;
  30108. }
  30109. exports.gte = gte;
  30110. function gte(a, b, loose) {
  30111. return compare(a, b, loose) >= 0;
  30112. }
  30113. exports.lte = lte;
  30114. function lte(a, b, loose) {
  30115. return compare(a, b, loose) <= 0;
  30116. }
  30117. exports.cmp = cmp;
  30118. function cmp(a, op, b, loose) {
  30119. var ret;
  30120. switch (op) {
  30121. case '===':
  30122. if (typeof a === 'object') a = a.version;
  30123. if (typeof b === 'object') b = b.version;
  30124. ret = a === b;
  30125. break;
  30126. case '!==':
  30127. if (typeof a === 'object') a = a.version;
  30128. if (typeof b === 'object') b = b.version;
  30129. ret = a !== b;
  30130. break;
  30131. case '':
  30132. case '=':
  30133. case '==':
  30134. ret = eq(a, b, loose);
  30135. break;
  30136. case '!=':
  30137. ret = neq(a, b, loose);
  30138. break;
  30139. case '>':
  30140. ret = gt(a, b, loose);
  30141. break;
  30142. case '>=':
  30143. ret = gte(a, b, loose);
  30144. break;
  30145. case '<':
  30146. ret = lt(a, b, loose);
  30147. break;
  30148. case '<=':
  30149. ret = lte(a, b, loose);
  30150. break;
  30151. default:
  30152. throw new TypeError('Invalid operator: ' + op);
  30153. }
  30154. return ret;
  30155. }
  30156. exports.Comparator = Comparator;
  30157. function Comparator(comp, options) {
  30158. if (!options || typeof options !== 'object') options = {
  30159. loose: !!options,
  30160. includePrerelease: false
  30161. };
  30162. if (comp instanceof Comparator) {
  30163. if (comp.loose === !!options.loose) return comp;else comp = comp.value;
  30164. }
  30165. if (!(this instanceof Comparator)) return new Comparator(comp, options);
  30166. debug('comparator', comp, options);
  30167. this.options = options;
  30168. this.loose = !!options.loose;
  30169. this.parse(comp);
  30170. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  30171. debug('comp', this);
  30172. }
  30173. var ANY = {};
  30174. Comparator.prototype.parse = function (comp) {
  30175. var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  30176. var m = comp.match(r);
  30177. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  30178. this.operator = m[1];
  30179. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  30180. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.options.loose);
  30181. };
  30182. Comparator.prototype.toString = function () {
  30183. return this.value;
  30184. };
  30185. Comparator.prototype.test = function (version) {
  30186. debug('Comparator.test', version, this.options.loose);
  30187. if (this.semver === ANY) return true;
  30188. if (typeof version === 'string') version = new SemVer(version, this.options);
  30189. return cmp(version, this.operator, this.semver, this.options);
  30190. };
  30191. Comparator.prototype.intersects = function (comp, options) {
  30192. if (!(comp instanceof Comparator)) {
  30193. throw new TypeError('a Comparator is required');
  30194. }
  30195. if (!options || typeof options !== 'object') options = {
  30196. loose: !!options,
  30197. includePrerelease: false
  30198. };
  30199. var rangeTmp;
  30200. if (this.operator === '') {
  30201. rangeTmp = new Range(comp.value, options);
  30202. return satisfies(this.value, rangeTmp, options);
  30203. } else if (comp.operator === '') {
  30204. rangeTmp = new Range(this.value, options);
  30205. return satisfies(comp.semver, rangeTmp, options);
  30206. }
  30207. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  30208. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  30209. var sameSemVer = this.semver.version === comp.semver.version;
  30210. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  30211. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, options) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  30212. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, options) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  30213. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  30214. };
  30215. exports.Range = Range;
  30216. function Range(range, options) {
  30217. if (!options || typeof options !== 'object') options = {
  30218. loose: !!options,
  30219. includePrerelease: false
  30220. };
  30221. if (range instanceof Range) {
  30222. if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
  30223. return range;
  30224. } else {
  30225. return new Range(range.raw, options);
  30226. }
  30227. }
  30228. if (range instanceof Comparator) {
  30229. return new Range(range.value, options);
  30230. }
  30231. if (!(this instanceof Range)) return new Range(range, options);
  30232. this.options = options;
  30233. this.loose = !!options.loose;
  30234. this.includePrerelease = !!options.includePrerelease; // First, split based on boolean or ||
  30235. this.raw = range;
  30236. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  30237. return this.parseRange(range.trim());
  30238. }, this).filter(function (c) {
  30239. // throw out any that are not relevant for whatever reason
  30240. return c.length;
  30241. });
  30242. if (!this.set.length) {
  30243. throw new TypeError('Invalid SemVer Range: ' + range);
  30244. }
  30245. this.format();
  30246. }
  30247. Range.prototype.format = function () {
  30248. this.range = this.set.map(function (comps) {
  30249. return comps.join(' ').trim();
  30250. }).join('||').trim();
  30251. return this.range;
  30252. };
  30253. Range.prototype.toString = function () {
  30254. return this.range;
  30255. };
  30256. Range.prototype.parseRange = function (range) {
  30257. var loose = this.options.loose;
  30258. range = range.trim(); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  30259. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  30260. range = range.replace(hr, hyphenReplace);
  30261. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  30262. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  30263. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  30264. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  30265. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  30266. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  30267. // ready to be split into comparators.
  30268. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  30269. var set = range.split(' ').map(function (comp) {
  30270. return parseComparator(comp, this.options);
  30271. }, this).join(' ').split(/\s+/);
  30272. if (this.options.loose) {
  30273. // in loose mode, throw out any that are not valid comparators
  30274. set = set.filter(function (comp) {
  30275. return !!comp.match(compRe);
  30276. });
  30277. }
  30278. set = set.map(function (comp) {
  30279. return new Comparator(comp, this.options);
  30280. }, this);
  30281. return set;
  30282. };
  30283. Range.prototype.intersects = function (range, options) {
  30284. if (!(range instanceof Range)) {
  30285. throw new TypeError('a Range is required');
  30286. }
  30287. return this.set.some(function (thisComparators) {
  30288. return thisComparators.every(function (thisComparator) {
  30289. return range.set.some(function (rangeComparators) {
  30290. return rangeComparators.every(function (rangeComparator) {
  30291. return thisComparator.intersects(rangeComparator, options);
  30292. });
  30293. });
  30294. });
  30295. });
  30296. }; // Mostly just for testing and legacy API reasons
  30297. exports.toComparators = toComparators;
  30298. function toComparators(range, options) {
  30299. return new Range(range, options).set.map(function (comp) {
  30300. return comp.map(function (c) {
  30301. return c.value;
  30302. }).join(' ').trim().split(' ');
  30303. });
  30304. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  30305. // already replaced the hyphen ranges
  30306. // turn into a set of JUST comparators.
  30307. function parseComparator(comp, options) {
  30308. debug('comp', comp, options);
  30309. comp = replaceCarets(comp, options);
  30310. debug('caret', comp);
  30311. comp = replaceTildes(comp, options);
  30312. debug('tildes', comp);
  30313. comp = replaceXRanges(comp, options);
  30314. debug('xrange', comp);
  30315. comp = replaceStars(comp, options);
  30316. debug('stars', comp);
  30317. return comp;
  30318. }
  30319. function isX(id) {
  30320. return !id || id.toLowerCase() === 'x' || id === '*';
  30321. } // ~, ~> --> * (any, kinda silly)
  30322. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  30323. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  30324. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  30325. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  30326. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  30327. function replaceTildes(comp, options) {
  30328. return comp.trim().split(/\s+/).map(function (comp) {
  30329. return replaceTilde(comp, options);
  30330. }).join(' ');
  30331. }
  30332. function replaceTilde(comp, options) {
  30333. if (!options || typeof options !== 'object') options = {
  30334. loose: !!options,
  30335. includePrerelease: false
  30336. };
  30337. var r = options.loose ? re[TILDELOOSE] : re[TILDE];
  30338. return comp.replace(r, function (_, M, m, p, pr) {
  30339. debug('tilde', comp, _, M, m, p, pr);
  30340. var ret;
  30341. 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
  30342. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  30343. debug('replaceTilde pr', pr);
  30344. if (pr.charAt(0) !== '-') pr = '-' + pr;
  30345. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  30346. } else // ~1.2.3 == >=1.2.3 <1.3.0
  30347. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  30348. debug('tilde return', ret);
  30349. return ret;
  30350. });
  30351. } // ^ --> * (any, kinda silly)
  30352. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  30353. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  30354. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  30355. // ^1.2.3 --> >=1.2.3 <2.0.0
  30356. // ^1.2.0 --> >=1.2.0 <2.0.0
  30357. function replaceCarets(comp, options) {
  30358. return comp.trim().split(/\s+/).map(function (comp) {
  30359. return replaceCaret(comp, options);
  30360. }).join(' ');
  30361. }
  30362. function replaceCaret(comp, options) {
  30363. debug('caret', comp, options);
  30364. if (!options || typeof options !== 'object') options = {
  30365. loose: !!options,
  30366. includePrerelease: false
  30367. };
  30368. var r = options.loose ? re[CARETLOOSE] : re[CARET];
  30369. return comp.replace(r, function (_, M, m, p, pr) {
  30370. debug('caret', comp, _, M, m, p, pr);
  30371. var ret;
  30372. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  30373. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  30374. } else if (pr) {
  30375. debug('replaceCaret pr', pr);
  30376. if (pr.charAt(0) !== '-') pr = '-' + pr;
  30377. if (M === '0') {
  30378. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  30379. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  30380. } else {
  30381. debug('no pr');
  30382. if (M === '0') {
  30383. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  30384. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  30385. }
  30386. debug('caret return', ret);
  30387. return ret;
  30388. });
  30389. }
  30390. function replaceXRanges(comp, options) {
  30391. debug('replaceXRanges', comp, options);
  30392. return comp.split(/\s+/).map(function (comp) {
  30393. return replaceXRange(comp, options);
  30394. }).join(' ');
  30395. }
  30396. function replaceXRange(comp, options) {
  30397. comp = comp.trim();
  30398. if (!options || typeof options !== 'object') options = {
  30399. loose: !!options,
  30400. includePrerelease: false
  30401. };
  30402. var r = options.loose ? re[XRANGELOOSE] : re[XRANGE];
  30403. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  30404. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  30405. var xM = isX(M);
  30406. var xm = xM || isX(m);
  30407. var xp = xm || isX(p);
  30408. var anyX = xp;
  30409. if (gtlt === '=' && anyX) gtlt = '';
  30410. if (xM) {
  30411. if (gtlt === '>' || gtlt === '<') {
  30412. // nothing is allowed
  30413. ret = '<0.0.0';
  30414. } else {
  30415. // nothing is forbidden
  30416. ret = '*';
  30417. }
  30418. } else if (gtlt && anyX) {
  30419. // replace X with 0
  30420. if (xm) m = 0;
  30421. if (xp) p = 0;
  30422. if (gtlt === '>') {
  30423. // >1 => >=2.0.0
  30424. // >1.2 => >=1.3.0
  30425. // >1.2.3 => >= 1.2.4
  30426. gtlt = '>=';
  30427. if (xm) {
  30428. M = +M + 1;
  30429. m = 0;
  30430. p = 0;
  30431. } else if (xp) {
  30432. m = +m + 1;
  30433. p = 0;
  30434. }
  30435. } else if (gtlt === '<=') {
  30436. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  30437. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  30438. gtlt = '<';
  30439. if (xm) M = +M + 1;else m = +m + 1;
  30440. }
  30441. ret = gtlt + M + '.' + m + '.' + p;
  30442. } else if (xm) {
  30443. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  30444. } else if (xp) {
  30445. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  30446. }
  30447. debug('xRange return', ret);
  30448. return ret;
  30449. });
  30450. } // Because * is AND-ed with everything else in the comparator,
  30451. // and '' means "any version", just remove the *s entirely.
  30452. function replaceStars(comp, options) {
  30453. debug('replaceStars', comp, options); // Looseness is ignored here. star is always as loose as it gets!
  30454. return comp.trim().replace(re[STAR], '');
  30455. } // This function is passed to string.replace(re[HYPHENRANGE])
  30456. // M, m, patch, prerelease, build
  30457. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  30458. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  30459. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  30460. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  30461. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  30462. 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;
  30463. return (from + ' ' + to).trim();
  30464. } // if ANY of the sets match ALL of its comparators, then pass
  30465. Range.prototype.test = function (version) {
  30466. if (!version) return false;
  30467. if (typeof version === 'string') version = new SemVer(version, this.options);
  30468. for (var i = 0; i < this.set.length; i++) {
  30469. if (testSet(this.set[i], version, this.options)) return true;
  30470. }
  30471. return false;
  30472. };
  30473. function testSet(set, version, options) {
  30474. for (var i = 0; i < set.length; i++) {
  30475. if (!set[i].test(version)) return false;
  30476. }
  30477. if (!options) options = {};
  30478. if (version.prerelease.length && !options.includePrerelease) {
  30479. // Find the set of versions that are allowed to have prereleases
  30480. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  30481. // That should allow `1.2.3-pr.2` to pass.
  30482. // However, `1.2.4-alpha.notready` should NOT be allowed,
  30483. // even though it's within the range set by the comparators.
  30484. for (var i = 0; i < set.length; i++) {
  30485. debug(set[i].semver);
  30486. if (set[i].semver === ANY) continue;
  30487. if (set[i].semver.prerelease.length > 0) {
  30488. var allowed = set[i].semver;
  30489. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  30490. }
  30491. } // Version has a -pre, but it's not one of the ones we like.
  30492. return false;
  30493. }
  30494. return true;
  30495. }
  30496. exports.satisfies = satisfies;
  30497. function satisfies(version, range, options) {
  30498. try {
  30499. range = new Range(range, options);
  30500. } catch (er) {
  30501. return false;
  30502. }
  30503. return range.test(version);
  30504. }
  30505. exports.maxSatisfying = maxSatisfying;
  30506. function maxSatisfying(versions, range, options) {
  30507. var max = null;
  30508. var maxSV = null;
  30509. try {
  30510. var rangeObj = new Range(range, options);
  30511. } catch (er) {
  30512. return null;
  30513. }
  30514. versions.forEach(function (v) {
  30515. if (rangeObj.test(v)) {
  30516. // satisfies(v, range, options)
  30517. if (!max || maxSV.compare(v) === -1) {
  30518. // compare(max, v, true)
  30519. max = v;
  30520. maxSV = new SemVer(max, options);
  30521. }
  30522. }
  30523. });
  30524. return max;
  30525. }
  30526. exports.minSatisfying = minSatisfying;
  30527. function minSatisfying(versions, range, options) {
  30528. var min = null;
  30529. var minSV = null;
  30530. try {
  30531. var rangeObj = new Range(range, options);
  30532. } catch (er) {
  30533. return null;
  30534. }
  30535. versions.forEach(function (v) {
  30536. if (rangeObj.test(v)) {
  30537. // satisfies(v, range, options)
  30538. if (!min || minSV.compare(v) === 1) {
  30539. // compare(min, v, true)
  30540. min = v;
  30541. minSV = new SemVer(min, options);
  30542. }
  30543. }
  30544. });
  30545. return min;
  30546. }
  30547. exports.validRange = validRange;
  30548. function validRange(range, options) {
  30549. try {
  30550. // Return '*' instead of '' so that truthiness works.
  30551. // This will throw if it's invalid anyway
  30552. return new Range(range, options).range || '*';
  30553. } catch (er) {
  30554. return null;
  30555. }
  30556. } // Determine if version is less than all the versions possible in the range
  30557. exports.ltr = ltr;
  30558. function ltr(version, range, options) {
  30559. return outside(version, range, '<', options);
  30560. } // Determine if version is greater than all the versions possible in the range.
  30561. exports.gtr = gtr;
  30562. function gtr(version, range, options) {
  30563. return outside(version, range, '>', options);
  30564. }
  30565. exports.outside = outside;
  30566. function outside(version, range, hilo, options) {
  30567. version = new SemVer(version, options);
  30568. range = new Range(range, options);
  30569. var gtfn, ltefn, ltfn, comp, ecomp;
  30570. switch (hilo) {
  30571. case '>':
  30572. gtfn = gt;
  30573. ltefn = lte;
  30574. ltfn = lt;
  30575. comp = '>';
  30576. ecomp = '>=';
  30577. break;
  30578. case '<':
  30579. gtfn = lt;
  30580. ltefn = gte;
  30581. ltfn = gt;
  30582. comp = '<';
  30583. ecomp = '<=';
  30584. break;
  30585. default:
  30586. throw new TypeError('Must provide a hilo val of "<" or ">"');
  30587. } // If it satisifes the range it is not outside
  30588. if (satisfies(version, range, options)) {
  30589. return false;
  30590. } // From now on, variable terms are as if we're in "gtr" mode.
  30591. // but note that everything is flipped for the "ltr" function.
  30592. for (var i = 0; i < range.set.length; ++i) {
  30593. var comparators = range.set[i];
  30594. var high = null;
  30595. var low = null;
  30596. comparators.forEach(function (comparator) {
  30597. if (comparator.semver === ANY) {
  30598. comparator = new Comparator('>=0.0.0');
  30599. }
  30600. high = high || comparator;
  30601. low = low || comparator;
  30602. if (gtfn(comparator.semver, high.semver, options)) {
  30603. high = comparator;
  30604. } else if (ltfn(comparator.semver, low.semver, options)) {
  30605. low = comparator;
  30606. }
  30607. }); // If the edge version comparator has a operator then our version
  30608. // isn't outside it
  30609. if (high.operator === comp || high.operator === ecomp) {
  30610. return false;
  30611. } // If the lowest version comparator has an operator and our version
  30612. // is less than it then it isn't higher than the range
  30613. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  30614. return false;
  30615. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  30616. return false;
  30617. }
  30618. }
  30619. return true;
  30620. }
  30621. exports.prerelease = prerelease;
  30622. function prerelease(version, options) {
  30623. var parsed = parse(version, options);
  30624. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  30625. }
  30626. exports.intersects = intersects;
  30627. function intersects(r1, r2, options) {
  30628. r1 = new Range(r1, options);
  30629. r2 = new Range(r2, options);
  30630. return r1.intersects(r2);
  30631. }
  30632. exports.coerce = coerce;
  30633. function coerce(version) {
  30634. if (version instanceof SemVer) return version;
  30635. if (typeof version !== 'string') return null;
  30636. var match = version.match(re[COERCE]);
  30637. if (match == null) return null;
  30638. return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  30639. }
  30640. });
  30641. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  30642. var pseudomap = PseudoMap;
  30643. function PseudoMap(set) {
  30644. if (!(this instanceof PseudoMap)) // whyyyyyyy
  30645. throw new TypeError("Constructor PseudoMap requires 'new'");
  30646. this.clear();
  30647. if (set) {
  30648. if (set instanceof PseudoMap || typeof Map === 'function' && set instanceof Map) set.forEach(function (value, key) {
  30649. this.set(key, value);
  30650. }, this);else if (Array.isArray(set)) set.forEach(function (kv) {
  30651. this.set(kv[0], kv[1]);
  30652. }, this);else throw new TypeError('invalid argument');
  30653. }
  30654. }
  30655. PseudoMap.prototype.forEach = function (fn, thisp) {
  30656. thisp = thisp || this;
  30657. Object.keys(this._data).forEach(function (k) {
  30658. if (k !== 'size') fn.call(thisp, this._data[k].value, this._data[k].key);
  30659. }, this);
  30660. };
  30661. PseudoMap.prototype.has = function (k) {
  30662. return !!find(this._data, k);
  30663. };
  30664. PseudoMap.prototype.get = function (k) {
  30665. var res = find(this._data, k);
  30666. return res && res.value;
  30667. };
  30668. PseudoMap.prototype.set = function (k, v) {
  30669. set$1(this._data, k, v);
  30670. };
  30671. PseudoMap.prototype.delete = function (k) {
  30672. var res = find(this._data, k);
  30673. if (res) {
  30674. delete this._data[res._index];
  30675. this._data.size--;
  30676. }
  30677. };
  30678. PseudoMap.prototype.clear = function () {
  30679. var data = Object.create(null);
  30680. data.size = 0;
  30681. Object.defineProperty(this, '_data', {
  30682. value: data,
  30683. enumerable: false,
  30684. configurable: true,
  30685. writable: false
  30686. });
  30687. };
  30688. Object.defineProperty(PseudoMap.prototype, 'size', {
  30689. get: function get() {
  30690. return this._data.size;
  30691. },
  30692. set: function set(n) {},
  30693. enumerable: true,
  30694. configurable: true
  30695. });
  30696. PseudoMap.prototype.values = PseudoMap.prototype.keys = PseudoMap.prototype.entries = function () {
  30697. throw new Error('iterators are not implemented in this version');
  30698. }; // Either identical, or both NaN
  30699. function same(a, b) {
  30700. return a === b || a !== a && b !== b;
  30701. }
  30702. function Entry$1(k, v, i) {
  30703. this.key = k;
  30704. this.value = v;
  30705. this._index = i;
  30706. }
  30707. function find(data, k) {
  30708. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  30709. if (same(data[key].key, k)) return data[key];
  30710. }
  30711. }
  30712. function set$1(data, k, v) {
  30713. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  30714. if (same(data[key].key, k)) {
  30715. data[key].value = v;
  30716. return;
  30717. }
  30718. }
  30719. data.size++;
  30720. data[key] = new Entry$1(k, v, key);
  30721. }
  30722. var map$1 = createCommonjsModule(function (module) {
  30723. if (process.env.npm_package_name === 'pseudomap' && process.env.npm_lifecycle_script === 'test') process.env.TEST_PSEUDOMAP = 'true';
  30724. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  30725. module.exports = Map;
  30726. } else {
  30727. module.exports = pseudomap;
  30728. }
  30729. });
  30730. var yallist = Yallist;
  30731. Yallist.Node = Node;
  30732. Yallist.create = Yallist;
  30733. function Yallist(list) {
  30734. var self = this;
  30735. if (!(self instanceof Yallist)) {
  30736. self = new Yallist();
  30737. }
  30738. self.tail = null;
  30739. self.head = null;
  30740. self.length = 0;
  30741. if (list && typeof list.forEach === 'function') {
  30742. list.forEach(function (item) {
  30743. self.push(item);
  30744. });
  30745. } else if (arguments.length > 0) {
  30746. for (var i = 0, l = arguments.length; i < l; i++) {
  30747. self.push(arguments[i]);
  30748. }
  30749. }
  30750. return self;
  30751. }
  30752. Yallist.prototype.removeNode = function (node) {
  30753. if (node.list !== this) {
  30754. throw new Error('removing node which does not belong to this list');
  30755. }
  30756. var next = node.next;
  30757. var prev = node.prev;
  30758. if (next) {
  30759. next.prev = prev;
  30760. }
  30761. if (prev) {
  30762. prev.next = next;
  30763. }
  30764. if (node === this.head) {
  30765. this.head = next;
  30766. }
  30767. if (node === this.tail) {
  30768. this.tail = prev;
  30769. }
  30770. node.list.length--;
  30771. node.next = null;
  30772. node.prev = null;
  30773. node.list = null;
  30774. };
  30775. Yallist.prototype.unshiftNode = function (node) {
  30776. if (node === this.head) {
  30777. return;
  30778. }
  30779. if (node.list) {
  30780. node.list.removeNode(node);
  30781. }
  30782. var head = this.head;
  30783. node.list = this;
  30784. node.next = head;
  30785. if (head) {
  30786. head.prev = node;
  30787. }
  30788. this.head = node;
  30789. if (!this.tail) {
  30790. this.tail = node;
  30791. }
  30792. this.length++;
  30793. };
  30794. Yallist.prototype.pushNode = function (node) {
  30795. if (node === this.tail) {
  30796. return;
  30797. }
  30798. if (node.list) {
  30799. node.list.removeNode(node);
  30800. }
  30801. var tail = this.tail;
  30802. node.list = this;
  30803. node.prev = tail;
  30804. if (tail) {
  30805. tail.next = node;
  30806. }
  30807. this.tail = node;
  30808. if (!this.head) {
  30809. this.head = node;
  30810. }
  30811. this.length++;
  30812. };
  30813. Yallist.prototype.push = function () {
  30814. for (var i = 0, l = arguments.length; i < l; i++) {
  30815. push(this, arguments[i]);
  30816. }
  30817. return this.length;
  30818. };
  30819. Yallist.prototype.unshift = function () {
  30820. for (var i = 0, l = arguments.length; i < l; i++) {
  30821. unshift(this, arguments[i]);
  30822. }
  30823. return this.length;
  30824. };
  30825. Yallist.prototype.pop = function () {
  30826. if (!this.tail) {
  30827. return undefined;
  30828. }
  30829. var res = this.tail.value;
  30830. this.tail = this.tail.prev;
  30831. if (this.tail) {
  30832. this.tail.next = null;
  30833. } else {
  30834. this.head = null;
  30835. }
  30836. this.length--;
  30837. return res;
  30838. };
  30839. Yallist.prototype.shift = function () {
  30840. if (!this.head) {
  30841. return undefined;
  30842. }
  30843. var res = this.head.value;
  30844. this.head = this.head.next;
  30845. if (this.head) {
  30846. this.head.prev = null;
  30847. } else {
  30848. this.tail = null;
  30849. }
  30850. this.length--;
  30851. return res;
  30852. };
  30853. Yallist.prototype.forEach = function (fn, thisp) {
  30854. thisp = thisp || this;
  30855. for (var walker = this.head, i = 0; walker !== null; i++) {
  30856. fn.call(thisp, walker.value, i, this);
  30857. walker = walker.next;
  30858. }
  30859. };
  30860. Yallist.prototype.forEachReverse = function (fn, thisp) {
  30861. thisp = thisp || this;
  30862. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  30863. fn.call(thisp, walker.value, i, this);
  30864. walker = walker.prev;
  30865. }
  30866. };
  30867. Yallist.prototype.get = function (n) {
  30868. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  30869. // abort out of the list early if we hit a cycle
  30870. walker = walker.next;
  30871. }
  30872. if (i === n && walker !== null) {
  30873. return walker.value;
  30874. }
  30875. };
  30876. Yallist.prototype.getReverse = function (n) {
  30877. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  30878. // abort out of the list early if we hit a cycle
  30879. walker = walker.prev;
  30880. }
  30881. if (i === n && walker !== null) {
  30882. return walker.value;
  30883. }
  30884. };
  30885. Yallist.prototype.map = function (fn, thisp) {
  30886. thisp = thisp || this;
  30887. var res = new Yallist();
  30888. for (var walker = this.head; walker !== null;) {
  30889. res.push(fn.call(thisp, walker.value, this));
  30890. walker = walker.next;
  30891. }
  30892. return res;
  30893. };
  30894. Yallist.prototype.mapReverse = function (fn, thisp) {
  30895. thisp = thisp || this;
  30896. var res = new Yallist();
  30897. for (var walker = this.tail; walker !== null;) {
  30898. res.push(fn.call(thisp, walker.value, this));
  30899. walker = walker.prev;
  30900. }
  30901. return res;
  30902. };
  30903. Yallist.prototype.reduce = function (fn, initial) {
  30904. var acc;
  30905. var walker = this.head;
  30906. if (arguments.length > 1) {
  30907. acc = initial;
  30908. } else if (this.head) {
  30909. walker = this.head.next;
  30910. acc = this.head.value;
  30911. } else {
  30912. throw new TypeError('Reduce of empty list with no initial value');
  30913. }
  30914. for (var i = 0; walker !== null; i++) {
  30915. acc = fn(acc, walker.value, i);
  30916. walker = walker.next;
  30917. }
  30918. return acc;
  30919. };
  30920. Yallist.prototype.reduceReverse = function (fn, initial) {
  30921. var acc;
  30922. var walker = this.tail;
  30923. if (arguments.length > 1) {
  30924. acc = initial;
  30925. } else if (this.tail) {
  30926. walker = this.tail.prev;
  30927. acc = this.tail.value;
  30928. } else {
  30929. throw new TypeError('Reduce of empty list with no initial value');
  30930. }
  30931. for (var i = this.length - 1; walker !== null; i--) {
  30932. acc = fn(acc, walker.value, i);
  30933. walker = walker.prev;
  30934. }
  30935. return acc;
  30936. };
  30937. Yallist.prototype.toArray = function () {
  30938. var arr = new Array(this.length);
  30939. for (var i = 0, walker = this.head; walker !== null; i++) {
  30940. arr[i] = walker.value;
  30941. walker = walker.next;
  30942. }
  30943. return arr;
  30944. };
  30945. Yallist.prototype.toArrayReverse = function () {
  30946. var arr = new Array(this.length);
  30947. for (var i = 0, walker = this.tail; walker !== null; i++) {
  30948. arr[i] = walker.value;
  30949. walker = walker.prev;
  30950. }
  30951. return arr;
  30952. };
  30953. Yallist.prototype.slice = function (from, to) {
  30954. to = to || this.length;
  30955. if (to < 0) {
  30956. to += this.length;
  30957. }
  30958. from = from || 0;
  30959. if (from < 0) {
  30960. from += this.length;
  30961. }
  30962. var ret = new Yallist();
  30963. if (to < from || to < 0) {
  30964. return ret;
  30965. }
  30966. if (from < 0) {
  30967. from = 0;
  30968. }
  30969. if (to > this.length) {
  30970. to = this.length;
  30971. }
  30972. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  30973. walker = walker.next;
  30974. }
  30975. for (; walker !== null && i < to; i++, walker = walker.next) {
  30976. ret.push(walker.value);
  30977. }
  30978. return ret;
  30979. };
  30980. Yallist.prototype.sliceReverse = function (from, to) {
  30981. to = to || this.length;
  30982. if (to < 0) {
  30983. to += this.length;
  30984. }
  30985. from = from || 0;
  30986. if (from < 0) {
  30987. from += this.length;
  30988. }
  30989. var ret = new Yallist();
  30990. if (to < from || to < 0) {
  30991. return ret;
  30992. }
  30993. if (from < 0) {
  30994. from = 0;
  30995. }
  30996. if (to > this.length) {
  30997. to = this.length;
  30998. }
  30999. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  31000. walker = walker.prev;
  31001. }
  31002. for (; walker !== null && i > from; i--, walker = walker.prev) {
  31003. ret.push(walker.value);
  31004. }
  31005. return ret;
  31006. };
  31007. Yallist.prototype.reverse = function () {
  31008. var head = this.head;
  31009. var tail = this.tail;
  31010. for (var walker = head; walker !== null; walker = walker.prev) {
  31011. var p = walker.prev;
  31012. walker.prev = walker.next;
  31013. walker.next = p;
  31014. }
  31015. this.head = tail;
  31016. this.tail = head;
  31017. return this;
  31018. };
  31019. function push(self, item) {
  31020. self.tail = new Node(item, self.tail, null, self);
  31021. if (!self.head) {
  31022. self.head = self.tail;
  31023. }
  31024. self.length++;
  31025. }
  31026. function unshift(self, item) {
  31027. self.head = new Node(item, null, self.head, self);
  31028. if (!self.tail) {
  31029. self.tail = self.head;
  31030. }
  31031. self.length++;
  31032. }
  31033. function Node(value, prev, next, list) {
  31034. if (!(this instanceof Node)) {
  31035. return new Node(value, prev, next, list);
  31036. }
  31037. this.list = list;
  31038. this.value = value;
  31039. if (prev) {
  31040. prev.next = this;
  31041. this.prev = prev;
  31042. } else {
  31043. this.prev = null;
  31044. }
  31045. if (next) {
  31046. next.prev = this;
  31047. this.next = next;
  31048. } else {
  31049. this.next = null;
  31050. }
  31051. }
  31052. var lruCache = LRUCache; // This will be a proper iterable 'Map' in engines that support it,
  31053. // or a fakey-fake PseudoMap in older versions.
  31054. // A linked list to keep track of recently-used-ness
  31055. // use symbols if possible, otherwise just _props
  31056. var hasSymbol = typeof Symbol === 'function';
  31057. var makeSymbol;
  31058. if (hasSymbol) {
  31059. makeSymbol = function makeSymbol(key) {
  31060. return Symbol(key);
  31061. };
  31062. } else {
  31063. makeSymbol = function makeSymbol(key) {
  31064. return '_' + key;
  31065. };
  31066. }
  31067. var MAX = makeSymbol('max');
  31068. var LENGTH = makeSymbol('length');
  31069. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  31070. var ALLOW_STALE = makeSymbol('allowStale');
  31071. var MAX_AGE = makeSymbol('maxAge');
  31072. var DISPOSE = makeSymbol('dispose');
  31073. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  31074. var LRU_LIST = makeSymbol('lruList');
  31075. var CACHE = makeSymbol('cache');
  31076. function naiveLength() {
  31077. return 1;
  31078. } // lruList is a yallist where the head is the youngest
  31079. // item, and the tail is the oldest. the list contains the Hit
  31080. // objects as the entries.
  31081. // Each Hit object has a reference to its Yallist.Node. This
  31082. // never changes.
  31083. //
  31084. // cache is a Map (or PseudoMap) that matches the keys to
  31085. // the Yallist.Node object.
  31086. function LRUCache(options) {
  31087. if (!(this instanceof LRUCache)) {
  31088. return new LRUCache(options);
  31089. }
  31090. if (typeof options === 'number') {
  31091. options = {
  31092. max: options
  31093. };
  31094. }
  31095. if (!options) {
  31096. options = {};
  31097. }
  31098. var max = this[MAX] = options.max; // Kind of weird to have a default max of Infinity, but oh well.
  31099. if (!max || !(typeof max === 'number') || max <= 0) {
  31100. this[MAX] = Infinity;
  31101. }
  31102. var lc = options.length || naiveLength;
  31103. if (typeof lc !== 'function') {
  31104. lc = naiveLength;
  31105. }
  31106. this[LENGTH_CALCULATOR] = lc;
  31107. this[ALLOW_STALE] = options.stale || false;
  31108. this[MAX_AGE] = options.maxAge || 0;
  31109. this[DISPOSE] = options.dispose;
  31110. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  31111. this.reset();
  31112. } // resize the cache when the max changes.
  31113. Object.defineProperty(LRUCache.prototype, 'max', {
  31114. set: function set(mL) {
  31115. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  31116. mL = Infinity;
  31117. }
  31118. this[MAX] = mL;
  31119. trim$2(this);
  31120. },
  31121. get: function get() {
  31122. return this[MAX];
  31123. },
  31124. enumerable: true
  31125. });
  31126. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  31127. set: function set(allowStale) {
  31128. this[ALLOW_STALE] = !!allowStale;
  31129. },
  31130. get: function get() {
  31131. return this[ALLOW_STALE];
  31132. },
  31133. enumerable: true
  31134. });
  31135. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  31136. set: function set(mA) {
  31137. if (!mA || !(typeof mA === 'number') || mA < 0) {
  31138. mA = 0;
  31139. }
  31140. this[MAX_AGE] = mA;
  31141. trim$2(this);
  31142. },
  31143. get: function get() {
  31144. return this[MAX_AGE];
  31145. },
  31146. enumerable: true
  31147. }); // resize the cache when the lengthCalculator changes.
  31148. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  31149. set: function set(lC) {
  31150. if (typeof lC !== 'function') {
  31151. lC = naiveLength;
  31152. }
  31153. if (lC !== this[LENGTH_CALCULATOR]) {
  31154. this[LENGTH_CALCULATOR] = lC;
  31155. this[LENGTH] = 0;
  31156. this[LRU_LIST].forEach(function (hit) {
  31157. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  31158. this[LENGTH] += hit.length;
  31159. }, this);
  31160. }
  31161. trim$2(this);
  31162. },
  31163. get: function get() {
  31164. return this[LENGTH_CALCULATOR];
  31165. },
  31166. enumerable: true
  31167. });
  31168. Object.defineProperty(LRUCache.prototype, 'length', {
  31169. get: function get() {
  31170. return this[LENGTH];
  31171. },
  31172. enumerable: true
  31173. });
  31174. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  31175. get: function get() {
  31176. return this[LRU_LIST].length;
  31177. },
  31178. enumerable: true
  31179. });
  31180. LRUCache.prototype.rforEach = function (fn, thisp) {
  31181. thisp = thisp || this;
  31182. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  31183. var prev = walker.prev;
  31184. forEachStep(this, fn, walker, thisp);
  31185. walker = prev;
  31186. }
  31187. };
  31188. function forEachStep(self, fn, node, thisp) {
  31189. var hit = node.value;
  31190. if (isStale(self, hit)) {
  31191. del$1(self, node);
  31192. if (!self[ALLOW_STALE]) {
  31193. hit = undefined;
  31194. }
  31195. }
  31196. if (hit) {
  31197. fn.call(thisp, hit.value, hit.key, self);
  31198. }
  31199. }
  31200. LRUCache.prototype.forEach = function (fn, thisp) {
  31201. thisp = thisp || this;
  31202. for (var walker = this[LRU_LIST].head; walker !== null;) {
  31203. var next = walker.next;
  31204. forEachStep(this, fn, walker, thisp);
  31205. walker = next;
  31206. }
  31207. };
  31208. LRUCache.prototype.keys = function () {
  31209. return this[LRU_LIST].toArray().map(function (k) {
  31210. return k.key;
  31211. }, this);
  31212. };
  31213. LRUCache.prototype.values = function () {
  31214. return this[LRU_LIST].toArray().map(function (k) {
  31215. return k.value;
  31216. }, this);
  31217. };
  31218. LRUCache.prototype.reset = function () {
  31219. if (this[DISPOSE] && this[LRU_LIST] && this[LRU_LIST].length) {
  31220. this[LRU_LIST].forEach(function (hit) {
  31221. this[DISPOSE](hit.key, hit.value);
  31222. }, this);
  31223. }
  31224. this[CACHE] = new map$1(); // hash of items by key
  31225. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  31226. this[LENGTH] = 0; // length of items in the list
  31227. };
  31228. LRUCache.prototype.dump = function () {
  31229. return this[LRU_LIST].map(function (hit) {
  31230. if (!isStale(this, hit)) {
  31231. return {
  31232. k: hit.key,
  31233. v: hit.value,
  31234. e: hit.now + (hit.maxAge || 0)
  31235. };
  31236. }
  31237. }, this).toArray().filter(function (h) {
  31238. return h;
  31239. });
  31240. };
  31241. LRUCache.prototype.dumpLru = function () {
  31242. return this[LRU_LIST];
  31243. };
  31244. LRUCache.prototype.inspect = function (n, opts) {
  31245. var str = 'LRUCache {';
  31246. var extras = false;
  31247. var as = this[ALLOW_STALE];
  31248. if (as) {
  31249. str += '\n allowStale: true';
  31250. extras = true;
  31251. }
  31252. var max = this[MAX];
  31253. if (max && max !== Infinity) {
  31254. if (extras) {
  31255. str += ',';
  31256. }
  31257. str += '\n max: ' + util.inspect(max, opts);
  31258. extras = true;
  31259. }
  31260. var maxAge = this[MAX_AGE];
  31261. if (maxAge) {
  31262. if (extras) {
  31263. str += ',';
  31264. }
  31265. str += '\n maxAge: ' + util.inspect(maxAge, opts);
  31266. extras = true;
  31267. }
  31268. var lc = this[LENGTH_CALCULATOR];
  31269. if (lc && lc !== naiveLength) {
  31270. if (extras) {
  31271. str += ',';
  31272. }
  31273. str += '\n length: ' + util.inspect(this[LENGTH], opts);
  31274. extras = true;
  31275. }
  31276. var didFirst = false;
  31277. this[LRU_LIST].forEach(function (item) {
  31278. if (didFirst) {
  31279. str += ',\n ';
  31280. } else {
  31281. if (extras) {
  31282. str += ',\n';
  31283. }
  31284. didFirst = true;
  31285. str += '\n ';
  31286. }
  31287. var key = util.inspect(item.key).split('\n').join('\n ');
  31288. var val = {
  31289. value: item.value
  31290. };
  31291. if (item.maxAge !== maxAge) {
  31292. val.maxAge = item.maxAge;
  31293. }
  31294. if (lc !== naiveLength) {
  31295. val.length = item.length;
  31296. }
  31297. if (isStale(this, item)) {
  31298. val.stale = true;
  31299. }
  31300. val = util.inspect(val, opts).split('\n').join('\n ');
  31301. str += key + ' => ' + val;
  31302. });
  31303. if (didFirst || extras) {
  31304. str += '\n';
  31305. }
  31306. str += '}';
  31307. return str;
  31308. };
  31309. LRUCache.prototype.set = function (key, value, maxAge) {
  31310. maxAge = maxAge || this[MAX_AGE];
  31311. var now = maxAge ? Date.now() : 0;
  31312. var len = this[LENGTH_CALCULATOR](value, key);
  31313. if (this[CACHE].has(key)) {
  31314. if (len > this[MAX]) {
  31315. del$1(this, this[CACHE].get(key));
  31316. return false;
  31317. }
  31318. var node = this[CACHE].get(key);
  31319. var item = node.value; // dispose of the old one before overwriting
  31320. // split out into 2 ifs for better coverage tracking
  31321. if (this[DISPOSE]) {
  31322. if (!this[NO_DISPOSE_ON_SET]) {
  31323. this[DISPOSE](key, item.value);
  31324. }
  31325. }
  31326. item.now = now;
  31327. item.maxAge = maxAge;
  31328. item.value = value;
  31329. this[LENGTH] += len - item.length;
  31330. item.length = len;
  31331. this.get(key);
  31332. trim$2(this);
  31333. return true;
  31334. }
  31335. var hit = new Entry(key, value, len, now, maxAge); // oversized objects fall out of cache automatically.
  31336. if (hit.length > this[MAX]) {
  31337. if (this[DISPOSE]) {
  31338. this[DISPOSE](key, value);
  31339. }
  31340. return false;
  31341. }
  31342. this[LENGTH] += hit.length;
  31343. this[LRU_LIST].unshift(hit);
  31344. this[CACHE].set(key, this[LRU_LIST].head);
  31345. trim$2(this);
  31346. return true;
  31347. };
  31348. LRUCache.prototype.has = function (key) {
  31349. if (!this[CACHE].has(key)) return false;
  31350. var hit = this[CACHE].get(key).value;
  31351. if (isStale(this, hit)) {
  31352. return false;
  31353. }
  31354. return true;
  31355. };
  31356. LRUCache.prototype.get = function (key) {
  31357. return get(this, key, true);
  31358. };
  31359. LRUCache.prototype.peek = function (key) {
  31360. return get(this, key, false);
  31361. };
  31362. LRUCache.prototype.pop = function () {
  31363. var node = this[LRU_LIST].tail;
  31364. if (!node) return null;
  31365. del$1(this, node);
  31366. return node.value;
  31367. };
  31368. LRUCache.prototype.del = function (key) {
  31369. del$1(this, this[CACHE].get(key));
  31370. };
  31371. LRUCache.prototype.load = function (arr) {
  31372. // reset the cache
  31373. this.reset();
  31374. var now = Date.now(); // A previous serialized cache has the most recent items first
  31375. for (var l = arr.length - 1; l >= 0; l--) {
  31376. var hit = arr[l];
  31377. var expiresAt = hit.e || 0;
  31378. if (expiresAt === 0) {
  31379. // the item was created without expiration in a non aged cache
  31380. this.set(hit.k, hit.v);
  31381. } else {
  31382. var maxAge = expiresAt - now; // dont add already expired items
  31383. if (maxAge > 0) {
  31384. this.set(hit.k, hit.v, maxAge);
  31385. }
  31386. }
  31387. }
  31388. };
  31389. LRUCache.prototype.prune = function () {
  31390. var self = this;
  31391. this[CACHE].forEach(function (value, key) {
  31392. get(self, key, false);
  31393. });
  31394. };
  31395. function get(self, key, doUse) {
  31396. var node = self[CACHE].get(key);
  31397. if (node) {
  31398. var hit = node.value;
  31399. if (isStale(self, hit)) {
  31400. del$1(self, node);
  31401. if (!self[ALLOW_STALE]) hit = undefined;
  31402. } else {
  31403. if (doUse) {
  31404. self[LRU_LIST].unshiftNode(node);
  31405. }
  31406. }
  31407. if (hit) hit = hit.value;
  31408. }
  31409. return hit;
  31410. }
  31411. function isStale(self, hit) {
  31412. if (!hit || !hit.maxAge && !self[MAX_AGE]) {
  31413. return false;
  31414. }
  31415. var stale = false;
  31416. var diff = Date.now() - hit.now;
  31417. if (hit.maxAge) {
  31418. stale = diff > hit.maxAge;
  31419. } else {
  31420. stale = self[MAX_AGE] && diff > self[MAX_AGE];
  31421. }
  31422. return stale;
  31423. }
  31424. function trim$2(self) {
  31425. if (self[LENGTH] > self[MAX]) {
  31426. for (var walker = self[LRU_LIST].tail; self[LENGTH] > self[MAX] && walker !== null;) {
  31427. // We know that we're about to delete this one, and also
  31428. // what the next least recently used key will be, so just
  31429. // go ahead and set it now.
  31430. var prev = walker.prev;
  31431. del$1(self, walker);
  31432. walker = prev;
  31433. }
  31434. }
  31435. }
  31436. function del$1(self, node) {
  31437. if (node) {
  31438. var hit = node.value;
  31439. if (self[DISPOSE]) {
  31440. self[DISPOSE](hit.key, hit.value);
  31441. }
  31442. self[LENGTH] -= hit.length;
  31443. self[CACHE].delete(hit.key);
  31444. self[LRU_LIST].removeNode(node);
  31445. }
  31446. } // classy, since V8 prefers predictable objects.
  31447. function Entry(key, value, length, now, maxAge) {
  31448. this.key = key;
  31449. this.value = value;
  31450. this.length = length;
  31451. this.now = now;
  31452. this.maxAge = maxAge || 0;
  31453. }
  31454. var sigmund_1 = sigmund;
  31455. function sigmund(subject, maxSessions) {
  31456. maxSessions = maxSessions || 10;
  31457. var notes = [];
  31458. var analysis = '';
  31459. var RE = RegExp;
  31460. function psychoAnalyze(subject, session) {
  31461. if (session > maxSessions) return;
  31462. if (typeof subject === 'function' || typeof subject === 'undefined') {
  31463. return;
  31464. }
  31465. if (typeof subject !== 'object' || !subject || subject instanceof RE) {
  31466. analysis += subject;
  31467. return;
  31468. }
  31469. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  31470. notes.push(subject);
  31471. analysis += '{';
  31472. Object.keys(subject).forEach(function (issue, _, __) {
  31473. // pseudo-private values. skip those.
  31474. if (issue.charAt(0) === '_') return;
  31475. var to = typeof subject[issue];
  31476. if (to === 'function' || to === 'undefined') return;
  31477. analysis += issue;
  31478. psychoAnalyze(subject[issue], session + 1);
  31479. });
  31480. }
  31481. psychoAnalyze(subject, 0);
  31482. return analysis;
  31483. } // vim: set softtabstop=4 shiftwidth=4:
  31484. var fnmatch = createCommonjsModule(function (module, exports) {
  31485. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  31486. var platform = typeof process === "object" ? process.platform : "win32";
  31487. if (module) module.exports = minimatch;else exports.minimatch = minimatch;
  31488. minimatch.Minimatch = Minimatch;
  31489. var cache = minimatch.cache = new lruCache({
  31490. max: 100
  31491. }),
  31492. GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  31493. var qmark = "[^/]" // * => any number of characters
  31494. ,
  31495. star = qmark + "*?" // ** when dots are allowed. Anything goes, except .. and .
  31496. // not (^ or / followed by one or two dots followed by $ or /),
  31497. // followed by anything, any number of times.
  31498. ,
  31499. twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" // not a ^ or / followed by a dot,
  31500. // followed by anything, any number of times.
  31501. ,
  31502. twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" // characters that need to be escaped in RegExp.
  31503. ,
  31504. reSpecials = charSet("().*{}+?[]^$\\!"); // "abc" -> { a:true, b:true, c:true }
  31505. function charSet(s) {
  31506. return s.split("").reduce(function (set, c) {
  31507. set[c] = true;
  31508. return set;
  31509. }, {});
  31510. } // normalizes slashes.
  31511. var slashSplit = /\/+/;
  31512. minimatch.monkeyPatch = monkeyPatch;
  31513. function monkeyPatch() {
  31514. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  31515. var orig = desc.value;
  31516. desc.value = function (p) {
  31517. if (p instanceof Minimatch) return p.match(this);
  31518. return orig.call(this, p);
  31519. };
  31520. Object.defineProperty(String.prototype, desc);
  31521. }
  31522. minimatch.filter = filter;
  31523. function filter(pattern, options) {
  31524. options = options || {};
  31525. return function (p, i, list) {
  31526. return minimatch(p, pattern, options);
  31527. };
  31528. }
  31529. function ext(a, b) {
  31530. a = a || {};
  31531. b = b || {};
  31532. var t = {};
  31533. Object.keys(b).forEach(function (k) {
  31534. t[k] = b[k];
  31535. });
  31536. Object.keys(a).forEach(function (k) {
  31537. t[k] = a[k];
  31538. });
  31539. return t;
  31540. }
  31541. minimatch.defaults = function (def) {
  31542. if (!def || !Object.keys(def).length) return minimatch;
  31543. var orig = minimatch;
  31544. var m = function minimatch(p, pattern, options) {
  31545. return orig.minimatch(p, pattern, ext(def, options));
  31546. };
  31547. m.Minimatch = function Minimatch(pattern, options) {
  31548. return new orig.Minimatch(pattern, ext(def, options));
  31549. };
  31550. return m;
  31551. };
  31552. Minimatch.defaults = function (def) {
  31553. if (!def || !Object.keys(def).length) return Minimatch;
  31554. return minimatch.defaults(def).Minimatch;
  31555. };
  31556. function minimatch(p, pattern, options) {
  31557. if (typeof pattern !== "string") {
  31558. throw new TypeError("glob pattern string required");
  31559. }
  31560. if (!options) options = {}; // shortcut: comments match nothing.
  31561. if (!options.nocomment && pattern.charAt(0) === "#") {
  31562. return false;
  31563. } // "" only matches ""
  31564. if (pattern.trim() === "") return p === "";
  31565. return new Minimatch(pattern, options).match(p);
  31566. }
  31567. function Minimatch(pattern, options) {
  31568. if (!(this instanceof Minimatch)) {
  31569. return new Minimatch(pattern, options, cache);
  31570. }
  31571. if (typeof pattern !== "string") {
  31572. throw new TypeError("glob pattern string required");
  31573. }
  31574. if (!options) options = {}; // windows: need to use /, not \
  31575. // On other platforms, \ is a valid (albeit bad) filename char.
  31576. if (platform === "win32") {
  31577. pattern = pattern.split("\\").join("/");
  31578. } // lru storage.
  31579. // these things aren't particularly big, but walking down the string
  31580. // and turning it into a regexp can get pretty costly.
  31581. var cacheKey = pattern + "\n" + sigmund_1(options);
  31582. var cached = minimatch.cache.get(cacheKey);
  31583. if (cached) return cached;
  31584. minimatch.cache.set(cacheKey, this);
  31585. this.options = options;
  31586. this.set = [];
  31587. this.pattern = pattern;
  31588. this.regexp = null;
  31589. this.negate = false;
  31590. this.comment = false;
  31591. this.empty = false; // make the set of regexps etc.
  31592. this.make();
  31593. }
  31594. Minimatch.prototype.make = make;
  31595. function make() {
  31596. // don't do it more than once.
  31597. if (this._made) return;
  31598. var pattern = this.pattern;
  31599. var options = this.options; // empty patterns and comments match nothing.
  31600. if (!options.nocomment && pattern.charAt(0) === "#") {
  31601. this.comment = true;
  31602. return;
  31603. }
  31604. if (!pattern) {
  31605. this.empty = true;
  31606. return;
  31607. } // step 1: figure out negation, etc.
  31608. this.parseNegate(); // step 2: expand braces
  31609. var set = this.globSet = this.braceExpand();
  31610. 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
  31611. // matching patterns.
  31612. // These will be regexps, except in the case of "**", which is
  31613. // set to the GLOBSTAR object for globstar behavior,
  31614. // and will not contain any / characters
  31615. set = this.globParts = set.map(function (s) {
  31616. return s.split(slashSplit);
  31617. });
  31618. if (options.debug) console.error(this.pattern, set); // glob --> regexps
  31619. set = set.map(function (s, si, set) {
  31620. return s.map(this.parse, this);
  31621. }, this);
  31622. if (options.debug) console.error(this.pattern, set); // filter out everything that didn't compile properly.
  31623. set = set.filter(function (s) {
  31624. return -1 === s.indexOf(false);
  31625. });
  31626. if (options.debug) console.error(this.pattern, set);
  31627. this.set = set;
  31628. }
  31629. Minimatch.prototype.parseNegate = parseNegate;
  31630. function parseNegate() {
  31631. var pattern = this.pattern,
  31632. negate = false,
  31633. options = this.options,
  31634. negateOffset = 0;
  31635. if (options.nonegate) return;
  31636. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === "!"; i++) {
  31637. negate = !negate;
  31638. negateOffset++;
  31639. }
  31640. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  31641. this.negate = negate;
  31642. } // Brace expansion:
  31643. // a{b,c}d -> abd acd
  31644. // a{b,}c -> abc ac
  31645. // a{0..3}d -> a0d a1d a2d a3d
  31646. // a{b,c{d,e}f}g -> abg acdfg acefg
  31647. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  31648. //
  31649. // Invalid sets are not expanded.
  31650. // a{2..}b -> a{2..}b
  31651. // a{b}c -> a{b}c
  31652. minimatch.braceExpand = function (pattern, options) {
  31653. return new Minimatch(pattern, options).braceExpand();
  31654. };
  31655. Minimatch.prototype.braceExpand = braceExpand;
  31656. function braceExpand(pattern, options) {
  31657. options = options || this.options;
  31658. pattern = typeof pattern === "undefined" ? this.pattern : pattern;
  31659. if (typeof pattern === "undefined") {
  31660. throw new Error("undefined pattern");
  31661. }
  31662. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  31663. // shortcut. no need to expand.
  31664. return [pattern];
  31665. }
  31666. var escaping = false; // examples and comments refer to this crazy pattern:
  31667. // a{b,c{d,e},{f,g}h}x{y,z}
  31668. // expected:
  31669. // abxy
  31670. // abxz
  31671. // acdxy
  31672. // acdxz
  31673. // acexy
  31674. // acexz
  31675. // afhxy
  31676. // afhxz
  31677. // aghxy
  31678. // aghxz
  31679. // everything before the first \{ is just a prefix.
  31680. // So, we pluck that off, and work with the rest,
  31681. // and then prepend it to everything we find.
  31682. if (pattern.charAt(0) !== "{") {
  31683. // console.error(pattern)
  31684. var prefix = null;
  31685. for (var i = 0, l = pattern.length; i < l; i++) {
  31686. var c = pattern.charAt(i); // console.error(i, c)
  31687. if (c === "\\") {
  31688. escaping = !escaping;
  31689. } else if (c === "{" && !escaping) {
  31690. prefix = pattern.substr(0, i);
  31691. break;
  31692. }
  31693. } // actually no sets, all { were escaped.
  31694. if (prefix === null) {
  31695. // console.error("no sets")
  31696. return [pattern];
  31697. }
  31698. var tail = braceExpand(pattern.substr(i), options);
  31699. return tail.map(function (t) {
  31700. return prefix + t;
  31701. });
  31702. } // now we have something like:
  31703. // {b,c{d,e},{f,g}h}x{y,z}
  31704. // walk through the set, expanding each part, until
  31705. // the set ends. then, we'll expand the suffix.
  31706. // If the set only has a single member, then'll put the {} back
  31707. // first, handle numeric sets, since they're easier
  31708. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  31709. if (numset) {
  31710. // console.error("numset", numset[1], numset[2])
  31711. var suf = braceExpand(pattern.substr(numset[0].length), options),
  31712. start = +numset[1],
  31713. end = +numset[2],
  31714. inc = start > end ? -1 : 1,
  31715. set = [];
  31716. for (var i = start; i != end + inc; i += inc) {
  31717. // append all the suffixes
  31718. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  31719. set.push(i + suf[ii]);
  31720. }
  31721. }
  31722. return set;
  31723. } // ok, walk through the set
  31724. // We hope, somewhat optimistically, that there
  31725. // will be a } at the end.
  31726. // If the closing brace isn't found, then the pattern is
  31727. // interpreted as braceExpand("\\" + pattern) so that
  31728. // the leading \{ will be interpreted literally.
  31729. var i = 1 // skip the \{
  31730. ,
  31731. depth = 1,
  31732. set = [],
  31733. member = "",
  31734. sawEnd = false,
  31735. escaping = false;
  31736. function addMember() {
  31737. set.push(member);
  31738. member = "";
  31739. } // console.error("Entering for")
  31740. FOR: for (i = 1, l = pattern.length; i < l; i++) {
  31741. var c = pattern.charAt(i); // console.error("", i, c)
  31742. if (escaping) {
  31743. escaping = false;
  31744. member += "\\" + c;
  31745. } else {
  31746. switch (c) {
  31747. case "\\":
  31748. escaping = true;
  31749. continue;
  31750. case "{":
  31751. depth++;
  31752. member += "{";
  31753. continue;
  31754. case "}":
  31755. depth--; // if this closes the actual set, then we're done
  31756. if (depth === 0) {
  31757. addMember(); // pluck off the close-brace
  31758. i++;
  31759. break FOR;
  31760. } else {
  31761. member += c;
  31762. continue;
  31763. }
  31764. case ",":
  31765. if (depth === 1) {
  31766. addMember();
  31767. } else {
  31768. member += c;
  31769. }
  31770. continue;
  31771. default:
  31772. member += c;
  31773. continue;
  31774. } // switch
  31775. } // else
  31776. } // for
  31777. // now we've either finished the set, and the suffix is
  31778. // pattern.substr(i), or we have *not* closed the set,
  31779. // and need to escape the leading brace
  31780. if (depth !== 0) {
  31781. // console.error("didn't close", pattern)
  31782. return braceExpand("\\" + pattern, options);
  31783. } // x{y,z} -> ["xy", "xz"]
  31784. // console.error("set", set)
  31785. // console.error("suffix", pattern.substr(i))
  31786. var suf = braceExpand(pattern.substr(i), options); // ["b", "c{d,e}","{f,g}h"] ->
  31787. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  31788. var addBraces = set.length === 1; // console.error("set pre-expanded", set)
  31789. set = set.map(function (p) {
  31790. return braceExpand(p, options);
  31791. }); // console.error("set expanded", set)
  31792. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  31793. // ["b", "cd", "ce", "fh", "gh"]
  31794. set = set.reduce(function (l, r) {
  31795. return l.concat(r);
  31796. });
  31797. if (addBraces) {
  31798. set = set.map(function (s) {
  31799. return "{" + s + "}";
  31800. });
  31801. } // now attach the suffixes.
  31802. var ret = [];
  31803. for (var i = 0, l = set.length; i < l; i++) {
  31804. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  31805. ret.push(set[i] + suf[ii]);
  31806. }
  31807. }
  31808. return ret;
  31809. } // parse a component of the expanded set.
  31810. // At this point, no pattern may contain "/" in it
  31811. // so we're going to return a 2d array, where each entry is the full
  31812. // pattern, split on '/', and then turned into a regular expression.
  31813. // A regexp is made at the end which joins each array with an
  31814. // escaped /, and another full one which joins each regexp with |.
  31815. //
  31816. // Following the lead of Bash 4.1, note that "**" only has special meaning
  31817. // when it is the *only* thing in a path portion. Otherwise, any series
  31818. // of * is equivalent to a single *. Globstar behavior is enabled by
  31819. // default, and can be disabled by setting options.noglobstar.
  31820. Minimatch.prototype.parse = parse;
  31821. var SUBPARSE = {};
  31822. function parse(pattern, isSub) {
  31823. var options = this.options; // shortcuts
  31824. if (!options.noglobstar && pattern === "**") return GLOBSTAR;
  31825. if (pattern === "") return "";
  31826. var re = "",
  31827. hasMagic = !!options.nocase,
  31828. escaping = false // ? => one single character
  31829. ,
  31830. patternListStack = [],
  31831. plType,
  31832. stateChar,
  31833. inClass = false,
  31834. reClassStart = -1,
  31835. classStart = -1 // . and .. never match anything that doesn't start with .,
  31836. // even when options.dot is set.
  31837. ,
  31838. patternStart = pattern.charAt(0) === "." ? "" // anything
  31839. // not (start or / followed by . or .. followed by / or end)
  31840. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" : "(?!\\.)";
  31841. function clearStateChar() {
  31842. if (stateChar) {
  31843. // we had some state-tracking character
  31844. // that wasn't consumed by this pass.
  31845. switch (stateChar) {
  31846. case "*":
  31847. re += star;
  31848. hasMagic = true;
  31849. break;
  31850. case "?":
  31851. re += qmark;
  31852. hasMagic = true;
  31853. break;
  31854. default:
  31855. re += "\\" + stateChar;
  31856. break;
  31857. }
  31858. stateChar = false;
  31859. }
  31860. }
  31861. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  31862. if (options.debug) {
  31863. console.error("%s\t%s %s %j", pattern, i, re, c);
  31864. } // skip over any that are escaped.
  31865. if (escaping && reSpecials[c]) {
  31866. re += "\\" + c;
  31867. escaping = false;
  31868. continue;
  31869. }
  31870. SWITCH: switch (c) {
  31871. case "/":
  31872. // completely not allowed, even escaped.
  31873. // Should already be path-split by now.
  31874. return false;
  31875. case "\\":
  31876. clearStateChar();
  31877. escaping = true;
  31878. continue;
  31879. // the various stateChar values
  31880. // for the "extglob" stuff.
  31881. case "?":
  31882. case "*":
  31883. case "+":
  31884. case "@":
  31885. case "!":
  31886. if (options.debug) {
  31887. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  31888. } // all of those are literals inside a class, except that
  31889. // the glob [!a] means [^a] in regexp
  31890. if (inClass) {
  31891. if (c === "!" && i === classStart + 1) c = "^";
  31892. re += c;
  31893. continue;
  31894. } // if we already have a stateChar, then it means
  31895. // that there was something like ** or +? in there.
  31896. // Handle the stateChar, then proceed with this one.
  31897. clearStateChar();
  31898. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  31899. // just clear the statechar *now*, rather than even diving into
  31900. // the patternList stuff.
  31901. if (options.noext) clearStateChar();
  31902. continue;
  31903. case "(":
  31904. if (inClass) {
  31905. re += "(";
  31906. continue;
  31907. }
  31908. if (!stateChar) {
  31909. re += "\\(";
  31910. continue;
  31911. }
  31912. plType = stateChar;
  31913. patternListStack.push({
  31914. type: plType,
  31915. start: i - 1,
  31916. reStart: re.length
  31917. }); // negation is (?:(?!js)[^/]*)
  31918. re += stateChar === "!" ? "(?:(?!" : "(?:";
  31919. stateChar = false;
  31920. continue;
  31921. case ")":
  31922. if (inClass || !patternListStack.length) {
  31923. re += "\\)";
  31924. continue;
  31925. }
  31926. hasMagic = true;
  31927. re += ")";
  31928. plType = patternListStack.pop().type; // negation is (?:(?!js)[^/]*)
  31929. // The others are (?:<pattern>)<type>
  31930. switch (plType) {
  31931. case "!":
  31932. re += "[^/]*?)";
  31933. break;
  31934. case "?":
  31935. case "+":
  31936. case "*":
  31937. re += plType;
  31938. case "@":
  31939. break;
  31940. // the default anyway
  31941. }
  31942. continue;
  31943. case "|":
  31944. if (inClass || !patternListStack.length || escaping) {
  31945. re += "\\|";
  31946. escaping = false;
  31947. continue;
  31948. }
  31949. re += "|";
  31950. continue;
  31951. // these are mostly the same in regexp and glob
  31952. case "[":
  31953. // swallow any state-tracking char before the [
  31954. clearStateChar();
  31955. if (inClass) {
  31956. re += "\\" + c;
  31957. continue;
  31958. }
  31959. inClass = true;
  31960. classStart = i;
  31961. reClassStart = re.length;
  31962. re += c;
  31963. continue;
  31964. case "]":
  31965. // a right bracket shall lose its special
  31966. // meaning and represent itself in
  31967. // a bracket expression if it occurs
  31968. // first in the list. -- POSIX.2 2.8.3.2
  31969. if (i === classStart + 1 || !inClass) {
  31970. re += "\\" + c;
  31971. escaping = false;
  31972. continue;
  31973. } // finish up the class.
  31974. hasMagic = true;
  31975. inClass = false;
  31976. re += c;
  31977. continue;
  31978. default:
  31979. // swallow any state char that wasn't consumed
  31980. clearStateChar();
  31981. if (escaping) {
  31982. // no need
  31983. escaping = false;
  31984. } else if (reSpecials[c] && !(c === "^" && inClass)) {
  31985. re += "\\";
  31986. }
  31987. re += c;
  31988. } // switch
  31989. } // for
  31990. // handle the case where we left a class open.
  31991. // "[abc" is valid, equivalent to "\[abc"
  31992. if (inClass) {
  31993. // split where the last [ was, and escape it
  31994. // this is a huge pita. We now have to re-walk
  31995. // the contents of the would-be class to re-translate
  31996. // any characters that were passed through as-is
  31997. var cs = pattern.substr(classStart + 1),
  31998. sp = this.parse(cs, SUBPARSE);
  31999. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  32000. hasMagic = hasMagic || sp[1];
  32001. } // handle the case where we had a +( thing at the *end*
  32002. // of the pattern.
  32003. // each pattern list stack adds 3 chars, and we need to go through
  32004. // and escape any | chars that were passed through as-is for the regexp.
  32005. // Go through and escape them, taking care not to double-escape any
  32006. // | chars that were already escaped.
  32007. var pl;
  32008. while (pl = patternListStack.pop()) {
  32009. var tail = re.slice(pl.reStart + 3); // maybe some even number of \, then maybe 1 \, followed by a |
  32010. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  32011. if (!$2) {
  32012. // the | isn't already escaped, so escape it.
  32013. $2 = "\\";
  32014. } // need to escape all those slashes *again*, without escaping the
  32015. // one that we need for escaping the | character. As it works out,
  32016. // escaping an even number of slashes can be done by simply repeating
  32017. // it exactly after itself. That's why this trick works.
  32018. //
  32019. // I am sorry that you have to see this.
  32020. return $1 + $1 + $2 + "|";
  32021. }); // console.error("tail=%j\n %s", tail, tail)
  32022. var t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
  32023. hasMagic = true;
  32024. re = re.slice(0, pl.reStart) + t + "\\(" + tail;
  32025. } // handle trailing things that only matter at the very end.
  32026. clearStateChar();
  32027. if (escaping) {
  32028. // trailing \\
  32029. re += "\\\\";
  32030. } // only need to apply the nodot start if the re starts with
  32031. // something that could conceivably capture a dot
  32032. var addPatternStart = false;
  32033. switch (re.charAt(0)) {
  32034. case ".":
  32035. case "[":
  32036. case "(":
  32037. addPatternStart = true;
  32038. } // if the re is not "" at this point, then we need to make sure
  32039. // it doesn't match against an empty path part.
  32040. // Otherwise a/* will match a/, which it should not.
  32041. if (re !== "" && hasMagic) re = "(?=.)" + re;
  32042. if (addPatternStart) re = patternStart + re; // parsing just a piece of a larger pattern.
  32043. if (isSub === SUBPARSE) {
  32044. return [re, hasMagic];
  32045. } // skip the regexp for non-magical patterns
  32046. // unescape anything in it, though, so that it'll be
  32047. // an exact match against a file etc.
  32048. if (!hasMagic) {
  32049. return globUnescape(pattern);
  32050. }
  32051. var flags = options.nocase ? "i" : "",
  32052. regExp = new RegExp("^" + re + "$", flags);
  32053. regExp._glob = pattern;
  32054. regExp._src = re;
  32055. return regExp;
  32056. }
  32057. minimatch.makeRe = function (pattern, options) {
  32058. return new Minimatch(pattern, options || {}).makeRe();
  32059. };
  32060. Minimatch.prototype.makeRe = makeRe;
  32061. function makeRe() {
  32062. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  32063. // pattern strings, or "**".
  32064. //
  32065. // It's better to use .match(). This function shouldn't
  32066. // be used, really, but it's pretty convenient sometimes,
  32067. // when you just want to work with a regex.
  32068. var set = this.set;
  32069. if (!set.length) return this.regexp = false;
  32070. var options = this.options;
  32071. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot,
  32072. flags = options.nocase ? "i" : "";
  32073. var re = set.map(function (pattern) {
  32074. return pattern.map(function (p) {
  32075. return p === GLOBSTAR ? twoStar : typeof p === "string" ? regExpEscape(p) : p._src;
  32076. }).join("\\\/");
  32077. }).join("|"); // must match entire pattern
  32078. // ending in a * or ** will make it less strict.
  32079. re = "^(?:" + re + ")$"; // can match anything, as long as it's not this.
  32080. if (this.negate) re = "^(?!" + re + ").*$";
  32081. try {
  32082. return this.regexp = new RegExp(re, flags);
  32083. } catch (ex) {
  32084. return this.regexp = false;
  32085. }
  32086. }
  32087. minimatch.match = function (list, pattern, options) {
  32088. var mm = new Minimatch(pattern, options);
  32089. list = list.filter(function (f) {
  32090. return mm.match(f);
  32091. });
  32092. if (options.nonull && !list.length) {
  32093. list.push(pattern);
  32094. }
  32095. return list;
  32096. };
  32097. Minimatch.prototype.match = match;
  32098. function match(f, partial) {
  32099. // console.error("match", f, this.pattern)
  32100. // short-circuit in the case of busted things.
  32101. // comments, etc.
  32102. if (this.comment) return false;
  32103. if (this.empty) return f === "";
  32104. if (f === "/" && partial) return true;
  32105. var options = this.options; // windows: need to use /, not \
  32106. // On other platforms, \ is a valid (albeit bad) filename char.
  32107. if (platform === "win32") {
  32108. f = f.split("\\").join("/");
  32109. } // treat the test path as a set of pathparts.
  32110. f = f.split(slashSplit);
  32111. if (options.debug) {
  32112. console.error(this.pattern, "split", f);
  32113. } // just ONE of the pattern sets in this.set needs to match
  32114. // in order for it to be valid. If negating, then just one
  32115. // match means that we have failed.
  32116. // Either way, return on the first hit.
  32117. var set = this.set; // console.error(this.pattern, "set", set)
  32118. for (var i = 0, l = set.length; i < l; i++) {
  32119. var pattern = set[i];
  32120. var hit = this.matchOne(f, pattern, partial);
  32121. if (hit) {
  32122. if (options.flipNegate) return true;
  32123. return !this.negate;
  32124. }
  32125. } // didn't get any hits. this is success if it's a negative
  32126. // pattern, failure otherwise.
  32127. if (options.flipNegate) return false;
  32128. return this.negate;
  32129. } // set partial to true to test if, for example,
  32130. // "/a/b" matches the start of "/*/b/*/d"
  32131. // Partial means, if you run out of file before you run
  32132. // out of pattern, then that's fine, as long as all
  32133. // the parts match.
  32134. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  32135. var options = this.options;
  32136. if (options.debug) {
  32137. console.error("matchOne", {
  32138. "this": this,
  32139. file: file,
  32140. pattern: pattern
  32141. });
  32142. }
  32143. if (options.matchBase && pattern.length === 1) {
  32144. file = path.basename(file.join("/")).split("/");
  32145. }
  32146. if (options.debug) {
  32147. console.error("matchOne", file.length, pattern.length);
  32148. }
  32149. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  32150. if (options.debug) {
  32151. console.error("matchOne loop");
  32152. }
  32153. var p = pattern[pi],
  32154. f = file[fi];
  32155. if (options.debug) {
  32156. console.error(pattern, p, f);
  32157. } // should be impossible.
  32158. // some invalid regexp stuff in the set.
  32159. if (p === false) return false;
  32160. if (p === GLOBSTAR) {
  32161. if (options.debug) console.error('GLOBSTAR', [pattern, p, f]); // "**"
  32162. // a/**/b/**/c would match the following:
  32163. // a/b/x/y/z/c
  32164. // a/x/y/z/b/c
  32165. // a/b/x/b/x/c
  32166. // a/b/c
  32167. // To do this, take the rest of the pattern after
  32168. // the **, and see if it would match the file remainder.
  32169. // If so, return success.
  32170. // If not, the ** "swallows" a segment, and try again.
  32171. // This is recursively awful.
  32172. //
  32173. // a/**/b/**/c matching a/b/x/y/z/c
  32174. // - a matches a
  32175. // - doublestar
  32176. // - matchOne(b/x/y/z/c, b/**/c)
  32177. // - b matches b
  32178. // - doublestar
  32179. // - matchOne(x/y/z/c, c) -> no
  32180. // - matchOne(y/z/c, c) -> no
  32181. // - matchOne(z/c, c) -> no
  32182. // - matchOne(c, c) yes, hit
  32183. var fr = fi,
  32184. pr = pi + 1;
  32185. if (pr === pl) {
  32186. if (options.debug) console.error('** at the end'); // a ** at the end will just swallow the rest.
  32187. // We have found a match.
  32188. // however, it will not swallow /.x, unless
  32189. // options.dot is set.
  32190. // . and .. are *never* matched by **, for explosively
  32191. // exponential reasons.
  32192. for (; fi < fl; fi++) {
  32193. if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".") return false;
  32194. }
  32195. return true;
  32196. } // ok, let's see if we can swallow whatever we can.
  32197. WHILE: while (fr < fl) {
  32198. var swallowee = file[fr];
  32199. if (options.debug) {
  32200. console.error('\nglobstar while', file, fr, pattern, pr, swallowee);
  32201. } // XXX remove this slice. Just pass the start index.
  32202. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  32203. if (options.debug) console.error('globstar found match!', fr, fl, swallowee); // found a match.
  32204. return true;
  32205. } else {
  32206. // can't swallow "." or ".." ever.
  32207. // can only swallow ".foo" when explicitly asked.
  32208. if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
  32209. if (options.debug) console.error("dot detected!", file, fr, pattern, pr);
  32210. break WHILE;
  32211. } // ** swallows a segment, and continue.
  32212. if (options.debug) console.error('globstar swallow a segment, and continue');
  32213. fr++;
  32214. }
  32215. } // no match was found.
  32216. // However, in partial mode, we can't say this is necessarily over.
  32217. // If there's more *pattern* left, then
  32218. if (partial) {
  32219. // ran out of file
  32220. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  32221. if (fr === fl) return true;
  32222. }
  32223. return false;
  32224. } // something other than **
  32225. // non-magic patterns just have to match exactly
  32226. // patterns with magic have been turned into regexps.
  32227. var hit;
  32228. if (typeof p === "string") {
  32229. if (options.nocase) {
  32230. hit = f.toLowerCase() === p.toLowerCase();
  32231. } else {
  32232. hit = f === p;
  32233. }
  32234. if (options.debug) {
  32235. console.error("string match", p, f, hit);
  32236. }
  32237. } else {
  32238. hit = f.match(p);
  32239. if (options.debug) {
  32240. console.error("pattern match", p, f, hit);
  32241. }
  32242. }
  32243. if (!hit) return false;
  32244. } // Note: ending in / means that we'll get a final ""
  32245. // at the end of the pattern. This can only match a
  32246. // corresponding "" at the end of the file.
  32247. // If the file ends in /, then it can only match a
  32248. // a pattern that ends in /, unless the pattern just
  32249. // doesn't have any more for it. But, a/b/ should *not*
  32250. // match "a/b/*", even though "" matches against the
  32251. // [^/]*? pattern, except in partial mode, where it might
  32252. // simply not be reached yet.
  32253. // However, a/b/ should still satisfy a/*
  32254. // now either we fell off the end of the pattern, or we're done.
  32255. if (fi === fl && pi === pl) {
  32256. // ran out of pattern and filename at the same time.
  32257. // an exact hit!
  32258. return true;
  32259. } else if (fi === fl) {
  32260. // ran out of file, but still had pattern left.
  32261. // this is ok if we're doing the match as part of
  32262. // a glob fs traversal.
  32263. return partial;
  32264. } else if (pi === pl) {
  32265. // ran out of pattern, still have file left.
  32266. // this is only acceptable if we're on the very last
  32267. // empty segment of a file with a trailing slash.
  32268. // a/* should match a/b/
  32269. var emptyFileEnd = fi === fl - 1 && file[fi] === "";
  32270. return emptyFileEnd;
  32271. } // should be unreachable.
  32272. throw new Error("wtf?");
  32273. }; // replace stuff like \* with *
  32274. function globUnescape(s) {
  32275. return s.replace(/\\(.)/g, "$1");
  32276. }
  32277. function regExpEscape(s) {
  32278. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  32279. }
  32280. });
  32281. var ini = createCommonjsModule(function (module, exports) {
  32282. "use strict"; // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
  32283. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  32284. return new (P || (P = Promise))(function (resolve, reject) {
  32285. function fulfilled(value) {
  32286. try {
  32287. step(generator.next(value));
  32288. } catch (e) {
  32289. reject(e);
  32290. }
  32291. }
  32292. function rejected(value) {
  32293. try {
  32294. step(generator["throw"](value));
  32295. } catch (e) {
  32296. reject(e);
  32297. }
  32298. }
  32299. function step(result) {
  32300. result.done ? resolve(result.value) : new P(function (resolve) {
  32301. resolve(result.value);
  32302. }).then(fulfilled, rejected);
  32303. }
  32304. step((generator = generator.apply(thisArg, _arguments || [])).next());
  32305. });
  32306. };
  32307. var __generator = this && this.__generator || function (thisArg, body) {
  32308. var _ = {
  32309. label: 0,
  32310. sent: function sent() {
  32311. if (t[0] & 1) throw t[1];
  32312. return t[1];
  32313. },
  32314. trys: [],
  32315. ops: []
  32316. },
  32317. f,
  32318. y,
  32319. t,
  32320. g;
  32321. return g = {
  32322. next: verb(0),
  32323. "throw": verb(1),
  32324. "return": verb(2)
  32325. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  32326. return this;
  32327. }), g;
  32328. function verb(n) {
  32329. return function (v) {
  32330. return step([n, v]);
  32331. };
  32332. }
  32333. function step(op) {
  32334. if (f) throw new TypeError("Generator is already executing.");
  32335. while (_) {
  32336. try {
  32337. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  32338. if (y = 0, t) op = [op[0] & 2, t.value];
  32339. switch (op[0]) {
  32340. case 0:
  32341. case 1:
  32342. t = op;
  32343. break;
  32344. case 4:
  32345. _.label++;
  32346. return {
  32347. value: op[1],
  32348. done: false
  32349. };
  32350. case 5:
  32351. _.label++;
  32352. y = op[1];
  32353. op = [0];
  32354. continue;
  32355. case 7:
  32356. op = _.ops.pop();
  32357. _.trys.pop();
  32358. continue;
  32359. default:
  32360. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  32361. _ = 0;
  32362. continue;
  32363. }
  32364. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  32365. _.label = op[1];
  32366. break;
  32367. }
  32368. if (op[0] === 6 && _.label < t[1]) {
  32369. _.label = t[1];
  32370. t = op;
  32371. break;
  32372. }
  32373. if (t && _.label < t[2]) {
  32374. _.label = t[2];
  32375. _.ops.push(op);
  32376. break;
  32377. }
  32378. if (t[2]) _.ops.pop();
  32379. _.trys.pop();
  32380. continue;
  32381. }
  32382. op = body.call(thisArg, _);
  32383. } catch (e) {
  32384. op = [6, e];
  32385. y = 0;
  32386. } finally {
  32387. f = t = 0;
  32388. }
  32389. }
  32390. if (op[0] & 5) throw op[1];
  32391. return {
  32392. value: op[0] ? op[1] : void 0,
  32393. done: true
  32394. };
  32395. }
  32396. };
  32397. var __importStar = this && this.__importStar || function (mod) {
  32398. if (mod && mod.__esModule) return mod;
  32399. var result = {};
  32400. if (mod != null) for (var k in mod) {
  32401. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  32402. }
  32403. result["default"] = mod;
  32404. return result;
  32405. };
  32406. Object.defineProperty(exports, "__esModule", {
  32407. value: true
  32408. });
  32409. var fs$$2 = __importStar(fs);
  32410. /**
  32411. * define the possible values:
  32412. * section: [section]
  32413. * param: key=value
  32414. * comment: ;this is a comment
  32415. */
  32416. var regex = {
  32417. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  32418. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  32419. comment: /^\s*[#;].*$/
  32420. };
  32421. /**
  32422. * Parses an .ini file
  32423. * @param file The location of the .ini file
  32424. */
  32425. function parse(file) {
  32426. return __awaiter(this, void 0, void 0, function () {
  32427. return __generator(this, function (_a) {
  32428. return [2
  32429. /*return*/
  32430. , new Promise(function (resolve, reject) {
  32431. fs$$2.readFile(file, 'utf8', function (err, data) {
  32432. if (err) {
  32433. reject(err);
  32434. return;
  32435. }
  32436. resolve(parseString(data));
  32437. });
  32438. })];
  32439. });
  32440. });
  32441. }
  32442. exports.parse = parse;
  32443. function parseSync(file) {
  32444. return parseString(fs$$2.readFileSync(file, 'utf8'));
  32445. }
  32446. exports.parseSync = parseSync;
  32447. function parseString(data) {
  32448. var sectionBody = {};
  32449. var sectionName = null;
  32450. var value = [[sectionName, sectionBody]];
  32451. var lines = data.split(/\r\n|\r|\n/);
  32452. lines.forEach(function (line) {
  32453. var match;
  32454. if (regex.comment.test(line)) {
  32455. return;
  32456. }
  32457. if (regex.param.test(line)) {
  32458. match = line.match(regex.param);
  32459. sectionBody[match[1]] = match[2];
  32460. } else if (regex.section.test(line)) {
  32461. match = line.match(regex.section);
  32462. sectionName = match[1];
  32463. sectionBody = {};
  32464. value.push([sectionName, sectionBody]);
  32465. }
  32466. });
  32467. return value;
  32468. }
  32469. exports.parseString = parseString;
  32470. });
  32471. unwrapExports(ini);
  32472. var name$17 = "editorconfig";
  32473. var version$3 = "0.15.2";
  32474. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  32475. var keywords = ["editorconfig", "core"];
  32476. var main$1 = "src/index.js";
  32477. var contributors = ["Hong Xu (topbug.net)", "Jed Mao (https://github.com/jedmao/)", "Trey Hunner (http://treyhunner.com)"];
  32478. var directories = {
  32479. "bin": "./bin",
  32480. "lib": "./lib"
  32481. };
  32482. var scripts$1 = {
  32483. "clean": "rimraf dist",
  32484. "prebuild": "npm run clean",
  32485. "build": "tsc",
  32486. "pretest": "npm run lint && npm run build && npm run copy && cmake .",
  32487. "test": "ctest .",
  32488. "pretest:ci": "npm run pretest",
  32489. "test:ci": "ctest -VV --output-on-failure .",
  32490. "lint": "npm run eclint && npm run tslint",
  32491. "eclint": "eclint check --indent_size ignore \"src/**\"",
  32492. "tslint": "tslint --project tsconfig.json --exclude package.json",
  32493. "copy": "cpy .npmignore LICENSE README.md CHANGELOG.md dist && cpy bin/* dist/bin && cpy src/lib/fnmatch*.* dist/src/lib",
  32494. "prepub": "npm run lint && npm run build && npm run copy",
  32495. "pub": "npm publish ./dist"
  32496. };
  32497. var repository$1 = {
  32498. "type": "git",
  32499. "url": "git://github.com/editorconfig/editorconfig-core-js.git"
  32500. };
  32501. var bugs = "https://github.com/editorconfig/editorconfig-core-js/issues";
  32502. var author$1 = "EditorConfig Team";
  32503. var license$1 = "MIT";
  32504. var dependencies$1 = {
  32505. "@types/node": "^10.11.7",
  32506. "@types/semver": "^5.5.0",
  32507. "commander": "^2.19.0",
  32508. "lru-cache": "^4.1.3",
  32509. "semver": "^5.6.0",
  32510. "sigmund": "^1.0.1"
  32511. };
  32512. var devDependencies$1 = {
  32513. "@types/mocha": "^5.2.5",
  32514. "cpy-cli": "^2.0.0",
  32515. "eclint": "^2.8.0",
  32516. "mocha": "^5.2.0",
  32517. "rimraf": "^2.6.2",
  32518. "should": "^13.2.3",
  32519. "tslint": "^5.11.0",
  32520. "typescript": "^3.1.3"
  32521. };
  32522. var _package$2 = {
  32523. name: name$17,
  32524. version: version$3,
  32525. description: description$1,
  32526. keywords: keywords,
  32527. main: main$1,
  32528. contributors: contributors,
  32529. directories: directories,
  32530. scripts: scripts$1,
  32531. repository: repository$1,
  32532. bugs: bugs,
  32533. author: author$1,
  32534. license: license$1,
  32535. dependencies: dependencies$1,
  32536. devDependencies: devDependencies$1
  32537. };
  32538. var _package$3 = Object.freeze({
  32539. name: name$17,
  32540. version: version$3,
  32541. description: description$1,
  32542. keywords: keywords,
  32543. main: main$1,
  32544. contributors: contributors,
  32545. directories: directories,
  32546. scripts: scripts$1,
  32547. repository: repository$1,
  32548. bugs: bugs,
  32549. author: author$1,
  32550. license: license$1,
  32551. dependencies: dependencies$1,
  32552. devDependencies: devDependencies$1,
  32553. default: _package$2
  32554. });
  32555. var require$$4$6 = ( _package$3 && _package$2 ) || _package$3;
  32556. var src$2 = createCommonjsModule(function (module, exports) {
  32557. "use strict";
  32558. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  32559. return new (P || (P = Promise))(function (resolve, reject) {
  32560. function fulfilled(value) {
  32561. try {
  32562. step(generator.next(value));
  32563. } catch (e) {
  32564. reject(e);
  32565. }
  32566. }
  32567. function rejected(value) {
  32568. try {
  32569. step(generator["throw"](value));
  32570. } catch (e) {
  32571. reject(e);
  32572. }
  32573. }
  32574. function step(result) {
  32575. result.done ? resolve(result.value) : new P(function (resolve) {
  32576. resolve(result.value);
  32577. }).then(fulfilled, rejected);
  32578. }
  32579. step((generator = generator.apply(thisArg, _arguments || [])).next());
  32580. });
  32581. };
  32582. var __generator = this && this.__generator || function (thisArg, body) {
  32583. var _ = {
  32584. label: 0,
  32585. sent: function sent() {
  32586. if (t[0] & 1) throw t[1];
  32587. return t[1];
  32588. },
  32589. trys: [],
  32590. ops: []
  32591. },
  32592. f,
  32593. y,
  32594. t,
  32595. g;
  32596. return g = {
  32597. next: verb(0),
  32598. "throw": verb(1),
  32599. "return": verb(2)
  32600. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  32601. return this;
  32602. }), g;
  32603. function verb(n) {
  32604. return function (v) {
  32605. return step([n, v]);
  32606. };
  32607. }
  32608. function step(op) {
  32609. if (f) throw new TypeError("Generator is already executing.");
  32610. while (_) {
  32611. try {
  32612. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  32613. if (y = 0, t) op = [op[0] & 2, t.value];
  32614. switch (op[0]) {
  32615. case 0:
  32616. case 1:
  32617. t = op;
  32618. break;
  32619. case 4:
  32620. _.label++;
  32621. return {
  32622. value: op[1],
  32623. done: false
  32624. };
  32625. case 5:
  32626. _.label++;
  32627. y = op[1];
  32628. op = [0];
  32629. continue;
  32630. case 7:
  32631. op = _.ops.pop();
  32632. _.trys.pop();
  32633. continue;
  32634. default:
  32635. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  32636. _ = 0;
  32637. continue;
  32638. }
  32639. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  32640. _.label = op[1];
  32641. break;
  32642. }
  32643. if (op[0] === 6 && _.label < t[1]) {
  32644. _.label = t[1];
  32645. t = op;
  32646. break;
  32647. }
  32648. if (t && _.label < t[2]) {
  32649. _.label = t[2];
  32650. _.ops.push(op);
  32651. break;
  32652. }
  32653. if (t[2]) _.ops.pop();
  32654. _.trys.pop();
  32655. continue;
  32656. }
  32657. op = body.call(thisArg, _);
  32658. } catch (e) {
  32659. op = [6, e];
  32660. y = 0;
  32661. } finally {
  32662. f = t = 0;
  32663. }
  32664. }
  32665. if (op[0] & 5) throw op[1];
  32666. return {
  32667. value: op[0] ? op[1] : void 0,
  32668. done: true
  32669. };
  32670. }
  32671. };
  32672. var __importStar = this && this.__importStar || function (mod) {
  32673. if (mod && mod.__esModule) return mod;
  32674. var result = {};
  32675. if (mod != null) for (var k in mod) {
  32676. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  32677. }
  32678. result["default"] = mod;
  32679. return result;
  32680. };
  32681. var __importDefault = this && this.__importDefault || function (mod) {
  32682. return mod && mod.__esModule ? mod : {
  32683. "default": mod
  32684. };
  32685. };
  32686. Object.defineProperty(exports, "__esModule", {
  32687. value: true
  32688. });
  32689. var fs$$2 = __importStar(fs);
  32690. var path$$2 = __importStar(path);
  32691. var semver = __importStar(semver$3);
  32692. var fnmatch_1 = __importDefault(fnmatch);
  32693. exports.parseString = ini.parseString;
  32694. var package_json_1 = __importDefault(require$$4$6);
  32695. var knownProps = {
  32696. end_of_line: true,
  32697. indent_style: true,
  32698. indent_size: true,
  32699. insert_final_newline: true,
  32700. trim_trailing_whitespace: true,
  32701. charset: true
  32702. };
  32703. function fnmatch$$1(filepath, glob) {
  32704. var matchOptions = {
  32705. matchBase: true,
  32706. dot: true,
  32707. noext: true
  32708. };
  32709. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  32710. return fnmatch_1.default(filepath, glob, matchOptions);
  32711. }
  32712. function getConfigFileNames(filepath, options) {
  32713. var paths = [];
  32714. do {
  32715. filepath = path$$2.dirname(filepath);
  32716. paths.push(path$$2.join(filepath, options.config));
  32717. } while (filepath !== options.root);
  32718. return paths;
  32719. }
  32720. function processMatches(matches, version) {
  32721. // Set indent_size to 'tab' if indent_size is unspecified and
  32722. // indent_style is set to 'tab'.
  32723. if ('indent_style' in matches && matches.indent_style === 'tab' && !('indent_size' in matches) && semver.gte(version, '0.10.0')) {
  32724. matches.indent_size = 'tab';
  32725. } // Set tab_width to indent_size if indent_size is specified and
  32726. // tab_width is unspecified
  32727. if ('indent_size' in matches && !('tab_width' in matches) && matches.indent_size !== 'tab') {
  32728. matches.tab_width = matches.indent_size;
  32729. } // Set indent_size to tab_width if indent_size is 'tab'
  32730. if ('indent_size' in matches && 'tab_width' in matches && matches.indent_size === 'tab') {
  32731. matches.indent_size = matches.tab_width;
  32732. }
  32733. return matches;
  32734. }
  32735. function processOptions(options, filepath) {
  32736. if (options === void 0) {
  32737. options = {};
  32738. }
  32739. return {
  32740. config: options.config || '.editorconfig',
  32741. version: options.version || package_json_1.default.version,
  32742. root: path$$2.resolve(options.root || path$$2.parse(filepath).root)
  32743. };
  32744. }
  32745. function buildFullGlob(pathPrefix, glob) {
  32746. switch (glob.indexOf('/')) {
  32747. case -1:
  32748. glob = '**/' + glob;
  32749. break;
  32750. case 0:
  32751. glob = glob.substring(1);
  32752. break;
  32753. default:
  32754. break;
  32755. }
  32756. return path$$2.join(pathPrefix, glob);
  32757. }
  32758. function extendProps(props, options) {
  32759. if (props === void 0) {
  32760. props = {};
  32761. }
  32762. if (options === void 0) {
  32763. options = {};
  32764. }
  32765. for (var key in options) {
  32766. if (options.hasOwnProperty(key)) {
  32767. var value = options[key];
  32768. var key2 = key.toLowerCase();
  32769. var value2 = value;
  32770. if (knownProps[key2]) {
  32771. value2 = value.toLowerCase();
  32772. }
  32773. try {
  32774. value2 = JSON.parse(value);
  32775. } catch (e) {}
  32776. if (typeof value === 'undefined' || value === null) {
  32777. // null and undefined are values specific to JSON (no special meaning
  32778. // in editorconfig) & should just be returned as regular strings.
  32779. value2 = String(value);
  32780. }
  32781. props[key2] = value2;
  32782. }
  32783. }
  32784. return props;
  32785. }
  32786. function parseFromConfigs(configs, filepath, options) {
  32787. return processMatches(configs.reverse().reduce(function (matches, file) {
  32788. var pathPrefix = path$$2.dirname(file.name);
  32789. file.contents.forEach(function (section) {
  32790. var glob = section[0];
  32791. var options2 = section[1];
  32792. if (!glob) {
  32793. return;
  32794. }
  32795. var fullGlob = buildFullGlob(pathPrefix, glob);
  32796. if (!fnmatch$$1(filepath, fullGlob)) {
  32797. return;
  32798. }
  32799. matches = extendProps(matches, options2);
  32800. });
  32801. return matches;
  32802. }, {}), options.version);
  32803. }
  32804. function getConfigsForFiles(files) {
  32805. var configs = [];
  32806. for (var i in files) {
  32807. if (files.hasOwnProperty(i)) {
  32808. var file = files[i];
  32809. var contents = ini.parseString(file.contents);
  32810. configs.push({
  32811. name: file.name,
  32812. contents: contents
  32813. });
  32814. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  32815. break;
  32816. }
  32817. }
  32818. }
  32819. return configs;
  32820. }
  32821. function readConfigFiles(filepaths) {
  32822. return __awaiter(this, void 0, void 0, function () {
  32823. return __generator(this, function (_a) {
  32824. return [2
  32825. /*return*/
  32826. , Promise.all(filepaths.map(function (name) {
  32827. return new Promise(function (resolve) {
  32828. fs$$2.readFile(name, 'utf8', function (err, data) {
  32829. resolve({
  32830. name: name,
  32831. contents: err ? '' : data
  32832. });
  32833. });
  32834. });
  32835. }))];
  32836. });
  32837. });
  32838. }
  32839. function readConfigFilesSync(filepaths) {
  32840. var files = [];
  32841. var file;
  32842. filepaths.forEach(function (filepath) {
  32843. try {
  32844. file = fs$$2.readFileSync(filepath, 'utf8');
  32845. } catch (e) {
  32846. file = '';
  32847. }
  32848. files.push({
  32849. name: filepath,
  32850. contents: file
  32851. });
  32852. });
  32853. return files;
  32854. }
  32855. function opts(filepath, options) {
  32856. if (options === void 0) {
  32857. options = {};
  32858. }
  32859. var resolvedFilePath = path$$2.resolve(filepath);
  32860. return [resolvedFilePath, processOptions(options, resolvedFilePath)];
  32861. }
  32862. function parseFromFiles(filepath, files, options) {
  32863. if (options === void 0) {
  32864. options = {};
  32865. }
  32866. return __awaiter(this, void 0, void 0, function () {
  32867. var _a, resolvedFilePath, processedOptions;
  32868. return __generator(this, function (_b) {
  32869. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  32870. return [2
  32871. /*return*/
  32872. , files.then(getConfigsForFiles).then(function (configs) {
  32873. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  32874. })];
  32875. });
  32876. });
  32877. }
  32878. exports.parseFromFiles = parseFromFiles;
  32879. function parseFromFilesSync(filepath, files, options) {
  32880. if (options === void 0) {
  32881. options = {};
  32882. }
  32883. var _a = opts(filepath, options),
  32884. resolvedFilePath = _a[0],
  32885. processedOptions = _a[1];
  32886. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  32887. }
  32888. exports.parseFromFilesSync = parseFromFilesSync;
  32889. function parse(_filepath, _options) {
  32890. if (_options === void 0) {
  32891. _options = {};
  32892. }
  32893. return __awaiter(this, void 0, void 0, function () {
  32894. var _a, resolvedFilePath, processedOptions, filepaths;
  32895. return __generator(this, function (_b) {
  32896. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  32897. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  32898. return [2
  32899. /*return*/
  32900. , readConfigFiles(filepaths).then(getConfigsForFiles).then(function (configs) {
  32901. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  32902. })];
  32903. });
  32904. });
  32905. }
  32906. exports.parse = parse;
  32907. function parseSync(_filepath, _options) {
  32908. if (_options === void 0) {
  32909. _options = {};
  32910. }
  32911. var _a = opts(_filepath, _options),
  32912. resolvedFilePath = _a[0],
  32913. processedOptions = _a[1];
  32914. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  32915. var files = readConfigFilesSync(filepaths);
  32916. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  32917. }
  32918. exports.parseSync = parseSync;
  32919. });
  32920. unwrapExports(src$2);
  32921. var editorconfigToPrettier = editorConfigToPrettier;
  32922. function removeUnset(editorConfig) {
  32923. var result = {};
  32924. var keys = Object.keys(editorConfig);
  32925. for (var i = 0; i < keys.length; i++) {
  32926. var key = keys[i];
  32927. if (editorConfig[key] === "unset") {
  32928. continue;
  32929. }
  32930. result[key] = editorConfig[key];
  32931. }
  32932. return result;
  32933. }
  32934. function editorConfigToPrettier(editorConfig) {
  32935. if (!editorConfig) {
  32936. return null;
  32937. }
  32938. editorConfig = removeUnset(editorConfig);
  32939. if (Object.keys(editorConfig).length === 0) {
  32940. return null;
  32941. }
  32942. var result = {};
  32943. if (editorConfig.indent_style) {
  32944. result.useTabs = editorConfig.indent_style === "tab";
  32945. }
  32946. if (editorConfig.indent_size === "tab") {
  32947. result.useTabs = true;
  32948. }
  32949. if (result.useTabs && editorConfig.tab_width) {
  32950. result.tabWidth = editorConfig.tab_width;
  32951. } else if (editorConfig.indent_style === "space" && editorConfig.indent_size && editorConfig.indent_size !== "tab") {
  32952. result.tabWidth = editorConfig.indent_size;
  32953. } else if (editorConfig.tab_width !== undefined) {
  32954. result.tabWidth = editorConfig.tab_width;
  32955. }
  32956. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  32957. result.printWidth = editorConfig.max_line_length;
  32958. }
  32959. if (editorConfig.quote_type === "single") {
  32960. result.singleQuote = true;
  32961. } else if (editorConfig.quote_type === "double") {
  32962. result.singleQuote = false;
  32963. }
  32964. if (["cr", "crlf", "lf"].indexOf(editorConfig.end_of_line) !== -1) {
  32965. result.endOfLine = editorConfig.end_of_line;
  32966. }
  32967. return result;
  32968. }
  32969. function markerExists(files, markers) {
  32970. return markers.some(function (marker) {
  32971. return files.some(function (file) {
  32972. return file === marker;
  32973. });
  32974. });
  32975. }
  32976. function traverseFolder(directory, levels, markers) {
  32977. var files = fs.readdirSync(directory);
  32978. if (levels === 0) {
  32979. return null;
  32980. } else if (markerExists(files, markers)) {
  32981. return directory;
  32982. } else {
  32983. return traverseFolder(path.resolve(directory, '..'), levels - 1, markers);
  32984. }
  32985. }
  32986. var findProjectRoot = function findRoot(dir, opts) {
  32987. if (!dir) throw new Error("Directory not defined");
  32988. opts = opts || {};
  32989. var levels = opts.maxDepth || findRoot.MAX_DEPTH;
  32990. var markers = opts.markers || findRoot.MARKERS;
  32991. return traverseFolder(dir, levels, markers);
  32992. };
  32993. var MAX_DEPTH = 9;
  32994. var MARKERS = ['.git', '.hg'];
  32995. findProjectRoot.MAX_DEPTH = MAX_DEPTH;
  32996. findProjectRoot.MARKERS = MARKERS;
  32997. var resolveConfigEditorconfig = createCommonjsModule(function (module) {
  32998. "use strict";
  32999. var maybeParse = function maybeParse(filePath, config, parse) {
  33000. var root = findProjectRoot(path.dirname(path.resolve(filePath)));
  33001. return filePath && parse(filePath, {
  33002. root
  33003. });
  33004. };
  33005. var editorconfigAsyncNoCache = function editorconfigAsyncNoCache(filePath, config) {
  33006. return Promise.resolve(maybeParse(filePath, config, src$2.parse)).then(editorconfigToPrettier);
  33007. };
  33008. var editorconfigAsyncWithCache = mem(editorconfigAsyncNoCache);
  33009. var editorconfigSyncNoCache = function editorconfigSyncNoCache(filePath, config) {
  33010. return editorconfigToPrettier(maybeParse(filePath, config, src$2.parseSync));
  33011. };
  33012. var editorconfigSyncWithCache = mem(editorconfigSyncNoCache);
  33013. function getLoadFunction(opts) {
  33014. if (!opts.editorconfig) {
  33015. return function () {
  33016. return null;
  33017. };
  33018. }
  33019. if (opts.sync) {
  33020. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  33021. }
  33022. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  33023. }
  33024. function clearCache() {
  33025. mem.clear(editorconfigSyncWithCache);
  33026. mem.clear(editorconfigAsyncWithCache);
  33027. }
  33028. module.exports = {
  33029. getLoadFunction,
  33030. clearCache
  33031. };
  33032. });
  33033. var ParserEND = 0x110000;
  33034. var ParserError =
  33035. /*#__PURE__*/
  33036. function (_Error) {
  33037. _inherits(ParserError, _Error);
  33038. /* istanbul ignore next */
  33039. function ParserError(msg, filename, linenumber) {
  33040. var _this;
  33041. _classCallCheck(this, ParserError);
  33042. _this = _possibleConstructorReturn(this, _getPrototypeOf(ParserError).call(this, '[ParserError] ' + msg, filename, linenumber));
  33043. _this.name = 'ParserError';
  33044. _this.code = 'ParserError';
  33045. if (Error.captureStackTrace) Error.captureStackTrace(_assertThisInitialized(_assertThisInitialized(_this)), ParserError);
  33046. return _this;
  33047. }
  33048. return ParserError;
  33049. }(_wrapNativeSuper(Error));
  33050. var State = function State(parser) {
  33051. _classCallCheck(this, State);
  33052. this.parser = parser;
  33053. this.buf = '';
  33054. this.returned = null;
  33055. this.result = null;
  33056. this.resultTable = null;
  33057. this.resultArr = null;
  33058. };
  33059. var Parser =
  33060. /*#__PURE__*/
  33061. function () {
  33062. function Parser() {
  33063. _classCallCheck(this, Parser);
  33064. this.pos = 0;
  33065. this.col = 0;
  33066. this.line = 0;
  33067. this.obj = {};
  33068. this.ctx = this.obj;
  33069. this.stack = [];
  33070. this._buf = '';
  33071. this.char = null;
  33072. this.ii = 0;
  33073. this.state = new State(this.parseStart);
  33074. }
  33075. _createClass(Parser, [{
  33076. key: "parse",
  33077. value: function parse(str) {
  33078. /* istanbul ignore next */
  33079. if (str.length === 0 || str.length == null) return;
  33080. this._buf = String(str);
  33081. this.ii = -1;
  33082. this.char = -1;
  33083. var getNext;
  33084. while (getNext === false || this.nextChar()) {
  33085. getNext = this.runOne();
  33086. }
  33087. this._buf = null;
  33088. }
  33089. }, {
  33090. key: "nextChar",
  33091. value: function nextChar() {
  33092. if (this.char === 0x0A) {
  33093. ++this.line;
  33094. this.col = -1;
  33095. }
  33096. ++this.ii;
  33097. this.char = this._buf.codePointAt(this.ii);
  33098. ++this.pos;
  33099. ++this.col;
  33100. return this.haveBuffer();
  33101. }
  33102. }, {
  33103. key: "haveBuffer",
  33104. value: function haveBuffer() {
  33105. return this.ii < this._buf.length;
  33106. }
  33107. }, {
  33108. key: "runOne",
  33109. value: function runOne() {
  33110. return this.state.parser.call(this, this.state.returned);
  33111. }
  33112. }, {
  33113. key: "finish",
  33114. value: function finish() {
  33115. this.char = ParserEND;
  33116. var last;
  33117. do {
  33118. last = this.state.parser;
  33119. this.runOne();
  33120. } while (this.state.parser !== last);
  33121. this.ctx = null;
  33122. this.state = null;
  33123. this._buf = null;
  33124. return this.obj;
  33125. }
  33126. }, {
  33127. key: "next",
  33128. value: function next(fn) {
  33129. /* istanbul ignore next */
  33130. if (typeof fn !== 'function') throw new ParserError('Tried to set state to non-existent state: ' + JSON.stringify(fn));
  33131. this.state.parser = fn;
  33132. }
  33133. }, {
  33134. key: "goto",
  33135. value: function goto(fn) {
  33136. this.next(fn);
  33137. return this.runOne();
  33138. }
  33139. }, {
  33140. key: "call",
  33141. value: function call(fn, returnWith) {
  33142. if (returnWith) this.next(returnWith);
  33143. this.stack.push(this.state);
  33144. this.state = new State(fn);
  33145. }
  33146. }, {
  33147. key: "callNow",
  33148. value: function callNow(fn, returnWith) {
  33149. this.call(fn, returnWith);
  33150. return this.runOne();
  33151. }
  33152. }, {
  33153. key: "return",
  33154. value: function _return(value) {
  33155. /* istanbul ignore next */
  33156. if (this.stack.length === 0) throw this.error(new ParserError('Stack underflow'));
  33157. if (value === undefined) value = this.state.buf;
  33158. this.state = this.stack.pop();
  33159. this.state.returned = value;
  33160. }
  33161. }, {
  33162. key: "returnNow",
  33163. value: function returnNow(value) {
  33164. this.return(value);
  33165. return this.runOne();
  33166. }
  33167. }, {
  33168. key: "consume",
  33169. value: function consume() {
  33170. /* istanbul ignore next */
  33171. if (this.char === ParserEND) throw this.error(new ParserError('Unexpected end-of-buffer'));
  33172. this.state.buf += this._buf[this.ii];
  33173. }
  33174. }, {
  33175. key: "error",
  33176. value: function error(err) {
  33177. err.line = this.line;
  33178. err.col = this.col;
  33179. err.pos = this.pos;
  33180. return err;
  33181. }
  33182. /* istanbul ignore next */
  33183. }, {
  33184. key: "parseStart",
  33185. value: function parseStart() {
  33186. throw new ParserError('Must declare a parseStart method');
  33187. }
  33188. }]);
  33189. return Parser;
  33190. }();
  33191. Parser.END = ParserEND;
  33192. Parser.Error = ParserError;
  33193. var parser$2 = Parser;
  33194. var createDatetime = createCommonjsModule(function (module) {
  33195. 'use strict';
  33196. module.exports = function (value) {
  33197. var date = new Date(value);
  33198. /* istanbul ignore if */
  33199. if (isNaN(date)) {
  33200. throw new TypeError('Invalid Datetime');
  33201. } else {
  33202. return date;
  33203. }
  33204. };
  33205. });
  33206. var formatNum = createCommonjsModule(function (module) {
  33207. 'use strict';
  33208. module.exports = function (d, num) {
  33209. num = String(num);
  33210. while (num.length < d) {
  33211. num = '0' + num;
  33212. }
  33213. return num;
  33214. };
  33215. });
  33216. var createDatetimeFloat = createCommonjsModule(function (module) {
  33217. 'use strict';
  33218. var FloatingDateTime =
  33219. /*#__PURE__*/
  33220. function (_Date) {
  33221. _inherits(FloatingDateTime, _Date);
  33222. function FloatingDateTime(value) {
  33223. var _this;
  33224. _classCallCheck(this, FloatingDateTime);
  33225. _this = _possibleConstructorReturn(this, _getPrototypeOf(FloatingDateTime).call(this, value + 'Z'));
  33226. _this.isFloating = true;
  33227. return _this;
  33228. }
  33229. _createClass(FloatingDateTime, [{
  33230. key: "toISOString",
  33231. value: function toISOString() {
  33232. var date = `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  33233. var time = `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  33234. return `${date}T${time}`;
  33235. }
  33236. }]);
  33237. return FloatingDateTime;
  33238. }(_wrapNativeSuper(Date));
  33239. module.exports = function (value) {
  33240. var date = new FloatingDateTime(value);
  33241. /* istanbul ignore if */
  33242. if (isNaN(date)) {
  33243. throw new TypeError('Invalid Datetime');
  33244. } else {
  33245. return date;
  33246. }
  33247. };
  33248. });
  33249. var createDate = createCommonjsModule(function (module) {
  33250. 'use strict';
  33251. var DateTime = global.Date;
  33252. var Date =
  33253. /*#__PURE__*/
  33254. function (_DateTime) {
  33255. _inherits(Date, _DateTime);
  33256. function Date(value) {
  33257. var _this;
  33258. _classCallCheck(this, Date);
  33259. _this = _possibleConstructorReturn(this, _getPrototypeOf(Date).call(this, value));
  33260. _this.isDate = true;
  33261. return _this;
  33262. }
  33263. _createClass(Date, [{
  33264. key: "toISOString",
  33265. value: function toISOString() {
  33266. return `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  33267. }
  33268. }]);
  33269. return Date;
  33270. }(DateTime);
  33271. module.exports = function (value) {
  33272. var date = new Date(value);
  33273. /* istanbul ignore if */
  33274. if (isNaN(date)) {
  33275. throw new TypeError('Invalid Datetime');
  33276. } else {
  33277. return date;
  33278. }
  33279. };
  33280. });
  33281. var createTime = createCommonjsModule(function (module) {
  33282. 'use strict';
  33283. var Time =
  33284. /*#__PURE__*/
  33285. function (_Date) {
  33286. _inherits(Time, _Date);
  33287. function Time(value) {
  33288. var _this;
  33289. _classCallCheck(this, Time);
  33290. _this = _possibleConstructorReturn(this, _getPrototypeOf(Time).call(this, `0000-01-01T${value}Z`));
  33291. _this.isTime = true;
  33292. return _this;
  33293. }
  33294. _createClass(Time, [{
  33295. key: "toISOString",
  33296. value: function toISOString() {
  33297. return `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  33298. }
  33299. }]);
  33300. return Time;
  33301. }(_wrapNativeSuper(Date));
  33302. module.exports = function (value) {
  33303. var date = new Time(value);
  33304. /* istanbul ignore if */
  33305. if (isNaN(date)) {
  33306. throw new TypeError('Invalid Datetime');
  33307. } else {
  33308. return date;
  33309. }
  33310. };
  33311. });
  33312. var tomlParser = createCommonjsModule(function (module) {
  33313. 'use strict';
  33314. /* eslint-disable no-new-wrappers, no-eval, camelcase, operator-linebreak */
  33315. module.exports = makeParserClass(parser$2);
  33316. module.exports.makeParserClass = makeParserClass;
  33317. var TomlError =
  33318. /*#__PURE__*/
  33319. function (_Error) {
  33320. _inherits(TomlError, _Error);
  33321. function TomlError(msg) {
  33322. var _this;
  33323. _classCallCheck(this, TomlError);
  33324. _this = _possibleConstructorReturn(this, _getPrototypeOf(TomlError).call(this, msg));
  33325. _this.name = 'TomlError';
  33326. /* istanbul ignore next */
  33327. if (Error.captureStackTrace) Error.captureStackTrace(_assertThisInitialized(_assertThisInitialized(_this)), TomlError);
  33328. _this.fromTOML = true;
  33329. _this.wrapped = null;
  33330. return _this;
  33331. }
  33332. return TomlError;
  33333. }(_wrapNativeSuper(Error));
  33334. TomlError.wrap = function (err) {
  33335. var terr = new TomlError(err.message);
  33336. terr.code = err.code;
  33337. terr.wrapped = err;
  33338. return terr;
  33339. };
  33340. module.exports.TomlError = TomlError;
  33341. var CTRL_I = 0x09;
  33342. var CTRL_J = 0x0A;
  33343. var CTRL_M = 0x0D;
  33344. var CTRL_CHAR_BOUNDARY = 0x1F; // the last non-character in the latin1 region of unicode, except DEL
  33345. var CHAR_SP = 0x20;
  33346. var CHAR_QUOT = 0x22;
  33347. var CHAR_NUM = 0x23;
  33348. var CHAR_APOS = 0x27;
  33349. var CHAR_PLUS = 0x2B;
  33350. var CHAR_COMMA = 0x2C;
  33351. var CHAR_HYPHEN = 0x2D;
  33352. var CHAR_PERIOD = 0x2E;
  33353. var CHAR_0 = 0x30;
  33354. var CHAR_1 = 0x31;
  33355. var CHAR_7 = 0x37;
  33356. var CHAR_9 = 0x39;
  33357. var CHAR_COLON = 0x3A;
  33358. var CHAR_EQUALS = 0x3D;
  33359. var CHAR_A = 0x41;
  33360. var CHAR_E = 0x45;
  33361. var CHAR_F = 0x46;
  33362. var CHAR_T = 0x54;
  33363. var CHAR_U = 0x55;
  33364. var CHAR_Z = 0x5A;
  33365. var CHAR_LOWBAR = 0x5F;
  33366. var CHAR_a = 0x61;
  33367. var CHAR_b = 0x62;
  33368. var CHAR_e = 0x65;
  33369. var CHAR_f = 0x66;
  33370. var CHAR_i = 0x69;
  33371. var CHAR_l = 0x6C;
  33372. var CHAR_n = 0x6E;
  33373. var CHAR_o = 0x6F;
  33374. var CHAR_r = 0x72;
  33375. var CHAR_s = 0x73;
  33376. var CHAR_t = 0x74;
  33377. var CHAR_u = 0x75;
  33378. var CHAR_x = 0x78;
  33379. var CHAR_z = 0x7A;
  33380. var CHAR_LCUB = 0x7B;
  33381. var CHAR_RCUB = 0x7D;
  33382. var CHAR_LSQB = 0x5B;
  33383. var CHAR_BSOL = 0x5C;
  33384. var CHAR_RSQB = 0x5D;
  33385. var CHAR_DEL = 0x7F;
  33386. var SURROGATE_FIRST = 0xD800;
  33387. var SURROGATE_LAST = 0xDFFF;
  33388. var escapes = {
  33389. [CHAR_b]: '\u0008',
  33390. [CHAR_t]: '\u0009',
  33391. [CHAR_n]: '\u000A',
  33392. [CHAR_f]: '\u000C',
  33393. [CHAR_r]: '\u000D',
  33394. [CHAR_QUOT]: '\u0022',
  33395. [CHAR_BSOL]: '\u005C'
  33396. };
  33397. function isDigit(cp) {
  33398. return cp >= CHAR_0 && cp <= CHAR_9;
  33399. }
  33400. function isHexit(cp) {
  33401. return cp >= CHAR_A && cp <= CHAR_F || cp >= CHAR_a && cp <= CHAR_f || cp >= CHAR_0 && cp <= CHAR_9;
  33402. }
  33403. function isBit(cp) {
  33404. return cp === CHAR_1 || cp === CHAR_0;
  33405. }
  33406. function isOctit(cp) {
  33407. return cp >= CHAR_0 && cp <= CHAR_7;
  33408. }
  33409. function isAlphaNumQuoteHyphen(cp) {
  33410. return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_APOS || cp === CHAR_QUOT || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
  33411. }
  33412. function isAlphaNumHyphen(cp) {
  33413. return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
  33414. }
  33415. var _type = Symbol('type');
  33416. var _declared = Symbol('declared');
  33417. var hasOwnProperty = Object.prototype.hasOwnProperty;
  33418. var defineProperty = Object.defineProperty;
  33419. var descriptor = {
  33420. configurable: true,
  33421. enumerable: true,
  33422. writable: true,
  33423. value: undefined
  33424. };
  33425. function hasKey(obj, key) {
  33426. if (hasOwnProperty.call(obj, key)) return true;
  33427. if (key === '__proto__') defineProperty(obj, '__proto__', descriptor);
  33428. return false;
  33429. }
  33430. var INLINE_TABLE = Symbol('inline-table');
  33431. function InlineTable() {
  33432. return Object.defineProperties({}, {
  33433. [_type]: {
  33434. value: INLINE_TABLE
  33435. }
  33436. });
  33437. }
  33438. function isInlineTable(obj) {
  33439. if (obj === null || typeof obj !== 'object') return false;
  33440. return obj[_type] === INLINE_TABLE;
  33441. }
  33442. var TABLE = Symbol('table');
  33443. function Table() {
  33444. return Object.defineProperties({}, {
  33445. [_type]: {
  33446. value: TABLE
  33447. },
  33448. [_declared]: {
  33449. value: false,
  33450. writable: true
  33451. }
  33452. });
  33453. }
  33454. function isTable(obj) {
  33455. if (obj === null || typeof obj !== 'object') return false;
  33456. return obj[_type] === TABLE;
  33457. }
  33458. var _contentType = Symbol('content-type');
  33459. var INLINE_LIST = Symbol('inline-list');
  33460. function InlineList(type) {
  33461. return Object.defineProperties([], {
  33462. [_type]: {
  33463. value: INLINE_LIST
  33464. },
  33465. [_contentType]: {
  33466. value: type
  33467. }
  33468. });
  33469. }
  33470. function isInlineList(obj) {
  33471. if (obj === null || typeof obj !== 'object') return false;
  33472. return obj[_type] === INLINE_LIST;
  33473. }
  33474. var LIST = Symbol('list');
  33475. function List() {
  33476. return Object.defineProperties([], {
  33477. [_type]: {
  33478. value: LIST
  33479. }
  33480. });
  33481. }
  33482. function isList(obj) {
  33483. if (obj === null || typeof obj !== 'object') return false;
  33484. return obj[_type] === LIST;
  33485. } // in an eval, to let bundlers not slurp in a util proxy
  33486. var _custom;
  33487. try {
  33488. var utilInspect = eval("require('util').inspect");
  33489. _custom = utilInspect.custom;
  33490. } catch (_) {}
  33491. /* eval require not available in transpiled bundle */
  33492. /* istanbul ignore next */
  33493. var _inspect = _custom || 'inspect';
  33494. var BoxedBigInt =
  33495. /*#__PURE__*/
  33496. function () {
  33497. function BoxedBigInt(value) {
  33498. _classCallCheck(this, BoxedBigInt);
  33499. try {
  33500. this.value = global.BigInt.asIntN(64, value);
  33501. } catch (_) {
  33502. /* istanbul ignore next */
  33503. this.value = null;
  33504. }
  33505. Object.defineProperty(this, _type, {
  33506. value: INTEGER
  33507. });
  33508. }
  33509. _createClass(BoxedBigInt, [{
  33510. key: "isNaN",
  33511. value: function isNaN() {
  33512. return this.value === null;
  33513. }
  33514. /* istanbul ignore next */
  33515. }, {
  33516. key: "toString",
  33517. value: function toString() {
  33518. return String(this.value);
  33519. }
  33520. /* istanbul ignore next */
  33521. }, {
  33522. key: _inspect,
  33523. value: function value() {
  33524. return `[BigInt: ${this.toString()}]}`;
  33525. }
  33526. }, {
  33527. key: "valueOf",
  33528. value: function valueOf() {
  33529. return this.value;
  33530. }
  33531. }]);
  33532. return BoxedBigInt;
  33533. }();
  33534. var INTEGER = Symbol('integer');
  33535. function Integer(_value) {
  33536. var num = Number(_value); // -0 is a float thing, not an int thing
  33537. if (Object.is(num, -0)) num = 0;
  33538. /* istanbul ignore else */
  33539. if (global.BigInt && !Number.isSafeInteger(num)) {
  33540. return new BoxedBigInt(_value);
  33541. } else {
  33542. /* istanbul ignore next */
  33543. return Object.defineProperties(new Number(num), {
  33544. isNaN: {
  33545. value: function value() {
  33546. return isNaN(this);
  33547. }
  33548. },
  33549. [_type]: {
  33550. value: INTEGER
  33551. },
  33552. [_inspect]: {
  33553. value: function value() {
  33554. return `[Integer: ${_value}]`;
  33555. }
  33556. }
  33557. });
  33558. }
  33559. }
  33560. function isInteger(obj) {
  33561. if (obj === null || typeof obj !== 'object') return false;
  33562. return obj[_type] === INTEGER;
  33563. }
  33564. var FLOAT = Symbol('float');
  33565. function Float(_value2) {
  33566. /* istanbul ignore next */
  33567. return Object.defineProperties(new Number(_value2), {
  33568. [_type]: {
  33569. value: FLOAT
  33570. },
  33571. [_inspect]: {
  33572. value: function value() {
  33573. return `[Float: ${_value2}]`;
  33574. }
  33575. }
  33576. });
  33577. }
  33578. function isFloat(obj) {
  33579. if (obj === null || typeof obj !== 'object') return false;
  33580. return obj[_type] === FLOAT;
  33581. }
  33582. function tomlType(value) {
  33583. var type = typeof value;
  33584. if (type === 'object') {
  33585. /* istanbul ignore if */
  33586. if (value === null) return 'null';
  33587. if (value instanceof Date) return 'datetime';
  33588. /* istanbul ignore else */
  33589. if (_type in value) {
  33590. switch (value[_type]) {
  33591. case INLINE_TABLE:
  33592. return 'inline-table';
  33593. case INLINE_LIST:
  33594. return 'inline-list';
  33595. /* istanbul ignore next */
  33596. case TABLE:
  33597. return 'table';
  33598. /* istanbul ignore next */
  33599. case LIST:
  33600. return 'list';
  33601. case FLOAT:
  33602. return 'float';
  33603. case INTEGER:
  33604. return 'integer';
  33605. }
  33606. }
  33607. }
  33608. return type;
  33609. }
  33610. function makeParserClass(Parser) {
  33611. var TOMLParser =
  33612. /*#__PURE__*/
  33613. function (_Parser) {
  33614. _inherits(TOMLParser, _Parser);
  33615. function TOMLParser() {
  33616. var _this2;
  33617. _classCallCheck(this, TOMLParser);
  33618. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(TOMLParser).call(this));
  33619. _this2.ctx = _this2.obj = Table();
  33620. return _this2;
  33621. }
  33622. /* MATCH HELPER */
  33623. _createClass(TOMLParser, [{
  33624. key: "atEndOfWord",
  33625. value: function atEndOfWord() {
  33626. return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine();
  33627. }
  33628. }, {
  33629. key: "atEndOfLine",
  33630. value: function atEndOfLine() {
  33631. return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M;
  33632. }
  33633. }, {
  33634. key: "parseStart",
  33635. value: function parseStart() {
  33636. if (this.char === Parser.END) {
  33637. return null;
  33638. } else if (this.char === CHAR_LSQB) {
  33639. return this.call(this.parseTableOrList);
  33640. } else if (this.char === CHAR_NUM) {
  33641. return this.call(this.parseComment);
  33642. } else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  33643. return null;
  33644. } else if (isAlphaNumQuoteHyphen(this.char)) {
  33645. return this.callNow(this.parseAssignStatement);
  33646. } else {
  33647. throw this.error(new TomlError(`Unknown character "${this.char}"`));
  33648. }
  33649. } // HELPER, this strips any whitespace and comments to the end of the line
  33650. // then RETURNS. Last state in a production.
  33651. }, {
  33652. key: "parseWhitespaceToEOL",
  33653. value: function parseWhitespaceToEOL() {
  33654. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  33655. return null;
  33656. } else if (this.char === CHAR_NUM) {
  33657. return this.goto(this.parseComment);
  33658. } else if (this.char === Parser.END || this.char === CTRL_J) {
  33659. return this.return();
  33660. } else {
  33661. throw this.error(new TomlError('Unexpected character, expected only whitespace or comments till end of line'));
  33662. }
  33663. }
  33664. /* ASSIGNMENT: key = value */
  33665. }, {
  33666. key: "parseAssignStatement",
  33667. value: function parseAssignStatement() {
  33668. return this.callNow(this.parseAssign, this.recordAssignStatement);
  33669. }
  33670. }, {
  33671. key: "recordAssignStatement",
  33672. value: function recordAssignStatement(kv) {
  33673. var target = this.ctx;
  33674. var finalKey = kv.key.pop();
  33675. var _iteratorNormalCompletion = true;
  33676. var _didIteratorError = false;
  33677. var _iteratorError = undefined;
  33678. try {
  33679. for (var _iterator = kv.key[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  33680. var kw = _step.value;
  33681. if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
  33682. throw this.error(new TomlError("Can't redefine existing key"));
  33683. }
  33684. target = target[kw] = target[kw] || Table();
  33685. }
  33686. } catch (err) {
  33687. _didIteratorError = true;
  33688. _iteratorError = err;
  33689. } finally {
  33690. try {
  33691. if (!_iteratorNormalCompletion && _iterator.return != null) {
  33692. _iterator.return();
  33693. }
  33694. } finally {
  33695. if (_didIteratorError) {
  33696. throw _iteratorError;
  33697. }
  33698. }
  33699. }
  33700. if (hasKey(target, finalKey)) {
  33701. throw this.error(new TomlError("Can't redefine existing key"));
  33702. } // unbox our numbers
  33703. if (isInteger(kv.value) || isFloat(kv.value)) {
  33704. target[finalKey] = kv.value.valueOf();
  33705. } else {
  33706. target[finalKey] = kv.value;
  33707. }
  33708. return this.goto(this.parseWhitespaceToEOL);
  33709. }
  33710. /* ASSSIGNMENT expression, key = value possibly inside an inline table */
  33711. }, {
  33712. key: "parseAssign",
  33713. value: function parseAssign() {
  33714. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  33715. }
  33716. }, {
  33717. key: "recordAssignKeyword",
  33718. value: function recordAssignKeyword(key) {
  33719. if (this.state.resultTable) {
  33720. this.state.resultTable.push(key);
  33721. } else {
  33722. this.state.resultTable = [key];
  33723. }
  33724. return this.goto(this.parseAssignKeywordPreDot);
  33725. }
  33726. }, {
  33727. key: "parseAssignKeywordPreDot",
  33728. value: function parseAssignKeywordPreDot() {
  33729. if (this.char === CHAR_PERIOD) {
  33730. return this.next(this.parseAssignKeywordPostDot);
  33731. } else if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  33732. return this.goto(this.parseAssignEqual);
  33733. }
  33734. }
  33735. }, {
  33736. key: "parseAssignKeywordPostDot",
  33737. value: function parseAssignKeywordPostDot() {
  33738. if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  33739. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  33740. }
  33741. }
  33742. }, {
  33743. key: "parseAssignEqual",
  33744. value: function parseAssignEqual() {
  33745. if (this.char === CHAR_EQUALS) {
  33746. return this.next(this.parseAssignPreValue);
  33747. } else {
  33748. throw this.error(new TomlError('Invalid character, expected "="'));
  33749. }
  33750. }
  33751. }, {
  33752. key: "parseAssignPreValue",
  33753. value: function parseAssignPreValue() {
  33754. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33755. return null;
  33756. } else {
  33757. return this.callNow(this.parseValue, this.recordAssignValue);
  33758. }
  33759. }
  33760. }, {
  33761. key: "recordAssignValue",
  33762. value: function recordAssignValue(value) {
  33763. return this.returnNow({
  33764. key: this.state.resultTable,
  33765. value: value
  33766. });
  33767. }
  33768. /* COMMENTS: #...eol */
  33769. }, {
  33770. key: "parseComment",
  33771. value: function parseComment() {
  33772. do {
  33773. if (this.char === Parser.END || this.char === CTRL_J) {
  33774. return this.return();
  33775. }
  33776. } while (this.nextChar());
  33777. }
  33778. /* TABLES AND LISTS, [foo] and [[foo]] */
  33779. }, {
  33780. key: "parseTableOrList",
  33781. value: function parseTableOrList() {
  33782. if (this.char === CHAR_LSQB) {
  33783. this.next(this.parseList);
  33784. } else {
  33785. return this.goto(this.parseTable);
  33786. }
  33787. }
  33788. /* TABLE [foo.bar.baz] */
  33789. }, {
  33790. key: "parseTable",
  33791. value: function parseTable() {
  33792. this.ctx = this.obj;
  33793. return this.goto(this.parseTableNext);
  33794. }
  33795. }, {
  33796. key: "parseTableNext",
  33797. value: function parseTableNext() {
  33798. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33799. return null;
  33800. } else {
  33801. return this.callNow(this.parseKeyword, this.parseTableMore);
  33802. }
  33803. }
  33804. }, {
  33805. key: "parseTableMore",
  33806. value: function parseTableMore(keyword) {
  33807. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33808. return null;
  33809. } else if (this.char === CHAR_RSQB) {
  33810. if (hasKey(this.ctx, keyword) && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) {
  33811. throw this.error(new TomlError("Can't redefine existing key"));
  33812. } else {
  33813. this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table();
  33814. this.ctx[_declared] = true;
  33815. }
  33816. return this.next(this.parseWhitespaceToEOL);
  33817. } else if (this.char === CHAR_PERIOD) {
  33818. if (!hasKey(this.ctx, keyword)) {
  33819. this.ctx = this.ctx[keyword] = Table();
  33820. } else if (isTable(this.ctx[keyword])) {
  33821. this.ctx = this.ctx[keyword];
  33822. } else if (isList(this.ctx[keyword])) {
  33823. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  33824. } else {
  33825. throw this.error(new TomlError("Can't redefine existing key"));
  33826. }
  33827. return this.next(this.parseTableNext);
  33828. } else {
  33829. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  33830. }
  33831. }
  33832. /* LIST [[a.b.c]] */
  33833. }, {
  33834. key: "parseList",
  33835. value: function parseList() {
  33836. this.ctx = this.obj;
  33837. return this.goto(this.parseListNext);
  33838. }
  33839. }, {
  33840. key: "parseListNext",
  33841. value: function parseListNext() {
  33842. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33843. return null;
  33844. } else {
  33845. return this.callNow(this.parseKeyword, this.parseListMore);
  33846. }
  33847. }
  33848. }, {
  33849. key: "parseListMore",
  33850. value: function parseListMore(keyword) {
  33851. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33852. return null;
  33853. } else if (this.char === CHAR_RSQB) {
  33854. if (!hasKey(this.ctx, keyword)) {
  33855. this.ctx[keyword] = List();
  33856. }
  33857. if (isInlineList(this.ctx[keyword])) {
  33858. throw this.error(new TomlError("Can't extend an inline array"));
  33859. } else if (isList(this.ctx[keyword])) {
  33860. var next = Table();
  33861. this.ctx[keyword].push(next);
  33862. this.ctx = next;
  33863. } else {
  33864. throw this.error(new TomlError("Can't redefine an existing key"));
  33865. }
  33866. return this.next(this.parseListEnd);
  33867. } else if (this.char === CHAR_PERIOD) {
  33868. if (!hasKey(this.ctx, keyword)) {
  33869. this.ctx = this.ctx[keyword] = Table();
  33870. } else if (isInlineList(this.ctx[keyword])) {
  33871. throw this.error(new TomlError("Can't extend an inline array"));
  33872. } else if (isInlineTable(this.ctx[keyword])) {
  33873. throw this.error(new TomlError("Can't extend an inline table"));
  33874. } else if (isList(this.ctx[keyword])) {
  33875. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  33876. } else if (isTable(this.ctx[keyword])) {
  33877. this.ctx = this.ctx[keyword];
  33878. } else {
  33879. throw this.error(new TomlError("Can't redefine an existing key"));
  33880. }
  33881. return this.next(this.parseListNext);
  33882. } else {
  33883. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  33884. }
  33885. }
  33886. }, {
  33887. key: "parseListEnd",
  33888. value: function parseListEnd(keyword) {
  33889. if (this.char === CHAR_RSQB) {
  33890. return this.next(this.parseWhitespaceToEOL);
  33891. } else {
  33892. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  33893. }
  33894. }
  33895. /* VALUE string, number, boolean, inline list, inline object */
  33896. }, {
  33897. key: "parseValue",
  33898. value: function parseValue() {
  33899. if (this.char === Parser.END) {
  33900. throw this.error(new TomlError('Key without value'));
  33901. } else if (this.char === CHAR_QUOT) {
  33902. return this.next(this.parseDoubleString);
  33903. }
  33904. if (this.char === CHAR_APOS) {
  33905. return this.next(this.parseSingleString);
  33906. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  33907. return this.goto(this.parseNumberSign);
  33908. } else if (this.char === CHAR_i) {
  33909. return this.next(this.parseInf);
  33910. } else if (this.char === CHAR_n) {
  33911. return this.next(this.parseNan);
  33912. } else if (isDigit(this.char)) {
  33913. return this.goto(this.parseNumberOrDateTime);
  33914. } else if (this.char === CHAR_t || this.char === CHAR_f) {
  33915. return this.goto(this.parseBoolean);
  33916. } else if (this.char === CHAR_LSQB) {
  33917. return this.call(this.parseInlineList, this.recordValue);
  33918. } else if (this.char === CHAR_LCUB) {
  33919. return this.call(this.parseInlineTable, this.recordValue);
  33920. } else {
  33921. throw this.error(new TomlError('Unexpected character, expecting string, number, datetime, boolean, inline array or inline table'));
  33922. }
  33923. }
  33924. }, {
  33925. key: "recordValue",
  33926. value: function recordValue(value) {
  33927. return this.returnNow(value);
  33928. }
  33929. }, {
  33930. key: "parseInf",
  33931. value: function parseInf() {
  33932. if (this.char === CHAR_n) {
  33933. return this.next(this.parseInf2);
  33934. } else {
  33935. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  33936. }
  33937. }
  33938. }, {
  33939. key: "parseInf2",
  33940. value: function parseInf2() {
  33941. if (this.char === CHAR_f) {
  33942. if (this.state.buf === '-') {
  33943. return this.return(-Infinity);
  33944. } else {
  33945. return this.return(Infinity);
  33946. }
  33947. } else {
  33948. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  33949. }
  33950. }
  33951. }, {
  33952. key: "parseNan",
  33953. value: function parseNan() {
  33954. if (this.char === CHAR_a) {
  33955. return this.next(this.parseNan2);
  33956. } else {
  33957. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  33958. }
  33959. }
  33960. }, {
  33961. key: "parseNan2",
  33962. value: function parseNan2() {
  33963. if (this.char === CHAR_n) {
  33964. return this.return(NaN);
  33965. } else {
  33966. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  33967. }
  33968. }
  33969. /* KEYS, barewords or basic, literal, or dotted */
  33970. }, {
  33971. key: "parseKeyword",
  33972. value: function parseKeyword() {
  33973. if (this.char === CHAR_QUOT) {
  33974. return this.next(this.parseBasicString);
  33975. } else if (this.char === CHAR_APOS) {
  33976. return this.next(this.parseLiteralString);
  33977. } else {
  33978. return this.goto(this.parseBareKey);
  33979. }
  33980. }
  33981. /* KEYS: barewords */
  33982. }, {
  33983. key: "parseBareKey",
  33984. value: function parseBareKey() {
  33985. do {
  33986. if (this.char === Parser.END) {
  33987. throw this.error(new TomlError('Key ended without value'));
  33988. } else if (isAlphaNumHyphen(this.char)) {
  33989. this.consume();
  33990. } else if (this.state.buf.length === 0) {
  33991. throw this.error(new TomlError('Empty bare keys are not allowed'));
  33992. } else {
  33993. return this.returnNow();
  33994. }
  33995. } while (this.nextChar());
  33996. }
  33997. /* STRINGS, single quoted (literal) */
  33998. }, {
  33999. key: "parseSingleString",
  34000. value: function parseSingleString() {
  34001. if (this.char === CHAR_APOS) {
  34002. return this.next(this.parseLiteralMultiStringMaybe);
  34003. } else {
  34004. return this.goto(this.parseLiteralString);
  34005. }
  34006. }
  34007. }, {
  34008. key: "parseLiteralString",
  34009. value: function parseLiteralString() {
  34010. do {
  34011. if (this.char === CHAR_APOS) {
  34012. return this.return();
  34013. } else if (this.atEndOfLine()) {
  34014. throw this.error(new TomlError('Unterminated string'));
  34015. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  34016. throw this.errorControlCharInString();
  34017. } else {
  34018. this.consume();
  34019. }
  34020. } while (this.nextChar());
  34021. }
  34022. }, {
  34023. key: "parseLiteralMultiStringMaybe",
  34024. value: function parseLiteralMultiStringMaybe() {
  34025. if (this.char === CHAR_APOS) {
  34026. return this.next(this.parseLiteralMultiString);
  34027. } else {
  34028. return this.returnNow();
  34029. }
  34030. }
  34031. }, {
  34032. key: "parseLiteralMultiString",
  34033. value: function parseLiteralMultiString() {
  34034. if (this.char === CTRL_M) {
  34035. return null;
  34036. } else if (this.char === CTRL_J) {
  34037. return this.next(this.parseLiteralMultiStringContent);
  34038. } else {
  34039. return this.goto(this.parseLiteralMultiStringContent);
  34040. }
  34041. }
  34042. }, {
  34043. key: "parseLiteralMultiStringContent",
  34044. value: function parseLiteralMultiStringContent() {
  34045. do {
  34046. if (this.char === CHAR_APOS) {
  34047. return this.next(this.parseLiteralMultiEnd);
  34048. } else if (this.char === Parser.END) {
  34049. throw this.error(new TomlError('Unterminated multi-line string'));
  34050. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  34051. throw this.errorControlCharInString();
  34052. } else {
  34053. this.consume();
  34054. }
  34055. } while (this.nextChar());
  34056. }
  34057. }, {
  34058. key: "parseLiteralMultiEnd",
  34059. value: function parseLiteralMultiEnd() {
  34060. if (this.char === CHAR_APOS) {
  34061. return this.next(this.parseLiteralMultiEnd2);
  34062. } else {
  34063. this.state.buf += "'";
  34064. return this.goto(this.parseLiteralMultiStringContent);
  34065. }
  34066. }
  34067. }, {
  34068. key: "parseLiteralMultiEnd2",
  34069. value: function parseLiteralMultiEnd2() {
  34070. if (this.char === CHAR_APOS) {
  34071. return this.return();
  34072. } else {
  34073. this.state.buf += "''";
  34074. return this.goto(this.parseLiteralMultiStringContent);
  34075. }
  34076. }
  34077. /* STRINGS double quoted */
  34078. }, {
  34079. key: "parseDoubleString",
  34080. value: function parseDoubleString() {
  34081. if (this.char === CHAR_QUOT) {
  34082. return this.next(this.parseMultiStringMaybe);
  34083. } else {
  34084. return this.goto(this.parseBasicString);
  34085. }
  34086. }
  34087. }, {
  34088. key: "parseBasicString",
  34089. value: function parseBasicString() {
  34090. do {
  34091. if (this.char === CHAR_BSOL) {
  34092. return this.call(this.parseEscape, this.recordEscapeReplacement);
  34093. } else if (this.char === CHAR_QUOT) {
  34094. return this.return();
  34095. } else if (this.atEndOfLine()) {
  34096. throw this.error(new TomlError('Unterminated string'));
  34097. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  34098. throw this.errorControlCharInString();
  34099. } else {
  34100. this.consume();
  34101. }
  34102. } while (this.nextChar());
  34103. }
  34104. }, {
  34105. key: "recordEscapeReplacement",
  34106. value: function recordEscapeReplacement(replacement) {
  34107. this.state.buf += replacement;
  34108. return this.goto(this.parseBasicString);
  34109. }
  34110. }, {
  34111. key: "parseMultiStringMaybe",
  34112. value: function parseMultiStringMaybe() {
  34113. if (this.char === CHAR_QUOT) {
  34114. return this.next(this.parseMultiString);
  34115. } else {
  34116. return this.returnNow();
  34117. }
  34118. }
  34119. }, {
  34120. key: "parseMultiString",
  34121. value: function parseMultiString() {
  34122. if (this.char === CTRL_M) {
  34123. return null;
  34124. } else if (this.char === CTRL_J) {
  34125. return this.next(this.parseMultiStringContent);
  34126. } else {
  34127. return this.goto(this.parseMultiStringContent);
  34128. }
  34129. }
  34130. }, {
  34131. key: "parseMultiStringContent",
  34132. value: function parseMultiStringContent() {
  34133. do {
  34134. if (this.char === CHAR_BSOL) {
  34135. return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement);
  34136. } else if (this.char === CHAR_QUOT) {
  34137. return this.next(this.parseMultiEnd);
  34138. } else if (this.char === Parser.END) {
  34139. throw this.error(new TomlError('Unterminated multi-line string'));
  34140. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  34141. throw this.errorControlCharInString();
  34142. } else {
  34143. this.consume();
  34144. }
  34145. } while (this.nextChar());
  34146. }
  34147. }, {
  34148. key: "errorControlCharInString",
  34149. value: function errorControlCharInString() {
  34150. var displayCode = '\\u00';
  34151. if (this.char < 16) {
  34152. displayCode += '0';
  34153. }
  34154. displayCode += this.char.toString(16);
  34155. return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`));
  34156. }
  34157. }, {
  34158. key: "recordMultiEscapeReplacement",
  34159. value: function recordMultiEscapeReplacement(replacement) {
  34160. this.state.buf += replacement;
  34161. return this.goto(this.parseMultiStringContent);
  34162. }
  34163. }, {
  34164. key: "parseMultiEnd",
  34165. value: function parseMultiEnd() {
  34166. if (this.char === CHAR_QUOT) {
  34167. return this.next(this.parseMultiEnd2);
  34168. } else {
  34169. this.state.buf += '"';
  34170. return this.goto(this.parseMultiStringContent);
  34171. }
  34172. }
  34173. }, {
  34174. key: "parseMultiEnd2",
  34175. value: function parseMultiEnd2() {
  34176. if (this.char === CHAR_QUOT) {
  34177. return this.return();
  34178. } else {
  34179. this.state.buf += '""';
  34180. return this.goto(this.parseMultiStringContent);
  34181. }
  34182. }
  34183. }, {
  34184. key: "parseMultiEscape",
  34185. value: function parseMultiEscape() {
  34186. if (this.char === CTRL_M || this.char === CTRL_J) {
  34187. return this.next(this.parseMultiTrim);
  34188. } else if (this.char === CHAR_SP || this.char === CTRL_I) {
  34189. return this.next(this.parsePreMultiTrim);
  34190. } else {
  34191. return this.goto(this.parseEscape);
  34192. }
  34193. }
  34194. }, {
  34195. key: "parsePreMultiTrim",
  34196. value: function parsePreMultiTrim() {
  34197. if (this.char === CHAR_SP || this.char === CTRL_I) {
  34198. return null;
  34199. } else if (this.char === CTRL_M || this.char === CTRL_J) {
  34200. return this.next(this.parseMultiTrim);
  34201. } else {
  34202. throw this.error(new TomlError("Can't escape whitespace"));
  34203. }
  34204. }
  34205. }, {
  34206. key: "parseMultiTrim",
  34207. value: function parseMultiTrim() {
  34208. // explicitly whitespace here, END should follow the same path as chars
  34209. if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  34210. return null;
  34211. } else {
  34212. return this.returnNow();
  34213. }
  34214. }
  34215. }, {
  34216. key: "parseEscape",
  34217. value: function parseEscape() {
  34218. if (this.char in escapes) {
  34219. return this.return(escapes[this.char]);
  34220. } else if (this.char === CHAR_u) {
  34221. return this.call(this.parseSmallUnicode, this.parseUnicodeReturn);
  34222. } else if (this.char === CHAR_U) {
  34223. return this.call(this.parseLargeUnicode, this.parseUnicodeReturn);
  34224. } else {
  34225. throw this.error(new TomlError('Unknown escape character: ' + this.char));
  34226. }
  34227. }
  34228. }, {
  34229. key: "parseUnicodeReturn",
  34230. value: function parseUnicodeReturn(char) {
  34231. try {
  34232. var codePoint = parseInt(char, 16);
  34233. if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) {
  34234. throw this.error(new TomlError('Invalid unicode, character in range 0xD800 - 0xDFFF is reserved'));
  34235. }
  34236. return this.returnNow(String.fromCodePoint(codePoint));
  34237. } catch (err) {
  34238. throw this.error(TomlError.wrap(err));
  34239. }
  34240. }
  34241. }, {
  34242. key: "parseSmallUnicode",
  34243. value: function parseSmallUnicode() {
  34244. if (!isHexit(this.char)) {
  34245. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  34246. } else {
  34247. this.consume();
  34248. if (this.state.buf.length >= 4) return this.return();
  34249. }
  34250. }
  34251. }, {
  34252. key: "parseLargeUnicode",
  34253. value: function parseLargeUnicode() {
  34254. if (!isHexit(this.char)) {
  34255. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  34256. } else {
  34257. this.consume();
  34258. if (this.state.buf.length >= 8) return this.return();
  34259. }
  34260. }
  34261. /* NUMBERS */
  34262. }, {
  34263. key: "parseNumberSign",
  34264. value: function parseNumberSign() {
  34265. this.consume();
  34266. return this.next(this.parseMaybeSignedInfOrNan);
  34267. }
  34268. }, {
  34269. key: "parseMaybeSignedInfOrNan",
  34270. value: function parseMaybeSignedInfOrNan() {
  34271. if (this.char === CHAR_i) {
  34272. return this.next(this.parseInf);
  34273. } else if (this.char === CHAR_n) {
  34274. return this.next(this.parseNan);
  34275. } else {
  34276. return this.callNow(this.parseNoUnder, this.parseNumberIntegerStart);
  34277. }
  34278. }
  34279. }, {
  34280. key: "parseNumberIntegerStart",
  34281. value: function parseNumberIntegerStart() {
  34282. if (this.char === CHAR_0) {
  34283. this.consume();
  34284. return this.next(this.parseNumberIntegerExponentOrDecimal);
  34285. } else {
  34286. return this.goto(this.parseNumberInteger);
  34287. }
  34288. }
  34289. }, {
  34290. key: "parseNumberIntegerExponentOrDecimal",
  34291. value: function parseNumberIntegerExponentOrDecimal() {
  34292. if (this.char === CHAR_PERIOD) {
  34293. this.consume();
  34294. return this.call(this.parseNoUnder, this.parseNumberFloat);
  34295. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  34296. this.consume();
  34297. return this.next(this.parseNumberExponentSign);
  34298. } else {
  34299. return this.returnNow(Integer(this.state.buf));
  34300. }
  34301. }
  34302. }, {
  34303. key: "parseNumberInteger",
  34304. value: function parseNumberInteger() {
  34305. if (isDigit(this.char)) {
  34306. this.consume();
  34307. } else if (this.char === CHAR_LOWBAR) {
  34308. return this.call(this.parseNoUnder);
  34309. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  34310. this.consume();
  34311. return this.next(this.parseNumberExponentSign);
  34312. } else if (this.char === CHAR_PERIOD) {
  34313. this.consume();
  34314. return this.call(this.parseNoUnder, this.parseNumberFloat);
  34315. } else {
  34316. var result = Integer(this.state.buf);
  34317. /* istanbul ignore if */
  34318. if (result.isNaN()) {
  34319. throw this.error(new TomlError('Invalid number'));
  34320. } else {
  34321. return this.returnNow(result);
  34322. }
  34323. }
  34324. }
  34325. }, {
  34326. key: "parseNoUnder",
  34327. value: function parseNoUnder() {
  34328. if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD || this.char === CHAR_E || this.char === CHAR_e) {
  34329. throw this.error(new TomlError('Unexpected character, expected digit'));
  34330. } else if (this.atEndOfWord()) {
  34331. throw this.error(new TomlError('Incomplete number'));
  34332. }
  34333. return this.returnNow();
  34334. }
  34335. }, {
  34336. key: "parseNumberFloat",
  34337. value: function parseNumberFloat() {
  34338. if (this.char === CHAR_LOWBAR) {
  34339. return this.call(this.parseNoUnder, this.parseNumberFloat);
  34340. } else if (isDigit(this.char)) {
  34341. this.consume();
  34342. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  34343. this.consume();
  34344. return this.next(this.parseNumberExponentSign);
  34345. } else {
  34346. return this.returnNow(Float(this.state.buf));
  34347. }
  34348. }
  34349. }, {
  34350. key: "parseNumberExponentSign",
  34351. value: function parseNumberExponentSign() {
  34352. if (isDigit(this.char)) {
  34353. return this.goto(this.parseNumberExponent);
  34354. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  34355. this.consume();
  34356. this.call(this.parseNoUnder, this.parseNumberExponent);
  34357. } else {
  34358. throw this.error(new TomlError('Unexpected character, expected -, + or digit'));
  34359. }
  34360. }
  34361. }, {
  34362. key: "parseNumberExponent",
  34363. value: function parseNumberExponent() {
  34364. if (isDigit(this.char)) {
  34365. this.consume();
  34366. } else if (this.char === CHAR_LOWBAR) {
  34367. return this.call(this.parseNoUnder);
  34368. } else {
  34369. return this.returnNow(Float(this.state.buf));
  34370. }
  34371. }
  34372. /* NUMBERS or DATETIMES */
  34373. }, {
  34374. key: "parseNumberOrDateTime",
  34375. value: function parseNumberOrDateTime() {
  34376. if (this.char === CHAR_0) {
  34377. this.consume();
  34378. return this.next(this.parseNumberBaseOrDateTime);
  34379. } else {
  34380. return this.goto(this.parseNumberOrDateTimeOnly);
  34381. }
  34382. }
  34383. }, {
  34384. key: "parseNumberOrDateTimeOnly",
  34385. value: function parseNumberOrDateTimeOnly() {
  34386. // note, if two zeros are in a row then it MUST be a date
  34387. if (this.char === CHAR_LOWBAR) {
  34388. return this.call(this.parseNoUnder, this.parseNumberInteger);
  34389. } else if (isDigit(this.char)) {
  34390. this.consume();
  34391. if (this.state.buf.length > 4) this.next(this.parseNumberInteger);
  34392. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  34393. this.consume();
  34394. return this.next(this.parseNumberExponentSign);
  34395. } else if (this.char === CHAR_PERIOD) {
  34396. this.consume();
  34397. return this.call(this.parseNoUnder, this.parseNumberFloat);
  34398. } else if (this.char === CHAR_HYPHEN) {
  34399. return this.goto(this.parseDateTime);
  34400. } else if (this.char === CHAR_COLON) {
  34401. return this.goto(this.parseOnlyTimeHour);
  34402. } else {
  34403. return this.returnNow(Integer(this.state.buf));
  34404. }
  34405. }
  34406. }, {
  34407. key: "parseDateTimeOnly",
  34408. value: function parseDateTimeOnly() {
  34409. if (this.state.buf.length < 4) {
  34410. if (isDigit(this.char)) {
  34411. return this.consume();
  34412. } else if (this.char === CHAR_COLON) {
  34413. return this.goto(this.parseOnlyTimeHour);
  34414. } else {
  34415. throw this.error(new TomlError('Expected digit while parsing year part of a date'));
  34416. }
  34417. } else {
  34418. if (this.char === CHAR_HYPHEN) {
  34419. return this.goto(this.parseDateTime);
  34420. } else {
  34421. throw this.error(new TomlError('Expected hyphen (-) while parsing year part of date'));
  34422. }
  34423. }
  34424. }
  34425. }, {
  34426. key: "parseNumberBaseOrDateTime",
  34427. value: function parseNumberBaseOrDateTime() {
  34428. if (this.char === CHAR_b) {
  34429. this.consume();
  34430. return this.call(this.parseNoUnder, this.parseIntegerBin);
  34431. } else if (this.char === CHAR_o) {
  34432. this.consume();
  34433. return this.call(this.parseNoUnder, this.parseIntegerOct);
  34434. } else if (this.char === CHAR_x) {
  34435. this.consume();
  34436. return this.call(this.parseNoUnder, this.parseIntegerHex);
  34437. } else if (this.char === CHAR_PERIOD) {
  34438. return this.goto(this.parseNumberInteger);
  34439. } else if (isDigit(this.char)) {
  34440. return this.goto(this.parseDateTimeOnly);
  34441. } else {
  34442. return this.returnNow(Integer(this.state.buf));
  34443. }
  34444. }
  34445. }, {
  34446. key: "parseIntegerHex",
  34447. value: function parseIntegerHex() {
  34448. if (isHexit(this.char)) {
  34449. this.consume();
  34450. } else if (this.char === CHAR_LOWBAR) {
  34451. return this.call(this.parseNoUnder);
  34452. } else {
  34453. var result = Integer(this.state.buf);
  34454. /* istanbul ignore if */
  34455. if (result.isNaN()) {
  34456. throw this.error(new TomlError('Invalid number'));
  34457. } else {
  34458. return this.returnNow(result);
  34459. }
  34460. }
  34461. }
  34462. }, {
  34463. key: "parseIntegerOct",
  34464. value: function parseIntegerOct() {
  34465. if (isOctit(this.char)) {
  34466. this.consume();
  34467. } else if (this.char === CHAR_LOWBAR) {
  34468. return this.call(this.parseNoUnder);
  34469. } else {
  34470. var result = Integer(this.state.buf);
  34471. /* istanbul ignore if */
  34472. if (result.isNaN()) {
  34473. throw this.error(new TomlError('Invalid number'));
  34474. } else {
  34475. return this.returnNow(result);
  34476. }
  34477. }
  34478. }
  34479. }, {
  34480. key: "parseIntegerBin",
  34481. value: function parseIntegerBin() {
  34482. if (isBit(this.char)) {
  34483. this.consume();
  34484. } else if (this.char === CHAR_LOWBAR) {
  34485. return this.call(this.parseNoUnder);
  34486. } else {
  34487. var result = Integer(this.state.buf);
  34488. /* istanbul ignore if */
  34489. if (result.isNaN()) {
  34490. throw this.error(new TomlError('Invalid number'));
  34491. } else {
  34492. return this.returnNow(result);
  34493. }
  34494. }
  34495. }
  34496. /* DATETIME */
  34497. }, {
  34498. key: "parseDateTime",
  34499. value: function parseDateTime() {
  34500. // we enter here having just consumed the year and about to consume the hyphen
  34501. if (this.state.buf.length < 4) {
  34502. throw this.error(new TomlError('Years less than 1000 must be zero padded to four characters'));
  34503. }
  34504. this.state.result = this.state.buf;
  34505. this.state.buf = '';
  34506. return this.next(this.parseDateMonth);
  34507. }
  34508. }, {
  34509. key: "parseDateMonth",
  34510. value: function parseDateMonth() {
  34511. if (this.char === CHAR_HYPHEN) {
  34512. if (this.state.buf.length < 2) {
  34513. throw this.error(new TomlError('Months less than 10 must be zero padded to two characters'));
  34514. }
  34515. this.state.result += '-' + this.state.buf;
  34516. this.state.buf = '';
  34517. return this.next(this.parseDateDay);
  34518. } else if (isDigit(this.char)) {
  34519. this.consume();
  34520. } else {
  34521. throw this.error(new TomlError('Incomplete datetime'));
  34522. }
  34523. }
  34524. }, {
  34525. key: "parseDateDay",
  34526. value: function parseDateDay() {
  34527. if (this.char === CHAR_T || this.char === CHAR_SP) {
  34528. if (this.state.buf.length < 2) {
  34529. throw this.error(new TomlError('Days less than 10 must be zero padded to two characters'));
  34530. }
  34531. this.state.result += '-' + this.state.buf;
  34532. this.state.buf = '';
  34533. return this.next(this.parseStartTimeHour);
  34534. } else if (this.atEndOfWord()) {
  34535. return this.return(createDate(this.state.result + '-' + this.state.buf));
  34536. } else if (isDigit(this.char)) {
  34537. this.consume();
  34538. } else {
  34539. throw this.error(new TomlError('Incomplete datetime'));
  34540. }
  34541. }
  34542. }, {
  34543. key: "parseStartTimeHour",
  34544. value: function parseStartTimeHour() {
  34545. if (this.atEndOfWord()) {
  34546. return this.returnNow(createDate(this.state.result));
  34547. } else {
  34548. return this.goto(this.parseTimeHour);
  34549. }
  34550. }
  34551. }, {
  34552. key: "parseTimeHour",
  34553. value: function parseTimeHour() {
  34554. if (this.char === CHAR_COLON) {
  34555. if (this.state.buf.length < 2) {
  34556. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  34557. }
  34558. this.state.result += 'T' + this.state.buf;
  34559. this.state.buf = '';
  34560. return this.next(this.parseTimeMin);
  34561. } else if (isDigit(this.char)) {
  34562. this.consume();
  34563. } else {
  34564. throw this.error(new TomlError('Incomplete datetime'));
  34565. }
  34566. }
  34567. }, {
  34568. key: "parseTimeMin",
  34569. value: function parseTimeMin() {
  34570. if (this.state.buf.length < 2 && isDigit(this.char)) {
  34571. this.consume();
  34572. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  34573. this.state.result += ':' + this.state.buf;
  34574. this.state.buf = '';
  34575. return this.next(this.parseTimeSec);
  34576. } else {
  34577. throw this.error(new TomlError('Incomplete datetime'));
  34578. }
  34579. }
  34580. }, {
  34581. key: "parseTimeSec",
  34582. value: function parseTimeSec() {
  34583. if (isDigit(this.char)) {
  34584. this.consume();
  34585. if (this.state.buf.length === 2) {
  34586. this.state.result += ':' + this.state.buf;
  34587. this.state.buf = '';
  34588. return this.next(this.parseTimeZoneOrFraction);
  34589. }
  34590. } else {
  34591. throw this.error(new TomlError('Incomplete datetime'));
  34592. }
  34593. }
  34594. }, {
  34595. key: "parseOnlyTimeHour",
  34596. value: function parseOnlyTimeHour() {
  34597. /* istanbul ignore else */
  34598. if (this.char === CHAR_COLON) {
  34599. if (this.state.buf.length < 2) {
  34600. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  34601. }
  34602. this.state.result = this.state.buf;
  34603. this.state.buf = '';
  34604. return this.next(this.parseOnlyTimeMin);
  34605. } else {
  34606. throw this.error(new TomlError('Incomplete time'));
  34607. }
  34608. }
  34609. }, {
  34610. key: "parseOnlyTimeMin",
  34611. value: function parseOnlyTimeMin() {
  34612. if (this.state.buf.length < 2 && isDigit(this.char)) {
  34613. this.consume();
  34614. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  34615. this.state.result += ':' + this.state.buf;
  34616. this.state.buf = '';
  34617. return this.next(this.parseOnlyTimeSec);
  34618. } else {
  34619. throw this.error(new TomlError('Incomplete time'));
  34620. }
  34621. }
  34622. }, {
  34623. key: "parseOnlyTimeSec",
  34624. value: function parseOnlyTimeSec() {
  34625. if (isDigit(this.char)) {
  34626. this.consume();
  34627. if (this.state.buf.length === 2) {
  34628. return this.next(this.parseOnlyTimeFractionMaybe);
  34629. }
  34630. } else {
  34631. throw this.error(new TomlError('Incomplete time'));
  34632. }
  34633. }
  34634. }, {
  34635. key: "parseOnlyTimeFractionMaybe",
  34636. value: function parseOnlyTimeFractionMaybe() {
  34637. this.state.result += ':' + this.state.buf;
  34638. if (this.char === CHAR_PERIOD) {
  34639. this.state.buf = '';
  34640. this.next(this.parseOnlyTimeFraction);
  34641. } else {
  34642. return this.return(createTime(this.state.result));
  34643. }
  34644. }
  34645. }, {
  34646. key: "parseOnlyTimeFraction",
  34647. value: function parseOnlyTimeFraction() {
  34648. if (isDigit(this.char)) {
  34649. this.consume();
  34650. } else if (this.atEndOfWord()) {
  34651. if (this.state.buf.length === 0) throw this.error(new TomlError('Expected digit in milliseconds'));
  34652. return this.returnNow(createTime(this.state.result + '.' + this.state.buf));
  34653. } else {
  34654. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  34655. }
  34656. }
  34657. }, {
  34658. key: "parseTimeZoneOrFraction",
  34659. value: function parseTimeZoneOrFraction() {
  34660. if (this.char === CHAR_PERIOD) {
  34661. this.consume();
  34662. this.next(this.parseDateTimeFraction);
  34663. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  34664. this.consume();
  34665. this.next(this.parseTimeZoneHour);
  34666. } else if (this.char === CHAR_Z) {
  34667. this.consume();
  34668. return this.return(createDatetime(this.state.result + this.state.buf));
  34669. } else if (this.atEndOfWord()) {
  34670. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  34671. } else {
  34672. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  34673. }
  34674. }
  34675. }, {
  34676. key: "parseDateTimeFraction",
  34677. value: function parseDateTimeFraction() {
  34678. if (isDigit(this.char)) {
  34679. this.consume();
  34680. } else if (this.state.buf.length === 1) {
  34681. throw this.error(new TomlError('Expected digit in milliseconds'));
  34682. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  34683. this.consume();
  34684. this.next(this.parseTimeZoneHour);
  34685. } else if (this.char === CHAR_Z) {
  34686. this.consume();
  34687. return this.return(createDatetime(this.state.result + this.state.buf));
  34688. } else if (this.atEndOfWord()) {
  34689. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  34690. } else {
  34691. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  34692. }
  34693. }
  34694. }, {
  34695. key: "parseTimeZoneHour",
  34696. value: function parseTimeZoneHour() {
  34697. if (isDigit(this.char)) {
  34698. this.consume(); // FIXME: No more regexps
  34699. if (/\d\d$/.test(this.state.buf)) return this.next(this.parseTimeZoneSep);
  34700. } else {
  34701. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  34702. }
  34703. }
  34704. }, {
  34705. key: "parseTimeZoneSep",
  34706. value: function parseTimeZoneSep() {
  34707. if (this.char === CHAR_COLON) {
  34708. this.consume();
  34709. this.next(this.parseTimeZoneMin);
  34710. } else {
  34711. throw this.error(new TomlError('Unexpected character in datetime, expected colon'));
  34712. }
  34713. }
  34714. }, {
  34715. key: "parseTimeZoneMin",
  34716. value: function parseTimeZoneMin() {
  34717. if (isDigit(this.char)) {
  34718. this.consume();
  34719. if (/\d\d$/.test(this.state.buf)) return this.return(createDatetime(this.state.result + this.state.buf));
  34720. } else {
  34721. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  34722. }
  34723. }
  34724. /* BOOLEAN */
  34725. }, {
  34726. key: "parseBoolean",
  34727. value: function parseBoolean() {
  34728. /* istanbul ignore else */
  34729. if (this.char === CHAR_t) {
  34730. this.consume();
  34731. return this.next(this.parseTrue_r);
  34732. } else if (this.char === CHAR_f) {
  34733. this.consume();
  34734. return this.next(this.parseFalse_a);
  34735. }
  34736. }
  34737. }, {
  34738. key: "parseTrue_r",
  34739. value: function parseTrue_r() {
  34740. if (this.char === CHAR_r) {
  34741. this.consume();
  34742. return this.next(this.parseTrue_u);
  34743. } else {
  34744. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34745. }
  34746. }
  34747. }, {
  34748. key: "parseTrue_u",
  34749. value: function parseTrue_u() {
  34750. if (this.char === CHAR_u) {
  34751. this.consume();
  34752. return this.next(this.parseTrue_e);
  34753. } else {
  34754. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34755. }
  34756. }
  34757. }, {
  34758. key: "parseTrue_e",
  34759. value: function parseTrue_e() {
  34760. if (this.char === CHAR_e) {
  34761. return this.return(true);
  34762. } else {
  34763. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34764. }
  34765. }
  34766. }, {
  34767. key: "parseFalse_a",
  34768. value: function parseFalse_a() {
  34769. if (this.char === CHAR_a) {
  34770. this.consume();
  34771. return this.next(this.parseFalse_l);
  34772. } else {
  34773. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34774. }
  34775. }
  34776. }, {
  34777. key: "parseFalse_l",
  34778. value: function parseFalse_l() {
  34779. if (this.char === CHAR_l) {
  34780. this.consume();
  34781. return this.next(this.parseFalse_s);
  34782. } else {
  34783. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34784. }
  34785. }
  34786. }, {
  34787. key: "parseFalse_s",
  34788. value: function parseFalse_s() {
  34789. if (this.char === CHAR_s) {
  34790. this.consume();
  34791. return this.next(this.parseFalse_e);
  34792. } else {
  34793. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34794. }
  34795. }
  34796. }, {
  34797. key: "parseFalse_e",
  34798. value: function parseFalse_e() {
  34799. if (this.char === CHAR_e) {
  34800. return this.return(false);
  34801. } else {
  34802. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34803. }
  34804. }
  34805. /* INLINE LISTS */
  34806. }, {
  34807. key: "parseInlineList",
  34808. value: function parseInlineList() {
  34809. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  34810. return null;
  34811. } else if (this.char === Parser.END) {
  34812. throw this.error(new TomlError('Unterminated inline array'));
  34813. } else if (this.char === CHAR_NUM) {
  34814. return this.call(this.parseComment);
  34815. } else if (this.char === CHAR_RSQB) {
  34816. return this.return(this.state.resultArr || InlineList());
  34817. } else {
  34818. return this.callNow(this.parseValue, this.recordInlineListValue);
  34819. }
  34820. }
  34821. }, {
  34822. key: "recordInlineListValue",
  34823. value: function recordInlineListValue(value) {
  34824. if (this.state.resultArr) {
  34825. var listType = this.state.resultArr[_contentType];
  34826. var valueType = tomlType(value);
  34827. if (listType !== valueType) {
  34828. throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`));
  34829. }
  34830. } else {
  34831. this.state.resultArr = InlineList(tomlType(value));
  34832. }
  34833. if (isFloat(value) || isInteger(value)) {
  34834. // unbox now that we've verified they're ok
  34835. this.state.resultArr.push(value.valueOf());
  34836. } else {
  34837. this.state.resultArr.push(value);
  34838. }
  34839. return this.goto(this.parseInlineListNext);
  34840. }
  34841. }, {
  34842. key: "parseInlineListNext",
  34843. value: function parseInlineListNext() {
  34844. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  34845. return null;
  34846. } else if (this.char === CHAR_NUM) {
  34847. return this.call(this.parseComment);
  34848. } else if (this.char === CHAR_COMMA) {
  34849. return this.next(this.parseInlineList);
  34850. } else if (this.char === CHAR_RSQB) {
  34851. return this.goto(this.parseInlineList);
  34852. } else {
  34853. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  34854. }
  34855. }
  34856. /* INLINE TABLE */
  34857. }, {
  34858. key: "parseInlineTable",
  34859. value: function parseInlineTable() {
  34860. if (this.char === CHAR_SP || this.char === CTRL_I) {
  34861. return null;
  34862. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  34863. throw this.error(new TomlError('Unterminated inline array'));
  34864. } else if (this.char === CHAR_RCUB) {
  34865. return this.return(this.state.resultTable || InlineTable());
  34866. } else {
  34867. if (!this.state.resultTable) this.state.resultTable = InlineTable();
  34868. return this.callNow(this.parseAssign, this.recordInlineTableValue);
  34869. }
  34870. }
  34871. }, {
  34872. key: "recordInlineTableValue",
  34873. value: function recordInlineTableValue(kv) {
  34874. var target = this.state.resultTable;
  34875. var finalKey = kv.key.pop();
  34876. var _iteratorNormalCompletion2 = true;
  34877. var _didIteratorError2 = false;
  34878. var _iteratorError2 = undefined;
  34879. try {
  34880. for (var _iterator2 = kv.key[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  34881. var kw = _step2.value;
  34882. if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
  34883. throw this.error(new TomlError("Can't redefine existing key"));
  34884. }
  34885. target = target[kw] = target[kw] || Table();
  34886. }
  34887. } catch (err) {
  34888. _didIteratorError2 = true;
  34889. _iteratorError2 = err;
  34890. } finally {
  34891. try {
  34892. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  34893. _iterator2.return();
  34894. }
  34895. } finally {
  34896. if (_didIteratorError2) {
  34897. throw _iteratorError2;
  34898. }
  34899. }
  34900. }
  34901. if (hasKey(target, finalKey)) {
  34902. throw this.error(new TomlError("Can't redefine existing key"));
  34903. }
  34904. if (isInteger(kv.value) || isFloat(kv.value)) {
  34905. target[finalKey] = kv.value.valueOf();
  34906. } else {
  34907. target[finalKey] = kv.value;
  34908. }
  34909. return this.goto(this.parseInlineTableNext);
  34910. }
  34911. }, {
  34912. key: "parseInlineTableNext",
  34913. value: function parseInlineTableNext() {
  34914. if (this.char === CHAR_SP || this.char === CTRL_I) {
  34915. return null;
  34916. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  34917. throw this.error(new TomlError('Unterminated inline array'));
  34918. } else if (this.char === CHAR_COMMA) {
  34919. return this.next(this.parseInlineTable);
  34920. } else if (this.char === CHAR_RCUB) {
  34921. return this.goto(this.parseInlineTable);
  34922. } else {
  34923. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  34924. }
  34925. }
  34926. }]);
  34927. return TOMLParser;
  34928. }(Parser);
  34929. return TOMLParser;
  34930. }
  34931. });
  34932. var parsePrettyError = prettyError;
  34933. function prettyError(err, buf) {
  34934. /* istanbul ignore if */
  34935. if (err.pos == null || err.line == null) return err;
  34936. var msg = err.message;
  34937. msg += ` at row ${err.line + 1}, col ${err.col + 1}, pos ${err.pos}:\n`;
  34938. /* istanbul ignore else */
  34939. if (buf && buf.split) {
  34940. var lines = buf.split(/\n/);
  34941. var lineNumWidth = String(Math.min(lines.length, err.line + 3)).length;
  34942. var linePadding = ' ';
  34943. while (linePadding.length < lineNumWidth) {
  34944. linePadding += ' ';
  34945. }
  34946. for (var ii = Math.max(0, err.line - 1); ii < Math.min(lines.length, err.line + 2); ++ii) {
  34947. var lineNum = String(ii + 1);
  34948. if (lineNum.length < lineNumWidth) lineNum = ' ' + lineNum;
  34949. if (err.line === ii) {
  34950. msg += lineNum + '> ' + lines[ii] + '\n';
  34951. msg += linePadding + ' ';
  34952. for (var hh = 0; hh < err.col; ++hh) {
  34953. msg += ' ';
  34954. }
  34955. msg += '^\n';
  34956. } else {
  34957. msg += lineNum + ': ' + lines[ii] + '\n';
  34958. }
  34959. }
  34960. }
  34961. err.message = msg + '\n';
  34962. return err;
  34963. }
  34964. var parseString_1 = parseString;
  34965. function parseString(str) {
  34966. if (global.Buffer && global.Buffer.isBuffer(str)) {
  34967. str = str.toString('utf8');
  34968. }
  34969. var parser = new tomlParser();
  34970. try {
  34971. parser.parse(str);
  34972. return parser.finish();
  34973. } catch (err) {
  34974. throw parsePrettyError(err, str);
  34975. }
  34976. }
  34977. var loadToml = function loadToml(filePath, content) {
  34978. try {
  34979. return parseString_1(content);
  34980. } catch (error) {
  34981. error.message = `TOML Error in ${filePath}:\n${error.message}`;
  34982. throw error;
  34983. }
  34984. };
  34985. var resolveConfig_1 = createCommonjsModule(function (module) {
  34986. "use strict";
  34987. var getExplorerMemoized = mem(function (opts) {
  34988. var explorer = thirdParty$1.cosmiconfig("prettier", {
  34989. cache: opts.cache,
  34990. transform: function transform(result) {
  34991. if (result && result.config) {
  34992. if (typeof result.config === "string") {
  34993. var modulePath = resolve$1.sync(result.config, {
  34994. basedir: path.dirname(result.filepath)
  34995. });
  34996. result.config = require(modulePath);
  34997. }
  34998. if (typeof result.config !== "object") {
  34999. throw new Error(`Config is only allowed to be an object, ` + `but received ${typeof result.config} in "${result.filepath}"`);
  35000. }
  35001. delete result.config.$schema;
  35002. }
  35003. return result;
  35004. },
  35005. searchPlaces: ["package.json", ".prettierrc", ".prettierrc.json", ".prettierrc.yaml", ".prettierrc.yml", ".prettierrc.js", "prettier.config.js", ".prettierrc.toml"],
  35006. loaders: {
  35007. ".toml": loadToml
  35008. }
  35009. });
  35010. var _load = opts.sync ? explorer.loadSync : explorer.load;
  35011. var search = opts.sync ? explorer.searchSync : explorer.search;
  35012. return {
  35013. // cosmiconfig v4 interface
  35014. load: function load(searchPath, configPath) {
  35015. return configPath ? _load(configPath) : search(searchPath);
  35016. }
  35017. };
  35018. });
  35019. /** @param {{ cache: boolean, sync: boolean }} opts */
  35020. function getLoadFunction(opts) {
  35021. // Normalize opts before passing to a memoized function
  35022. opts = Object.assign({
  35023. sync: false,
  35024. cache: false
  35025. }, opts);
  35026. return getExplorerMemoized(opts).load;
  35027. }
  35028. function _resolveConfig(filePath, opts, sync) {
  35029. opts = Object.assign({
  35030. useCache: true
  35031. }, opts);
  35032. var loadOpts = {
  35033. cache: !!opts.useCache,
  35034. sync: !!sync,
  35035. editorconfig: !!opts.editorconfig
  35036. };
  35037. var load = getLoadFunction(loadOpts);
  35038. var loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  35039. var arr = [load, loadEditorConfig].map(function (l) {
  35040. return l(filePath, opts.config);
  35041. });
  35042. var unwrapAndMerge = function unwrapAndMerge(arr) {
  35043. var result = arr[0];
  35044. var editorConfigured = arr[1];
  35045. var merged = Object.assign({}, editorConfigured, mergeOverrides(Object.assign({}, result), filePath));
  35046. ["plugins", "pluginSearchDirs"].forEach(function (optionName) {
  35047. if (Array.isArray(merged[optionName])) {
  35048. merged[optionName] = merged[optionName].map(function (value) {
  35049. return typeof value === "string" && value.startsWith(".") // relative path
  35050. ? path.resolve(path.dirname(result.filepath), value) : value;
  35051. });
  35052. }
  35053. });
  35054. if (!result && !editorConfigured) {
  35055. return null;
  35056. }
  35057. return merged;
  35058. };
  35059. if (loadOpts.sync) {
  35060. return unwrapAndMerge(arr);
  35061. }
  35062. return Promise.all(arr).then(unwrapAndMerge);
  35063. }
  35064. var resolveConfig = function resolveConfig(filePath, opts) {
  35065. return _resolveConfig(filePath, opts, false);
  35066. };
  35067. resolveConfig.sync = function (filePath, opts) {
  35068. return _resolveConfig(filePath, opts, true);
  35069. };
  35070. function clearCache() {
  35071. mem.clear(getExplorerMemoized);
  35072. resolveConfigEditorconfig.clearCache();
  35073. }
  35074. function resolveConfigFile(filePath) {
  35075. var load = getLoadFunction({
  35076. sync: false
  35077. });
  35078. return load(filePath).then(function (result) {
  35079. return result ? result.filepath : null;
  35080. });
  35081. }
  35082. resolveConfigFile.sync = function (filePath) {
  35083. var load = getLoadFunction({
  35084. sync: true
  35085. });
  35086. var result = load(filePath);
  35087. return result ? result.filepath : null;
  35088. };
  35089. function mergeOverrides(configResult, filePath) {
  35090. var options = Object.assign({}, configResult.config);
  35091. if (filePath && options.overrides) {
  35092. var relativeFilePath = path.relative(path.dirname(configResult.filepath), filePath);
  35093. var _iteratorNormalCompletion = true;
  35094. var _didIteratorError = false;
  35095. var _iteratorError = undefined;
  35096. try {
  35097. for (var _iterator = options.overrides[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  35098. var override = _step.value;
  35099. if (pathMatchesGlobs(relativeFilePath, override.files, override.excludeFiles)) {
  35100. Object.assign(options, override.options);
  35101. }
  35102. }
  35103. } catch (err) {
  35104. _didIteratorError = true;
  35105. _iteratorError = err;
  35106. } finally {
  35107. try {
  35108. if (!_iteratorNormalCompletion && _iterator.return != null) {
  35109. _iterator.return();
  35110. }
  35111. } finally {
  35112. if (_didIteratorError) {
  35113. throw _iteratorError;
  35114. }
  35115. }
  35116. }
  35117. }
  35118. delete options.overrides;
  35119. return options;
  35120. } // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  35121. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  35122. var patternList = [].concat(patterns);
  35123. var excludedPatternList = [].concat(excludedPatterns || []);
  35124. var opts = {
  35125. matchBase: true,
  35126. dot: true
  35127. };
  35128. return patternList.some(function (pattern) {
  35129. return minimatch_1(filePath, pattern, opts);
  35130. }) && !excludedPatternList.some(function (excludedPattern) {
  35131. return minimatch_1(filePath, excludedPattern, opts);
  35132. });
  35133. }
  35134. module.exports = {
  35135. resolveConfig,
  35136. resolveConfigFile,
  35137. clearCache
  35138. };
  35139. });
  35140. var version = require$$0.version;
  35141. var getSupportInfo = support.getSupportInfo; // Luckily `opts` is always the 2nd argument
  35142. function _withPlugins(fn) {
  35143. return function () {
  35144. var args = Array.from(arguments);
  35145. var opts = args[1] || {};
  35146. args[1] = Object.assign({}, opts, {
  35147. plugins: loadPlugins_1(opts.plugins, opts.pluginSearchDirs)
  35148. });
  35149. return fn.apply(null, args);
  35150. };
  35151. }
  35152. function withPlugins(fn) {
  35153. var resultingFn = _withPlugins(fn);
  35154. if (fn.sync) {
  35155. resultingFn.sync = _withPlugins(fn.sync);
  35156. }
  35157. return resultingFn;
  35158. }
  35159. var formatWithCursor = withPlugins(core.formatWithCursor);
  35160. var src = {
  35161. formatWithCursor,
  35162. format(text, opts) {
  35163. return formatWithCursor(text, opts).formatted;
  35164. },
  35165. check: function check(text, opts) {
  35166. var formatted = formatWithCursor(text, opts).formatted;
  35167. return formatted === text;
  35168. },
  35169. doc,
  35170. resolveConfig: resolveConfig_1.resolveConfig,
  35171. resolveConfigFile: resolveConfig_1.resolveConfigFile,
  35172. clearConfigCache: resolveConfig_1.clearCache,
  35173. getFileInfo: withPlugins(getFileInfo_1),
  35174. getSupportInfo: withPlugins(getSupportInfo),
  35175. version,
  35176. util: utilShared,
  35177. /* istanbul ignore next */
  35178. __debug: {
  35179. parse: withPlugins(core.parse),
  35180. formatAST: withPlugins(core.formatAST),
  35181. formatDoc: withPlugins(core.formatDoc),
  35182. printToDoc: withPlugins(core.printToDoc),
  35183. printDocToString: withPlugins(core.printDocToString)
  35184. }
  35185. };
  35186. var prettier$2 = src;
  35187. var at;
  35188. var ch;
  35189. var escapee = {
  35190. '"': '"',
  35191. '\\': '\\',
  35192. '/': '/',
  35193. b: '\b',
  35194. f: '\f',
  35195. n: '\n',
  35196. r: '\r',
  35197. t: '\t'
  35198. };
  35199. var text;
  35200. var error = function error(m) {
  35201. // Call error when something is wrong.
  35202. throw {
  35203. name: 'SyntaxError',
  35204. message: m,
  35205. at: at,
  35206. text: text
  35207. };
  35208. };
  35209. var next = function next(c) {
  35210. // If a c parameter is provided, verify that it matches the current character.
  35211. if (c && c !== ch) {
  35212. error("Expected '" + c + "' instead of '" + ch + "'");
  35213. } // Get the next character. When there are no more characters,
  35214. // return the empty string.
  35215. ch = text.charAt(at);
  35216. at += 1;
  35217. return ch;
  35218. };
  35219. var number$2 = function number() {
  35220. // Parse a number value.
  35221. var number,
  35222. string = '';
  35223. if (ch === '-') {
  35224. string = '-';
  35225. next('-');
  35226. }
  35227. while (ch >= '0' && ch <= '9') {
  35228. string += ch;
  35229. next();
  35230. }
  35231. if (ch === '.') {
  35232. string += '.';
  35233. while (next() && ch >= '0' && ch <= '9') {
  35234. string += ch;
  35235. }
  35236. }
  35237. if (ch === 'e' || ch === 'E') {
  35238. string += ch;
  35239. next();
  35240. if (ch === '-' || ch === '+') {
  35241. string += ch;
  35242. next();
  35243. }
  35244. while (ch >= '0' && ch <= '9') {
  35245. string += ch;
  35246. next();
  35247. }
  35248. }
  35249. number = +string;
  35250. if (!isFinite(number)) {
  35251. error("Bad number");
  35252. } else {
  35253. return number;
  35254. }
  35255. };
  35256. var string$2 = function string() {
  35257. // Parse a string value.
  35258. var hex,
  35259. i,
  35260. string = '',
  35261. uffff; // When parsing for string values, we must look for " and \ characters.
  35262. if (ch === '"') {
  35263. while (next()) {
  35264. if (ch === '"') {
  35265. next();
  35266. return string;
  35267. } else if (ch === '\\') {
  35268. next();
  35269. if (ch === 'u') {
  35270. uffff = 0;
  35271. for (i = 0; i < 4; i += 1) {
  35272. hex = parseInt(next(), 16);
  35273. if (!isFinite(hex)) {
  35274. break;
  35275. }
  35276. uffff = uffff * 16 + hex;
  35277. }
  35278. string += String.fromCharCode(uffff);
  35279. } else if (typeof escapee[ch] === 'string') {
  35280. string += escapee[ch];
  35281. } else {
  35282. break;
  35283. }
  35284. } else {
  35285. string += ch;
  35286. }
  35287. }
  35288. }
  35289. error("Bad string");
  35290. };
  35291. var white = function white() {
  35292. // Skip whitespace.
  35293. while (ch && ch <= ' ') {
  35294. next();
  35295. }
  35296. };
  35297. var word$2 = function word() {
  35298. // true, false, or null.
  35299. switch (ch) {
  35300. case 't':
  35301. next('t');
  35302. next('r');
  35303. next('u');
  35304. next('e');
  35305. return true;
  35306. case 'f':
  35307. next('f');
  35308. next('a');
  35309. next('l');
  35310. next('s');
  35311. next('e');
  35312. return false;
  35313. case 'n':
  35314. next('n');
  35315. next('u');
  35316. next('l');
  35317. next('l');
  35318. return null;
  35319. }
  35320. error("Unexpected '" + ch + "'");
  35321. };
  35322. var value;
  35323. var array$4 = function array() {
  35324. // Parse an array value.
  35325. var array = [];
  35326. if (ch === '[') {
  35327. next('[');
  35328. white();
  35329. if (ch === ']') {
  35330. next(']');
  35331. return array; // empty array
  35332. }
  35333. while (ch) {
  35334. array.push(value());
  35335. white();
  35336. if (ch === ']') {
  35337. next(']');
  35338. return array;
  35339. }
  35340. next(',');
  35341. white();
  35342. }
  35343. }
  35344. error("Bad array");
  35345. };
  35346. var object$1 = function object() {
  35347. // Parse an object value.
  35348. var key,
  35349. object = {};
  35350. if (ch === '{') {
  35351. next('{');
  35352. white();
  35353. if (ch === '}') {
  35354. next('}');
  35355. return object; // empty object
  35356. }
  35357. while (ch) {
  35358. key = string$2();
  35359. white();
  35360. next(':');
  35361. if (Object.hasOwnProperty.call(object, key)) {
  35362. error('Duplicate key "' + key + '"');
  35363. }
  35364. object[key] = value();
  35365. white();
  35366. if (ch === '}') {
  35367. next('}');
  35368. return object;
  35369. }
  35370. next(',');
  35371. white();
  35372. }
  35373. }
  35374. error("Bad object");
  35375. };
  35376. value = function value() {
  35377. // Parse a JSON value. It could be an object, an array, a string, a number,
  35378. // or a word.
  35379. white();
  35380. switch (ch) {
  35381. case '{':
  35382. return object$1();
  35383. case '[':
  35384. return array$4();
  35385. case '"':
  35386. return string$2();
  35387. case '-':
  35388. return number$2();
  35389. default:
  35390. return ch >= '0' && ch <= '9' ? number$2() : word$2();
  35391. }
  35392. }; // Return the json_parse function. It will have access to all of the above
  35393. // functions and variables.
  35394. var parse$8 = function parse(source, reviver) {
  35395. var result;
  35396. text = source;
  35397. at = 0;
  35398. ch = ' ';
  35399. result = value();
  35400. white();
  35401. if (ch) {
  35402. error("Syntax error");
  35403. } // If there is a reviver function, we recursively walk the new structure,
  35404. // passing each name/value pair to the reviver function for possible
  35405. // transformation, starting with a temporary root object that holds the result
  35406. // in an empty key. If there is not a reviver function, we simply return the
  35407. // result.
  35408. return typeof reviver === 'function' ? function walk(holder, key) {
  35409. var k,
  35410. v,
  35411. value = holder[key];
  35412. if (value && typeof value === 'object') {
  35413. for (k in value) {
  35414. if (Object.prototype.hasOwnProperty.call(value, k)) {
  35415. v = walk(value, k);
  35416. if (v !== undefined) {
  35417. value[k] = v;
  35418. } else {
  35419. delete value[k];
  35420. }
  35421. }
  35422. }
  35423. }
  35424. return reviver.call(holder, key, value);
  35425. }({
  35426. '': result
  35427. }, '') : result;
  35428. };
  35429. var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  35430. var gap;
  35431. var indent$10;
  35432. var meta$1 = {
  35433. // table of character substitutions
  35434. '\b': '\\b',
  35435. '\t': '\\t',
  35436. '\n': '\\n',
  35437. '\f': '\\f',
  35438. '\r': '\\r',
  35439. '"': '\\"',
  35440. '\\': '\\\\'
  35441. };
  35442. var rep;
  35443. function quote(string) {
  35444. // If the string contains no control characters, no quote characters, and no
  35445. // backslash characters, then we can safely slap some quotes around it.
  35446. // Otherwise we must also replace the offending characters with safe escape
  35447. // sequences.
  35448. escapable.lastIndex = 0;
  35449. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  35450. var c = meta$1[a];
  35451. return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  35452. }) + '"' : '"' + string + '"';
  35453. }
  35454. function str(key, holder) {
  35455. // Produce a string from holder[key].
  35456. var i,
  35457. // The loop counter.
  35458. k,
  35459. // The member key.
  35460. v,
  35461. // The member value.
  35462. length,
  35463. mind = gap,
  35464. partial,
  35465. value = holder[key]; // If the value has a toJSON method, call it to obtain a replacement value.
  35466. if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
  35467. value = value.toJSON(key);
  35468. } // If we were called with a replacer function, then call the replacer to
  35469. // obtain a replacement value.
  35470. if (typeof rep === 'function') {
  35471. value = rep.call(holder, key, value);
  35472. } // What happens next depends on the value's type.
  35473. switch (typeof value) {
  35474. case 'string':
  35475. return quote(value);
  35476. case 'number':
  35477. // JSON numbers must be finite. Encode non-finite numbers as null.
  35478. return isFinite(value) ? String(value) : 'null';
  35479. case 'boolean':
  35480. case 'null':
  35481. // If the value is a boolean or null, convert it to a string. Note:
  35482. // typeof null does not produce 'null'. The case is included here in
  35483. // the remote chance that this gets fixed someday.
  35484. return String(value);
  35485. case 'object':
  35486. if (!value) return 'null';
  35487. gap += indent$10;
  35488. partial = []; // Array.isArray
  35489. if (Object.prototype.toString.apply(value) === '[object Array]') {
  35490. length = value.length;
  35491. for (i = 0; i < length; i += 1) {
  35492. partial[i] = str(i, value) || 'null';
  35493. } // Join all of the elements together, separated with commas, and
  35494. // wrap them in brackets.
  35495. v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
  35496. gap = mind;
  35497. return v;
  35498. } // If the replacer is an array, use it to select the members to be
  35499. // stringified.
  35500. if (rep && typeof rep === 'object') {
  35501. length = rep.length;
  35502. for (i = 0; i < length; i += 1) {
  35503. k = rep[i];
  35504. if (typeof k === 'string') {
  35505. v = str(k, value);
  35506. if (v) {
  35507. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  35508. }
  35509. }
  35510. }
  35511. } else {
  35512. // Otherwise, iterate through all of the keys in the object.
  35513. for (k in value) {
  35514. if (Object.prototype.hasOwnProperty.call(value, k)) {
  35515. v = str(k, value);
  35516. if (v) {
  35517. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  35518. }
  35519. }
  35520. }
  35521. } // Join all of the member texts together, separated with commas,
  35522. // and wrap them in braces.
  35523. v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
  35524. gap = mind;
  35525. return v;
  35526. }
  35527. }
  35528. var stringify$1 = function stringify(value, replacer, space) {
  35529. var i;
  35530. gap = '';
  35531. indent$10 = ''; // If the space parameter is a number, make an indent string containing that
  35532. // many spaces.
  35533. if (typeof space === 'number') {
  35534. for (i = 0; i < space; i += 1) {
  35535. indent$10 += ' ';
  35536. }
  35537. } // If the space parameter is a string, it will be used as the indent string.
  35538. else if (typeof space === 'string') {
  35539. indent$10 = space;
  35540. } // If there is a replacer, it must be a function or an array.
  35541. // Otherwise, throw an error.
  35542. rep = replacer;
  35543. if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  35544. throw new Error('JSON.stringify');
  35545. } // Make a fake root object containing our value under the key of ''.
  35546. // Return the result of stringifying the value.
  35547. return str('', {
  35548. '': value
  35549. });
  35550. };
  35551. var parse$7 = parse$8;
  35552. var stringify = stringify$1;
  35553. var jsonify = {
  35554. parse: parse$7,
  35555. stringify: stringify
  35556. };
  35557. var json$10 = typeof JSON !== 'undefined' ? JSON : jsonify;
  35558. var jsonStableStringify = function jsonStableStringify(obj, opts) {
  35559. if (!opts) opts = {};
  35560. if (typeof opts === 'function') opts = {
  35561. cmp: opts
  35562. };
  35563. var space = opts.space || '';
  35564. if (typeof space === 'number') space = Array(space + 1).join(' ');
  35565. var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
  35566. var replacer = opts.replacer || function (key, value) {
  35567. return value;
  35568. };
  35569. var cmp = opts.cmp && function (f) {
  35570. return function (node) {
  35571. return function (a, b) {
  35572. var aobj = {
  35573. key: a,
  35574. value: node[a]
  35575. };
  35576. var bobj = {
  35577. key: b,
  35578. value: node[b]
  35579. };
  35580. return f(aobj, bobj);
  35581. };
  35582. };
  35583. }(opts.cmp);
  35584. var seen = [];
  35585. return function stringify(parent, key, node, level) {
  35586. var indent = space ? '\n' + new Array(level + 1).join(space) : '';
  35587. var colonSeparator = space ? ': ' : ':';
  35588. if (node && node.toJSON && typeof node.toJSON === 'function') {
  35589. node = node.toJSON();
  35590. }
  35591. node = replacer.call(parent, key, node);
  35592. if (node === undefined) {
  35593. return;
  35594. }
  35595. if (typeof node !== 'object' || node === null) {
  35596. return json$10.stringify(node);
  35597. }
  35598. if (isArray$1(node)) {
  35599. var out = [];
  35600. for (var i = 0; i < node.length; i++) {
  35601. var item = stringify(node, i, node[i], level + 1) || json$10.stringify(null);
  35602. out.push(indent + space + item);
  35603. }
  35604. return '[' + out.join(',') + indent + ']';
  35605. } else {
  35606. if (seen.indexOf(node) !== -1) {
  35607. if (cycles) return json$10.stringify('__cycle__');
  35608. throw new TypeError('Converting circular structure to JSON');
  35609. } else seen.push(node);
  35610. var keys = objectKeys(node).sort(cmp && cmp(node));
  35611. var out = [];
  35612. for (var i = 0; i < keys.length; i++) {
  35613. var key = keys[i];
  35614. var value = stringify(node, key, node[key], level + 1);
  35615. if (!value) continue;
  35616. var keyValue = json$10.stringify(key) + colonSeparator + value;
  35617. out.push(indent + space + keyValue);
  35618. }
  35619. seen.splice(seen.indexOf(node), 1);
  35620. return '{' + out.join(',') + indent + '}';
  35621. }
  35622. }({
  35623. '': obj
  35624. }, '', obj, 0);
  35625. };
  35626. var isArray$1 = Array.isArray || function (x) {
  35627. return {}.toString.call(x) === '[object Array]';
  35628. };
  35629. var objectKeys = Object.keys || function (obj) {
  35630. var has = Object.prototype.hasOwnProperty || function () {
  35631. return true;
  35632. };
  35633. var keys = [];
  35634. for (var key in obj) {
  35635. if (has.call(obj, key)) keys.push(key);
  35636. }
  35637. return keys;
  35638. };
  35639. function preserveCamelCase(str) {
  35640. var isLastCharLower = false;
  35641. var isLastCharUpper = false;
  35642. var isLastLastCharUpper = false;
  35643. for (var i = 0; i < str.length; i++) {
  35644. var c = str[i];
  35645. if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
  35646. str = str.substr(0, i) + '-' + str.substr(i);
  35647. isLastCharLower = false;
  35648. isLastLastCharUpper = isLastCharUpper;
  35649. isLastCharUpper = true;
  35650. i++;
  35651. } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
  35652. str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
  35653. isLastLastCharUpper = isLastCharUpper;
  35654. isLastCharUpper = false;
  35655. isLastCharLower = true;
  35656. } else {
  35657. isLastCharLower = c.toLowerCase() === c;
  35658. isLastLastCharUpper = isLastCharUpper;
  35659. isLastCharUpper = c.toUpperCase() === c;
  35660. }
  35661. }
  35662. return str;
  35663. }
  35664. var camelcase = function camelcase(str) {
  35665. if (arguments.length > 1) {
  35666. str = Array.from(arguments).map(function (x) {
  35667. return x.trim();
  35668. }).filter(function (x) {
  35669. return x.length;
  35670. }).join('-');
  35671. } else {
  35672. str = str.trim();
  35673. }
  35674. if (str.length === 0) {
  35675. return '';
  35676. }
  35677. if (str.length === 1) {
  35678. return str.toLowerCase();
  35679. }
  35680. if (/^[a-z0-9]+$/.test(str)) {
  35681. return str;
  35682. }
  35683. var hasUpperCase = str !== str.toLowerCase();
  35684. if (hasUpperCase) {
  35685. str = preserveCamelCase(str);
  35686. }
  35687. return str.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
  35688. return p1.toUpperCase();
  35689. });
  35690. };
  35691. /*!
  35692. * dashify <https://github.com/jonschlinkert/dashify>
  35693. *
  35694. * Copyright (c) 2015 Jon Schlinkert.
  35695. * Licensed under the MIT license.
  35696. */
  35697. var dashify = function dashify(str) {
  35698. if (typeof str !== 'string') {
  35699. throw new TypeError('expected a string');
  35700. }
  35701. str = str.replace(/([a-z])([A-Z])/g, '$1-$2');
  35702. str = str.replace(/[ \t\W]/g, '-');
  35703. str = str.replace(/^-+|-+$/g, '');
  35704. return str.toLowerCase();
  35705. };
  35706. var minimist = function minimist(args, opts) {
  35707. if (!opts) opts = {};
  35708. var flags = {
  35709. bools: {},
  35710. strings: {},
  35711. unknownFn: null
  35712. };
  35713. if (typeof opts['unknown'] === 'function') {
  35714. flags.unknownFn = opts['unknown'];
  35715. }
  35716. if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
  35717. flags.allBools = true;
  35718. } else {
  35719. [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
  35720. flags.bools[key] = true;
  35721. });
  35722. }
  35723. var aliases = {};
  35724. Object.keys(opts.alias || {}).forEach(function (key) {
  35725. aliases[key] = [].concat(opts.alias[key]);
  35726. aliases[key].forEach(function (x) {
  35727. aliases[x] = [key].concat(aliases[key].filter(function (y) {
  35728. return x !== y;
  35729. }));
  35730. });
  35731. });
  35732. [].concat(opts.string).filter(Boolean).forEach(function (key) {
  35733. flags.strings[key] = true;
  35734. if (aliases[key]) {
  35735. flags.strings[aliases[key]] = true;
  35736. }
  35737. });
  35738. var defaults = opts['default'] || {};
  35739. var argv = {
  35740. _: []
  35741. };
  35742. Object.keys(flags.bools).forEach(function (key) {
  35743. setArg(key, defaults[key] === undefined ? false : defaults[key]);
  35744. });
  35745. var notFlags = [];
  35746. if (args.indexOf('--') !== -1) {
  35747. notFlags = args.slice(args.indexOf('--') + 1);
  35748. args = args.slice(0, args.indexOf('--'));
  35749. }
  35750. function argDefined(key, arg) {
  35751. return flags.allBools && /^--[^=]+$/.test(arg) || flags.strings[key] || flags.bools[key] || aliases[key];
  35752. }
  35753. function setArg(key, val, arg) {
  35754. if (arg && flags.unknownFn && !argDefined(key, arg)) {
  35755. if (flags.unknownFn(arg) === false) return;
  35756. }
  35757. var value = !flags.strings[key] && isNumber(val) ? Number(val) : val;
  35758. setKey(argv, key.split('.'), value);
  35759. (aliases[key] || []).forEach(function (x) {
  35760. setKey(argv, x.split('.'), value);
  35761. });
  35762. }
  35763. function setKey(obj, keys, value) {
  35764. var o = obj;
  35765. keys.slice(0, -1).forEach(function (key) {
  35766. if (o[key] === undefined) o[key] = {};
  35767. o = o[key];
  35768. });
  35769. var key = keys[keys.length - 1];
  35770. if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
  35771. o[key] = value;
  35772. } else if (Array.isArray(o[key])) {
  35773. o[key].push(value);
  35774. } else {
  35775. o[key] = [o[key], value];
  35776. }
  35777. }
  35778. function aliasIsBoolean(key) {
  35779. return aliases[key].some(function (x) {
  35780. return flags.bools[x];
  35781. });
  35782. }
  35783. for (var i = 0; i < args.length; i++) {
  35784. var arg = args[i];
  35785. if (/^--.+=/.test(arg)) {
  35786. // Using [\s\S] instead of . because js doesn't support the
  35787. // 'dotall' regex modifier. See:
  35788. // http://stackoverflow.com/a/1068308/13216
  35789. var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
  35790. var key = m[1];
  35791. var value = m[2];
  35792. if (flags.bools[key]) {
  35793. value = value !== 'false';
  35794. }
  35795. setArg(key, value, arg);
  35796. } else if (/^--no-.+/.test(arg)) {
  35797. var key = arg.match(/^--no-(.+)/)[1];
  35798. setArg(key, false, arg);
  35799. } else if (/^--.+/.test(arg)) {
  35800. var key = arg.match(/^--(.+)/)[1];
  35801. var next = args[i + 1];
  35802. if (next !== undefined && !/^-/.test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  35803. setArg(key, next, arg);
  35804. i++;
  35805. } else if (/^(true|false)$/.test(next)) {
  35806. setArg(key, next === 'true', arg);
  35807. i++;
  35808. } else {
  35809. setArg(key, flags.strings[key] ? '' : true, arg);
  35810. }
  35811. } else if (/^-[^-]+/.test(arg)) {
  35812. var letters = arg.slice(1, -1).split('');
  35813. var broken = false;
  35814. for (var j = 0; j < letters.length; j++) {
  35815. var next = arg.slice(j + 2);
  35816. if (next === '-') {
  35817. setArg(letters[j], next, arg);
  35818. continue;
  35819. }
  35820. if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
  35821. setArg(letters[j], next.split('=')[1], arg);
  35822. broken = true;
  35823. break;
  35824. }
  35825. if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
  35826. setArg(letters[j], next, arg);
  35827. broken = true;
  35828. break;
  35829. }
  35830. if (letters[j + 1] && letters[j + 1].match(/\W/)) {
  35831. setArg(letters[j], arg.slice(j + 2), arg);
  35832. broken = true;
  35833. break;
  35834. } else {
  35835. setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
  35836. }
  35837. }
  35838. var key = arg.slice(-1)[0];
  35839. if (!broken && key !== '-') {
  35840. if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !flags.bools[key] && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  35841. setArg(key, args[i + 1], arg);
  35842. i++;
  35843. } else if (args[i + 1] && /true|false/.test(args[i + 1])) {
  35844. setArg(key, args[i + 1] === 'true', arg);
  35845. i++;
  35846. } else {
  35847. setArg(key, flags.strings[key] ? '' : true, arg);
  35848. }
  35849. }
  35850. } else {
  35851. if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
  35852. argv._.push(flags.strings['_'] || !isNumber(arg) ? arg : Number(arg));
  35853. }
  35854. if (opts.stopEarly) {
  35855. argv._.push.apply(argv._, args.slice(i + 1));
  35856. break;
  35857. }
  35858. }
  35859. }
  35860. Object.keys(defaults).forEach(function (key) {
  35861. if (!hasKey(argv, key.split('.'))) {
  35862. setKey(argv, key.split('.'), defaults[key]);
  35863. (aliases[key] || []).forEach(function (x) {
  35864. setKey(argv, x.split('.'), defaults[key]);
  35865. });
  35866. }
  35867. });
  35868. if (opts['--']) {
  35869. argv['--'] = new Array();
  35870. notFlags.forEach(function (key) {
  35871. argv['--'].push(key);
  35872. });
  35873. } else {
  35874. notFlags.forEach(function (key) {
  35875. argv._.push(key);
  35876. });
  35877. }
  35878. return argv;
  35879. };
  35880. function hasKey(obj, keys) {
  35881. var o = obj;
  35882. keys.slice(0, -1).forEach(function (key) {
  35883. o = o[key] || {};
  35884. });
  35885. var key = keys[keys.length - 1];
  35886. return key in o;
  35887. }
  35888. function isNumber(x) {
  35889. if (typeof x === 'number') return true;
  35890. if (/^0x[0-9a-f]+$/i.test(x)) return true;
  35891. return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
  35892. }
  35893. var PLACEHOLDER = null;
  35894. /**
  35895. * unspecified boolean flag without default value is parsed as `undefined` instead of `false`
  35896. */
  35897. var minimist_1 = function minimist_1(args, options) {
  35898. var boolean = options.boolean || [];
  35899. var defaults = options.default || {};
  35900. var booleanWithoutDefault = boolean.filter(function (key) {
  35901. return !(key in defaults);
  35902. });
  35903. var newDefaults = Object.assign({}, defaults, booleanWithoutDefault.reduce(function (reduced, key) {
  35904. return Object.assign(reduced, {
  35905. [key]: PLACEHOLDER
  35906. });
  35907. }, {}));
  35908. var parsed = minimist(args, Object.assign({}, options, {
  35909. default: newDefaults
  35910. }));
  35911. return Object.keys(parsed).reduce(function (reduced, key) {
  35912. if (parsed[key] !== PLACEHOLDER) {
  35913. reduced[key] = parsed[key];
  35914. }
  35915. return reduced;
  35916. }, {});
  35917. };
  35918. var categoryOrder = [coreOptions$1.CATEGORY_OUTPUT, coreOptions$1.CATEGORY_FORMAT, coreOptions$1.CATEGORY_CONFIG, coreOptions$1.CATEGORY_EDITOR, coreOptions$1.CATEGORY_OTHER];
  35919. /**
  35920. * {
  35921. * [optionName]: {
  35922. * // The type of the option. For 'choice', see also `choices` below.
  35923. * // When passing a type other than the ones listed below, the option is
  35924. * // treated as taking any string as argument, and `--option <${type}>` will
  35925. * // be displayed in --help.
  35926. * type: "boolean" | "choice" | "int" | string;
  35927. *
  35928. * // Default value to be passed to the minimist option `default`.
  35929. * default?: any;
  35930. *
  35931. * // Alias name to be passed to the minimist option `alias`.
  35932. * alias?: string;
  35933. *
  35934. * // For grouping options by category in --help.
  35935. * category?: string;
  35936. *
  35937. * // Description to be displayed in --help. If omitted, the option won't be
  35938. * // shown at all in --help (but see also `oppositeDescription` below).
  35939. * description?: string;
  35940. *
  35941. * // Description for `--no-${name}` to be displayed in --help. If omitted,
  35942. * // `--no-${name}` won't be shown.
  35943. * oppositeDescription?: string;
  35944. *
  35945. * // Indicate if this option is simply passed to the API.
  35946. * // true: use camelified name as the API option name.
  35947. * // string: use this value as the API option name.
  35948. * forwardToApi?: boolean | string;
  35949. *
  35950. * // Indicate that a CLI flag should be an array when forwarded to the API.
  35951. * array?: boolean;
  35952. *
  35953. * // Specify available choices for validation. They will also be displayed
  35954. * // in --help as <a|b|c>.
  35955. * // Use an object instead of a string if a choice is deprecated and should
  35956. * // be treated as `redirect` instead, or if you'd like to add description for
  35957. * // the choice.
  35958. * choices?: Array<
  35959. * | string
  35960. * | { value: string, description?: string, deprecated?: boolean, redirect?: string }
  35961. * >;
  35962. *
  35963. * // If the option has a value that is an exception to the regular value
  35964. * // constraints, indicate that value here (or use a function for more
  35965. * // flexibility).
  35966. * exception?: ((value: any) => boolean);
  35967. *
  35968. * // Indicate that the option is deprecated. Use a string to add an extra
  35969. * // message to --help for the option, for example to suggest a replacement
  35970. * // option.
  35971. * deprecated?: true | string;
  35972. * }
  35973. * }
  35974. *
  35975. * Note: The options below are sorted alphabetically.
  35976. */
  35977. var options$21 = {
  35978. check: {
  35979. type: "boolean",
  35980. category: coreOptions$1.CATEGORY_OUTPUT,
  35981. alias: "c",
  35982. description: dedent_1`
  35983. Check if the given files are formatted, print a human-friendly summary
  35984. message and paths to unformatted files (see also --list-different).
  35985. `
  35986. },
  35987. color: {
  35988. // The supports-color package (a sub sub dependency) looks directly at
  35989. // `process.argv` for `--no-color` and such-like options. The reason it is
  35990. // listed here is to avoid "Ignored unknown option: --no-color" warnings.
  35991. // See https://github.com/chalk/supports-color/#info for more information.
  35992. type: "boolean",
  35993. default: true,
  35994. description: "Colorize error messages.",
  35995. oppositeDescription: "Do not colorize error messages."
  35996. },
  35997. config: {
  35998. type: "path",
  35999. category: coreOptions$1.CATEGORY_CONFIG,
  36000. description: "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
  36001. oppositeDescription: "Do not look for a configuration file.",
  36002. exception: function exception(value) {
  36003. return value === false;
  36004. }
  36005. },
  36006. "config-precedence": {
  36007. type: "choice",
  36008. category: coreOptions$1.CATEGORY_CONFIG,
  36009. default: "cli-override",
  36010. choices: [{
  36011. value: "cli-override",
  36012. description: "CLI options take precedence over config file"
  36013. }, {
  36014. value: "file-override",
  36015. description: "Config file take precedence over CLI options"
  36016. }, {
  36017. value: "prefer-file",
  36018. description: dedent_1`
  36019. If a config file is found will evaluate it and ignore other CLI options.
  36020. If no config file is found CLI options will evaluate as normal.
  36021. `
  36022. }],
  36023. description: "Define in which order config files and CLI options should be evaluated."
  36024. },
  36025. "debug-benchmark": {
  36026. // Run the formatting benchmarks. Requires 'benchmark' module to be installed.
  36027. type: "boolean"
  36028. },
  36029. "debug-check": {
  36030. // Run the formatting once again on the formatted output, throw if different.
  36031. type: "boolean"
  36032. },
  36033. "debug-print-doc": {
  36034. type: "boolean"
  36035. },
  36036. "debug-repeat": {
  36037. // Repeat the formatting a few times and measure the average duration.
  36038. type: "int",
  36039. default: 0
  36040. },
  36041. editorconfig: {
  36042. type: "boolean",
  36043. category: coreOptions$1.CATEGORY_CONFIG,
  36044. description: "Take .editorconfig into account when parsing configuration.",
  36045. oppositeDescription: "Don't take .editorconfig into account when parsing configuration.",
  36046. default: true
  36047. },
  36048. "find-config-path": {
  36049. type: "path",
  36050. category: coreOptions$1.CATEGORY_CONFIG,
  36051. description: "Find and print the path to a configuration file for the given input file."
  36052. },
  36053. "file-info": {
  36054. type: "path",
  36055. description: dedent_1`
  36056. Extract the following info (as JSON) for a given file path. Reported fields:
  36057. * ignored (boolean) - true if file path is filtered by --ignore-path
  36058. * inferredParser (string | null) - name of parser inferred from file path
  36059. `
  36060. },
  36061. help: {
  36062. type: "flag",
  36063. alias: "h",
  36064. description: dedent_1`
  36065. Show CLI usage, or details about the given flag.
  36066. Example: --help write
  36067. `,
  36068. exception: function exception(value) {
  36069. return value === "";
  36070. }
  36071. },
  36072. "ignore-path": {
  36073. type: "path",
  36074. category: coreOptions$1.CATEGORY_CONFIG,
  36075. default: ".prettierignore",
  36076. description: "Path to a file with patterns describing files to ignore."
  36077. },
  36078. "list-different": {
  36079. type: "boolean",
  36080. category: coreOptions$1.CATEGORY_OUTPUT,
  36081. alias: "l",
  36082. description: "Print the names of files that are different from Prettier's formatting (see also --check)."
  36083. },
  36084. loglevel: {
  36085. type: "choice",
  36086. description: "What level of logs to report.",
  36087. default: "log",
  36088. choices: ["silent", "error", "warn", "log", "debug"]
  36089. },
  36090. stdin: {
  36091. type: "boolean",
  36092. description: "Force reading input from stdin."
  36093. },
  36094. "support-info": {
  36095. type: "boolean",
  36096. description: "Print support information as JSON."
  36097. },
  36098. version: {
  36099. type: "boolean",
  36100. alias: "v",
  36101. description: "Print Prettier version."
  36102. },
  36103. "with-node-modules": {
  36104. type: "boolean",
  36105. category: coreOptions$1.CATEGORY_CONFIG,
  36106. description: "Process files inside 'node_modules' directory."
  36107. },
  36108. write: {
  36109. type: "boolean",
  36110. category: coreOptions$1.CATEGORY_OUTPUT,
  36111. description: "Edit files in-place. (Beware!)"
  36112. }
  36113. };
  36114. var usageSummary = dedent_1`
  36115. Usage: prettier [options] [file/glob ...]
  36116. By default, output is written to stdout.
  36117. Stdin is read if it is piped to Prettier and no files are given.
  36118. `;
  36119. var constant = {
  36120. categoryOrder,
  36121. options: options$21,
  36122. usageSummary
  36123. };
  36124. // which causes unwanted lines in the output. An additional check for isCI() helps.
  36125. // See https://github.com/prettier/prettier/issues/5801
  36126. var isTty = function isTTY() {
  36127. return process.stdout.isTTY && !thirdParty$1.isCI();
  36128. };
  36129. var OPTION_USAGE_THRESHOLD = 25;
  36130. var CHOICE_USAGE_MARGIN = 3;
  36131. var CHOICE_USAGE_INDENTATION = 2;
  36132. function getOptions(argv, detailedOptions) {
  36133. return detailedOptions.filter(function (option) {
  36134. return option.forwardToApi;
  36135. }).reduce(function (current, option) {
  36136. return Object.assign(current, {
  36137. [option.forwardToApi]: argv[option.name]
  36138. });
  36139. }, {});
  36140. }
  36141. function cliifyOptions(object, apiDetailedOptionMap) {
  36142. return Object.keys(object || {}).reduce(function (output, key) {
  36143. var apiOption = apiDetailedOptionMap[key];
  36144. var cliKey = apiOption ? apiOption.name : key;
  36145. output[dashify(cliKey)] = object[key];
  36146. return output;
  36147. }, {});
  36148. }
  36149. function diff(a, b) {
  36150. return lib.createTwoFilesPatch("", "", a, b, "", "", {
  36151. context: 2
  36152. });
  36153. }
  36154. function handleError(context, filename, error) {
  36155. if (error instanceof errors.UndefinedParserError) {
  36156. if (context.argv["write"] && isTty()) {
  36157. readline.clearLine(process.stdout, 0);
  36158. readline.cursorTo(process.stdout, 0, null);
  36159. }
  36160. if (!context.argv["check"] && !context.argv["list-different"]) {
  36161. process.exitCode = 2;
  36162. }
  36163. context.logger.error(error.message);
  36164. return;
  36165. }
  36166. if (context.argv["write"]) {
  36167. // Add newline to split errors from filename line.
  36168. process.stdout.write("\n");
  36169. }
  36170. var isParseError = Boolean(error && error.loc);
  36171. var isValidationError = /Validation Error/.test(error && error.message); // For parse errors and validation errors, we only want to show the error
  36172. // message formatted in a nice way. `String(error)` takes care of that. Other
  36173. // (unexpected) errors are passed as-is as a separate argument to
  36174. // `console.error`. That includes the stack trace (if any), and shows a nice
  36175. // `util.inspect` of throws things that aren't `Error` objects. (The Flow
  36176. // parser has mistakenly thrown arrays sometimes.)
  36177. if (isParseError) {
  36178. context.logger.error(`${filename}: ${String(error)}`);
  36179. } else if (isValidationError || error instanceof errors.ConfigError) {
  36180. context.logger.error(String(error)); // If validation fails for one file, it will fail for all of them.
  36181. process.exit(1);
  36182. } else if (error instanceof errors.DebugError) {
  36183. context.logger.error(`${filename}: ${error.message}`);
  36184. } else {
  36185. context.logger.error(filename + ": " + (error.stack || error));
  36186. } // Don't exit the process if one file failed
  36187. process.exitCode = 2;
  36188. }
  36189. function logResolvedConfigPathOrDie(context) {
  36190. var configFile = prettier$2.resolveConfigFile.sync(context.argv["find-config-path"]);
  36191. if (configFile) {
  36192. context.logger.log(path.relative(process.cwd(), configFile));
  36193. } else {
  36194. process.exit(1);
  36195. }
  36196. }
  36197. function logFileInfoOrDie(context) {
  36198. var options$$2 = {
  36199. ignorePath: context.argv["ignore-path"],
  36200. withNodeModules: context.argv["with-node-modules"],
  36201. plugins: context.argv["plugin"],
  36202. pluginSearchDirs: context.argv["plugin-search-dir"]
  36203. };
  36204. context.logger.log(prettier$2.format(jsonStableStringify(prettier$2.getFileInfo.sync(context.argv["file-info"], options$$2)), {
  36205. parser: "json"
  36206. }));
  36207. }
  36208. function writeOutput(context, result, options$$2) {
  36209. // Don't use `console.log` here since it adds an extra newline at the end.
  36210. process.stdout.write(context.argv["debug-check"] ? result.filepath : result.formatted);
  36211. if (options$$2 && options$$2.cursorOffset >= 0) {
  36212. process.stderr.write(result.cursorOffset + "\n");
  36213. }
  36214. }
  36215. function listDifferent(context, input, options$$2, filename) {
  36216. if (!context.argv["check"] && !context.argv["list-different"]) {
  36217. return;
  36218. }
  36219. try {
  36220. if (!options$$2.filepath && !options$$2.parser) {
  36221. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  36222. }
  36223. if (!prettier$2.check(input, options$$2)) {
  36224. if (!context.argv["write"]) {
  36225. context.logger.log(filename);
  36226. process.exitCode = 1;
  36227. }
  36228. }
  36229. } catch (error) {
  36230. context.logger.error(error.message);
  36231. }
  36232. return true;
  36233. }
  36234. function format$1(context, input, opt) {
  36235. if (!opt.parser && !opt.filepath) {
  36236. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  36237. }
  36238. if (context.argv["debug-print-doc"]) {
  36239. var doc = prettier$2.__debug.printToDoc(input, opt);
  36240. return {
  36241. formatted: prettier$2.__debug.formatDoc(doc)
  36242. };
  36243. }
  36244. if (context.argv["debug-check"]) {
  36245. var pp = prettier$2.format(input, opt);
  36246. var pppp = prettier$2.format(pp, opt);
  36247. if (pp !== pppp) {
  36248. throw new errors.DebugError("prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp));
  36249. } else {
  36250. var _stringify = function _stringify(obj) {
  36251. return JSON.stringify(obj, null, 2);
  36252. };
  36253. var ast = _stringify(prettier$2.__debug.parse(input, opt,
  36254. /* massage */
  36255. true).ast);
  36256. var past = _stringify(prettier$2.__debug.parse(pp, opt,
  36257. /* massage */
  36258. true).ast);
  36259. if (ast !== past) {
  36260. var MAX_AST_SIZE = 2097152; // 2MB
  36261. var astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
  36262. throw new errors.DebugError("ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp));
  36263. }
  36264. }
  36265. return {
  36266. formatted: pp,
  36267. filepath: opt.filepath || "(stdin)\n"
  36268. };
  36269. }
  36270. /* istanbul ignore if */
  36271. if (context.argv["debug-benchmark"]) {
  36272. var benchmark;
  36273. try {
  36274. benchmark = require("benchmark");
  36275. } catch (err) {
  36276. context.logger.debug("'--debug-benchmark' requires the 'benchmark' package to be installed.");
  36277. process.exit(2);
  36278. }
  36279. context.logger.debug("'--debug-benchmark' option found, measuring formatWithCursor with 'benchmark' module.");
  36280. var suite = new benchmark.Suite();
  36281. suite.add("format", function () {
  36282. prettier$2.formatWithCursor(input, opt);
  36283. }).on("cycle", function (event) {
  36284. var results = {
  36285. benchmark: String(event.target),
  36286. hz: event.target.hz,
  36287. ms: event.target.times.cycle * 1000
  36288. };
  36289. context.logger.debug("'--debug-benchmark' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
  36290. }).run({
  36291. async: false
  36292. });
  36293. } else if (context.argv["debug-repeat"] > 0) {
  36294. var repeat = context.argv["debug-repeat"];
  36295. context.logger.debug("'--debug-repeat' option found, running formatWithCursor " + repeat + " times."); // should be using `performance.now()`, but only `Date` is cross-platform enough
  36296. var now = Date.now ? function () {
  36297. return Date.now();
  36298. } : function () {
  36299. return +new Date();
  36300. };
  36301. var totalMs = 0;
  36302. for (var i = 0; i < repeat; ++i) {
  36303. var startMs = now();
  36304. prettier$2.formatWithCursor(input, opt);
  36305. totalMs += now() - startMs;
  36306. }
  36307. var averageMs = totalMs / repeat;
  36308. var results = {
  36309. repeat,
  36310. hz: 1000 / averageMs,
  36311. ms: averageMs
  36312. };
  36313. context.logger.debug("'--debug-repeat' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
  36314. }
  36315. return prettier$2.formatWithCursor(input, opt);
  36316. }
  36317. function getOptionsOrDie(context, filePath) {
  36318. try {
  36319. if (context.argv["config"] === false) {
  36320. context.logger.debug("'--no-config' option found, skip loading config file.");
  36321. return null;
  36322. }
  36323. context.logger.debug(context.argv["config"] ? `load config file from '${context.argv["config"]}'` : `resolve config from '${filePath}'`);
  36324. var options$$2 = prettier$2.resolveConfig.sync(filePath, {
  36325. editorconfig: context.argv["editorconfig"],
  36326. config: context.argv["config"]
  36327. });
  36328. context.logger.debug("loaded options `" + JSON.stringify(options$$2) + "`");
  36329. return options$$2;
  36330. } catch (error) {
  36331. context.logger.error("Invalid configuration file: " + error.message);
  36332. process.exit(2);
  36333. }
  36334. }
  36335. function getOptionsForFile(context, filepath) {
  36336. var options$$2 = getOptionsOrDie(context, filepath);
  36337. var hasPlugins = options$$2 && options$$2.plugins;
  36338. if (hasPlugins) {
  36339. pushContextPlugins(context, options$$2.plugins);
  36340. }
  36341. var appliedOptions = Object.assign({
  36342. filepath
  36343. }, applyConfigPrecedence(context, options$$2 && optionsNormalizer.normalizeApiOptions(options$$2, context.supportOptions, {
  36344. logger: context.logger
  36345. })));
  36346. context.logger.debug(`applied config-precedence (${context.argv["config-precedence"]}): ` + `${JSON.stringify(appliedOptions)}`);
  36347. if (hasPlugins) {
  36348. popContextPlugins(context);
  36349. }
  36350. return appliedOptions;
  36351. }
  36352. function parseArgsToOptions(context, overrideDefaults) {
  36353. var minimistOptions = createMinimistOptions(context.detailedOptions);
  36354. var apiDetailedOptionMap = createApiDetailedOptionMap(context.detailedOptions);
  36355. return getOptions(optionsNormalizer.normalizeCliOptions(minimist_1(context.args, Object.assign({
  36356. string: minimistOptions.string,
  36357. boolean: minimistOptions.boolean,
  36358. default: cliifyOptions(overrideDefaults, apiDetailedOptionMap)
  36359. })), context.detailedOptions, {
  36360. logger: false
  36361. }), context.detailedOptions);
  36362. }
  36363. function applyConfigPrecedence(context, options$$2) {
  36364. try {
  36365. switch (context.argv["config-precedence"]) {
  36366. case "cli-override":
  36367. return parseArgsToOptions(context, options$$2);
  36368. case "file-override":
  36369. return Object.assign({}, parseArgsToOptions(context), options$$2);
  36370. case "prefer-file":
  36371. return options$$2 || parseArgsToOptions(context);
  36372. }
  36373. } catch (error) {
  36374. context.logger.error(error.toString());
  36375. process.exit(2);
  36376. }
  36377. }
  36378. function formatStdin(context) {
  36379. var filepath = context.argv["stdin-filepath"] ? path.resolve(process.cwd(), context.argv["stdin-filepath"]) : process.cwd();
  36380. var ignorer = createIgnorerFromContextOrDie(context);
  36381. var relativeFilepath = path.relative(process.cwd(), filepath);
  36382. thirdParty$1.getStream(process.stdin).then(function (input) {
  36383. if (relativeFilepath && ignorer.filter([relativeFilepath]).length === 0) {
  36384. writeOutput(context, {
  36385. formatted: input
  36386. });
  36387. return;
  36388. }
  36389. var options$$2 = getOptionsForFile(context, filepath);
  36390. try {
  36391. if (listDifferent(context, input, options$$2, "(stdin)")) {
  36392. return;
  36393. }
  36394. writeOutput(context, format$1(context, input, options$$2), options$$2);
  36395. } catch (error) {
  36396. handleError(context, relativeFilepath || "stdin", error);
  36397. }
  36398. });
  36399. }
  36400. function createIgnorerFromContextOrDie(context) {
  36401. try {
  36402. return createIgnorer_1.sync(context.argv["ignore-path"], context.argv["with-node-modules"]);
  36403. } catch (e) {
  36404. context.logger.error(e.message);
  36405. process.exit(2);
  36406. }
  36407. }
  36408. function eachFilename(context, patterns, callback) {
  36409. // The '!./' globs are due to https://github.com/prettier/prettier/issues/2110
  36410. var ignoreNodeModules = context.argv["with-node-modules"] !== true;
  36411. if (ignoreNodeModules) {
  36412. patterns = patterns.concat(["!**/node_modules/**", "!./node_modules/**"]);
  36413. }
  36414. patterns = patterns.concat(["!**/.{git,svn,hg}/**", "!./.{git,svn,hg}/**"]);
  36415. try {
  36416. var filePaths = globby.sync(patterns, {
  36417. dot: true,
  36418. nodir: true
  36419. }).map(function (filePath) {
  36420. return path.relative(process.cwd(), filePath);
  36421. });
  36422. if (filePaths.length === 0) {
  36423. context.logger.error(`No matching files. Patterns tried: ${patterns.join(" ")}`);
  36424. process.exitCode = 2;
  36425. return;
  36426. }
  36427. filePaths.forEach(function (filePath) {
  36428. return callback(filePath, Object.assign(getOptionsForFile(context, filePath), {
  36429. filepath: filePath
  36430. }));
  36431. });
  36432. } catch (error) {
  36433. context.logger.error(`Unable to expand glob patterns: ${patterns.join(" ")}\n${error.message}`); // Don't exit the process if one pattern failed
  36434. process.exitCode = 2;
  36435. }
  36436. }
  36437. function formatFiles(context) {
  36438. // The ignorer will be used to filter file paths after the glob is checked,
  36439. // before any files are actually written
  36440. var ignorer = createIgnorerFromContextOrDie(context);
  36441. var numberOfUnformattedFilesFound = 0;
  36442. if (context.argv["check"]) {
  36443. context.logger.log("Checking formatting...");
  36444. }
  36445. eachFilename(context, context.filePatterns, function (filename, options$$2) {
  36446. var fileIgnored = ignorer.filter([filename]).length === 0;
  36447. if (fileIgnored && (context.argv["debug-check"] || context.argv["write"] || context.argv["check"] || context.argv["list-different"])) {
  36448. return;
  36449. }
  36450. if (isTty()) {
  36451. // Don't use `console.log` here since we need to replace this line.
  36452. context.logger.log(filename, {
  36453. newline: false
  36454. });
  36455. }
  36456. var input;
  36457. try {
  36458. input = fs.readFileSync(filename, "utf8");
  36459. } catch (error) {
  36460. // Add newline to split errors from filename line.
  36461. context.logger.log("");
  36462. context.logger.error(`Unable to read file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  36463. process.exitCode = 2;
  36464. return;
  36465. }
  36466. if (fileIgnored) {
  36467. writeOutput(context, {
  36468. formatted: input
  36469. }, options$$2);
  36470. return;
  36471. }
  36472. var start = Date.now();
  36473. var result;
  36474. var output;
  36475. try {
  36476. result = format$1(context, input, Object.assign({}, options$$2, {
  36477. filepath: filename
  36478. }));
  36479. output = result.formatted;
  36480. } catch (error) {
  36481. handleError(context, filename, error);
  36482. return;
  36483. }
  36484. var isDifferent = output !== input;
  36485. if (isTty()) {
  36486. // Remove previously printed filename to log it with duration.
  36487. readline.clearLine(process.stdout, 0);
  36488. readline.cursorTo(process.stdout, 0, null);
  36489. }
  36490. if (context.argv["write"]) {
  36491. // Don't write the file if it won't change in order not to invalidate
  36492. // mtime based caches.
  36493. if (isDifferent) {
  36494. if (!context.argv["check"] && !context.argv["list-different"]) {
  36495. context.logger.log(`${filename} ${Date.now() - start}ms`);
  36496. }
  36497. try {
  36498. fs.writeFileSync(filename, output, "utf8");
  36499. } catch (error) {
  36500. context.logger.error(`Unable to write file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  36501. process.exitCode = 2;
  36502. }
  36503. } else if (!context.argv["check"] && !context.argv["list-different"]) {
  36504. context.logger.log(`${chalk$2.grey(filename)} ${Date.now() - start}ms`);
  36505. }
  36506. } else if (context.argv["debug-check"]) {
  36507. if (result.filepath) {
  36508. context.logger.log(result.filepath);
  36509. } else {
  36510. process.exitCode = 2;
  36511. }
  36512. } else if (!context.argv["check"] && !context.argv["list-different"]) {
  36513. writeOutput(context, result, options$$2);
  36514. }
  36515. if ((context.argv["check"] || context.argv["list-different"]) && isDifferent) {
  36516. context.logger.log(filename);
  36517. numberOfUnformattedFilesFound += 1;
  36518. }
  36519. }); // Print check summary based on expected exit code
  36520. if (context.argv["check"]) {
  36521. context.logger.log(numberOfUnformattedFilesFound === 0 ? "All matched files use Prettier code style!" : context.argv["write"] ? "Code style issues fixed in the above file(s)." : "Code style issues found in the above file(s). Forgot to run Prettier?");
  36522. } // Ensure non-zero exitCode when using --check/list-different is not combined with --write
  36523. if ((context.argv["check"] || context.argv["list-different"]) && numberOfUnformattedFilesFound > 0 && !process.exitCode && !context.argv["write"]) {
  36524. process.exitCode = 1;
  36525. }
  36526. }
  36527. function getOptionsWithOpposites(options$$2) {
  36528. // Add --no-foo after --foo.
  36529. var optionsWithOpposites = options$$2.map(function (option) {
  36530. return [option.description ? option : null, option.oppositeDescription ? Object.assign({}, option, {
  36531. name: `no-${option.name}`,
  36532. type: "boolean",
  36533. description: option.oppositeDescription
  36534. }) : null];
  36535. });
  36536. return flattenArray(optionsWithOpposites).filter(Boolean);
  36537. }
  36538. function createUsage(context) {
  36539. var options$$2 = getOptionsWithOpposites(context.detailedOptions).filter( // remove unnecessary option (e.g. `semi`, `color`, etc.), which is only used for --help <flag>
  36540. function (option) {
  36541. return !(option.type === "boolean" && option.oppositeDescription && !option.name.startsWith("no-"));
  36542. });
  36543. var groupedOptions = groupBy(options$$2, function (option) {
  36544. return option.category;
  36545. });
  36546. var firstCategories = constant.categoryOrder.slice(0, -1);
  36547. var lastCategories = constant.categoryOrder.slice(-1);
  36548. var restCategories = Object.keys(groupedOptions).filter(function (category) {
  36549. return firstCategories.indexOf(category) === -1 && lastCategories.indexOf(category) === -1;
  36550. });
  36551. var allCategories = firstCategories.concat(restCategories, lastCategories);
  36552. var optionsUsage = allCategories.map(function (category) {
  36553. var categoryOptions = groupedOptions[category].map(function (option) {
  36554. return createOptionUsage(context, option, OPTION_USAGE_THRESHOLD);
  36555. }).join("\n");
  36556. return `${category} options:\n\n${indent$11(categoryOptions, 2)}`;
  36557. });
  36558. return [constant.usageSummary].concat(optionsUsage, [""]).join("\n\n");
  36559. }
  36560. function createOptionUsage(context, option, threshold) {
  36561. var header = createOptionUsageHeader(option);
  36562. var optionDefaultValue = getOptionDefaultValue(context, option.name);
  36563. return createOptionUsageRow(header, `${option.description}${optionDefaultValue === undefined ? "" : `\nDefaults to ${createDefaultValueDisplay(optionDefaultValue)}.`}`, threshold);
  36564. }
  36565. function createDefaultValueDisplay(value) {
  36566. return Array.isArray(value) ? `[${value.map(createDefaultValueDisplay).join(", ")}]` : value;
  36567. }
  36568. function createOptionUsageHeader(option) {
  36569. var name = `--${option.name}`;
  36570. var alias = option.alias ? `-${option.alias},` : null;
  36571. var type = createOptionUsageType(option);
  36572. return [alias, name, type].filter(Boolean).join(" ");
  36573. }
  36574. function createOptionUsageRow(header, content, threshold) {
  36575. var separator = header.length >= threshold ? `\n${" ".repeat(threshold)}` : " ".repeat(threshold - header.length);
  36576. var description = content.replace(/\n/g, `\n${" ".repeat(threshold)}`);
  36577. return `${header}${separator}${description}`;
  36578. }
  36579. function createOptionUsageType(option) {
  36580. switch (option.type) {
  36581. case "boolean":
  36582. return null;
  36583. case "choice":
  36584. return `<${option.choices.filter(function (choice) {
  36585. return choice.since !== null;
  36586. }).filter(function (choice) {
  36587. return !choice.deprecated;
  36588. }).map(function (choice) {
  36589. return choice.value;
  36590. }).join("|")}>`;
  36591. default:
  36592. return `<${option.type}>`;
  36593. }
  36594. }
  36595. function flattenArray(array) {
  36596. return [].concat.apply([], array);
  36597. }
  36598. function createChoiceUsages(choices, margin, indentation) {
  36599. var activeChoices = choices.filter(function (choice) {
  36600. return !choice.deprecated && choice.since !== null;
  36601. });
  36602. var threshold = activeChoices.map(function (choice) {
  36603. return choice.value.length;
  36604. }).reduce(function (current, length) {
  36605. return Math.max(current, length);
  36606. }, 0) + margin;
  36607. return activeChoices.map(function (choice) {
  36608. return indent$11(createOptionUsageRow(choice.value, choice.description, threshold), indentation);
  36609. });
  36610. }
  36611. function createDetailedUsage(context, flag) {
  36612. var option = getOptionsWithOpposites(context.detailedOptions).find(function (option) {
  36613. return option.name === flag || option.alias === flag;
  36614. });
  36615. var header = createOptionUsageHeader(option);
  36616. var description = `\n\n${indent$11(option.description, 2)}`;
  36617. var choices = option.type !== "choice" ? "" : `\n\nValid options:\n\n${createChoiceUsages(option.choices, CHOICE_USAGE_MARGIN, CHOICE_USAGE_INDENTATION).join("\n")}`;
  36618. var optionDefaultValue = getOptionDefaultValue(context, option.name);
  36619. var defaults = optionDefaultValue !== undefined ? `\n\nDefault: ${createDefaultValueDisplay(optionDefaultValue)}` : "";
  36620. var pluginDefaults = option.pluginDefaults && Object.keys(option.pluginDefaults).length ? `\nPlugin defaults:${Object.keys(option.pluginDefaults).map(function (key) {
  36621. return `\n* ${key}: ${createDefaultValueDisplay(option.pluginDefaults[key])}`;
  36622. })}` : "";
  36623. return `${header}${description}${choices}${defaults}${pluginDefaults}`;
  36624. }
  36625. function getOptionDefaultValue(context, optionName) {
  36626. // --no-option
  36627. if (!(optionName in context.detailedOptionMap)) {
  36628. return undefined;
  36629. }
  36630. var option = context.detailedOptionMap[optionName];
  36631. if (option.default !== undefined) {
  36632. return option.default;
  36633. }
  36634. var optionCamelName = camelcase(optionName);
  36635. if (optionCamelName in context.apiDefaultOptions) {
  36636. return context.apiDefaultOptions[optionCamelName];
  36637. }
  36638. return undefined;
  36639. }
  36640. function indent$11(str, spaces) {
  36641. return str.replace(/^/gm, " ".repeat(spaces));
  36642. }
  36643. function groupBy(array, getKey) {
  36644. return array.reduce(function (obj, item) {
  36645. var key = getKey(item);
  36646. var previousItems = key in obj ? obj[key] : [];
  36647. return Object.assign({}, obj, {
  36648. [key]: previousItems.concat(item)
  36649. });
  36650. }, Object.create(null));
  36651. }
  36652. function pick(object, keys) {
  36653. return !keys ? object : keys.reduce(function (reduced, key) {
  36654. return Object.assign(reduced, {
  36655. [key]: object[key]
  36656. });
  36657. }, {});
  36658. }
  36659. function createLogger(logLevel) {
  36660. return {
  36661. warn: createLogFunc("warn", "yellow"),
  36662. error: createLogFunc("error", "red"),
  36663. debug: createLogFunc("debug", "blue"),
  36664. log: createLogFunc("log")
  36665. };
  36666. function createLogFunc(loggerName, color) {
  36667. if (!shouldLog(loggerName)) {
  36668. return function () {};
  36669. }
  36670. var prefix = color ? `[${chalk$2[color](loggerName)}] ` : "";
  36671. return function (message, opts) {
  36672. opts = Object.assign({
  36673. newline: true
  36674. }, opts);
  36675. var stream = process[loggerName === "log" ? "stdout" : "stderr"];
  36676. stream.write(message.replace(/^/gm, prefix) + (opts.newline ? "\n" : ""));
  36677. };
  36678. }
  36679. function shouldLog(loggerName) {
  36680. switch (logLevel) {
  36681. case "silent":
  36682. return false;
  36683. default:
  36684. return true;
  36685. case "debug":
  36686. if (loggerName === "debug") {
  36687. return true;
  36688. }
  36689. // fall through
  36690. case "log":
  36691. if (loggerName === "log") {
  36692. return true;
  36693. }
  36694. // fall through
  36695. case "warn":
  36696. if (loggerName === "warn") {
  36697. return true;
  36698. }
  36699. // fall through
  36700. case "error":
  36701. return loggerName === "error";
  36702. }
  36703. }
  36704. }
  36705. function normalizeDetailedOption(name, option) {
  36706. return Object.assign({
  36707. category: coreOptions$1.CATEGORY_OTHER
  36708. }, option, {
  36709. choices: option.choices && option.choices.map(function (choice) {
  36710. var newChoice = Object.assign({
  36711. description: "",
  36712. deprecated: false
  36713. }, typeof choice === "object" ? choice : {
  36714. value: choice
  36715. });
  36716. if (newChoice.value === true) {
  36717. newChoice.value = ""; // backward compability for original boolean option
  36718. }
  36719. return newChoice;
  36720. })
  36721. });
  36722. }
  36723. function normalizeDetailedOptionMap(detailedOptionMap) {
  36724. return Object.keys(detailedOptionMap).sort().reduce(function (normalized, name) {
  36725. var option = detailedOptionMap[name];
  36726. return Object.assign(normalized, {
  36727. [name]: normalizeDetailedOption(name, option)
  36728. });
  36729. }, {});
  36730. }
  36731. function createMinimistOptions(detailedOptions) {
  36732. return {
  36733. // we use vnopts' AliasSchema to handle aliases for better error messages
  36734. alias: {},
  36735. boolean: detailedOptions.filter(function (option) {
  36736. return option.type === "boolean";
  36737. }).map(function (option) {
  36738. return [option.name].concat(option.alias || []);
  36739. }).reduce(function (a, b) {
  36740. return a.concat(b);
  36741. }),
  36742. string: detailedOptions.filter(function (option) {
  36743. return option.type !== "boolean";
  36744. }).map(function (option) {
  36745. return [option.name].concat(option.alias || []);
  36746. }).reduce(function (a, b) {
  36747. return a.concat(b);
  36748. }),
  36749. default: detailedOptions.filter(function (option) {
  36750. return !option.deprecated;
  36751. }).filter(function (option) {
  36752. return !option.forwardToApi || option.name === "plugin" || option.name === "plugin-search-dir";
  36753. }).filter(function (option) {
  36754. return option.default !== undefined;
  36755. }).reduce(function (current, option) {
  36756. return Object.assign({
  36757. [option.name]: option.default
  36758. }, current);
  36759. }, {})
  36760. };
  36761. }
  36762. function createApiDetailedOptionMap(detailedOptions) {
  36763. return detailedOptions.reduce(function (current, option) {
  36764. return option.forwardToApi && option.forwardToApi !== option.name ? Object.assign(current, {
  36765. [option.forwardToApi]: option
  36766. }) : current;
  36767. }, {});
  36768. }
  36769. function createDetailedOptionMap(supportOptions) {
  36770. return supportOptions.reduce(function (reduced, option) {
  36771. var newOption = Object.assign({}, option, {
  36772. name: option.cliName || dashify(option.name),
  36773. description: option.cliDescription || option.description,
  36774. category: option.cliCategory || coreOptions$1.CATEGORY_FORMAT,
  36775. forwardToApi: option.name
  36776. });
  36777. if (option.deprecated) {
  36778. delete newOption.forwardToApi;
  36779. delete newOption.description;
  36780. delete newOption.oppositeDescription;
  36781. newOption.deprecated = true;
  36782. }
  36783. return Object.assign(reduced, {
  36784. [newOption.name]: newOption
  36785. });
  36786. }, {});
  36787. } //-----------------------------context-util-start-------------------------------
  36788. /**
  36789. * @typedef {Object} Context
  36790. * @property logger
  36791. * @property args
  36792. * @property argv
  36793. * @property filePatterns
  36794. * @property supportOptions
  36795. * @property detailedOptions
  36796. * @property detailedOptionMap
  36797. * @property apiDefaultOptions
  36798. */
  36799. function createContext(args) {
  36800. var context = {
  36801. args
  36802. };
  36803. updateContextArgv(context);
  36804. normalizeContextArgv(context, ["loglevel", "plugin", "plugin-search-dir"]);
  36805. context.logger = createLogger(context.argv["loglevel"]);
  36806. updateContextArgv(context, context.argv["plugin"], context.argv["plugin-search-dir"]);
  36807. return context;
  36808. }
  36809. function initContext(context) {
  36810. // split into 2 step so that we could wrap this in a `try..catch` in cli/index.js
  36811. normalizeContextArgv(context);
  36812. }
  36813. function updateContextOptions(context, plugins, pluginSearchDirs) {
  36814. var supportOptions = prettier$2.getSupportInfo(null, {
  36815. showDeprecated: true,
  36816. showUnreleased: true,
  36817. showInternal: true,
  36818. plugins,
  36819. pluginSearchDirs
  36820. }).options;
  36821. var detailedOptionMap = normalizeDetailedOptionMap(Object.assign({}, createDetailedOptionMap(supportOptions), constant.options));
  36822. var detailedOptions = arrayify(detailedOptionMap, "name");
  36823. var apiDefaultOptions = supportOptions.filter(function (optionInfo) {
  36824. return !optionInfo.deprecated;
  36825. }).reduce(function (reduced, optionInfo) {
  36826. return Object.assign(reduced, {
  36827. [optionInfo.name]: optionInfo.default
  36828. });
  36829. }, Object.assign({}, options.hiddenDefaults));
  36830. context.supportOptions = supportOptions;
  36831. context.detailedOptions = detailedOptions;
  36832. context.detailedOptionMap = detailedOptionMap;
  36833. context.apiDefaultOptions = apiDefaultOptions;
  36834. }
  36835. function pushContextPlugins(context, plugins, pluginSearchDirs) {
  36836. context._supportOptions = context.supportOptions;
  36837. context._detailedOptions = context.detailedOptions;
  36838. context._detailedOptionMap = context.detailedOptionMap;
  36839. context._apiDefaultOptions = context.apiDefaultOptions;
  36840. updateContextOptions(context, plugins, pluginSearchDirs);
  36841. }
  36842. function popContextPlugins(context) {
  36843. context.supportOptions = context._supportOptions;
  36844. context.detailedOptions = context._detailedOptions;
  36845. context.detailedOptionMap = context._detailedOptionMap;
  36846. context.apiDefaultOptions = context._apiDefaultOptions;
  36847. }
  36848. function updateContextArgv(context, plugins, pluginSearchDirs) {
  36849. pushContextPlugins(context, plugins, pluginSearchDirs);
  36850. var minimistOptions = createMinimistOptions(context.detailedOptions);
  36851. var argv = minimist_1(context.args, minimistOptions);
  36852. context.argv = argv;
  36853. context.filePatterns = argv["_"];
  36854. }
  36855. function normalizeContextArgv(context, keys) {
  36856. var detailedOptions = !keys ? context.detailedOptions : context.detailedOptions.filter(function (option) {
  36857. return keys.indexOf(option.name) !== -1;
  36858. });
  36859. var argv = !keys ? context.argv : pick(context.argv, keys);
  36860. context.argv = optionsNormalizer.normalizeCliOptions(argv, detailedOptions, {
  36861. logger: context.logger
  36862. });
  36863. } //------------------------------context-util-end--------------------------------
  36864. var util$5 = {
  36865. createContext,
  36866. createDetailedOptionMap,
  36867. createDetailedUsage,
  36868. createUsage,
  36869. format: format$1,
  36870. formatFiles,
  36871. formatStdin,
  36872. initContext,
  36873. logResolvedConfigPathOrDie,
  36874. logFileInfoOrDie,
  36875. normalizeDetailedOptionMap
  36876. };
  36877. function run(args) {
  36878. var context = util$5.createContext(args);
  36879. try {
  36880. util$5.initContext(context);
  36881. context.logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
  36882. if (context.argv["check"] && context.argv["list-different"]) {
  36883. context.logger.error("Cannot use --check and --list-different together.");
  36884. process.exit(1);
  36885. }
  36886. if (context.argv["write"] && context.argv["debug-check"]) {
  36887. context.logger.error("Cannot use --write and --debug-check together.");
  36888. process.exit(1);
  36889. }
  36890. if (context.argv["find-config-path"] && context.filePatterns.length) {
  36891. context.logger.error("Cannot use --find-config-path with multiple files");
  36892. process.exit(1);
  36893. }
  36894. if (context.argv["file-info"] && context.filePatterns.length) {
  36895. context.logger.error("Cannot use --file-info with multiple files");
  36896. process.exit(1);
  36897. }
  36898. if (context.argv["version"]) {
  36899. context.logger.log(prettier$2.version);
  36900. process.exit(0);
  36901. }
  36902. if (context.argv["help"] !== undefined) {
  36903. context.logger.log(typeof context.argv["help"] === "string" && context.argv["help"] !== "" ? util$5.createDetailedUsage(context, context.argv["help"]) : util$5.createUsage(context));
  36904. process.exit(0);
  36905. }
  36906. if (context.argv["support-info"]) {
  36907. context.logger.log(prettier$2.format(jsonStableStringify(prettier$2.getSupportInfo()), {
  36908. parser: "json"
  36909. }));
  36910. process.exit(0);
  36911. }
  36912. var hasFilePatterns = context.filePatterns.length !== 0;
  36913. var useStdin = context.argv["stdin"] || !hasFilePatterns && !process.stdin.isTTY;
  36914. if (context.argv["find-config-path"]) {
  36915. util$5.logResolvedConfigPathOrDie(context);
  36916. } else if (context.argv["file-info"]) {
  36917. util$5.logFileInfoOrDie(context);
  36918. } else if (useStdin) {
  36919. util$5.formatStdin(context);
  36920. } else if (hasFilePatterns) {
  36921. util$5.formatFiles(context);
  36922. } else {
  36923. context.logger.log(util$5.createUsage(context));
  36924. process.exit(1);
  36925. }
  36926. } catch (error) {
  36927. context.logger.error(error.message);
  36928. process.exit(1);
  36929. }
  36930. }
  36931. var cli = {
  36932. run
  36933. };
  36934. cli.run(process.argv.slice(2));
  36935. var prettier = {};
  36936. module.exports = prettier;