bin-prettier.js 1.3 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492
  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.16.3";
  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": "6.1.10",
  29. "@babel/code-frame": "7.0.0-beta.46",
  30. "@babel/parser": "7.2.0",
  31. "@glimmer/syntax": "0.30.3",
  32. "@iarna/toml": "2.0.0",
  33. "angular-estree-parser": "1.1.5",
  34. "angular-html-parser": "1.2.0",
  35. "camelcase": "4.1.0",
  36. "chalk": "2.1.0",
  37. "cjk-regex": "2.0.0",
  38. "cosmiconfig": "5.0.7",
  39. "dashify": "0.2.2",
  40. "dedent": "0.7.0",
  41. "diff": "3.2.0",
  42. "editorconfig": "0.15.2",
  43. "editorconfig-to-prettier": "0.1.1",
  44. "escape-string-regexp": "1.0.5",
  45. "esutils": "2.0.2",
  46. "find-parent-dir": "0.3.0",
  47. "find-project-root": "1.1.1",
  48. "flow-parser": "0.84.0",
  49. "get-stream": "3.0.0",
  50. "globby": "6.1.0",
  51. "graphql": "0.13.2",
  52. "html-element-attributes": "2.0.0",
  53. "html-styles": "1.0.0",
  54. "html-tag-names": "1.1.2",
  55. "ignore": "3.3.7",
  56. "is-ci": "2.0.0",
  57. "jest-docblock": "23.2.0",
  58. "json-stable-stringify": "1.0.1",
  59. "leven": "2.1.0",
  60. "lines-and-columns": "1.1.6",
  61. "linguist-languages": "6.2.1-dev.20180706",
  62. "lodash.uniqby": "4.7.0",
  63. "mem": "1.1.0",
  64. "minimatch": "3.0.4",
  65. "minimist": "1.2.0",
  66. "n-readlines": "1.0.0",
  67. "normalize-path": "3.0.0",
  68. "parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
  69. "postcss-less": "1.1.5",
  70. "postcss-media-query-parser": "0.2.3",
  71. "postcss-scss": "2.0.0",
  72. "postcss-selector-parser": "2.2.3",
  73. "postcss-values-parser": "1.5.0",
  74. "regexp-util": "1.2.2",
  75. "remark-math": "1.0.4",
  76. "remark-parse": "5.0.0",
  77. "resolve": "1.5.0",
  78. "semver": "5.4.1",
  79. "string-width": "3.0.0",
  80. "typescript": "3.2.2",
  81. "typescript-estree": "18.0.0",
  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.16.2",
  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 resolutions = {
  130. "@babel/code-frame": "7.0.0-beta.46"
  131. };
  132. var scripts = {
  133. "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
  134. "prepare-release": "yarn && yarn build && yarn test:dist",
  135. "test": "jest",
  136. "test:dist": "node ./scripts/test-dist.js",
  137. "test-integration": "jest tests_integration",
  138. "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",
  139. "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",
  140. "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",
  141. "lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
  142. "lint-docs": "prettylint {.,docs,website,website/blog}/*.md",
  143. "lint-dist": "eslint --no-eslintrc --no-ignore --env=browser \"dist/!(bin-prettier|index|third-party).js\"",
  144. "build": "node --max-old-space-size=2048 ./scripts/build/build.js",
  145. "build-docs": "node ./scripts/build-docs.js",
  146. "check-deps": "node ./scripts/check-deps.js"
  147. };
  148. var _package = {
  149. name: name,
  150. version: version$1,
  151. description: description,
  152. bin: bin,
  153. repository: repository,
  154. homepage: homepage,
  155. author: author,
  156. license: license,
  157. main: main,
  158. engines: engines,
  159. dependencies: dependencies,
  160. devDependencies: devDependencies,
  161. resolutions: resolutions,
  162. scripts: scripts
  163. };
  164. var _package$1 = Object.freeze({
  165. name: name,
  166. version: version$1,
  167. description: description,
  168. bin: bin,
  169. repository: repository,
  170. homepage: homepage,
  171. author: author,
  172. license: license,
  173. main: main,
  174. engines: engines,
  175. dependencies: dependencies,
  176. devDependencies: devDependencies,
  177. resolutions: resolutions,
  178. scripts: scripts,
  179. default: _package
  180. });
  181. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  182. function unwrapExports (x) {
  183. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  184. }
  185. function createCommonjsModule(fn, module) {
  186. return module = { exports: {} }, fn(module, module.exports), module.exports;
  187. }
  188. var base = createCommonjsModule(function (module, exports) {
  189. /*istanbul ignore start*/
  190. 'use strict';
  191. exports.__esModule = true;
  192. exports['default'] =
  193. /*istanbul ignore end*/
  194. Diff;
  195. function Diff() {}
  196. Diff.prototype = {
  197. /*istanbul ignore start*/
  198. /*istanbul ignore end*/
  199. diff: function diff(oldString, newString) {
  200. /*istanbul ignore start*/
  201. var
  202. /*istanbul ignore end*/
  203. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  204. var callback = options.callback;
  205. if (typeof options === 'function') {
  206. callback = options;
  207. options = {};
  208. }
  209. this.options = options;
  210. var self = this;
  211. function done(value) {
  212. if (callback) {
  213. setTimeout(function () {
  214. callback(undefined, value);
  215. }, 0);
  216. return true;
  217. } else {
  218. return value;
  219. }
  220. } // Allow subclasses to massage the input prior to running
  221. oldString = this.castInput(oldString);
  222. newString = this.castInput(newString);
  223. oldString = this.removeEmpty(this.tokenize(oldString));
  224. newString = this.removeEmpty(this.tokenize(newString));
  225. var newLen = newString.length,
  226. oldLen = oldString.length;
  227. var editLength = 1;
  228. var maxEditLength = newLen + oldLen;
  229. var bestPath = [{
  230. newPos: -1,
  231. components: []
  232. }]; // Seed editLength = 0, i.e. the content starts with the same values
  233. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  234. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  235. // Identity per the equality and tokenizer
  236. return done([{
  237. value: this.join(newString),
  238. count: newString.length
  239. }]);
  240. } // Main worker method. checks all permutations of a given edit length for acceptance.
  241. function execEditLength() {
  242. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  243. var basePath =
  244. /*istanbul ignore start*/
  245. void 0;
  246. var addPath = bestPath[diagonalPath - 1],
  247. removePath = bestPath[diagonalPath + 1],
  248. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  249. if (addPath) {
  250. // No one else is going to attempt to use this value, clear it
  251. bestPath[diagonalPath - 1] = undefined;
  252. }
  253. var canAdd = addPath && addPath.newPos + 1 < newLen,
  254. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  255. if (!canAdd && !canRemove) {
  256. // If this path is a terminal then prune
  257. bestPath[diagonalPath] = undefined;
  258. continue;
  259. } // Select the diagonal that we want to branch from. We select the prior
  260. // path whose position in the new string is the farthest from the origin
  261. // and does not pass the bounds of the diff graph
  262. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  263. basePath = clonePath(removePath);
  264. self.pushComponent(basePath.components, undefined, true);
  265. } else {
  266. basePath = addPath; // No need to clone, we've pulled it from the list
  267. basePath.newPos++;
  268. self.pushComponent(basePath.components, true, undefined);
  269. }
  270. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  271. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  272. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  273. } else {
  274. // Otherwise track this path as a potential candidate and continue.
  275. bestPath[diagonalPath] = basePath;
  276. }
  277. }
  278. editLength++;
  279. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  280. // sync and async mode which is never fun. Loops over execEditLength until a value
  281. // is produced.
  282. if (callback) {
  283. (function exec() {
  284. setTimeout(function () {
  285. // This should not happen, but we want to be safe.
  286. /* istanbul ignore next */
  287. if (editLength > maxEditLength) {
  288. return callback();
  289. }
  290. if (!execEditLength()) {
  291. exec();
  292. }
  293. }, 0);
  294. })();
  295. } else {
  296. while (editLength <= maxEditLength) {
  297. var ret = execEditLength();
  298. if (ret) {
  299. return ret;
  300. }
  301. }
  302. }
  303. },
  304. /*istanbul ignore start*/
  305. /*istanbul ignore end*/
  306. pushComponent: function pushComponent(components, added, removed) {
  307. var last = components[components.length - 1];
  308. if (last && last.added === added && last.removed === removed) {
  309. // We need to clone here as the component clone operation is just
  310. // as shallow array clone
  311. components[components.length - 1] = {
  312. count: last.count + 1,
  313. added: added,
  314. removed: removed
  315. };
  316. } else {
  317. components.push({
  318. count: 1,
  319. added: added,
  320. removed: removed
  321. });
  322. }
  323. },
  324. /*istanbul ignore start*/
  325. /*istanbul ignore end*/
  326. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  327. var newLen = newString.length,
  328. oldLen = oldString.length,
  329. newPos = basePath.newPos,
  330. oldPos = newPos - diagonalPath,
  331. commonCount = 0;
  332. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  333. newPos++;
  334. oldPos++;
  335. commonCount++;
  336. }
  337. if (commonCount) {
  338. basePath.components.push({
  339. count: commonCount
  340. });
  341. }
  342. basePath.newPos = newPos;
  343. return oldPos;
  344. },
  345. /*istanbul ignore start*/
  346. /*istanbul ignore end*/
  347. equals: function equals(left, right) {
  348. return left === right;
  349. },
  350. /*istanbul ignore start*/
  351. /*istanbul ignore end*/
  352. removeEmpty: function removeEmpty(array) {
  353. var ret = [];
  354. for (var i = 0; i < array.length; i++) {
  355. if (array[i]) {
  356. ret.push(array[i]);
  357. }
  358. }
  359. return ret;
  360. },
  361. /*istanbul ignore start*/
  362. /*istanbul ignore end*/
  363. castInput: function castInput(value) {
  364. return value;
  365. },
  366. /*istanbul ignore start*/
  367. /*istanbul ignore end*/
  368. tokenize: function tokenize(value) {
  369. return value.split('');
  370. },
  371. /*istanbul ignore start*/
  372. /*istanbul ignore end*/
  373. join: function join(chars) {
  374. return chars.join('');
  375. }
  376. };
  377. function buildValues(diff, components, newString, oldString, useLongestToken) {
  378. var componentPos = 0,
  379. componentLen = components.length,
  380. newPos = 0,
  381. oldPos = 0;
  382. for (; componentPos < componentLen; componentPos++) {
  383. var component = components[componentPos];
  384. if (!component.removed) {
  385. if (!component.added && useLongestToken) {
  386. var value = newString.slice(newPos, newPos + component.count);
  387. value = value.map(function (value, i) {
  388. var oldValue = oldString[oldPos + i];
  389. return oldValue.length > value.length ? oldValue : value;
  390. });
  391. component.value = diff.join(value);
  392. } else {
  393. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  394. }
  395. newPos += component.count; // Common case
  396. if (!component.added) {
  397. oldPos += component.count;
  398. }
  399. } else {
  400. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  401. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  402. // The diffing algorithm is tied to add then remove output and this is the simplest
  403. // route to get the desired output with minimal overhead.
  404. if (componentPos && components[componentPos - 1].added) {
  405. var tmp = components[componentPos - 1];
  406. components[componentPos - 1] = components[componentPos];
  407. components[componentPos] = tmp;
  408. }
  409. }
  410. } // Special case handle for when one terminal is ignored. For this case we merge the
  411. // terminal into the prior string and drop the change.
  412. var lastComponent = components[componentLen - 1];
  413. if (componentLen > 1 && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  414. components[componentLen - 2].value += lastComponent.value;
  415. components.pop();
  416. }
  417. return components;
  418. }
  419. function clonePath(path$$1) {
  420. return {
  421. newPos: path$$1.newPos,
  422. components: path$$1.components.slice(0)
  423. };
  424. }
  425. });
  426. unwrapExports(base);
  427. var character = createCommonjsModule(function (module, exports) {
  428. /*istanbul ignore start*/
  429. 'use strict';
  430. exports.__esModule = true;
  431. exports.characterDiff = undefined;
  432. exports.
  433. /*istanbul ignore end*/
  434. diffChars = diffChars;
  435. /*istanbul ignore start*/
  436. var _base2 = _interopRequireDefault(base);
  437. function _interopRequireDefault(obj) {
  438. return obj && obj.__esModule ? obj : {
  439. 'default': obj
  440. };
  441. }
  442. /*istanbul ignore end*/
  443. var characterDiff =
  444. /*istanbul ignore start*/
  445. exports.
  446. /*istanbul ignore end*/
  447. characterDiff = new
  448. /*istanbul ignore start*/
  449. _base2['default']();
  450. function diffChars(oldStr, newStr, callback) {
  451. return characterDiff.diff(oldStr, newStr, callback);
  452. }
  453. });
  454. unwrapExports(character);
  455. var params = createCommonjsModule(function (module, exports) {
  456. /*istanbul ignore start*/
  457. 'use strict';
  458. exports.__esModule = true;
  459. exports.
  460. /*istanbul ignore end*/
  461. generateOptions = generateOptions;
  462. function generateOptions(options, defaults) {
  463. if (typeof options === 'function') {
  464. defaults.callback = options;
  465. } else if (options) {
  466. for (var name in options) {
  467. /* istanbul ignore else */
  468. if (options.hasOwnProperty(name)) {
  469. defaults[name] = options[name];
  470. }
  471. }
  472. }
  473. return defaults;
  474. }
  475. });
  476. unwrapExports(params);
  477. var word = createCommonjsModule(function (module, exports) {
  478. /*istanbul ignore start*/
  479. 'use strict';
  480. exports.__esModule = true;
  481. exports.wordDiff = undefined;
  482. exports.
  483. /*istanbul ignore end*/
  484. diffWords = diffWords;
  485. /*istanbul ignore start*/
  486. exports.
  487. /*istanbul ignore end*/
  488. diffWordsWithSpace = diffWordsWithSpace;
  489. /*istanbul ignore start*/
  490. var _base2 = _interopRequireDefault(base);
  491. /*istanbul ignore end*/
  492. /*istanbul ignore start*/
  493. function _interopRequireDefault(obj) {
  494. return obj && obj.__esModule ? obj : {
  495. 'default': obj
  496. };
  497. }
  498. /*istanbul ignore end*/
  499. // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
  500. //
  501. // Ranges and exceptions:
  502. // Latin-1 Supplement, 0080–00FF
  503. // - U+00D7 × Multiplication sign
  504. // - U+00F7 ÷ Division sign
  505. // Latin Extended-A, 0100–017F
  506. // Latin Extended-B, 0180–024F
  507. // IPA Extensions, 0250–02AF
  508. // Spacing Modifier Letters, 02B0–02FF
  509. // - U+02C7 ˇ &#711; Caron
  510. // - U+02D8 ˘ &#728; Breve
  511. // - U+02D9 ˙ &#729; Dot Above
  512. // - U+02DA ˚ &#730; Ring Above
  513. // - U+02DB ˛ &#731; Ogonek
  514. // - U+02DC ˜ &#732; Small Tilde
  515. // - U+02DD ˝ &#733; Double Acute Accent
  516. // Latin Extended Additional, 1E00–1EFF
  517. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  518. var reWhitespace = /\S/;
  519. var wordDiff =
  520. /*istanbul ignore start*/
  521. exports.
  522. /*istanbul ignore end*/
  523. wordDiff = new
  524. /*istanbul ignore start*/
  525. _base2['default']();
  526. wordDiff.equals = function (left, right) {
  527. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  528. };
  529. wordDiff.tokenize = function (value) {
  530. 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.
  531. for (var i = 0; i < tokens.length - 1; i++) {
  532. // If we have an empty string in the next field and we have only word chars before and after, merge
  533. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  534. tokens[i] += tokens[i + 2];
  535. tokens.splice(i + 1, 2);
  536. i--;
  537. }
  538. }
  539. return tokens;
  540. };
  541. function diffWords(oldStr, newStr, callback) {
  542. var options =
  543. /*istanbul ignore start*/
  544. (0, params.generateOptions
  545. /*istanbul ignore end*/
  546. )(callback, {
  547. ignoreWhitespace: true
  548. });
  549. return wordDiff.diff(oldStr, newStr, options);
  550. }
  551. function diffWordsWithSpace(oldStr, newStr, callback) {
  552. return wordDiff.diff(oldStr, newStr, callback);
  553. }
  554. });
  555. unwrapExports(word);
  556. var line = createCommonjsModule(function (module, exports) {
  557. /*istanbul ignore start*/
  558. 'use strict';
  559. exports.__esModule = true;
  560. exports.lineDiff = undefined;
  561. exports.
  562. /*istanbul ignore end*/
  563. diffLines = diffLines;
  564. /*istanbul ignore start*/
  565. exports.
  566. /*istanbul ignore end*/
  567. diffTrimmedLines = diffTrimmedLines;
  568. /*istanbul ignore start*/
  569. var _base2 = _interopRequireDefault(base);
  570. /*istanbul ignore end*/
  571. /*istanbul ignore start*/
  572. function _interopRequireDefault(obj) {
  573. return obj && obj.__esModule ? obj : {
  574. 'default': obj
  575. };
  576. }
  577. /*istanbul ignore end*/
  578. var lineDiff =
  579. /*istanbul ignore start*/
  580. exports.
  581. /*istanbul ignore end*/
  582. lineDiff = new
  583. /*istanbul ignore start*/
  584. _base2['default']();
  585. lineDiff.tokenize = function (value) {
  586. var retLines = [],
  587. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  588. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  589. linesAndNewlines.pop();
  590. } // Merge the content and line separators into single tokens
  591. for (var i = 0; i < linesAndNewlines.length; i++) {
  592. var line = linesAndNewlines[i];
  593. if (i % 2 && !this.options.newlineIsToken) {
  594. retLines[retLines.length - 1] += line;
  595. } else {
  596. if (this.options.ignoreWhitespace) {
  597. line = line.trim();
  598. }
  599. retLines.push(line);
  600. }
  601. }
  602. return retLines;
  603. };
  604. function diffLines(oldStr, newStr, callback) {
  605. return lineDiff.diff(oldStr, newStr, callback);
  606. }
  607. function diffTrimmedLines(oldStr, newStr, callback) {
  608. var options =
  609. /*istanbul ignore start*/
  610. (0, params.generateOptions
  611. /*istanbul ignore end*/
  612. )(callback, {
  613. ignoreWhitespace: true
  614. });
  615. return lineDiff.diff(oldStr, newStr, options);
  616. }
  617. });
  618. unwrapExports(line);
  619. var sentence = createCommonjsModule(function (module, exports) {
  620. /*istanbul ignore start*/
  621. 'use strict';
  622. exports.__esModule = true;
  623. exports.sentenceDiff = undefined;
  624. exports.
  625. /*istanbul ignore end*/
  626. diffSentences = diffSentences;
  627. /*istanbul ignore start*/
  628. var _base2 = _interopRequireDefault(base);
  629. function _interopRequireDefault(obj) {
  630. return obj && obj.__esModule ? obj : {
  631. 'default': obj
  632. };
  633. }
  634. /*istanbul ignore end*/
  635. var sentenceDiff =
  636. /*istanbul ignore start*/
  637. exports.
  638. /*istanbul ignore end*/
  639. sentenceDiff = new
  640. /*istanbul ignore start*/
  641. _base2['default']();
  642. sentenceDiff.tokenize = function (value) {
  643. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  644. };
  645. function diffSentences(oldStr, newStr, callback) {
  646. return sentenceDiff.diff(oldStr, newStr, callback);
  647. }
  648. });
  649. unwrapExports(sentence);
  650. var css = createCommonjsModule(function (module, exports) {
  651. /*istanbul ignore start*/
  652. 'use strict';
  653. exports.__esModule = true;
  654. exports.cssDiff = undefined;
  655. exports.
  656. /*istanbul ignore end*/
  657. diffCss = diffCss;
  658. /*istanbul ignore start*/
  659. var _base2 = _interopRequireDefault(base);
  660. function _interopRequireDefault(obj) {
  661. return obj && obj.__esModule ? obj : {
  662. 'default': obj
  663. };
  664. }
  665. /*istanbul ignore end*/
  666. var cssDiff =
  667. /*istanbul ignore start*/
  668. exports.
  669. /*istanbul ignore end*/
  670. cssDiff = new
  671. /*istanbul ignore start*/
  672. _base2['default']();
  673. cssDiff.tokenize = function (value) {
  674. return value.split(/([{}:;,]|\s+)/);
  675. };
  676. function diffCss(oldStr, newStr, callback) {
  677. return cssDiff.diff(oldStr, newStr, callback);
  678. }
  679. });
  680. unwrapExports(css);
  681. var json = createCommonjsModule(function (module, exports) {
  682. /*istanbul ignore start*/
  683. 'use strict';
  684. exports.__esModule = true;
  685. exports.jsonDiff = undefined;
  686. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  687. return typeof obj;
  688. } : function (obj) {
  689. return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
  690. };
  691. exports.
  692. /*istanbul ignore end*/
  693. diffJson = diffJson;
  694. /*istanbul ignore start*/
  695. exports.
  696. /*istanbul ignore end*/
  697. canonicalize = canonicalize;
  698. /*istanbul ignore start*/
  699. var _base2 = _interopRequireDefault(base);
  700. /*istanbul ignore end*/
  701. /*istanbul ignore start*/
  702. function _interopRequireDefault(obj) {
  703. return obj && obj.__esModule ? obj : {
  704. 'default': obj
  705. };
  706. }
  707. /*istanbul ignore end*/
  708. var objectPrototypeToString = Object.prototype.toString;
  709. var jsonDiff =
  710. /*istanbul ignore start*/
  711. exports.
  712. /*istanbul ignore end*/
  713. jsonDiff = new
  714. /*istanbul ignore start*/
  715. _base2['default'](); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  716. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  717. jsonDiff.useLongestToken = true;
  718. jsonDiff.tokenize =
  719. /*istanbul ignore start*/
  720. line.lineDiff.
  721. /*istanbul ignore end*/
  722. tokenize;
  723. jsonDiff.castInput = function (value) {
  724. /*istanbul ignore start*/
  725. var
  726. /*istanbul ignore end*/
  727. undefinedReplacement = this.options.undefinedReplacement;
  728. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), function (k, v) {
  729. if (typeof v === 'undefined') {
  730. return undefinedReplacement;
  731. }
  732. return v;
  733. }, ' ');
  734. };
  735. jsonDiff.equals = function (left, right) {
  736. return (
  737. /*istanbul ignore start*/
  738. _base2['default'].
  739. /*istanbul ignore end*/
  740. prototype.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
  741. );
  742. };
  743. function diffJson(oldObj, newObj, options) {
  744. return jsonDiff.diff(oldObj, newObj, options);
  745. } // This function handles the presence of circular references by bailing out when encountering an
  746. // object that is already on the "stack" of items being processed.
  747. function canonicalize(obj, stack, replacementStack) {
  748. stack = stack || [];
  749. replacementStack = replacementStack || [];
  750. var i =
  751. /*istanbul ignore start*/
  752. void 0;
  753. for (i = 0; i < stack.length; i += 1) {
  754. if (stack[i] === obj) {
  755. return replacementStack[i];
  756. }
  757. }
  758. var canonicalizedObj =
  759. /*istanbul ignore start*/
  760. void 0;
  761. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  762. stack.push(obj);
  763. canonicalizedObj = new Array(obj.length);
  764. replacementStack.push(canonicalizedObj);
  765. for (i = 0; i < obj.length; i += 1) {
  766. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  767. }
  768. stack.pop();
  769. replacementStack.pop();
  770. return canonicalizedObj;
  771. }
  772. if (obj && obj.toJSON) {
  773. obj = obj.toJSON();
  774. }
  775. if (
  776. /*istanbul ignore start*/
  777. (typeof
  778. /*istanbul ignore end*/
  779. obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
  780. stack.push(obj);
  781. canonicalizedObj = {};
  782. replacementStack.push(canonicalizedObj);
  783. var sortedKeys = [],
  784. key =
  785. /*istanbul ignore start*/
  786. void 0;
  787. for (key in obj) {
  788. /* istanbul ignore else */
  789. if (obj.hasOwnProperty(key)) {
  790. sortedKeys.push(key);
  791. }
  792. }
  793. sortedKeys.sort();
  794. for (i = 0; i < sortedKeys.length; i += 1) {
  795. key = sortedKeys[i];
  796. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  797. }
  798. stack.pop();
  799. replacementStack.pop();
  800. } else {
  801. canonicalizedObj = obj;
  802. }
  803. return canonicalizedObj;
  804. }
  805. });
  806. unwrapExports(json);
  807. var array = createCommonjsModule(function (module, exports) {
  808. /*istanbul ignore start*/
  809. 'use strict';
  810. exports.__esModule = true;
  811. exports.arrayDiff = undefined;
  812. exports.
  813. /*istanbul ignore end*/
  814. diffArrays = diffArrays;
  815. /*istanbul ignore start*/
  816. var _base2 = _interopRequireDefault(base);
  817. function _interopRequireDefault(obj) {
  818. return obj && obj.__esModule ? obj : {
  819. 'default': obj
  820. };
  821. }
  822. /*istanbul ignore end*/
  823. var arrayDiff =
  824. /*istanbul ignore start*/
  825. exports.
  826. /*istanbul ignore end*/
  827. arrayDiff = new
  828. /*istanbul ignore start*/
  829. _base2['default']();
  830. arrayDiff.tokenize = arrayDiff.join = function (value) {
  831. return value.slice();
  832. };
  833. function diffArrays(oldArr, newArr, callback) {
  834. return arrayDiff.diff(oldArr, newArr, callback);
  835. }
  836. });
  837. unwrapExports(array);
  838. var parse = createCommonjsModule(function (module, exports) {
  839. /*istanbul ignore start*/
  840. 'use strict';
  841. exports.__esModule = true;
  842. exports.
  843. /*istanbul ignore end*/
  844. parsePatch = parsePatch;
  845. function parsePatch(uniDiff) {
  846. /*istanbul ignore start*/
  847. var
  848. /*istanbul ignore end*/
  849. options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  850. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  851. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  852. list = [],
  853. i = 0;
  854. function parseIndex() {
  855. var index = {};
  856. list.push(index); // Parse diff metadata
  857. while (i < diffstr.length) {
  858. var line = diffstr[i]; // File header found, end parsing diff metadata
  859. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  860. break;
  861. } // Diff index
  862. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  863. if (header) {
  864. index.index = header[1];
  865. }
  866. i++;
  867. } // Parse file headers if they are defined. Unified diff requires them, but
  868. // there's no technical issues to have an isolated hunk without file header
  869. parseFileHeader(index);
  870. parseFileHeader(index); // Parse hunks
  871. index.hunks = [];
  872. while (i < diffstr.length) {
  873. var _line = diffstr[i];
  874. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  875. break;
  876. } else if (/^@@/.test(_line)) {
  877. index.hunks.push(parseHunk());
  878. } else if (_line && options.strict) {
  879. // Ignore unexpected content unless in strict mode
  880. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  881. } else {
  882. i++;
  883. }
  884. }
  885. } // Parses the --- and +++ headers, if none are found, no lines
  886. // are consumed.
  887. function parseFileHeader(index) {
  888. var headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
  889. var fileHeader = headerPattern.exec(diffstr[i]);
  890. if (fileHeader) {
  891. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  892. index[keyPrefix + 'FileName'] = fileHeader[2];
  893. index[keyPrefix + 'Header'] = fileHeader[3];
  894. i++;
  895. }
  896. } // Parses a hunk
  897. // This assumes that we are at the start of a hunk.
  898. function parseHunk() {
  899. var chunkHeaderIndex = i,
  900. chunkHeaderLine = diffstr[i++],
  901. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  902. var hunk = {
  903. oldStart: +chunkHeader[1],
  904. oldLines: +chunkHeader[2] || 1,
  905. newStart: +chunkHeader[3],
  906. newLines: +chunkHeader[4] || 1,
  907. lines: [],
  908. linedelimiters: []
  909. };
  910. var addCount = 0,
  911. removeCount = 0;
  912. for (; i < diffstr.length; i++) {
  913. // Lines starting with '---' could be mistaken for the "remove line" operation
  914. // But they could be the header for the next file. Therefore prune such cases out.
  915. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  916. break;
  917. }
  918. var operation = diffstr[i][0];
  919. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  920. hunk.lines.push(diffstr[i]);
  921. hunk.linedelimiters.push(delimiters[i] || '\n');
  922. if (operation === '+') {
  923. addCount++;
  924. } else if (operation === '-') {
  925. removeCount++;
  926. } else if (operation === ' ') {
  927. addCount++;
  928. removeCount++;
  929. }
  930. } else {
  931. break;
  932. }
  933. } // Handle the empty block count case
  934. if (!addCount && hunk.newLines === 1) {
  935. hunk.newLines = 0;
  936. }
  937. if (!removeCount && hunk.oldLines === 1) {
  938. hunk.oldLines = 0;
  939. } // Perform optional sanity checking
  940. if (options.strict) {
  941. if (addCount !== hunk.newLines) {
  942. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  943. }
  944. if (removeCount !== hunk.oldLines) {
  945. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  946. }
  947. }
  948. return hunk;
  949. }
  950. while (i < diffstr.length) {
  951. parseIndex();
  952. }
  953. return list;
  954. }
  955. });
  956. unwrapExports(parse);
  957. var distanceIterator = createCommonjsModule(function (module, exports) {
  958. /*istanbul ignore start*/
  959. "use strict";
  960. exports.__esModule = true;
  961. exports["default"] =
  962. /*istanbul ignore end*/
  963. function (start, minLine, maxLine) {
  964. var wantForward = true,
  965. backwardExhausted = false,
  966. forwardExhausted = false,
  967. localOffset = 1;
  968. return function iterator() {
  969. if (wantForward && !forwardExhausted) {
  970. if (backwardExhausted) {
  971. localOffset++;
  972. } else {
  973. wantForward = false;
  974. } // Check if trying to fit beyond text length, and if not, check it fits
  975. // after offset location (or desired location on first iteration)
  976. if (start + localOffset <= maxLine) {
  977. return localOffset;
  978. }
  979. forwardExhausted = true;
  980. }
  981. if (!backwardExhausted) {
  982. if (!forwardExhausted) {
  983. wantForward = true;
  984. } // Check if trying to fit before text beginning, and if not, check it fits
  985. // before offset location
  986. if (minLine <= start - localOffset) {
  987. return -localOffset++;
  988. }
  989. backwardExhausted = true;
  990. return iterator();
  991. } // We tried to fit hunk before text beginning and beyond text lenght, then
  992. // hunk can't fit on the text. Return undefined
  993. };
  994. };
  995. });
  996. unwrapExports(distanceIterator);
  997. var apply = createCommonjsModule(function (module, exports) {
  998. /*istanbul ignore start*/
  999. 'use strict';
  1000. exports.__esModule = true;
  1001. exports.
  1002. /*istanbul ignore end*/
  1003. applyPatch = applyPatch;
  1004. /*istanbul ignore start*/
  1005. exports.
  1006. /*istanbul ignore end*/
  1007. applyPatches = applyPatches;
  1008. /*istanbul ignore start*/
  1009. var _distanceIterator2 = _interopRequireDefault(distanceIterator);
  1010. function _interopRequireDefault(obj) {
  1011. return obj && obj.__esModule ? obj : {
  1012. 'default': obj
  1013. };
  1014. }
  1015. /*istanbul ignore end*/
  1016. function applyPatch(source, uniDiff) {
  1017. /*istanbul ignore start*/
  1018. var
  1019. /*istanbul ignore end*/
  1020. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  1021. if (typeof uniDiff === 'string') {
  1022. uniDiff =
  1023. /*istanbul ignore start*/
  1024. (0, parse.parsePatch
  1025. /*istanbul ignore end*/
  1026. )(uniDiff);
  1027. }
  1028. if (Array.isArray(uniDiff)) {
  1029. if (uniDiff.length > 1) {
  1030. throw new Error('applyPatch only works with a single input.');
  1031. }
  1032. uniDiff = uniDiff[0];
  1033. } // Apply the diff to the input
  1034. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  1035. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  1036. hunks = uniDiff.hunks,
  1037. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent)
  1038. /*istanbul ignore start*/
  1039. {
  1040. return (
  1041. /*istanbul ignore end*/
  1042. line === patchContent
  1043. );
  1044. },
  1045. errorCount = 0,
  1046. fuzzFactor = options.fuzzFactor || 0,
  1047. minLine = 0,
  1048. offset = 0,
  1049. removeEOFNL =
  1050. /*istanbul ignore start*/
  1051. void 0
  1052. /*istanbul ignore end*/
  1053. ,
  1054. addEOFNL =
  1055. /*istanbul ignore start*/
  1056. void 0;
  1057. /**
  1058. * Checks if the hunk exactly fits on the provided location
  1059. */
  1060. function hunkFits(hunk, toPos) {
  1061. for (var j = 0; j < hunk.lines.length; j++) {
  1062. var line = hunk.lines[j],
  1063. operation = line[0],
  1064. content = line.substr(1);
  1065. if (operation === ' ' || operation === '-') {
  1066. // Context sanity check
  1067. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  1068. errorCount++;
  1069. if (errorCount > fuzzFactor) {
  1070. return false;
  1071. }
  1072. }
  1073. toPos++;
  1074. }
  1075. }
  1076. return true;
  1077. } // Search best fit offsets for each hunk based on the previous ones
  1078. for (var i = 0; i < hunks.length; i++) {
  1079. var hunk = hunks[i],
  1080. maxLine = lines.length - hunk.oldLines,
  1081. localOffset = 0,
  1082. toPos = offset + hunk.oldStart - 1;
  1083. var iterator =
  1084. /*istanbul ignore start*/
  1085. (0, _distanceIterator2['default']
  1086. /*istanbul ignore end*/
  1087. )(toPos, minLine, maxLine);
  1088. for (; localOffset !== undefined; localOffset = iterator()) {
  1089. if (hunkFits(hunk, toPos + localOffset)) {
  1090. hunk.offset = offset += localOffset;
  1091. break;
  1092. }
  1093. }
  1094. if (localOffset === undefined) {
  1095. return false;
  1096. } // Set lower text limit to end of the current hunk, so next ones don't try
  1097. // to fit over already patched text
  1098. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  1099. } // Apply patch hunks
  1100. for (var _i = 0; _i < hunks.length; _i++) {
  1101. var _hunk = hunks[_i],
  1102. _toPos = _hunk.offset + _hunk.newStart - 1;
  1103. if (_hunk.newLines == 0) {
  1104. _toPos++;
  1105. }
  1106. for (var j = 0; j < _hunk.lines.length; j++) {
  1107. var line = _hunk.lines[j],
  1108. operation = line[0],
  1109. content = line.substr(1),
  1110. delimiter = _hunk.linedelimiters[j];
  1111. if (operation === ' ') {
  1112. _toPos++;
  1113. } else if (operation === '-') {
  1114. lines.splice(_toPos, 1);
  1115. delimiters.splice(_toPos, 1);
  1116. /* istanbul ignore else */
  1117. } else if (operation === '+') {
  1118. lines.splice(_toPos, 0, content);
  1119. delimiters.splice(_toPos, 0, delimiter);
  1120. _toPos++;
  1121. } else if (operation === '\\') {
  1122. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  1123. if (previousOperation === '+') {
  1124. removeEOFNL = true;
  1125. } else if (previousOperation === '-') {
  1126. addEOFNL = true;
  1127. }
  1128. }
  1129. }
  1130. } // Handle EOFNL insertion/removal
  1131. if (removeEOFNL) {
  1132. while (!lines[lines.length - 1]) {
  1133. lines.pop();
  1134. delimiters.pop();
  1135. }
  1136. } else if (addEOFNL) {
  1137. lines.push('');
  1138. delimiters.push('\n');
  1139. }
  1140. for (var _k = 0; _k < lines.length - 1; _k++) {
  1141. lines[_k] = lines[_k] + delimiters[_k];
  1142. }
  1143. return lines.join('');
  1144. } // Wrapper that supports multiple file patches via callbacks.
  1145. function applyPatches(uniDiff, options) {
  1146. if (typeof uniDiff === 'string') {
  1147. uniDiff =
  1148. /*istanbul ignore start*/
  1149. (0, parse.parsePatch
  1150. /*istanbul ignore end*/
  1151. )(uniDiff);
  1152. }
  1153. var currentIndex = 0;
  1154. function processIndex() {
  1155. var index = uniDiff[currentIndex++];
  1156. if (!index) {
  1157. return options.complete();
  1158. }
  1159. options.loadFile(index, function (err, data) {
  1160. if (err) {
  1161. return options.complete(err);
  1162. }
  1163. var updatedContent = applyPatch(data, index, options);
  1164. options.patched(index, updatedContent, function (err) {
  1165. if (err) {
  1166. return options.complete(err);
  1167. }
  1168. processIndex();
  1169. });
  1170. });
  1171. }
  1172. processIndex();
  1173. }
  1174. });
  1175. unwrapExports(apply);
  1176. var create = createCommonjsModule(function (module, exports) {
  1177. /*istanbul ignore start*/
  1178. 'use strict';
  1179. exports.__esModule = true;
  1180. exports.
  1181. /*istanbul ignore end*/
  1182. structuredPatch = structuredPatch;
  1183. /*istanbul ignore start*/
  1184. exports.
  1185. /*istanbul ignore end*/
  1186. createTwoFilesPatch = createTwoFilesPatch;
  1187. /*istanbul ignore start*/
  1188. exports.
  1189. /*istanbul ignore end*/
  1190. createPatch = createPatch;
  1191. /*istanbul ignore start*/
  1192. function _toConsumableArray(arr) {
  1193. if (Array.isArray(arr)) {
  1194. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
  1195. arr2[i] = arr[i];
  1196. }
  1197. return arr2;
  1198. } else {
  1199. return Array.from(arr);
  1200. }
  1201. }
  1202. /*istanbul ignore end*/
  1203. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1204. if (!options) {
  1205. options = {};
  1206. }
  1207. if (typeof options.context === 'undefined') {
  1208. options.context = 4;
  1209. }
  1210. var diff =
  1211. /*istanbul ignore start*/
  1212. (0, line.diffLines
  1213. /*istanbul ignore end*/
  1214. )(oldStr, newStr, options);
  1215. diff.push({
  1216. value: '',
  1217. lines: []
  1218. }); // Append an empty value to make cleanup easier
  1219. function contextLines(lines) {
  1220. return lines.map(function (entry) {
  1221. return ' ' + entry;
  1222. });
  1223. }
  1224. var hunks = [];
  1225. var oldRangeStart = 0,
  1226. newRangeStart = 0,
  1227. curRange = [],
  1228. oldLine = 1,
  1229. newLine = 1;
  1230. /*istanbul ignore start*/
  1231. var _loop = function _loop(
  1232. /*istanbul ignore end*/
  1233. i) {
  1234. var current = diff[i],
  1235. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  1236. current.lines = lines;
  1237. if (current.added || current.removed) {
  1238. /*istanbul ignore start*/
  1239. var _curRange;
  1240. /*istanbul ignore end*/
  1241. // If we have previous context, start with that
  1242. if (!oldRangeStart) {
  1243. var prev = diff[i - 1];
  1244. oldRangeStart = oldLine;
  1245. newRangeStart = newLine;
  1246. if (prev) {
  1247. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  1248. oldRangeStart -= curRange.length;
  1249. newRangeStart -= curRange.length;
  1250. }
  1251. } // Output our changes
  1252. /*istanbul ignore start*/
  1253. (_curRange =
  1254. /*istanbul ignore end*/
  1255. curRange).push.
  1256. /*istanbul ignore start*/
  1257. apply
  1258. /*istanbul ignore end*/
  1259. (
  1260. /*istanbul ignore start*/
  1261. _curRange
  1262. /*istanbul ignore end*/
  1263. ,
  1264. /*istanbul ignore start*/
  1265. _toConsumableArray(
  1266. /*istanbul ignore end*/
  1267. lines.map(function (entry) {
  1268. return (current.added ? '+' : '-') + entry;
  1269. }))); // Track the updated file position
  1270. if (current.added) {
  1271. newLine += lines.length;
  1272. } else {
  1273. oldLine += lines.length;
  1274. }
  1275. } else {
  1276. // Identical context lines. Track line changes
  1277. if (oldRangeStart) {
  1278. // Close out any changes that have been output (or join overlapping)
  1279. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  1280. /*istanbul ignore start*/
  1281. var _curRange2;
  1282. /*istanbul ignore end*/
  1283. // Overlapping
  1284. /*istanbul ignore start*/
  1285. (_curRange2 =
  1286. /*istanbul ignore end*/
  1287. curRange).push.
  1288. /*istanbul ignore start*/
  1289. apply
  1290. /*istanbul ignore end*/
  1291. (
  1292. /*istanbul ignore start*/
  1293. _curRange2
  1294. /*istanbul ignore end*/
  1295. ,
  1296. /*istanbul ignore start*/
  1297. _toConsumableArray(
  1298. /*istanbul ignore end*/
  1299. contextLines(lines)));
  1300. } else {
  1301. /*istanbul ignore start*/
  1302. var _curRange3;
  1303. /*istanbul ignore end*/
  1304. // end the range and output
  1305. var contextSize = Math.min(lines.length, options.context);
  1306. /*istanbul ignore start*/
  1307. (_curRange3 =
  1308. /*istanbul ignore end*/
  1309. curRange).push.
  1310. /*istanbul ignore start*/
  1311. apply
  1312. /*istanbul ignore end*/
  1313. (
  1314. /*istanbul ignore start*/
  1315. _curRange3
  1316. /*istanbul ignore end*/
  1317. ,
  1318. /*istanbul ignore start*/
  1319. _toConsumableArray(
  1320. /*istanbul ignore end*/
  1321. contextLines(lines.slice(0, contextSize))));
  1322. var hunk = {
  1323. oldStart: oldRangeStart,
  1324. oldLines: oldLine - oldRangeStart + contextSize,
  1325. newStart: newRangeStart,
  1326. newLines: newLine - newRangeStart + contextSize,
  1327. lines: curRange
  1328. };
  1329. if (i >= diff.length - 2 && lines.length <= options.context) {
  1330. // EOF is inside this hunk
  1331. var oldEOFNewline = /\n$/.test(oldStr);
  1332. var newEOFNewline = /\n$/.test(newStr);
  1333. if (lines.length == 0 && !oldEOFNewline) {
  1334. // special case: old has no eol and no trailing context; no-nl can end up before adds
  1335. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  1336. } else if (!oldEOFNewline || !newEOFNewline) {
  1337. curRange.push('\\ No newline at end of file');
  1338. }
  1339. }
  1340. hunks.push(hunk);
  1341. oldRangeStart = 0;
  1342. newRangeStart = 0;
  1343. curRange = [];
  1344. }
  1345. }
  1346. oldLine += lines.length;
  1347. newLine += lines.length;
  1348. }
  1349. };
  1350. for (var i = 0; i < diff.length; i++) {
  1351. /*istanbul ignore start*/
  1352. _loop(
  1353. /*istanbul ignore end*/
  1354. i);
  1355. }
  1356. return {
  1357. oldFileName: oldFileName,
  1358. newFileName: newFileName,
  1359. oldHeader: oldHeader,
  1360. newHeader: newHeader,
  1361. hunks: hunks
  1362. };
  1363. }
  1364. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1365. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  1366. var ret = [];
  1367. if (oldFileName == newFileName) {
  1368. ret.push('Index: ' + oldFileName);
  1369. }
  1370. ret.push('===================================================================');
  1371. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  1372. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  1373. for (var i = 0; i < diff.hunks.length; i++) {
  1374. var hunk = diff.hunks[i];
  1375. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  1376. ret.push.apply(ret, hunk.lines);
  1377. }
  1378. return ret.join('\n') + '\n';
  1379. }
  1380. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  1381. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  1382. }
  1383. });
  1384. unwrapExports(create);
  1385. var dmp = createCommonjsModule(function (module, exports) {
  1386. /*istanbul ignore start*/
  1387. "use strict";
  1388. exports.__esModule = true;
  1389. exports.
  1390. /*istanbul ignore end*/
  1391. convertChangesToDMP = convertChangesToDMP; // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  1392. function convertChangesToDMP(changes) {
  1393. var ret = [],
  1394. change =
  1395. /*istanbul ignore start*/
  1396. void 0
  1397. /*istanbul ignore end*/
  1398. ,
  1399. operation =
  1400. /*istanbul ignore start*/
  1401. void 0;
  1402. for (var i = 0; i < changes.length; i++) {
  1403. change = changes[i];
  1404. if (change.added) {
  1405. operation = 1;
  1406. } else if (change.removed) {
  1407. operation = -1;
  1408. } else {
  1409. operation = 0;
  1410. }
  1411. ret.push([operation, change.value]);
  1412. }
  1413. return ret;
  1414. }
  1415. });
  1416. unwrapExports(dmp);
  1417. var xml = createCommonjsModule(function (module, exports) {
  1418. /*istanbul ignore start*/
  1419. 'use strict';
  1420. exports.__esModule = true;
  1421. exports.
  1422. /*istanbul ignore end*/
  1423. convertChangesToXML = convertChangesToXML;
  1424. function convertChangesToXML(changes) {
  1425. var ret = [];
  1426. for (var i = 0; i < changes.length; i++) {
  1427. var change = changes[i];
  1428. if (change.added) {
  1429. ret.push('<ins>');
  1430. } else if (change.removed) {
  1431. ret.push('<del>');
  1432. }
  1433. ret.push(escapeHTML(change.value));
  1434. if (change.added) {
  1435. ret.push('</ins>');
  1436. } else if (change.removed) {
  1437. ret.push('</del>');
  1438. }
  1439. }
  1440. return ret.join('');
  1441. }
  1442. function escapeHTML(s) {
  1443. var n = s;
  1444. n = n.replace(/&/g, '&amp;');
  1445. n = n.replace(/</g, '&lt;');
  1446. n = n.replace(/>/g, '&gt;');
  1447. n = n.replace(/"/g, '&quot;');
  1448. return n;
  1449. }
  1450. });
  1451. unwrapExports(xml);
  1452. var lib = createCommonjsModule(function (module, exports) {
  1453. /*istanbul ignore start*/
  1454. 'use strict';
  1455. exports.__esModule = true;
  1456. 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;
  1457. /*istanbul ignore end*/
  1458. /*istanbul ignore start*/
  1459. var _base2 = _interopRequireDefault(base);
  1460. /*istanbul ignore end*/
  1461. /*istanbul ignore start*/
  1462. function _interopRequireDefault(obj) {
  1463. return obj && obj.__esModule ? obj : {
  1464. 'default': obj
  1465. };
  1466. }
  1467. exports.
  1468. /*istanbul ignore end*/
  1469. Diff = _base2['default'];
  1470. /*istanbul ignore start*/
  1471. exports.
  1472. /*istanbul ignore end*/
  1473. diffChars = character.diffChars;
  1474. /*istanbul ignore start*/
  1475. exports.
  1476. /*istanbul ignore end*/
  1477. diffWords = word.diffWords;
  1478. /*istanbul ignore start*/
  1479. exports.
  1480. /*istanbul ignore end*/
  1481. diffWordsWithSpace = word.diffWordsWithSpace;
  1482. /*istanbul ignore start*/
  1483. exports.
  1484. /*istanbul ignore end*/
  1485. diffLines = line.diffLines;
  1486. /*istanbul ignore start*/
  1487. exports.
  1488. /*istanbul ignore end*/
  1489. diffTrimmedLines = line.diffTrimmedLines;
  1490. /*istanbul ignore start*/
  1491. exports.
  1492. /*istanbul ignore end*/
  1493. diffSentences = sentence.diffSentences;
  1494. /*istanbul ignore start*/
  1495. exports.
  1496. /*istanbul ignore end*/
  1497. diffCss = css.diffCss;
  1498. /*istanbul ignore start*/
  1499. exports.
  1500. /*istanbul ignore end*/
  1501. diffJson = json.diffJson;
  1502. /*istanbul ignore start*/
  1503. exports.
  1504. /*istanbul ignore end*/
  1505. diffArrays = array.diffArrays;
  1506. /*istanbul ignore start*/
  1507. exports.
  1508. /*istanbul ignore end*/
  1509. structuredPatch = create.structuredPatch;
  1510. /*istanbul ignore start*/
  1511. exports.
  1512. /*istanbul ignore end*/
  1513. createTwoFilesPatch = create.createTwoFilesPatch;
  1514. /*istanbul ignore start*/
  1515. exports.
  1516. /*istanbul ignore end*/
  1517. createPatch = create.createPatch;
  1518. /*istanbul ignore start*/
  1519. exports.
  1520. /*istanbul ignore end*/
  1521. applyPatch = apply.applyPatch;
  1522. /*istanbul ignore start*/
  1523. exports.
  1524. /*istanbul ignore end*/
  1525. applyPatches = apply.applyPatches;
  1526. /*istanbul ignore start*/
  1527. exports.
  1528. /*istanbul ignore end*/
  1529. parsePatch = parse.parsePatch;
  1530. /*istanbul ignore start*/
  1531. exports.
  1532. /*istanbul ignore end*/
  1533. convertChangesToDMP = dmp.convertChangesToDMP;
  1534. /*istanbul ignore start*/
  1535. exports.
  1536. /*istanbul ignore end*/
  1537. convertChangesToXML = xml.convertChangesToXML;
  1538. /*istanbul ignore start*/
  1539. exports.
  1540. /*istanbul ignore end*/
  1541. canonicalize = json.canonicalize;
  1542. /* See LICENSE file for terms of use */
  1543. /*
  1544. * Text diff implementation.
  1545. *
  1546. * This library supports the following APIS:
  1547. * JsDiff.diffChars: Character by character diff
  1548. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  1549. * JsDiff.diffLines: Line based diff
  1550. *
  1551. * JsDiff.diffCss: Diff targeted at CSS content
  1552. *
  1553. * These methods are based on the implementation proposed in
  1554. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  1555. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  1556. */
  1557. });
  1558. unwrapExports(lib);
  1559. /*!
  1560. * normalize-path <https://github.com/jonschlinkert/normalize-path>
  1561. *
  1562. * Copyright (c) 2014-2018, Jon Schlinkert.
  1563. * Released under the MIT License.
  1564. */
  1565. var normalizePath = function normalizePath(path$$1, stripTrailing) {
  1566. if (typeof path$$1 !== 'string') {
  1567. throw new TypeError('expected path to be a string');
  1568. }
  1569. if (path$$1 === '\\' || path$$1 === '/') return '/';
  1570. var len = path$$1.length;
  1571. if (len <= 1) return path$$1; // ensure that win32 namespaces has two leading slashes, so that the path is
  1572. // handled properly by the win32 version of path.parse() after being normalized
  1573. // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
  1574. var prefix = '';
  1575. if (len > 4 && path$$1[3] === '\\') {
  1576. var ch = path$$1[2];
  1577. if ((ch === '?' || ch === '.') && path$$1.slice(0, 2) === '\\\\') {
  1578. path$$1 = path$$1.slice(2);
  1579. prefix = '//';
  1580. }
  1581. }
  1582. var segs = path$$1.split(/[/\\]+/);
  1583. if (stripTrailing !== false && segs[segs.length - 1] === '') {
  1584. segs.pop();
  1585. }
  1586. return prefix + segs.join('/');
  1587. };
  1588. function _classCallCheck(instance, Constructor) {
  1589. if (!(instance instanceof Constructor)) {
  1590. throw new TypeError("Cannot call a class as a function");
  1591. }
  1592. }
  1593. function _defineProperties(target, props) {
  1594. for (var i = 0; i < props.length; i++) {
  1595. var descriptor = props[i];
  1596. descriptor.enumerable = descriptor.enumerable || false;
  1597. descriptor.configurable = true;
  1598. if ("value" in descriptor) descriptor.writable = true;
  1599. Object.defineProperty(target, descriptor.key, descriptor);
  1600. }
  1601. }
  1602. function _createClass(Constructor, protoProps, staticProps) {
  1603. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1604. if (staticProps) _defineProperties(Constructor, staticProps);
  1605. return Constructor;
  1606. }
  1607. function _inherits(subClass, superClass) {
  1608. if (typeof superClass !== "function" && superClass !== null) {
  1609. throw new TypeError("Super expression must either be null or a function");
  1610. }
  1611. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1612. constructor: {
  1613. value: subClass,
  1614. writable: true,
  1615. configurable: true
  1616. }
  1617. });
  1618. if (superClass) _setPrototypeOf(subClass, superClass);
  1619. }
  1620. function _getPrototypeOf(o) {
  1621. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  1622. return o.__proto__ || Object.getPrototypeOf(o);
  1623. };
  1624. return _getPrototypeOf(o);
  1625. }
  1626. function _setPrototypeOf(o, p) {
  1627. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1628. o.__proto__ = p;
  1629. return o;
  1630. };
  1631. return _setPrototypeOf(o, p);
  1632. }
  1633. function isNativeReflectConstruct() {
  1634. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1635. if (Reflect.construct.sham) return false;
  1636. if (typeof Proxy === "function") return true;
  1637. try {
  1638. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  1639. return true;
  1640. } catch (e) {
  1641. return false;
  1642. }
  1643. }
  1644. function _construct(Parent, args, Class) {
  1645. if (isNativeReflectConstruct()) {
  1646. _construct = Reflect.construct;
  1647. } else {
  1648. _construct = function _construct(Parent, args, Class) {
  1649. var a = [null];
  1650. a.push.apply(a, args);
  1651. var Constructor = Function.bind.apply(Parent, a);
  1652. var instance = new Constructor();
  1653. if (Class) _setPrototypeOf(instance, Class.prototype);
  1654. return instance;
  1655. };
  1656. }
  1657. return _construct.apply(null, arguments);
  1658. }
  1659. function _isNativeFunction(fn) {
  1660. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  1661. }
  1662. function _wrapNativeSuper(Class) {
  1663. var _cache = typeof Map === "function" ? new Map() : undefined;
  1664. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1665. if (Class === null || !_isNativeFunction(Class)) return Class;
  1666. if (typeof Class !== "function") {
  1667. throw new TypeError("Super expression must either be null or a function");
  1668. }
  1669. if (typeof _cache !== "undefined") {
  1670. if (_cache.has(Class)) return _cache.get(Class);
  1671. _cache.set(Class, Wrapper);
  1672. }
  1673. function Wrapper() {
  1674. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1675. }
  1676. Wrapper.prototype = Object.create(Class.prototype, {
  1677. constructor: {
  1678. value: Wrapper,
  1679. enumerable: false,
  1680. writable: true,
  1681. configurable: true
  1682. }
  1683. });
  1684. return _setPrototypeOf(Wrapper, Class);
  1685. };
  1686. return _wrapNativeSuper(Class);
  1687. }
  1688. function _assertThisInitialized(self) {
  1689. if (self === void 0) {
  1690. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1691. }
  1692. return self;
  1693. }
  1694. function _possibleConstructorReturn(self, call) {
  1695. if (call && (typeof call === "object" || typeof call === "function")) {
  1696. return call;
  1697. }
  1698. return _assertThisInitialized(self);
  1699. }
  1700. function _superPropBase(object, property) {
  1701. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  1702. object = _getPrototypeOf(object);
  1703. if (object === null) break;
  1704. }
  1705. return object;
  1706. }
  1707. function _get(target, property, receiver) {
  1708. if (typeof Reflect !== "undefined" && Reflect.get) {
  1709. _get = Reflect.get;
  1710. } else {
  1711. _get = function _get(target, property, receiver) {
  1712. var base = _superPropBase(target, property);
  1713. if (!base) return;
  1714. var desc = Object.getOwnPropertyDescriptor(base, property);
  1715. if (desc.get) {
  1716. return desc.get.call(receiver);
  1717. }
  1718. return desc.value;
  1719. };
  1720. }
  1721. return _get(target, property, receiver || target);
  1722. }
  1723. function _slicedToArray(arr, i) {
  1724. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  1725. }
  1726. function _toArray(arr) {
  1727. return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
  1728. }
  1729. function _toConsumableArray(arr) {
  1730. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  1731. }
  1732. function _arrayWithoutHoles(arr) {
  1733. if (Array.isArray(arr)) {
  1734. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  1735. return arr2;
  1736. }
  1737. }
  1738. function _arrayWithHoles(arr) {
  1739. if (Array.isArray(arr)) return arr;
  1740. }
  1741. function _iterableToArray(iter) {
  1742. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  1743. }
  1744. function _iterableToArrayLimit(arr, i) {
  1745. var _arr = [];
  1746. var _n = true;
  1747. var _d = false;
  1748. var _e = undefined;
  1749. try {
  1750. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  1751. _arr.push(_s.value);
  1752. if (i && _arr.length === i) break;
  1753. }
  1754. } catch (err) {
  1755. _d = true;
  1756. _e = err;
  1757. } finally {
  1758. try {
  1759. if (!_n && _i["return"] != null) _i["return"]();
  1760. } finally {
  1761. if (_d) throw _e;
  1762. }
  1763. }
  1764. return _arr;
  1765. }
  1766. function _nonIterableSpread() {
  1767. throw new TypeError("Invalid attempt to spread non-iterable instance");
  1768. }
  1769. function _nonIterableRest() {
  1770. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  1771. }
  1772. function _toPrimitive(input, hint) {
  1773. if (typeof input !== "object" || input === null) return input;
  1774. var prim = input[Symbol.toPrimitive];
  1775. if (prim !== undefined) {
  1776. var res = prim.call(input, hint || "default");
  1777. if (typeof res !== "object") return res;
  1778. throw new TypeError("@@toPrimitive must return a primitive value.");
  1779. }
  1780. return (hint === "string" ? String : Number)(input);
  1781. }
  1782. function _toPropertyKey(arg) {
  1783. var key = _toPrimitive(arg, "string");
  1784. return typeof key === "symbol" ? key : String(key);
  1785. }
  1786. function _addElementPlacement(element, placements, silent) {
  1787. var keys = placements[element.placement];
  1788. if (!silent && keys.indexOf(element.key) !== -1) {
  1789. throw new TypeError("Duplicated element (" + element.key + ")");
  1790. }
  1791. keys.push(element.key);
  1792. }
  1793. function _fromElementDescriptor(element) {
  1794. var obj = {
  1795. kind: element.kind,
  1796. key: element.key,
  1797. placement: element.placement,
  1798. descriptor: element.descriptor
  1799. };
  1800. var desc = {
  1801. value: "Descriptor",
  1802. configurable: true
  1803. };
  1804. Object.defineProperty(obj, Symbol.toStringTag, desc);
  1805. if (element.kind === "field") obj.initializer = element.initializer;
  1806. return obj;
  1807. }
  1808. function _toElementDescriptors(elementObjects) {
  1809. if (elementObjects === undefined) return;
  1810. return _toArray(elementObjects).map(function (elementObject) {
  1811. var element = _toElementDescriptor(elementObject);
  1812. _disallowProperty(elementObject, "finisher", "An element descriptor");
  1813. _disallowProperty(elementObject, "extras", "An element descriptor");
  1814. return element;
  1815. });
  1816. }
  1817. function _toElementDescriptor(elementObject) {
  1818. var kind = String(elementObject.kind);
  1819. if (kind !== "method" && kind !== "field") {
  1820. 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 + '"');
  1821. }
  1822. var key = _toPropertyKey(elementObject.key);
  1823. var placement = String(elementObject.placement);
  1824. if (placement !== "static" && placement !== "prototype" && placement !== "own") {
  1825. 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 + '"');
  1826. }
  1827. var descriptor = elementObject.descriptor;
  1828. _disallowProperty(elementObject, "elements", "An element descriptor");
  1829. var element = {
  1830. kind: kind,
  1831. key: key,
  1832. placement: placement,
  1833. descriptor: Object.assign({}, descriptor)
  1834. };
  1835. if (kind !== "field") {
  1836. _disallowProperty(elementObject, "initializer", "A method descriptor");
  1837. } else {
  1838. _disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");
  1839. _disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");
  1840. _disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");
  1841. element.initializer = elementObject.initializer;
  1842. }
  1843. return element;
  1844. }
  1845. function _toElementFinisherExtras(elementObject) {
  1846. var element = _toElementDescriptor(elementObject);
  1847. var finisher = _optionalCallableProperty(elementObject, "finisher");
  1848. var extras = _toElementDescriptors(elementObject.extras);
  1849. return {
  1850. element: element,
  1851. finisher: finisher,
  1852. extras: extras
  1853. };
  1854. }
  1855. function _fromClassDescriptor(elements) {
  1856. var obj = {
  1857. kind: "class",
  1858. elements: elements.map(_fromElementDescriptor)
  1859. };
  1860. var desc = {
  1861. value: "Descriptor",
  1862. configurable: true
  1863. };
  1864. Object.defineProperty(obj, Symbol.toStringTag, desc);
  1865. return obj;
  1866. }
  1867. function _toClassDescriptor(obj) {
  1868. var kind = String(obj.kind);
  1869. if (kind !== "class") {
  1870. throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
  1871. }
  1872. _disallowProperty(obj, "key", "A class descriptor");
  1873. _disallowProperty(obj, "placement", "A class descriptor");
  1874. _disallowProperty(obj, "descriptor", "A class descriptor");
  1875. _disallowProperty(obj, "initializer", "A class descriptor");
  1876. _disallowProperty(obj, "extras", "A class descriptor");
  1877. var finisher = _optionalCallableProperty(obj, "finisher");
  1878. var elements = _toElementDescriptors(obj.elements);
  1879. return {
  1880. elements: elements,
  1881. finisher: finisher
  1882. };
  1883. }
  1884. function _disallowProperty(obj, name, objectType) {
  1885. if (obj[name] !== undefined) {
  1886. throw new TypeError(objectType + " can't have a ." + name + " property.");
  1887. }
  1888. }
  1889. function _optionalCallableProperty(obj, name) {
  1890. var value = obj[name];
  1891. if (value !== undefined && typeof value !== "function") {
  1892. throw new TypeError("Expected '" + name + "' to be a function");
  1893. }
  1894. return value;
  1895. }
  1896. /**
  1897. * @class
  1898. */
  1899. var LineByLine =
  1900. /*#__PURE__*/
  1901. function () {
  1902. function LineByLine(file, options) {
  1903. _classCallCheck(this, LineByLine);
  1904. options = options || {};
  1905. if (!options.readChunk) options.readChunk = 1024;
  1906. if (!options.newLineCharacter) {
  1907. options.newLineCharacter = 0x0a; //linux line ending
  1908. } else {
  1909. options.newLineCharacter = options.newLineCharacter.charCodeAt(0);
  1910. }
  1911. if (typeof file === 'number') {
  1912. this.fd = file;
  1913. } else {
  1914. this.fd = fs.openSync(file, 'r');
  1915. }
  1916. this.options = options;
  1917. this.newLineCharacter = options.newLineCharacter;
  1918. this.reset();
  1919. }
  1920. _createClass(LineByLine, [{
  1921. key: "_searchInBuffer",
  1922. value: function _searchInBuffer(buffer, hexNeedle) {
  1923. var found = -1;
  1924. for (var i = 0; i <= buffer.length; i++) {
  1925. var b_byte = buffer[i];
  1926. if (b_byte === hexNeedle) {
  1927. found = i;
  1928. break;
  1929. }
  1930. }
  1931. return found;
  1932. }
  1933. }, {
  1934. key: "reset",
  1935. value: function reset() {
  1936. this.eofReached = false;
  1937. this.linesCache = [];
  1938. this.fdPosition = 0;
  1939. }
  1940. }, {
  1941. key: "close",
  1942. value: function close() {
  1943. fs.closeSync(this.fd);
  1944. this.fd = null;
  1945. }
  1946. }, {
  1947. key: "_extractLines",
  1948. value: function _extractLines(buffer) {
  1949. var line;
  1950. var lines = [];
  1951. var bufferPosition = 0;
  1952. var lastNewLineBufferPosition = 0;
  1953. while (true) {
  1954. var bufferPositionValue = buffer[bufferPosition++];
  1955. if (bufferPositionValue === this.newLineCharacter) {
  1956. line = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  1957. lines.push(line);
  1958. lastNewLineBufferPosition = bufferPosition;
  1959. } else if (!bufferPositionValue) {
  1960. break;
  1961. }
  1962. }
  1963. var leftovers = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  1964. if (leftovers.length) {
  1965. lines.push(leftovers);
  1966. }
  1967. return lines;
  1968. }
  1969. }, {
  1970. key: "_readChunk",
  1971. value: function _readChunk(lineLeftovers) {
  1972. var totalBytesRead = 0;
  1973. var bytesRead;
  1974. var buffers = [];
  1975. do {
  1976. var readBuffer = new Buffer(this.options.readChunk);
  1977. bytesRead = fs.readSync(this.fd, readBuffer, 0, this.options.readChunk, this.fdPosition);
  1978. totalBytesRead = totalBytesRead + bytesRead;
  1979. this.fdPosition = this.fdPosition + bytesRead;
  1980. buffers.push(readBuffer);
  1981. } while (bytesRead && this._searchInBuffer(buffers[buffers.length - 1], this.options.newLineCharacter) === -1);
  1982. var bufferData = Buffer.concat(buffers);
  1983. if (bytesRead < this.options.readChunk) {
  1984. this.eofReached = true;
  1985. bufferData = bufferData.slice(0, totalBytesRead);
  1986. }
  1987. if (totalBytesRead) {
  1988. this.linesCache = this._extractLines(bufferData);
  1989. if (lineLeftovers) {
  1990. this.linesCache[0] = Buffer.concat([lineLeftovers, this.linesCache[0]]);
  1991. }
  1992. }
  1993. return totalBytesRead;
  1994. }
  1995. }, {
  1996. key: "next",
  1997. value: function next() {
  1998. if (!this.fd) return false;
  1999. var line = false;
  2000. if (this.eofReached && this.linesCache.length === 0) {
  2001. return line;
  2002. }
  2003. var bytesRead;
  2004. if (!this.linesCache.length) {
  2005. bytesRead = this._readChunk();
  2006. }
  2007. if (this.linesCache.length) {
  2008. line = this.linesCache.shift();
  2009. var lastLineCharacter = line[line.length - 1];
  2010. if (lastLineCharacter !== 0x0a) {
  2011. bytesRead = this._readChunk(line);
  2012. if (bytesRead) {
  2013. line = this.linesCache.shift();
  2014. }
  2015. }
  2016. }
  2017. if (this.eofReached && this.linesCache.length === 0) {
  2018. this.close();
  2019. }
  2020. if (line && line[line.length - 1] === this.newLineCharacter) {
  2021. line = line.slice(0, line.length - 1);
  2022. }
  2023. return line;
  2024. }
  2025. }]);
  2026. return LineByLine;
  2027. }();
  2028. var readlines = LineByLine;
  2029. var ConfigError =
  2030. /*#__PURE__*/
  2031. function (_Error) {
  2032. _inherits(ConfigError, _Error);
  2033. function ConfigError() {
  2034. _classCallCheck(this, ConfigError);
  2035. return _possibleConstructorReturn(this, _getPrototypeOf(ConfigError).apply(this, arguments));
  2036. }
  2037. return ConfigError;
  2038. }(_wrapNativeSuper(Error));
  2039. var DebugError =
  2040. /*#__PURE__*/
  2041. function (_Error2) {
  2042. _inherits(DebugError, _Error2);
  2043. function DebugError() {
  2044. _classCallCheck(this, DebugError);
  2045. return _possibleConstructorReturn(this, _getPrototypeOf(DebugError).apply(this, arguments));
  2046. }
  2047. return DebugError;
  2048. }(_wrapNativeSuper(Error));
  2049. var UndefinedParserError$1 =
  2050. /*#__PURE__*/
  2051. function (_Error3) {
  2052. _inherits(UndefinedParserError, _Error3);
  2053. function UndefinedParserError() {
  2054. _classCallCheck(this, UndefinedParserError);
  2055. return _possibleConstructorReturn(this, _getPrototypeOf(UndefinedParserError).apply(this, arguments));
  2056. }
  2057. return UndefinedParserError;
  2058. }(_wrapNativeSuper(Error));
  2059. var errors = {
  2060. ConfigError,
  2061. DebugError,
  2062. UndefinedParserError: UndefinedParserError$1
  2063. };
  2064. var semver = createCommonjsModule(function (module, exports) {
  2065. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  2066. /* nomin */
  2067. var debug;
  2068. /* nomin */
  2069. if (typeof process === 'object' &&
  2070. /* nomin */
  2071. process.env &&
  2072. /* nomin */
  2073. process.env.NODE_DEBUG &&
  2074. /* nomin */
  2075. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  2076. /* nomin */
  2077. debug = function debug() {
  2078. /* nomin */
  2079. var args = Array.prototype.slice.call(arguments, 0);
  2080. /* nomin */
  2081. args.unshift('SEMVER');
  2082. /* nomin */
  2083. console.log.apply(console, args);
  2084. /* nomin */
  2085. };
  2086. /* nomin */
  2087. else
  2088. /* nomin */
  2089. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  2090. // Not necessarily the package version of this code.
  2091. exports.SEMVER_SPEC_VERSION = '2.0.0';
  2092. var MAX_LENGTH = 256;
  2093. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // The actual regexps go on exports.re
  2094. var re = exports.re = [];
  2095. var src = exports.src = [];
  2096. var R = 0; // The following Regular Expressions can be used for tokenizing,
  2097. // validating, and parsing SemVer version strings.
  2098. // ## Numeric Identifier
  2099. // A single `0`, or a non-zero digit followed by zero or more digits.
  2100. var NUMERICIDENTIFIER = R++;
  2101. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  2102. var NUMERICIDENTIFIERLOOSE = R++;
  2103. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  2104. // Zero or more digits, followed by a letter or hyphen, and then zero or
  2105. // more letters, digits, or hyphens.
  2106. var NONNUMERICIDENTIFIER = R++;
  2107. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  2108. // Three dot-separated numeric identifiers.
  2109. var MAINVERSION = R++;
  2110. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  2111. var MAINVERSIONLOOSE = R++;
  2112. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  2113. // A numeric identifier, or a non-numeric identifier.
  2114. var PRERELEASEIDENTIFIER = R++;
  2115. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  2116. var PRERELEASEIDENTIFIERLOOSE = R++;
  2117. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  2118. // Hyphen, followed by one or more dot-separated pre-release version
  2119. // identifiers.
  2120. var PRERELEASE = R++;
  2121. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  2122. var PRERELEASELOOSE = R++;
  2123. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  2124. // Any combination of digits, letters, or hyphens.
  2125. var BUILDIDENTIFIER = R++;
  2126. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  2127. // Plus sign, followed by one or more period-separated build metadata
  2128. // identifiers.
  2129. var BUILD = R++;
  2130. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  2131. // A main version, followed optionally by a pre-release version and
  2132. // build metadata.
  2133. // Note that the only major, minor, patch, and pre-release sections of
  2134. // the version string are capturing groups. The build metadata is not a
  2135. // capturing group, because it should not ever be used in version
  2136. // comparison.
  2137. var FULL = R++;
  2138. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  2139. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  2140. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  2141. // common in the npm registry.
  2142. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  2143. var LOOSE = R++;
  2144. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  2145. var GTLT = R++;
  2146. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  2147. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  2148. // Only the first item is strictly required.
  2149. var XRANGEIDENTIFIERLOOSE = R++;
  2150. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  2151. var XRANGEIDENTIFIER = R++;
  2152. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  2153. var XRANGEPLAIN = R++;
  2154. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  2155. var XRANGEPLAINLOOSE = R++;
  2156. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  2157. var XRANGE = R++;
  2158. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  2159. var XRANGELOOSE = R++;
  2160. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Tilde ranges.
  2161. // Meaning is "reasonably at or greater than"
  2162. var LONETILDE = R++;
  2163. src[LONETILDE] = '(?:~>?)';
  2164. var TILDETRIM = R++;
  2165. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  2166. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  2167. var tildeTrimReplace = '$1~';
  2168. var TILDE = R++;
  2169. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  2170. var TILDELOOSE = R++;
  2171. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  2172. // Meaning is "at least and backwards compatible with"
  2173. var LONECARET = R++;
  2174. src[LONECARET] = '(?:\\^)';
  2175. var CARETTRIM = R++;
  2176. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  2177. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  2178. var caretTrimReplace = '$1^';
  2179. var CARET = R++;
  2180. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  2181. var CARETLOOSE = R++;
  2182. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  2183. var COMPARATORLOOSE = R++;
  2184. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  2185. var COMPARATOR = R++;
  2186. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  2187. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  2188. var COMPARATORTRIM = R++;
  2189. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  2190. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  2191. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  2192. // Note that these all use the loose form, because they'll be
  2193. // checked against either the strict or loose comparator form
  2194. // later.
  2195. var HYPHENRANGE = R++;
  2196. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  2197. var HYPHENRANGELOOSE = R++;
  2198. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  2199. var STAR = R++;
  2200. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  2201. // All are flag-free, unless they were created above with a flag.
  2202. for (var i = 0; i < R; i++) {
  2203. debug(i, src[i]);
  2204. if (!re[i]) re[i] = new RegExp(src[i]);
  2205. }
  2206. exports.parse = parse;
  2207. function parse(version, loose) {
  2208. if (version instanceof SemVer) return version;
  2209. if (typeof version !== 'string') return null;
  2210. if (version.length > MAX_LENGTH) return null;
  2211. var r = loose ? re[LOOSE] : re[FULL];
  2212. if (!r.test(version)) return null;
  2213. try {
  2214. return new SemVer(version, loose);
  2215. } catch (er) {
  2216. return null;
  2217. }
  2218. }
  2219. exports.valid = valid;
  2220. function valid(version, loose) {
  2221. var v = parse(version, loose);
  2222. return v ? v.version : null;
  2223. }
  2224. exports.clean = clean;
  2225. function clean(version, loose) {
  2226. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  2227. return s ? s.version : null;
  2228. }
  2229. exports.SemVer = SemVer;
  2230. function SemVer(version, loose) {
  2231. if (version instanceof SemVer) {
  2232. if (version.loose === loose) return version;else version = version.version;
  2233. } else if (typeof version !== 'string') {
  2234. throw new TypeError('Invalid Version: ' + version);
  2235. }
  2236. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  2237. if (!(this instanceof SemVer)) return new SemVer(version, loose);
  2238. debug('SemVer', version, loose);
  2239. this.loose = loose;
  2240. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  2241. if (!m) throw new TypeError('Invalid Version: ' + version);
  2242. this.raw = version; // these are actually numbers
  2243. this.major = +m[1];
  2244. this.minor = +m[2];
  2245. this.patch = +m[3];
  2246. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  2247. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  2248. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  2249. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  2250. if (/^[0-9]+$/.test(id)) {
  2251. var num = +id;
  2252. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  2253. }
  2254. return id;
  2255. });
  2256. this.build = m[5] ? m[5].split('.') : [];
  2257. this.format();
  2258. }
  2259. SemVer.prototype.format = function () {
  2260. this.version = this.major + '.' + this.minor + '.' + this.patch;
  2261. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  2262. return this.version;
  2263. };
  2264. SemVer.prototype.toString = function () {
  2265. return this.version;
  2266. };
  2267. SemVer.prototype.compare = function (other) {
  2268. debug('SemVer.compare', this.version, this.loose, other);
  2269. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  2270. return this.compareMain(other) || this.comparePre(other);
  2271. };
  2272. SemVer.prototype.compareMain = function (other) {
  2273. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  2274. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  2275. };
  2276. SemVer.prototype.comparePre = function (other) {
  2277. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); // NOT having a prerelease is > having one
  2278. 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;
  2279. var i = 0;
  2280. do {
  2281. var a = this.prerelease[i];
  2282. var b = other.prerelease[i];
  2283. debug('prerelease compare', i, a, b);
  2284. 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);
  2285. } while (++i);
  2286. }; // preminor will bump the version up to the next minor release, and immediately
  2287. // down to pre-release. premajor and prepatch work the same way.
  2288. SemVer.prototype.inc = function (release, identifier) {
  2289. switch (release) {
  2290. case 'premajor':
  2291. this.prerelease.length = 0;
  2292. this.patch = 0;
  2293. this.minor = 0;
  2294. this.major++;
  2295. this.inc('pre', identifier);
  2296. break;
  2297. case 'preminor':
  2298. this.prerelease.length = 0;
  2299. this.patch = 0;
  2300. this.minor++;
  2301. this.inc('pre', identifier);
  2302. break;
  2303. case 'prepatch':
  2304. // If this is already a prerelease, it will bump to the next version
  2305. // drop any prereleases that might already exist, since they are not
  2306. // relevant at this point.
  2307. this.prerelease.length = 0;
  2308. this.inc('patch', identifier);
  2309. this.inc('pre', identifier);
  2310. break;
  2311. // If the input is a non-prerelease version, this acts the same as
  2312. // prepatch.
  2313. case 'prerelease':
  2314. if (this.prerelease.length === 0) this.inc('patch', identifier);
  2315. this.inc('pre', identifier);
  2316. break;
  2317. case 'major':
  2318. // If this is a pre-major version, bump up to the same major version.
  2319. // Otherwise increment major.
  2320. // 1.0.0-5 bumps to 1.0.0
  2321. // 1.1.0 bumps to 2.0.0
  2322. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  2323. this.minor = 0;
  2324. this.patch = 0;
  2325. this.prerelease = [];
  2326. break;
  2327. case 'minor':
  2328. // If this is a pre-minor version, bump up to the same minor version.
  2329. // Otherwise increment minor.
  2330. // 1.2.0-5 bumps to 1.2.0
  2331. // 1.2.1 bumps to 1.3.0
  2332. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  2333. this.patch = 0;
  2334. this.prerelease = [];
  2335. break;
  2336. case 'patch':
  2337. // If this is not a pre-release version, it will increment the patch.
  2338. // If it is a pre-release it will bump up to the same patch version.
  2339. // 1.2.0-5 patches to 1.2.0
  2340. // 1.2.0 patches to 1.2.1
  2341. if (this.prerelease.length === 0) this.patch++;
  2342. this.prerelease = [];
  2343. break;
  2344. // This probably shouldn't be used publicly.
  2345. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  2346. case 'pre':
  2347. if (this.prerelease.length === 0) this.prerelease = [0];else {
  2348. var i = this.prerelease.length;
  2349. while (--i >= 0) {
  2350. if (typeof this.prerelease[i] === 'number') {
  2351. this.prerelease[i]++;
  2352. i = -2;
  2353. }
  2354. }
  2355. if (i === -1) // didn't increment anything
  2356. this.prerelease.push(0);
  2357. }
  2358. if (identifier) {
  2359. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  2360. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  2361. if (this.prerelease[0] === identifier) {
  2362. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  2363. } else this.prerelease = [identifier, 0];
  2364. }
  2365. break;
  2366. default:
  2367. throw new Error('invalid increment argument: ' + release);
  2368. }
  2369. this.format();
  2370. this.raw = this.version;
  2371. return this;
  2372. };
  2373. exports.inc = inc;
  2374. function inc(version, release, loose, identifier) {
  2375. if (typeof loose === 'string') {
  2376. identifier = loose;
  2377. loose = undefined;
  2378. }
  2379. try {
  2380. return new SemVer(version, loose).inc(release, identifier).version;
  2381. } catch (er) {
  2382. return null;
  2383. }
  2384. }
  2385. exports.diff = diff;
  2386. function diff(version1, version2) {
  2387. if (eq(version1, version2)) {
  2388. return null;
  2389. } else {
  2390. var v1 = parse(version1);
  2391. var v2 = parse(version2);
  2392. if (v1.prerelease.length || v2.prerelease.length) {
  2393. for (var key in v1) {
  2394. if (key === 'major' || key === 'minor' || key === 'patch') {
  2395. if (v1[key] !== v2[key]) {
  2396. return 'pre' + key;
  2397. }
  2398. }
  2399. }
  2400. return 'prerelease';
  2401. }
  2402. for (var key in v1) {
  2403. if (key === 'major' || key === 'minor' || key === 'patch') {
  2404. if (v1[key] !== v2[key]) {
  2405. return key;
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. exports.compareIdentifiers = compareIdentifiers;
  2412. var numeric = /^[0-9]+$/;
  2413. function compareIdentifiers(a, b) {
  2414. var anum = numeric.test(a);
  2415. var bnum = numeric.test(b);
  2416. if (anum && bnum) {
  2417. a = +a;
  2418. b = +b;
  2419. }
  2420. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  2421. }
  2422. exports.rcompareIdentifiers = rcompareIdentifiers;
  2423. function rcompareIdentifiers(a, b) {
  2424. return compareIdentifiers(b, a);
  2425. }
  2426. exports.major = major;
  2427. function major(a, loose) {
  2428. return new SemVer(a, loose).major;
  2429. }
  2430. exports.minor = minor;
  2431. function minor(a, loose) {
  2432. return new SemVer(a, loose).minor;
  2433. }
  2434. exports.patch = patch;
  2435. function patch(a, loose) {
  2436. return new SemVer(a, loose).patch;
  2437. }
  2438. exports.compare = compare;
  2439. function compare(a, b, loose) {
  2440. return new SemVer(a, loose).compare(new SemVer(b, loose));
  2441. }
  2442. exports.compareLoose = compareLoose;
  2443. function compareLoose(a, b) {
  2444. return compare(a, b, true);
  2445. }
  2446. exports.rcompare = rcompare;
  2447. function rcompare(a, b, loose) {
  2448. return compare(b, a, loose);
  2449. }
  2450. exports.sort = sort;
  2451. function sort(list, loose) {
  2452. return list.sort(function (a, b) {
  2453. return exports.compare(a, b, loose);
  2454. });
  2455. }
  2456. exports.rsort = rsort;
  2457. function rsort(list, loose) {
  2458. return list.sort(function (a, b) {
  2459. return exports.rcompare(a, b, loose);
  2460. });
  2461. }
  2462. exports.gt = gt;
  2463. function gt(a, b, loose) {
  2464. return compare(a, b, loose) > 0;
  2465. }
  2466. exports.lt = lt;
  2467. function lt(a, b, loose) {
  2468. return compare(a, b, loose) < 0;
  2469. }
  2470. exports.eq = eq;
  2471. function eq(a, b, loose) {
  2472. return compare(a, b, loose) === 0;
  2473. }
  2474. exports.neq = neq;
  2475. function neq(a, b, loose) {
  2476. return compare(a, b, loose) !== 0;
  2477. }
  2478. exports.gte = gte;
  2479. function gte(a, b, loose) {
  2480. return compare(a, b, loose) >= 0;
  2481. }
  2482. exports.lte = lte;
  2483. function lte(a, b, loose) {
  2484. return compare(a, b, loose) <= 0;
  2485. }
  2486. exports.cmp = cmp;
  2487. function cmp(a, op, b, loose) {
  2488. var ret;
  2489. switch (op) {
  2490. case '===':
  2491. if (typeof a === 'object') a = a.version;
  2492. if (typeof b === 'object') b = b.version;
  2493. ret = a === b;
  2494. break;
  2495. case '!==':
  2496. if (typeof a === 'object') a = a.version;
  2497. if (typeof b === 'object') b = b.version;
  2498. ret = a !== b;
  2499. break;
  2500. case '':
  2501. case '=':
  2502. case '==':
  2503. ret = eq(a, b, loose);
  2504. break;
  2505. case '!=':
  2506. ret = neq(a, b, loose);
  2507. break;
  2508. case '>':
  2509. ret = gt(a, b, loose);
  2510. break;
  2511. case '>=':
  2512. ret = gte(a, b, loose);
  2513. break;
  2514. case '<':
  2515. ret = lt(a, b, loose);
  2516. break;
  2517. case '<=':
  2518. ret = lte(a, b, loose);
  2519. break;
  2520. default:
  2521. throw new TypeError('Invalid operator: ' + op);
  2522. }
  2523. return ret;
  2524. }
  2525. exports.Comparator = Comparator;
  2526. function Comparator(comp, loose) {
  2527. if (comp instanceof Comparator) {
  2528. if (comp.loose === loose) return comp;else comp = comp.value;
  2529. }
  2530. if (!(this instanceof Comparator)) return new Comparator(comp, loose);
  2531. debug('comparator', comp, loose);
  2532. this.loose = loose;
  2533. this.parse(comp);
  2534. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  2535. debug('comp', this);
  2536. }
  2537. var ANY = {};
  2538. Comparator.prototype.parse = function (comp) {
  2539. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2540. var m = comp.match(r);
  2541. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  2542. this.operator = m[1];
  2543. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  2544. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.loose);
  2545. };
  2546. Comparator.prototype.toString = function () {
  2547. return this.value;
  2548. };
  2549. Comparator.prototype.test = function (version) {
  2550. debug('Comparator.test', version, this.loose);
  2551. if (this.semver === ANY) return true;
  2552. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2553. return cmp(version, this.operator, this.semver, this.loose);
  2554. };
  2555. Comparator.prototype.intersects = function (comp, loose) {
  2556. if (!(comp instanceof Comparator)) {
  2557. throw new TypeError('a Comparator is required');
  2558. }
  2559. var rangeTmp;
  2560. if (this.operator === '') {
  2561. rangeTmp = new Range(comp.value, loose);
  2562. return satisfies(this.value, rangeTmp, loose);
  2563. } else if (comp.operator === '') {
  2564. rangeTmp = new Range(this.value, loose);
  2565. return satisfies(comp.semver, rangeTmp, loose);
  2566. }
  2567. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  2568. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  2569. var sameSemVer = this.semver.version === comp.semver.version;
  2570. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  2571. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, loose) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  2572. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, loose) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  2573. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  2574. };
  2575. exports.Range = Range;
  2576. function Range(range, loose) {
  2577. if (range instanceof Range) {
  2578. if (range.loose === loose) {
  2579. return range;
  2580. } else {
  2581. return new Range(range.raw, loose);
  2582. }
  2583. }
  2584. if (range instanceof Comparator) {
  2585. return new Range(range.value, loose);
  2586. }
  2587. if (!(this instanceof Range)) return new Range(range, loose);
  2588. this.loose = loose; // First, split based on boolean or ||
  2589. this.raw = range;
  2590. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  2591. return this.parseRange(range.trim());
  2592. }, this).filter(function (c) {
  2593. // throw out any that are not relevant for whatever reason
  2594. return c.length;
  2595. });
  2596. if (!this.set.length) {
  2597. throw new TypeError('Invalid SemVer Range: ' + range);
  2598. }
  2599. this.format();
  2600. }
  2601. Range.prototype.format = function () {
  2602. this.range = this.set.map(function (comps) {
  2603. return comps.join(' ').trim();
  2604. }).join('||').trim();
  2605. return this.range;
  2606. };
  2607. Range.prototype.toString = function () {
  2608. return this.range;
  2609. };
  2610. Range.prototype.parseRange = function (range) {
  2611. var loose = this.loose;
  2612. range = range.trim();
  2613. debug('range', range, loose); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  2614. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  2615. range = range.replace(hr, hyphenReplace);
  2616. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  2617. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  2618. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  2619. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  2620. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  2621. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  2622. // ready to be split into comparators.
  2623. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2624. var set = range.split(' ').map(function (comp) {
  2625. return parseComparator(comp, loose);
  2626. }).join(' ').split(/\s+/);
  2627. if (this.loose) {
  2628. // in loose mode, throw out any that are not valid comparators
  2629. set = set.filter(function (comp) {
  2630. return !!comp.match(compRe);
  2631. });
  2632. }
  2633. set = set.map(function (comp) {
  2634. return new Comparator(comp, loose);
  2635. });
  2636. return set;
  2637. };
  2638. Range.prototype.intersects = function (range, loose) {
  2639. if (!(range instanceof Range)) {
  2640. throw new TypeError('a Range is required');
  2641. }
  2642. return this.set.some(function (thisComparators) {
  2643. return thisComparators.every(function (thisComparator) {
  2644. return range.set.some(function (rangeComparators) {
  2645. return rangeComparators.every(function (rangeComparator) {
  2646. return thisComparator.intersects(rangeComparator, loose);
  2647. });
  2648. });
  2649. });
  2650. });
  2651. }; // Mostly just for testing and legacy API reasons
  2652. exports.toComparators = toComparators;
  2653. function toComparators(range, loose) {
  2654. return new Range(range, loose).set.map(function (comp) {
  2655. return comp.map(function (c) {
  2656. return c.value;
  2657. }).join(' ').trim().split(' ');
  2658. });
  2659. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  2660. // already replaced the hyphen ranges
  2661. // turn into a set of JUST comparators.
  2662. function parseComparator(comp, loose) {
  2663. debug('comp', comp);
  2664. comp = replaceCarets(comp, loose);
  2665. debug('caret', comp);
  2666. comp = replaceTildes(comp, loose);
  2667. debug('tildes', comp);
  2668. comp = replaceXRanges(comp, loose);
  2669. debug('xrange', comp);
  2670. comp = replaceStars(comp, loose);
  2671. debug('stars', comp);
  2672. return comp;
  2673. }
  2674. function isX(id) {
  2675. return !id || id.toLowerCase() === 'x' || id === '*';
  2676. } // ~, ~> --> * (any, kinda silly)
  2677. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  2678. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  2679. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  2680. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  2681. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  2682. function replaceTildes(comp, loose) {
  2683. return comp.trim().split(/\s+/).map(function (comp) {
  2684. return replaceTilde(comp, loose);
  2685. }).join(' ');
  2686. }
  2687. function replaceTilde(comp, loose) {
  2688. var r = loose ? re[TILDELOOSE] : re[TILDE];
  2689. return comp.replace(r, function (_, M, m, p, pr) {
  2690. debug('tilde', comp, _, M, m, p, pr);
  2691. var ret;
  2692. 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
  2693. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  2694. debug('replaceTilde pr', pr);
  2695. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2696. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2697. } else // ~1.2.3 == >=1.2.3 <1.3.0
  2698. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2699. debug('tilde return', ret);
  2700. return ret;
  2701. });
  2702. } // ^ --> * (any, kinda silly)
  2703. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  2704. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  2705. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  2706. // ^1.2.3 --> >=1.2.3 <2.0.0
  2707. // ^1.2.0 --> >=1.2.0 <2.0.0
  2708. function replaceCarets(comp, loose) {
  2709. return comp.trim().split(/\s+/).map(function (comp) {
  2710. return replaceCaret(comp, loose);
  2711. }).join(' ');
  2712. }
  2713. function replaceCaret(comp, loose) {
  2714. debug('caret', comp, loose);
  2715. var r = loose ? re[CARETLOOSE] : re[CARET];
  2716. return comp.replace(r, function (_, M, m, p, pr) {
  2717. debug('caret', comp, _, M, m, p, pr);
  2718. var ret;
  2719. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  2720. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  2721. } else if (pr) {
  2722. debug('replaceCaret pr', pr);
  2723. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2724. if (M === '0') {
  2725. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2726. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  2727. } else {
  2728. debug('no pr');
  2729. if (M === '0') {
  2730. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2731. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  2732. }
  2733. debug('caret return', ret);
  2734. return ret;
  2735. });
  2736. }
  2737. function replaceXRanges(comp, loose) {
  2738. debug('replaceXRanges', comp, loose);
  2739. return comp.split(/\s+/).map(function (comp) {
  2740. return replaceXRange(comp, loose);
  2741. }).join(' ');
  2742. }
  2743. function replaceXRange(comp, loose) {
  2744. comp = comp.trim();
  2745. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  2746. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  2747. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  2748. var xM = isX(M);
  2749. var xm = xM || isX(m);
  2750. var xp = xm || isX(p);
  2751. var anyX = xp;
  2752. if (gtlt === '=' && anyX) gtlt = '';
  2753. if (xM) {
  2754. if (gtlt === '>' || gtlt === '<') {
  2755. // nothing is allowed
  2756. ret = '<0.0.0';
  2757. } else {
  2758. // nothing is forbidden
  2759. ret = '*';
  2760. }
  2761. } else if (gtlt && anyX) {
  2762. // replace X with 0
  2763. if (xm) m = 0;
  2764. if (xp) p = 0;
  2765. if (gtlt === '>') {
  2766. // >1 => >=2.0.0
  2767. // >1.2 => >=1.3.0
  2768. // >1.2.3 => >= 1.2.4
  2769. gtlt = '>=';
  2770. if (xm) {
  2771. M = +M + 1;
  2772. m = 0;
  2773. p = 0;
  2774. } else if (xp) {
  2775. m = +m + 1;
  2776. p = 0;
  2777. }
  2778. } else if (gtlt === '<=') {
  2779. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  2780. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  2781. gtlt = '<';
  2782. if (xm) M = +M + 1;else m = +m + 1;
  2783. }
  2784. ret = gtlt + M + '.' + m + '.' + p;
  2785. } else if (xm) {
  2786. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2787. } else if (xp) {
  2788. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2789. }
  2790. debug('xRange return', ret);
  2791. return ret;
  2792. });
  2793. } // Because * is AND-ed with everything else in the comparator,
  2794. // and '' means "any version", just remove the *s entirely.
  2795. function replaceStars(comp, loose) {
  2796. debug('replaceStars', comp, loose); // Looseness is ignored here. star is always as loose as it gets!
  2797. return comp.trim().replace(re[STAR], '');
  2798. } // This function is passed to string.replace(re[HYPHENRANGE])
  2799. // M, m, patch, prerelease, build
  2800. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  2801. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  2802. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  2803. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  2804. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  2805. 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;
  2806. return (from + ' ' + to).trim();
  2807. } // if ANY of the sets match ALL of its comparators, then pass
  2808. Range.prototype.test = function (version) {
  2809. if (!version) return false;
  2810. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2811. for (var i = 0; i < this.set.length; i++) {
  2812. if (testSet(this.set[i], version)) return true;
  2813. }
  2814. return false;
  2815. };
  2816. function testSet(set, version) {
  2817. for (var i = 0; i < set.length; i++) {
  2818. if (!set[i].test(version)) return false;
  2819. }
  2820. if (version.prerelease.length) {
  2821. // Find the set of versions that are allowed to have prereleases
  2822. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  2823. // That should allow `1.2.3-pr.2` to pass.
  2824. // However, `1.2.4-alpha.notready` should NOT be allowed,
  2825. // even though it's within the range set by the comparators.
  2826. for (var i = 0; i < set.length; i++) {
  2827. debug(set[i].semver);
  2828. if (set[i].semver === ANY) continue;
  2829. if (set[i].semver.prerelease.length > 0) {
  2830. var allowed = set[i].semver;
  2831. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  2832. }
  2833. } // Version has a -pre, but it's not one of the ones we like.
  2834. return false;
  2835. }
  2836. return true;
  2837. }
  2838. exports.satisfies = satisfies;
  2839. function satisfies(version, range, loose) {
  2840. try {
  2841. range = new Range(range, loose);
  2842. } catch (er) {
  2843. return false;
  2844. }
  2845. return range.test(version);
  2846. }
  2847. exports.maxSatisfying = maxSatisfying;
  2848. function maxSatisfying(versions, range, loose) {
  2849. var max = null;
  2850. var maxSV = null;
  2851. try {
  2852. var rangeObj = new Range(range, loose);
  2853. } catch (er) {
  2854. return null;
  2855. }
  2856. versions.forEach(function (v) {
  2857. if (rangeObj.test(v)) {
  2858. // satisfies(v, range, loose)
  2859. if (!max || maxSV.compare(v) === -1) {
  2860. // compare(max, v, true)
  2861. max = v;
  2862. maxSV = new SemVer(max, loose);
  2863. }
  2864. }
  2865. });
  2866. return max;
  2867. }
  2868. exports.minSatisfying = minSatisfying;
  2869. function minSatisfying(versions, range, loose) {
  2870. var min = null;
  2871. var minSV = null;
  2872. try {
  2873. var rangeObj = new Range(range, loose);
  2874. } catch (er) {
  2875. return null;
  2876. }
  2877. versions.forEach(function (v) {
  2878. if (rangeObj.test(v)) {
  2879. // satisfies(v, range, loose)
  2880. if (!min || minSV.compare(v) === 1) {
  2881. // compare(min, v, true)
  2882. min = v;
  2883. minSV = new SemVer(min, loose);
  2884. }
  2885. }
  2886. });
  2887. return min;
  2888. }
  2889. exports.validRange = validRange;
  2890. function validRange(range, loose) {
  2891. try {
  2892. // Return '*' instead of '' so that truthiness works.
  2893. // This will throw if it's invalid anyway
  2894. return new Range(range, loose).range || '*';
  2895. } catch (er) {
  2896. return null;
  2897. }
  2898. } // Determine if version is less than all the versions possible in the range
  2899. exports.ltr = ltr;
  2900. function ltr(version, range, loose) {
  2901. return outside(version, range, '<', loose);
  2902. } // Determine if version is greater than all the versions possible in the range.
  2903. exports.gtr = gtr;
  2904. function gtr(version, range, loose) {
  2905. return outside(version, range, '>', loose);
  2906. }
  2907. exports.outside = outside;
  2908. function outside(version, range, hilo, loose) {
  2909. version = new SemVer(version, loose);
  2910. range = new Range(range, loose);
  2911. var gtfn, ltefn, ltfn, comp, ecomp;
  2912. switch (hilo) {
  2913. case '>':
  2914. gtfn = gt;
  2915. ltefn = lte;
  2916. ltfn = lt;
  2917. comp = '>';
  2918. ecomp = '>=';
  2919. break;
  2920. case '<':
  2921. gtfn = lt;
  2922. ltefn = gte;
  2923. ltfn = gt;
  2924. comp = '<';
  2925. ecomp = '<=';
  2926. break;
  2927. default:
  2928. throw new TypeError('Must provide a hilo val of "<" or ">"');
  2929. } // If it satisifes the range it is not outside
  2930. if (satisfies(version, range, loose)) {
  2931. return false;
  2932. } // From now on, variable terms are as if we're in "gtr" mode.
  2933. // but note that everything is flipped for the "ltr" function.
  2934. for (var i = 0; i < range.set.length; ++i) {
  2935. var comparators = range.set[i];
  2936. var high = null;
  2937. var low = null;
  2938. comparators.forEach(function (comparator) {
  2939. if (comparator.semver === ANY) {
  2940. comparator = new Comparator('>=0.0.0');
  2941. }
  2942. high = high || comparator;
  2943. low = low || comparator;
  2944. if (gtfn(comparator.semver, high.semver, loose)) {
  2945. high = comparator;
  2946. } else if (ltfn(comparator.semver, low.semver, loose)) {
  2947. low = comparator;
  2948. }
  2949. }); // If the edge version comparator has a operator then our version
  2950. // isn't outside it
  2951. if (high.operator === comp || high.operator === ecomp) {
  2952. return false;
  2953. } // If the lowest version comparator has an operator and our version
  2954. // is less than it then it isn't higher than the range
  2955. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  2956. return false;
  2957. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  2958. return false;
  2959. }
  2960. }
  2961. return true;
  2962. }
  2963. exports.prerelease = prerelease;
  2964. function prerelease(version, loose) {
  2965. var parsed = parse(version, loose);
  2966. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  2967. }
  2968. exports.intersects = intersects;
  2969. function intersects(r1, r2, loose) {
  2970. r1 = new Range(r1, loose);
  2971. r2 = new Range(r2, loose);
  2972. return r1.intersects(r2);
  2973. }
  2974. });
  2975. var arrayify = function arrayify(object, keyName) {
  2976. return Object.keys(object).reduce(function (array, key) {
  2977. return array.concat(Object.assign({
  2978. [keyName]: key
  2979. }, object[key]));
  2980. }, []);
  2981. };
  2982. var dedent_1 = createCommonjsModule(function (module) {
  2983. "use strict";
  2984. function dedent(strings) {
  2985. var raw = void 0;
  2986. if (typeof strings === "string") {
  2987. // dedent can be used as a plain function
  2988. raw = [strings];
  2989. } else {
  2990. raw = strings.raw;
  2991. } // first, perform interpolation
  2992. var result = "";
  2993. for (var i = 0; i < raw.length; i++) {
  2994. result += raw[i]. // join lines when there is a suppressed newline
  2995. replace(/\\\n[ \t]*/g, ""). // handle escaped backticks
  2996. replace(/\\`/g, "`");
  2997. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  2998. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  2999. }
  3000. } // now strip indentation
  3001. var lines = result.split("\n");
  3002. var mindent = null;
  3003. lines.forEach(function (l) {
  3004. var m = l.match(/^(\s+)\S+/);
  3005. if (m) {
  3006. var indent = m[1].length;
  3007. if (!mindent) {
  3008. // this is the first indented line
  3009. mindent = indent;
  3010. } else {
  3011. mindent = Math.min(mindent, indent);
  3012. }
  3013. }
  3014. });
  3015. if (mindent !== null) {
  3016. result = lines.map(function (l) {
  3017. return l[0] === " " ? l.slice(mindent) : l;
  3018. }).join("\n");
  3019. } // dedent eats leading and trailing whitespace too
  3020. result = result.trim(); // handle escaped newlines at the end to ensure they don't get stripped too
  3021. return result.replace(/\\n/g, "\n");
  3022. }
  3023. {
  3024. module.exports = dedent;
  3025. }
  3026. });
  3027. var CATEGORY_CONFIG = "Config";
  3028. var CATEGORY_EDITOR = "Editor";
  3029. var CATEGORY_FORMAT = "Format";
  3030. var CATEGORY_OTHER = "Other";
  3031. var CATEGORY_OUTPUT = "Output";
  3032. var CATEGORY_GLOBAL = "Global";
  3033. var CATEGORY_SPECIAL = "Special";
  3034. /**
  3035. * @typedef {Object} OptionInfo
  3036. * @property {string} since - available since version
  3037. * @property {string} category
  3038. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  3039. * @property {boolean} array - indicate it's an array of the specified type
  3040. * @property {boolean?} deprecated - deprecated since version
  3041. * @property {OptionRedirectInfo?} redirect - redirect deprecated option
  3042. * @property {string} description
  3043. * @property {string?} oppositeDescription - for `false` option
  3044. * @property {OptionValueInfo} default
  3045. * @property {OptionRangeInfo?} range - for type int
  3046. * @property {OptionChoiceInfo?} choices - for type choice
  3047. * @property {(value: any) => boolean} exception
  3048. *
  3049. * @typedef {number | boolean | string} OptionValue
  3050. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  3051. *
  3052. * @typedef {Object} OptionRedirectInfo
  3053. * @property {string} option
  3054. * @property {OptionValue} value
  3055. *
  3056. * @typedef {Object} OptionRangeInfo
  3057. * @property {number} start - recommended range start
  3058. * @property {number} end - recommended range end
  3059. * @property {number} step - recommended range step
  3060. *
  3061. * @typedef {Object} OptionChoiceInfo
  3062. * @property {boolean | string} value - boolean for the option that is originally boolean type
  3063. * @property {string?} description - undefined if redirect
  3064. * @property {string?} since - undefined if available since the first version of the option
  3065. * @property {string?} deprecated - deprecated since version
  3066. * @property {OptionValueInfo?} redirect - redirect deprecated value
  3067. *
  3068. * @property {string?} cliName
  3069. * @property {string?} cliCategory
  3070. * @property {string?} cliDescription
  3071. */
  3072. /** @type {{ [name: string]: OptionInfo } */
  3073. var options$2 = {
  3074. cursorOffset: {
  3075. since: "1.4.0",
  3076. category: CATEGORY_SPECIAL,
  3077. type: "int",
  3078. default: -1,
  3079. range: {
  3080. start: -1,
  3081. end: Infinity,
  3082. step: 1
  3083. },
  3084. description: dedent_1`
  3085. Print (to stderr) where a cursor at the given position would move to after formatting.
  3086. This option cannot be used with --range-start and --range-end.
  3087. `,
  3088. cliCategory: CATEGORY_EDITOR
  3089. },
  3090. endOfLine: {
  3091. since: "1.15.0",
  3092. category: CATEGORY_GLOBAL,
  3093. type: "choice",
  3094. default: "auto",
  3095. description: "Which end of line characters to apply.",
  3096. choices: [{
  3097. value: "auto",
  3098. description: dedent_1`
  3099. Maintain existing
  3100. (mixed values within one file are normalised by looking at what's used after the first line)
  3101. `
  3102. }, {
  3103. value: "lf",
  3104. description: "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
  3105. }, {
  3106. value: "crlf",
  3107. description: "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
  3108. }, {
  3109. value: "cr",
  3110. description: "Carriage Return character only (\\r), used very rarely"
  3111. }]
  3112. },
  3113. filepath: {
  3114. since: "1.4.0",
  3115. category: CATEGORY_SPECIAL,
  3116. type: "path",
  3117. description: "Specify the input filepath. This will be used to do parser inference.",
  3118. cliName: "stdin-filepath",
  3119. cliCategory: CATEGORY_OTHER,
  3120. cliDescription: "Path to the file to pretend that stdin comes from."
  3121. },
  3122. insertPragma: {
  3123. since: "1.8.0",
  3124. category: CATEGORY_SPECIAL,
  3125. type: "boolean",
  3126. default: false,
  3127. description: "Insert @format pragma into file's first docblock comment.",
  3128. cliCategory: CATEGORY_OTHER
  3129. },
  3130. parser: {
  3131. since: "0.0.10",
  3132. category: CATEGORY_GLOBAL,
  3133. type: "choice",
  3134. default: [{
  3135. since: "0.0.10",
  3136. value: "babylon"
  3137. }, {
  3138. since: "1.13.0",
  3139. value: undefined
  3140. }],
  3141. description: "Which parser to use.",
  3142. exception: function exception(value) {
  3143. return typeof value === "string" || typeof value === "function";
  3144. },
  3145. choices: [{
  3146. value: "flow",
  3147. description: "Flow"
  3148. }, {
  3149. value: "babylon",
  3150. description: "JavaScript",
  3151. deprecated: "1.16.0",
  3152. redirect: "babel"
  3153. }, {
  3154. value: "babel",
  3155. since: "1.16.0",
  3156. description: "JavaScript"
  3157. }, {
  3158. value: "babel-flow",
  3159. since: "1.16.0",
  3160. description: "Flow"
  3161. }, {
  3162. value: "typescript",
  3163. since: "1.4.0",
  3164. description: "TypeScript"
  3165. }, {
  3166. value: "css",
  3167. since: "1.7.1",
  3168. description: "CSS"
  3169. }, {
  3170. value: "postcss",
  3171. since: "1.4.0",
  3172. description: "CSS/Less/SCSS",
  3173. deprecated: "1.7.1",
  3174. redirect: "css"
  3175. }, {
  3176. value: "less",
  3177. since: "1.7.1",
  3178. description: "Less"
  3179. }, {
  3180. value: "scss",
  3181. since: "1.7.1",
  3182. description: "SCSS"
  3183. }, {
  3184. value: "json",
  3185. since: "1.5.0",
  3186. description: "JSON"
  3187. }, {
  3188. value: "json5",
  3189. since: "1.13.0",
  3190. description: "JSON5"
  3191. }, {
  3192. value: "json-stringify",
  3193. since: "1.13.0",
  3194. description: "JSON.stringify"
  3195. }, {
  3196. value: "graphql",
  3197. since: "1.5.0",
  3198. description: "GraphQL"
  3199. }, {
  3200. value: "markdown",
  3201. since: "1.8.0",
  3202. description: "Markdown"
  3203. }, {
  3204. value: "mdx",
  3205. since: "1.15.0",
  3206. description: "MDX"
  3207. }, {
  3208. value: "vue",
  3209. since: "1.10.0",
  3210. description: "Vue"
  3211. }, {
  3212. value: "yaml",
  3213. since: "1.14.0",
  3214. description: "YAML"
  3215. }, {
  3216. value: "glimmer",
  3217. since: null,
  3218. description: "Handlebars"
  3219. }, {
  3220. value: "html",
  3221. since: "1.15.0",
  3222. description: "HTML"
  3223. }, {
  3224. value: "angular",
  3225. since: "1.15.0",
  3226. description: "Angular"
  3227. }]
  3228. },
  3229. plugins: {
  3230. since: "1.10.0",
  3231. type: "path",
  3232. array: true,
  3233. default: [{
  3234. value: []
  3235. }],
  3236. category: CATEGORY_GLOBAL,
  3237. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  3238. exception: function exception(value) {
  3239. return typeof value === "string" || typeof value === "object";
  3240. },
  3241. cliName: "plugin",
  3242. cliCategory: CATEGORY_CONFIG
  3243. },
  3244. pluginSearchDirs: {
  3245. since: "1.13.0",
  3246. type: "path",
  3247. array: true,
  3248. default: [{
  3249. value: []
  3250. }],
  3251. category: CATEGORY_GLOBAL,
  3252. description: dedent_1`
  3253. Custom directory that contains prettier plugins in node_modules subdirectory.
  3254. Overrides default behavior when plugins are searched relatively to the location of Prettier.
  3255. Multiple values are accepted.
  3256. `,
  3257. exception: function exception(value) {
  3258. return typeof value === "string" || typeof value === "object";
  3259. },
  3260. cliName: "plugin-search-dir",
  3261. cliCategory: CATEGORY_CONFIG
  3262. },
  3263. printWidth: {
  3264. since: "0.0.0",
  3265. category: CATEGORY_GLOBAL,
  3266. type: "int",
  3267. default: 80,
  3268. description: "The line length where Prettier will try wrap.",
  3269. range: {
  3270. start: 0,
  3271. end: Infinity,
  3272. step: 1
  3273. }
  3274. },
  3275. rangeEnd: {
  3276. since: "1.4.0",
  3277. category: CATEGORY_SPECIAL,
  3278. type: "int",
  3279. default: Infinity,
  3280. range: {
  3281. start: 0,
  3282. end: Infinity,
  3283. step: 1
  3284. },
  3285. description: dedent_1`
  3286. Format code ending at a given character offset (exclusive).
  3287. The range will extend forwards to the end of the selected statement.
  3288. This option cannot be used with --cursor-offset.
  3289. `,
  3290. cliCategory: CATEGORY_EDITOR
  3291. },
  3292. rangeStart: {
  3293. since: "1.4.0",
  3294. category: CATEGORY_SPECIAL,
  3295. type: "int",
  3296. default: 0,
  3297. range: {
  3298. start: 0,
  3299. end: Infinity,
  3300. step: 1
  3301. },
  3302. description: dedent_1`
  3303. Format code starting at a given character offset.
  3304. The range will extend backwards to the start of the first line containing the selected statement.
  3305. This option cannot be used with --cursor-offset.
  3306. `,
  3307. cliCategory: CATEGORY_EDITOR
  3308. },
  3309. requirePragma: {
  3310. since: "1.7.0",
  3311. category: CATEGORY_SPECIAL,
  3312. type: "boolean",
  3313. default: false,
  3314. description: dedent_1`
  3315. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  3316. in order for it to be formatted.
  3317. `,
  3318. cliCategory: CATEGORY_OTHER
  3319. },
  3320. tabWidth: {
  3321. type: "int",
  3322. category: CATEGORY_GLOBAL,
  3323. default: 2,
  3324. description: "Number of spaces per indentation level.",
  3325. range: {
  3326. start: 0,
  3327. end: Infinity,
  3328. step: 1
  3329. }
  3330. },
  3331. useFlowParser: {
  3332. since: "0.0.0",
  3333. category: CATEGORY_GLOBAL,
  3334. type: "boolean",
  3335. default: [{
  3336. since: "0.0.0",
  3337. value: false
  3338. }, {
  3339. since: "1.15.0",
  3340. value: undefined
  3341. }],
  3342. deprecated: "0.0.10",
  3343. description: "Use flow parser.",
  3344. redirect: {
  3345. option: "parser",
  3346. value: "flow"
  3347. },
  3348. cliName: "flow-parser"
  3349. },
  3350. useTabs: {
  3351. since: "1.0.0",
  3352. category: CATEGORY_GLOBAL,
  3353. type: "boolean",
  3354. default: false,
  3355. description: "Indent with tabs instead of spaces."
  3356. }
  3357. };
  3358. var coreOptions$1 = {
  3359. CATEGORY_CONFIG,
  3360. CATEGORY_EDITOR,
  3361. CATEGORY_FORMAT,
  3362. CATEGORY_OTHER,
  3363. CATEGORY_OUTPUT,
  3364. CATEGORY_GLOBAL,
  3365. CATEGORY_SPECIAL,
  3366. options: options$2
  3367. };
  3368. var require$$0 = ( _package$1 && _package ) || _package$1;
  3369. var currentVersion = require$$0.version;
  3370. var coreOptions = coreOptions$1.options;
  3371. function getSupportInfo$2(version, opts) {
  3372. opts = Object.assign({
  3373. plugins: [],
  3374. showUnreleased: false,
  3375. showDeprecated: false,
  3376. showInternal: false
  3377. }, opts);
  3378. if (!version) {
  3379. // pre-release version is smaller than the normal version in semver,
  3380. // we need to treat it as the normal one so as to test new features.
  3381. version = currentVersion.split("-", 1)[0];
  3382. }
  3383. var plugins = opts.plugins;
  3384. var options = arrayify(Object.assign(plugins.reduce(function (currentOptions, plugin) {
  3385. return Object.assign(currentOptions, plugin.options);
  3386. }, {}), coreOptions), "name").sort(function (a, b) {
  3387. return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
  3388. }).filter(filterSince).filter(filterDeprecated).map(mapDeprecated).map(mapInternal).map(function (option) {
  3389. var newOption = Object.assign({}, option);
  3390. if (Array.isArray(newOption.default)) {
  3391. newOption.default = newOption.default.length === 1 ? newOption.default[0].value : newOption.default.filter(filterSince).sort(function (info1, info2) {
  3392. return semver.compare(info2.since, info1.since);
  3393. })[0].value;
  3394. }
  3395. if (Array.isArray(newOption.choices)) {
  3396. newOption.choices = newOption.choices.filter(filterSince).filter(filterDeprecated).map(mapDeprecated);
  3397. }
  3398. return newOption;
  3399. }).map(function (option) {
  3400. var filteredPlugins = plugins.filter(function (plugin) {
  3401. return plugin.defaultOptions && plugin.defaultOptions[option.name];
  3402. });
  3403. var pluginDefaults = filteredPlugins.reduce(function (reduced, plugin) {
  3404. reduced[plugin.name] = plugin.defaultOptions[option.name];
  3405. return reduced;
  3406. }, {});
  3407. return Object.assign(option, {
  3408. pluginDefaults
  3409. });
  3410. });
  3411. var usePostCssParser = semver.lt(version, "1.7.1");
  3412. var languages = plugins.reduce(function (all, plugin) {
  3413. return all.concat(plugin.languages || []);
  3414. }, []).filter(filterSince).map(function (language) {
  3415. // Prevent breaking changes
  3416. if (language.name === "Markdown") {
  3417. return Object.assign({}, language, {
  3418. parsers: ["markdown"]
  3419. });
  3420. }
  3421. if (language.name === "TypeScript") {
  3422. return Object.assign({}, language, {
  3423. parsers: ["typescript"]
  3424. });
  3425. }
  3426. if (usePostCssParser && (language.name === "CSS" || language.group === "CSS")) {
  3427. return Object.assign({}, language, {
  3428. parsers: ["postcss"]
  3429. });
  3430. }
  3431. return language;
  3432. });
  3433. return {
  3434. languages,
  3435. options
  3436. };
  3437. function filterSince(object) {
  3438. return opts.showUnreleased || !("since" in object) || object.since && semver.gte(version, object.since);
  3439. }
  3440. function filterDeprecated(object) {
  3441. return opts.showDeprecated || !("deprecated" in object) || object.deprecated && semver.lt(version, object.deprecated);
  3442. }
  3443. function mapDeprecated(object) {
  3444. if (!object.deprecated || opts.showDeprecated) {
  3445. return object;
  3446. }
  3447. var newObject = Object.assign({}, object);
  3448. delete newObject.deprecated;
  3449. delete newObject.redirect;
  3450. return newObject;
  3451. }
  3452. function mapInternal(object) {
  3453. if (opts.showInternal) {
  3454. return object;
  3455. }
  3456. var newObject = Object.assign({}, object);
  3457. delete newObject.cliName;
  3458. delete newObject.cliCategory;
  3459. delete newObject.cliDescription;
  3460. return newObject;
  3461. }
  3462. }
  3463. var support = {
  3464. getSupportInfo: getSupportInfo$2
  3465. };
  3466. /*! *****************************************************************************
  3467. Copyright (c) Microsoft Corporation. All rights reserved.
  3468. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  3469. this file except in compliance with the License. You may obtain a copy of the
  3470. License at http://www.apache.org/licenses/LICENSE-2.0
  3471. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  3472. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  3473. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  3474. MERCHANTABLITY OR NON-INFRINGEMENT.
  3475. See the Apache Version 2.0 License for specific language governing permissions
  3476. and limitations under the License.
  3477. ***************************************************************************** */
  3478. /* global Reflect, Promise */
  3479. var _extendStatics = function extendStatics(d, b) {
  3480. _extendStatics = Object.setPrototypeOf || {
  3481. __proto__: []
  3482. } instanceof Array && function (d, b) {
  3483. d.__proto__ = b;
  3484. } || function (d, b) {
  3485. for (var p in b) {
  3486. if (b.hasOwnProperty(p)) d[p] = b[p];
  3487. }
  3488. };
  3489. return _extendStatics(d, b);
  3490. };
  3491. function __extends(d, b) {
  3492. _extendStatics(d, b);
  3493. function __() {
  3494. this.constructor = d;
  3495. }
  3496. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3497. }
  3498. var _assign = function __assign() {
  3499. _assign = Object.assign || function __assign(t) {
  3500. for (var s, i = 1, n = arguments.length; i < n; i++) {
  3501. s = arguments[i];
  3502. for (var p in s) {
  3503. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  3504. }
  3505. }
  3506. return t;
  3507. };
  3508. return _assign.apply(this, arguments);
  3509. };
  3510. function __rest(s, e) {
  3511. var t = {};
  3512. for (var p in s) {
  3513. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  3514. }
  3515. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  3516. if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
  3517. }
  3518. return t;
  3519. }
  3520. function __decorate(decorators, target, key, desc) {
  3521. var c = arguments.length,
  3522. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  3523. d;
  3524. 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--) {
  3525. if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  3526. }
  3527. return c > 3 && r && Object.defineProperty(target, key, r), r;
  3528. }
  3529. function __param(paramIndex, decorator) {
  3530. return function (target, key) {
  3531. decorator(target, key, paramIndex);
  3532. };
  3533. }
  3534. function __metadata(metadataKey, metadataValue) {
  3535. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  3536. }
  3537. function __awaiter(thisArg, _arguments, P, generator) {
  3538. return new (P || (P = Promise))(function (resolve, reject) {
  3539. function fulfilled(value) {
  3540. try {
  3541. step(generator.next(value));
  3542. } catch (e) {
  3543. reject(e);
  3544. }
  3545. }
  3546. function rejected(value) {
  3547. try {
  3548. step(generator["throw"](value));
  3549. } catch (e) {
  3550. reject(e);
  3551. }
  3552. }
  3553. function step(result) {
  3554. result.done ? resolve(result.value) : new P(function (resolve) {
  3555. resolve(result.value);
  3556. }).then(fulfilled, rejected);
  3557. }
  3558. step((generator = generator.apply(thisArg, _arguments || [])).next());
  3559. });
  3560. }
  3561. function __generator(thisArg, body) {
  3562. var _ = {
  3563. label: 0,
  3564. sent: function sent() {
  3565. if (t[0] & 1) throw t[1];
  3566. return t[1];
  3567. },
  3568. trys: [],
  3569. ops: []
  3570. },
  3571. f,
  3572. y,
  3573. t,
  3574. g;
  3575. return g = {
  3576. next: verb(0),
  3577. "throw": verb(1),
  3578. "return": verb(2)
  3579. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  3580. return this;
  3581. }), g;
  3582. function verb(n) {
  3583. return function (v) {
  3584. return step([n, v]);
  3585. };
  3586. }
  3587. function step(op) {
  3588. if (f) throw new TypeError("Generator is already executing.");
  3589. while (_) {
  3590. try {
  3591. 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;
  3592. if (y = 0, t) op = [op[0] & 2, t.value];
  3593. switch (op[0]) {
  3594. case 0:
  3595. case 1:
  3596. t = op;
  3597. break;
  3598. case 4:
  3599. _.label++;
  3600. return {
  3601. value: op[1],
  3602. done: false
  3603. };
  3604. case 5:
  3605. _.label++;
  3606. y = op[1];
  3607. op = [0];
  3608. continue;
  3609. case 7:
  3610. op = _.ops.pop();
  3611. _.trys.pop();
  3612. continue;
  3613. default:
  3614. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  3615. _ = 0;
  3616. continue;
  3617. }
  3618. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  3619. _.label = op[1];
  3620. break;
  3621. }
  3622. if (op[0] === 6 && _.label < t[1]) {
  3623. _.label = t[1];
  3624. t = op;
  3625. break;
  3626. }
  3627. if (t && _.label < t[2]) {
  3628. _.label = t[2];
  3629. _.ops.push(op);
  3630. break;
  3631. }
  3632. if (t[2]) _.ops.pop();
  3633. _.trys.pop();
  3634. continue;
  3635. }
  3636. op = body.call(thisArg, _);
  3637. } catch (e) {
  3638. op = [6, e];
  3639. y = 0;
  3640. } finally {
  3641. f = t = 0;
  3642. }
  3643. }
  3644. if (op[0] & 5) throw op[1];
  3645. return {
  3646. value: op[0] ? op[1] : void 0,
  3647. done: true
  3648. };
  3649. }
  3650. }
  3651. function __exportStar(m, exports) {
  3652. for (var p in m) {
  3653. if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  3654. }
  3655. }
  3656. function __values(o) {
  3657. var m = typeof Symbol === "function" && o[Symbol.iterator],
  3658. i = 0;
  3659. if (m) return m.call(o);
  3660. return {
  3661. next: function next() {
  3662. if (o && i >= o.length) o = void 0;
  3663. return {
  3664. value: o && o[i++],
  3665. done: !o
  3666. };
  3667. }
  3668. };
  3669. }
  3670. function __read(o, n) {
  3671. var m = typeof Symbol === "function" && o[Symbol.iterator];
  3672. if (!m) return o;
  3673. var i = m.call(o),
  3674. r,
  3675. ar = [],
  3676. e;
  3677. try {
  3678. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
  3679. ar.push(r.value);
  3680. }
  3681. } catch (error) {
  3682. e = {
  3683. error: error
  3684. };
  3685. } finally {
  3686. try {
  3687. if (r && !r.done && (m = i["return"])) m.call(i);
  3688. } finally {
  3689. if (e) throw e.error;
  3690. }
  3691. }
  3692. return ar;
  3693. }
  3694. function __spread() {
  3695. for (var ar = [], i = 0; i < arguments.length; i++) {
  3696. ar = ar.concat(__read(arguments[i]));
  3697. }
  3698. return ar;
  3699. }
  3700. function __await(v) {
  3701. return this instanceof __await ? (this.v = v, this) : new __await(v);
  3702. }
  3703. function __asyncGenerator(thisArg, _arguments, generator) {
  3704. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  3705. var g = generator.apply(thisArg, _arguments || []),
  3706. i,
  3707. q = [];
  3708. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  3709. return this;
  3710. }, i;
  3711. function verb(n) {
  3712. if (g[n]) i[n] = function (v) {
  3713. return new Promise(function (a, b) {
  3714. q.push([n, v, a, b]) > 1 || resume(n, v);
  3715. });
  3716. };
  3717. }
  3718. function resume(n, v) {
  3719. try {
  3720. step(g[n](v));
  3721. } catch (e) {
  3722. settle(q[0][3], e);
  3723. }
  3724. }
  3725. function step(r) {
  3726. r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
  3727. }
  3728. function fulfill(value) {
  3729. resume("next", value);
  3730. }
  3731. function reject(value) {
  3732. resume("throw", value);
  3733. }
  3734. function settle(f, v) {
  3735. if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
  3736. }
  3737. }
  3738. function __asyncDelegator(o) {
  3739. var i, p;
  3740. return i = {}, verb("next"), verb("throw", function (e) {
  3741. throw e;
  3742. }), verb("return"), i[Symbol.iterator] = function () {
  3743. return this;
  3744. }, i;
  3745. function verb(n, f) {
  3746. i[n] = o[n] ? function (v) {
  3747. return (p = !p) ? {
  3748. value: __await(o[n](v)),
  3749. done: n === "return"
  3750. } : f ? f(v) : v;
  3751. } : f;
  3752. }
  3753. }
  3754. function __asyncValues(o) {
  3755. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  3756. var m = o[Symbol.asyncIterator],
  3757. i;
  3758. 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 () {
  3759. return this;
  3760. }, i);
  3761. function verb(n) {
  3762. i[n] = o[n] && function (v) {
  3763. return new Promise(function (resolve, reject) {
  3764. v = o[n](v), settle(resolve, reject, v.done, v.value);
  3765. });
  3766. };
  3767. }
  3768. function settle(resolve, reject, d, v) {
  3769. Promise.resolve(v).then(function (v) {
  3770. resolve({
  3771. value: v,
  3772. done: d
  3773. });
  3774. }, reject);
  3775. }
  3776. }
  3777. function __makeTemplateObject(cooked, raw) {
  3778. if (Object.defineProperty) {
  3779. Object.defineProperty(cooked, "raw", {
  3780. value: raw
  3781. });
  3782. } else {
  3783. cooked.raw = raw;
  3784. }
  3785. return cooked;
  3786. }
  3787. function __importStar(mod) {
  3788. if (mod && mod.__esModule) return mod;
  3789. var result = {};
  3790. if (mod != null) for (var k in mod) {
  3791. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  3792. }
  3793. result.default = mod;
  3794. return result;
  3795. }
  3796. function __importDefault(mod) {
  3797. return mod && mod.__esModule ? mod : {
  3798. default: mod
  3799. };
  3800. }
  3801. var tslib_1 = Object.freeze({
  3802. __extends: __extends,
  3803. get __assign () { return _assign; },
  3804. __rest: __rest,
  3805. __decorate: __decorate,
  3806. __param: __param,
  3807. __metadata: __metadata,
  3808. __awaiter: __awaiter,
  3809. __generator: __generator,
  3810. __exportStar: __exportStar,
  3811. __values: __values,
  3812. __read: __read,
  3813. __spread: __spread,
  3814. __await: __await,
  3815. __asyncGenerator: __asyncGenerator,
  3816. __asyncDelegator: __asyncDelegator,
  3817. __asyncValues: __asyncValues,
  3818. __makeTemplateObject: __makeTemplateObject,
  3819. __importStar: __importStar,
  3820. __importDefault: __importDefault
  3821. });
  3822. var api = createCommonjsModule(function (module, exports) {
  3823. "use strict";
  3824. Object.defineProperty(exports, "__esModule", {
  3825. value: true
  3826. });
  3827. exports.apiDescriptor = {
  3828. key: function key(_key) {
  3829. return /^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(_key) ? _key : JSON.stringify(_key);
  3830. },
  3831. value(value) {
  3832. if (value === null || typeof value !== 'object') {
  3833. return JSON.stringify(value);
  3834. }
  3835. if (Array.isArray(value)) {
  3836. return `[${value.map(function (subValue) {
  3837. return exports.apiDescriptor.value(subValue);
  3838. }).join(', ')}]`;
  3839. }
  3840. var keys = Object.keys(value);
  3841. return keys.length === 0 ? '{}' : `{ ${keys.map(function (key) {
  3842. return `${exports.apiDescriptor.key(key)}: ${exports.apiDescriptor.value(value[key])}`;
  3843. }).join(', ')} }`;
  3844. },
  3845. pair: function pair(_ref) {
  3846. var key = _ref.key,
  3847. value = _ref.value;
  3848. return exports.apiDescriptor.value({
  3849. [key]: value
  3850. });
  3851. }
  3852. };
  3853. });
  3854. unwrapExports(api);
  3855. var descriptors = createCommonjsModule(function (module, exports) {
  3856. "use strict";
  3857. Object.defineProperty(exports, "__esModule", {
  3858. value: true
  3859. });
  3860. tslib_1.__exportStar(api, exports);
  3861. });
  3862. unwrapExports(descriptors);
  3863. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  3864. var escapeStringRegexp = function escapeStringRegexp(str) {
  3865. if (typeof str !== 'string') {
  3866. throw new TypeError('Expected a string');
  3867. }
  3868. return str.replace(matchOperatorsRe, '\\$&');
  3869. };
  3870. var colorName = {
  3871. "aliceblue": [240, 248, 255],
  3872. "antiquewhite": [250, 235, 215],
  3873. "aqua": [0, 255, 255],
  3874. "aquamarine": [127, 255, 212],
  3875. "azure": [240, 255, 255],
  3876. "beige": [245, 245, 220],
  3877. "bisque": [255, 228, 196],
  3878. "black": [0, 0, 0],
  3879. "blanchedalmond": [255, 235, 205],
  3880. "blue": [0, 0, 255],
  3881. "blueviolet": [138, 43, 226],
  3882. "brown": [165, 42, 42],
  3883. "burlywood": [222, 184, 135],
  3884. "cadetblue": [95, 158, 160],
  3885. "chartreuse": [127, 255, 0],
  3886. "chocolate": [210, 105, 30],
  3887. "coral": [255, 127, 80],
  3888. "cornflowerblue": [100, 149, 237],
  3889. "cornsilk": [255, 248, 220],
  3890. "crimson": [220, 20, 60],
  3891. "cyan": [0, 255, 255],
  3892. "darkblue": [0, 0, 139],
  3893. "darkcyan": [0, 139, 139],
  3894. "darkgoldenrod": [184, 134, 11],
  3895. "darkgray": [169, 169, 169],
  3896. "darkgreen": [0, 100, 0],
  3897. "darkgrey": [169, 169, 169],
  3898. "darkkhaki": [189, 183, 107],
  3899. "darkmagenta": [139, 0, 139],
  3900. "darkolivegreen": [85, 107, 47],
  3901. "darkorange": [255, 140, 0],
  3902. "darkorchid": [153, 50, 204],
  3903. "darkred": [139, 0, 0],
  3904. "darksalmon": [233, 150, 122],
  3905. "darkseagreen": [143, 188, 143],
  3906. "darkslateblue": [72, 61, 139],
  3907. "darkslategray": [47, 79, 79],
  3908. "darkslategrey": [47, 79, 79],
  3909. "darkturquoise": [0, 206, 209],
  3910. "darkviolet": [148, 0, 211],
  3911. "deeppink": [255, 20, 147],
  3912. "deepskyblue": [0, 191, 255],
  3913. "dimgray": [105, 105, 105],
  3914. "dimgrey": [105, 105, 105],
  3915. "dodgerblue": [30, 144, 255],
  3916. "firebrick": [178, 34, 34],
  3917. "floralwhite": [255, 250, 240],
  3918. "forestgreen": [34, 139, 34],
  3919. "fuchsia": [255, 0, 255],
  3920. "gainsboro": [220, 220, 220],
  3921. "ghostwhite": [248, 248, 255],
  3922. "gold": [255, 215, 0],
  3923. "goldenrod": [218, 165, 32],
  3924. "gray": [128, 128, 128],
  3925. "green": [0, 128, 0],
  3926. "greenyellow": [173, 255, 47],
  3927. "grey": [128, 128, 128],
  3928. "honeydew": [240, 255, 240],
  3929. "hotpink": [255, 105, 180],
  3930. "indianred": [205, 92, 92],
  3931. "indigo": [75, 0, 130],
  3932. "ivory": [255, 255, 240],
  3933. "khaki": [240, 230, 140],
  3934. "lavender": [230, 230, 250],
  3935. "lavenderblush": [255, 240, 245],
  3936. "lawngreen": [124, 252, 0],
  3937. "lemonchiffon": [255, 250, 205],
  3938. "lightblue": [173, 216, 230],
  3939. "lightcoral": [240, 128, 128],
  3940. "lightcyan": [224, 255, 255],
  3941. "lightgoldenrodyellow": [250, 250, 210],
  3942. "lightgray": [211, 211, 211],
  3943. "lightgreen": [144, 238, 144],
  3944. "lightgrey": [211, 211, 211],
  3945. "lightpink": [255, 182, 193],
  3946. "lightsalmon": [255, 160, 122],
  3947. "lightseagreen": [32, 178, 170],
  3948. "lightskyblue": [135, 206, 250],
  3949. "lightslategray": [119, 136, 153],
  3950. "lightslategrey": [119, 136, 153],
  3951. "lightsteelblue": [176, 196, 222],
  3952. "lightyellow": [255, 255, 224],
  3953. "lime": [0, 255, 0],
  3954. "limegreen": [50, 205, 50],
  3955. "linen": [250, 240, 230],
  3956. "magenta": [255, 0, 255],
  3957. "maroon": [128, 0, 0],
  3958. "mediumaquamarine": [102, 205, 170],
  3959. "mediumblue": [0, 0, 205],
  3960. "mediumorchid": [186, 85, 211],
  3961. "mediumpurple": [147, 112, 219],
  3962. "mediumseagreen": [60, 179, 113],
  3963. "mediumslateblue": [123, 104, 238],
  3964. "mediumspringgreen": [0, 250, 154],
  3965. "mediumturquoise": [72, 209, 204],
  3966. "mediumvioletred": [199, 21, 133],
  3967. "midnightblue": [25, 25, 112],
  3968. "mintcream": [245, 255, 250],
  3969. "mistyrose": [255, 228, 225],
  3970. "moccasin": [255, 228, 181],
  3971. "navajowhite": [255, 222, 173],
  3972. "navy": [0, 0, 128],
  3973. "oldlace": [253, 245, 230],
  3974. "olive": [128, 128, 0],
  3975. "olivedrab": [107, 142, 35],
  3976. "orange": [255, 165, 0],
  3977. "orangered": [255, 69, 0],
  3978. "orchid": [218, 112, 214],
  3979. "palegoldenrod": [238, 232, 170],
  3980. "palegreen": [152, 251, 152],
  3981. "paleturquoise": [175, 238, 238],
  3982. "palevioletred": [219, 112, 147],
  3983. "papayawhip": [255, 239, 213],
  3984. "peachpuff": [255, 218, 185],
  3985. "peru": [205, 133, 63],
  3986. "pink": [255, 192, 203],
  3987. "plum": [221, 160, 221],
  3988. "powderblue": [176, 224, 230],
  3989. "purple": [128, 0, 128],
  3990. "rebeccapurple": [102, 51, 153],
  3991. "red": [255, 0, 0],
  3992. "rosybrown": [188, 143, 143],
  3993. "royalblue": [65, 105, 225],
  3994. "saddlebrown": [139, 69, 19],
  3995. "salmon": [250, 128, 114],
  3996. "sandybrown": [244, 164, 96],
  3997. "seagreen": [46, 139, 87],
  3998. "seashell": [255, 245, 238],
  3999. "sienna": [160, 82, 45],
  4000. "silver": [192, 192, 192],
  4001. "skyblue": [135, 206, 235],
  4002. "slateblue": [106, 90, 205],
  4003. "slategray": [112, 128, 144],
  4004. "slategrey": [112, 128, 144],
  4005. "snow": [255, 250, 250],
  4006. "springgreen": [0, 255, 127],
  4007. "steelblue": [70, 130, 180],
  4008. "tan": [210, 180, 140],
  4009. "teal": [0, 128, 128],
  4010. "thistle": [216, 191, 216],
  4011. "tomato": [255, 99, 71],
  4012. "turquoise": [64, 224, 208],
  4013. "violet": [238, 130, 238],
  4014. "wheat": [245, 222, 179],
  4015. "white": [255, 255, 255],
  4016. "whitesmoke": [245, 245, 245],
  4017. "yellow": [255, 255, 0],
  4018. "yellowgreen": [154, 205, 50]
  4019. };
  4020. var conversions = createCommonjsModule(function (module) {
  4021. /* MIT license */
  4022. // NOTE: conversions should only return primitive values (i.e. arrays, or
  4023. // values that give correct `typeof` results).
  4024. // do not use box values types (i.e. Number(), String(), etc.)
  4025. var reverseKeywords = {};
  4026. for (var key in colorName) {
  4027. if (colorName.hasOwnProperty(key)) {
  4028. reverseKeywords[colorName[key]] = key;
  4029. }
  4030. }
  4031. var convert = module.exports = {
  4032. rgb: {
  4033. channels: 3,
  4034. labels: 'rgb'
  4035. },
  4036. hsl: {
  4037. channels: 3,
  4038. labels: 'hsl'
  4039. },
  4040. hsv: {
  4041. channels: 3,
  4042. labels: 'hsv'
  4043. },
  4044. hwb: {
  4045. channels: 3,
  4046. labels: 'hwb'
  4047. },
  4048. cmyk: {
  4049. channels: 4,
  4050. labels: 'cmyk'
  4051. },
  4052. xyz: {
  4053. channels: 3,
  4054. labels: 'xyz'
  4055. },
  4056. lab: {
  4057. channels: 3,
  4058. labels: 'lab'
  4059. },
  4060. lch: {
  4061. channels: 3,
  4062. labels: 'lch'
  4063. },
  4064. hex: {
  4065. channels: 1,
  4066. labels: ['hex']
  4067. },
  4068. keyword: {
  4069. channels: 1,
  4070. labels: ['keyword']
  4071. },
  4072. ansi16: {
  4073. channels: 1,
  4074. labels: ['ansi16']
  4075. },
  4076. ansi256: {
  4077. channels: 1,
  4078. labels: ['ansi256']
  4079. },
  4080. hcg: {
  4081. channels: 3,
  4082. labels: ['h', 'c', 'g']
  4083. },
  4084. apple: {
  4085. channels: 3,
  4086. labels: ['r16', 'g16', 'b16']
  4087. },
  4088. gray: {
  4089. channels: 1,
  4090. labels: ['gray']
  4091. }
  4092. }; // hide .channels and .labels properties
  4093. for (var model in convert) {
  4094. if (convert.hasOwnProperty(model)) {
  4095. if (!('channels' in convert[model])) {
  4096. throw new Error('missing channels property: ' + model);
  4097. }
  4098. if (!('labels' in convert[model])) {
  4099. throw new Error('missing channel labels property: ' + model);
  4100. }
  4101. if (convert[model].labels.length !== convert[model].channels) {
  4102. throw new Error('channel and label counts mismatch: ' + model);
  4103. }
  4104. var channels = convert[model].channels;
  4105. var labels = convert[model].labels;
  4106. delete convert[model].channels;
  4107. delete convert[model].labels;
  4108. Object.defineProperty(convert[model], 'channels', {
  4109. value: channels
  4110. });
  4111. Object.defineProperty(convert[model], 'labels', {
  4112. value: labels
  4113. });
  4114. }
  4115. }
  4116. convert.rgb.hsl = function (rgb) {
  4117. var r = rgb[0] / 255;
  4118. var g = rgb[1] / 255;
  4119. var b = rgb[2] / 255;
  4120. var min = Math.min(r, g, b);
  4121. var max = Math.max(r, g, b);
  4122. var delta = max - min;
  4123. var h;
  4124. var s;
  4125. var l;
  4126. if (max === min) {
  4127. h = 0;
  4128. } else if (r === max) {
  4129. h = (g - b) / delta;
  4130. } else if (g === max) {
  4131. h = 2 + (b - r) / delta;
  4132. } else if (b === max) {
  4133. h = 4 + (r - g) / delta;
  4134. }
  4135. h = Math.min(h * 60, 360);
  4136. if (h < 0) {
  4137. h += 360;
  4138. }
  4139. l = (min + max) / 2;
  4140. if (max === min) {
  4141. s = 0;
  4142. } else if (l <= 0.5) {
  4143. s = delta / (max + min);
  4144. } else {
  4145. s = delta / (2 - max - min);
  4146. }
  4147. return [h, s * 100, l * 100];
  4148. };
  4149. convert.rgb.hsv = function (rgb) {
  4150. var r = rgb[0];
  4151. var g = rgb[1];
  4152. var b = rgb[2];
  4153. var min = Math.min(r, g, b);
  4154. var max = Math.max(r, g, b);
  4155. var delta = max - min;
  4156. var h;
  4157. var s;
  4158. var v;
  4159. if (max === 0) {
  4160. s = 0;
  4161. } else {
  4162. s = delta / max * 1000 / 10;
  4163. }
  4164. if (max === min) {
  4165. h = 0;
  4166. } else if (r === max) {
  4167. h = (g - b) / delta;
  4168. } else if (g === max) {
  4169. h = 2 + (b - r) / delta;
  4170. } else if (b === max) {
  4171. h = 4 + (r - g) / delta;
  4172. }
  4173. h = Math.min(h * 60, 360);
  4174. if (h < 0) {
  4175. h += 360;
  4176. }
  4177. v = max / 255 * 1000 / 10;
  4178. return [h, s, v];
  4179. };
  4180. convert.rgb.hwb = function (rgb) {
  4181. var r = rgb[0];
  4182. var g = rgb[1];
  4183. var b = rgb[2];
  4184. var h = convert.rgb.hsl(rgb)[0];
  4185. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  4186. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  4187. return [h, w * 100, b * 100];
  4188. };
  4189. convert.rgb.cmyk = function (rgb) {
  4190. var r = rgb[0] / 255;
  4191. var g = rgb[1] / 255;
  4192. var b = rgb[2] / 255;
  4193. var c;
  4194. var m;
  4195. var y;
  4196. var k;
  4197. k = Math.min(1 - r, 1 - g, 1 - b);
  4198. c = (1 - r - k) / (1 - k) || 0;
  4199. m = (1 - g - k) / (1 - k) || 0;
  4200. y = (1 - b - k) / (1 - k) || 0;
  4201. return [c * 100, m * 100, y * 100, k * 100];
  4202. };
  4203. /**
  4204. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  4205. * */
  4206. function comparativeDistance(x, y) {
  4207. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  4208. }
  4209. convert.rgb.keyword = function (rgb) {
  4210. var reversed = reverseKeywords[rgb];
  4211. if (reversed) {
  4212. return reversed;
  4213. }
  4214. var currentClosestDistance = Infinity;
  4215. var currentClosestKeyword;
  4216. for (var keyword in colorName) {
  4217. if (colorName.hasOwnProperty(keyword)) {
  4218. var value = colorName[keyword]; // Compute comparative distance
  4219. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  4220. if (distance < currentClosestDistance) {
  4221. currentClosestDistance = distance;
  4222. currentClosestKeyword = keyword;
  4223. }
  4224. }
  4225. }
  4226. return currentClosestKeyword;
  4227. };
  4228. convert.keyword.rgb = function (keyword) {
  4229. return colorName[keyword];
  4230. };
  4231. convert.rgb.xyz = function (rgb) {
  4232. var r = rgb[0] / 255;
  4233. var g = rgb[1] / 255;
  4234. var b = rgb[2] / 255; // assume sRGB
  4235. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  4236. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  4237. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  4238. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  4239. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  4240. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  4241. return [x * 100, y * 100, z * 100];
  4242. };
  4243. convert.rgb.lab = function (rgb) {
  4244. var xyz = convert.rgb.xyz(rgb);
  4245. var x = xyz[0];
  4246. var y = xyz[1];
  4247. var z = xyz[2];
  4248. var l;
  4249. var a;
  4250. var b;
  4251. x /= 95.047;
  4252. y /= 100;
  4253. z /= 108.883;
  4254. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4255. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4256. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4257. l = 116 * y - 16;
  4258. a = 500 * (x - y);
  4259. b = 200 * (y - z);
  4260. return [l, a, b];
  4261. };
  4262. convert.hsl.rgb = function (hsl) {
  4263. var h = hsl[0] / 360;
  4264. var s = hsl[1] / 100;
  4265. var l = hsl[2] / 100;
  4266. var t1;
  4267. var t2;
  4268. var t3;
  4269. var rgb;
  4270. var val;
  4271. if (s === 0) {
  4272. val = l * 255;
  4273. return [val, val, val];
  4274. }
  4275. if (l < 0.5) {
  4276. t2 = l * (1 + s);
  4277. } else {
  4278. t2 = l + s - l * s;
  4279. }
  4280. t1 = 2 * l - t2;
  4281. rgb = [0, 0, 0];
  4282. for (var i = 0; i < 3; i++) {
  4283. t3 = h + 1 / 3 * -(i - 1);
  4284. if (t3 < 0) {
  4285. t3++;
  4286. }
  4287. if (t3 > 1) {
  4288. t3--;
  4289. }
  4290. if (6 * t3 < 1) {
  4291. val = t1 + (t2 - t1) * 6 * t3;
  4292. } else if (2 * t3 < 1) {
  4293. val = t2;
  4294. } else if (3 * t3 < 2) {
  4295. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  4296. } else {
  4297. val = t1;
  4298. }
  4299. rgb[i] = val * 255;
  4300. }
  4301. return rgb;
  4302. };
  4303. convert.hsl.hsv = function (hsl) {
  4304. var h = hsl[0];
  4305. var s = hsl[1] / 100;
  4306. var l = hsl[2] / 100;
  4307. var smin = s;
  4308. var lmin = Math.max(l, 0.01);
  4309. var sv;
  4310. var v;
  4311. l *= 2;
  4312. s *= l <= 1 ? l : 2 - l;
  4313. smin *= lmin <= 1 ? lmin : 2 - lmin;
  4314. v = (l + s) / 2;
  4315. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  4316. return [h, sv * 100, v * 100];
  4317. };
  4318. convert.hsv.rgb = function (hsv) {
  4319. var h = hsv[0] / 60;
  4320. var s = hsv[1] / 100;
  4321. var v = hsv[2] / 100;
  4322. var hi = Math.floor(h) % 6;
  4323. var f = h - Math.floor(h);
  4324. var p = 255 * v * (1 - s);
  4325. var q = 255 * v * (1 - s * f);
  4326. var t = 255 * v * (1 - s * (1 - f));
  4327. v *= 255;
  4328. switch (hi) {
  4329. case 0:
  4330. return [v, t, p];
  4331. case 1:
  4332. return [q, v, p];
  4333. case 2:
  4334. return [p, v, t];
  4335. case 3:
  4336. return [p, q, v];
  4337. case 4:
  4338. return [t, p, v];
  4339. case 5:
  4340. return [v, p, q];
  4341. }
  4342. };
  4343. convert.hsv.hsl = function (hsv) {
  4344. var h = hsv[0];
  4345. var s = hsv[1] / 100;
  4346. var v = hsv[2] / 100;
  4347. var vmin = Math.max(v, 0.01);
  4348. var lmin;
  4349. var sl;
  4350. var l;
  4351. l = (2 - s) * v;
  4352. lmin = (2 - s) * vmin;
  4353. sl = s * vmin;
  4354. sl /= lmin <= 1 ? lmin : 2 - lmin;
  4355. sl = sl || 0;
  4356. l /= 2;
  4357. return [h, sl * 100, l * 100];
  4358. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  4359. convert.hwb.rgb = function (hwb) {
  4360. var h = hwb[0] / 360;
  4361. var wh = hwb[1] / 100;
  4362. var bl = hwb[2] / 100;
  4363. var ratio = wh + bl;
  4364. var i;
  4365. var v;
  4366. var f;
  4367. var n; // wh + bl cant be > 1
  4368. if (ratio > 1) {
  4369. wh /= ratio;
  4370. bl /= ratio;
  4371. }
  4372. i = Math.floor(6 * h);
  4373. v = 1 - bl;
  4374. f = 6 * h - i;
  4375. if ((i & 0x01) !== 0) {
  4376. f = 1 - f;
  4377. }
  4378. n = wh + f * (v - wh); // linear interpolation
  4379. var r;
  4380. var g;
  4381. var b;
  4382. switch (i) {
  4383. default:
  4384. case 6:
  4385. case 0:
  4386. r = v;
  4387. g = n;
  4388. b = wh;
  4389. break;
  4390. case 1:
  4391. r = n;
  4392. g = v;
  4393. b = wh;
  4394. break;
  4395. case 2:
  4396. r = wh;
  4397. g = v;
  4398. b = n;
  4399. break;
  4400. case 3:
  4401. r = wh;
  4402. g = n;
  4403. b = v;
  4404. break;
  4405. case 4:
  4406. r = n;
  4407. g = wh;
  4408. b = v;
  4409. break;
  4410. case 5:
  4411. r = v;
  4412. g = wh;
  4413. b = n;
  4414. break;
  4415. }
  4416. return [r * 255, g * 255, b * 255];
  4417. };
  4418. convert.cmyk.rgb = function (cmyk) {
  4419. var c = cmyk[0] / 100;
  4420. var m = cmyk[1] / 100;
  4421. var y = cmyk[2] / 100;
  4422. var k = cmyk[3] / 100;
  4423. var r;
  4424. var g;
  4425. var b;
  4426. r = 1 - Math.min(1, c * (1 - k) + k);
  4427. g = 1 - Math.min(1, m * (1 - k) + k);
  4428. b = 1 - Math.min(1, y * (1 - k) + k);
  4429. return [r * 255, g * 255, b * 255];
  4430. };
  4431. convert.xyz.rgb = function (xyz) {
  4432. var x = xyz[0] / 100;
  4433. var y = xyz[1] / 100;
  4434. var z = xyz[2] / 100;
  4435. var r;
  4436. var g;
  4437. var b;
  4438. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  4439. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  4440. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  4441. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  4442. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  4443. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  4444. r = Math.min(Math.max(0, r), 1);
  4445. g = Math.min(Math.max(0, g), 1);
  4446. b = Math.min(Math.max(0, b), 1);
  4447. return [r * 255, g * 255, b * 255];
  4448. };
  4449. convert.xyz.lab = function (xyz) {
  4450. var x = xyz[0];
  4451. var y = xyz[1];
  4452. var z = xyz[2];
  4453. var l;
  4454. var a;
  4455. var b;
  4456. x /= 95.047;
  4457. y /= 100;
  4458. z /= 108.883;
  4459. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4460. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4461. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4462. l = 116 * y - 16;
  4463. a = 500 * (x - y);
  4464. b = 200 * (y - z);
  4465. return [l, a, b];
  4466. };
  4467. convert.lab.xyz = function (lab) {
  4468. var l = lab[0];
  4469. var a = lab[1];
  4470. var b = lab[2];
  4471. var x;
  4472. var y;
  4473. var z;
  4474. y = (l + 16) / 116;
  4475. x = a / 500 + y;
  4476. z = y - b / 200;
  4477. var y2 = Math.pow(y, 3);
  4478. var x2 = Math.pow(x, 3);
  4479. var z2 = Math.pow(z, 3);
  4480. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  4481. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  4482. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  4483. x *= 95.047;
  4484. y *= 100;
  4485. z *= 108.883;
  4486. return [x, y, z];
  4487. };
  4488. convert.lab.lch = function (lab) {
  4489. var l = lab[0];
  4490. var a = lab[1];
  4491. var b = lab[2];
  4492. var hr;
  4493. var h;
  4494. var c;
  4495. hr = Math.atan2(b, a);
  4496. h = hr * 360 / 2 / Math.PI;
  4497. if (h < 0) {
  4498. h += 360;
  4499. }
  4500. c = Math.sqrt(a * a + b * b);
  4501. return [l, c, h];
  4502. };
  4503. convert.lch.lab = function (lch) {
  4504. var l = lch[0];
  4505. var c = lch[1];
  4506. var h = lch[2];
  4507. var a;
  4508. var b;
  4509. var hr;
  4510. hr = h / 360 * 2 * Math.PI;
  4511. a = c * Math.cos(hr);
  4512. b = c * Math.sin(hr);
  4513. return [l, a, b];
  4514. };
  4515. convert.rgb.ansi16 = function (args) {
  4516. var r = args[0];
  4517. var g = args[1];
  4518. var b = args[2];
  4519. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  4520. value = Math.round(value / 50);
  4521. if (value === 0) {
  4522. return 30;
  4523. }
  4524. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  4525. if (value === 2) {
  4526. ansi += 60;
  4527. }
  4528. return ansi;
  4529. };
  4530. convert.hsv.ansi16 = function (args) {
  4531. // optimization here; we already know the value and don't need to get
  4532. // it converted for us.
  4533. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  4534. };
  4535. convert.rgb.ansi256 = function (args) {
  4536. var r = args[0];
  4537. var g = args[1];
  4538. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  4539. // black and white. normal palette only has 4 greyscale shades.
  4540. if (r === g && g === b) {
  4541. if (r < 8) {
  4542. return 16;
  4543. }
  4544. if (r > 248) {
  4545. return 231;
  4546. }
  4547. return Math.round((r - 8) / 247 * 24) + 232;
  4548. }
  4549. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  4550. return ansi;
  4551. };
  4552. convert.ansi16.rgb = function (args) {
  4553. var color = args % 10; // handle greyscale
  4554. if (color === 0 || color === 7) {
  4555. if (args > 50) {
  4556. color += 3.5;
  4557. }
  4558. color = color / 10.5 * 255;
  4559. return [color, color, color];
  4560. }
  4561. var mult = (~~(args > 50) + 1) * 0.5;
  4562. var r = (color & 1) * mult * 255;
  4563. var g = (color >> 1 & 1) * mult * 255;
  4564. var b = (color >> 2 & 1) * mult * 255;
  4565. return [r, g, b];
  4566. };
  4567. convert.ansi256.rgb = function (args) {
  4568. // handle greyscale
  4569. if (args >= 232) {
  4570. var c = (args - 232) * 10 + 8;
  4571. return [c, c, c];
  4572. }
  4573. args -= 16;
  4574. var rem;
  4575. var r = Math.floor(args / 36) / 5 * 255;
  4576. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  4577. var b = rem % 6 / 5 * 255;
  4578. return [r, g, b];
  4579. };
  4580. convert.rgb.hex = function (args) {
  4581. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  4582. var string = integer.toString(16).toUpperCase();
  4583. return '000000'.substring(string.length) + string;
  4584. };
  4585. convert.hex.rgb = function (args) {
  4586. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  4587. if (!match) {
  4588. return [0, 0, 0];
  4589. }
  4590. var colorString = match[0];
  4591. if (match[0].length === 3) {
  4592. colorString = colorString.split('').map(function (char) {
  4593. return char + char;
  4594. }).join('');
  4595. }
  4596. var integer = parseInt(colorString, 16);
  4597. var r = integer >> 16 & 0xFF;
  4598. var g = integer >> 8 & 0xFF;
  4599. var b = integer & 0xFF;
  4600. return [r, g, b];
  4601. };
  4602. convert.rgb.hcg = function (rgb) {
  4603. var r = rgb[0] / 255;
  4604. var g = rgb[1] / 255;
  4605. var b = rgb[2] / 255;
  4606. var max = Math.max(Math.max(r, g), b);
  4607. var min = Math.min(Math.min(r, g), b);
  4608. var chroma = max - min;
  4609. var grayscale;
  4610. var hue;
  4611. if (chroma < 1) {
  4612. grayscale = min / (1 - chroma);
  4613. } else {
  4614. grayscale = 0;
  4615. }
  4616. if (chroma <= 0) {
  4617. hue = 0;
  4618. } else if (max === r) {
  4619. hue = (g - b) / chroma % 6;
  4620. } else if (max === g) {
  4621. hue = 2 + (b - r) / chroma;
  4622. } else {
  4623. hue = 4 + (r - g) / chroma + 4;
  4624. }
  4625. hue /= 6;
  4626. hue %= 1;
  4627. return [hue * 360, chroma * 100, grayscale * 100];
  4628. };
  4629. convert.hsl.hcg = function (hsl) {
  4630. var s = hsl[1] / 100;
  4631. var l = hsl[2] / 100;
  4632. var c = 1;
  4633. var f = 0;
  4634. if (l < 0.5) {
  4635. c = 2.0 * s * l;
  4636. } else {
  4637. c = 2.0 * s * (1.0 - l);
  4638. }
  4639. if (c < 1.0) {
  4640. f = (l - 0.5 * c) / (1.0 - c);
  4641. }
  4642. return [hsl[0], c * 100, f * 100];
  4643. };
  4644. convert.hsv.hcg = function (hsv) {
  4645. var s = hsv[1] / 100;
  4646. var v = hsv[2] / 100;
  4647. var c = s * v;
  4648. var f = 0;
  4649. if (c < 1.0) {
  4650. f = (v - c) / (1 - c);
  4651. }
  4652. return [hsv[0], c * 100, f * 100];
  4653. };
  4654. convert.hcg.rgb = function (hcg) {
  4655. var h = hcg[0] / 360;
  4656. var c = hcg[1] / 100;
  4657. var g = hcg[2] / 100;
  4658. if (c === 0.0) {
  4659. return [g * 255, g * 255, g * 255];
  4660. }
  4661. var pure = [0, 0, 0];
  4662. var hi = h % 1 * 6;
  4663. var v = hi % 1;
  4664. var w = 1 - v;
  4665. var mg = 0;
  4666. switch (Math.floor(hi)) {
  4667. case 0:
  4668. pure[0] = 1;
  4669. pure[1] = v;
  4670. pure[2] = 0;
  4671. break;
  4672. case 1:
  4673. pure[0] = w;
  4674. pure[1] = 1;
  4675. pure[2] = 0;
  4676. break;
  4677. case 2:
  4678. pure[0] = 0;
  4679. pure[1] = 1;
  4680. pure[2] = v;
  4681. break;
  4682. case 3:
  4683. pure[0] = 0;
  4684. pure[1] = w;
  4685. pure[2] = 1;
  4686. break;
  4687. case 4:
  4688. pure[0] = v;
  4689. pure[1] = 0;
  4690. pure[2] = 1;
  4691. break;
  4692. default:
  4693. pure[0] = 1;
  4694. pure[1] = 0;
  4695. pure[2] = w;
  4696. }
  4697. mg = (1.0 - c) * g;
  4698. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  4699. };
  4700. convert.hcg.hsv = function (hcg) {
  4701. var c = hcg[1] / 100;
  4702. var g = hcg[2] / 100;
  4703. var v = c + g * (1.0 - c);
  4704. var f = 0;
  4705. if (v > 0.0) {
  4706. f = c / v;
  4707. }
  4708. return [hcg[0], f * 100, v * 100];
  4709. };
  4710. convert.hcg.hsl = function (hcg) {
  4711. var c = hcg[1] / 100;
  4712. var g = hcg[2] / 100;
  4713. var l = g * (1.0 - c) + 0.5 * c;
  4714. var s = 0;
  4715. if (l > 0.0 && l < 0.5) {
  4716. s = c / (2 * l);
  4717. } else if (l >= 0.5 && l < 1.0) {
  4718. s = c / (2 * (1 - l));
  4719. }
  4720. return [hcg[0], s * 100, l * 100];
  4721. };
  4722. convert.hcg.hwb = function (hcg) {
  4723. var c = hcg[1] / 100;
  4724. var g = hcg[2] / 100;
  4725. var v = c + g * (1.0 - c);
  4726. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  4727. };
  4728. convert.hwb.hcg = function (hwb) {
  4729. var w = hwb[1] / 100;
  4730. var b = hwb[2] / 100;
  4731. var v = 1 - b;
  4732. var c = v - w;
  4733. var g = 0;
  4734. if (c < 1) {
  4735. g = (v - c) / (1 - c);
  4736. }
  4737. return [hwb[0], c * 100, g * 100];
  4738. };
  4739. convert.apple.rgb = function (apple) {
  4740. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  4741. };
  4742. convert.rgb.apple = function (rgb) {
  4743. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  4744. };
  4745. convert.gray.rgb = function (args) {
  4746. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  4747. };
  4748. convert.gray.hsl = convert.gray.hsv = function (args) {
  4749. return [0, 0, args[0]];
  4750. };
  4751. convert.gray.hwb = function (gray) {
  4752. return [0, 100, gray[0]];
  4753. };
  4754. convert.gray.cmyk = function (gray) {
  4755. return [0, 0, 0, gray[0]];
  4756. };
  4757. convert.gray.lab = function (gray) {
  4758. return [gray[0], 0, 0];
  4759. };
  4760. convert.gray.hex = function (gray) {
  4761. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  4762. var integer = (val << 16) + (val << 8) + val;
  4763. var string = integer.toString(16).toUpperCase();
  4764. return '000000'.substring(string.length) + string;
  4765. };
  4766. convert.rgb.gray = function (rgb) {
  4767. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  4768. return [val / 255 * 100];
  4769. };
  4770. });
  4771. /*
  4772. this function routes a model to all other models.
  4773. all functions that are routed have a property `.conversion` attached
  4774. to the returned synthetic function. This property is an array
  4775. of strings, each with the steps in between the 'from' and 'to'
  4776. color models (inclusive).
  4777. conversions that are not possible simply are not included.
  4778. */
  4779. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  4780. var models$1 = Object.keys(conversions);
  4781. function buildGraph() {
  4782. var graph = {};
  4783. for (var len = models$1.length, i = 0; i < len; i++) {
  4784. graph[models$1[i]] = {
  4785. // http://jsperf.com/1-vs-infinity
  4786. // micro-opt, but this is simple.
  4787. distance: -1,
  4788. parent: null
  4789. };
  4790. }
  4791. return graph;
  4792. } // https://en.wikipedia.org/wiki/Breadth-first_search
  4793. function deriveBFS(fromModel) {
  4794. var graph = buildGraph();
  4795. var queue = [fromModel]; // unshift -> queue -> pop
  4796. graph[fromModel].distance = 0;
  4797. while (queue.length) {
  4798. var current = queue.pop();
  4799. var adjacents = Object.keys(conversions[current]);
  4800. for (var len = adjacents.length, i = 0; i < len; i++) {
  4801. var adjacent = adjacents[i];
  4802. var node = graph[adjacent];
  4803. if (node.distance === -1) {
  4804. node.distance = graph[current].distance + 1;
  4805. node.parent = current;
  4806. queue.unshift(adjacent);
  4807. }
  4808. }
  4809. }
  4810. return graph;
  4811. }
  4812. function link(from, to) {
  4813. return function (args) {
  4814. return to(from(args));
  4815. };
  4816. }
  4817. function wrapConversion(toModel, graph) {
  4818. var path$$1 = [graph[toModel].parent, toModel];
  4819. var fn = conversions[graph[toModel].parent][toModel];
  4820. var cur = graph[toModel].parent;
  4821. while (graph[cur].parent) {
  4822. path$$1.unshift(graph[cur].parent);
  4823. fn = link(conversions[graph[cur].parent][cur], fn);
  4824. cur = graph[cur].parent;
  4825. }
  4826. fn.conversion = path$$1;
  4827. return fn;
  4828. }
  4829. var route = function route(fromModel) {
  4830. var graph = deriveBFS(fromModel);
  4831. var conversion = {};
  4832. var models = Object.keys(graph);
  4833. for (var len = models.length, i = 0; i < len; i++) {
  4834. var toModel = models[i];
  4835. var node = graph[toModel];
  4836. if (node.parent === null) {
  4837. // no possible conversion, or this node is the source model.
  4838. continue;
  4839. }
  4840. conversion[toModel] = wrapConversion(toModel, graph);
  4841. }
  4842. return conversion;
  4843. };
  4844. var convert = {};
  4845. var models = Object.keys(conversions);
  4846. function wrapRaw(fn) {
  4847. var wrappedFn = function wrappedFn(args) {
  4848. if (args === undefined || args === null) {
  4849. return args;
  4850. }
  4851. if (arguments.length > 1) {
  4852. args = Array.prototype.slice.call(arguments);
  4853. }
  4854. return fn(args);
  4855. }; // preserve .conversion property if there is one
  4856. if ('conversion' in fn) {
  4857. wrappedFn.conversion = fn.conversion;
  4858. }
  4859. return wrappedFn;
  4860. }
  4861. function wrapRounded(fn) {
  4862. var wrappedFn = function wrappedFn(args) {
  4863. if (args === undefined || args === null) {
  4864. return args;
  4865. }
  4866. if (arguments.length > 1) {
  4867. args = Array.prototype.slice.call(arguments);
  4868. }
  4869. var result = fn(args); // we're assuming the result is an array here.
  4870. // see notice in conversions.js; don't use box types
  4871. // in conversion functions.
  4872. if (typeof result === 'object') {
  4873. for (var len = result.length, i = 0; i < len; i++) {
  4874. result[i] = Math.round(result[i]);
  4875. }
  4876. }
  4877. return result;
  4878. }; // preserve .conversion property if there is one
  4879. if ('conversion' in fn) {
  4880. wrappedFn.conversion = fn.conversion;
  4881. }
  4882. return wrappedFn;
  4883. }
  4884. models.forEach(function (fromModel) {
  4885. convert[fromModel] = {};
  4886. Object.defineProperty(convert[fromModel], 'channels', {
  4887. value: conversions[fromModel].channels
  4888. });
  4889. Object.defineProperty(convert[fromModel], 'labels', {
  4890. value: conversions[fromModel].labels
  4891. });
  4892. var routes = route(fromModel);
  4893. var routeModels = Object.keys(routes);
  4894. routeModels.forEach(function (toModel) {
  4895. var fn = routes[toModel];
  4896. convert[fromModel][toModel] = wrapRounded(fn);
  4897. convert[fromModel][toModel].raw = wrapRaw(fn);
  4898. });
  4899. });
  4900. var colorConvert = convert;
  4901. var ansiStyles = createCommonjsModule(function (module) {
  4902. 'use strict';
  4903. var wrapAnsi16 = function wrapAnsi16(fn, offset) {
  4904. return function () {
  4905. var code = fn.apply(colorConvert, arguments);
  4906. return `\u001B[${code + offset}m`;
  4907. };
  4908. };
  4909. var wrapAnsi256 = function wrapAnsi256(fn, offset) {
  4910. return function () {
  4911. var code = fn.apply(colorConvert, arguments);
  4912. return `\u001B[${38 + offset};5;${code}m`;
  4913. };
  4914. };
  4915. var wrapAnsi16m = function wrapAnsi16m(fn, offset) {
  4916. return function () {
  4917. var rgb = fn.apply(colorConvert, arguments);
  4918. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  4919. };
  4920. };
  4921. function assembleStyles() {
  4922. var codes = new Map();
  4923. var styles = {
  4924. modifier: {
  4925. reset: [0, 0],
  4926. // 21 isn't widely supported and 22 does the same thing
  4927. bold: [1, 22],
  4928. dim: [2, 22],
  4929. italic: [3, 23],
  4930. underline: [4, 24],
  4931. inverse: [7, 27],
  4932. hidden: [8, 28],
  4933. strikethrough: [9, 29]
  4934. },
  4935. color: {
  4936. black: [30, 39],
  4937. red: [31, 39],
  4938. green: [32, 39],
  4939. yellow: [33, 39],
  4940. blue: [34, 39],
  4941. magenta: [35, 39],
  4942. cyan: [36, 39],
  4943. white: [37, 39],
  4944. gray: [90, 39],
  4945. // Bright color
  4946. redBright: [91, 39],
  4947. greenBright: [92, 39],
  4948. yellowBright: [93, 39],
  4949. blueBright: [94, 39],
  4950. magentaBright: [95, 39],
  4951. cyanBright: [96, 39],
  4952. whiteBright: [97, 39]
  4953. },
  4954. bgColor: {
  4955. bgBlack: [40, 49],
  4956. bgRed: [41, 49],
  4957. bgGreen: [42, 49],
  4958. bgYellow: [43, 49],
  4959. bgBlue: [44, 49],
  4960. bgMagenta: [45, 49],
  4961. bgCyan: [46, 49],
  4962. bgWhite: [47, 49],
  4963. // Bright color
  4964. bgBlackBright: [100, 49],
  4965. bgRedBright: [101, 49],
  4966. bgGreenBright: [102, 49],
  4967. bgYellowBright: [103, 49],
  4968. bgBlueBright: [104, 49],
  4969. bgMagentaBright: [105, 49],
  4970. bgCyanBright: [106, 49],
  4971. bgWhiteBright: [107, 49]
  4972. }
  4973. }; // Fix humans
  4974. styles.color.grey = styles.color.gray;
  4975. var _arr = Object.keys(styles);
  4976. for (var _i = 0; _i < _arr.length; _i++) {
  4977. var groupName = _arr[_i];
  4978. var group = styles[groupName];
  4979. var _arr3 = Object.keys(group);
  4980. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  4981. var styleName = _arr3[_i3];
  4982. var style = group[styleName];
  4983. styles[styleName] = {
  4984. open: `\u001B[${style[0]}m`,
  4985. close: `\u001B[${style[1]}m`
  4986. };
  4987. group[styleName] = styles[styleName];
  4988. codes.set(style[0], style[1]);
  4989. }
  4990. Object.defineProperty(styles, groupName, {
  4991. value: group,
  4992. enumerable: false
  4993. });
  4994. Object.defineProperty(styles, 'codes', {
  4995. value: codes,
  4996. enumerable: false
  4997. });
  4998. }
  4999. var ansi2ansi = function ansi2ansi(n) {
  5000. return n;
  5001. };
  5002. var rgb2rgb = function rgb2rgb(r, g, b) {
  5003. return [r, g, b];
  5004. };
  5005. styles.color.close = '\u001B[39m';
  5006. styles.bgColor.close = '\u001B[49m';
  5007. styles.color.ansi = {
  5008. ansi: wrapAnsi16(ansi2ansi, 0)
  5009. };
  5010. styles.color.ansi256 = {
  5011. ansi256: wrapAnsi256(ansi2ansi, 0)
  5012. };
  5013. styles.color.ansi16m = {
  5014. rgb: wrapAnsi16m(rgb2rgb, 0)
  5015. };
  5016. styles.bgColor.ansi = {
  5017. ansi: wrapAnsi16(ansi2ansi, 10)
  5018. };
  5019. styles.bgColor.ansi256 = {
  5020. ansi256: wrapAnsi256(ansi2ansi, 10)
  5021. };
  5022. styles.bgColor.ansi16m = {
  5023. rgb: wrapAnsi16m(rgb2rgb, 10)
  5024. };
  5025. var _arr2 = Object.keys(colorConvert);
  5026. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  5027. var key = _arr2[_i2];
  5028. if (typeof colorConvert[key] !== 'object') {
  5029. continue;
  5030. }
  5031. var suite = colorConvert[key];
  5032. if (key === 'ansi16') {
  5033. key = 'ansi';
  5034. }
  5035. if ('ansi16' in suite) {
  5036. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  5037. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  5038. }
  5039. if ('ansi256' in suite) {
  5040. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  5041. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  5042. }
  5043. if ('rgb' in suite) {
  5044. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  5045. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  5046. }
  5047. }
  5048. return styles;
  5049. } // Make the export immutable
  5050. Object.defineProperty(module, 'exports', {
  5051. enumerable: true,
  5052. get: assembleStyles
  5053. });
  5054. });
  5055. var hasFlag = createCommonjsModule(function (module) {
  5056. 'use strict';
  5057. module.exports = function (flag, argv) {
  5058. argv = argv || process.argv;
  5059. var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  5060. var pos = argv.indexOf(prefix + flag);
  5061. var terminatorPos = argv.indexOf('--');
  5062. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  5063. };
  5064. });
  5065. var env = process.env;
  5066. var forceColor;
  5067. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  5068. forceColor = false;
  5069. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  5070. forceColor = true;
  5071. }
  5072. if ('FORCE_COLOR' in env) {
  5073. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  5074. }
  5075. function translateLevel(level) {
  5076. if (level === 0) {
  5077. return false;
  5078. }
  5079. return {
  5080. level,
  5081. hasBasic: true,
  5082. has256: level >= 2,
  5083. has16m: level >= 3
  5084. };
  5085. }
  5086. function supportsColor(stream) {
  5087. if (forceColor === false) {
  5088. return 0;
  5089. }
  5090. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  5091. return 3;
  5092. }
  5093. if (hasFlag('color=256')) {
  5094. return 2;
  5095. }
  5096. if (stream && !stream.isTTY && forceColor !== true) {
  5097. return 0;
  5098. }
  5099. var min = forceColor ? 1 : 0;
  5100. if (process.platform === 'win32') {
  5101. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  5102. // libuv that enables 256 color output on Windows. Anything earlier and it
  5103. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  5104. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  5105. // release that supports 256 colors. Windows 10 build 14931 is the first release
  5106. // that supports 16m/TrueColor.
  5107. var osRelease = os.release().split('.');
  5108. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  5109. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  5110. }
  5111. return 1;
  5112. }
  5113. if ('CI' in env) {
  5114. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  5115. return sign in env;
  5116. }) || env.CI_NAME === 'codeship') {
  5117. return 1;
  5118. }
  5119. return min;
  5120. }
  5121. if ('TEAMCITY_VERSION' in env) {
  5122. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  5123. }
  5124. if (env.COLORTERM === 'truecolor') {
  5125. return 3;
  5126. }
  5127. if ('TERM_PROGRAM' in env) {
  5128. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  5129. switch (env.TERM_PROGRAM) {
  5130. case 'iTerm.app':
  5131. return version >= 3 ? 3 : 2;
  5132. case 'Apple_Terminal':
  5133. return 2;
  5134. // No default
  5135. }
  5136. }
  5137. if (/-256(color)?$/i.test(env.TERM)) {
  5138. return 2;
  5139. }
  5140. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  5141. return 1;
  5142. }
  5143. if ('COLORTERM' in env) {
  5144. return 1;
  5145. }
  5146. if (env.TERM === 'dumb') {
  5147. return min;
  5148. }
  5149. return min;
  5150. }
  5151. function getSupportLevel(stream) {
  5152. var level = supportsColor(stream);
  5153. return translateLevel(level);
  5154. }
  5155. var supportsColor_1 = {
  5156. supportsColor: getSupportLevel,
  5157. stdout: getSupportLevel(process.stdout),
  5158. stderr: getSupportLevel(process.stderr)
  5159. };
  5160. var templates = createCommonjsModule(function (module) {
  5161. 'use strict';
  5162. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  5163. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  5164. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  5165. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  5166. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  5167. function unescape(c) {
  5168. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  5169. return String.fromCharCode(parseInt(c.slice(1), 16));
  5170. }
  5171. return ESCAPES.get(c) || c;
  5172. }
  5173. function parseArguments(name, args) {
  5174. var results = [];
  5175. var chunks = args.trim().split(/\s*,\s*/g);
  5176. var matches;
  5177. var _iteratorNormalCompletion = true;
  5178. var _didIteratorError = false;
  5179. var _iteratorError = undefined;
  5180. try {
  5181. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5182. var chunk = _step.value;
  5183. if (!isNaN(chunk)) {
  5184. results.push(Number(chunk));
  5185. } else if (matches = chunk.match(STRING_REGEX)) {
  5186. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  5187. return escape ? unescape(escape) : chr;
  5188. }));
  5189. } else {
  5190. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  5191. }
  5192. }
  5193. } catch (err) {
  5194. _didIteratorError = true;
  5195. _iteratorError = err;
  5196. } finally {
  5197. try {
  5198. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5199. _iterator.return();
  5200. }
  5201. } finally {
  5202. if (_didIteratorError) {
  5203. throw _iteratorError;
  5204. }
  5205. }
  5206. }
  5207. return results;
  5208. }
  5209. function parseStyle(style) {
  5210. STYLE_REGEX.lastIndex = 0;
  5211. var results = [];
  5212. var matches;
  5213. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  5214. var name = matches[1];
  5215. if (matches[2]) {
  5216. var args = parseArguments(name, matches[2]);
  5217. results.push([name].concat(args));
  5218. } else {
  5219. results.push([name]);
  5220. }
  5221. }
  5222. return results;
  5223. }
  5224. function buildStyle(chalk, styles) {
  5225. var enabled = {};
  5226. var _iteratorNormalCompletion2 = true;
  5227. var _didIteratorError2 = false;
  5228. var _iteratorError2 = undefined;
  5229. try {
  5230. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5231. var layer = _step2.value;
  5232. var _iteratorNormalCompletion3 = true;
  5233. var _didIteratorError3 = false;
  5234. var _iteratorError3 = undefined;
  5235. try {
  5236. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  5237. var style = _step3.value;
  5238. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  5239. }
  5240. } catch (err) {
  5241. _didIteratorError3 = true;
  5242. _iteratorError3 = err;
  5243. } finally {
  5244. try {
  5245. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  5246. _iterator3.return();
  5247. }
  5248. } finally {
  5249. if (_didIteratorError3) {
  5250. throw _iteratorError3;
  5251. }
  5252. }
  5253. }
  5254. }
  5255. } catch (err) {
  5256. _didIteratorError2 = true;
  5257. _iteratorError2 = err;
  5258. } finally {
  5259. try {
  5260. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5261. _iterator2.return();
  5262. }
  5263. } finally {
  5264. if (_didIteratorError2) {
  5265. throw _iteratorError2;
  5266. }
  5267. }
  5268. }
  5269. var current = chalk;
  5270. var _arr = Object.keys(enabled);
  5271. for (var _i = 0; _i < _arr.length; _i++) {
  5272. var styleName = _arr[_i];
  5273. if (Array.isArray(enabled[styleName])) {
  5274. if (!(styleName in current)) {
  5275. throw new Error(`Unknown Chalk style: ${styleName}`);
  5276. }
  5277. if (enabled[styleName].length > 0) {
  5278. current = current[styleName].apply(current, enabled[styleName]);
  5279. } else {
  5280. current = current[styleName];
  5281. }
  5282. }
  5283. }
  5284. return current;
  5285. }
  5286. module.exports = function (chalk, tmp) {
  5287. var styles = [];
  5288. var chunks = [];
  5289. var chunk = []; // eslint-disable-next-line max-params
  5290. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  5291. if (escapeChar) {
  5292. chunk.push(unescape(escapeChar));
  5293. } else if (style) {
  5294. var str = chunk.join('');
  5295. chunk = [];
  5296. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  5297. styles.push({
  5298. inverse,
  5299. styles: parseStyle(style)
  5300. });
  5301. } else if (close) {
  5302. if (styles.length === 0) {
  5303. throw new Error('Found extraneous } in Chalk template literal');
  5304. }
  5305. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  5306. chunk = [];
  5307. styles.pop();
  5308. } else {
  5309. chunk.push(chr);
  5310. }
  5311. });
  5312. chunks.push(chunk.join(''));
  5313. if (styles.length > 0) {
  5314. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  5315. throw new Error(errMsg);
  5316. }
  5317. return chunks.join('');
  5318. };
  5319. });
  5320. var chalk = createCommonjsModule(function (module) {
  5321. 'use strict';
  5322. var stdoutColor = supportsColor_1.stdout;
  5323. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  5324. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  5325. var skipModels = new Set(['gray']);
  5326. var styles = Object.create(null);
  5327. function applyOptions(obj, options) {
  5328. options = options || {}; // Detect level if not set manually
  5329. var scLevel = stdoutColor ? stdoutColor.level : 0;
  5330. obj.level = options.level === undefined ? scLevel : options.level;
  5331. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  5332. }
  5333. function Chalk(options) {
  5334. // We check for this.template here since calling `chalk.constructor()`
  5335. // by itself will have a `this` of a previously constructed chalk object
  5336. if (!this || !(this instanceof Chalk) || this.template) {
  5337. var _chalk = {};
  5338. applyOptions(_chalk, options);
  5339. _chalk.template = function () {
  5340. var args = [].slice.call(arguments);
  5341. return chalkTag.apply(null, [_chalk.template].concat(args));
  5342. };
  5343. Object.setPrototypeOf(_chalk, Chalk.prototype);
  5344. Object.setPrototypeOf(_chalk.template, _chalk);
  5345. _chalk.template.constructor = Chalk;
  5346. return _chalk.template;
  5347. }
  5348. applyOptions(this, options);
  5349. } // Use bright blue on Windows as the normal blue color is illegible
  5350. if (isSimpleWindowsTerm) {
  5351. ansiStyles.blue.open = '\u001B[94m';
  5352. }
  5353. var _arr = Object.keys(ansiStyles);
  5354. var _loop = function _loop() {
  5355. var key = _arr[_i];
  5356. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  5357. styles[key] = {
  5358. get() {
  5359. var codes = ansiStyles[key];
  5360. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  5361. }
  5362. };
  5363. };
  5364. for (var _i = 0; _i < _arr.length; _i++) {
  5365. _loop();
  5366. }
  5367. styles.visible = {
  5368. get() {
  5369. return build.call(this, this._styles || [], true, 'visible');
  5370. }
  5371. };
  5372. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  5373. var _arr2 = Object.keys(ansiStyles.color.ansi);
  5374. var _loop2 = function _loop2() {
  5375. var model = _arr2[_i2];
  5376. if (skipModels.has(model)) {
  5377. return "continue";
  5378. }
  5379. styles[model] = {
  5380. get() {
  5381. var level = this.level;
  5382. return function () {
  5383. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  5384. var codes = {
  5385. open,
  5386. close: ansiStyles.color.close,
  5387. closeRe: ansiStyles.color.closeRe
  5388. };
  5389. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5390. };
  5391. }
  5392. };
  5393. };
  5394. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  5395. var _ret = _loop2();
  5396. if (_ret === "continue") continue;
  5397. }
  5398. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  5399. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  5400. var _loop3 = function _loop3() {
  5401. var model = _arr3[_i3];
  5402. if (skipModels.has(model)) {
  5403. return "continue";
  5404. }
  5405. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  5406. styles[bgModel] = {
  5407. get() {
  5408. var level = this.level;
  5409. return function () {
  5410. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  5411. var codes = {
  5412. open,
  5413. close: ansiStyles.bgColor.close,
  5414. closeRe: ansiStyles.bgColor.closeRe
  5415. };
  5416. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5417. };
  5418. }
  5419. };
  5420. };
  5421. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  5422. var _ret2 = _loop3();
  5423. if (_ret2 === "continue") continue;
  5424. }
  5425. var proto = Object.defineProperties(function () {}, styles);
  5426. function build(_styles, _empty, key) {
  5427. var builder = function builder() {
  5428. return applyStyle.apply(builder, arguments);
  5429. };
  5430. builder._styles = _styles;
  5431. builder._empty = _empty;
  5432. var self = this;
  5433. Object.defineProperty(builder, 'level', {
  5434. enumerable: true,
  5435. get() {
  5436. return self.level;
  5437. },
  5438. set(level) {
  5439. self.level = level;
  5440. }
  5441. });
  5442. Object.defineProperty(builder, 'enabled', {
  5443. enumerable: true,
  5444. get() {
  5445. return self.enabled;
  5446. },
  5447. set(enabled) {
  5448. self.enabled = enabled;
  5449. }
  5450. }); // See below for fix regarding invisible grey/dim combination on Windows
  5451. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  5452. // no way to create a function with a different prototype
  5453. builder.__proto__ = proto; // eslint-disable-line no-proto
  5454. return builder;
  5455. }
  5456. function applyStyle() {
  5457. // Support varags, but simply cast to string in case there's only one arg
  5458. var args = arguments;
  5459. var argsLen = args.length;
  5460. var str = String(arguments[0]);
  5461. if (argsLen === 0) {
  5462. return '';
  5463. }
  5464. if (argsLen > 1) {
  5465. // Don't slice `arguments`, it prevents V8 optimizations
  5466. for (var a = 1; a < argsLen; a++) {
  5467. str += ' ' + args[a];
  5468. }
  5469. }
  5470. if (!this.enabled || this.level <= 0 || !str) {
  5471. return this._empty ? '' : str;
  5472. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  5473. // see https://github.com/chalk/chalk/issues/58
  5474. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  5475. var originalDim = ansiStyles.dim.open;
  5476. if (isSimpleWindowsTerm && this.hasGrey) {
  5477. ansiStyles.dim.open = '';
  5478. }
  5479. var _iteratorNormalCompletion = true;
  5480. var _didIteratorError = false;
  5481. var _iteratorError = undefined;
  5482. try {
  5483. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5484. var code = _step.value;
  5485. // Replace any instances already present with a re-opening code
  5486. // otherwise only the part of the string until said closing code
  5487. // will be colored, and the rest will simply be 'plain'.
  5488. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  5489. // after next line to fix a bleed issue on macOS
  5490. // https://github.com/chalk/chalk/pull/92
  5491. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  5492. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  5493. } catch (err) {
  5494. _didIteratorError = true;
  5495. _iteratorError = err;
  5496. } finally {
  5497. try {
  5498. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5499. _iterator.return();
  5500. }
  5501. } finally {
  5502. if (_didIteratorError) {
  5503. throw _iteratorError;
  5504. }
  5505. }
  5506. }
  5507. ansiStyles.dim.open = originalDim;
  5508. return str;
  5509. }
  5510. function chalkTag(chalk, strings) {
  5511. if (!Array.isArray(strings)) {
  5512. // If chalk() was called by itself or with a string,
  5513. // return the string itself as a string.
  5514. return [].slice.call(arguments, 1).join(' ');
  5515. }
  5516. var args = [].slice.call(arguments, 2);
  5517. var parts = [strings.raw[0]];
  5518. for (var i = 1; i < strings.length; i++) {
  5519. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  5520. parts.push(String(strings.raw[i]));
  5521. }
  5522. return templates(chalk, parts.join(''));
  5523. }
  5524. Object.defineProperties(Chalk.prototype, styles);
  5525. module.exports = Chalk(); // eslint-disable-line new-cap
  5526. module.exports.supportsColor = stdoutColor;
  5527. module.exports.default = module.exports; // For TypeScript
  5528. });
  5529. var common = createCommonjsModule(function (module, exports) {
  5530. "use strict";
  5531. Object.defineProperty(exports, "__esModule", {
  5532. value: true
  5533. });
  5534. exports.commonDeprecatedHandler = function (keyOrPair, redirectTo, _ref) {
  5535. var descriptor = _ref.descriptor;
  5536. var messages = [`${chalk.default.yellow(typeof keyOrPair === 'string' ? descriptor.key(keyOrPair) : descriptor.pair(keyOrPair))} is deprecated`];
  5537. if (redirectTo) {
  5538. messages.push(`we now treat it as ${chalk.default.blue(typeof redirectTo === 'string' ? descriptor.key(redirectTo) : descriptor.pair(redirectTo))}`);
  5539. }
  5540. return messages.join('; ') + '.';
  5541. };
  5542. });
  5543. unwrapExports(common);
  5544. var deprecated = createCommonjsModule(function (module, exports) {
  5545. "use strict";
  5546. Object.defineProperty(exports, "__esModule", {
  5547. value: true
  5548. });
  5549. tslib_1.__exportStar(common, exports);
  5550. });
  5551. unwrapExports(deprecated);
  5552. var common$2 = createCommonjsModule(function (module, exports) {
  5553. "use strict";
  5554. Object.defineProperty(exports, "__esModule", {
  5555. value: true
  5556. });
  5557. exports.commonInvalidHandler = function (key, value, utils) {
  5558. 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(' ');
  5559. };
  5560. });
  5561. unwrapExports(common$2);
  5562. var invalid = createCommonjsModule(function (module, exports) {
  5563. "use strict";
  5564. Object.defineProperty(exports, "__esModule", {
  5565. value: true
  5566. });
  5567. tslib_1.__exportStar(common$2, exports);
  5568. });
  5569. unwrapExports(invalid);
  5570. /* eslint-disable no-nested-ternary */
  5571. var arr = [];
  5572. var charCodeCache = [];
  5573. var leven$1 = function leven(a, b) {
  5574. if (a === b) {
  5575. return 0;
  5576. }
  5577. var swap = a; // Swapping the strings if `a` is longer than `b` so we know which one is the
  5578. // shortest & which one is the longest
  5579. if (a.length > b.length) {
  5580. a = b;
  5581. b = swap;
  5582. }
  5583. var aLen = a.length;
  5584. var bLen = b.length;
  5585. if (aLen === 0) {
  5586. return bLen;
  5587. }
  5588. if (bLen === 0) {
  5589. return aLen;
  5590. } // Performing suffix trimming:
  5591. // We can linearly drop suffix common to both strings since they
  5592. // don't increase distance at all
  5593. // Note: `~-` is the bitwise way to perform a `- 1` operation
  5594. while (aLen > 0 && a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen)) {
  5595. aLen--;
  5596. bLen--;
  5597. }
  5598. if (aLen === 0) {
  5599. return bLen;
  5600. } // Performing prefix trimming
  5601. // We can linearly drop prefix common to both strings since they
  5602. // don't increase distance at all
  5603. var start = 0;
  5604. while (start < aLen && a.charCodeAt(start) === b.charCodeAt(start)) {
  5605. start++;
  5606. }
  5607. aLen -= start;
  5608. bLen -= start;
  5609. if (aLen === 0) {
  5610. return bLen;
  5611. }
  5612. var bCharCode;
  5613. var ret;
  5614. var tmp;
  5615. var tmp2;
  5616. var i = 0;
  5617. var j = 0;
  5618. while (i < aLen) {
  5619. charCodeCache[start + i] = a.charCodeAt(start + i);
  5620. arr[i] = ++i;
  5621. }
  5622. while (j < bLen) {
  5623. bCharCode = b.charCodeAt(start + j);
  5624. tmp = j++;
  5625. ret = j;
  5626. for (i = 0; i < aLen; i++) {
  5627. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  5628. tmp = arr[i];
  5629. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  5630. }
  5631. }
  5632. return ret;
  5633. };
  5634. var leven_1 = createCommonjsModule(function (module, exports) {
  5635. "use strict";
  5636. Object.defineProperty(exports, "__esModule", {
  5637. value: true
  5638. });
  5639. exports.levenUnknownHandler = function (key, value, _ref) {
  5640. var descriptor = _ref.descriptor,
  5641. logger = _ref.logger,
  5642. schemas = _ref.schemas;
  5643. var messages = [`Ignored unknown option ${chalk.default.yellow(descriptor.pair({
  5644. key,
  5645. value
  5646. }))}.`];
  5647. var suggestion = Object.keys(schemas).sort().find(function (knownKey) {
  5648. return leven$1(key, knownKey) < 3;
  5649. });
  5650. if (suggestion) {
  5651. messages.push(`Did you mean ${chalk.default.blue(descriptor.key(suggestion))}?`);
  5652. }
  5653. logger.warn(messages.join(' '));
  5654. };
  5655. });
  5656. unwrapExports(leven_1);
  5657. var unknown = createCommonjsModule(function (module, exports) {
  5658. "use strict";
  5659. Object.defineProperty(exports, "__esModule", {
  5660. value: true
  5661. });
  5662. tslib_1.__exportStar(leven_1, exports);
  5663. });
  5664. unwrapExports(unknown);
  5665. var handlers = createCommonjsModule(function (module, exports) {
  5666. "use strict";
  5667. Object.defineProperty(exports, "__esModule", {
  5668. value: true
  5669. });
  5670. tslib_1.__exportStar(deprecated, exports);
  5671. tslib_1.__exportStar(invalid, exports);
  5672. tslib_1.__exportStar(unknown, exports);
  5673. });
  5674. unwrapExports(handlers);
  5675. var schema = createCommonjsModule(function (module, exports) {
  5676. "use strict";
  5677. Object.defineProperty(exports, "__esModule", {
  5678. value: true
  5679. });
  5680. var HANDLER_KEYS = ['default', 'expected', 'validate', 'deprecated', 'forward', 'redirect', 'overlap', 'preprocess', 'postprocess'];
  5681. function createSchema(SchemaConstructor, parameters) {
  5682. var schema = new SchemaConstructor(parameters);
  5683. var subSchema = Object.create(schema);
  5684. for (var _i = 0; _i < HANDLER_KEYS.length; _i++) {
  5685. var handlerKey = HANDLER_KEYS[_i];
  5686. if (handlerKey in parameters) {
  5687. subSchema[handlerKey] = normalizeHandler(parameters[handlerKey], schema, Schema.prototype[handlerKey].length);
  5688. }
  5689. }
  5690. return subSchema;
  5691. }
  5692. exports.createSchema = createSchema;
  5693. var Schema =
  5694. /*#__PURE__*/
  5695. function () {
  5696. function Schema(parameters) {
  5697. _classCallCheck(this, Schema);
  5698. this.name = parameters.name;
  5699. }
  5700. _createClass(Schema, [{
  5701. key: "default",
  5702. value: function _default(_utils) {
  5703. return undefined;
  5704. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  5705. }, {
  5706. key: "expected",
  5707. value: function expected(_utils) {
  5708. return 'nothing';
  5709. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  5710. }, {
  5711. key: "validate",
  5712. value: function validate(_value, _utils) {
  5713. return false;
  5714. }
  5715. }, {
  5716. key: "deprecated",
  5717. value: function deprecated(_value, _utils) {
  5718. return false;
  5719. }
  5720. }, {
  5721. key: "forward",
  5722. value: function forward(_value, _utils) {
  5723. return undefined;
  5724. }
  5725. }, {
  5726. key: "redirect",
  5727. value: function redirect(_value, _utils) {
  5728. return undefined;
  5729. }
  5730. }, {
  5731. key: "overlap",
  5732. value: function overlap(currentValue, _newValue, _utils) {
  5733. return currentValue;
  5734. }
  5735. }, {
  5736. key: "preprocess",
  5737. value: function preprocess(value, _utils) {
  5738. return value;
  5739. }
  5740. }, {
  5741. key: "postprocess",
  5742. value: function postprocess(value, _utils) {
  5743. return value;
  5744. }
  5745. }], [{
  5746. key: "create",
  5747. value: function create(parameters) {
  5748. // @ts-ignore: https://github.com/Microsoft/TypeScript/issues/5863
  5749. return createSchema(this, parameters);
  5750. }
  5751. }]);
  5752. return Schema;
  5753. }();
  5754. exports.Schema = Schema;
  5755. function normalizeHandler(handler, superSchema, handlerArgumentsLength) {
  5756. return typeof handler === 'function' ? function () {
  5757. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5758. args[_key] = arguments[_key];
  5759. }
  5760. return handler.apply(void 0, _toConsumableArray(args.slice(0, handlerArgumentsLength - 1)).concat([superSchema], _toConsumableArray(args.slice(handlerArgumentsLength - 1))));
  5761. } : function () {
  5762. return handler;
  5763. };
  5764. }
  5765. });
  5766. unwrapExports(schema);
  5767. var alias = createCommonjsModule(function (module, exports) {
  5768. "use strict";
  5769. Object.defineProperty(exports, "__esModule", {
  5770. value: true
  5771. });
  5772. var AliasSchema =
  5773. /*#__PURE__*/
  5774. function (_schema_1$Schema) {
  5775. _inherits(AliasSchema, _schema_1$Schema);
  5776. function AliasSchema(parameters) {
  5777. var _this;
  5778. _classCallCheck(this, AliasSchema);
  5779. _this = _possibleConstructorReturn(this, _getPrototypeOf(AliasSchema).call(this, parameters));
  5780. _this._sourceName = parameters.sourceName;
  5781. return _this;
  5782. }
  5783. _createClass(AliasSchema, [{
  5784. key: "expected",
  5785. value: function expected(utils) {
  5786. return utils.schemas[this._sourceName].expected(utils);
  5787. }
  5788. }, {
  5789. key: "validate",
  5790. value: function validate(value, utils) {
  5791. return utils.schemas[this._sourceName].validate(value, utils);
  5792. }
  5793. }, {
  5794. key: "redirect",
  5795. value: function redirect(_value, _utils) {
  5796. return this._sourceName;
  5797. }
  5798. }]);
  5799. return AliasSchema;
  5800. }(schema.Schema);
  5801. exports.AliasSchema = AliasSchema;
  5802. });
  5803. unwrapExports(alias);
  5804. var any = createCommonjsModule(function (module, exports) {
  5805. "use strict";
  5806. Object.defineProperty(exports, "__esModule", {
  5807. value: true
  5808. });
  5809. var AnySchema =
  5810. /*#__PURE__*/
  5811. function (_schema_1$Schema) {
  5812. _inherits(AnySchema, _schema_1$Schema);
  5813. function AnySchema() {
  5814. _classCallCheck(this, AnySchema);
  5815. return _possibleConstructorReturn(this, _getPrototypeOf(AnySchema).apply(this, arguments));
  5816. }
  5817. _createClass(AnySchema, [{
  5818. key: "expected",
  5819. value: function expected() {
  5820. return 'anything';
  5821. }
  5822. }, {
  5823. key: "validate",
  5824. value: function validate() {
  5825. return true;
  5826. }
  5827. }]);
  5828. return AnySchema;
  5829. }(schema.Schema);
  5830. exports.AnySchema = AnySchema;
  5831. });
  5832. unwrapExports(any);
  5833. var array$2 = createCommonjsModule(function (module, exports) {
  5834. "use strict";
  5835. Object.defineProperty(exports, "__esModule", {
  5836. value: true
  5837. });
  5838. var ArraySchema =
  5839. /*#__PURE__*/
  5840. function (_schema_1$Schema) {
  5841. _inherits(ArraySchema, _schema_1$Schema);
  5842. function ArraySchema(_a) {
  5843. var _this;
  5844. _classCallCheck(this, ArraySchema);
  5845. var valueSchema = _a.valueSchema,
  5846. _a$name = _a.name,
  5847. name = _a$name === void 0 ? valueSchema.name : _a$name,
  5848. handlers = tslib_1.__rest(_a, ["valueSchema", "name"]);
  5849. _this = _possibleConstructorReturn(this, _getPrototypeOf(ArraySchema).call(this, Object.assign({}, handlers, {
  5850. name
  5851. })));
  5852. _this._valueSchema = valueSchema;
  5853. return _this;
  5854. }
  5855. _createClass(ArraySchema, [{
  5856. key: "expected",
  5857. value: function expected(utils) {
  5858. return `an array of ${this._valueSchema.expected(utils)}`;
  5859. }
  5860. }, {
  5861. key: "validate",
  5862. value: function validate(value, utils) {
  5863. if (!Array.isArray(value)) {
  5864. return false;
  5865. }
  5866. var invalidValues = [];
  5867. var _iteratorNormalCompletion = true;
  5868. var _didIteratorError = false;
  5869. var _iteratorError = undefined;
  5870. try {
  5871. for (var _iterator = value[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5872. var subValue = _step.value;
  5873. var subValidateResult = utils.normalizeValidateResult(this._valueSchema.validate(subValue, utils), subValue);
  5874. if (subValidateResult !== true) {
  5875. invalidValues.push(subValidateResult.value);
  5876. }
  5877. }
  5878. } catch (err) {
  5879. _didIteratorError = true;
  5880. _iteratorError = err;
  5881. } finally {
  5882. try {
  5883. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5884. _iterator.return();
  5885. }
  5886. } finally {
  5887. if (_didIteratorError) {
  5888. throw _iteratorError;
  5889. }
  5890. }
  5891. }
  5892. return invalidValues.length === 0 ? true : {
  5893. value: invalidValues
  5894. };
  5895. }
  5896. }, {
  5897. key: "deprecated",
  5898. value: function deprecated(value, utils) {
  5899. var deprecatedResult = [];
  5900. var _iteratorNormalCompletion2 = true;
  5901. var _didIteratorError2 = false;
  5902. var _iteratorError2 = undefined;
  5903. try {
  5904. for (var _iterator2 = value[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5905. var subValue = _step2.value;
  5906. var subDeprecatedResult = utils.normalizeDeprecatedResult(this._valueSchema.deprecated(subValue, utils), subValue);
  5907. if (subDeprecatedResult !== false) {
  5908. deprecatedResult.push.apply(deprecatedResult, _toConsumableArray(subDeprecatedResult.map(function (_ref) {
  5909. var deprecatedValue = _ref.value;
  5910. return {
  5911. value: [deprecatedValue]
  5912. };
  5913. })));
  5914. }
  5915. }
  5916. } catch (err) {
  5917. _didIteratorError2 = true;
  5918. _iteratorError2 = err;
  5919. } finally {
  5920. try {
  5921. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5922. _iterator2.return();
  5923. }
  5924. } finally {
  5925. if (_didIteratorError2) {
  5926. throw _iteratorError2;
  5927. }
  5928. }
  5929. }
  5930. return deprecatedResult;
  5931. }
  5932. }, {
  5933. key: "forward",
  5934. value: function forward(value, utils) {
  5935. var forwardResult = [];
  5936. var _iteratorNormalCompletion3 = true;
  5937. var _didIteratorError3 = false;
  5938. var _iteratorError3 = undefined;
  5939. try {
  5940. for (var _iterator3 = value[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  5941. var subValue = _step3.value;
  5942. var subForwardResult = utils.normalizeForwardResult(this._valueSchema.forward(subValue, utils), subValue);
  5943. forwardResult.push.apply(forwardResult, _toConsumableArray(subForwardResult.map(wrapTransferResult)));
  5944. }
  5945. } catch (err) {
  5946. _didIteratorError3 = true;
  5947. _iteratorError3 = err;
  5948. } finally {
  5949. try {
  5950. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  5951. _iterator3.return();
  5952. }
  5953. } finally {
  5954. if (_didIteratorError3) {
  5955. throw _iteratorError3;
  5956. }
  5957. }
  5958. }
  5959. return forwardResult;
  5960. }
  5961. }, {
  5962. key: "redirect",
  5963. value: function redirect(value, utils) {
  5964. var remain = [];
  5965. var redirect = [];
  5966. var _iteratorNormalCompletion4 = true;
  5967. var _didIteratorError4 = false;
  5968. var _iteratorError4 = undefined;
  5969. try {
  5970. for (var _iterator4 = value[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  5971. var subValue = _step4.value;
  5972. var subRedirectResult = utils.normalizeRedirectResult(this._valueSchema.redirect(subValue, utils), subValue);
  5973. if ('remain' in subRedirectResult) {
  5974. remain.push(subRedirectResult.remain);
  5975. }
  5976. redirect.push.apply(redirect, _toConsumableArray(subRedirectResult.redirect.map(wrapTransferResult)));
  5977. }
  5978. } catch (err) {
  5979. _didIteratorError4 = true;
  5980. _iteratorError4 = err;
  5981. } finally {
  5982. try {
  5983. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  5984. _iterator4.return();
  5985. }
  5986. } finally {
  5987. if (_didIteratorError4) {
  5988. throw _iteratorError4;
  5989. }
  5990. }
  5991. }
  5992. return remain.length === 0 ? {
  5993. redirect
  5994. } : {
  5995. redirect,
  5996. remain
  5997. };
  5998. }
  5999. }, {
  6000. key: "overlap",
  6001. value: function overlap(currentValue, newValue) {
  6002. return currentValue.concat(newValue);
  6003. }
  6004. }]);
  6005. return ArraySchema;
  6006. }(schema.Schema);
  6007. exports.ArraySchema = ArraySchema;
  6008. function wrapTransferResult(_ref2) {
  6009. var from = _ref2.from,
  6010. to = _ref2.to;
  6011. return {
  6012. from: [from],
  6013. to
  6014. };
  6015. }
  6016. });
  6017. unwrapExports(array$2);
  6018. var boolean_1 = createCommonjsModule(function (module, exports) {
  6019. "use strict";
  6020. Object.defineProperty(exports, "__esModule", {
  6021. value: true
  6022. });
  6023. var BooleanSchema =
  6024. /*#__PURE__*/
  6025. function (_schema_1$Schema) {
  6026. _inherits(BooleanSchema, _schema_1$Schema);
  6027. function BooleanSchema() {
  6028. _classCallCheck(this, BooleanSchema);
  6029. return _possibleConstructorReturn(this, _getPrototypeOf(BooleanSchema).apply(this, arguments));
  6030. }
  6031. _createClass(BooleanSchema, [{
  6032. key: "expected",
  6033. value: function expected() {
  6034. return 'true or false';
  6035. }
  6036. }, {
  6037. key: "validate",
  6038. value: function validate(value) {
  6039. return typeof value === 'boolean';
  6040. }
  6041. }]);
  6042. return BooleanSchema;
  6043. }(schema.Schema);
  6044. exports.BooleanSchema = BooleanSchema;
  6045. });
  6046. unwrapExports(boolean_1);
  6047. var utils = createCommonjsModule(function (module, exports) {
  6048. "use strict";
  6049. Object.defineProperty(exports, "__esModule", {
  6050. value: true
  6051. });
  6052. function recordFromArray(array, mainKey) {
  6053. var record = Object.create(null);
  6054. var _iteratorNormalCompletion = true;
  6055. var _didIteratorError = false;
  6056. var _iteratorError = undefined;
  6057. try {
  6058. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6059. var value = _step.value;
  6060. var key = value[mainKey]; // istanbul ignore next
  6061. if (record[key]) {
  6062. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6063. } // @ts-ignore
  6064. record[key] = value;
  6065. }
  6066. } catch (err) {
  6067. _didIteratorError = true;
  6068. _iteratorError = err;
  6069. } finally {
  6070. try {
  6071. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6072. _iterator.return();
  6073. }
  6074. } finally {
  6075. if (_didIteratorError) {
  6076. throw _iteratorError;
  6077. }
  6078. }
  6079. }
  6080. return record;
  6081. }
  6082. exports.recordFromArray = recordFromArray;
  6083. function mapFromArray(array, mainKey) {
  6084. var map = new Map();
  6085. var _iteratorNormalCompletion2 = true;
  6086. var _didIteratorError2 = false;
  6087. var _iteratorError2 = undefined;
  6088. try {
  6089. for (var _iterator2 = array[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6090. var value = _step2.value;
  6091. var key = value[mainKey]; // istanbul ignore next
  6092. if (map.has(key)) {
  6093. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6094. }
  6095. map.set(key, value);
  6096. }
  6097. } catch (err) {
  6098. _didIteratorError2 = true;
  6099. _iteratorError2 = err;
  6100. } finally {
  6101. try {
  6102. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6103. _iterator2.return();
  6104. }
  6105. } finally {
  6106. if (_didIteratorError2) {
  6107. throw _iteratorError2;
  6108. }
  6109. }
  6110. }
  6111. return map;
  6112. }
  6113. exports.mapFromArray = mapFromArray;
  6114. function createAutoChecklist() {
  6115. var map = Object.create(null);
  6116. return function (id) {
  6117. var idString = JSON.stringify(id);
  6118. if (map[idString]) {
  6119. return true;
  6120. }
  6121. map[idString] = true;
  6122. return false;
  6123. };
  6124. }
  6125. exports.createAutoChecklist = createAutoChecklist;
  6126. function partition(array, predicate) {
  6127. var trueArray = [];
  6128. var falseArray = [];
  6129. var _iteratorNormalCompletion3 = true;
  6130. var _didIteratorError3 = false;
  6131. var _iteratorError3 = undefined;
  6132. try {
  6133. for (var _iterator3 = array[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6134. var value = _step3.value;
  6135. if (predicate(value)) {
  6136. trueArray.push(value);
  6137. } else {
  6138. falseArray.push(value);
  6139. }
  6140. }
  6141. } catch (err) {
  6142. _didIteratorError3 = true;
  6143. _iteratorError3 = err;
  6144. } finally {
  6145. try {
  6146. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6147. _iterator3.return();
  6148. }
  6149. } finally {
  6150. if (_didIteratorError3) {
  6151. throw _iteratorError3;
  6152. }
  6153. }
  6154. }
  6155. return [trueArray, falseArray];
  6156. }
  6157. exports.partition = partition;
  6158. function isInt(value) {
  6159. return value === Math.floor(value);
  6160. }
  6161. exports.isInt = isInt;
  6162. function comparePrimitive(a, b) {
  6163. if (a === b) {
  6164. return 0;
  6165. }
  6166. var typeofA = typeof a;
  6167. var typeofB = typeof b;
  6168. var orders = ['undefined', 'object', 'boolean', 'number', 'string'];
  6169. if (typeofA !== typeofB) {
  6170. return orders.indexOf(typeofA) - orders.indexOf(typeofB);
  6171. }
  6172. if (typeofA !== 'string') {
  6173. return Number(a) - Number(b);
  6174. }
  6175. return a.localeCompare(b);
  6176. }
  6177. exports.comparePrimitive = comparePrimitive;
  6178. function normalizeDefaultResult(result) {
  6179. return result === undefined ? {} : result;
  6180. }
  6181. exports.normalizeDefaultResult = normalizeDefaultResult;
  6182. function normalizeValidateResult(result, value) {
  6183. return result === true ? true : result === false ? {
  6184. value
  6185. } : result;
  6186. }
  6187. exports.normalizeValidateResult = normalizeValidateResult;
  6188. function normalizeDeprecatedResult(result, value) {
  6189. var doNotNormalizeTrue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6190. return result === false ? false : result === true ? doNotNormalizeTrue ? true : [{
  6191. value
  6192. }] : 'value' in result ? [result] : result.length === 0 ? false : result;
  6193. }
  6194. exports.normalizeDeprecatedResult = normalizeDeprecatedResult;
  6195. function normalizeTransferResult(result, value) {
  6196. return typeof result === 'string' || 'key' in result ? {
  6197. from: value,
  6198. to: result
  6199. } : 'from' in result ? {
  6200. from: result.from,
  6201. to: result.to
  6202. } : {
  6203. from: value,
  6204. to: result.to
  6205. };
  6206. }
  6207. exports.normalizeTransferResult = normalizeTransferResult;
  6208. function normalizeForwardResult(result, value) {
  6209. return result === undefined ? [] : Array.isArray(result) ? result.map(function (transferResult) {
  6210. return normalizeTransferResult(transferResult, value);
  6211. }) : [normalizeTransferResult(result, value)];
  6212. }
  6213. exports.normalizeForwardResult = normalizeForwardResult;
  6214. function normalizeRedirectResult(result, value) {
  6215. var redirect = normalizeForwardResult(typeof result === 'object' && 'redirect' in result ? result.redirect : result, value);
  6216. return redirect.length === 0 ? {
  6217. remain: value,
  6218. redirect
  6219. } : typeof result === 'object' && 'remain' in result ? {
  6220. remain: result.remain,
  6221. redirect
  6222. } : {
  6223. redirect
  6224. };
  6225. }
  6226. exports.normalizeRedirectResult = normalizeRedirectResult;
  6227. });
  6228. unwrapExports(utils);
  6229. var choice = createCommonjsModule(function (module, exports) {
  6230. "use strict";
  6231. Object.defineProperty(exports, "__esModule", {
  6232. value: true
  6233. });
  6234. var ChoiceSchema =
  6235. /*#__PURE__*/
  6236. function (_schema_1$Schema) {
  6237. _inherits(ChoiceSchema, _schema_1$Schema);
  6238. function ChoiceSchema(parameters) {
  6239. var _this;
  6240. _classCallCheck(this, ChoiceSchema);
  6241. _this = _possibleConstructorReturn(this, _getPrototypeOf(ChoiceSchema).call(this, parameters));
  6242. _this._choices = utils.mapFromArray(parameters.choices.map(function (choice) {
  6243. return choice && typeof choice === 'object' ? choice : {
  6244. value: choice
  6245. };
  6246. }), 'value');
  6247. return _this;
  6248. }
  6249. _createClass(ChoiceSchema, [{
  6250. key: "expected",
  6251. value: function expected(_ref) {
  6252. var _this2 = this;
  6253. var descriptor = _ref.descriptor;
  6254. var choiceValues = Array.from(this._choices.keys()).map(function (value) {
  6255. return _this2._choices.get(value);
  6256. }).filter(function (choiceInfo) {
  6257. return !choiceInfo.deprecated;
  6258. }).map(function (choiceInfo) {
  6259. return choiceInfo.value;
  6260. }).sort(utils.comparePrimitive).map(descriptor.value);
  6261. var head = choiceValues.slice(0, -2);
  6262. var tail = choiceValues.slice(-2);
  6263. return head.concat(tail.join(' or ')).join(', ');
  6264. }
  6265. }, {
  6266. key: "validate",
  6267. value: function validate(value) {
  6268. return this._choices.has(value);
  6269. }
  6270. }, {
  6271. key: "deprecated",
  6272. value: function deprecated(value) {
  6273. var choiceInfo = this._choices.get(value);
  6274. return choiceInfo && choiceInfo.deprecated ? {
  6275. value
  6276. } : false;
  6277. }
  6278. }, {
  6279. key: "forward",
  6280. value: function forward(value) {
  6281. var choiceInfo = this._choices.get(value);
  6282. return choiceInfo ? choiceInfo.forward : undefined;
  6283. }
  6284. }, {
  6285. key: "redirect",
  6286. value: function redirect(value) {
  6287. var choiceInfo = this._choices.get(value);
  6288. return choiceInfo ? choiceInfo.redirect : undefined;
  6289. }
  6290. }]);
  6291. return ChoiceSchema;
  6292. }(schema.Schema);
  6293. exports.ChoiceSchema = ChoiceSchema;
  6294. });
  6295. unwrapExports(choice);
  6296. var number = createCommonjsModule(function (module, exports) {
  6297. "use strict";
  6298. Object.defineProperty(exports, "__esModule", {
  6299. value: true
  6300. });
  6301. var NumberSchema =
  6302. /*#__PURE__*/
  6303. function (_schema_1$Schema) {
  6304. _inherits(NumberSchema, _schema_1$Schema);
  6305. function NumberSchema() {
  6306. _classCallCheck(this, NumberSchema);
  6307. return _possibleConstructorReturn(this, _getPrototypeOf(NumberSchema).apply(this, arguments));
  6308. }
  6309. _createClass(NumberSchema, [{
  6310. key: "expected",
  6311. value: function expected() {
  6312. return 'a number';
  6313. }
  6314. }, {
  6315. key: "validate",
  6316. value: function validate(value, _utils) {
  6317. return typeof value === 'number';
  6318. }
  6319. }]);
  6320. return NumberSchema;
  6321. }(schema.Schema);
  6322. exports.NumberSchema = NumberSchema;
  6323. });
  6324. unwrapExports(number);
  6325. var integer = createCommonjsModule(function (module, exports) {
  6326. "use strict";
  6327. Object.defineProperty(exports, "__esModule", {
  6328. value: true
  6329. });
  6330. var IntegerSchema =
  6331. /*#__PURE__*/
  6332. function (_number_1$NumberSchem) {
  6333. _inherits(IntegerSchema, _number_1$NumberSchem);
  6334. function IntegerSchema() {
  6335. _classCallCheck(this, IntegerSchema);
  6336. return _possibleConstructorReturn(this, _getPrototypeOf(IntegerSchema).apply(this, arguments));
  6337. }
  6338. _createClass(IntegerSchema, [{
  6339. key: "expected",
  6340. value: function expected() {
  6341. return 'an integer';
  6342. }
  6343. }, {
  6344. key: "validate",
  6345. value: function validate(value, utils$$2) {
  6346. return utils$$2.normalizeValidateResult(_get(_getPrototypeOf(IntegerSchema.prototype), "validate", this).call(this, value, utils$$2), value) === true && utils.isInt(value);
  6347. }
  6348. }]);
  6349. return IntegerSchema;
  6350. }(number.NumberSchema);
  6351. exports.IntegerSchema = IntegerSchema;
  6352. });
  6353. unwrapExports(integer);
  6354. var string = createCommonjsModule(function (module, exports) {
  6355. "use strict";
  6356. Object.defineProperty(exports, "__esModule", {
  6357. value: true
  6358. });
  6359. var StringSchema =
  6360. /*#__PURE__*/
  6361. function (_schema_1$Schema) {
  6362. _inherits(StringSchema, _schema_1$Schema);
  6363. function StringSchema() {
  6364. _classCallCheck(this, StringSchema);
  6365. return _possibleConstructorReturn(this, _getPrototypeOf(StringSchema).apply(this, arguments));
  6366. }
  6367. _createClass(StringSchema, [{
  6368. key: "expected",
  6369. value: function expected() {
  6370. return 'a string';
  6371. }
  6372. }, {
  6373. key: "validate",
  6374. value: function validate(value) {
  6375. return typeof value === 'string';
  6376. }
  6377. }]);
  6378. return StringSchema;
  6379. }(schema.Schema);
  6380. exports.StringSchema = StringSchema;
  6381. });
  6382. unwrapExports(string);
  6383. var schemas = createCommonjsModule(function (module, exports) {
  6384. "use strict";
  6385. Object.defineProperty(exports, "__esModule", {
  6386. value: true
  6387. });
  6388. tslib_1.__exportStar(alias, exports);
  6389. tslib_1.__exportStar(any, exports);
  6390. tslib_1.__exportStar(array$2, exports);
  6391. tslib_1.__exportStar(boolean_1, exports);
  6392. tslib_1.__exportStar(choice, exports);
  6393. tslib_1.__exportStar(integer, exports);
  6394. tslib_1.__exportStar(number, exports);
  6395. tslib_1.__exportStar(string, exports);
  6396. });
  6397. unwrapExports(schemas);
  6398. var defaults = createCommonjsModule(function (module, exports) {
  6399. "use strict";
  6400. Object.defineProperty(exports, "__esModule", {
  6401. value: true
  6402. });
  6403. exports.defaultDescriptor = api.apiDescriptor;
  6404. exports.defaultUnknownHandler = leven_1.levenUnknownHandler;
  6405. exports.defaultInvalidHandler = invalid.commonInvalidHandler;
  6406. exports.defaultDeprecatedHandler = common.commonDeprecatedHandler;
  6407. });
  6408. unwrapExports(defaults);
  6409. var normalize$1 = createCommonjsModule(function (module, exports) {
  6410. "use strict";
  6411. Object.defineProperty(exports, "__esModule", {
  6412. value: true
  6413. });
  6414. exports.normalize = function (options, schemas, opts) {
  6415. return new Normalizer(schemas, opts).normalize(options);
  6416. };
  6417. var Normalizer =
  6418. /*#__PURE__*/
  6419. function () {
  6420. function Normalizer(schemas, opts) {
  6421. _classCallCheck(this, Normalizer);
  6422. // istanbul ignore next
  6423. var _ref = opts || {},
  6424. _ref$logger = _ref.logger,
  6425. logger = _ref$logger === void 0 ? console : _ref$logger,
  6426. _ref$descriptor = _ref.descriptor,
  6427. descriptor = _ref$descriptor === void 0 ? defaults.defaultDescriptor : _ref$descriptor,
  6428. _ref$unknown = _ref.unknown,
  6429. unknown = _ref$unknown === void 0 ? defaults.defaultUnknownHandler : _ref$unknown,
  6430. _ref$invalid = _ref.invalid,
  6431. invalid = _ref$invalid === void 0 ? defaults.defaultInvalidHandler : _ref$invalid,
  6432. _ref$deprecated = _ref.deprecated,
  6433. deprecated = _ref$deprecated === void 0 ? defaults.defaultDeprecatedHandler : _ref$deprecated;
  6434. this._utils = {
  6435. descriptor,
  6436. logger:
  6437. /* istanbul ignore next */
  6438. logger || {
  6439. warn: function warn() {}
  6440. },
  6441. schemas: utils.recordFromArray(schemas, 'name'),
  6442. normalizeDefaultResult: utils.normalizeDefaultResult,
  6443. normalizeDeprecatedResult: utils.normalizeDeprecatedResult,
  6444. normalizeForwardResult: utils.normalizeForwardResult,
  6445. normalizeRedirectResult: utils.normalizeRedirectResult,
  6446. normalizeValidateResult: utils.normalizeValidateResult
  6447. };
  6448. this._unknownHandler = unknown;
  6449. this._invalidHandler = invalid;
  6450. this._deprecatedHandler = deprecated;
  6451. this.cleanHistory();
  6452. }
  6453. _createClass(Normalizer, [{
  6454. key: "cleanHistory",
  6455. value: function cleanHistory() {
  6456. this._hasDeprecationWarned = utils.createAutoChecklist();
  6457. }
  6458. }, {
  6459. key: "normalize",
  6460. value: function normalize(options) {
  6461. var _this = this;
  6462. var normalized = {};
  6463. var restOptionsArray = [options];
  6464. var applyNormalization = function applyNormalization() {
  6465. while (restOptionsArray.length !== 0) {
  6466. var currentOptions = restOptionsArray.shift();
  6467. var transferredOptionsArray = _this._applyNormalization(currentOptions, normalized);
  6468. restOptionsArray.push.apply(restOptionsArray, _toConsumableArray(transferredOptionsArray));
  6469. }
  6470. };
  6471. applyNormalization();
  6472. var _arr = Object.keys(this._utils.schemas);
  6473. for (var _i = 0; _i < _arr.length; _i++) {
  6474. var key = _arr[_i];
  6475. var schema = this._utils.schemas[key];
  6476. if (!(key in normalized)) {
  6477. var defaultResult = utils.normalizeDefaultResult(schema.default(this._utils));
  6478. if ('value' in defaultResult) {
  6479. restOptionsArray.push({
  6480. [key]: defaultResult.value
  6481. });
  6482. }
  6483. }
  6484. }
  6485. applyNormalization();
  6486. var _arr2 = Object.keys(this._utils.schemas);
  6487. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  6488. var _key = _arr2[_i2];
  6489. var _schema = this._utils.schemas[_key];
  6490. if (_key in normalized) {
  6491. normalized[_key] = _schema.postprocess(normalized[_key], this._utils);
  6492. }
  6493. }
  6494. return normalized;
  6495. }
  6496. }, {
  6497. key: "_applyNormalization",
  6498. value: function _applyNormalization(options, normalized) {
  6499. var _this2 = this;
  6500. var transferredOptionsArray = [];
  6501. var _utils_1$partition = utils.partition(Object.keys(options), function (key) {
  6502. return key in _this2._utils.schemas;
  6503. }),
  6504. _utils_1$partition2 = _slicedToArray(_utils_1$partition, 2),
  6505. knownOptionNames = _utils_1$partition2[0],
  6506. unknownOptionNames = _utils_1$partition2[1];
  6507. var _iteratorNormalCompletion = true;
  6508. var _didIteratorError = false;
  6509. var _iteratorError = undefined;
  6510. try {
  6511. var _loop = function _loop() {
  6512. var key = _step.value;
  6513. var schema = _this2._utils.schemas[key];
  6514. var value = schema.preprocess(options[key], _this2._utils);
  6515. var validateResult = utils.normalizeValidateResult(schema.validate(value, _this2._utils), value);
  6516. if (validateResult !== true) {
  6517. var invalidValue = validateResult.value;
  6518. var errorMessageOrError = _this2._invalidHandler(key, invalidValue, _this2._utils);
  6519. throw typeof errorMessageOrError === 'string' ? new Error(errorMessageOrError) :
  6520. /* istanbul ignore next*/
  6521. errorMessageOrError;
  6522. }
  6523. var appendTransferredOptions = function appendTransferredOptions(_ref2) {
  6524. var from = _ref2.from,
  6525. to = _ref2.to;
  6526. transferredOptionsArray.push(typeof to === 'string' ? {
  6527. [to]: from
  6528. } : {
  6529. [to.key]: to.value
  6530. });
  6531. };
  6532. var warnDeprecated = function warnDeprecated(_ref3) {
  6533. var currentValue = _ref3.value,
  6534. redirectTo = _ref3.redirectTo;
  6535. var deprecatedResult = utils.normalizeDeprecatedResult(schema.deprecated(currentValue, _this2._utils), value,
  6536. /* doNotNormalizeTrue */
  6537. true);
  6538. if (deprecatedResult === false) {
  6539. return;
  6540. }
  6541. if (deprecatedResult === true) {
  6542. if (!_this2._hasDeprecationWarned(key)) {
  6543. _this2._utils.logger.warn(_this2._deprecatedHandler(key, redirectTo, _this2._utils));
  6544. }
  6545. } else {
  6546. var _iteratorNormalCompletion3 = true;
  6547. var _didIteratorError3 = false;
  6548. var _iteratorError3 = undefined;
  6549. try {
  6550. for (var _iterator3 = deprecatedResult[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6551. var deprecatedValue = _step3.value.value;
  6552. var pair = {
  6553. key,
  6554. value: deprecatedValue
  6555. };
  6556. if (!_this2._hasDeprecationWarned(pair)) {
  6557. var redirectToPair = typeof redirectTo === 'string' ? {
  6558. key: redirectTo,
  6559. value: deprecatedValue
  6560. } : redirectTo;
  6561. _this2._utils.logger.warn(_this2._deprecatedHandler(pair, redirectToPair, _this2._utils));
  6562. }
  6563. }
  6564. } catch (err) {
  6565. _didIteratorError3 = true;
  6566. _iteratorError3 = err;
  6567. } finally {
  6568. try {
  6569. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6570. _iterator3.return();
  6571. }
  6572. } finally {
  6573. if (_didIteratorError3) {
  6574. throw _iteratorError3;
  6575. }
  6576. }
  6577. }
  6578. }
  6579. };
  6580. var forwardResult = utils.normalizeForwardResult(schema.forward(value, _this2._utils), value);
  6581. forwardResult.forEach(appendTransferredOptions);
  6582. var redirectResult = utils.normalizeRedirectResult(schema.redirect(value, _this2._utils), value);
  6583. redirectResult.redirect.forEach(appendTransferredOptions);
  6584. if ('remain' in redirectResult) {
  6585. var remainingValue = redirectResult.remain;
  6586. normalized[key] = key in normalized ? schema.overlap(normalized[key], remainingValue, _this2._utils) : remainingValue;
  6587. warnDeprecated({
  6588. value: remainingValue
  6589. });
  6590. }
  6591. var _iteratorNormalCompletion4 = true;
  6592. var _didIteratorError4 = false;
  6593. var _iteratorError4 = undefined;
  6594. try {
  6595. for (var _iterator4 = redirectResult.redirect[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  6596. var _step4$value = _step4.value,
  6597. from = _step4$value.from,
  6598. to = _step4$value.to;
  6599. warnDeprecated({
  6600. value: from,
  6601. redirectTo: to
  6602. });
  6603. }
  6604. } catch (err) {
  6605. _didIteratorError4 = true;
  6606. _iteratorError4 = err;
  6607. } finally {
  6608. try {
  6609. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  6610. _iterator4.return();
  6611. }
  6612. } finally {
  6613. if (_didIteratorError4) {
  6614. throw _iteratorError4;
  6615. }
  6616. }
  6617. }
  6618. };
  6619. for (var _iterator = knownOptionNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6620. _loop();
  6621. }
  6622. } catch (err) {
  6623. _didIteratorError = true;
  6624. _iteratorError = err;
  6625. } finally {
  6626. try {
  6627. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6628. _iterator.return();
  6629. }
  6630. } finally {
  6631. if (_didIteratorError) {
  6632. throw _iteratorError;
  6633. }
  6634. }
  6635. }
  6636. var _iteratorNormalCompletion2 = true;
  6637. var _didIteratorError2 = false;
  6638. var _iteratorError2 = undefined;
  6639. try {
  6640. for (var _iterator2 = unknownOptionNames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6641. var key = _step2.value;
  6642. var value = options[key];
  6643. var unknownResult = this._unknownHandler(key, value, this._utils);
  6644. if (unknownResult) {
  6645. var _arr3 = Object.keys(unknownResult);
  6646. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  6647. var unknownKey = _arr3[_i3];
  6648. var unknownOption = {
  6649. [unknownKey]: unknownResult[unknownKey]
  6650. };
  6651. if (unknownKey in this._utils.schemas) {
  6652. transferredOptionsArray.push(unknownOption);
  6653. } else {
  6654. Object.assign(normalized, unknownOption);
  6655. }
  6656. }
  6657. }
  6658. }
  6659. } catch (err) {
  6660. _didIteratorError2 = true;
  6661. _iteratorError2 = err;
  6662. } finally {
  6663. try {
  6664. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6665. _iterator2.return();
  6666. }
  6667. } finally {
  6668. if (_didIteratorError2) {
  6669. throw _iteratorError2;
  6670. }
  6671. }
  6672. }
  6673. return transferredOptionsArray;
  6674. }
  6675. }]);
  6676. return Normalizer;
  6677. }();
  6678. exports.Normalizer = Normalizer;
  6679. });
  6680. unwrapExports(normalize$1);
  6681. var lib$1 = createCommonjsModule(function (module, exports) {
  6682. "use strict";
  6683. Object.defineProperty(exports, "__esModule", {
  6684. value: true
  6685. });
  6686. tslib_1.__exportStar(descriptors, exports);
  6687. tslib_1.__exportStar(handlers, exports);
  6688. tslib_1.__exportStar(schemas, exports);
  6689. tslib_1.__exportStar(normalize$1, exports);
  6690. tslib_1.__exportStar(schema, exports);
  6691. });
  6692. unwrapExports(lib$1);
  6693. var hasFlag$3 = function hasFlag(flag, argv) {
  6694. argv = argv || process.argv;
  6695. var terminatorPos = argv.indexOf('--');
  6696. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  6697. var pos = argv.indexOf(prefix + flag);
  6698. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  6699. };
  6700. var supportsColor$1 = createCommonjsModule(function (module) {
  6701. 'use strict';
  6702. var env = process.env;
  6703. var support = function support(level) {
  6704. if (level === 0) {
  6705. return false;
  6706. }
  6707. return {
  6708. level,
  6709. hasBasic: true,
  6710. has256: level >= 2,
  6711. has16m: level >= 3
  6712. };
  6713. };
  6714. var supportLevel = function () {
  6715. if (hasFlag$3('no-color') || hasFlag$3('no-colors') || hasFlag$3('color=false')) {
  6716. return 0;
  6717. }
  6718. if (hasFlag$3('color=16m') || hasFlag$3('color=full') || hasFlag$3('color=truecolor')) {
  6719. return 3;
  6720. }
  6721. if (hasFlag$3('color=256')) {
  6722. return 2;
  6723. }
  6724. if (hasFlag$3('color') || hasFlag$3('colors') || hasFlag$3('color=true') || hasFlag$3('color=always')) {
  6725. return 1;
  6726. }
  6727. if (process.stdout && !process.stdout.isTTY) {
  6728. return 0;
  6729. }
  6730. if (process.platform === 'win32') {
  6731. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  6732. // libuv that enables 256 color output on Windows. Anything earlier and it
  6733. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  6734. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  6735. // release that supports 256 colors.
  6736. var osRelease = os.release().split('.');
  6737. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  6738. return 2;
  6739. }
  6740. return 1;
  6741. }
  6742. if ('CI' in env) {
  6743. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  6744. return sign in env;
  6745. }) || env.CI_NAME === 'codeship') {
  6746. return 1;
  6747. }
  6748. return 0;
  6749. }
  6750. if ('TEAMCITY_VERSION' in env) {
  6751. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  6752. }
  6753. if ('TERM_PROGRAM' in env) {
  6754. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  6755. switch (env.TERM_PROGRAM) {
  6756. case 'iTerm.app':
  6757. return version >= 3 ? 3 : 2;
  6758. case 'Hyper':
  6759. return 3;
  6760. case 'Apple_Terminal':
  6761. return 2;
  6762. // No default
  6763. }
  6764. }
  6765. if (/-256(color)?$/i.test(env.TERM)) {
  6766. return 2;
  6767. }
  6768. if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  6769. return 1;
  6770. }
  6771. if ('COLORTERM' in env) {
  6772. return 1;
  6773. }
  6774. if (env.TERM === 'dumb') {
  6775. return 0;
  6776. }
  6777. return 0;
  6778. }();
  6779. if ('FORCE_COLOR' in env) {
  6780. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : supportLevel || 1;
  6781. }
  6782. module.exports = process && support(supportLevel);
  6783. });
  6784. var templates$2 = createCommonjsModule(function (module) {
  6785. 'use strict';
  6786. var TEMPLATE_REGEX = /(?:\\(u[a-f0-9]{4}|x[a-f0-9]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  6787. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  6788. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  6789. var ESCAPE_REGEX = /\\(u[0-9a-f]{4}|x[0-9a-f]{2}|.)|([^\\])/gi;
  6790. var ESCAPES = {
  6791. n: '\n',
  6792. r: '\r',
  6793. t: '\t',
  6794. b: '\b',
  6795. f: '\f',
  6796. v: '\v',
  6797. 0: '\0',
  6798. '\\': '\\',
  6799. e: '\u001b',
  6800. a: '\u0007'
  6801. };
  6802. function unescape(c) {
  6803. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  6804. return String.fromCharCode(parseInt(c.slice(1), 16));
  6805. }
  6806. return ESCAPES[c] || c;
  6807. }
  6808. function parseArguments(name, args) {
  6809. var results = [];
  6810. var chunks = args.trim().split(/\s*,\s*/g);
  6811. var matches;
  6812. var _iteratorNormalCompletion = true;
  6813. var _didIteratorError = false;
  6814. var _iteratorError = undefined;
  6815. try {
  6816. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6817. var chunk = _step.value;
  6818. if (!isNaN(chunk)) {
  6819. results.push(Number(chunk));
  6820. } else if (matches = chunk.match(STRING_REGEX)) {
  6821. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  6822. return escape ? unescape(escape) : chr;
  6823. }));
  6824. } else {
  6825. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  6826. }
  6827. }
  6828. } catch (err) {
  6829. _didIteratorError = true;
  6830. _iteratorError = err;
  6831. } finally {
  6832. try {
  6833. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6834. _iterator.return();
  6835. }
  6836. } finally {
  6837. if (_didIteratorError) {
  6838. throw _iteratorError;
  6839. }
  6840. }
  6841. }
  6842. return results;
  6843. }
  6844. function parseStyle(style) {
  6845. STYLE_REGEX.lastIndex = 0;
  6846. var results = [];
  6847. var matches;
  6848. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  6849. var name = matches[1];
  6850. if (matches[2]) {
  6851. var args = parseArguments(name, matches[2]);
  6852. results.push([name].concat(args));
  6853. } else {
  6854. results.push([name]);
  6855. }
  6856. }
  6857. return results;
  6858. }
  6859. function buildStyle(chalk, styles) {
  6860. var enabled = {};
  6861. var _iteratorNormalCompletion2 = true;
  6862. var _didIteratorError2 = false;
  6863. var _iteratorError2 = undefined;
  6864. try {
  6865. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6866. var layer = _step2.value;
  6867. var _iteratorNormalCompletion3 = true;
  6868. var _didIteratorError3 = false;
  6869. var _iteratorError3 = undefined;
  6870. try {
  6871. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6872. var style = _step3.value;
  6873. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  6874. }
  6875. } catch (err) {
  6876. _didIteratorError3 = true;
  6877. _iteratorError3 = err;
  6878. } finally {
  6879. try {
  6880. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6881. _iterator3.return();
  6882. }
  6883. } finally {
  6884. if (_didIteratorError3) {
  6885. throw _iteratorError3;
  6886. }
  6887. }
  6888. }
  6889. }
  6890. } catch (err) {
  6891. _didIteratorError2 = true;
  6892. _iteratorError2 = err;
  6893. } finally {
  6894. try {
  6895. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6896. _iterator2.return();
  6897. }
  6898. } finally {
  6899. if (_didIteratorError2) {
  6900. throw _iteratorError2;
  6901. }
  6902. }
  6903. }
  6904. var current = chalk;
  6905. var _arr = Object.keys(enabled);
  6906. for (var _i = 0; _i < _arr.length; _i++) {
  6907. var styleName = _arr[_i];
  6908. if (Array.isArray(enabled[styleName])) {
  6909. if (!(styleName in current)) {
  6910. throw new Error(`Unknown Chalk style: ${styleName}`);
  6911. }
  6912. if (enabled[styleName].length > 0) {
  6913. current = current[styleName].apply(current, enabled[styleName]);
  6914. } else {
  6915. current = current[styleName];
  6916. }
  6917. }
  6918. }
  6919. return current;
  6920. }
  6921. module.exports = function (chalk, tmp) {
  6922. var styles = [];
  6923. var chunks = [];
  6924. var chunk = []; // eslint-disable-next-line max-params
  6925. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  6926. if (escapeChar) {
  6927. chunk.push(unescape(escapeChar));
  6928. } else if (style) {
  6929. var str = chunk.join('');
  6930. chunk = [];
  6931. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  6932. styles.push({
  6933. inverse,
  6934. styles: parseStyle(style)
  6935. });
  6936. } else if (close) {
  6937. if (styles.length === 0) {
  6938. throw new Error('Found extraneous } in Chalk template literal');
  6939. }
  6940. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  6941. chunk = [];
  6942. styles.pop();
  6943. } else {
  6944. chunk.push(chr);
  6945. }
  6946. });
  6947. chunks.push(chunk.join(''));
  6948. if (styles.length > 0) {
  6949. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  6950. throw new Error(errMsg);
  6951. }
  6952. return chunks.join('');
  6953. };
  6954. });
  6955. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  6956. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  6957. var skipModels = new Set(['gray']);
  6958. var styles = Object.create(null);
  6959. function applyOptions(obj, options) {
  6960. options = options || {}; // Detect level if not set manually
  6961. var scLevel = supportsColor$1 ? supportsColor$1.level : 0;
  6962. obj.level = options.level === undefined ? scLevel : options.level;
  6963. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  6964. }
  6965. function Chalk(options) {
  6966. // We check for this.template here since calling `chalk.constructor()`
  6967. // by itself will have a `this` of a previously constructed chalk object
  6968. if (!this || !(this instanceof Chalk) || this.template) {
  6969. var _chalk = {};
  6970. applyOptions(_chalk, options);
  6971. _chalk.template = function () {
  6972. var args = [].slice.call(arguments);
  6973. return chalkTag.apply(null, [_chalk.template].concat(args));
  6974. };
  6975. Object.setPrototypeOf(_chalk, Chalk.prototype);
  6976. Object.setPrototypeOf(_chalk.template, _chalk);
  6977. _chalk.template.constructor = Chalk;
  6978. return _chalk.template;
  6979. }
  6980. applyOptions(this, options);
  6981. } // Use bright blue on Windows as the normal blue color is illegible
  6982. if (isSimpleWindowsTerm) {
  6983. ansiStyles.blue.open = '\u001B[94m';
  6984. }
  6985. var _arr = Object.keys(ansiStyles);
  6986. var _loop = function _loop() {
  6987. var key = _arr[_i];
  6988. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  6989. styles[key] = {
  6990. get() {
  6991. var codes = ansiStyles[key];
  6992. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
  6993. }
  6994. };
  6995. };
  6996. for (var _i = 0; _i < _arr.length; _i++) {
  6997. _loop();
  6998. }
  6999. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  7000. var _arr2 = Object.keys(ansiStyles.color.ansi);
  7001. var _loop2 = function _loop2() {
  7002. var model = _arr2[_i2];
  7003. if (skipModels.has(model)) {
  7004. return "continue";
  7005. }
  7006. styles[model] = {
  7007. get() {
  7008. var level = this.level;
  7009. return function () {
  7010. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  7011. var codes = {
  7012. open,
  7013. close: ansiStyles.color.close,
  7014. closeRe: ansiStyles.color.closeRe
  7015. };
  7016. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  7017. };
  7018. }
  7019. };
  7020. };
  7021. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  7022. var _ret = _loop2();
  7023. if (_ret === "continue") continue;
  7024. }
  7025. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  7026. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  7027. var _loop3 = function _loop3() {
  7028. var model = _arr3[_i3];
  7029. if (skipModels.has(model)) {
  7030. return "continue";
  7031. }
  7032. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  7033. styles[bgModel] = {
  7034. get() {
  7035. var level = this.level;
  7036. return function () {
  7037. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  7038. var codes = {
  7039. open,
  7040. close: ansiStyles.bgColor.close,
  7041. closeRe: ansiStyles.bgColor.closeRe
  7042. };
  7043. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  7044. };
  7045. }
  7046. };
  7047. };
  7048. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  7049. var _ret2 = _loop3();
  7050. if (_ret2 === "continue") continue;
  7051. }
  7052. var proto = Object.defineProperties(function () {}, styles);
  7053. function build(_styles, key) {
  7054. var builder = function builder() {
  7055. return applyStyle.apply(builder, arguments);
  7056. };
  7057. builder._styles = _styles;
  7058. var self = this;
  7059. Object.defineProperty(builder, 'level', {
  7060. enumerable: true,
  7061. get() {
  7062. return self.level;
  7063. },
  7064. set(level) {
  7065. self.level = level;
  7066. }
  7067. });
  7068. Object.defineProperty(builder, 'enabled', {
  7069. enumerable: true,
  7070. get() {
  7071. return self.enabled;
  7072. },
  7073. set(enabled) {
  7074. self.enabled = enabled;
  7075. }
  7076. }); // See below for fix regarding invisible grey/dim combination on Windows
  7077. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  7078. // no way to create a function with a different prototype
  7079. builder.__proto__ = proto; // eslint-disable-line no-proto
  7080. return builder;
  7081. }
  7082. function applyStyle() {
  7083. // Support varags, but simply cast to string in case there's only one arg
  7084. var args = arguments;
  7085. var argsLen = args.length;
  7086. var str = String(arguments[0]);
  7087. if (argsLen === 0) {
  7088. return '';
  7089. }
  7090. if (argsLen > 1) {
  7091. // Don't slice `arguments`, it prevents V8 optimizations
  7092. for (var a = 1; a < argsLen; a++) {
  7093. str += ' ' + args[a];
  7094. }
  7095. }
  7096. if (!this.enabled || this.level <= 0 || !str) {
  7097. return str;
  7098. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  7099. // see https://github.com/chalk/chalk/issues/58
  7100. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  7101. var originalDim = ansiStyles.dim.open;
  7102. if (isSimpleWindowsTerm && this.hasGrey) {
  7103. ansiStyles.dim.open = '';
  7104. }
  7105. var _iteratorNormalCompletion = true;
  7106. var _didIteratorError = false;
  7107. var _iteratorError = undefined;
  7108. try {
  7109. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7110. var code = _step.value;
  7111. // Replace any instances already present with a re-opening code
  7112. // otherwise only the part of the string until said closing code
  7113. // will be colored, and the rest will simply be 'plain'.
  7114. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  7115. // after next line to fix a bleed issue on macOS
  7116. // https://github.com/chalk/chalk/pull/92
  7117. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  7118. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  7119. } catch (err) {
  7120. _didIteratorError = true;
  7121. _iteratorError = err;
  7122. } finally {
  7123. try {
  7124. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7125. _iterator.return();
  7126. }
  7127. } finally {
  7128. if (_didIteratorError) {
  7129. throw _iteratorError;
  7130. }
  7131. }
  7132. }
  7133. ansiStyles.dim.open = originalDim;
  7134. return str;
  7135. }
  7136. function chalkTag(chalk, strings) {
  7137. if (!Array.isArray(strings)) {
  7138. // If chalk() was called by itself or with a string,
  7139. // return the string itself as a string.
  7140. return [].slice.call(arguments, 1).join(' ');
  7141. }
  7142. var args = [].slice.call(arguments, 2);
  7143. var parts = [strings.raw[0]];
  7144. for (var i = 1; i < strings.length; i++) {
  7145. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  7146. parts.push(String(strings.raw[i]));
  7147. }
  7148. return templates$2(chalk, parts.join(''));
  7149. }
  7150. Object.defineProperties(Chalk.prototype, styles);
  7151. var chalk$2 = Chalk(); // eslint-disable-line new-cap
  7152. var supportsColor_1$2 = supportsColor$1;
  7153. chalk$2.supportsColor = supportsColor_1$2;
  7154. var cliDescriptor = {
  7155. key: function key(_key) {
  7156. return _key.length === 1 ? `-${_key}` : `--${_key}`;
  7157. },
  7158. value: function value(_value) {
  7159. return lib$1.apiDescriptor.value(_value);
  7160. },
  7161. pair: function pair(_ref) {
  7162. var key = _ref.key,
  7163. value = _ref.value;
  7164. return value === false ? `--no-${key}` : value === true ? cliDescriptor.key(key) : value === "" ? `${cliDescriptor.key(key)} without an argument` : `${cliDescriptor.key(key)}=${value}`;
  7165. }
  7166. };
  7167. var FlagSchema =
  7168. /*#__PURE__*/
  7169. function (_vnopts$ChoiceSchema) {
  7170. _inherits(FlagSchema, _vnopts$ChoiceSchema);
  7171. function FlagSchema(_ref2) {
  7172. var _this;
  7173. var name = _ref2.name,
  7174. flags = _ref2.flags;
  7175. _classCallCheck(this, FlagSchema);
  7176. _this = _possibleConstructorReturn(this, _getPrototypeOf(FlagSchema).call(this, {
  7177. name,
  7178. choices: flags
  7179. }));
  7180. _this._flags = flags.slice().sort();
  7181. return _this;
  7182. }
  7183. _createClass(FlagSchema, [{
  7184. key: "preprocess",
  7185. value: function preprocess(value, utils) {
  7186. if (typeof value === "string" && value.length !== 0 && this._flags.indexOf(value) === -1) {
  7187. var suggestion = this._flags.find(function (flag) {
  7188. return leven$1(flag, value) < 3;
  7189. });
  7190. if (suggestion) {
  7191. utils.logger.warn([`Unknown flag ${chalk$2.yellow(utils.descriptor.value(value))},`, `did you mean ${chalk$2.blue(utils.descriptor.value(suggestion))}?`].join(" "));
  7192. return suggestion;
  7193. }
  7194. }
  7195. return value;
  7196. }
  7197. }, {
  7198. key: "expected",
  7199. value: function expected() {
  7200. return "a flag";
  7201. }
  7202. }]);
  7203. return FlagSchema;
  7204. }(lib$1.ChoiceSchema);
  7205. var hasDeprecationWarned;
  7206. function normalizeOptions$1(options, optionInfos) {
  7207. var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  7208. logger = _ref3.logger,
  7209. _ref3$isCLI = _ref3.isCLI,
  7210. isCLI = _ref3$isCLI === void 0 ? false : _ref3$isCLI,
  7211. _ref3$passThrough = _ref3.passThrough,
  7212. passThrough = _ref3$passThrough === void 0 ? false : _ref3$passThrough;
  7213. var unknown = !passThrough ? lib$1.levenUnknownHandler : Array.isArray(passThrough) ? function (key, value) {
  7214. return passThrough.indexOf(key) === -1 ? undefined : {
  7215. [key]: value
  7216. };
  7217. } : function (key, value) {
  7218. return {
  7219. [key]: value
  7220. };
  7221. };
  7222. var descriptor = isCLI ? cliDescriptor : lib$1.apiDescriptor;
  7223. var schemas = optionInfosToSchemas(optionInfos, {
  7224. isCLI
  7225. });
  7226. var normalizer = new lib$1.Normalizer(schemas, {
  7227. logger,
  7228. unknown,
  7229. descriptor
  7230. });
  7231. var shouldSuppressDuplicateDeprecationWarnings = logger !== false;
  7232. if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) {
  7233. normalizer._hasDeprecationWarned = hasDeprecationWarned;
  7234. }
  7235. var normalized = normalizer.normalize(options);
  7236. if (shouldSuppressDuplicateDeprecationWarnings) {
  7237. hasDeprecationWarned = normalizer._hasDeprecationWarned;
  7238. }
  7239. return normalized;
  7240. }
  7241. function optionInfosToSchemas(optionInfos, _ref4) {
  7242. var isCLI = _ref4.isCLI;
  7243. var schemas = [];
  7244. if (isCLI) {
  7245. schemas.push(lib$1.AnySchema.create({
  7246. name: "_"
  7247. }));
  7248. }
  7249. var _iteratorNormalCompletion = true;
  7250. var _didIteratorError = false;
  7251. var _iteratorError = undefined;
  7252. try {
  7253. for (var _iterator = optionInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7254. var optionInfo = _step.value;
  7255. schemas.push(optionInfoToSchema(optionInfo, {
  7256. isCLI,
  7257. optionInfos
  7258. }));
  7259. if (optionInfo.alias && isCLI) {
  7260. schemas.push(lib$1.AliasSchema.create({
  7261. name: optionInfo.alias,
  7262. sourceName: optionInfo.name
  7263. }));
  7264. }
  7265. }
  7266. } catch (err) {
  7267. _didIteratorError = true;
  7268. _iteratorError = err;
  7269. } finally {
  7270. try {
  7271. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7272. _iterator.return();
  7273. }
  7274. } finally {
  7275. if (_didIteratorError) {
  7276. throw _iteratorError;
  7277. }
  7278. }
  7279. }
  7280. return schemas;
  7281. }
  7282. function optionInfoToSchema(optionInfo, _ref5) {
  7283. var isCLI = _ref5.isCLI,
  7284. optionInfos = _ref5.optionInfos;
  7285. var SchemaConstructor;
  7286. var parameters = {
  7287. name: optionInfo.name
  7288. };
  7289. var handlers = {};
  7290. switch (optionInfo.type) {
  7291. case "int":
  7292. SchemaConstructor = lib$1.IntegerSchema;
  7293. if (isCLI) {
  7294. parameters.preprocess = function (value) {
  7295. return Number(value);
  7296. };
  7297. }
  7298. break;
  7299. case "choice":
  7300. SchemaConstructor = lib$1.ChoiceSchema;
  7301. parameters.choices = optionInfo.choices.map(function (choiceInfo) {
  7302. return typeof choiceInfo === "object" && choiceInfo.redirect ? Object.assign({}, choiceInfo, {
  7303. redirect: {
  7304. to: {
  7305. key: optionInfo.name,
  7306. value: choiceInfo.redirect
  7307. }
  7308. }
  7309. }) : choiceInfo;
  7310. });
  7311. break;
  7312. case "boolean":
  7313. SchemaConstructor = lib$1.BooleanSchema;
  7314. break;
  7315. case "flag":
  7316. SchemaConstructor = FlagSchema;
  7317. parameters.flags = optionInfos.map(function (optionInfo) {
  7318. return [].concat(optionInfo.alias || [], optionInfo.description ? optionInfo.name : [], optionInfo.oppositeDescription ? `no-${optionInfo.name}` : []);
  7319. }).reduce(function (a, b) {
  7320. return a.concat(b);
  7321. }, []);
  7322. break;
  7323. case "path":
  7324. SchemaConstructor = lib$1.StringSchema;
  7325. break;
  7326. default:
  7327. throw new Error(`Unexpected type ${optionInfo.type}`);
  7328. }
  7329. if (optionInfo.exception) {
  7330. parameters.validate = function (value, schema, utils) {
  7331. return optionInfo.exception(value) || schema.validate(value, utils);
  7332. };
  7333. } else {
  7334. parameters.validate = function (value, schema, utils) {
  7335. return value === undefined || schema.validate(value, utils);
  7336. };
  7337. }
  7338. if (optionInfo.redirect) {
  7339. handlers.redirect = function (value) {
  7340. return !value ? undefined : {
  7341. to: {
  7342. key: optionInfo.redirect.option,
  7343. value: optionInfo.redirect.value
  7344. }
  7345. };
  7346. };
  7347. }
  7348. if (optionInfo.deprecated) {
  7349. handlers.deprecated = true;
  7350. } // allow CLI overriding, e.g., prettier package.json --tab-width 1 --tab-width 2
  7351. if (isCLI && !optionInfo.array) {
  7352. var originalPreprocess = parameters.preprocess || function (x) {
  7353. return x;
  7354. };
  7355. parameters.preprocess = function (value, schema, utils) {
  7356. return schema.preprocess(originalPreprocess(Array.isArray(value) ? value[value.length - 1] : value), utils);
  7357. };
  7358. }
  7359. return optionInfo.array ? lib$1.ArraySchema.create(Object.assign(isCLI ? {
  7360. preprocess: function preprocess(v) {
  7361. return [].concat(v);
  7362. }
  7363. } : {}, handlers, {
  7364. valueSchema: SchemaConstructor.create(parameters)
  7365. })) : SchemaConstructor.create(Object.assign({}, parameters, handlers));
  7366. }
  7367. function normalizeApiOptions(options, optionInfos, opts) {
  7368. return normalizeOptions$1(options, optionInfos, opts);
  7369. }
  7370. function normalizeCliOptions(options, optionInfos, opts) {
  7371. return normalizeOptions$1(options, optionInfos, Object.assign({
  7372. isCLI: true
  7373. }, opts));
  7374. }
  7375. var optionsNormalizer = {
  7376. normalizeApiOptions,
  7377. normalizeCliOptions
  7378. };
  7379. var getLast = function getLast(arr) {
  7380. return arr.length > 0 ? arr[arr.length - 1] : null;
  7381. };
  7382. function locStart$1(node, opts) {
  7383. opts = opts || {}; // Handle nodes with decorators. They should start at the first decorator
  7384. if (!opts.ignoreDecorators && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0) {
  7385. return locStart$1(node.declaration.decorators[0]);
  7386. }
  7387. if (!opts.ignoreDecorators && node.decorators && node.decorators.length > 0) {
  7388. return locStart$1(node.decorators[0]);
  7389. }
  7390. if (node.__location) {
  7391. return node.__location.startOffset;
  7392. }
  7393. if (node.range) {
  7394. return node.range[0];
  7395. }
  7396. if (typeof node.start === "number") {
  7397. return node.start;
  7398. }
  7399. if (node.loc) {
  7400. return node.loc.start;
  7401. }
  7402. return null;
  7403. }
  7404. function locEnd$1(node) {
  7405. var endNode = node.nodes && getLast(node.nodes);
  7406. if (endNode && node.source && !node.source.end) {
  7407. node = endNode;
  7408. }
  7409. if (node.__location) {
  7410. return node.__location.endOffset;
  7411. }
  7412. var loc = node.range ? node.range[1] : typeof node.end === "number" ? node.end : null;
  7413. if (node.typeAnnotation) {
  7414. return Math.max(loc, locEnd$1(node.typeAnnotation));
  7415. }
  7416. if (node.loc && !loc) {
  7417. return node.loc.end;
  7418. }
  7419. return loc;
  7420. }
  7421. var loc = {
  7422. locStart: locStart$1,
  7423. locEnd: locEnd$1
  7424. };
  7425. var jsTokens = createCommonjsModule(function (module, exports) {
  7426. // Copyright 2014, 2015, 2016, 2017 Simon Lydell
  7427. // License: MIT. (See LICENSE.)
  7428. Object.defineProperty(exports, "__esModule", {
  7429. value: true
  7430. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  7431. // (run `npm run build`).
  7432. exports.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyu]{1,5}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
  7433. exports.matchToToken = function (match) {
  7434. var token = {
  7435. type: "invalid",
  7436. value: match[0]
  7437. };
  7438. 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";
  7439. return token;
  7440. };
  7441. });
  7442. unwrapExports(jsTokens);
  7443. var ast = createCommonjsModule(function (module) {
  7444. /*
  7445. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7446. Redistribution and use in source and binary forms, with or without
  7447. modification, are permitted provided that the following conditions are met:
  7448. * Redistributions of source code must retain the above copyright
  7449. notice, this list of conditions and the following disclaimer.
  7450. * Redistributions in binary form must reproduce the above copyright
  7451. notice, this list of conditions and the following disclaimer in the
  7452. documentation and/or other materials provided with the distribution.
  7453. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  7454. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7455. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7456. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7457. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7458. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7459. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7460. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7461. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7462. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7463. */
  7464. (function () {
  7465. 'use strict';
  7466. function isExpression(node) {
  7467. if (node == null) {
  7468. return false;
  7469. }
  7470. switch (node.type) {
  7471. case 'ArrayExpression':
  7472. case 'AssignmentExpression':
  7473. case 'BinaryExpression':
  7474. case 'CallExpression':
  7475. case 'ConditionalExpression':
  7476. case 'FunctionExpression':
  7477. case 'Identifier':
  7478. case 'Literal':
  7479. case 'LogicalExpression':
  7480. case 'MemberExpression':
  7481. case 'NewExpression':
  7482. case 'ObjectExpression':
  7483. case 'SequenceExpression':
  7484. case 'ThisExpression':
  7485. case 'UnaryExpression':
  7486. case 'UpdateExpression':
  7487. return true;
  7488. }
  7489. return false;
  7490. }
  7491. function isIterationStatement(node) {
  7492. if (node == null) {
  7493. return false;
  7494. }
  7495. switch (node.type) {
  7496. case 'DoWhileStatement':
  7497. case 'ForInStatement':
  7498. case 'ForStatement':
  7499. case 'WhileStatement':
  7500. return true;
  7501. }
  7502. return false;
  7503. }
  7504. function isStatement(node) {
  7505. if (node == null) {
  7506. return false;
  7507. }
  7508. switch (node.type) {
  7509. case 'BlockStatement':
  7510. case 'BreakStatement':
  7511. case 'ContinueStatement':
  7512. case 'DebuggerStatement':
  7513. case 'DoWhileStatement':
  7514. case 'EmptyStatement':
  7515. case 'ExpressionStatement':
  7516. case 'ForInStatement':
  7517. case 'ForStatement':
  7518. case 'IfStatement':
  7519. case 'LabeledStatement':
  7520. case 'ReturnStatement':
  7521. case 'SwitchStatement':
  7522. case 'ThrowStatement':
  7523. case 'TryStatement':
  7524. case 'VariableDeclaration':
  7525. case 'WhileStatement':
  7526. case 'WithStatement':
  7527. return true;
  7528. }
  7529. return false;
  7530. }
  7531. function isSourceElement(node) {
  7532. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  7533. }
  7534. function trailingStatement(node) {
  7535. switch (node.type) {
  7536. case 'IfStatement':
  7537. if (node.alternate != null) {
  7538. return node.alternate;
  7539. }
  7540. return node.consequent;
  7541. case 'LabeledStatement':
  7542. case 'ForStatement':
  7543. case 'ForInStatement':
  7544. case 'WhileStatement':
  7545. case 'WithStatement':
  7546. return node.body;
  7547. }
  7548. return null;
  7549. }
  7550. function isProblematicIfStatement(node) {
  7551. var current;
  7552. if (node.type !== 'IfStatement') {
  7553. return false;
  7554. }
  7555. if (node.alternate == null) {
  7556. return false;
  7557. }
  7558. current = node.consequent;
  7559. do {
  7560. if (current.type === 'IfStatement') {
  7561. if (current.alternate == null) {
  7562. return true;
  7563. }
  7564. }
  7565. current = trailingStatement(current);
  7566. } while (current);
  7567. return false;
  7568. }
  7569. module.exports = {
  7570. isExpression: isExpression,
  7571. isStatement: isStatement,
  7572. isIterationStatement: isIterationStatement,
  7573. isSourceElement: isSourceElement,
  7574. isProblematicIfStatement: isProblematicIfStatement,
  7575. trailingStatement: trailingStatement
  7576. };
  7577. })();
  7578. /* vim: set sw=4 ts=4 et tw=80 : */
  7579. });
  7580. var code = createCommonjsModule(function (module) {
  7581. /*
  7582. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  7583. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  7584. Redistribution and use in source and binary forms, with or without
  7585. modification, are permitted provided that the following conditions are met:
  7586. * Redistributions of source code must retain the above copyright
  7587. notice, this list of conditions and the following disclaimer.
  7588. * Redistributions in binary form must reproduce the above copyright
  7589. notice, this list of conditions and the following disclaimer in the
  7590. documentation and/or other materials provided with the distribution.
  7591. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7592. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7593. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7594. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7595. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7596. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7597. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7598. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7599. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7600. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7601. */
  7602. (function () {
  7603. 'use strict';
  7604. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch; // See `tools/generate-identifier-regex.js`.
  7605. ES5Regex = {
  7606. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierStart:
  7607. 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]/,
  7608. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierPart:
  7609. 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]/
  7610. };
  7611. ES6Regex = {
  7612. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  7613. 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]/,
  7614. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  7615. 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]/
  7616. };
  7617. function isDecimalDigit(ch) {
  7618. return 0x30 <= ch && ch <= 0x39; // 0..9
  7619. }
  7620. function isHexDigit(ch) {
  7621. return 0x30 <= ch && ch <= 0x39 || // 0..9
  7622. 0x61 <= ch && ch <= 0x66 || // a..f
  7623. 0x41 <= ch && ch <= 0x46; // A..F
  7624. }
  7625. function isOctalDigit(ch) {
  7626. return ch >= 0x30 && ch <= 0x37; // 0..7
  7627. } // 7.2 White Space
  7628. NON_ASCII_WHITESPACES = [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF];
  7629. function isWhiteSpace(ch) {
  7630. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 || ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  7631. } // 7.3 Line Terminators
  7632. function isLineTerminator(ch) {
  7633. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  7634. } // 7.6 Identifier Names and Identifiers
  7635. function fromCodePoint(cp) {
  7636. if (cp <= 0xFFFF) {
  7637. return String.fromCharCode(cp);
  7638. }
  7639. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  7640. var cu2 = String.fromCharCode((cp - 0x10000) % 0x400 + 0xDC00);
  7641. return cu1 + cu2;
  7642. }
  7643. IDENTIFIER_START = new Array(0x80);
  7644. for (ch = 0; ch < 0x80; ++ch) {
  7645. IDENTIFIER_START[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  7646. ch >= 0x41 && ch <= 0x5A || // A..Z
  7647. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7648. }
  7649. IDENTIFIER_PART = new Array(0x80);
  7650. for (ch = 0; ch < 0x80; ++ch) {
  7651. IDENTIFIER_PART[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  7652. ch >= 0x41 && ch <= 0x5A || // A..Z
  7653. ch >= 0x30 && ch <= 0x39 || // 0..9
  7654. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7655. }
  7656. function isIdentifierStartES5(ch) {
  7657. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7658. }
  7659. function isIdentifierPartES5(ch) {
  7660. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7661. }
  7662. function isIdentifierStartES6(ch) {
  7663. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7664. }
  7665. function isIdentifierPartES6(ch) {
  7666. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7667. }
  7668. module.exports = {
  7669. isDecimalDigit: isDecimalDigit,
  7670. isHexDigit: isHexDigit,
  7671. isOctalDigit: isOctalDigit,
  7672. isWhiteSpace: isWhiteSpace,
  7673. isLineTerminator: isLineTerminator,
  7674. isIdentifierStartES5: isIdentifierStartES5,
  7675. isIdentifierPartES5: isIdentifierPartES5,
  7676. isIdentifierStartES6: isIdentifierStartES6,
  7677. isIdentifierPartES6: isIdentifierPartES6
  7678. };
  7679. })();
  7680. /* vim: set sw=4 ts=4 et tw=80 : */
  7681. });
  7682. var keyword = createCommonjsModule(function (module) {
  7683. /*
  7684. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7685. Redistribution and use in source and binary forms, with or without
  7686. modification, are permitted provided that the following conditions are met:
  7687. * Redistributions of source code must retain the above copyright
  7688. notice, this list of conditions and the following disclaimer.
  7689. * Redistributions in binary form must reproduce the above copyright
  7690. notice, this list of conditions and the following disclaimer in the
  7691. documentation and/or other materials provided with the distribution.
  7692. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7693. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7694. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7695. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7696. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7697. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7698. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7699. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7700. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7701. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7702. */
  7703. (function () {
  7704. 'use strict';
  7705. var code$$1 = code;
  7706. function isStrictModeReservedWordES6(id) {
  7707. switch (id) {
  7708. case 'implements':
  7709. case 'interface':
  7710. case 'package':
  7711. case 'private':
  7712. case 'protected':
  7713. case 'public':
  7714. case 'static':
  7715. case 'let':
  7716. return true;
  7717. default:
  7718. return false;
  7719. }
  7720. }
  7721. function isKeywordES5(id, strict) {
  7722. // yield should not be treated as keyword under non-strict mode.
  7723. if (!strict && id === 'yield') {
  7724. return false;
  7725. }
  7726. return isKeywordES6(id, strict);
  7727. }
  7728. function isKeywordES6(id, strict) {
  7729. if (strict && isStrictModeReservedWordES6(id)) {
  7730. return true;
  7731. }
  7732. switch (id.length) {
  7733. case 2:
  7734. return id === 'if' || id === 'in' || id === 'do';
  7735. case 3:
  7736. return id === 'var' || id === 'for' || id === 'new' || id === 'try';
  7737. case 4:
  7738. return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
  7739. case 5:
  7740. return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
  7741. case 6:
  7742. return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
  7743. case 7:
  7744. return id === 'default' || id === 'finally' || id === 'extends';
  7745. case 8:
  7746. return id === 'function' || id === 'continue' || id === 'debugger';
  7747. case 10:
  7748. return id === 'instanceof';
  7749. default:
  7750. return false;
  7751. }
  7752. }
  7753. function isReservedWordES5(id, strict) {
  7754. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  7755. }
  7756. function isReservedWordES6(id, strict) {
  7757. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  7758. }
  7759. function isRestrictedWord(id) {
  7760. return id === 'eval' || id === 'arguments';
  7761. }
  7762. function isIdentifierNameES5(id) {
  7763. var i, iz, ch;
  7764. if (id.length === 0) {
  7765. return false;
  7766. }
  7767. ch = id.charCodeAt(0);
  7768. if (!code$$1.isIdentifierStartES5(ch)) {
  7769. return false;
  7770. }
  7771. for (i = 1, iz = id.length; i < iz; ++i) {
  7772. ch = id.charCodeAt(i);
  7773. if (!code$$1.isIdentifierPartES5(ch)) {
  7774. return false;
  7775. }
  7776. }
  7777. return true;
  7778. }
  7779. function decodeUtf16(lead, trail) {
  7780. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  7781. }
  7782. function isIdentifierNameES6(id) {
  7783. var i, iz, ch, lowCh, check;
  7784. if (id.length === 0) {
  7785. return false;
  7786. }
  7787. check = code$$1.isIdentifierStartES6;
  7788. for (i = 0, iz = id.length; i < iz; ++i) {
  7789. ch = id.charCodeAt(i);
  7790. if (0xD800 <= ch && ch <= 0xDBFF) {
  7791. ++i;
  7792. if (i >= iz) {
  7793. return false;
  7794. }
  7795. lowCh = id.charCodeAt(i);
  7796. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  7797. return false;
  7798. }
  7799. ch = decodeUtf16(ch, lowCh);
  7800. }
  7801. if (!check(ch)) {
  7802. return false;
  7803. }
  7804. check = code$$1.isIdentifierPartES6;
  7805. }
  7806. return true;
  7807. }
  7808. function isIdentifierES5(id, strict) {
  7809. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  7810. }
  7811. function isIdentifierES6(id, strict) {
  7812. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  7813. }
  7814. module.exports = {
  7815. isKeywordES5: isKeywordES5,
  7816. isKeywordES6: isKeywordES6,
  7817. isReservedWordES5: isReservedWordES5,
  7818. isReservedWordES6: isReservedWordES6,
  7819. isRestrictedWord: isRestrictedWord,
  7820. isIdentifierNameES5: isIdentifierNameES5,
  7821. isIdentifierNameES6: isIdentifierNameES6,
  7822. isIdentifierES5: isIdentifierES5,
  7823. isIdentifierES6: isIdentifierES6
  7824. };
  7825. })();
  7826. /* vim: set sw=4 ts=4 et tw=80 : */
  7827. });
  7828. var utils$2 = createCommonjsModule(function (module, exports) {
  7829. /*
  7830. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7831. Redistribution and use in source and binary forms, with or without
  7832. modification, are permitted provided that the following conditions are met:
  7833. * Redistributions of source code must retain the above copyright
  7834. notice, this list of conditions and the following disclaimer.
  7835. * Redistributions in binary form must reproduce the above copyright
  7836. notice, this list of conditions and the following disclaimer in the
  7837. documentation and/or other materials provided with the distribution.
  7838. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7839. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7840. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7841. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7842. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7843. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7844. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7845. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7846. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7847. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7848. */
  7849. (function () {
  7850. 'use strict';
  7851. exports.ast = ast;
  7852. exports.code = code;
  7853. exports.keyword = keyword;
  7854. })();
  7855. /* vim: set sw=4 ts=4 et tw=80 : */
  7856. });
  7857. var hasFlag$6 = createCommonjsModule(function (module) {
  7858. 'use strict';
  7859. module.exports = function (flag, argv) {
  7860. argv = argv || process.argv;
  7861. var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  7862. var pos = argv.indexOf(prefix + flag);
  7863. var terminatorPos = argv.indexOf('--');
  7864. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  7865. };
  7866. });
  7867. var env$1 = process.env;
  7868. var forceColor$1;
  7869. if (hasFlag$6('no-color') || hasFlag$6('no-colors') || hasFlag$6('color=false')) {
  7870. forceColor$1 = false;
  7871. } else if (hasFlag$6('color') || hasFlag$6('colors') || hasFlag$6('color=true') || hasFlag$6('color=always')) {
  7872. forceColor$1 = true;
  7873. }
  7874. if ('FORCE_COLOR' in env$1) {
  7875. forceColor$1 = env$1.FORCE_COLOR.length === 0 || parseInt(env$1.FORCE_COLOR, 10) !== 0;
  7876. }
  7877. function translateLevel$1(level) {
  7878. if (level === 0) {
  7879. return false;
  7880. }
  7881. return {
  7882. level,
  7883. hasBasic: true,
  7884. has256: level >= 2,
  7885. has16m: level >= 3
  7886. };
  7887. }
  7888. function supportsColor$4(stream) {
  7889. if (forceColor$1 === false) {
  7890. return 0;
  7891. }
  7892. if (hasFlag$6('color=16m') || hasFlag$6('color=full') || hasFlag$6('color=truecolor')) {
  7893. return 3;
  7894. }
  7895. if (hasFlag$6('color=256')) {
  7896. return 2;
  7897. }
  7898. if (stream && !stream.isTTY && forceColor$1 !== true) {
  7899. return 0;
  7900. }
  7901. var min = forceColor$1 ? 1 : 0;
  7902. if (process.platform === 'win32') {
  7903. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  7904. // libuv that enables 256 color output on Windows. Anything earlier and it
  7905. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  7906. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  7907. // release that supports 256 colors. Windows 10 build 14931 is the first release
  7908. // that supports 16m/TrueColor.
  7909. var osRelease = os.release().split('.');
  7910. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  7911. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  7912. }
  7913. return 1;
  7914. }
  7915. if ('CI' in env$1) {
  7916. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  7917. return sign in env$1;
  7918. }) || env$1.CI_NAME === 'codeship') {
  7919. return 1;
  7920. }
  7921. return min;
  7922. }
  7923. if ('TEAMCITY_VERSION' in env$1) {
  7924. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env$1.TEAMCITY_VERSION) ? 1 : 0;
  7925. }
  7926. if (env$1.COLORTERM === 'truecolor') {
  7927. return 3;
  7928. }
  7929. if ('TERM_PROGRAM' in env$1) {
  7930. var version = parseInt((env$1.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  7931. switch (env$1.TERM_PROGRAM) {
  7932. case 'iTerm.app':
  7933. return version >= 3 ? 3 : 2;
  7934. case 'Apple_Terminal':
  7935. return 2;
  7936. // No default
  7937. }
  7938. }
  7939. if (/-256(color)?$/i.test(env$1.TERM)) {
  7940. return 2;
  7941. }
  7942. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env$1.TERM)) {
  7943. return 1;
  7944. }
  7945. if ('COLORTERM' in env$1) {
  7946. return 1;
  7947. }
  7948. if (env$1.TERM === 'dumb') {
  7949. return min;
  7950. }
  7951. return min;
  7952. }
  7953. function getSupportLevel$1(stream) {
  7954. var level = supportsColor$4(stream);
  7955. return translateLevel$1(level);
  7956. }
  7957. var supportsColor_1$3 = {
  7958. supportsColor: getSupportLevel$1,
  7959. stdout: getSupportLevel$1(process.stdout),
  7960. stderr: getSupportLevel$1(process.stderr)
  7961. };
  7962. var templates$4 = createCommonjsModule(function (module) {
  7963. 'use strict';
  7964. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  7965. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  7966. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  7967. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  7968. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  7969. function unescape(c) {
  7970. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  7971. return String.fromCharCode(parseInt(c.slice(1), 16));
  7972. }
  7973. return ESCAPES.get(c) || c;
  7974. }
  7975. function parseArguments(name, args) {
  7976. var results = [];
  7977. var chunks = args.trim().split(/\s*,\s*/g);
  7978. var matches;
  7979. var _iteratorNormalCompletion = true;
  7980. var _didIteratorError = false;
  7981. var _iteratorError = undefined;
  7982. try {
  7983. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7984. var chunk = _step.value;
  7985. if (!isNaN(chunk)) {
  7986. results.push(Number(chunk));
  7987. } else if (matches = chunk.match(STRING_REGEX)) {
  7988. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  7989. return escape ? unescape(escape) : chr;
  7990. }));
  7991. } else {
  7992. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  7993. }
  7994. }
  7995. } catch (err) {
  7996. _didIteratorError = true;
  7997. _iteratorError = err;
  7998. } finally {
  7999. try {
  8000. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8001. _iterator.return();
  8002. }
  8003. } finally {
  8004. if (_didIteratorError) {
  8005. throw _iteratorError;
  8006. }
  8007. }
  8008. }
  8009. return results;
  8010. }
  8011. function parseStyle(style) {
  8012. STYLE_REGEX.lastIndex = 0;
  8013. var results = [];
  8014. var matches;
  8015. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  8016. var name = matches[1];
  8017. if (matches[2]) {
  8018. var args = parseArguments(name, matches[2]);
  8019. results.push([name].concat(args));
  8020. } else {
  8021. results.push([name]);
  8022. }
  8023. }
  8024. return results;
  8025. }
  8026. function buildStyle(chalk, styles) {
  8027. var enabled = {};
  8028. var _iteratorNormalCompletion2 = true;
  8029. var _didIteratorError2 = false;
  8030. var _iteratorError2 = undefined;
  8031. try {
  8032. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8033. var layer = _step2.value;
  8034. var _iteratorNormalCompletion3 = true;
  8035. var _didIteratorError3 = false;
  8036. var _iteratorError3 = undefined;
  8037. try {
  8038. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  8039. var style = _step3.value;
  8040. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  8041. }
  8042. } catch (err) {
  8043. _didIteratorError3 = true;
  8044. _iteratorError3 = err;
  8045. } finally {
  8046. try {
  8047. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  8048. _iterator3.return();
  8049. }
  8050. } finally {
  8051. if (_didIteratorError3) {
  8052. throw _iteratorError3;
  8053. }
  8054. }
  8055. }
  8056. }
  8057. } catch (err) {
  8058. _didIteratorError2 = true;
  8059. _iteratorError2 = err;
  8060. } finally {
  8061. try {
  8062. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8063. _iterator2.return();
  8064. }
  8065. } finally {
  8066. if (_didIteratorError2) {
  8067. throw _iteratorError2;
  8068. }
  8069. }
  8070. }
  8071. var current = chalk;
  8072. var _arr = Object.keys(enabled);
  8073. for (var _i = 0; _i < _arr.length; _i++) {
  8074. var styleName = _arr[_i];
  8075. if (Array.isArray(enabled[styleName])) {
  8076. if (!(styleName in current)) {
  8077. throw new Error(`Unknown Chalk style: ${styleName}`);
  8078. }
  8079. if (enabled[styleName].length > 0) {
  8080. current = current[styleName].apply(current, enabled[styleName]);
  8081. } else {
  8082. current = current[styleName];
  8083. }
  8084. }
  8085. }
  8086. return current;
  8087. }
  8088. module.exports = function (chalk, tmp) {
  8089. var styles = [];
  8090. var chunks = [];
  8091. var chunk = []; // eslint-disable-next-line max-params
  8092. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  8093. if (escapeChar) {
  8094. chunk.push(unescape(escapeChar));
  8095. } else if (style) {
  8096. var str = chunk.join('');
  8097. chunk = [];
  8098. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  8099. styles.push({
  8100. inverse,
  8101. styles: parseStyle(style)
  8102. });
  8103. } else if (close) {
  8104. if (styles.length === 0) {
  8105. throw new Error('Found extraneous } in Chalk template literal');
  8106. }
  8107. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  8108. chunk = [];
  8109. styles.pop();
  8110. } else {
  8111. chunk.push(chr);
  8112. }
  8113. });
  8114. chunks.push(chunk.join(''));
  8115. if (styles.length > 0) {
  8116. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  8117. throw new Error(errMsg);
  8118. }
  8119. return chunks.join('');
  8120. };
  8121. });
  8122. var chalk$5 = createCommonjsModule(function (module) {
  8123. 'use strict';
  8124. var stdoutColor = supportsColor_1$3.stdout;
  8125. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  8126. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  8127. var skipModels = new Set(['gray']);
  8128. var styles = Object.create(null);
  8129. function applyOptions(obj, options) {
  8130. options = options || {}; // Detect level if not set manually
  8131. var scLevel = stdoutColor ? stdoutColor.level : 0;
  8132. obj.level = options.level === undefined ? scLevel : options.level;
  8133. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  8134. }
  8135. function Chalk(options) {
  8136. // We check for this.template here since calling `chalk.constructor()`
  8137. // by itself will have a `this` of a previously constructed chalk object
  8138. if (!this || !(this instanceof Chalk) || this.template) {
  8139. var _chalk = {};
  8140. applyOptions(_chalk, options);
  8141. _chalk.template = function () {
  8142. var args = [].slice.call(arguments);
  8143. return chalkTag.apply(null, [_chalk.template].concat(args));
  8144. };
  8145. Object.setPrototypeOf(_chalk, Chalk.prototype);
  8146. Object.setPrototypeOf(_chalk.template, _chalk);
  8147. _chalk.template.constructor = Chalk;
  8148. return _chalk.template;
  8149. }
  8150. applyOptions(this, options);
  8151. } // Use bright blue on Windows as the normal blue color is illegible
  8152. if (isSimpleWindowsTerm) {
  8153. ansiStyles.blue.open = '\u001B[94m';
  8154. }
  8155. var _arr = Object.keys(ansiStyles);
  8156. var _loop = function _loop() {
  8157. var key = _arr[_i];
  8158. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  8159. styles[key] = {
  8160. get() {
  8161. var codes = ansiStyles[key];
  8162. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  8163. }
  8164. };
  8165. };
  8166. for (var _i = 0; _i < _arr.length; _i++) {
  8167. _loop();
  8168. }
  8169. styles.visible = {
  8170. get() {
  8171. return build.call(this, this._styles || [], true, 'visible');
  8172. }
  8173. };
  8174. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  8175. var _arr2 = Object.keys(ansiStyles.color.ansi);
  8176. var _loop2 = function _loop2() {
  8177. var model = _arr2[_i2];
  8178. if (skipModels.has(model)) {
  8179. return "continue";
  8180. }
  8181. styles[model] = {
  8182. get() {
  8183. var level = this.level;
  8184. return function () {
  8185. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  8186. var codes = {
  8187. open,
  8188. close: ansiStyles.color.close,
  8189. closeRe: ansiStyles.color.closeRe
  8190. };
  8191. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  8192. };
  8193. }
  8194. };
  8195. };
  8196. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  8197. var _ret = _loop2();
  8198. if (_ret === "continue") continue;
  8199. }
  8200. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  8201. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  8202. var _loop3 = function _loop3() {
  8203. var model = _arr3[_i3];
  8204. if (skipModels.has(model)) {
  8205. return "continue";
  8206. }
  8207. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  8208. styles[bgModel] = {
  8209. get() {
  8210. var level = this.level;
  8211. return function () {
  8212. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  8213. var codes = {
  8214. open,
  8215. close: ansiStyles.bgColor.close,
  8216. closeRe: ansiStyles.bgColor.closeRe
  8217. };
  8218. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  8219. };
  8220. }
  8221. };
  8222. };
  8223. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  8224. var _ret2 = _loop3();
  8225. if (_ret2 === "continue") continue;
  8226. }
  8227. var proto = Object.defineProperties(function () {}, styles);
  8228. function build(_styles, _empty, key) {
  8229. var builder = function builder() {
  8230. return applyStyle.apply(builder, arguments);
  8231. };
  8232. builder._styles = _styles;
  8233. builder._empty = _empty;
  8234. var self = this;
  8235. Object.defineProperty(builder, 'level', {
  8236. enumerable: true,
  8237. get() {
  8238. return self.level;
  8239. },
  8240. set(level) {
  8241. self.level = level;
  8242. }
  8243. });
  8244. Object.defineProperty(builder, 'enabled', {
  8245. enumerable: true,
  8246. get() {
  8247. return self.enabled;
  8248. },
  8249. set(enabled) {
  8250. self.enabled = enabled;
  8251. }
  8252. }); // See below for fix regarding invisible grey/dim combination on Windows
  8253. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  8254. // no way to create a function with a different prototype
  8255. builder.__proto__ = proto; // eslint-disable-line no-proto
  8256. return builder;
  8257. }
  8258. function applyStyle() {
  8259. // Support varags, but simply cast to string in case there's only one arg
  8260. var args = arguments;
  8261. var argsLen = args.length;
  8262. var str = String(arguments[0]);
  8263. if (argsLen === 0) {
  8264. return '';
  8265. }
  8266. if (argsLen > 1) {
  8267. // Don't slice `arguments`, it prevents V8 optimizations
  8268. for (var a = 1; a < argsLen; a++) {
  8269. str += ' ' + args[a];
  8270. }
  8271. }
  8272. if (!this.enabled || this.level <= 0 || !str) {
  8273. return this._empty ? '' : str;
  8274. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  8275. // see https://github.com/chalk/chalk/issues/58
  8276. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  8277. var originalDim = ansiStyles.dim.open;
  8278. if (isSimpleWindowsTerm && this.hasGrey) {
  8279. ansiStyles.dim.open = '';
  8280. }
  8281. var _iteratorNormalCompletion = true;
  8282. var _didIteratorError = false;
  8283. var _iteratorError = undefined;
  8284. try {
  8285. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8286. var code = _step.value;
  8287. // Replace any instances already present with a re-opening code
  8288. // otherwise only the part of the string until said closing code
  8289. // will be colored, and the rest will simply be 'plain'.
  8290. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  8291. // after next line to fix a bleed issue on macOS
  8292. // https://github.com/chalk/chalk/pull/92
  8293. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  8294. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  8295. } catch (err) {
  8296. _didIteratorError = true;
  8297. _iteratorError = err;
  8298. } finally {
  8299. try {
  8300. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8301. _iterator.return();
  8302. }
  8303. } finally {
  8304. if (_didIteratorError) {
  8305. throw _iteratorError;
  8306. }
  8307. }
  8308. }
  8309. ansiStyles.dim.open = originalDim;
  8310. return str;
  8311. }
  8312. function chalkTag(chalk, strings) {
  8313. if (!Array.isArray(strings)) {
  8314. // If chalk() was called by itself or with a string,
  8315. // return the string itself as a string.
  8316. return [].slice.call(arguments, 1).join(' ');
  8317. }
  8318. var args = [].slice.call(arguments, 2);
  8319. var parts = [strings.raw[0]];
  8320. for (var i = 1; i < strings.length; i++) {
  8321. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  8322. parts.push(String(strings.raw[i]));
  8323. }
  8324. return templates$4(chalk, parts.join(''));
  8325. }
  8326. Object.defineProperties(Chalk.prototype, styles);
  8327. module.exports = Chalk(); // eslint-disable-line new-cap
  8328. module.exports.supportsColor = stdoutColor;
  8329. module.exports.default = module.exports; // For TypeScript
  8330. });
  8331. var lib$3 = createCommonjsModule(function (module, exports) {
  8332. "use strict";
  8333. Object.defineProperty(exports, "__esModule", {
  8334. value: true
  8335. });
  8336. exports.shouldHighlight = shouldHighlight;
  8337. exports.getChalk = getChalk;
  8338. exports.default = highlight;
  8339. function _jsTokens() {
  8340. var data = _interopRequireWildcard(jsTokens);
  8341. _jsTokens = function _jsTokens() {
  8342. return data;
  8343. };
  8344. return data;
  8345. }
  8346. function _esutils() {
  8347. var data = _interopRequireDefault(utils$2);
  8348. _esutils = function _esutils() {
  8349. return data;
  8350. };
  8351. return data;
  8352. }
  8353. function _chalk() {
  8354. var data = _interopRequireDefault(chalk$5);
  8355. _chalk = function _chalk() {
  8356. return data;
  8357. };
  8358. return data;
  8359. }
  8360. function _interopRequireDefault(obj) {
  8361. return obj && obj.__esModule ? obj : {
  8362. default: obj
  8363. };
  8364. }
  8365. function _interopRequireWildcard(obj) {
  8366. if (obj && obj.__esModule) {
  8367. return obj;
  8368. } else {
  8369. var newObj = {};
  8370. if (obj != null) {
  8371. for (var key in obj) {
  8372. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  8373. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  8374. if (desc.get || desc.set) {
  8375. Object.defineProperty(newObj, key, desc);
  8376. } else {
  8377. newObj[key] = obj[key];
  8378. }
  8379. }
  8380. }
  8381. }
  8382. newObj.default = obj;
  8383. return newObj;
  8384. }
  8385. }
  8386. function getDefs(chalk) {
  8387. return {
  8388. keyword: chalk.cyan,
  8389. capitalized: chalk.yellow,
  8390. jsx_tag: chalk.yellow,
  8391. punctuator: chalk.yellow,
  8392. number: chalk.magenta,
  8393. string: chalk.green,
  8394. regex: chalk.magenta,
  8395. comment: chalk.grey,
  8396. invalid: chalk.white.bgRed.bold
  8397. };
  8398. }
  8399. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  8400. var JSX_TAG = /^[a-z][\w-]*$/i;
  8401. var BRACKET = /^[()[\]{}]$/;
  8402. function getTokenType(match) {
  8403. var _match$slice = match.slice(-2),
  8404. offset = _match$slice[0],
  8405. text = _match$slice[1];
  8406. var token = (0, _jsTokens().matchToToken)(match);
  8407. if (token.type === "name") {
  8408. if (_esutils().default.keyword.isReservedWordES6(token.value)) {
  8409. return "keyword";
  8410. }
  8411. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  8412. return "jsx_tag";
  8413. }
  8414. if (token.value[0] !== token.value[0].toLowerCase()) {
  8415. return "capitalized";
  8416. }
  8417. }
  8418. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  8419. return "bracket";
  8420. }
  8421. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  8422. return "punctuator";
  8423. }
  8424. return token.type;
  8425. }
  8426. function highlightTokens(defs, text) {
  8427. return text.replace(_jsTokens().default, function () {
  8428. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  8429. args[_key] = arguments[_key];
  8430. }
  8431. var type = getTokenType(args);
  8432. var colorize = defs[type];
  8433. if (colorize) {
  8434. return args[0].split(NEWLINE).map(function (str) {
  8435. return colorize(str);
  8436. }).join("\n");
  8437. } else {
  8438. return args[0];
  8439. }
  8440. });
  8441. }
  8442. function shouldHighlight(options) {
  8443. return _chalk().default.supportsColor || options.forceColor;
  8444. }
  8445. function getChalk(options) {
  8446. var chalk = _chalk().default;
  8447. if (options.forceColor) {
  8448. chalk = new (_chalk().default.constructor)({
  8449. enabled: true,
  8450. level: 1
  8451. });
  8452. }
  8453. return chalk;
  8454. }
  8455. function highlight(code, options) {
  8456. if (options === void 0) {
  8457. options = {};
  8458. }
  8459. if (shouldHighlight(options)) {
  8460. var chalk = getChalk(options);
  8461. var defs = getDefs(chalk);
  8462. return highlightTokens(defs, code);
  8463. } else {
  8464. return code;
  8465. }
  8466. }
  8467. });
  8468. unwrapExports(lib$3);
  8469. var lib$2 = createCommonjsModule(function (module, exports) {
  8470. "use strict";
  8471. Object.defineProperty(exports, "__esModule", {
  8472. value: true
  8473. });
  8474. exports.codeFrameColumns = codeFrameColumns;
  8475. exports.default = _default;
  8476. function _highlight() {
  8477. var data = _interopRequireWildcard(lib$3);
  8478. _highlight = function _highlight() {
  8479. return data;
  8480. };
  8481. return data;
  8482. }
  8483. function _interopRequireWildcard(obj) {
  8484. if (obj && obj.__esModule) {
  8485. return obj;
  8486. } else {
  8487. var newObj = {};
  8488. if (obj != null) {
  8489. for (var key in obj) {
  8490. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  8491. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  8492. if (desc.get || desc.set) {
  8493. Object.defineProperty(newObj, key, desc);
  8494. } else {
  8495. newObj[key] = obj[key];
  8496. }
  8497. }
  8498. }
  8499. }
  8500. newObj.default = obj;
  8501. return newObj;
  8502. }
  8503. }
  8504. var deprecationWarningShown = false;
  8505. function getDefs(chalk) {
  8506. return {
  8507. gutter: chalk.grey,
  8508. marker: chalk.red.bold,
  8509. message: chalk.red.bold
  8510. };
  8511. }
  8512. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  8513. function getMarkerLines(loc, source, opts) {
  8514. var startLoc = Object.assign({}, {
  8515. column: 0,
  8516. line: -1
  8517. }, loc.start);
  8518. var endLoc = Object.assign({}, startLoc, loc.end);
  8519. var _ref = opts || {},
  8520. _ref$linesAbove = _ref.linesAbove,
  8521. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  8522. _ref$linesBelow = _ref.linesBelow,
  8523. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  8524. var startLine = startLoc.line;
  8525. var startColumn = startLoc.column;
  8526. var endLine = endLoc.line;
  8527. var endColumn = endLoc.column;
  8528. var start = Math.max(startLine - (linesAbove + 1), 0);
  8529. var end = Math.min(source.length, endLine + linesBelow);
  8530. if (startLine === -1) {
  8531. start = 0;
  8532. }
  8533. if (endLine === -1) {
  8534. end = source.length;
  8535. }
  8536. var lineDiff = endLine - startLine;
  8537. var markerLines = {};
  8538. if (lineDiff) {
  8539. for (var i = 0; i <= lineDiff; i++) {
  8540. var lineNumber = i + startLine;
  8541. if (!startColumn) {
  8542. markerLines[lineNumber] = true;
  8543. } else if (i === 0) {
  8544. var sourceLength = source[lineNumber - 1].length;
  8545. markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
  8546. } else if (i === lineDiff) {
  8547. markerLines[lineNumber] = [0, endColumn];
  8548. } else {
  8549. var _sourceLength = source[lineNumber - i].length;
  8550. markerLines[lineNumber] = [0, _sourceLength];
  8551. }
  8552. }
  8553. } else {
  8554. if (startColumn === endColumn) {
  8555. if (startColumn) {
  8556. markerLines[startLine] = [startColumn, 0];
  8557. } else {
  8558. markerLines[startLine] = true;
  8559. }
  8560. } else {
  8561. markerLines[startLine] = [startColumn, endColumn - startColumn];
  8562. }
  8563. }
  8564. return {
  8565. start: start,
  8566. end: end,
  8567. markerLines: markerLines
  8568. };
  8569. }
  8570. function codeFrameColumns(rawLines, loc, opts) {
  8571. if (opts === void 0) {
  8572. opts = {};
  8573. }
  8574. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
  8575. var chalk = (0, _highlight().getChalk)(opts);
  8576. var defs = getDefs(chalk);
  8577. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  8578. return highlighted ? chalkFn(string) : string;
  8579. };
  8580. if (highlighted) rawLines = (0, _highlight().default)(rawLines, opts);
  8581. var lines = rawLines.split(NEWLINE);
  8582. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  8583. start = _getMarkerLines.start,
  8584. end = _getMarkerLines.end,
  8585. markerLines = _getMarkerLines.markerLines;
  8586. var hasColumns = loc.start && typeof loc.start.column === "number";
  8587. var numberMaxWidth = String(end).length;
  8588. var frame = lines.slice(start, end).map(function (line, index) {
  8589. var number = start + 1 + index;
  8590. var paddedNumber = (" " + number).slice(-numberMaxWidth);
  8591. var gutter = " " + paddedNumber + " | ";
  8592. var hasMarker = markerLines[number];
  8593. var lastMarkerLine = !markerLines[number + 1];
  8594. if (hasMarker) {
  8595. var markerLine = "";
  8596. if (Array.isArray(hasMarker)) {
  8597. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  8598. var numberOfMarkers = hasMarker[1] || 1;
  8599. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  8600. if (lastMarkerLine && opts.message) {
  8601. markerLine += " " + maybeHighlight(defs.message, opts.message);
  8602. }
  8603. }
  8604. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  8605. } else {
  8606. return " " + maybeHighlight(defs.gutter, gutter) + line;
  8607. }
  8608. }).join("\n");
  8609. if (opts.message && !hasColumns) {
  8610. frame = "" + " ".repeat(numberMaxWidth + 1) + opts.message + "\n" + frame;
  8611. }
  8612. if (highlighted) {
  8613. return chalk.reset(frame);
  8614. } else {
  8615. return frame;
  8616. }
  8617. }
  8618. function _default(rawLines, lineNumber, colNumber, opts) {
  8619. if (opts === void 0) {
  8620. opts = {};
  8621. }
  8622. if (!deprecationWarningShown) {
  8623. deprecationWarningShown = true;
  8624. var message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  8625. if (process.emitWarning) {
  8626. process.emitWarning(message, "DeprecationWarning");
  8627. } else {
  8628. var deprecationError = new Error(message);
  8629. deprecationError.name = "DeprecationWarning";
  8630. console.warn(new Error(message));
  8631. }
  8632. }
  8633. colNumber = Math.max(colNumber, 0);
  8634. var location = {
  8635. start: {
  8636. column: colNumber,
  8637. line: lineNumber
  8638. }
  8639. };
  8640. return codeFrameColumns(rawLines, location, opts);
  8641. }
  8642. });
  8643. unwrapExports(lib$2);
  8644. var ConfigError$1 = errors.ConfigError;
  8645. var locStart = loc.locStart;
  8646. var locEnd = loc.locEnd; // Use defineProperties()/getOwnPropertyDescriptor() to prevent
  8647. // triggering the parsers getters.
  8648. var ownNames = Object.getOwnPropertyNames;
  8649. var ownDescriptor = Object.getOwnPropertyDescriptor;
  8650. function getParsers(options) {
  8651. var parsers = {};
  8652. var _iteratorNormalCompletion = true;
  8653. var _didIteratorError = false;
  8654. var _iteratorError = undefined;
  8655. try {
  8656. for (var _iterator = options.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8657. var plugin = _step.value;
  8658. if (!plugin.parsers) {
  8659. continue;
  8660. }
  8661. var _iteratorNormalCompletion2 = true;
  8662. var _didIteratorError2 = false;
  8663. var _iteratorError2 = undefined;
  8664. try {
  8665. for (var _iterator2 = ownNames(plugin.parsers)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8666. var name = _step2.value;
  8667. Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name));
  8668. }
  8669. } catch (err) {
  8670. _didIteratorError2 = true;
  8671. _iteratorError2 = err;
  8672. } finally {
  8673. try {
  8674. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8675. _iterator2.return();
  8676. }
  8677. } finally {
  8678. if (_didIteratorError2) {
  8679. throw _iteratorError2;
  8680. }
  8681. }
  8682. }
  8683. }
  8684. } catch (err) {
  8685. _didIteratorError = true;
  8686. _iteratorError = err;
  8687. } finally {
  8688. try {
  8689. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8690. _iterator.return();
  8691. }
  8692. } finally {
  8693. if (_didIteratorError) {
  8694. throw _iteratorError;
  8695. }
  8696. }
  8697. }
  8698. return parsers;
  8699. }
  8700. function resolveParser$1(opts, parsers) {
  8701. parsers = parsers || getParsers(opts);
  8702. if (typeof opts.parser === "function") {
  8703. // Custom parser API always works with JavaScript.
  8704. return {
  8705. parse: opts.parser,
  8706. astFormat: "estree",
  8707. locStart,
  8708. locEnd
  8709. };
  8710. }
  8711. if (typeof opts.parser === "string") {
  8712. if (parsers.hasOwnProperty(opts.parser)) {
  8713. return parsers[opts.parser];
  8714. }
  8715. /* istanbul ignore next */
  8716. {
  8717. try {
  8718. return {
  8719. parse: require(path.resolve(process.cwd(), opts.parser)),
  8720. astFormat: "estree",
  8721. locStart,
  8722. locEnd
  8723. };
  8724. } catch (err) {
  8725. /* istanbul ignore next */
  8726. throw new ConfigError$1(`Couldn't resolve parser "${opts.parser}"`);
  8727. }
  8728. }
  8729. }
  8730. }
  8731. function parse$2(text, opts) {
  8732. var parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call
  8733. // the parsers getters when actually calling the parser `parse` function.
  8734. var parsersForCustomParserApi = Object.keys(parsers).reduce(function (object, parserName) {
  8735. return Object.defineProperty(object, parserName, {
  8736. enumerable: true,
  8737. get() {
  8738. return parsers[parserName].parse;
  8739. }
  8740. });
  8741. }, {});
  8742. var parser = resolveParser$1(opts, parsers);
  8743. try {
  8744. if (parser.preprocess) {
  8745. text = parser.preprocess(text, opts);
  8746. }
  8747. return {
  8748. text,
  8749. ast: parser.parse(text, parsersForCustomParserApi, opts)
  8750. };
  8751. } catch (error) {
  8752. var loc$$1 = error.loc;
  8753. if (loc$$1) {
  8754. var codeFrame = lib$2;
  8755. error.codeFrame = codeFrame.codeFrameColumns(text, loc$$1, {
  8756. highlightCode: true
  8757. });
  8758. error.message += "\n" + error.codeFrame;
  8759. throw error;
  8760. }
  8761. /* istanbul ignore next */
  8762. throw error.stack;
  8763. }
  8764. }
  8765. var parser = {
  8766. parse: parse$2,
  8767. resolveParser: resolveParser$1
  8768. };
  8769. var UndefinedParserError = errors.UndefinedParserError;
  8770. var getSupportInfo$1 = support.getSupportInfo;
  8771. var resolveParser = parser.resolveParser;
  8772. var hiddenDefaults = {
  8773. astFormat: "estree",
  8774. printer: {},
  8775. originalText: undefined,
  8776. locStart: null,
  8777. locEnd: null
  8778. }; // Copy options and fill in default values.
  8779. function normalize(options, opts) {
  8780. opts = opts || {};
  8781. var rawOptions = Object.assign({}, options);
  8782. var supportOptions = getSupportInfo$1(null, {
  8783. plugins: options.plugins,
  8784. showUnreleased: true,
  8785. showDeprecated: true
  8786. }).options;
  8787. var defaults = supportOptions.reduce(function (reduced, optionInfo) {
  8788. return optionInfo.default !== undefined ? Object.assign(reduced, {
  8789. [optionInfo.name]: optionInfo.default
  8790. }) : reduced;
  8791. }, Object.assign({}, hiddenDefaults));
  8792. if (!rawOptions.parser) {
  8793. if (!rawOptions.filepath) {
  8794. var logger = opts.logger || console;
  8795. 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.");
  8796. rawOptions.parser = "babel";
  8797. } else {
  8798. rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins);
  8799. if (!rawOptions.parser) {
  8800. throw new UndefinedParserError(`No parser could be inferred for file: ${rawOptions.filepath}`);
  8801. }
  8802. }
  8803. }
  8804. var parser$$1 = resolveParser(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(function (x) {
  8805. return x.name === "parser";
  8806. })], {
  8807. passThrough: true,
  8808. logger: false
  8809. }));
  8810. rawOptions.astFormat = parser$$1.astFormat;
  8811. rawOptions.locEnd = parser$$1.locEnd;
  8812. rawOptions.locStart = parser$$1.locStart;
  8813. var plugin = getPlugin(rawOptions);
  8814. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  8815. var pluginDefaults = supportOptions.filter(function (optionInfo) {
  8816. return optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name];
  8817. }).reduce(function (reduced, optionInfo) {
  8818. return Object.assign(reduced, {
  8819. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  8820. });
  8821. }, {});
  8822. var mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  8823. Object.keys(mixedDefaults).forEach(function (k) {
  8824. if (rawOptions[k] == null) {
  8825. rawOptions[k] = mixedDefaults[k];
  8826. }
  8827. });
  8828. if (rawOptions.parser === "json") {
  8829. rawOptions.trailingComma = "none";
  8830. }
  8831. return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({
  8832. passThrough: Object.keys(hiddenDefaults)
  8833. }, opts));
  8834. }
  8835. function getPlugin(options) {
  8836. var astFormat = options.astFormat;
  8837. if (!astFormat) {
  8838. throw new Error("getPlugin() requires astFormat to be set");
  8839. }
  8840. var printerPlugin = options.plugins.find(function (plugin) {
  8841. return plugin.printers && plugin.printers[astFormat];
  8842. });
  8843. if (!printerPlugin) {
  8844. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  8845. }
  8846. return printerPlugin;
  8847. }
  8848. function getInterpreter(filepath) {
  8849. if (typeof filepath !== "string") {
  8850. return "";
  8851. }
  8852. var fd;
  8853. try {
  8854. fd = fs.openSync(filepath, "r");
  8855. } catch (err) {
  8856. return "";
  8857. }
  8858. try {
  8859. var liner = new readlines(fd);
  8860. var firstLine = liner.next().toString("utf8"); // #!/bin/env node, #!/usr/bin/env node
  8861. var m1 = firstLine.match(/^#!\/(?:usr\/)?bin\/env\s+(\S+)/);
  8862. if (m1) {
  8863. return m1[1];
  8864. } // #!/bin/node, #!/usr/bin/node, #!/usr/local/bin/node
  8865. var m2 = firstLine.match(/^#!\/(?:usr\/(?:local\/)?)?bin\/(\S+)/);
  8866. if (m2) {
  8867. return m2[1];
  8868. }
  8869. return "";
  8870. } catch (err) {
  8871. // There are some weird cases where paths are missing, causing Jest
  8872. // failures. It's unclear what these correspond to in the real world.
  8873. return "";
  8874. } finally {
  8875. try {
  8876. // There are some weird cases where paths are missing, causing Jest
  8877. // failures. It's unclear what these correspond to in the real world.
  8878. fs.closeSync(fd);
  8879. } catch (err) {// nop
  8880. }
  8881. }
  8882. }
  8883. function inferParser(filepath, plugins) {
  8884. var filepathParts = normalizePath(filepath).split("/");
  8885. var filename = filepathParts[filepathParts.length - 1].toLowerCase(); // If the file has no extension, we can try to infer the language from the
  8886. // interpreter in the shebang line, if any; but since this requires FS access,
  8887. // do it last.
  8888. var language = getSupportInfo$1(null, {
  8889. plugins
  8890. }).languages.find(function (language) {
  8891. return language.since !== null && (language.extensions && language.extensions.some(function (extension) {
  8892. return filename.endsWith(extension);
  8893. }) || language.filenames && language.filenames.find(function (name) {
  8894. return name.toLowerCase() === filename;
  8895. }) || filename.indexOf(".") === -1 && language.interpreters && language.interpreters.indexOf(getInterpreter(filepath)) !== -1);
  8896. });
  8897. return language && language.parsers[0];
  8898. }
  8899. var options = {
  8900. normalize,
  8901. hiddenDefaults,
  8902. inferParser
  8903. };
  8904. function massageAST(ast, options, parent) {
  8905. if (Array.isArray(ast)) {
  8906. return ast.map(function (e) {
  8907. return massageAST(e, options, parent);
  8908. }).filter(function (e) {
  8909. return e;
  8910. });
  8911. }
  8912. if (!ast || typeof ast !== "object") {
  8913. return ast;
  8914. }
  8915. var newObj = {};
  8916. var _arr = Object.keys(ast);
  8917. for (var _i = 0; _i < _arr.length; _i++) {
  8918. var key = _arr[_i];
  8919. if (typeof ast[key] !== "function") {
  8920. newObj[key] = massageAST(ast[key], options, ast);
  8921. }
  8922. }
  8923. if (options.printer.massageAstNode) {
  8924. var result = options.printer.massageAstNode(ast, newObj, parent);
  8925. if (result === null) {
  8926. return undefined;
  8927. }
  8928. if (result) {
  8929. return result;
  8930. }
  8931. }
  8932. return newObj;
  8933. }
  8934. var massageAst = massageAST;
  8935. function concat$1(parts) {
  8936. return {
  8937. type: "concat",
  8938. parts
  8939. };
  8940. }
  8941. function indent$1(contents) {
  8942. return {
  8943. type: "indent",
  8944. contents
  8945. };
  8946. }
  8947. function align(n, contents) {
  8948. return {
  8949. type: "align",
  8950. contents,
  8951. n
  8952. };
  8953. }
  8954. function group(contents, opts) {
  8955. opts = opts || {};
  8956. return {
  8957. type: "group",
  8958. id: opts.id,
  8959. contents: contents,
  8960. break: !!opts.shouldBreak,
  8961. expandedStates: opts.expandedStates
  8962. };
  8963. }
  8964. function dedentToRoot(contents) {
  8965. return align(-Infinity, contents);
  8966. }
  8967. function markAsRoot(contents) {
  8968. return align({
  8969. type: "root"
  8970. }, contents);
  8971. }
  8972. function dedent$1(contents) {
  8973. return align(-1, contents);
  8974. }
  8975. function conditionalGroup(states, opts) {
  8976. return group(states[0], Object.assign(opts || {}, {
  8977. expandedStates: states
  8978. }));
  8979. }
  8980. function fill(parts) {
  8981. return {
  8982. type: "fill",
  8983. parts
  8984. };
  8985. }
  8986. function ifBreak(breakContents, flatContents, opts) {
  8987. opts = opts || {};
  8988. return {
  8989. type: "if-break",
  8990. breakContents,
  8991. flatContents,
  8992. groupId: opts.groupId
  8993. };
  8994. }
  8995. function lineSuffix$1(contents) {
  8996. return {
  8997. type: "line-suffix",
  8998. contents
  8999. };
  9000. }
  9001. var lineSuffixBoundary = {
  9002. type: "line-suffix-boundary"
  9003. };
  9004. var breakParent$1 = {
  9005. type: "break-parent"
  9006. };
  9007. var trim = {
  9008. type: "trim"
  9009. };
  9010. var line$2 = {
  9011. type: "line"
  9012. };
  9013. var softline = {
  9014. type: "line",
  9015. soft: true
  9016. };
  9017. var hardline$1 = concat$1([{
  9018. type: "line",
  9019. hard: true
  9020. }, breakParent$1]);
  9021. var literalline = concat$1([{
  9022. type: "line",
  9023. hard: true,
  9024. literal: true
  9025. }, breakParent$1]);
  9026. var cursor$1 = {
  9027. type: "cursor",
  9028. placeholder: Symbol("cursor")
  9029. };
  9030. function join$1(sep, arr) {
  9031. var res = [];
  9032. for (var i = 0; i < arr.length; i++) {
  9033. if (i !== 0) {
  9034. res.push(sep);
  9035. }
  9036. res.push(arr[i]);
  9037. }
  9038. return concat$1(res);
  9039. }
  9040. function addAlignmentToDoc(doc, size, tabWidth) {
  9041. var aligned = doc;
  9042. if (size > 0) {
  9043. // Use indent to add tabs for all the levels of tabs we need
  9044. for (var i = 0; i < Math.floor(size / tabWidth); ++i) {
  9045. aligned = indent$1(aligned);
  9046. } // Use align for all the spaces that are needed
  9047. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  9048. // indentation, so we use -Infinity to reset the indentation to 0
  9049. aligned = align(-Infinity, aligned);
  9050. }
  9051. return aligned;
  9052. }
  9053. var docBuilders = {
  9054. concat: concat$1,
  9055. join: join$1,
  9056. line: line$2,
  9057. softline,
  9058. hardline: hardline$1,
  9059. literalline,
  9060. group,
  9061. conditionalGroup,
  9062. fill,
  9063. lineSuffix: lineSuffix$1,
  9064. lineSuffixBoundary,
  9065. cursor: cursor$1,
  9066. breakParent: breakParent$1,
  9067. ifBreak,
  9068. trim,
  9069. indent: indent$1,
  9070. align,
  9071. addAlignmentToDoc,
  9072. markAsRoot,
  9073. dedentToRoot,
  9074. dedent: dedent$1
  9075. };
  9076. var ansiRegex = createCommonjsModule(function (module) {
  9077. 'use strict';
  9078. module.exports = function (options) {
  9079. options = Object.assign({
  9080. onlyFirst: false
  9081. }, options);
  9082. var pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  9083. return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
  9084. };
  9085. });
  9086. var stripAnsi = function stripAnsi(input) {
  9087. return typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
  9088. };
  9089. var isFullwidthCodePoint = createCommonjsModule(function (module) {
  9090. 'use strict';
  9091. /* eslint-disable yoda */
  9092. module.exports = function (x) {
  9093. if (Number.isNaN(x)) {
  9094. return false;
  9095. } // code points are derived from:
  9096. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  9097. if (x >= 0x1100 && (x <= 0x115f || // Hangul Jamo
  9098. x === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  9099. x === 0x232a || // RIGHT-POINTING ANGLE BRACKET
  9100. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  9101. 0x2e80 <= x && x <= 0x3247 && x !== 0x303f || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  9102. 0x3250 <= x && x <= 0x4dbf || // CJK Unified Ideographs .. Yi Radicals
  9103. 0x4e00 <= x && x <= 0xa4c6 || // Hangul Jamo Extended-A
  9104. 0xa960 <= x && x <= 0xa97c || // Hangul Syllables
  9105. 0xac00 <= x && x <= 0xd7a3 || // CJK Compatibility Ideographs
  9106. 0xf900 <= x && x <= 0xfaff || // Vertical Forms
  9107. 0xfe10 <= x && x <= 0xfe19 || // CJK Compatibility Forms .. Small Form Variants
  9108. 0xfe30 <= x && x <= 0xfe6b || // Halfwidth and Fullwidth Forms
  9109. 0xff01 <= x && x <= 0xff60 || 0xffe0 <= x && x <= 0xffe6 || // Kana Supplement
  9110. 0x1b000 <= x && x <= 0x1b001 || // Enclosed Ideographic Supplement
  9111. 0x1f200 <= x && x <= 0x1f251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  9112. 0x20000 <= x && x <= 0x3fffd)) {
  9113. return true;
  9114. }
  9115. return false;
  9116. };
  9117. });
  9118. var emojiRegex = function emojiRegex() {
  9119. // https://mths.be/emoji
  9120. 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;
  9121. };
  9122. var stringWidth = createCommonjsModule(function (module) {
  9123. 'use strict';
  9124. var emojiRegex$$1 = emojiRegex();
  9125. module.exports = function (input) {
  9126. input = input.replace(emojiRegex$$1, ' ');
  9127. if (typeof input !== 'string' || input.length === 0) {
  9128. return 0;
  9129. }
  9130. input = stripAnsi(input);
  9131. var width = 0;
  9132. for (var i = 0; i < input.length; i++) {
  9133. var code = input.codePointAt(i); // Ignore control characters
  9134. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  9135. continue;
  9136. } // Ignore combining characters
  9137. if (code >= 0x300 && code <= 0x36F) {
  9138. continue;
  9139. } // Surrogates
  9140. if (code > 0xFFFF) {
  9141. i++;
  9142. }
  9143. width += isFullwidthCodePoint(code) ? 2 : 1;
  9144. }
  9145. return width;
  9146. };
  9147. });
  9148. var notAsciiRegex = /[^\x20-\x7F]/;
  9149. function isExportDeclaration(node) {
  9150. if (node) {
  9151. switch (node.type) {
  9152. case "ExportDefaultDeclaration":
  9153. case "ExportDefaultSpecifier":
  9154. case "DeclareExportDeclaration":
  9155. case "ExportNamedDeclaration":
  9156. case "ExportAllDeclaration":
  9157. return true;
  9158. }
  9159. }
  9160. return false;
  9161. }
  9162. function getParentExportDeclaration(path$$1) {
  9163. var parentNode = path$$1.getParentNode();
  9164. if (path$$1.getName() === "declaration" && isExportDeclaration(parentNode)) {
  9165. return parentNode;
  9166. }
  9167. return null;
  9168. }
  9169. function getPenultimate(arr) {
  9170. if (arr.length > 1) {
  9171. return arr[arr.length - 2];
  9172. }
  9173. return null;
  9174. }
  9175. function getLast$3(arr) {
  9176. if (arr.length > 0) {
  9177. return arr[arr.length - 1];
  9178. }
  9179. return null;
  9180. }
  9181. function skip(chars) {
  9182. return function (text, index, opts) {
  9183. var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  9184. // to check for failures (did someone say monads?).
  9185. if (index === false) {
  9186. return false;
  9187. }
  9188. var length = text.length;
  9189. var cursor = index;
  9190. while (cursor >= 0 && cursor < length) {
  9191. var c = text.charAt(cursor);
  9192. if (chars instanceof RegExp) {
  9193. if (!chars.test(c)) {
  9194. return cursor;
  9195. }
  9196. } else if (chars.indexOf(c) === -1) {
  9197. return cursor;
  9198. }
  9199. backwards ? cursor-- : cursor++;
  9200. }
  9201. if (cursor === -1 || cursor === length) {
  9202. // If we reached the beginning or end of the file, return the
  9203. // out-of-bounds cursor. It's up to the caller to handle this
  9204. // correctly. We don't want to indicate `false` though if it
  9205. // actually skipped valid characters.
  9206. return cursor;
  9207. }
  9208. return false;
  9209. };
  9210. }
  9211. var skipWhitespace = skip(/\s/);
  9212. var skipSpaces = skip(" \t");
  9213. var skipToLineEnd = skip(",; \t");
  9214. var skipEverythingButNewLine = skip(/[^\r\n]/);
  9215. function skipInlineComment(text, index) {
  9216. if (index === false) {
  9217. return false;
  9218. }
  9219. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  9220. for (var i = index + 2; i < text.length; ++i) {
  9221. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  9222. return i + 2;
  9223. }
  9224. }
  9225. }
  9226. return index;
  9227. }
  9228. function skipTrailingComment(text, index) {
  9229. if (index === false) {
  9230. return false;
  9231. }
  9232. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  9233. return skipEverythingButNewLine(text, index);
  9234. }
  9235. return index;
  9236. } // This one doesn't use the above helper function because it wants to
  9237. // test \r\n in order and `skip` doesn't support ordering and we only
  9238. // want to skip one newline. It's simple to implement.
  9239. function skipNewline$1(text, index, opts) {
  9240. var backwards = opts && opts.backwards;
  9241. if (index === false) {
  9242. return false;
  9243. }
  9244. var atIndex = text.charAt(index);
  9245. if (backwards) {
  9246. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  9247. return index - 2;
  9248. }
  9249. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  9250. return index - 1;
  9251. }
  9252. } else {
  9253. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  9254. return index + 2;
  9255. }
  9256. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  9257. return index + 1;
  9258. }
  9259. }
  9260. return index;
  9261. }
  9262. function hasNewline$1(text, index, opts) {
  9263. opts = opts || {};
  9264. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  9265. var idx2 = skipNewline$1(text, idx, opts);
  9266. return idx !== idx2;
  9267. }
  9268. function hasNewlineInRange(text, start, end) {
  9269. for (var i = start; i < end; ++i) {
  9270. if (text.charAt(i) === "\n") {
  9271. return true;
  9272. }
  9273. }
  9274. return false;
  9275. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  9276. function isPreviousLineEmpty$1(text, node, locStart) {
  9277. var idx = locStart(node) - 1;
  9278. idx = skipSpaces(text, idx, {
  9279. backwards: true
  9280. });
  9281. idx = skipNewline$1(text, idx, {
  9282. backwards: true
  9283. });
  9284. idx = skipSpaces(text, idx, {
  9285. backwards: true
  9286. });
  9287. var idx2 = skipNewline$1(text, idx, {
  9288. backwards: true
  9289. });
  9290. return idx !== idx2;
  9291. }
  9292. function isNextLineEmptyAfterIndex(text, index) {
  9293. var oldIdx = null;
  9294. var idx = index;
  9295. while (idx !== oldIdx) {
  9296. // We need to skip all the potential trailing inline comments
  9297. oldIdx = idx;
  9298. idx = skipToLineEnd(text, idx);
  9299. idx = skipInlineComment(text, idx);
  9300. idx = skipSpaces(text, idx);
  9301. }
  9302. idx = skipTrailingComment(text, idx);
  9303. idx = skipNewline$1(text, idx);
  9304. return hasNewline$1(text, idx);
  9305. }
  9306. function isNextLineEmpty(text, node, locEnd) {
  9307. return isNextLineEmptyAfterIndex(text, locEnd(node));
  9308. }
  9309. function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
  9310. var oldIdx = null;
  9311. while (idx !== oldIdx) {
  9312. oldIdx = idx;
  9313. idx = skipSpaces(text, idx);
  9314. idx = skipInlineComment(text, idx);
  9315. idx = skipTrailingComment(text, idx);
  9316. idx = skipNewline$1(text, idx);
  9317. }
  9318. return idx;
  9319. }
  9320. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  9321. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
  9322. }
  9323. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  9324. return text.charAt(getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  9325. }
  9326. function hasSpaces(text, index, opts) {
  9327. opts = opts || {};
  9328. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  9329. return idx !== index;
  9330. }
  9331. function setLocStart(node, index) {
  9332. if (node.range) {
  9333. node.range[0] = index;
  9334. } else {
  9335. node.start = index;
  9336. }
  9337. }
  9338. function setLocEnd(node, index) {
  9339. if (node.range) {
  9340. node.range[1] = index;
  9341. } else {
  9342. node.end = index;
  9343. }
  9344. }
  9345. var PRECEDENCE = {};
  9346. [["|>"], ["||", "??"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(function (tier, i) {
  9347. tier.forEach(function (op) {
  9348. PRECEDENCE[op] = i;
  9349. });
  9350. });
  9351. function getPrecedence(op) {
  9352. return PRECEDENCE[op];
  9353. }
  9354. var equalityOperators = {
  9355. "==": true,
  9356. "!=": true,
  9357. "===": true,
  9358. "!==": true
  9359. };
  9360. var multiplicativeOperators = {
  9361. "*": true,
  9362. "/": true,
  9363. "%": true
  9364. };
  9365. var bitshiftOperators = {
  9366. ">>": true,
  9367. ">>>": true,
  9368. "<<": true
  9369. };
  9370. function shouldFlatten(parentOp, nodeOp) {
  9371. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  9372. return false;
  9373. } // ** is right-associative
  9374. // x ** y ** z --> x ** (y ** z)
  9375. if (parentOp === "**") {
  9376. return false;
  9377. } // x == y == z --> (x == y) == z
  9378. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  9379. return false;
  9380. } // x * y % z --> (x * y) % z
  9381. if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
  9382. return false;
  9383. } // x * y / z --> (x * y) / z
  9384. // x / y * z --> (x / y) * z
  9385. if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
  9386. return false;
  9387. } // x << y << z --> (x << y) << z
  9388. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  9389. return false;
  9390. }
  9391. return true;
  9392. }
  9393. function isBitwiseOperator(operator) {
  9394. return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
  9395. } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
  9396. // holds) `function`, `class`, or `do {}`. Will be overzealous if there's
  9397. // already necessary grouping parentheses.
  9398. function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
  9399. node = getLeftMost(node);
  9400. switch (node.type) {
  9401. case "FunctionExpression":
  9402. case "ClassExpression":
  9403. case "DoExpression":
  9404. return forbidFunctionClassAndDoExpr;
  9405. case "ObjectExpression":
  9406. return true;
  9407. case "MemberExpression":
  9408. return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  9409. case "TaggedTemplateExpression":
  9410. if (node.tag.type === "FunctionExpression") {
  9411. // IIFEs are always already parenthesized
  9412. return false;
  9413. }
  9414. return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
  9415. case "CallExpression":
  9416. if (node.callee.type === "FunctionExpression") {
  9417. // IIFEs are always already parenthesized
  9418. return false;
  9419. }
  9420. return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
  9421. case "ConditionalExpression":
  9422. return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
  9423. case "UpdateExpression":
  9424. return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
  9425. case "BindExpression":
  9426. return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  9427. case "SequenceExpression":
  9428. return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
  9429. case "TSAsExpression":
  9430. return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
  9431. default:
  9432. return false;
  9433. }
  9434. }
  9435. function getLeftMost(node) {
  9436. if (node.left) {
  9437. return getLeftMost(node.left);
  9438. }
  9439. return node;
  9440. }
  9441. function getAlignmentSize(value, tabWidth, startIndex) {
  9442. startIndex = startIndex || 0;
  9443. var size = 0;
  9444. for (var i = startIndex; i < value.length; ++i) {
  9445. if (value[i] === "\t") {
  9446. // Tabs behave in a way that they are aligned to the nearest
  9447. // multiple of tabWidth:
  9448. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  9449. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  9450. size = size + tabWidth - size % tabWidth;
  9451. } else {
  9452. size++;
  9453. }
  9454. }
  9455. return size;
  9456. }
  9457. function getIndentSize(value, tabWidth) {
  9458. var lastNewlineIndex = value.lastIndexOf("\n");
  9459. if (lastNewlineIndex === -1) {
  9460. return 0;
  9461. }
  9462. return getAlignmentSize( // All the leading whitespaces
  9463. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0], tabWidth);
  9464. }
  9465. function getPreferredQuote(raw, preferredQuote) {
  9466. // `rawContent` is the string exactly like it appeared in the input source
  9467. // code, without its enclosing quotes.
  9468. var rawContent = raw.slice(1, -1);
  9469. var double = {
  9470. quote: '"',
  9471. regex: /"/g
  9472. };
  9473. var single = {
  9474. quote: "'",
  9475. regex: /'/g
  9476. };
  9477. var preferred = preferredQuote === "'" ? single : double;
  9478. var alternate = preferred === single ? double : single;
  9479. var result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
  9480. // the string, we might want to enclose with the alternate quote instead, to
  9481. // minimize the number of escaped quotes.
  9482. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  9483. var numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  9484. var numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  9485. result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
  9486. }
  9487. return result;
  9488. }
  9489. function printString(raw, options, isDirectiveLiteral) {
  9490. // `rawContent` is the string exactly like it appeared in the input source
  9491. // code, without its enclosing quotes.
  9492. var rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
  9493. // the quotes on a DirectiveLiteral.
  9494. var canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
  9495. var enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
  9496. // change the escape sequences they use.
  9497. // See https://github.com/prettier/prettier/issues/1555
  9498. // and https://tc39.github.io/ecma262/#directive-prologue
  9499. if (isDirectiveLiteral) {
  9500. if (canChangeDirectiveQuotes) {
  9501. return enclosingQuote + rawContent + enclosingQuote;
  9502. }
  9503. return raw;
  9504. } // It might sound unnecessary to use `makeString` even if the string already
  9505. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  9506. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  9507. // sure that we consistently output the minimum amount of escaped quotes.
  9508. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.parentParser === "html" || options.parentParser === "vue" || options.parentParser === "angular"));
  9509. }
  9510. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  9511. var otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  9512. var regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
  9513. // enclose `rawContent` with `enclosingQuote`.
  9514. var newContent = rawContent.replace(regex, function (match, escaped, quote) {
  9515. // If we matched an escape, and the escaped character is a quote of the
  9516. // other type than we intend to enclose the string with, there's no need for
  9517. // it to be escaped, so return it _without_ the backslash.
  9518. if (escaped === otherQuote) {
  9519. return escaped;
  9520. } // If we matched an unescaped quote and it is of the _same_ type as we
  9521. // intend to enclose the string with, it must be escaped, so return it with
  9522. // a backslash.
  9523. if (quote === enclosingQuote) {
  9524. return "\\" + quote;
  9525. }
  9526. if (quote) {
  9527. return quote;
  9528. } // Unescape any unnecessarily escaped character.
  9529. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  9530. return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) ? escaped : "\\" + escaped;
  9531. });
  9532. return enclosingQuote + newContent + enclosingQuote;
  9533. }
  9534. function printNumber(rawNumber) {
  9535. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  9536. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  9537. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  9538. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  9539. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  9540. .replace(/\.(?=e|$)/, "");
  9541. }
  9542. function getMaxContinuousCount(str, target) {
  9543. var results = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  9544. if (results === null) {
  9545. return 0;
  9546. }
  9547. return results.reduce(function (maxCount, result) {
  9548. return Math.max(maxCount, result.length / target.length);
  9549. }, 0);
  9550. }
  9551. function getStringWidth$1(text) {
  9552. if (!text) {
  9553. return 0;
  9554. } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
  9555. if (!notAsciiRegex.test(text)) {
  9556. return text.length;
  9557. }
  9558. return stringWidth(text);
  9559. }
  9560. function hasIgnoreComment(path$$1) {
  9561. var node = path$$1.getValue();
  9562. return hasNodeIgnoreComment(node);
  9563. }
  9564. function hasNodeIgnoreComment(node) {
  9565. return node && node.comments && node.comments.length > 0 && node.comments.some(function (comment) {
  9566. return comment.value.trim() === "prettier-ignore";
  9567. });
  9568. }
  9569. function matchAncestorTypes(path$$1, types, index) {
  9570. index = index || 0;
  9571. types = types.slice();
  9572. while (types.length) {
  9573. var parent = path$$1.getParentNode(index);
  9574. var type = types.shift();
  9575. if (!parent || parent.type !== type) {
  9576. return false;
  9577. }
  9578. index++;
  9579. }
  9580. return true;
  9581. }
  9582. function addCommentHelper(node, comment) {
  9583. var comments = node.comments || (node.comments = []);
  9584. comments.push(comment);
  9585. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  9586. // We already "print" it via the raw text, we don't need to re-print it as a
  9587. // comment
  9588. if (node.type === "JSXText") {
  9589. comment.printed = true;
  9590. }
  9591. }
  9592. function addLeadingComment$1(node, comment) {
  9593. comment.leading = true;
  9594. comment.trailing = false;
  9595. addCommentHelper(node, comment);
  9596. }
  9597. function addDanglingComment$1(node, comment) {
  9598. comment.leading = false;
  9599. comment.trailing = false;
  9600. addCommentHelper(node, comment);
  9601. }
  9602. function addTrailingComment$1(node, comment) {
  9603. comment.leading = false;
  9604. comment.trailing = true;
  9605. addCommentHelper(node, comment);
  9606. }
  9607. function isWithinParentArrayProperty(path$$1, propertyName) {
  9608. var node = path$$1.getValue();
  9609. var parent = path$$1.getParentNode();
  9610. if (parent == null) {
  9611. return false;
  9612. }
  9613. if (!Array.isArray(parent[propertyName])) {
  9614. return false;
  9615. }
  9616. var key = path$$1.getName();
  9617. return parent[propertyName][key] === node;
  9618. }
  9619. function replaceEndOfLineWith(text, replacement) {
  9620. var parts = [];
  9621. var _iteratorNormalCompletion = true;
  9622. var _didIteratorError = false;
  9623. var _iteratorError = undefined;
  9624. try {
  9625. for (var _iterator = text.split("\n")[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  9626. var part = _step.value;
  9627. if (parts.length !== 0) {
  9628. parts.push(replacement);
  9629. }
  9630. parts.push(part);
  9631. }
  9632. } catch (err) {
  9633. _didIteratorError = true;
  9634. _iteratorError = err;
  9635. } finally {
  9636. try {
  9637. if (!_iteratorNormalCompletion && _iterator.return != null) {
  9638. _iterator.return();
  9639. }
  9640. } finally {
  9641. if (_didIteratorError) {
  9642. throw _iteratorError;
  9643. }
  9644. }
  9645. }
  9646. return parts;
  9647. }
  9648. var util$1 = {
  9649. replaceEndOfLineWith,
  9650. getStringWidth: getStringWidth$1,
  9651. getMaxContinuousCount,
  9652. getPrecedence,
  9653. shouldFlatten,
  9654. isBitwiseOperator,
  9655. isExportDeclaration,
  9656. getParentExportDeclaration,
  9657. getPenultimate,
  9658. getLast: getLast$3,
  9659. getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
  9660. getNextNonSpaceNonCommentCharacterIndex,
  9661. getNextNonSpaceNonCommentCharacter,
  9662. skip,
  9663. skipWhitespace,
  9664. skipSpaces,
  9665. skipToLineEnd,
  9666. skipEverythingButNewLine,
  9667. skipInlineComment,
  9668. skipTrailingComment,
  9669. skipNewline: skipNewline$1,
  9670. isNextLineEmptyAfterIndex,
  9671. isNextLineEmpty,
  9672. isPreviousLineEmpty: isPreviousLineEmpty$1,
  9673. hasNewline: hasNewline$1,
  9674. hasNewlineInRange,
  9675. hasSpaces,
  9676. setLocStart,
  9677. setLocEnd,
  9678. startsWithNoLookaheadToken,
  9679. getAlignmentSize,
  9680. getIndentSize,
  9681. getPreferredQuote,
  9682. printString,
  9683. printNumber,
  9684. hasIgnoreComment,
  9685. hasNodeIgnoreComment,
  9686. makeString,
  9687. matchAncestorTypes,
  9688. addLeadingComment: addLeadingComment$1,
  9689. addDanglingComment: addDanglingComment$1,
  9690. addTrailingComment: addTrailingComment$1,
  9691. isWithinParentArrayProperty
  9692. };
  9693. function guessEndOfLine$1(text) {
  9694. var index = text.indexOf("\r");
  9695. if (index >= 0) {
  9696. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  9697. }
  9698. return "lf";
  9699. }
  9700. function convertEndOfLineToChars$2(value) {
  9701. switch (value) {
  9702. case "cr":
  9703. return "\r";
  9704. case "crlf":
  9705. return "\r\n";
  9706. default:
  9707. return "\n";
  9708. }
  9709. }
  9710. var endOfLine = {
  9711. guessEndOfLine: guessEndOfLine$1,
  9712. convertEndOfLineToChars: convertEndOfLineToChars$2
  9713. };
  9714. var getStringWidth = util$1.getStringWidth;
  9715. var convertEndOfLineToChars$1 = endOfLine.convertEndOfLineToChars;
  9716. var concat$2 = docBuilders.concat;
  9717. var fill$1 = docBuilders.fill;
  9718. var cursor$2 = docBuilders.cursor;
  9719. /** @type {{[groupId: PropertyKey]: MODE}} */
  9720. var groupModeMap;
  9721. var MODE_BREAK = 1;
  9722. var MODE_FLAT = 2;
  9723. function rootIndent() {
  9724. return {
  9725. value: "",
  9726. length: 0,
  9727. queue: []
  9728. };
  9729. }
  9730. function makeIndent(ind, options) {
  9731. return generateInd(ind, {
  9732. type: "indent"
  9733. }, options);
  9734. }
  9735. function makeAlign(ind, n, options) {
  9736. return n === -Infinity ? ind.root || rootIndent() : n < 0 ? generateInd(ind, {
  9737. type: "dedent"
  9738. }, options) : !n ? ind : n.type === "root" ? Object.assign({}, ind, {
  9739. root: ind
  9740. }) : typeof n === "string" ? generateInd(ind, {
  9741. type: "stringAlign",
  9742. n
  9743. }, options) : generateInd(ind, {
  9744. type: "numberAlign",
  9745. n
  9746. }, options);
  9747. }
  9748. function generateInd(ind, newPart, options) {
  9749. var queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  9750. var value = "";
  9751. var length = 0;
  9752. var lastTabs = 0;
  9753. var lastSpaces = 0;
  9754. var _iteratorNormalCompletion = true;
  9755. var _didIteratorError = false;
  9756. var _iteratorError = undefined;
  9757. try {
  9758. for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  9759. var part = _step.value;
  9760. switch (part.type) {
  9761. case "indent":
  9762. flush();
  9763. if (options.useTabs) {
  9764. addTabs(1);
  9765. } else {
  9766. addSpaces(options.tabWidth);
  9767. }
  9768. break;
  9769. case "stringAlign":
  9770. flush();
  9771. value += part.n;
  9772. length += part.n.length;
  9773. break;
  9774. case "numberAlign":
  9775. lastTabs += 1;
  9776. lastSpaces += part.n;
  9777. break;
  9778. /* istanbul ignore next */
  9779. default:
  9780. throw new Error(`Unexpected type '${part.type}'`);
  9781. }
  9782. }
  9783. } catch (err) {
  9784. _didIteratorError = true;
  9785. _iteratorError = err;
  9786. } finally {
  9787. try {
  9788. if (!_iteratorNormalCompletion && _iterator.return != null) {
  9789. _iterator.return();
  9790. }
  9791. } finally {
  9792. if (_didIteratorError) {
  9793. throw _iteratorError;
  9794. }
  9795. }
  9796. }
  9797. flushSpaces();
  9798. return Object.assign({}, ind, {
  9799. value,
  9800. length,
  9801. queue
  9802. });
  9803. function addTabs(count) {
  9804. value += "\t".repeat(count);
  9805. length += options.tabWidth * count;
  9806. }
  9807. function addSpaces(count) {
  9808. value += " ".repeat(count);
  9809. length += count;
  9810. }
  9811. function flush() {
  9812. if (options.useTabs) {
  9813. flushTabs();
  9814. } else {
  9815. flushSpaces();
  9816. }
  9817. }
  9818. function flushTabs() {
  9819. if (lastTabs > 0) {
  9820. addTabs(lastTabs);
  9821. }
  9822. resetLast();
  9823. }
  9824. function flushSpaces() {
  9825. if (lastSpaces > 0) {
  9826. addSpaces(lastSpaces);
  9827. }
  9828. resetLast();
  9829. }
  9830. function resetLast() {
  9831. lastTabs = 0;
  9832. lastSpaces = 0;
  9833. }
  9834. }
  9835. function trim$1(out) {
  9836. if (out.length === 0) {
  9837. return 0;
  9838. }
  9839. var trimCount = 0; // Trim whitespace at the end of line
  9840. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[ \t]*$/)) {
  9841. trimCount += out.pop().length;
  9842. }
  9843. if (out.length && typeof out[out.length - 1] === "string") {
  9844. var trimmed = out[out.length - 1].replace(/[ \t]*$/, "");
  9845. trimCount += out[out.length - 1].length - trimmed.length;
  9846. out[out.length - 1] = trimmed;
  9847. }
  9848. return trimCount;
  9849. }
  9850. function fits(next, restCommands, width, options, mustBeFlat) {
  9851. var restIdx = restCommands.length;
  9852. var cmds = [next]; // `out` is only used for width counting because `trim` requires to look
  9853. // backwards for space characters.
  9854. var out = [];
  9855. while (width >= 0) {
  9856. if (cmds.length === 0) {
  9857. if (restIdx === 0) {
  9858. return true;
  9859. }
  9860. cmds.push(restCommands[restIdx - 1]);
  9861. restIdx--;
  9862. continue;
  9863. }
  9864. var x = cmds.pop();
  9865. var ind = x[0];
  9866. var mode = x[1];
  9867. var doc = x[2];
  9868. if (typeof doc === "string") {
  9869. out.push(doc);
  9870. width -= getStringWidth(doc);
  9871. } else {
  9872. switch (doc.type) {
  9873. case "concat":
  9874. for (var i = doc.parts.length - 1; i >= 0; i--) {
  9875. cmds.push([ind, mode, doc.parts[i]]);
  9876. }
  9877. break;
  9878. case "indent":
  9879. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  9880. break;
  9881. case "align":
  9882. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  9883. break;
  9884. case "trim":
  9885. width += trim$1(out);
  9886. break;
  9887. case "group":
  9888. if (mustBeFlat && doc.break) {
  9889. return false;
  9890. }
  9891. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  9892. if (doc.id) {
  9893. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  9894. }
  9895. break;
  9896. case "fill":
  9897. for (var _i = doc.parts.length - 1; _i >= 0; _i--) {
  9898. cmds.push([ind, mode, doc.parts[_i]]);
  9899. }
  9900. break;
  9901. case "if-break":
  9902. {
  9903. var groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  9904. if (groupMode === MODE_BREAK) {
  9905. if (doc.breakContents) {
  9906. cmds.push([ind, mode, doc.breakContents]);
  9907. }
  9908. }
  9909. if (groupMode === MODE_FLAT) {
  9910. if (doc.flatContents) {
  9911. cmds.push([ind, mode, doc.flatContents]);
  9912. }
  9913. }
  9914. break;
  9915. }
  9916. case "line":
  9917. switch (mode) {
  9918. // fallthrough
  9919. case MODE_FLAT:
  9920. if (!doc.hard) {
  9921. if (!doc.soft) {
  9922. out.push(" ");
  9923. width -= 1;
  9924. }
  9925. break;
  9926. }
  9927. return true;
  9928. case MODE_BREAK:
  9929. return true;
  9930. }
  9931. break;
  9932. }
  9933. }
  9934. }
  9935. return false;
  9936. }
  9937. function printDocToString$1(doc, options) {
  9938. groupModeMap = {};
  9939. var width = options.printWidth;
  9940. var newLine = convertEndOfLineToChars$1(options.endOfLine);
  9941. var pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  9942. // while loop which is much faster. The while loop below adds new
  9943. // cmds to the array instead of recursively calling `print`.
  9944. var cmds = [[rootIndent(), MODE_BREAK, doc]];
  9945. var out = [];
  9946. var shouldRemeasure = false;
  9947. var lineSuffix = [];
  9948. while (cmds.length !== 0) {
  9949. var x = cmds.pop();
  9950. var ind = x[0];
  9951. var mode = x[1];
  9952. var _doc = x[2];
  9953. if (typeof _doc === "string") {
  9954. out.push(_doc);
  9955. pos += getStringWidth(_doc);
  9956. } else {
  9957. switch (_doc.type) {
  9958. case "cursor":
  9959. out.push(cursor$2.placeholder);
  9960. break;
  9961. case "concat":
  9962. for (var i = _doc.parts.length - 1; i >= 0; i--) {
  9963. cmds.push([ind, mode, _doc.parts[i]]);
  9964. }
  9965. break;
  9966. case "indent":
  9967. cmds.push([makeIndent(ind, options), mode, _doc.contents]);
  9968. break;
  9969. case "align":
  9970. cmds.push([makeAlign(ind, _doc.n, options), mode, _doc.contents]);
  9971. break;
  9972. case "trim":
  9973. pos -= trim$1(out);
  9974. break;
  9975. case "group":
  9976. switch (mode) {
  9977. case MODE_FLAT:
  9978. if (!shouldRemeasure) {
  9979. cmds.push([ind, _doc.break ? MODE_BREAK : MODE_FLAT, _doc.contents]);
  9980. break;
  9981. }
  9982. // fallthrough
  9983. case MODE_BREAK:
  9984. {
  9985. shouldRemeasure = false;
  9986. var next = [ind, MODE_FLAT, _doc.contents];
  9987. var rem = width - pos;
  9988. if (!_doc.break && fits(next, cmds, rem, options)) {
  9989. cmds.push(next);
  9990. } else {
  9991. // Expanded states are a rare case where a document
  9992. // can manually provide multiple representations of
  9993. // itself. It provides an array of documents
  9994. // going from the least expanded (most flattened)
  9995. // representation first to the most expanded. If a
  9996. // group has these, we need to manually go through
  9997. // these states and find the first one that fits.
  9998. if (_doc.expandedStates) {
  9999. var mostExpanded = _doc.expandedStates[_doc.expandedStates.length - 1];
  10000. if (_doc.break) {
  10001. cmds.push([ind, MODE_BREAK, mostExpanded]);
  10002. break;
  10003. } else {
  10004. for (var _i2 = 1; _i2 < _doc.expandedStates.length + 1; _i2++) {
  10005. if (_i2 >= _doc.expandedStates.length) {
  10006. cmds.push([ind, MODE_BREAK, mostExpanded]);
  10007. break;
  10008. } else {
  10009. var state = _doc.expandedStates[_i2];
  10010. var cmd = [ind, MODE_FLAT, state];
  10011. if (fits(cmd, cmds, rem, options)) {
  10012. cmds.push(cmd);
  10013. break;
  10014. }
  10015. }
  10016. }
  10017. }
  10018. } else {
  10019. cmds.push([ind, MODE_BREAK, _doc.contents]);
  10020. }
  10021. }
  10022. break;
  10023. }
  10024. }
  10025. if (_doc.id) {
  10026. groupModeMap[_doc.id] = cmds[cmds.length - 1][1];
  10027. }
  10028. break;
  10029. // Fills each line with as much code as possible before moving to a new
  10030. // line with the same indentation.
  10031. //
  10032. // Expects doc.parts to be an array of alternating content and
  10033. // whitespace. The whitespace contains the linebreaks.
  10034. //
  10035. // For example:
  10036. // ["I", line, "love", line, "monkeys"]
  10037. // or
  10038. // [{ type: group, ... }, softline, { type: group, ... }]
  10039. //
  10040. // It uses this parts structure to handle three main layout cases:
  10041. // * The first two content items fit on the same line without
  10042. // breaking
  10043. // -> output the first content item and the whitespace "flat".
  10044. // * Only the first content item fits on the line without breaking
  10045. // -> output the first content item "flat" and the whitespace with
  10046. // "break".
  10047. // * Neither content item fits on the line without breaking
  10048. // -> output the first content item and the whitespace with "break".
  10049. case "fill":
  10050. {
  10051. var _rem = width - pos;
  10052. var parts = _doc.parts;
  10053. if (parts.length === 0) {
  10054. break;
  10055. }
  10056. var content = parts[0];
  10057. var contentFlatCmd = [ind, MODE_FLAT, content];
  10058. var contentBreakCmd = [ind, MODE_BREAK, content];
  10059. var contentFits = fits(contentFlatCmd, [], _rem, options, true);
  10060. if (parts.length === 1) {
  10061. if (contentFits) {
  10062. cmds.push(contentFlatCmd);
  10063. } else {
  10064. cmds.push(contentBreakCmd);
  10065. }
  10066. break;
  10067. }
  10068. var whitespace = parts[1];
  10069. var whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  10070. var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  10071. if (parts.length === 2) {
  10072. if (contentFits) {
  10073. cmds.push(whitespaceFlatCmd);
  10074. cmds.push(contentFlatCmd);
  10075. } else {
  10076. cmds.push(whitespaceBreakCmd);
  10077. cmds.push(contentBreakCmd);
  10078. }
  10079. break;
  10080. } // At this point we've handled the first pair (context, separator)
  10081. // and will create a new fill doc for the rest of the content.
  10082. // Ideally we wouldn't mutate the array here but coping all the
  10083. // elements to a new array would make this algorithm quadratic,
  10084. // which is unusable for large arrays (e.g. large texts in JSX).
  10085. parts.splice(0, 2);
  10086. var remainingCmd = [ind, mode, fill$1(parts)];
  10087. var secondContent = parts[0];
  10088. var firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$2([content, whitespace, secondContent])];
  10089. var firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], _rem, options, true);
  10090. if (firstAndSecondContentFits) {
  10091. cmds.push(remainingCmd);
  10092. cmds.push(whitespaceFlatCmd);
  10093. cmds.push(contentFlatCmd);
  10094. } else if (contentFits) {
  10095. cmds.push(remainingCmd);
  10096. cmds.push(whitespaceBreakCmd);
  10097. cmds.push(contentFlatCmd);
  10098. } else {
  10099. cmds.push(remainingCmd);
  10100. cmds.push(whitespaceBreakCmd);
  10101. cmds.push(contentBreakCmd);
  10102. }
  10103. break;
  10104. }
  10105. case "if-break":
  10106. {
  10107. var groupMode = _doc.groupId ? groupModeMap[_doc.groupId] : mode;
  10108. if (groupMode === MODE_BREAK) {
  10109. if (_doc.breakContents) {
  10110. cmds.push([ind, mode, _doc.breakContents]);
  10111. }
  10112. }
  10113. if (groupMode === MODE_FLAT) {
  10114. if (_doc.flatContents) {
  10115. cmds.push([ind, mode, _doc.flatContents]);
  10116. }
  10117. }
  10118. break;
  10119. }
  10120. case "line-suffix":
  10121. lineSuffix.push([ind, mode, _doc.contents]);
  10122. break;
  10123. case "line-suffix-boundary":
  10124. if (lineSuffix.length > 0) {
  10125. cmds.push([ind, mode, {
  10126. type: "line",
  10127. hard: true
  10128. }]);
  10129. }
  10130. break;
  10131. case "line":
  10132. switch (mode) {
  10133. case MODE_FLAT:
  10134. if (!_doc.hard) {
  10135. if (!_doc.soft) {
  10136. out.push(" ");
  10137. pos += 1;
  10138. }
  10139. break;
  10140. } else {
  10141. // This line was forced into the output even if we
  10142. // were in flattened mode, so we need to tell the next
  10143. // group that no matter what, it needs to remeasure
  10144. // because the previous measurement didn't accurately
  10145. // capture the entire expression (this is necessary
  10146. // for nested groups)
  10147. shouldRemeasure = true;
  10148. }
  10149. // fallthrough
  10150. case MODE_BREAK:
  10151. if (lineSuffix.length) {
  10152. cmds.push([ind, mode, _doc]);
  10153. [].push.apply(cmds, lineSuffix.reverse());
  10154. lineSuffix = [];
  10155. break;
  10156. }
  10157. if (_doc.literal) {
  10158. if (ind.root) {
  10159. out.push(newLine, ind.root.value);
  10160. pos = ind.root.length;
  10161. } else {
  10162. out.push(newLine);
  10163. pos = 0;
  10164. }
  10165. } else {
  10166. pos -= trim$1(out);
  10167. out.push(newLine + ind.value);
  10168. pos = ind.length;
  10169. }
  10170. break;
  10171. }
  10172. break;
  10173. default:
  10174. }
  10175. }
  10176. }
  10177. var cursorPlaceholderIndex = out.indexOf(cursor$2.placeholder);
  10178. if (cursorPlaceholderIndex !== -1) {
  10179. var otherCursorPlaceholderIndex = out.indexOf(cursor$2.placeholder, cursorPlaceholderIndex + 1);
  10180. var beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  10181. var aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  10182. var afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  10183. return {
  10184. formatted: beforeCursor + aroundCursor + afterCursor,
  10185. cursorNodeStart: beforeCursor.length,
  10186. cursorNodeText: aroundCursor
  10187. };
  10188. }
  10189. return {
  10190. formatted: out.join("")
  10191. };
  10192. }
  10193. var docPrinter = {
  10194. printDocToString: printDocToString$1
  10195. };
  10196. var traverseDocOnExitStackMarker = {};
  10197. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  10198. var docsStack = [doc];
  10199. while (docsStack.length !== 0) {
  10200. var _doc = docsStack.pop();
  10201. if (_doc === traverseDocOnExitStackMarker) {
  10202. onExit(docsStack.pop());
  10203. continue;
  10204. }
  10205. var shouldRecurse = true;
  10206. if (onEnter) {
  10207. if (onEnter(_doc) === false) {
  10208. shouldRecurse = false;
  10209. }
  10210. }
  10211. if (onExit) {
  10212. docsStack.push(_doc);
  10213. docsStack.push(traverseDocOnExitStackMarker);
  10214. }
  10215. if (shouldRecurse) {
  10216. // When there are multiple parts to process,
  10217. // the parts need to be pushed onto the stack in reverse order,
  10218. // so that they are processed in the original order
  10219. // when the stack is popped.
  10220. if (_doc.type === "concat" || _doc.type === "fill") {
  10221. for (var ic = _doc.parts.length, i = ic - 1; i >= 0; --i) {
  10222. docsStack.push(_doc.parts[i]);
  10223. }
  10224. } else if (_doc.type === "if-break") {
  10225. if (_doc.flatContents) {
  10226. docsStack.push(_doc.flatContents);
  10227. }
  10228. if (_doc.breakContents) {
  10229. docsStack.push(_doc.breakContents);
  10230. }
  10231. } else if (_doc.type === "group" && _doc.expandedStates) {
  10232. if (shouldTraverseConditionalGroups) {
  10233. for (var _ic = _doc.expandedStates.length, _i = _ic - 1; _i >= 0; --_i) {
  10234. docsStack.push(_doc.expandedStates[_i]);
  10235. }
  10236. } else {
  10237. docsStack.push(_doc.contents);
  10238. }
  10239. } else if (_doc.contents) {
  10240. docsStack.push(_doc.contents);
  10241. }
  10242. }
  10243. }
  10244. }
  10245. function mapDoc$1(doc, cb) {
  10246. if (doc.type === "concat" || doc.type === "fill") {
  10247. var parts = doc.parts.map(function (part) {
  10248. return mapDoc$1(part, cb);
  10249. });
  10250. return cb(Object.assign({}, doc, {
  10251. parts
  10252. }));
  10253. } else if (doc.type === "if-break") {
  10254. var breakContents = doc.breakContents && mapDoc$1(doc.breakContents, cb);
  10255. var flatContents = doc.flatContents && mapDoc$1(doc.flatContents, cb);
  10256. return cb(Object.assign({}, doc, {
  10257. breakContents,
  10258. flatContents
  10259. }));
  10260. } else if (doc.contents) {
  10261. var contents = mapDoc$1(doc.contents, cb);
  10262. return cb(Object.assign({}, doc, {
  10263. contents
  10264. }));
  10265. }
  10266. return cb(doc);
  10267. }
  10268. function findInDoc(doc, fn, defaultValue) {
  10269. var result = defaultValue;
  10270. var hasStopped = false;
  10271. function findInDocOnEnterFn(doc) {
  10272. var maybeResult = fn(doc);
  10273. if (maybeResult !== undefined) {
  10274. hasStopped = true;
  10275. result = maybeResult;
  10276. }
  10277. if (hasStopped) {
  10278. return false;
  10279. }
  10280. }
  10281. traverseDoc(doc, findInDocOnEnterFn);
  10282. return result;
  10283. }
  10284. function isEmpty(n) {
  10285. return typeof n === "string" && n.length === 0;
  10286. }
  10287. function isLineNextFn(doc) {
  10288. if (typeof doc === "string") {
  10289. return false;
  10290. }
  10291. if (doc.type === "line") {
  10292. return true;
  10293. }
  10294. }
  10295. function isLineNext(doc) {
  10296. return findInDoc(doc, isLineNextFn, false);
  10297. }
  10298. function willBreakFn(doc) {
  10299. if (doc.type === "group" && doc.break) {
  10300. return true;
  10301. }
  10302. if (doc.type === "line" && doc.hard) {
  10303. return true;
  10304. }
  10305. if (doc.type === "break-parent") {
  10306. return true;
  10307. }
  10308. }
  10309. function willBreak(doc) {
  10310. return findInDoc(doc, willBreakFn, false);
  10311. }
  10312. function breakParentGroup(groupStack) {
  10313. if (groupStack.length > 0) {
  10314. var parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  10315. // the user is expected to manually handle what breaks.
  10316. if (!parentGroup.expandedStates) {
  10317. parentGroup.break = true;
  10318. }
  10319. }
  10320. return null;
  10321. }
  10322. function propagateBreaks(doc) {
  10323. var alreadyVisitedSet = new Set();
  10324. var groupStack = [];
  10325. function propagateBreaksOnEnterFn(doc) {
  10326. if (doc.type === "break-parent") {
  10327. breakParentGroup(groupStack);
  10328. }
  10329. if (doc.type === "group") {
  10330. groupStack.push(doc);
  10331. if (alreadyVisitedSet.has(doc)) {
  10332. return false;
  10333. }
  10334. alreadyVisitedSet.add(doc);
  10335. }
  10336. }
  10337. function propagateBreaksOnExitFn(doc) {
  10338. if (doc.type === "group") {
  10339. var group = groupStack.pop();
  10340. if (group.break) {
  10341. breakParentGroup(groupStack);
  10342. }
  10343. }
  10344. }
  10345. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
  10346. /* shouldTraverseConditionalGroups */
  10347. true);
  10348. }
  10349. function removeLinesFn(doc) {
  10350. // Force this doc into flat mode by statically converting all
  10351. // lines into spaces (or soft lines into nothing). Hard lines
  10352. // should still output because there's too great of a chance
  10353. // of breaking existing assumptions otherwise.
  10354. if (doc.type === "line" && !doc.hard) {
  10355. return doc.soft ? "" : " ";
  10356. } else if (doc.type === "if-break") {
  10357. return doc.flatContents || "";
  10358. }
  10359. return doc;
  10360. }
  10361. function removeLines(doc) {
  10362. return mapDoc$1(doc, removeLinesFn);
  10363. }
  10364. function stripTrailingHardline(doc) {
  10365. // HACK remove ending hardline, original PR: #1984
  10366. if (doc.type === "concat" && doc.parts.length !== 0) {
  10367. var lastPart = doc.parts[doc.parts.length - 1];
  10368. if (lastPart.type === "concat") {
  10369. if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
  10370. return {
  10371. type: "concat",
  10372. parts: doc.parts.slice(0, -1)
  10373. };
  10374. }
  10375. return {
  10376. type: "concat",
  10377. parts: doc.parts.slice(0, -1).concat(stripTrailingHardline(lastPart))
  10378. };
  10379. }
  10380. }
  10381. return doc;
  10382. }
  10383. var docUtils = {
  10384. isEmpty,
  10385. willBreak,
  10386. isLineNext,
  10387. traverseDoc,
  10388. mapDoc: mapDoc$1,
  10389. propagateBreaks,
  10390. removeLines,
  10391. stripTrailingHardline
  10392. };
  10393. function flattenDoc(doc) {
  10394. if (doc.type === "concat") {
  10395. var res = [];
  10396. for (var i = 0; i < doc.parts.length; ++i) {
  10397. var doc2 = doc.parts[i];
  10398. if (typeof doc2 !== "string" && doc2.type === "concat") {
  10399. [].push.apply(res, flattenDoc(doc2).parts);
  10400. } else {
  10401. var flattened = flattenDoc(doc2);
  10402. if (flattened !== "") {
  10403. res.push(flattened);
  10404. }
  10405. }
  10406. }
  10407. return Object.assign({}, doc, {
  10408. parts: res
  10409. });
  10410. } else if (doc.type === "if-break") {
  10411. return Object.assign({}, doc, {
  10412. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  10413. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  10414. });
  10415. } else if (doc.type === "group") {
  10416. return Object.assign({}, doc, {
  10417. contents: flattenDoc(doc.contents),
  10418. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  10419. });
  10420. } else if (doc.contents) {
  10421. return Object.assign({}, doc, {
  10422. contents: flattenDoc(doc.contents)
  10423. });
  10424. }
  10425. return doc;
  10426. }
  10427. function printDoc(doc) {
  10428. if (typeof doc === "string") {
  10429. return JSON.stringify(doc);
  10430. }
  10431. if (doc.type === "line") {
  10432. if (doc.literal) {
  10433. return "literalline";
  10434. }
  10435. if (doc.hard) {
  10436. return "hardline";
  10437. }
  10438. if (doc.soft) {
  10439. return "softline";
  10440. }
  10441. return "line";
  10442. }
  10443. if (doc.type === "break-parent") {
  10444. return "breakParent";
  10445. }
  10446. if (doc.type === "trim") {
  10447. return "trim";
  10448. }
  10449. if (doc.type === "concat") {
  10450. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  10451. }
  10452. if (doc.type === "indent") {
  10453. return "indent(" + printDoc(doc.contents) + ")";
  10454. }
  10455. if (doc.type === "align") {
  10456. 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) + ")";
  10457. }
  10458. if (doc.type === "if-break") {
  10459. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  10460. }
  10461. if (doc.type === "group") {
  10462. if (doc.expandedStates) {
  10463. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  10464. }
  10465. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  10466. }
  10467. if (doc.type === "fill") {
  10468. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  10469. }
  10470. if (doc.type === "line-suffix") {
  10471. return "lineSuffix(" + printDoc(doc.contents) + ")";
  10472. }
  10473. if (doc.type === "line-suffix-boundary") {
  10474. return "lineSuffixBoundary";
  10475. }
  10476. throw new Error("Unknown doc type " + doc.type);
  10477. }
  10478. var docDebug = {
  10479. printDocToDebug: function printDocToDebug(doc) {
  10480. return printDoc(flattenDoc(doc));
  10481. }
  10482. };
  10483. var doc = {
  10484. builders: docBuilders,
  10485. printer: docPrinter,
  10486. utils: docUtils,
  10487. debug: docDebug
  10488. };
  10489. var mapDoc$2 = doc.utils.mapDoc;
  10490. function isNextLineEmpty$1(text, node, options) {
  10491. return util$1.isNextLineEmpty(text, node, options.locEnd);
  10492. }
  10493. function isPreviousLineEmpty$2(text, node, options) {
  10494. return util$1.isPreviousLineEmpty(text, node, options.locStart);
  10495. }
  10496. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  10497. return util$1.getNextNonSpaceNonCommentCharacterIndex(text, node, options.locEnd);
  10498. }
  10499. var utilShared = {
  10500. getMaxContinuousCount: util$1.getMaxContinuousCount,
  10501. getStringWidth: util$1.getStringWidth,
  10502. getAlignmentSize: util$1.getAlignmentSize,
  10503. getIndentSize: util$1.getIndentSize,
  10504. skip: util$1.skip,
  10505. skipWhitespace: util$1.skipWhitespace,
  10506. skipSpaces: util$1.skipSpaces,
  10507. skipNewline: util$1.skipNewline,
  10508. skipToLineEnd: util$1.skipToLineEnd,
  10509. skipEverythingButNewLine: util$1.skipEverythingButNewLine,
  10510. skipInlineComment: util$1.skipInlineComment,
  10511. skipTrailingComment: util$1.skipTrailingComment,
  10512. hasNewline: util$1.hasNewline,
  10513. hasNewlineInRange: util$1.hasNewlineInRange,
  10514. hasSpaces: util$1.hasSpaces,
  10515. isNextLineEmpty: isNextLineEmpty$1,
  10516. isNextLineEmptyAfterIndex: util$1.isNextLineEmptyAfterIndex,
  10517. isPreviousLineEmpty: isPreviousLineEmpty$2,
  10518. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  10519. mapDoc: mapDoc$2,
  10520. // TODO: remove in 2.0, we already exposed it in docUtils
  10521. makeString: util$1.makeString,
  10522. addLeadingComment: util$1.addLeadingComment,
  10523. addDanglingComment: util$1.addDanglingComment,
  10524. addTrailingComment: util$1.addTrailingComment
  10525. };
  10526. var _require$$0$builders = doc.builders;
  10527. var concat = _require$$0$builders.concat;
  10528. var hardline = _require$$0$builders.hardline;
  10529. var breakParent = _require$$0$builders.breakParent;
  10530. var indent = _require$$0$builders.indent;
  10531. var lineSuffix = _require$$0$builders.lineSuffix;
  10532. var join = _require$$0$builders.join;
  10533. var cursor = _require$$0$builders.cursor;
  10534. var hasNewline = util$1.hasNewline;
  10535. var skipNewline = util$1.skipNewline;
  10536. var isPreviousLineEmpty = util$1.isPreviousLineEmpty;
  10537. var addLeadingComment = utilShared.addLeadingComment;
  10538. var addDanglingComment = utilShared.addDanglingComment;
  10539. var addTrailingComment = utilShared.addTrailingComment;
  10540. var childNodesCacheKey = Symbol("child-nodes");
  10541. function getSortedChildNodes(node, options, resultArray) {
  10542. if (!node) {
  10543. return;
  10544. }
  10545. var printer = options.printer,
  10546. locStart = options.locStart,
  10547. locEnd = options.locEnd;
  10548. if (resultArray) {
  10549. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  10550. // This reverse insertion sort almost always takes constant
  10551. // time because we almost always (maybe always?) append the
  10552. // nodes in order anyway.
  10553. var i;
  10554. for (i = resultArray.length - 1; i >= 0; --i) {
  10555. if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
  10556. break;
  10557. }
  10558. }
  10559. resultArray.splice(i + 1, 0, node);
  10560. return;
  10561. }
  10562. } else if (node[childNodesCacheKey]) {
  10563. return node[childNodesCacheKey];
  10564. }
  10565. var childNodes;
  10566. if (printer.getCommentChildNodes) {
  10567. childNodes = printer.getCommentChildNodes(node);
  10568. } else if (node && typeof node === "object") {
  10569. childNodes = Object.keys(node).filter(function (n) {
  10570. return n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode";
  10571. }).map(function (n) {
  10572. return node[n];
  10573. });
  10574. }
  10575. if (!childNodes) {
  10576. return;
  10577. }
  10578. if (!resultArray) {
  10579. Object.defineProperty(node, childNodesCacheKey, {
  10580. value: resultArray = [],
  10581. enumerable: false
  10582. });
  10583. }
  10584. childNodes.forEach(function (childNode) {
  10585. getSortedChildNodes(childNode, options, resultArray);
  10586. });
  10587. return resultArray;
  10588. } // As efficiently as possible, decorate the comment object with
  10589. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  10590. // least one of which is guaranteed to be defined.
  10591. function decorateComment(node, comment, options) {
  10592. var locStart = options.locStart,
  10593. locEnd = options.locEnd;
  10594. var childNodes = getSortedChildNodes(node, options);
  10595. var precedingNode;
  10596. var followingNode; // Time to dust off the old binary search robes and wizard hat.
  10597. var left = 0;
  10598. var right = childNodes.length;
  10599. while (left < right) {
  10600. var middle = left + right >> 1;
  10601. var child = childNodes[middle];
  10602. if (locStart(child) - locStart(comment) <= 0 && locEnd(comment) - locEnd(child) <= 0) {
  10603. // The comment is completely contained by this child node.
  10604. comment.enclosingNode = child;
  10605. decorateComment(child, comment, options);
  10606. return; // Abandon the binary search at this level.
  10607. }
  10608. if (locEnd(child) - locStart(comment) <= 0) {
  10609. // This child node falls completely before the comment.
  10610. // Because we will never consider this node or any nodes
  10611. // before it again, this node must be the closest preceding
  10612. // node we have encountered so far.
  10613. precedingNode = child;
  10614. left = middle + 1;
  10615. continue;
  10616. }
  10617. if (locEnd(comment) - locStart(child) <= 0) {
  10618. // This child node falls completely after the comment.
  10619. // Because we will never consider this node or any nodes after
  10620. // it again, this node must be the closest following node we
  10621. // have encountered so far.
  10622. followingNode = child;
  10623. right = middle;
  10624. continue;
  10625. }
  10626. /* istanbul ignore next */
  10627. throw new Error("Comment location overlaps with node location");
  10628. } // We don't want comments inside of different expressions inside of the same
  10629. // template literal to move to another expression.
  10630. if (comment.enclosingNode && comment.enclosingNode.type === "TemplateLiteral") {
  10631. var quasis = comment.enclosingNode.quasis;
  10632. var commentIndex = findExpressionIndexForComment(quasis, comment, options);
  10633. if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
  10634. precedingNode = null;
  10635. }
  10636. if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
  10637. followingNode = null;
  10638. }
  10639. }
  10640. if (precedingNode) {
  10641. comment.precedingNode = precedingNode;
  10642. }
  10643. if (followingNode) {
  10644. comment.followingNode = followingNode;
  10645. }
  10646. }
  10647. function attach(comments, ast, text, options) {
  10648. if (!Array.isArray(comments)) {
  10649. return;
  10650. }
  10651. var tiesToBreak = [];
  10652. var locStart = options.locStart,
  10653. locEnd = options.locEnd;
  10654. comments.forEach(function (comment, i) {
  10655. if (options.parser === "json" || options.parser === "json5" || options.parser === "__js_expression" || options.parser === "__vue_expression") {
  10656. if (locStart(comment) - locStart(ast) <= 0) {
  10657. addLeadingComment(ast, comment);
  10658. return;
  10659. }
  10660. if (locEnd(comment) - locEnd(ast) >= 0) {
  10661. addTrailingComment(ast, comment);
  10662. return;
  10663. }
  10664. }
  10665. decorateComment(ast, comment, options);
  10666. var precedingNode = comment.precedingNode,
  10667. enclosingNode = comment.enclosingNode,
  10668. followingNode = comment.followingNode;
  10669. var pluginHandleOwnLineComment = options.printer.handleComments && options.printer.handleComments.ownLine ? options.printer.handleComments.ownLine : function () {
  10670. return false;
  10671. };
  10672. var pluginHandleEndOfLineComment = options.printer.handleComments && options.printer.handleComments.endOfLine ? options.printer.handleComments.endOfLine : function () {
  10673. return false;
  10674. };
  10675. var pluginHandleRemainingComment = options.printer.handleComments && options.printer.handleComments.remaining ? options.printer.handleComments.remaining : function () {
  10676. return false;
  10677. };
  10678. var isLastComment = comments.length - 1 === i;
  10679. if (hasNewline(text, locStart(comment), {
  10680. backwards: true
  10681. })) {
  10682. // If a comment exists on its own line, prefer a leading comment.
  10683. // We also need to check if it's the first line of the file.
  10684. if (pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)) {// We're good
  10685. } else if (followingNode) {
  10686. // Always a leading comment.
  10687. addLeadingComment(followingNode, comment);
  10688. } else if (precedingNode) {
  10689. addTrailingComment(precedingNode, comment);
  10690. } else if (enclosingNode) {
  10691. addDanglingComment(enclosingNode, comment);
  10692. } else {
  10693. // There are no nodes, let's attach it to the root of the ast
  10694. /* istanbul ignore next */
  10695. addDanglingComment(ast, comment);
  10696. }
  10697. } else if (hasNewline(text, locEnd(comment))) {
  10698. if (pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)) {// We're good
  10699. } else if (precedingNode) {
  10700. // There is content before this comment on the same line, but
  10701. // none after it, so prefer a trailing comment of the previous node.
  10702. addTrailingComment(precedingNode, comment);
  10703. } else if (followingNode) {
  10704. addLeadingComment(followingNode, comment);
  10705. } else if (enclosingNode) {
  10706. addDanglingComment(enclosingNode, comment);
  10707. } else {
  10708. // There are no nodes, let's attach it to the root of the ast
  10709. /* istanbul ignore next */
  10710. addDanglingComment(ast, comment);
  10711. }
  10712. } else {
  10713. if (pluginHandleRemainingComment(comment, text, options, ast, isLastComment)) {// We're good
  10714. } else if (precedingNode && followingNode) {
  10715. // Otherwise, text exists both before and after the comment on
  10716. // the same line. If there is both a preceding and following
  10717. // node, use a tie-breaking algorithm to determine if it should
  10718. // be attached to the next or previous node. In the last case,
  10719. // simply attach the right node;
  10720. var tieCount = tiesToBreak.length;
  10721. if (tieCount > 0) {
  10722. var lastTie = tiesToBreak[tieCount - 1];
  10723. if (lastTie.followingNode !== comment.followingNode) {
  10724. breakTies(tiesToBreak, text, options);
  10725. }
  10726. }
  10727. tiesToBreak.push(comment);
  10728. } else if (precedingNode) {
  10729. addTrailingComment(precedingNode, comment);
  10730. } else if (followingNode) {
  10731. addLeadingComment(followingNode, comment);
  10732. } else if (enclosingNode) {
  10733. addDanglingComment(enclosingNode, comment);
  10734. } else {
  10735. // There are no nodes, let's attach it to the root of the ast
  10736. /* istanbul ignore next */
  10737. addDanglingComment(ast, comment);
  10738. }
  10739. }
  10740. });
  10741. breakTies(tiesToBreak, text, options);
  10742. comments.forEach(function (comment) {
  10743. // These node references were useful for breaking ties, but we
  10744. // don't need them anymore, and they create cycles in the AST that
  10745. // may lead to infinite recursion if we don't delete them here.
  10746. delete comment.precedingNode;
  10747. delete comment.enclosingNode;
  10748. delete comment.followingNode;
  10749. });
  10750. }
  10751. function breakTies(tiesToBreak, text, options) {
  10752. var tieCount = tiesToBreak.length;
  10753. if (tieCount === 0) {
  10754. return;
  10755. }
  10756. var _tiesToBreak$ = tiesToBreak[0],
  10757. precedingNode = _tiesToBreak$.precedingNode,
  10758. followingNode = _tiesToBreak$.followingNode;
  10759. var gapEndPos = options.locStart(followingNode); // Iterate backwards through tiesToBreak, examining the gaps
  10760. // between the tied comments. In order to qualify as leading, a
  10761. // comment must be separated from followingNode by an unbroken series of
  10762. // gaps (or other comments). Gaps should only contain whitespace or open
  10763. // parentheses.
  10764. var indexOfFirstLeadingComment;
  10765. for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
  10766. var comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  10767. assert.strictEqual(comment.precedingNode, precedingNode);
  10768. assert.strictEqual(comment.followingNode, followingNode);
  10769. var gap = text.slice(options.locEnd(comment), gapEndPos).trim();
  10770. if (gap === "" || /^\(+$/.test(gap)) {
  10771. gapEndPos = options.locStart(comment);
  10772. } else {
  10773. // The gap string contained something other than whitespace or open
  10774. // parentheses.
  10775. break;
  10776. }
  10777. }
  10778. tiesToBreak.forEach(function (comment, i) {
  10779. if (i < indexOfFirstLeadingComment) {
  10780. addTrailingComment(precedingNode, comment);
  10781. } else {
  10782. addLeadingComment(followingNode, comment);
  10783. }
  10784. });
  10785. tiesToBreak.length = 0;
  10786. }
  10787. function printComment(commentPath, options) {
  10788. var comment = commentPath.getValue();
  10789. comment.printed = true;
  10790. return options.printer.printComment(commentPath, options);
  10791. }
  10792. function findExpressionIndexForComment(quasis, comment, options) {
  10793. var startPos = options.locStart(comment) - 1;
  10794. for (var i = 1; i < quasis.length; ++i) {
  10795. if (startPos < getQuasiRange(quasis[i]).start) {
  10796. return i - 1;
  10797. }
  10798. } // We haven't found it, it probably means that some of the locations are off.
  10799. // Let's just return the first one.
  10800. /* istanbul ignore next */
  10801. return 0;
  10802. }
  10803. function getQuasiRange(expr) {
  10804. if (expr.start !== undefined) {
  10805. // Babel
  10806. return {
  10807. start: expr.start,
  10808. end: expr.end
  10809. };
  10810. } // Flow
  10811. return {
  10812. start: expr.range[0],
  10813. end: expr.range[1]
  10814. };
  10815. }
  10816. function printLeadingComment(commentPath, print, options) {
  10817. var comment = commentPath.getValue();
  10818. var contents = printComment(commentPath, options);
  10819. if (!contents) {
  10820. return "";
  10821. }
  10822. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // Leading block comments should see if they need to stay on the
  10823. // same line or not.
  10824. if (isBlock) {
  10825. return concat([contents, hasNewline(options.originalText, options.locEnd(comment)) ? hardline : " "]);
  10826. }
  10827. return concat([contents, hardline]);
  10828. }
  10829. function printTrailingComment(commentPath, print, options) {
  10830. var comment = commentPath.getValue();
  10831. var contents = printComment(commentPath, options);
  10832. if (!contents) {
  10833. return "";
  10834. }
  10835. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // We don't want the line to break
  10836. // when the parentParentNode is a ClassDeclaration/-Expression
  10837. // And the parentNode is in the superClass property
  10838. var parentNode = commentPath.getNode(1);
  10839. var parentParentNode = commentPath.getNode(2);
  10840. var isParentSuperClass = parentParentNode && (parentParentNode.type === "ClassDeclaration" || parentParentNode.type === "ClassExpression") && parentParentNode.superClass === parentNode;
  10841. if (hasNewline(options.originalText, options.locStart(comment), {
  10842. backwards: true
  10843. })) {
  10844. // This allows comments at the end of nested structures:
  10845. // {
  10846. // x: 1,
  10847. // y: 2
  10848. // // A comment
  10849. // }
  10850. // Those kinds of comments are almost always leading comments, but
  10851. // here it doesn't go "outside" the block and turns it into a
  10852. // trailing comment for `2`. We can simulate the above by checking
  10853. // if this a comment on its own line; normal trailing comments are
  10854. // always at the end of another expression.
  10855. var isLineBeforeEmpty = isPreviousLineEmpty(options.originalText, comment, options.locStart);
  10856. return lineSuffix(concat([hardline, isLineBeforeEmpty ? hardline : "", contents]));
  10857. } else if (isBlock || isParentSuperClass) {
  10858. // Trailing block comments never need a newline
  10859. return concat([" ", contents]);
  10860. }
  10861. return concat([lineSuffix(" " + contents), !isBlock ? breakParent : ""]);
  10862. }
  10863. function printDanglingComments(path$$1, options, sameIndent, filter) {
  10864. var parts = [];
  10865. var node = path$$1.getValue();
  10866. if (!node || !node.comments) {
  10867. return "";
  10868. }
  10869. path$$1.each(function (commentPath) {
  10870. var comment = commentPath.getValue();
  10871. if (comment && !comment.leading && !comment.trailing && (!filter || filter(comment))) {
  10872. parts.push(printComment(commentPath, options));
  10873. }
  10874. }, "comments");
  10875. if (parts.length === 0) {
  10876. return "";
  10877. }
  10878. if (sameIndent) {
  10879. return join(hardline, parts);
  10880. }
  10881. return indent(concat([hardline, join(hardline, parts)]));
  10882. }
  10883. function prependCursorPlaceholder(path$$1, options, printed) {
  10884. if (path$$1.getNode() === options.cursorNode && path$$1.getValue()) {
  10885. return concat([cursor, printed, cursor]);
  10886. }
  10887. return printed;
  10888. }
  10889. function printComments(path$$1, print, options, needsSemi) {
  10890. var value = path$$1.getValue();
  10891. var printed = print(path$$1);
  10892. var comments = value && value.comments;
  10893. if (!comments || comments.length === 0) {
  10894. return prependCursorPlaceholder(path$$1, options, printed);
  10895. }
  10896. var leadingParts = [];
  10897. var trailingParts = [needsSemi ? ";" : "", printed];
  10898. path$$1.each(function (commentPath) {
  10899. var comment = commentPath.getValue();
  10900. var leading = comment.leading,
  10901. trailing = comment.trailing;
  10902. if (leading) {
  10903. var contents = printLeadingComment(commentPath, print, options);
  10904. if (!contents) {
  10905. return;
  10906. }
  10907. leadingParts.push(contents);
  10908. var text = options.originalText;
  10909. if (hasNewline(text, skipNewline(text, options.locEnd(comment)))) {
  10910. leadingParts.push(hardline);
  10911. }
  10912. } else if (trailing) {
  10913. trailingParts.push(printTrailingComment(commentPath, print, options));
  10914. }
  10915. }, "comments");
  10916. return prependCursorPlaceholder(path$$1, options, concat(leadingParts.concat(trailingParts)));
  10917. }
  10918. var comments = {
  10919. attach,
  10920. printComments,
  10921. printDanglingComments,
  10922. getSortedChildNodes
  10923. };
  10924. function FastPath(value) {
  10925. assert.ok(this instanceof FastPath);
  10926. this.stack = [value];
  10927. } // The name of the current property is always the penultimate element of
  10928. // this.stack, and always a String.
  10929. FastPath.prototype.getName = function getName() {
  10930. var s = this.stack;
  10931. var len = s.length;
  10932. if (len > 1) {
  10933. return s[len - 2];
  10934. } // Since the name is always a string, null is a safe sentinel value to
  10935. // return if we do not know the name of the (root) value.
  10936. /* istanbul ignore next */
  10937. return null;
  10938. }; // The value of the current property is always the final element of
  10939. // this.stack.
  10940. FastPath.prototype.getValue = function getValue() {
  10941. var s = this.stack;
  10942. return s[s.length - 1];
  10943. };
  10944. function getNodeHelper(path$$1, count) {
  10945. var stackIndex = getNodeStackIndexHelper(path$$1.stack, count);
  10946. return stackIndex === -1 ? null : path$$1.stack[stackIndex];
  10947. }
  10948. function getNodeStackIndexHelper(stack, count) {
  10949. for (var i = stack.length - 1; i >= 0; i -= 2) {
  10950. var value = stack[i];
  10951. if (value && !Array.isArray(value) && --count < 0) {
  10952. return i;
  10953. }
  10954. }
  10955. return -1;
  10956. }
  10957. FastPath.prototype.getNode = function getNode(count) {
  10958. return getNodeHelper(this, ~~count);
  10959. };
  10960. FastPath.prototype.getParentNode = function getParentNode(count) {
  10961. return getNodeHelper(this, ~~count + 1);
  10962. }; // Temporarily push properties named by string arguments given after the
  10963. // callback function onto this.stack, then call the callback with a
  10964. // reference to this (modified) FastPath object. Note that the stack will
  10965. // be restored to its original state after the callback is finished, so it
  10966. // is probably a mistake to retain a reference to the path.
  10967. FastPath.prototype.call = function call(callback
  10968. /*, name1, name2, ... */
  10969. ) {
  10970. var s = this.stack;
  10971. var origLen = s.length;
  10972. var value = s[origLen - 1];
  10973. var argc = arguments.length;
  10974. for (var i = 1; i < argc; ++i) {
  10975. var name = arguments[i];
  10976. value = value[name];
  10977. s.push(name, value);
  10978. }
  10979. var result = callback(this);
  10980. s.length = origLen;
  10981. return result;
  10982. };
  10983. FastPath.prototype.callParent = function callParent(callback, count) {
  10984. var stackIndex = getNodeStackIndexHelper(this.stack, ~~count + 1);
  10985. var parentValues = this.stack.splice(stackIndex + 1);
  10986. var result = callback(this);
  10987. Array.prototype.push.apply(this.stack, parentValues);
  10988. return result;
  10989. }; // Similar to FastPath.prototype.call, except that the value obtained by
  10990. // accessing this.getValue()[name1][name2]... should be array-like. The
  10991. // callback will be called with a reference to this path object for each
  10992. // element of the array.
  10993. FastPath.prototype.each = function each(callback
  10994. /*, name1, name2, ... */
  10995. ) {
  10996. var s = this.stack;
  10997. var origLen = s.length;
  10998. var value = s[origLen - 1];
  10999. var argc = arguments.length;
  11000. for (var i = 1; i < argc; ++i) {
  11001. var name = arguments[i];
  11002. value = value[name];
  11003. s.push(name, value);
  11004. }
  11005. for (var _i = 0; _i < value.length; ++_i) {
  11006. if (_i in value) {
  11007. s.push(_i, value[_i]); // If the callback needs to know the value of i, call
  11008. // path.getName(), assuming path is the parameter name.
  11009. callback(this);
  11010. s.length -= 2;
  11011. }
  11012. }
  11013. s.length = origLen;
  11014. }; // Similar to FastPath.prototype.each, except that the results of the
  11015. // callback function invocations are stored in an array and returned at
  11016. // the end of the iteration.
  11017. FastPath.prototype.map = function map(callback
  11018. /*, name1, name2, ... */
  11019. ) {
  11020. var s = this.stack;
  11021. var origLen = s.length;
  11022. var value = s[origLen - 1];
  11023. var argc = arguments.length;
  11024. for (var i = 1; i < argc; ++i) {
  11025. var name = arguments[i];
  11026. value = value[name];
  11027. s.push(name, value);
  11028. }
  11029. var result = new Array(value.length);
  11030. for (var _i2 = 0; _i2 < value.length; ++_i2) {
  11031. if (_i2 in value) {
  11032. s.push(_i2, value[_i2]);
  11033. result[_i2] = callback(this, _i2);
  11034. s.length -= 2;
  11035. }
  11036. }
  11037. s.length = origLen;
  11038. return result;
  11039. };
  11040. var fastPath = FastPath;
  11041. var normalize$3 = options.normalize;
  11042. function printSubtree(path$$1, print, options$$1, printAstToDoc) {
  11043. if (options$$1.printer.embed) {
  11044. return options$$1.printer.embed(path$$1, print, function (text, partialNextOptions) {
  11045. return textToDoc(text, partialNextOptions, options$$1, printAstToDoc);
  11046. }, options$$1);
  11047. }
  11048. }
  11049. function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) {
  11050. var nextOptions = normalize$3(Object.assign({}, parentOptions, partialNextOptions, {
  11051. parentParser: parentOptions.parser,
  11052. originalText: text
  11053. }), {
  11054. passThrough: true
  11055. });
  11056. var result = parser.parse(text, nextOptions);
  11057. var ast = result.ast;
  11058. text = result.text;
  11059. var astComments = ast.comments;
  11060. delete ast.comments;
  11061. comments.attach(astComments, ast, text, nextOptions);
  11062. return printAstToDoc(ast, nextOptions);
  11063. }
  11064. var multiparser = {
  11065. printSubtree
  11066. };
  11067. var doc$2 = doc;
  11068. var docBuilders$2 = doc$2.builders;
  11069. var concat$3 = docBuilders$2.concat;
  11070. var hardline$2 = docBuilders$2.hardline;
  11071. var addAlignmentToDoc$1 = docBuilders$2.addAlignmentToDoc;
  11072. var docUtils$2 = doc$2.utils;
  11073. /**
  11074. * Takes an abstract syntax tree (AST) and recursively converts it to a
  11075. * document (series of printing primitives).
  11076. *
  11077. * This is done by descending down the AST recursively. The recursion
  11078. * involves two functions that call each other:
  11079. *
  11080. * 1. printGenerically(), which is defined as an inner function here.
  11081. * It basically takes care of node caching.
  11082. * 2. callPluginPrintFunction(), which checks for some options, and
  11083. * ultimately calls the print() function provided by the plugin.
  11084. *
  11085. * The plugin function will call printGenerically() again for child nodes
  11086. * of the current node, which will do its housekeeping, then call the
  11087. * plugin function again, and so on.
  11088. *
  11089. * All the while, these functions pass a "path" variable around, which
  11090. * is a stack-like data structure (FastPath) that maintains the current
  11091. * state of the recursion. It is called "path", because it represents
  11092. * the path to the current node through the Abstract Syntax Tree.
  11093. */
  11094. function printAstToDoc(ast, options) {
  11095. var alignmentSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  11096. var printer = options.printer;
  11097. if (printer.preprocess) {
  11098. ast = printer.preprocess(ast, options);
  11099. }
  11100. var cache = new Map();
  11101. function printGenerically(path$$1, args) {
  11102. var node = path$$1.getValue();
  11103. var shouldCache = node && typeof node === "object" && args === undefined;
  11104. if (shouldCache && cache.has(node)) {
  11105. return cache.get(node);
  11106. } // We let JSXElement print its comments itself because it adds () around
  11107. // UnionTypeAnnotation has to align the child without the comments
  11108. var res;
  11109. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path$$1)) {
  11110. res = callPluginPrintFunction(path$$1, options, printGenerically, args);
  11111. } else {
  11112. // printComments will call the plugin print function and check for
  11113. // comments to print
  11114. res = comments.printComments(path$$1, function (p) {
  11115. return callPluginPrintFunction(p, options, printGenerically, args);
  11116. }, options, args && args.needsSemi);
  11117. }
  11118. if (shouldCache) {
  11119. cache.set(node, res);
  11120. }
  11121. return res;
  11122. }
  11123. var doc$$2 = printGenerically(new fastPath(ast));
  11124. if (alignmentSize > 0) {
  11125. // Add a hardline to make the indents take effect
  11126. // It should be removed in index.js format()
  11127. doc$$2 = addAlignmentToDoc$1(concat$3([hardline$2, doc$$2]), alignmentSize, options.tabWidth);
  11128. }
  11129. docUtils$2.propagateBreaks(doc$$2);
  11130. return doc$$2;
  11131. }
  11132. function callPluginPrintFunction(path$$1, options, printPath, args) {
  11133. assert.ok(path$$1 instanceof fastPath);
  11134. var node = path$$1.getValue();
  11135. var printer = options.printer; // Escape hatch
  11136. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path$$1)) {
  11137. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  11138. }
  11139. if (node) {
  11140. try {
  11141. // Potentially switch to a different parser
  11142. var sub = multiparser.printSubtree(path$$1, printPath, options, printAstToDoc);
  11143. if (sub) {
  11144. return sub;
  11145. }
  11146. } catch (error) {
  11147. /* istanbul ignore if */
  11148. if (process.env.PRETTIER_DEBUG) {
  11149. throw error;
  11150. } // Continue with current parser
  11151. }
  11152. }
  11153. return printer.print(path$$1, options, printPath, args);
  11154. }
  11155. var astToDoc = printAstToDoc;
  11156. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  11157. var resultStartNode = startNodeAndParents.node;
  11158. var resultEndNode = endNodeAndParents.node;
  11159. if (resultStartNode === resultEndNode) {
  11160. return {
  11161. startNode: resultStartNode,
  11162. endNode: resultEndNode
  11163. };
  11164. }
  11165. var _iteratorNormalCompletion = true;
  11166. var _didIteratorError = false;
  11167. var _iteratorError = undefined;
  11168. try {
  11169. for (var _iterator = endNodeAndParents.parentNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  11170. var endParent = _step.value;
  11171. if (endParent.type !== "Program" && endParent.type !== "File" && opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)) {
  11172. resultEndNode = endParent;
  11173. } else {
  11174. break;
  11175. }
  11176. }
  11177. } catch (err) {
  11178. _didIteratorError = true;
  11179. _iteratorError = err;
  11180. } finally {
  11181. try {
  11182. if (!_iteratorNormalCompletion && _iterator.return != null) {
  11183. _iterator.return();
  11184. }
  11185. } finally {
  11186. if (_didIteratorError) {
  11187. throw _iteratorError;
  11188. }
  11189. }
  11190. }
  11191. var _iteratorNormalCompletion2 = true;
  11192. var _didIteratorError2 = false;
  11193. var _iteratorError2 = undefined;
  11194. try {
  11195. for (var _iterator2 = startNodeAndParents.parentNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  11196. var startParent = _step2.value;
  11197. if (startParent.type !== "Program" && startParent.type !== "File" && opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)) {
  11198. resultStartNode = startParent;
  11199. } else {
  11200. break;
  11201. }
  11202. }
  11203. } catch (err) {
  11204. _didIteratorError2 = true;
  11205. _iteratorError2 = err;
  11206. } finally {
  11207. try {
  11208. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  11209. _iterator2.return();
  11210. }
  11211. } finally {
  11212. if (_didIteratorError2) {
  11213. throw _iteratorError2;
  11214. }
  11215. }
  11216. }
  11217. return {
  11218. startNode: resultStartNode,
  11219. endNode: resultEndNode
  11220. };
  11221. }
  11222. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  11223. predicate = predicate || function () {
  11224. return true;
  11225. };
  11226. parentNodes = parentNodes || [];
  11227. var start = options.locStart(node, options.locStart);
  11228. var end = options.locEnd(node, options.locEnd);
  11229. if (start <= offset && offset <= end) {
  11230. var _iteratorNormalCompletion3 = true;
  11231. var _didIteratorError3 = false;
  11232. var _iteratorError3 = undefined;
  11233. try {
  11234. for (var _iterator3 = comments.getSortedChildNodes(node, options)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  11235. var childNode = _step3.value;
  11236. var childResult = findNodeAtOffset(childNode, offset, options, predicate, [node].concat(parentNodes));
  11237. if (childResult) {
  11238. return childResult;
  11239. }
  11240. }
  11241. } catch (err) {
  11242. _didIteratorError3 = true;
  11243. _iteratorError3 = err;
  11244. } finally {
  11245. try {
  11246. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  11247. _iterator3.return();
  11248. }
  11249. } finally {
  11250. if (_didIteratorError3) {
  11251. throw _iteratorError3;
  11252. }
  11253. }
  11254. }
  11255. if (predicate(node)) {
  11256. return {
  11257. node: node,
  11258. parentNodes: parentNodes
  11259. };
  11260. }
  11261. }
  11262. } // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  11263. function isSourceElement(opts, node) {
  11264. if (node == null) {
  11265. return false;
  11266. } // JS and JS like to avoid repetitions
  11267. var jsSourceElements = ["FunctionDeclaration", "BlockStatement", "BreakStatement", "ContinueStatement", "DebuggerStatement", "DoWhileStatement", "EmptyStatement", "ExpressionStatement", "ForInStatement", "ForStatement", "IfStatement", "LabeledStatement", "ReturnStatement", "SwitchStatement", "ThrowStatement", "TryStatement", "VariableDeclaration", "WhileStatement", "WithStatement", "ClassDeclaration", // ES 2015
  11268. "ImportDeclaration", // Module
  11269. "ExportDefaultDeclaration", // Module
  11270. "ExportNamedDeclaration", // Module
  11271. "ExportAllDeclaration", // Module
  11272. "TypeAlias", // Flow
  11273. "InterfaceDeclaration", // Flow, TypeScript
  11274. "TypeAliasDeclaration", // TypeScript
  11275. "ExportAssignment", // TypeScript
  11276. "ExportDeclaration" // TypeScript
  11277. ];
  11278. var jsonSourceElements = ["ObjectExpression", "ArrayExpression", "StringLiteral", "NumericLiteral", "BooleanLiteral", "NullLiteral"];
  11279. var graphqlSourceElements = ["OperationDefinition", "FragmentDefinition", "VariableDefinition", "TypeExtensionDefinition", "ObjectTypeDefinition", "FieldDefinition", "DirectiveDefinition", "EnumTypeDefinition", "EnumValueDefinition", "InputValueDefinition", "InputObjectTypeDefinition", "SchemaDefinition", "OperationTypeDefinition", "InterfaceTypeDefinition", "UnionTypeDefinition", "ScalarTypeDefinition"];
  11280. switch (opts.parser) {
  11281. case "flow":
  11282. case "babel":
  11283. case "typescript":
  11284. return jsSourceElements.indexOf(node.type) > -1;
  11285. case "json":
  11286. return jsonSourceElements.indexOf(node.type) > -1;
  11287. case "graphql":
  11288. return graphqlSourceElements.indexOf(node.kind) > -1;
  11289. case "vue":
  11290. return node.tag !== "root";
  11291. }
  11292. return false;
  11293. }
  11294. function calculateRange(text, opts, ast) {
  11295. // Contract the range so that it has non-whitespace characters at its endpoints.
  11296. // This ensures we can format a range that doesn't end on a node.
  11297. var rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  11298. var startNonWhitespace = Math.max(opts.rangeStart + rangeStringOrig.search(/\S/), opts.rangeStart);
  11299. var endNonWhitespace;
  11300. for (endNonWhitespace = opts.rangeEnd; endNonWhitespace > opts.rangeStart; --endNonWhitespace) {
  11301. if (text[endNonWhitespace - 1].match(/\S/)) {
  11302. break;
  11303. }
  11304. }
  11305. var startNodeAndParents = findNodeAtOffset(ast, startNonWhitespace, opts, function (node) {
  11306. return isSourceElement(opts, node);
  11307. });
  11308. var endNodeAndParents = findNodeAtOffset(ast, endNonWhitespace, opts, function (node) {
  11309. return isSourceElement(opts, node);
  11310. });
  11311. if (!startNodeAndParents || !endNodeAndParents) {
  11312. return {
  11313. rangeStart: 0,
  11314. rangeEnd: 0
  11315. };
  11316. }
  11317. var siblingAncestors = findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts);
  11318. var startNode = siblingAncestors.startNode,
  11319. endNode = siblingAncestors.endNode;
  11320. var rangeStart = Math.min(opts.locStart(startNode, opts.locStart), opts.locStart(endNode, opts.locStart));
  11321. var rangeEnd = Math.max(opts.locEnd(startNode, opts.locEnd), opts.locEnd(endNode, opts.locEnd));
  11322. return {
  11323. rangeStart: rangeStart,
  11324. rangeEnd: rangeEnd
  11325. };
  11326. }
  11327. var rangeUtil = {
  11328. calculateRange,
  11329. findNodeAtOffset
  11330. };
  11331. var normalizeOptions = options.normalize;
  11332. var guessEndOfLine = endOfLine.guessEndOfLine;
  11333. var convertEndOfLineToChars = endOfLine.convertEndOfLineToChars;
  11334. var mapDoc = doc.utils.mapDoc;
  11335. var printDocToString = doc.printer.printDocToString;
  11336. var printDocToDebug = doc.debug.printDocToDebug;
  11337. var UTF8BOM = 0xfeff;
  11338. var CURSOR = Symbol("cursor");
  11339. var PLACEHOLDERS = {
  11340. cursorOffset: "<<<PRETTIER_CURSOR>>>",
  11341. rangeStart: "<<<PRETTIER_RANGE_START>>>",
  11342. rangeEnd: "<<<PRETTIER_RANGE_END>>>"
  11343. };
  11344. function ensureAllCommentsPrinted(astComments) {
  11345. if (!astComments) {
  11346. return;
  11347. }
  11348. for (var i = 0; i < astComments.length; ++i) {
  11349. if (astComments[i].value.trim() === "prettier-ignore") {
  11350. // If there's a prettier-ignore, we're not printing that sub-tree so we
  11351. // don't know if the comments was printed or not.
  11352. return;
  11353. }
  11354. }
  11355. astComments.forEach(function (comment) {
  11356. if (!comment.printed) {
  11357. throw new Error('Comment "' + comment.value.trim() + '" was not printed. Please report this error!');
  11358. }
  11359. delete comment.printed;
  11360. });
  11361. }
  11362. function attachComments(text, ast, opts) {
  11363. var astComments = ast.comments;
  11364. if (astComments) {
  11365. delete ast.comments;
  11366. comments.attach(astComments, ast, text, opts);
  11367. }
  11368. ast.tokens = [];
  11369. opts.originalText = opts.parser === "yaml" ? text : text.trimRight();
  11370. return astComments;
  11371. }
  11372. function coreFormat(text, opts, addAlignmentSize) {
  11373. if (!text || !text.trim().length) {
  11374. return {
  11375. formatted: "",
  11376. cursorOffset: 0
  11377. };
  11378. }
  11379. addAlignmentSize = addAlignmentSize || 0;
  11380. var parsed = parser.parse(text, opts);
  11381. var ast = parsed.ast;
  11382. text = parsed.text;
  11383. if (opts.cursorOffset >= 0) {
  11384. var nodeResult = rangeUtil.findNodeAtOffset(ast, opts.cursorOffset, opts);
  11385. if (nodeResult && nodeResult.node) {
  11386. opts.cursorNode = nodeResult.node;
  11387. }
  11388. }
  11389. var astComments = attachComments(text, ast, opts);
  11390. var doc$$1 = astToDoc(ast, opts, addAlignmentSize);
  11391. var eol = convertEndOfLineToChars(opts.endOfLine);
  11392. var result = printDocToString(opts.endOfLine === "lf" ? doc$$1 : mapDoc(doc$$1, function (currentDoc) {
  11393. return typeof currentDoc === "string" && currentDoc.indexOf("\n") !== -1 ? currentDoc.replace(/\n/g, eol) : currentDoc;
  11394. }), opts);
  11395. ensureAllCommentsPrinted(astComments); // Remove extra leading indentation as well as the added indentation after last newline
  11396. if (addAlignmentSize > 0) {
  11397. var trimmed = result.formatted.trim();
  11398. if (result.cursorNodeStart !== undefined) {
  11399. result.cursorNodeStart -= result.formatted.indexOf(trimmed);
  11400. }
  11401. result.formatted = trimmed + convertEndOfLineToChars(opts.endOfLine);
  11402. }
  11403. if (opts.cursorOffset >= 0) {
  11404. var oldCursorNodeStart;
  11405. var oldCursorNodeText;
  11406. var cursorOffsetRelativeToOldCursorNode;
  11407. var newCursorNodeStart;
  11408. var newCursorNodeText;
  11409. if (opts.cursorNode && result.cursorNodeText) {
  11410. oldCursorNodeStart = opts.locStart(opts.cursorNode);
  11411. oldCursorNodeText = text.slice(oldCursorNodeStart, opts.locEnd(opts.cursorNode));
  11412. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset - oldCursorNodeStart;
  11413. newCursorNodeStart = result.cursorNodeStart;
  11414. newCursorNodeText = result.cursorNodeText;
  11415. } else {
  11416. oldCursorNodeStart = 0;
  11417. oldCursorNodeText = text;
  11418. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset;
  11419. newCursorNodeStart = 0;
  11420. newCursorNodeText = result.formatted;
  11421. }
  11422. if (oldCursorNodeText === newCursorNodeText) {
  11423. return {
  11424. formatted: result.formatted,
  11425. cursorOffset: newCursorNodeStart + cursorOffsetRelativeToOldCursorNode
  11426. };
  11427. } // diff old and new cursor node texts, with a special cursor
  11428. // symbol inserted to find out where it moves to
  11429. var oldCursorNodeCharArray = oldCursorNodeText.split("");
  11430. oldCursorNodeCharArray.splice(cursorOffsetRelativeToOldCursorNode, 0, CURSOR);
  11431. var newCursorNodeCharArray = newCursorNodeText.split("");
  11432. var cursorNodeDiff = lib.diffArrays(oldCursorNodeCharArray, newCursorNodeCharArray);
  11433. var cursorOffset = newCursorNodeStart;
  11434. var _iteratorNormalCompletion = true;
  11435. var _didIteratorError = false;
  11436. var _iteratorError = undefined;
  11437. try {
  11438. for (var _iterator = cursorNodeDiff[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  11439. var entry = _step.value;
  11440. if (entry.removed) {
  11441. if (entry.value.indexOf(CURSOR) > -1) {
  11442. break;
  11443. }
  11444. } else {
  11445. cursorOffset += entry.count;
  11446. }
  11447. }
  11448. } catch (err) {
  11449. _didIteratorError = true;
  11450. _iteratorError = err;
  11451. } finally {
  11452. try {
  11453. if (!_iteratorNormalCompletion && _iterator.return != null) {
  11454. _iterator.return();
  11455. }
  11456. } finally {
  11457. if (_didIteratorError) {
  11458. throw _iteratorError;
  11459. }
  11460. }
  11461. }
  11462. return {
  11463. formatted: result.formatted,
  11464. cursorOffset
  11465. };
  11466. }
  11467. return {
  11468. formatted: result.formatted
  11469. };
  11470. }
  11471. function formatRange(text, opts) {
  11472. var parsed = parser.parse(text, opts);
  11473. var ast = parsed.ast;
  11474. text = parsed.text;
  11475. var range = rangeUtil.calculateRange(text, opts, ast);
  11476. var rangeStart = range.rangeStart;
  11477. var rangeEnd = range.rangeEnd;
  11478. var rangeString = text.slice(rangeStart, rangeEnd); // Try to extend the range backwards to the beginning of the line.
  11479. // This is so we can detect indentation correctly and restore it.
  11480. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  11481. var rangeStart2 = Math.min(rangeStart, text.lastIndexOf("\n", rangeStart) + 1);
  11482. var indentString = text.slice(rangeStart2, rangeStart);
  11483. var alignmentSize = util$1.getAlignmentSize(indentString, opts.tabWidth);
  11484. var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
  11485. rangeStart: 0,
  11486. rangeEnd: Infinity,
  11487. printWidth: opts.printWidth - alignmentSize,
  11488. // track the cursor offset only if it's within our range
  11489. cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
  11490. }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
  11491. // we need to remove the newline that was inserted by the `format` call.
  11492. var rangeTrimmed = rangeResult.formatted.trimRight();
  11493. var rangeLeft = text.slice(0, rangeStart);
  11494. var rangeRight = text.slice(rangeEnd);
  11495. var cursorOffset = opts.cursorOffset;
  11496. if (opts.cursorOffset >= rangeEnd) {
  11497. // handle the case where the cursor was past the end of the range
  11498. cursorOffset = opts.cursorOffset - rangeEnd + (rangeStart + rangeTrimmed.length);
  11499. } else if (rangeResult.cursorOffset !== undefined) {
  11500. // handle the case where the cursor was in the range
  11501. cursorOffset = rangeResult.cursorOffset + rangeStart;
  11502. } // keep the cursor as it was if it was before the start of the range
  11503. var formatted;
  11504. if (opts.endOfLine === "lf") {
  11505. formatted = rangeLeft + rangeTrimmed + rangeRight;
  11506. } else {
  11507. var eol = convertEndOfLineToChars(opts.endOfLine);
  11508. if (cursorOffset >= 0) {
  11509. var parts = [rangeLeft, rangeTrimmed, rangeRight];
  11510. var partIndex = 0;
  11511. var partOffset = cursorOffset;
  11512. while (partIndex < parts.length) {
  11513. var part = parts[partIndex];
  11514. if (partOffset < part.length) {
  11515. parts[partIndex] = parts[partIndex].slice(0, partOffset) + PLACEHOLDERS.cursorOffset + parts[partIndex].slice(partOffset);
  11516. break;
  11517. }
  11518. partIndex++;
  11519. partOffset -= part.length;
  11520. }
  11521. var newRangeLeft = parts[0],
  11522. newRangeTrimmed = parts[1],
  11523. newRangeRight = parts[2];
  11524. formatted = (newRangeLeft.replace(/\n/g, eol) + newRangeTrimmed + newRangeRight.replace(/\n/g, eol)).replace(PLACEHOLDERS.cursorOffset, function (_, index) {
  11525. cursorOffset = index;
  11526. return "";
  11527. });
  11528. } else {
  11529. formatted = rangeLeft.replace(/\n/g, eol) + rangeTrimmed + rangeRight.replace(/\n/g, eol);
  11530. }
  11531. }
  11532. return {
  11533. formatted,
  11534. cursorOffset
  11535. };
  11536. }
  11537. function format(text, opts) {
  11538. var selectedParser = parser.resolveParser(opts);
  11539. var hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  11540. if (opts.requirePragma && !hasPragma) {
  11541. return {
  11542. formatted: text
  11543. };
  11544. }
  11545. if (opts.endOfLine === "auto") {
  11546. opts.endOfLine = guessEndOfLine(text);
  11547. }
  11548. var hasCursor = opts.cursorOffset >= 0;
  11549. var hasRangeStart = opts.rangeStart > 0;
  11550. var hasRangeEnd = opts.rangeEnd < text.length; // get rid of CR/CRLF parsing
  11551. if (text.indexOf("\r") !== -1) {
  11552. var offsetKeys = [hasCursor && "cursorOffset", hasRangeStart && "rangeStart", hasRangeEnd && "rangeEnd"].filter(Boolean).sort(function (aKey, bKey) {
  11553. return opts[aKey] - opts[bKey];
  11554. });
  11555. for (var i = offsetKeys.length - 1; i >= 0; i--) {
  11556. var key = offsetKeys[i];
  11557. text = text.slice(0, opts[key]) + PLACEHOLDERS[key] + text.slice(opts[key]);
  11558. }
  11559. text = text.replace(/\r\n?/g, "\n");
  11560. var _loop = function _loop(_i) {
  11561. var key = offsetKeys[_i];
  11562. text = text.replace(PLACEHOLDERS[key], function (_, index) {
  11563. opts[key] = index;
  11564. return "";
  11565. });
  11566. };
  11567. for (var _i = 0; _i < offsetKeys.length; _i++) {
  11568. _loop(_i);
  11569. }
  11570. }
  11571. var hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  11572. if (hasUnicodeBOM) {
  11573. text = text.substring(1);
  11574. if (hasCursor) {
  11575. opts.cursorOffset++;
  11576. }
  11577. if (hasRangeStart) {
  11578. opts.rangeStart++;
  11579. }
  11580. if (hasRangeEnd) {
  11581. opts.rangeEnd++;
  11582. }
  11583. }
  11584. if (!hasCursor) {
  11585. opts.cursorOffset = -1;
  11586. }
  11587. if (opts.rangeStart < 0) {
  11588. opts.rangeStart = 0;
  11589. }
  11590. if (opts.rangeEnd > text.length) {
  11591. opts.rangeEnd = text.length;
  11592. }
  11593. var result = hasRangeStart || hasRangeEnd ? formatRange(text, opts) : coreFormat(opts.insertPragma && opts.printer.insertPragma && !hasPragma ? opts.printer.insertPragma(text) : text, opts);
  11594. if (hasUnicodeBOM) {
  11595. result.formatted = String.fromCharCode(UTF8BOM) + result.formatted;
  11596. if (hasCursor) {
  11597. result.cursorOffset++;
  11598. }
  11599. }
  11600. return result;
  11601. }
  11602. var core = {
  11603. formatWithCursor(text, opts) {
  11604. opts = normalizeOptions(opts);
  11605. return format(text, opts);
  11606. },
  11607. parse(text, opts, massage) {
  11608. opts = normalizeOptions(opts);
  11609. if (text.indexOf("\r") !== -1) {
  11610. text = text.replace(/\r\n?/g, "\n");
  11611. }
  11612. var parsed = parser.parse(text, opts);
  11613. if (massage) {
  11614. parsed.ast = massageAst(parsed.ast, opts);
  11615. }
  11616. return parsed;
  11617. },
  11618. formatAST(ast, opts) {
  11619. opts = normalizeOptions(opts);
  11620. var doc$$1 = astToDoc(ast, opts);
  11621. return printDocToString(doc$$1, opts);
  11622. },
  11623. // Doesn't handle shebang for now
  11624. formatDoc(doc$$1, opts) {
  11625. var debug = printDocToDebug(doc$$1);
  11626. opts = normalizeOptions(Object.assign({}, opts, {
  11627. parser: "babel"
  11628. }));
  11629. return format(debug, opts).formatted;
  11630. },
  11631. printToDoc(text, opts) {
  11632. opts = normalizeOptions(opts);
  11633. var parsed = parser.parse(text, opts);
  11634. var ast = parsed.ast;
  11635. text = parsed.text;
  11636. attachComments(text, ast, opts);
  11637. return astToDoc(ast, opts);
  11638. },
  11639. printDocToString(doc$$1, opts) {
  11640. return printDocToString(doc$$1, normalizeOptions(opts));
  11641. }
  11642. };
  11643. var _createClass$1 = function () {
  11644. function defineProperties(target, props) {
  11645. for (var i = 0; i < props.length; i++) {
  11646. var descriptor = props[i];
  11647. descriptor.enumerable = descriptor.enumerable || false;
  11648. descriptor.configurable = true;
  11649. if ("value" in descriptor) descriptor.writable = true;
  11650. Object.defineProperty(target, descriptor.key, descriptor);
  11651. }
  11652. }
  11653. return function (Constructor, protoProps, staticProps) {
  11654. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  11655. if (staticProps) defineProperties(Constructor, staticProps);
  11656. return Constructor;
  11657. };
  11658. }();
  11659. function _classCallCheck$1(instance, Constructor) {
  11660. if (!(instance instanceof Constructor)) {
  11661. throw new TypeError("Cannot call a class as a function");
  11662. }
  11663. }
  11664. var ignore = function ignore() {
  11665. return new IgnoreBase();
  11666. }; // A simple implementation of make-array
  11667. function make_array(subject) {
  11668. return Array.isArray(subject) ? subject : [subject];
  11669. }
  11670. var REGEX_BLANK_LINE = /^\s+$/;
  11671. var REGEX_LEADING_EXCAPED_EXCLAMATION = /^\\\!/;
  11672. var REGEX_LEADING_EXCAPED_HASH = /^\\#/;
  11673. var SLASH = '/';
  11674. var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  11675. /* istanbul ignore next */
  11676. : 'node-ignore';
  11677. var IgnoreBase = function () {
  11678. function IgnoreBase() {
  11679. _classCallCheck$1(this, IgnoreBase);
  11680. this._rules = [];
  11681. this[KEY_IGNORE] = true;
  11682. this._initCache();
  11683. }
  11684. _createClass$1(IgnoreBase, [{
  11685. key: '_initCache',
  11686. value: function _initCache() {
  11687. this._cache = {};
  11688. } // @param {Array.<string>|string|Ignore} pattern
  11689. }, {
  11690. key: 'add',
  11691. value: function add(pattern) {
  11692. this._added = false;
  11693. if (typeof pattern === 'string') {
  11694. pattern = pattern.split(/\r?\n/g);
  11695. }
  11696. make_array(pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
  11697. // making the behavior changed.
  11698. if (this._added) {
  11699. this._initCache();
  11700. }
  11701. return this;
  11702. } // legacy
  11703. }, {
  11704. key: 'addPattern',
  11705. value: function addPattern(pattern) {
  11706. return this.add(pattern);
  11707. }
  11708. }, {
  11709. key: '_addPattern',
  11710. value: function _addPattern(pattern) {
  11711. // #32
  11712. if (pattern && pattern[KEY_IGNORE]) {
  11713. this._rules = this._rules.concat(pattern._rules);
  11714. this._added = true;
  11715. return;
  11716. }
  11717. if (this._checkPattern(pattern)) {
  11718. var rule = this._createRule(pattern);
  11719. this._added = true;
  11720. this._rules.push(rule);
  11721. }
  11722. }
  11723. }, {
  11724. key: '_checkPattern',
  11725. value: function _checkPattern(pattern) {
  11726. // > A blank line matches no files, so it can serve as a separator for readability.
  11727. return pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
  11728. && pattern.indexOf('#') !== 0;
  11729. }
  11730. }, {
  11731. key: 'filter',
  11732. value: function filter(paths) {
  11733. var _this = this;
  11734. return make_array(paths).filter(function (path$$1) {
  11735. return _this._filter(path$$1);
  11736. });
  11737. }
  11738. }, {
  11739. key: 'createFilter',
  11740. value: function createFilter() {
  11741. var _this2 = this;
  11742. return function (path$$1) {
  11743. return _this2._filter(path$$1);
  11744. };
  11745. }
  11746. }, {
  11747. key: 'ignores',
  11748. value: function ignores(path$$1) {
  11749. return !this._filter(path$$1);
  11750. }
  11751. }, {
  11752. key: '_createRule',
  11753. value: function _createRule(pattern) {
  11754. var origin = pattern;
  11755. var negative = false; // > An optional prefix "!" which negates the pattern;
  11756. if (pattern.indexOf('!') === 0) {
  11757. negative = true;
  11758. pattern = pattern.substr(1);
  11759. }
  11760. pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, `"\!important!.txt"`.
  11761. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that begin with a hash.
  11762. .replace(REGEX_LEADING_EXCAPED_HASH, '#');
  11763. var regex = make_regex(pattern, negative);
  11764. return {
  11765. origin: origin,
  11766. pattern: pattern,
  11767. negative: negative,
  11768. regex: regex
  11769. };
  11770. } // @returns `Boolean` true if the `path` is NOT ignored
  11771. }, {
  11772. key: '_filter',
  11773. value: function _filter(path$$1, slices) {
  11774. if (!path$$1) {
  11775. return false;
  11776. }
  11777. if (path$$1 in this._cache) {
  11778. return this._cache[path$$1];
  11779. }
  11780. if (!slices) {
  11781. // path/to/a.js
  11782. // ['path', 'to', 'a.js']
  11783. slices = path$$1.split(SLASH);
  11784. }
  11785. slices.pop();
  11786. return this._cache[path$$1] = slices.length // > It is not possible to re-include a file if a parent directory of that file is excluded.
  11787. // If the path contains a parent directory, check the parent first
  11788. ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path$$1) // Or only test the path
  11789. : this._test(path$$1);
  11790. } // @returns {Boolean} true if a file is NOT ignored
  11791. }, {
  11792. key: '_test',
  11793. value: function _test(path$$1) {
  11794. // Explicitly define variable type by setting matched to `0`
  11795. var matched = 0;
  11796. this._rules.forEach(function (rule) {
  11797. // if matched = true, then we only test negative rules
  11798. // if matched = false, then we test non-negative rules
  11799. if (!(matched ^ rule.negative)) {
  11800. matched = rule.negative ^ rule.regex.test(path$$1);
  11801. }
  11802. });
  11803. return !matched;
  11804. }
  11805. }]);
  11806. return IgnoreBase;
  11807. }(); // > If the pattern ends with a slash,
  11808. // > it is removed for the purpose of the following description,
  11809. // > but it would only find a match with a directory.
  11810. // > In other words, foo/ will match a directory foo and paths underneath it,
  11811. // > but will not match a regular file or a symbolic link foo
  11812. // > (this is consistent with the way how pathspec works in general in Git).
  11813. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  11814. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  11815. // you could use option `mark: true` with `glob`
  11816. // '`foo/`' should not continue with the '`..`'
  11817. var DEFAULT_REPLACER_PREFIX = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
  11818. [// (a\ ) -> (a )
  11819. // (a ) -> (a)
  11820. // (a \ ) -> (a )
  11821. /\\?\s+$/, function (match) {
  11822. return match.indexOf('\\') === 0 ? ' ' : '';
  11823. }], // replace (\ ) with ' '
  11824. [/\\\s/g, function () {
  11825. return ' ';
  11826. }], // Escape metacharacters
  11827. // which is written down by users but means special for regular expressions.
  11828. // > There are 12 characters with special meanings:
  11829. // > - the backslash \,
  11830. // > - the caret ^,
  11831. // > - the dollar sign $,
  11832. // > - the period or dot .,
  11833. // > - the vertical bar or pipe symbol |,
  11834. // > - the question mark ?,
  11835. // > - the asterisk or star *,
  11836. // > - the plus sign +,
  11837. // > - the opening parenthesis (,
  11838. // > - the closing parenthesis ),
  11839. // > - and the opening square bracket [,
  11840. // > - the opening curly brace {,
  11841. // > These special characters are often called "metacharacters".
  11842. [/[\\\^$.|?*+()\[{]/g, function (match) {
  11843. return '\\' + match;
  11844. }], // leading slash
  11845. [// > A leading slash matches the beginning of the pathname.
  11846. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  11847. // A leading slash matches the beginning of the pathname
  11848. /^\//, function () {
  11849. return '^';
  11850. }], // replace special metacharacter slash after the leading slash
  11851. [/\//g, function () {
  11852. return '\\/';
  11853. }], [// > A leading "**" followed by a slash means match in all directories.
  11854. // > For example, "**/foo" matches file or directory "foo" anywhere,
  11855. // > the same as pattern "foo".
  11856. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".
  11857. // Notice that the '*'s have been replaced as '\\*'
  11858. /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
  11859. function () {
  11860. return '^(?:.*\\/)?';
  11861. }]];
  11862. var DEFAULT_REPLACER_SUFFIX = [// starting
  11863. [// there will be no leading '/' (which has been replaced by section "leading slash")
  11864. // If starts with '**', adding a '^' to the regular expression also works
  11865. /^(?=[^\^])/, function () {
  11866. return !/\/(?!$)/.test(this) // > If the pattern does not contain a slash /, Git treats it as a shell glob pattern
  11867. // Actually, if there is only a trailing slash, git also treats it as a shell glob pattern
  11868. ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for consumption by fnmatch(3)
  11869. : '^';
  11870. }], // two globstars
  11871. [// Use lookahead assertions so that we could match more than one `'/**'`
  11872. /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
  11873. // should not use '*', or it will be replaced by the next replacer
  11874. // Check if it is not the last `'/**'`
  11875. function (match, index, str) {
  11876. return index + 6 < str.length // case: /**/
  11877. // > A slash followed by two consecutive asterisks then a slash matches zero or more directories.
  11878. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  11879. // '/**/'
  11880. ? '(?:\\/[^\\/]+)*' // case: /**
  11881. // > A trailing `"/**"` matches everything inside.
  11882. // #21: everything inside but it should not include the current folder
  11883. : '\\/.+';
  11884. }], // intermediate wildcards
  11885. [// Never replace escaped '*'
  11886. // ignore rule '\*' will match the path '*'
  11887. // 'abc.*/' -> go
  11888. // 'abc.*' -> skip this rule
  11889. /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
  11890. // '*.js' doesn't match 'abc'
  11891. function (match, p1) {
  11892. return p1 + '[^\\/]*';
  11893. }], // trailing wildcard
  11894. [/(\^|\\\/)?\\\*$/, function (match, p1) {
  11895. return (p1 // '\^':
  11896. // '/*' does not match ''
  11897. // '/*' does not match everything
  11898. // '\\\/':
  11899. // 'abc/*' does not match 'abc/'
  11900. ? p1 + '[^/]+' // 'a*' matches 'a'
  11901. // 'a*' matches 'aa'
  11902. : '[^/]*') + '(?=$|\\/$)';
  11903. }], [// unescape
  11904. /\\\\\\/g, function () {
  11905. return '\\';
  11906. }]];
  11907. var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// 'f'
  11908. // matches
  11909. // - /f(end)
  11910. // - /f/
  11911. // - (start)f(end)
  11912. // - (start)f/
  11913. // doesn't match
  11914. // - oof
  11915. // - foo
  11916. // pseudo:
  11917. // -> (^|/)f(/|$)
  11918. // ending
  11919. [// 'js' will not match 'js.'
  11920. // 'ab' will not match 'abc'
  11921. /(?:[^*\/])$/, // 'js*' will not match 'a.js'
  11922. // 'js/' will not match 'a.js'
  11923. // 'js' will match 'a.js' and 'a.js/'
  11924. function (match) {
  11925. return match + '(?=$|\\/)';
  11926. }]], DEFAULT_REPLACER_SUFFIX);
  11927. var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// #24
  11928. // The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore)
  11929. // A negative pattern without a trailing wildcard should not
  11930. // re-include the things inside that directory.
  11931. // eg:
  11932. // ['node_modules/*', '!node_modules']
  11933. // should ignore `node_modules/a.js`
  11934. [/(?:[^*\/])$/, function (match) {
  11935. return match + '(?=$|\\/$)';
  11936. }]], DEFAULT_REPLACER_SUFFIX); // A simple cache, because an ignore rule only has only one certain meaning
  11937. var cache = {}; // @param {pattern}
  11938. function make_regex(pattern, negative) {
  11939. var r = cache[pattern];
  11940. if (r) {
  11941. return r;
  11942. }
  11943. var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS;
  11944. var source = replacers.reduce(function (prev, current) {
  11945. return prev.replace(current[0], current[1].bind(pattern));
  11946. }, pattern);
  11947. return cache[pattern] = new RegExp(source, 'i');
  11948. } // Windows
  11949. // --------------------------------------------------------------
  11950. /* istanbul ignore if */
  11951. if ( // Detect `process` so that it can run in browsers.
  11952. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  11953. var filter = IgnoreBase.prototype._filter;
  11954. var make_posix = function make_posix(str) {
  11955. return /^\\\\\?\\/.test(str) || /[^\x00-\x80]+/.test(str) ? str : str.replace(/\\/g, '/');
  11956. };
  11957. IgnoreBase.prototype._filter = function (path$$1, slices) {
  11958. path$$1 = make_posix(path$$1);
  11959. return filter.call(this, path$$1, slices);
  11960. };
  11961. }
  11962. /**
  11963. * @param {string} filename
  11964. * @returns {Promise<null | string>}
  11965. */
  11966. function getFileContentOrNull(filename) {
  11967. return new Promise(function (resolve, reject) {
  11968. fs.readFile(filename, "utf8", function (error, data) {
  11969. if (error && error.code !== "ENOENT") {
  11970. reject(createError(filename, error));
  11971. } else {
  11972. resolve(error ? null : data);
  11973. }
  11974. });
  11975. });
  11976. }
  11977. /**
  11978. * @param {string} filename
  11979. * @returns {null | string}
  11980. */
  11981. getFileContentOrNull.sync = function (filename) {
  11982. try {
  11983. return fs.readFileSync(filename, "utf8");
  11984. } catch (error) {
  11985. if (error && error.code === "ENOENT") {
  11986. return null;
  11987. }
  11988. throw createError(filename, error);
  11989. }
  11990. };
  11991. function createError(filename, error) {
  11992. return new Error(`Unable to read ${filename}: ${error.message}`);
  11993. }
  11994. var getFileContentOrNull_1 = getFileContentOrNull;
  11995. /**
  11996. * @param {undefined | string} ignorePath
  11997. * @param {undefined | boolean} withNodeModules
  11998. */
  11999. function createIgnorer(ignorePath, withNodeModules) {
  12000. return (!ignorePath ? Promise.resolve(null) : getFileContentOrNull_1(path.resolve(ignorePath))).then(function (ignoreContent) {
  12001. return _createIgnorer(ignoreContent, withNodeModules);
  12002. });
  12003. }
  12004. /**
  12005. * @param {undefined | string} ignorePath
  12006. * @param {undefined | boolean} withNodeModules
  12007. */
  12008. createIgnorer.sync = function (ignorePath, withNodeModules) {
  12009. var ignoreContent = !ignorePath ? null : getFileContentOrNull_1.sync(path.resolve(ignorePath));
  12010. return _createIgnorer(ignoreContent, withNodeModules);
  12011. };
  12012. /**
  12013. * @param {null | string} ignoreContent
  12014. * @param {undefined | boolean} withNodeModules
  12015. */
  12016. function _createIgnorer(ignoreContent, withNodeModules) {
  12017. var ignorer = ignore().add(ignoreContent || "");
  12018. if (!withNodeModules) {
  12019. ignorer.add("node_modules");
  12020. }
  12021. return ignorer;
  12022. }
  12023. var createIgnorer_1 = createIgnorer;
  12024. /**
  12025. * @typedef {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} FileInfoOptions
  12026. * @typedef {{ ignored: boolean, inferredParser: string | null }} FileInfoResult
  12027. */
  12028. /**
  12029. * @param {string} filePath
  12030. * @param {FileInfoOptions} opts
  12031. * @returns {Promise<FileInfoResult>}
  12032. *
  12033. * Please note that prettier.getFileInfo() expects opts.plugins to be an array of paths,
  12034. * not an object. A transformation from this array to an object is automatically done
  12035. * internally by the method wrapper. See withPlugins() in index.js.
  12036. */
  12037. function getFileInfo(filePath, opts) {
  12038. return createIgnorer_1(opts.ignorePath, opts.withNodeModules).then(function (ignorer) {
  12039. return _getFileInfo(ignorer, normalizeFilePath(filePath, opts.ignorePath), opts.plugins);
  12040. });
  12041. }
  12042. /**
  12043. * @param {string} filePath
  12044. * @param {FileInfoOptions} opts
  12045. * @returns {FileInfoResult}
  12046. */
  12047. getFileInfo.sync = function (filePath, opts) {
  12048. var ignorer = createIgnorer_1.sync(opts.ignorePath, opts.withNodeModules);
  12049. return _getFileInfo(ignorer, normalizeFilePath(filePath, opts.ignorePath), opts.plugins);
  12050. };
  12051. function _getFileInfo(ignorer, filePath, plugins) {
  12052. var ignored = ignorer.ignores(filePath);
  12053. var inferredParser = options.inferParser(filePath, plugins) || null;
  12054. return {
  12055. ignored,
  12056. inferredParser
  12057. };
  12058. }
  12059. function normalizeFilePath(filePath, ignorePath) {
  12060. return ignorePath ? path.relative(path.dirname(ignorePath), filePath) : filePath;
  12061. }
  12062. var getFileInfo_1 = getFileInfo;
  12063. var lodash_uniqby = createCommonjsModule(function (module, exports) {
  12064. /**
  12065. * lodash (Custom Build) <https://lodash.com/>
  12066. * Build: `lodash modularize exports="npm" -o ./`
  12067. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  12068. * Released under MIT license <https://lodash.com/license>
  12069. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  12070. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  12071. */
  12072. /** Used as the size to enable large array optimizations. */
  12073. var LARGE_ARRAY_SIZE = 200;
  12074. /** Used as the `TypeError` message for "Functions" methods. */
  12075. var FUNC_ERROR_TEXT = 'Expected a function';
  12076. /** Used to stand-in for `undefined` hash values. */
  12077. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  12078. /** Used to compose bitmasks for comparison styles. */
  12079. var UNORDERED_COMPARE_FLAG = 1,
  12080. PARTIAL_COMPARE_FLAG = 2;
  12081. /** Used as references for various `Number` constants. */
  12082. var INFINITY = 1 / 0,
  12083. MAX_SAFE_INTEGER = 9007199254740991;
  12084. /** `Object#toString` result references. */
  12085. var argsTag = '[object Arguments]',
  12086. arrayTag = '[object Array]',
  12087. boolTag = '[object Boolean]',
  12088. dateTag = '[object Date]',
  12089. errorTag = '[object Error]',
  12090. funcTag = '[object Function]',
  12091. genTag = '[object GeneratorFunction]',
  12092. mapTag = '[object Map]',
  12093. numberTag = '[object Number]',
  12094. objectTag = '[object Object]',
  12095. promiseTag = '[object Promise]',
  12096. regexpTag = '[object RegExp]',
  12097. setTag = '[object Set]',
  12098. stringTag = '[object String]',
  12099. symbolTag = '[object Symbol]',
  12100. weakMapTag = '[object WeakMap]';
  12101. var arrayBufferTag = '[object ArrayBuffer]',
  12102. dataViewTag = '[object DataView]',
  12103. float32Tag = '[object Float32Array]',
  12104. float64Tag = '[object Float64Array]',
  12105. int8Tag = '[object Int8Array]',
  12106. int16Tag = '[object Int16Array]',
  12107. int32Tag = '[object Int32Array]',
  12108. uint8Tag = '[object Uint8Array]',
  12109. uint8ClampedTag = '[object Uint8ClampedArray]',
  12110. uint16Tag = '[object Uint16Array]',
  12111. uint32Tag = '[object Uint32Array]';
  12112. /** Used to match property names within property paths. */
  12113. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  12114. reIsPlainProp = /^\w*$/,
  12115. reLeadingDot = /^\./,
  12116. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  12117. /**
  12118. * Used to match `RegExp`
  12119. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  12120. */
  12121. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  12122. /** Used to match backslashes in property paths. */
  12123. var reEscapeChar = /\\(\\)?/g;
  12124. /** Used to detect host constructors (Safari). */
  12125. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  12126. /** Used to detect unsigned integer values. */
  12127. var reIsUint = /^(?:0|[1-9]\d*)$/;
  12128. /** Used to identify `toStringTag` values of typed arrays. */
  12129. var typedArrayTags = {};
  12130. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  12131. 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;
  12132. /** Detect free variable `global` from Node.js. */
  12133. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
  12134. /** Detect free variable `self`. */
  12135. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  12136. /** Used as a reference to the global object. */
  12137. var root = freeGlobal || freeSelf || Function('return this')();
  12138. /** Detect free variable `exports`. */
  12139. var freeExports = 'object' == 'object' && exports && !exports.nodeType && exports;
  12140. /** Detect free variable `module`. */
  12141. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  12142. /** Detect the popular CommonJS extension `module.exports`. */
  12143. var moduleExports = freeModule && freeModule.exports === freeExports;
  12144. /** Detect free variable `process` from Node.js. */
  12145. var freeProcess = moduleExports && freeGlobal.process;
  12146. /** Used to access faster Node.js helpers. */
  12147. var nodeUtil = function () {
  12148. try {
  12149. return freeProcess && freeProcess.binding('util');
  12150. } catch (e) {}
  12151. }();
  12152. /* Node.js helper references. */
  12153. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  12154. /**
  12155. * A specialized version of `_.includes` for arrays without support for
  12156. * specifying an index to search from.
  12157. *
  12158. * @private
  12159. * @param {Array} [array] The array to inspect.
  12160. * @param {*} target The value to search for.
  12161. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  12162. */
  12163. function arrayIncludes(array, value) {
  12164. var length = array ? array.length : 0;
  12165. return !!length && baseIndexOf(array, value, 0) > -1;
  12166. }
  12167. /**
  12168. * This function is like `arrayIncludes` except that it accepts a comparator.
  12169. *
  12170. * @private
  12171. * @param {Array} [array] The array to inspect.
  12172. * @param {*} target The value to search for.
  12173. * @param {Function} comparator The comparator invoked per element.
  12174. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  12175. */
  12176. function arrayIncludesWith(array, value, comparator) {
  12177. var index = -1,
  12178. length = array ? array.length : 0;
  12179. while (++index < length) {
  12180. if (comparator(value, array[index])) {
  12181. return true;
  12182. }
  12183. }
  12184. return false;
  12185. }
  12186. /**
  12187. * A specialized version of `_.some` for arrays without support for iteratee
  12188. * shorthands.
  12189. *
  12190. * @private
  12191. * @param {Array} [array] The array to iterate over.
  12192. * @param {Function} predicate The function invoked per iteration.
  12193. * @returns {boolean} Returns `true` if any element passes the predicate check,
  12194. * else `false`.
  12195. */
  12196. function arraySome(array, predicate) {
  12197. var index = -1,
  12198. length = array ? array.length : 0;
  12199. while (++index < length) {
  12200. if (predicate(array[index], index, array)) {
  12201. return true;
  12202. }
  12203. }
  12204. return false;
  12205. }
  12206. /**
  12207. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  12208. * support for iteratee shorthands.
  12209. *
  12210. * @private
  12211. * @param {Array} array The array to inspect.
  12212. * @param {Function} predicate The function invoked per iteration.
  12213. * @param {number} fromIndex The index to search from.
  12214. * @param {boolean} [fromRight] Specify iterating from right to left.
  12215. * @returns {number} Returns the index of the matched value, else `-1`.
  12216. */
  12217. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  12218. var length = array.length,
  12219. index = fromIndex + (fromRight ? 1 : -1);
  12220. while (fromRight ? index-- : ++index < length) {
  12221. if (predicate(array[index], index, array)) {
  12222. return index;
  12223. }
  12224. }
  12225. return -1;
  12226. }
  12227. /**
  12228. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  12229. *
  12230. * @private
  12231. * @param {Array} array The array to inspect.
  12232. * @param {*} value The value to search for.
  12233. * @param {number} fromIndex The index to search from.
  12234. * @returns {number} Returns the index of the matched value, else `-1`.
  12235. */
  12236. function baseIndexOf(array, value, fromIndex) {
  12237. if (value !== value) {
  12238. return baseFindIndex(array, baseIsNaN, fromIndex);
  12239. }
  12240. var index = fromIndex - 1,
  12241. length = array.length;
  12242. while (++index < length) {
  12243. if (array[index] === value) {
  12244. return index;
  12245. }
  12246. }
  12247. return -1;
  12248. }
  12249. /**
  12250. * The base implementation of `_.isNaN` without support for number objects.
  12251. *
  12252. * @private
  12253. * @param {*} value The value to check.
  12254. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  12255. */
  12256. function baseIsNaN(value) {
  12257. return value !== value;
  12258. }
  12259. /**
  12260. * The base implementation of `_.property` without support for deep paths.
  12261. *
  12262. * @private
  12263. * @param {string} key The key of the property to get.
  12264. * @returns {Function} Returns the new accessor function.
  12265. */
  12266. function baseProperty(key) {
  12267. return function (object) {
  12268. return object == null ? undefined : object[key];
  12269. };
  12270. }
  12271. /**
  12272. * The base implementation of `_.times` without support for iteratee shorthands
  12273. * or max array length checks.
  12274. *
  12275. * @private
  12276. * @param {number} n The number of times to invoke `iteratee`.
  12277. * @param {Function} iteratee The function invoked per iteration.
  12278. * @returns {Array} Returns the array of results.
  12279. */
  12280. function baseTimes(n, iteratee) {
  12281. var index = -1,
  12282. result = Array(n);
  12283. while (++index < n) {
  12284. result[index] = iteratee(index);
  12285. }
  12286. return result;
  12287. }
  12288. /**
  12289. * The base implementation of `_.unary` without support for storing metadata.
  12290. *
  12291. * @private
  12292. * @param {Function} func The function to cap arguments for.
  12293. * @returns {Function} Returns the new capped function.
  12294. */
  12295. function baseUnary(func) {
  12296. return function (value) {
  12297. return func(value);
  12298. };
  12299. }
  12300. /**
  12301. * Checks if a cache value for `key` exists.
  12302. *
  12303. * @private
  12304. * @param {Object} cache The cache to query.
  12305. * @param {string} key The key of the entry to check.
  12306. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12307. */
  12308. function cacheHas(cache, key) {
  12309. return cache.has(key);
  12310. }
  12311. /**
  12312. * Gets the value at `key` of `object`.
  12313. *
  12314. * @private
  12315. * @param {Object} [object] The object to query.
  12316. * @param {string} key The key of the property to get.
  12317. * @returns {*} Returns the property value.
  12318. */
  12319. function getValue(object, key) {
  12320. return object == null ? undefined : object[key];
  12321. }
  12322. /**
  12323. * Checks if `value` is a host object in IE < 9.
  12324. *
  12325. * @private
  12326. * @param {*} value The value to check.
  12327. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  12328. */
  12329. function isHostObject(value) {
  12330. // Many host objects are `Object` objects that can coerce to strings
  12331. // despite having improperly defined `toString` methods.
  12332. var result = false;
  12333. if (value != null && typeof value.toString != 'function') {
  12334. try {
  12335. result = !!(value + '');
  12336. } catch (e) {}
  12337. }
  12338. return result;
  12339. }
  12340. /**
  12341. * Converts `map` to its key-value pairs.
  12342. *
  12343. * @private
  12344. * @param {Object} map The map to convert.
  12345. * @returns {Array} Returns the key-value pairs.
  12346. */
  12347. function mapToArray(map) {
  12348. var index = -1,
  12349. result = Array(map.size);
  12350. map.forEach(function (value, key) {
  12351. result[++index] = [key, value];
  12352. });
  12353. return result;
  12354. }
  12355. /**
  12356. * Creates a unary function that invokes `func` with its argument transformed.
  12357. *
  12358. * @private
  12359. * @param {Function} func The function to wrap.
  12360. * @param {Function} transform The argument transform.
  12361. * @returns {Function} Returns the new function.
  12362. */
  12363. function overArg(func, transform) {
  12364. return function (arg) {
  12365. return func(transform(arg));
  12366. };
  12367. }
  12368. /**
  12369. * Converts `set` to an array of its values.
  12370. *
  12371. * @private
  12372. * @param {Object} set The set to convert.
  12373. * @returns {Array} Returns the values.
  12374. */
  12375. function setToArray(set) {
  12376. var index = -1,
  12377. result = Array(set.size);
  12378. set.forEach(function (value) {
  12379. result[++index] = value;
  12380. });
  12381. return result;
  12382. }
  12383. /** Used for built-in method references. */
  12384. var arrayProto = Array.prototype,
  12385. funcProto = Function.prototype,
  12386. objectProto = Object.prototype;
  12387. /** Used to detect overreaching core-js shims. */
  12388. var coreJsData = root['__core-js_shared__'];
  12389. /** Used to detect methods masquerading as native. */
  12390. var maskSrcKey = function () {
  12391. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  12392. return uid ? 'Symbol(src)_1.' + uid : '';
  12393. }();
  12394. /** Used to resolve the decompiled source of functions. */
  12395. var funcToString = funcProto.toString;
  12396. /** Used to check objects for own properties. */
  12397. var hasOwnProperty = objectProto.hasOwnProperty;
  12398. /**
  12399. * Used to resolve the
  12400. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  12401. * of values.
  12402. */
  12403. var objectToString = objectProto.toString;
  12404. /** Used to detect if a method is native. */
  12405. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  12406. /** Built-in value references. */
  12407. var Symbol = root.Symbol,
  12408. Uint8Array = root.Uint8Array,
  12409. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  12410. splice = arrayProto.splice;
  12411. /* Built-in method references for those with the same name as other `lodash` methods. */
  12412. var nativeKeys = overArg(Object.keys, Object);
  12413. /* Built-in method references that are verified to be native. */
  12414. var DataView = getNative(root, 'DataView'),
  12415. Map = getNative(root, 'Map'),
  12416. Promise = getNative(root, 'Promise'),
  12417. Set = getNative(root, 'Set'),
  12418. WeakMap = getNative(root, 'WeakMap'),
  12419. nativeCreate = getNative(Object, 'create');
  12420. /** Used to detect maps, sets, and weakmaps. */
  12421. var dataViewCtorString = toSource(DataView),
  12422. mapCtorString = toSource(Map),
  12423. promiseCtorString = toSource(Promise),
  12424. setCtorString = toSource(Set),
  12425. weakMapCtorString = toSource(WeakMap);
  12426. /** Used to convert symbols to primitives and strings. */
  12427. var symbolProto = Symbol ? Symbol.prototype : undefined,
  12428. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  12429. symbolToString = symbolProto ? symbolProto.toString : undefined;
  12430. /**
  12431. * Creates a hash object.
  12432. *
  12433. * @private
  12434. * @constructor
  12435. * @param {Array} [entries] The key-value pairs to cache.
  12436. */
  12437. function Hash(entries) {
  12438. var index = -1,
  12439. length = entries ? entries.length : 0;
  12440. this.clear();
  12441. while (++index < length) {
  12442. var entry = entries[index];
  12443. this.set(entry[0], entry[1]);
  12444. }
  12445. }
  12446. /**
  12447. * Removes all key-value entries from the hash.
  12448. *
  12449. * @private
  12450. * @name clear
  12451. * @memberOf Hash
  12452. */
  12453. function hashClear() {
  12454. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  12455. }
  12456. /**
  12457. * Removes `key` and its value from the hash.
  12458. *
  12459. * @private
  12460. * @name delete
  12461. * @memberOf Hash
  12462. * @param {Object} hash The hash to modify.
  12463. * @param {string} key The key of the value to remove.
  12464. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12465. */
  12466. function hashDelete(key) {
  12467. return this.has(key) && delete this.__data__[key];
  12468. }
  12469. /**
  12470. * Gets the hash value for `key`.
  12471. *
  12472. * @private
  12473. * @name get
  12474. * @memberOf Hash
  12475. * @param {string} key The key of the value to get.
  12476. * @returns {*} Returns the entry value.
  12477. */
  12478. function hashGet(key) {
  12479. var data = this.__data__;
  12480. if (nativeCreate) {
  12481. var result = data[key];
  12482. return result === HASH_UNDEFINED ? undefined : result;
  12483. }
  12484. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  12485. }
  12486. /**
  12487. * Checks if a hash value for `key` exists.
  12488. *
  12489. * @private
  12490. * @name has
  12491. * @memberOf Hash
  12492. * @param {string} key The key of the entry to check.
  12493. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12494. */
  12495. function hashHas(key) {
  12496. var data = this.__data__;
  12497. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  12498. }
  12499. /**
  12500. * Sets the hash `key` to `value`.
  12501. *
  12502. * @private
  12503. * @name set
  12504. * @memberOf Hash
  12505. * @param {string} key The key of the value to set.
  12506. * @param {*} value The value to set.
  12507. * @returns {Object} Returns the hash instance.
  12508. */
  12509. function hashSet(key, value) {
  12510. var data = this.__data__;
  12511. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  12512. return this;
  12513. } // Add methods to `Hash`.
  12514. Hash.prototype.clear = hashClear;
  12515. Hash.prototype['delete'] = hashDelete;
  12516. Hash.prototype.get = hashGet;
  12517. Hash.prototype.has = hashHas;
  12518. Hash.prototype.set = hashSet;
  12519. /**
  12520. * Creates an list cache object.
  12521. *
  12522. * @private
  12523. * @constructor
  12524. * @param {Array} [entries] The key-value pairs to cache.
  12525. */
  12526. function ListCache(entries) {
  12527. var index = -1,
  12528. length = entries ? entries.length : 0;
  12529. this.clear();
  12530. while (++index < length) {
  12531. var entry = entries[index];
  12532. this.set(entry[0], entry[1]);
  12533. }
  12534. }
  12535. /**
  12536. * Removes all key-value entries from the list cache.
  12537. *
  12538. * @private
  12539. * @name clear
  12540. * @memberOf ListCache
  12541. */
  12542. function listCacheClear() {
  12543. this.__data__ = [];
  12544. }
  12545. /**
  12546. * Removes `key` and its value from the list cache.
  12547. *
  12548. * @private
  12549. * @name delete
  12550. * @memberOf ListCache
  12551. * @param {string} key The key of the value to remove.
  12552. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12553. */
  12554. function listCacheDelete(key) {
  12555. var data = this.__data__,
  12556. index = assocIndexOf(data, key);
  12557. if (index < 0) {
  12558. return false;
  12559. }
  12560. var lastIndex = data.length - 1;
  12561. if (index == lastIndex) {
  12562. data.pop();
  12563. } else {
  12564. splice.call(data, index, 1);
  12565. }
  12566. return true;
  12567. }
  12568. /**
  12569. * Gets the list cache value for `key`.
  12570. *
  12571. * @private
  12572. * @name get
  12573. * @memberOf ListCache
  12574. * @param {string} key The key of the value to get.
  12575. * @returns {*} Returns the entry value.
  12576. */
  12577. function listCacheGet(key) {
  12578. var data = this.__data__,
  12579. index = assocIndexOf(data, key);
  12580. return index < 0 ? undefined : data[index][1];
  12581. }
  12582. /**
  12583. * Checks if a list cache value for `key` exists.
  12584. *
  12585. * @private
  12586. * @name has
  12587. * @memberOf ListCache
  12588. * @param {string} key The key of the entry to check.
  12589. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12590. */
  12591. function listCacheHas(key) {
  12592. return assocIndexOf(this.__data__, key) > -1;
  12593. }
  12594. /**
  12595. * Sets the list cache `key` to `value`.
  12596. *
  12597. * @private
  12598. * @name set
  12599. * @memberOf ListCache
  12600. * @param {string} key The key of the value to set.
  12601. * @param {*} value The value to set.
  12602. * @returns {Object} Returns the list cache instance.
  12603. */
  12604. function listCacheSet(key, value) {
  12605. var data = this.__data__,
  12606. index = assocIndexOf(data, key);
  12607. if (index < 0) {
  12608. data.push([key, value]);
  12609. } else {
  12610. data[index][1] = value;
  12611. }
  12612. return this;
  12613. } // Add methods to `ListCache`.
  12614. ListCache.prototype.clear = listCacheClear;
  12615. ListCache.prototype['delete'] = listCacheDelete;
  12616. ListCache.prototype.get = listCacheGet;
  12617. ListCache.prototype.has = listCacheHas;
  12618. ListCache.prototype.set = listCacheSet;
  12619. /**
  12620. * Creates a map cache object to store key-value pairs.
  12621. *
  12622. * @private
  12623. * @constructor
  12624. * @param {Array} [entries] The key-value pairs to cache.
  12625. */
  12626. function MapCache(entries) {
  12627. var index = -1,
  12628. length = entries ? entries.length : 0;
  12629. this.clear();
  12630. while (++index < length) {
  12631. var entry = entries[index];
  12632. this.set(entry[0], entry[1]);
  12633. }
  12634. }
  12635. /**
  12636. * Removes all key-value entries from the map.
  12637. *
  12638. * @private
  12639. * @name clear
  12640. * @memberOf MapCache
  12641. */
  12642. function mapCacheClear() {
  12643. this.__data__ = {
  12644. 'hash': new Hash(),
  12645. 'map': new (Map || ListCache)(),
  12646. 'string': new Hash()
  12647. };
  12648. }
  12649. /**
  12650. * Removes `key` and its value from the map.
  12651. *
  12652. * @private
  12653. * @name delete
  12654. * @memberOf MapCache
  12655. * @param {string} key The key of the value to remove.
  12656. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12657. */
  12658. function mapCacheDelete(key) {
  12659. return getMapData(this, key)['delete'](key);
  12660. }
  12661. /**
  12662. * Gets the map value for `key`.
  12663. *
  12664. * @private
  12665. * @name get
  12666. * @memberOf MapCache
  12667. * @param {string} key The key of the value to get.
  12668. * @returns {*} Returns the entry value.
  12669. */
  12670. function mapCacheGet(key) {
  12671. return getMapData(this, key).get(key);
  12672. }
  12673. /**
  12674. * Checks if a map value for `key` exists.
  12675. *
  12676. * @private
  12677. * @name has
  12678. * @memberOf MapCache
  12679. * @param {string} key The key of the entry to check.
  12680. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12681. */
  12682. function mapCacheHas(key) {
  12683. return getMapData(this, key).has(key);
  12684. }
  12685. /**
  12686. * Sets the map `key` to `value`.
  12687. *
  12688. * @private
  12689. * @name set
  12690. * @memberOf MapCache
  12691. * @param {string} key The key of the value to set.
  12692. * @param {*} value The value to set.
  12693. * @returns {Object} Returns the map cache instance.
  12694. */
  12695. function mapCacheSet(key, value) {
  12696. getMapData(this, key).set(key, value);
  12697. return this;
  12698. } // Add methods to `MapCache`.
  12699. MapCache.prototype.clear = mapCacheClear;
  12700. MapCache.prototype['delete'] = mapCacheDelete;
  12701. MapCache.prototype.get = mapCacheGet;
  12702. MapCache.prototype.has = mapCacheHas;
  12703. MapCache.prototype.set = mapCacheSet;
  12704. /**
  12705. *
  12706. * Creates an array cache object to store unique values.
  12707. *
  12708. * @private
  12709. * @constructor
  12710. * @param {Array} [values] The values to cache.
  12711. */
  12712. function SetCache(values) {
  12713. var index = -1,
  12714. length = values ? values.length : 0;
  12715. this.__data__ = new MapCache();
  12716. while (++index < length) {
  12717. this.add(values[index]);
  12718. }
  12719. }
  12720. /**
  12721. * Adds `value` to the array cache.
  12722. *
  12723. * @private
  12724. * @name add
  12725. * @memberOf SetCache
  12726. * @alias push
  12727. * @param {*} value The value to cache.
  12728. * @returns {Object} Returns the cache instance.
  12729. */
  12730. function setCacheAdd(value) {
  12731. this.__data__.set(value, HASH_UNDEFINED);
  12732. return this;
  12733. }
  12734. /**
  12735. * Checks if `value` is in the array cache.
  12736. *
  12737. * @private
  12738. * @name has
  12739. * @memberOf SetCache
  12740. * @param {*} value The value to search for.
  12741. * @returns {number} Returns `true` if `value` is found, else `false`.
  12742. */
  12743. function setCacheHas(value) {
  12744. return this.__data__.has(value);
  12745. } // Add methods to `SetCache`.
  12746. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  12747. SetCache.prototype.has = setCacheHas;
  12748. /**
  12749. * Creates a stack cache object to store key-value pairs.
  12750. *
  12751. * @private
  12752. * @constructor
  12753. * @param {Array} [entries] The key-value pairs to cache.
  12754. */
  12755. function Stack(entries) {
  12756. this.__data__ = new ListCache(entries);
  12757. }
  12758. /**
  12759. * Removes all key-value entries from the stack.
  12760. *
  12761. * @private
  12762. * @name clear
  12763. * @memberOf Stack
  12764. */
  12765. function stackClear() {
  12766. this.__data__ = new ListCache();
  12767. }
  12768. /**
  12769. * Removes `key` and its value from the stack.
  12770. *
  12771. * @private
  12772. * @name delete
  12773. * @memberOf Stack
  12774. * @param {string} key The key of the value to remove.
  12775. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  12776. */
  12777. function stackDelete(key) {
  12778. return this.__data__['delete'](key);
  12779. }
  12780. /**
  12781. * Gets the stack value for `key`.
  12782. *
  12783. * @private
  12784. * @name get
  12785. * @memberOf Stack
  12786. * @param {string} key The key of the value to get.
  12787. * @returns {*} Returns the entry value.
  12788. */
  12789. function stackGet(key) {
  12790. return this.__data__.get(key);
  12791. }
  12792. /**
  12793. * Checks if a stack value for `key` exists.
  12794. *
  12795. * @private
  12796. * @name has
  12797. * @memberOf Stack
  12798. * @param {string} key The key of the entry to check.
  12799. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  12800. */
  12801. function stackHas(key) {
  12802. return this.__data__.has(key);
  12803. }
  12804. /**
  12805. * Sets the stack `key` to `value`.
  12806. *
  12807. * @private
  12808. * @name set
  12809. * @memberOf Stack
  12810. * @param {string} key The key of the value to set.
  12811. * @param {*} value The value to set.
  12812. * @returns {Object} Returns the stack cache instance.
  12813. */
  12814. function stackSet(key, value) {
  12815. var cache = this.__data__;
  12816. if (cache instanceof ListCache) {
  12817. var pairs = cache.__data__;
  12818. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  12819. pairs.push([key, value]);
  12820. return this;
  12821. }
  12822. cache = this.__data__ = new MapCache(pairs);
  12823. }
  12824. cache.set(key, value);
  12825. return this;
  12826. } // Add methods to `Stack`.
  12827. Stack.prototype.clear = stackClear;
  12828. Stack.prototype['delete'] = stackDelete;
  12829. Stack.prototype.get = stackGet;
  12830. Stack.prototype.has = stackHas;
  12831. Stack.prototype.set = stackSet;
  12832. /**
  12833. * Creates an array of the enumerable property names of the array-like `value`.
  12834. *
  12835. * @private
  12836. * @param {*} value The value to query.
  12837. * @param {boolean} inherited Specify returning inherited property names.
  12838. * @returns {Array} Returns the array of property names.
  12839. */
  12840. function arrayLikeKeys(value, inherited) {
  12841. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  12842. // Safari 9 makes `arguments.length` enumerable in strict mode.
  12843. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  12844. var length = result.length,
  12845. skipIndexes = !!length;
  12846. for (var key in value) {
  12847. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  12848. result.push(key);
  12849. }
  12850. }
  12851. return result;
  12852. }
  12853. /**
  12854. * Gets the index at which the `key` is found in `array` of key-value pairs.
  12855. *
  12856. * @private
  12857. * @param {Array} array The array to inspect.
  12858. * @param {*} key The key to search for.
  12859. * @returns {number} Returns the index of the matched value, else `-1`.
  12860. */
  12861. function assocIndexOf(array, key) {
  12862. var length = array.length;
  12863. while (length--) {
  12864. if (eq(array[length][0], key)) {
  12865. return length;
  12866. }
  12867. }
  12868. return -1;
  12869. }
  12870. /**
  12871. * The base implementation of `_.get` without support for default values.
  12872. *
  12873. * @private
  12874. * @param {Object} object The object to query.
  12875. * @param {Array|string} path The path of the property to get.
  12876. * @returns {*} Returns the resolved value.
  12877. */
  12878. function baseGet(object, path$$1) {
  12879. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  12880. var index = 0,
  12881. length = path$$1.length;
  12882. while (object != null && index < length) {
  12883. object = object[toKey(path$$1[index++])];
  12884. }
  12885. return index && index == length ? object : undefined;
  12886. }
  12887. /**
  12888. * The base implementation of `getTag`.
  12889. *
  12890. * @private
  12891. * @param {*} value The value to query.
  12892. * @returns {string} Returns the `toStringTag`.
  12893. */
  12894. function baseGetTag(value) {
  12895. return objectToString.call(value);
  12896. }
  12897. /**
  12898. * The base implementation of `_.hasIn` without support for deep paths.
  12899. *
  12900. * @private
  12901. * @param {Object} [object] The object to query.
  12902. * @param {Array|string} key The key to check.
  12903. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  12904. */
  12905. function baseHasIn(object, key) {
  12906. return object != null && key in Object(object);
  12907. }
  12908. /**
  12909. * The base implementation of `_.isEqual` which supports partial comparisons
  12910. * and tracks traversed objects.
  12911. *
  12912. * @private
  12913. * @param {*} value The value to compare.
  12914. * @param {*} other The other value to compare.
  12915. * @param {Function} [customizer] The function to customize comparisons.
  12916. * @param {boolean} [bitmask] The bitmask of comparison flags.
  12917. * The bitmask may be composed of the following flags:
  12918. * 1 - Unordered comparison
  12919. * 2 - Partial comparison
  12920. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  12921. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  12922. */
  12923. function baseIsEqual(value, other, customizer, bitmask, stack) {
  12924. if (value === other) {
  12925. return true;
  12926. }
  12927. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  12928. return value !== value && other !== other;
  12929. }
  12930. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  12931. }
  12932. /**
  12933. * A specialized version of `baseIsEqual` for arrays and objects which performs
  12934. * deep comparisons and tracks traversed objects enabling objects with circular
  12935. * references to be compared.
  12936. *
  12937. * @private
  12938. * @param {Object} object The object to compare.
  12939. * @param {Object} other The other object to compare.
  12940. * @param {Function} equalFunc The function to determine equivalents of values.
  12941. * @param {Function} [customizer] The function to customize comparisons.
  12942. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  12943. * for more details.
  12944. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  12945. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  12946. */
  12947. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  12948. var objIsArr = isArray(object),
  12949. othIsArr = isArray(other),
  12950. objTag = arrayTag,
  12951. othTag = arrayTag;
  12952. if (!objIsArr) {
  12953. objTag = getTag(object);
  12954. objTag = objTag == argsTag ? objectTag : objTag;
  12955. }
  12956. if (!othIsArr) {
  12957. othTag = getTag(other);
  12958. othTag = othTag == argsTag ? objectTag : othTag;
  12959. }
  12960. var objIsObj = objTag == objectTag && !isHostObject(object),
  12961. othIsObj = othTag == objectTag && !isHostObject(other),
  12962. isSameTag = objTag == othTag;
  12963. if (isSameTag && !objIsObj) {
  12964. stack || (stack = new Stack());
  12965. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  12966. }
  12967. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  12968. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  12969. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  12970. if (objIsWrapped || othIsWrapped) {
  12971. var objUnwrapped = objIsWrapped ? object.value() : object,
  12972. othUnwrapped = othIsWrapped ? other.value() : other;
  12973. stack || (stack = new Stack());
  12974. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  12975. }
  12976. }
  12977. if (!isSameTag) {
  12978. return false;
  12979. }
  12980. stack || (stack = new Stack());
  12981. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  12982. }
  12983. /**
  12984. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  12985. *
  12986. * @private
  12987. * @param {Object} object The object to inspect.
  12988. * @param {Object} source The object of property values to match.
  12989. * @param {Array} matchData The property names, values, and compare flags to match.
  12990. * @param {Function} [customizer] The function to customize comparisons.
  12991. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  12992. */
  12993. function baseIsMatch(object, source, matchData, customizer) {
  12994. var index = matchData.length,
  12995. length = index,
  12996. noCustomizer = !customizer;
  12997. if (object == null) {
  12998. return !length;
  12999. }
  13000. object = Object(object);
  13001. while (index--) {
  13002. var data = matchData[index];
  13003. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  13004. return false;
  13005. }
  13006. }
  13007. while (++index < length) {
  13008. data = matchData[index];
  13009. var key = data[0],
  13010. objValue = object[key],
  13011. srcValue = data[1];
  13012. if (noCustomizer && data[2]) {
  13013. if (objValue === undefined && !(key in object)) {
  13014. return false;
  13015. }
  13016. } else {
  13017. var stack = new Stack();
  13018. if (customizer) {
  13019. var result = customizer(objValue, srcValue, key, object, source, stack);
  13020. }
  13021. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  13022. return false;
  13023. }
  13024. }
  13025. }
  13026. return true;
  13027. }
  13028. /**
  13029. * The base implementation of `_.isNative` without bad shim checks.
  13030. *
  13031. * @private
  13032. * @param {*} value The value to check.
  13033. * @returns {boolean} Returns `true` if `value` is a native function,
  13034. * else `false`.
  13035. */
  13036. function baseIsNative(value) {
  13037. if (!isObject(value) || isMasked(value)) {
  13038. return false;
  13039. }
  13040. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  13041. return pattern.test(toSource(value));
  13042. }
  13043. /**
  13044. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  13045. *
  13046. * @private
  13047. * @param {*} value The value to check.
  13048. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  13049. */
  13050. function baseIsTypedArray(value) {
  13051. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  13052. }
  13053. /**
  13054. * The base implementation of `_.iteratee`.
  13055. *
  13056. * @private
  13057. * @param {*} [value=_.identity] The value to convert to an iteratee.
  13058. * @returns {Function} Returns the iteratee.
  13059. */
  13060. function baseIteratee(value) {
  13061. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  13062. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  13063. if (typeof value == 'function') {
  13064. return value;
  13065. }
  13066. if (value == null) {
  13067. return identity;
  13068. }
  13069. if (typeof value == 'object') {
  13070. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  13071. }
  13072. return property(value);
  13073. }
  13074. /**
  13075. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  13076. *
  13077. * @private
  13078. * @param {Object} object The object to query.
  13079. * @returns {Array} Returns the array of property names.
  13080. */
  13081. function baseKeys(object) {
  13082. if (!isPrototype(object)) {
  13083. return nativeKeys(object);
  13084. }
  13085. var result = [];
  13086. for (var key in Object(object)) {
  13087. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  13088. result.push(key);
  13089. }
  13090. }
  13091. return result;
  13092. }
  13093. /**
  13094. * The base implementation of `_.matches` which doesn't clone `source`.
  13095. *
  13096. * @private
  13097. * @param {Object} source The object of property values to match.
  13098. * @returns {Function} Returns the new spec function.
  13099. */
  13100. function baseMatches(source) {
  13101. var matchData = getMatchData(source);
  13102. if (matchData.length == 1 && matchData[0][2]) {
  13103. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  13104. }
  13105. return function (object) {
  13106. return object === source || baseIsMatch(object, source, matchData);
  13107. };
  13108. }
  13109. /**
  13110. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  13111. *
  13112. * @private
  13113. * @param {string} path The path of the property to get.
  13114. * @param {*} srcValue The value to match.
  13115. * @returns {Function} Returns the new spec function.
  13116. */
  13117. function baseMatchesProperty(path$$1, srcValue) {
  13118. if (isKey(path$$1) && isStrictComparable(srcValue)) {
  13119. return matchesStrictComparable(toKey(path$$1), srcValue);
  13120. }
  13121. return function (object) {
  13122. var objValue = get(object, path$$1);
  13123. return objValue === undefined && objValue === srcValue ? hasIn(object, path$$1) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  13124. };
  13125. }
  13126. /**
  13127. * A specialized version of `baseProperty` which supports deep paths.
  13128. *
  13129. * @private
  13130. * @param {Array|string} path The path of the property to get.
  13131. * @returns {Function} Returns the new accessor function.
  13132. */
  13133. function basePropertyDeep(path$$1) {
  13134. return function (object) {
  13135. return baseGet(object, path$$1);
  13136. };
  13137. }
  13138. /**
  13139. * The base implementation of `_.toString` which doesn't convert nullish
  13140. * values to empty strings.
  13141. *
  13142. * @private
  13143. * @param {*} value The value to process.
  13144. * @returns {string} Returns the string.
  13145. */
  13146. function baseToString(value) {
  13147. // Exit early for strings to avoid a performance hit in some environments.
  13148. if (typeof value == 'string') {
  13149. return value;
  13150. }
  13151. if (isSymbol(value)) {
  13152. return symbolToString ? symbolToString.call(value) : '';
  13153. }
  13154. var result = value + '';
  13155. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  13156. }
  13157. /**
  13158. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  13159. *
  13160. * @private
  13161. * @param {Array} array The array to inspect.
  13162. * @param {Function} [iteratee] The iteratee invoked per element.
  13163. * @param {Function} [comparator] The comparator invoked per element.
  13164. * @returns {Array} Returns the new duplicate free array.
  13165. */
  13166. function baseUniq(array, iteratee, comparator) {
  13167. var index = -1,
  13168. includes = arrayIncludes,
  13169. length = array.length,
  13170. isCommon = true,
  13171. result = [],
  13172. seen = result;
  13173. if (comparator) {
  13174. isCommon = false;
  13175. includes = arrayIncludesWith;
  13176. } else if (length >= LARGE_ARRAY_SIZE) {
  13177. var set = iteratee ? null : createSet(array);
  13178. if (set) {
  13179. return setToArray(set);
  13180. }
  13181. isCommon = false;
  13182. includes = cacheHas;
  13183. seen = new SetCache();
  13184. } else {
  13185. seen = iteratee ? [] : result;
  13186. }
  13187. outer: while (++index < length) {
  13188. var value = array[index],
  13189. computed = iteratee ? iteratee(value) : value;
  13190. value = comparator || value !== 0 ? value : 0;
  13191. if (isCommon && computed === computed) {
  13192. var seenIndex = seen.length;
  13193. while (seenIndex--) {
  13194. if (seen[seenIndex] === computed) {
  13195. continue outer;
  13196. }
  13197. }
  13198. if (iteratee) {
  13199. seen.push(computed);
  13200. }
  13201. result.push(value);
  13202. } else if (!includes(seen, computed, comparator)) {
  13203. if (seen !== result) {
  13204. seen.push(computed);
  13205. }
  13206. result.push(value);
  13207. }
  13208. }
  13209. return result;
  13210. }
  13211. /**
  13212. * Casts `value` to a path array if it's not one.
  13213. *
  13214. * @private
  13215. * @param {*} value The value to inspect.
  13216. * @returns {Array} Returns the cast property path array.
  13217. */
  13218. function castPath(value) {
  13219. return isArray(value) ? value : stringToPath(value);
  13220. }
  13221. /**
  13222. * Creates a set object of `values`.
  13223. *
  13224. * @private
  13225. * @param {Array} values The values to add to the set.
  13226. * @returns {Object} Returns the new set.
  13227. */
  13228. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  13229. return new Set(values);
  13230. };
  13231. /**
  13232. * A specialized version of `baseIsEqualDeep` for arrays with support for
  13233. * partial deep comparisons.
  13234. *
  13235. * @private
  13236. * @param {Array} array The array to compare.
  13237. * @param {Array} other The other array to compare.
  13238. * @param {Function} equalFunc The function to determine equivalents of values.
  13239. * @param {Function} customizer The function to customize comparisons.
  13240. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  13241. * for more details.
  13242. * @param {Object} stack Tracks traversed `array` and `other` objects.
  13243. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  13244. */
  13245. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  13246. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  13247. arrLength = array.length,
  13248. othLength = other.length;
  13249. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  13250. return false;
  13251. } // Assume cyclic values are equal.
  13252. var stacked = stack.get(array);
  13253. if (stacked && stack.get(other)) {
  13254. return stacked == other;
  13255. }
  13256. var index = -1,
  13257. result = true,
  13258. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  13259. stack.set(array, other);
  13260. stack.set(other, array); // Ignore non-index properties.
  13261. while (++index < arrLength) {
  13262. var arrValue = array[index],
  13263. othValue = other[index];
  13264. if (customizer) {
  13265. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  13266. }
  13267. if (compared !== undefined) {
  13268. if (compared) {
  13269. continue;
  13270. }
  13271. result = false;
  13272. break;
  13273. } // Recursively compare arrays (susceptible to call stack limits).
  13274. if (seen) {
  13275. if (!arraySome(other, function (othValue, othIndex) {
  13276. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  13277. return seen.add(othIndex);
  13278. }
  13279. })) {
  13280. result = false;
  13281. break;
  13282. }
  13283. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  13284. result = false;
  13285. break;
  13286. }
  13287. }
  13288. stack['delete'](array);
  13289. stack['delete'](other);
  13290. return result;
  13291. }
  13292. /**
  13293. * A specialized version of `baseIsEqualDeep` for comparing objects of
  13294. * the same `toStringTag`.
  13295. *
  13296. * **Note:** This function only supports comparing values with tags of
  13297. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  13298. *
  13299. * @private
  13300. * @param {Object} object The object to compare.
  13301. * @param {Object} other The other object to compare.
  13302. * @param {string} tag The `toStringTag` of the objects to compare.
  13303. * @param {Function} equalFunc The function to determine equivalents of values.
  13304. * @param {Function} customizer The function to customize comparisons.
  13305. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  13306. * for more details.
  13307. * @param {Object} stack Tracks traversed `object` and `other` objects.
  13308. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  13309. */
  13310. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  13311. switch (tag) {
  13312. case dataViewTag:
  13313. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  13314. return false;
  13315. }
  13316. object = object.buffer;
  13317. other = other.buffer;
  13318. case arrayBufferTag:
  13319. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  13320. return false;
  13321. }
  13322. return true;
  13323. case boolTag:
  13324. case dateTag:
  13325. case numberTag:
  13326. // Coerce booleans to `1` or `0` and dates to milliseconds.
  13327. // Invalid dates are coerced to `NaN`.
  13328. return eq(+object, +other);
  13329. case errorTag:
  13330. return object.name == other.name && object.message == other.message;
  13331. case regexpTag:
  13332. case stringTag:
  13333. // Coerce regexes to strings and treat strings, primitives and objects,
  13334. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  13335. // for more details.
  13336. return object == other + '';
  13337. case mapTag:
  13338. var convert = mapToArray;
  13339. case setTag:
  13340. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  13341. convert || (convert = setToArray);
  13342. if (object.size != other.size && !isPartial) {
  13343. return false;
  13344. } // Assume cyclic values are equal.
  13345. var stacked = stack.get(object);
  13346. if (stacked) {
  13347. return stacked == other;
  13348. }
  13349. bitmask |= UNORDERED_COMPARE_FLAG; // Recursively compare objects (susceptible to call stack limits).
  13350. stack.set(object, other);
  13351. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  13352. stack['delete'](object);
  13353. return result;
  13354. case symbolTag:
  13355. if (symbolValueOf) {
  13356. return symbolValueOf.call(object) == symbolValueOf.call(other);
  13357. }
  13358. }
  13359. return false;
  13360. }
  13361. /**
  13362. * A specialized version of `baseIsEqualDeep` for objects with support for
  13363. * partial deep comparisons.
  13364. *
  13365. * @private
  13366. * @param {Object} object The object to compare.
  13367. * @param {Object} other The other object to compare.
  13368. * @param {Function} equalFunc The function to determine equivalents of values.
  13369. * @param {Function} customizer The function to customize comparisons.
  13370. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  13371. * for more details.
  13372. * @param {Object} stack Tracks traversed `object` and `other` objects.
  13373. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  13374. */
  13375. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  13376. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  13377. objProps = keys(object),
  13378. objLength = objProps.length,
  13379. othProps = keys(other),
  13380. othLength = othProps.length;
  13381. if (objLength != othLength && !isPartial) {
  13382. return false;
  13383. }
  13384. var index = objLength;
  13385. while (index--) {
  13386. var key = objProps[index];
  13387. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  13388. return false;
  13389. }
  13390. } // Assume cyclic values are equal.
  13391. var stacked = stack.get(object);
  13392. if (stacked && stack.get(other)) {
  13393. return stacked == other;
  13394. }
  13395. var result = true;
  13396. stack.set(object, other);
  13397. stack.set(other, object);
  13398. var skipCtor = isPartial;
  13399. while (++index < objLength) {
  13400. key = objProps[index];
  13401. var objValue = object[key],
  13402. othValue = other[key];
  13403. if (customizer) {
  13404. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  13405. } // Recursively compare objects (susceptible to call stack limits).
  13406. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  13407. result = false;
  13408. break;
  13409. }
  13410. skipCtor || (skipCtor = key == 'constructor');
  13411. }
  13412. if (result && !skipCtor) {
  13413. var objCtor = object.constructor,
  13414. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  13415. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  13416. result = false;
  13417. }
  13418. }
  13419. stack['delete'](object);
  13420. stack['delete'](other);
  13421. return result;
  13422. }
  13423. /**
  13424. * Gets the data for `map`.
  13425. *
  13426. * @private
  13427. * @param {Object} map The map to query.
  13428. * @param {string} key The reference key.
  13429. * @returns {*} Returns the map data.
  13430. */
  13431. function getMapData(map, key) {
  13432. var data = map.__data__;
  13433. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  13434. }
  13435. /**
  13436. * Gets the property names, values, and compare flags of `object`.
  13437. *
  13438. * @private
  13439. * @param {Object} object The object to query.
  13440. * @returns {Array} Returns the match data of `object`.
  13441. */
  13442. function getMatchData(object) {
  13443. var result = keys(object),
  13444. length = result.length;
  13445. while (length--) {
  13446. var key = result[length],
  13447. value = object[key];
  13448. result[length] = [key, value, isStrictComparable(value)];
  13449. }
  13450. return result;
  13451. }
  13452. /**
  13453. * Gets the native function at `key` of `object`.
  13454. *
  13455. * @private
  13456. * @param {Object} object The object to query.
  13457. * @param {string} key The key of the method to get.
  13458. * @returns {*} Returns the function if it's native, else `undefined`.
  13459. */
  13460. function getNative(object, key) {
  13461. var value = getValue(object, key);
  13462. return baseIsNative(value) ? value : undefined;
  13463. }
  13464. /**
  13465. * Gets the `toStringTag` of `value`.
  13466. *
  13467. * @private
  13468. * @param {*} value The value to query.
  13469. * @returns {string} Returns the `toStringTag`.
  13470. */
  13471. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11,
  13472. // for data views in Edge < 14, and promises in Node.js.
  13473. 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) {
  13474. getTag = function getTag(value) {
  13475. var result = objectToString.call(value),
  13476. Ctor = result == objectTag ? value.constructor : undefined,
  13477. ctorString = Ctor ? toSource(Ctor) : undefined;
  13478. if (ctorString) {
  13479. switch (ctorString) {
  13480. case dataViewCtorString:
  13481. return dataViewTag;
  13482. case mapCtorString:
  13483. return mapTag;
  13484. case promiseCtorString:
  13485. return promiseTag;
  13486. case setCtorString:
  13487. return setTag;
  13488. case weakMapCtorString:
  13489. return weakMapTag;
  13490. }
  13491. }
  13492. return result;
  13493. };
  13494. }
  13495. /**
  13496. * Checks if `path` exists on `object`.
  13497. *
  13498. * @private
  13499. * @param {Object} object The object to query.
  13500. * @param {Array|string} path The path to check.
  13501. * @param {Function} hasFunc The function to check properties.
  13502. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13503. */
  13504. function hasPath(object, path$$1, hasFunc) {
  13505. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  13506. var result,
  13507. index = -1,
  13508. length = path$$1.length;
  13509. while (++index < length) {
  13510. var key = toKey(path$$1[index]);
  13511. if (!(result = object != null && hasFunc(object, key))) {
  13512. break;
  13513. }
  13514. object = object[key];
  13515. }
  13516. if (result) {
  13517. return result;
  13518. }
  13519. var length = object ? object.length : 0;
  13520. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  13521. }
  13522. /**
  13523. * Checks if `value` is a valid array-like index.
  13524. *
  13525. * @private
  13526. * @param {*} value The value to check.
  13527. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  13528. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  13529. */
  13530. function isIndex(value, length) {
  13531. length = length == null ? MAX_SAFE_INTEGER : length;
  13532. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  13533. }
  13534. /**
  13535. * Checks if `value` is a property name and not a property path.
  13536. *
  13537. * @private
  13538. * @param {*} value The value to check.
  13539. * @param {Object} [object] The object to query keys on.
  13540. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  13541. */
  13542. function isKey(value, object) {
  13543. if (isArray(value)) {
  13544. return false;
  13545. }
  13546. var type = typeof value;
  13547. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  13548. return true;
  13549. }
  13550. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  13551. }
  13552. /**
  13553. * Checks if `value` is suitable for use as unique object key.
  13554. *
  13555. * @private
  13556. * @param {*} value The value to check.
  13557. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  13558. */
  13559. function isKeyable(value) {
  13560. var type = typeof value;
  13561. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  13562. }
  13563. /**
  13564. * Checks if `func` has its source masked.
  13565. *
  13566. * @private
  13567. * @param {Function} func The function to check.
  13568. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  13569. */
  13570. function isMasked(func) {
  13571. return !!maskSrcKey && maskSrcKey in func;
  13572. }
  13573. /**
  13574. * Checks if `value` is likely a prototype object.
  13575. *
  13576. * @private
  13577. * @param {*} value The value to check.
  13578. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  13579. */
  13580. function isPrototype(value) {
  13581. var Ctor = value && value.constructor,
  13582. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  13583. return value === proto;
  13584. }
  13585. /**
  13586. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  13587. *
  13588. * @private
  13589. * @param {*} value The value to check.
  13590. * @returns {boolean} Returns `true` if `value` if suitable for strict
  13591. * equality comparisons, else `false`.
  13592. */
  13593. function isStrictComparable(value) {
  13594. return value === value && !isObject(value);
  13595. }
  13596. /**
  13597. * A specialized version of `matchesProperty` for source values suitable
  13598. * for strict equality comparisons, i.e. `===`.
  13599. *
  13600. * @private
  13601. * @param {string} key The key of the property to get.
  13602. * @param {*} srcValue The value to match.
  13603. * @returns {Function} Returns the new spec function.
  13604. */
  13605. function matchesStrictComparable(key, srcValue) {
  13606. return function (object) {
  13607. if (object == null) {
  13608. return false;
  13609. }
  13610. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  13611. };
  13612. }
  13613. /**
  13614. * Converts `string` to a property path array.
  13615. *
  13616. * @private
  13617. * @param {string} string The string to convert.
  13618. * @returns {Array} Returns the property path array.
  13619. */
  13620. var stringToPath = memoize(function (string) {
  13621. string = toString(string);
  13622. var result = [];
  13623. if (reLeadingDot.test(string)) {
  13624. result.push('');
  13625. }
  13626. string.replace(rePropName, function (match, number, quote, string) {
  13627. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  13628. });
  13629. return result;
  13630. });
  13631. /**
  13632. * Converts `value` to a string key if it's not a string or symbol.
  13633. *
  13634. * @private
  13635. * @param {*} value The value to inspect.
  13636. * @returns {string|symbol} Returns the key.
  13637. */
  13638. function toKey(value) {
  13639. if (typeof value == 'string' || isSymbol(value)) {
  13640. return value;
  13641. }
  13642. var result = value + '';
  13643. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  13644. }
  13645. /**
  13646. * Converts `func` to its source code.
  13647. *
  13648. * @private
  13649. * @param {Function} func The function to process.
  13650. * @returns {string} Returns the source code.
  13651. */
  13652. function toSource(func) {
  13653. if (func != null) {
  13654. try {
  13655. return funcToString.call(func);
  13656. } catch (e) {}
  13657. try {
  13658. return func + '';
  13659. } catch (e) {}
  13660. }
  13661. return '';
  13662. }
  13663. /**
  13664. * This method is like `_.uniq` except that it accepts `iteratee` which is
  13665. * invoked for each element in `array` to generate the criterion by which
  13666. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  13667. *
  13668. * @static
  13669. * @memberOf _
  13670. * @since 4.0.0
  13671. * @category Array
  13672. * @param {Array} array The array to inspect.
  13673. * @param {Function} [iteratee=_.identity]
  13674. * The iteratee invoked per element.
  13675. * @returns {Array} Returns the new duplicate free array.
  13676. * @example
  13677. *
  13678. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  13679. * // => [2.1, 1.2]
  13680. *
  13681. * // The `_.property` iteratee shorthand.
  13682. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  13683. * // => [{ 'x': 1 }, { 'x': 2 }]
  13684. */
  13685. function uniqBy(array, iteratee) {
  13686. return array && array.length ? baseUniq(array, baseIteratee(iteratee, 2)) : [];
  13687. }
  13688. /**
  13689. * Creates a function that memoizes the result of `func`. If `resolver` is
  13690. * provided, it determines the cache key for storing the result based on the
  13691. * arguments provided to the memoized function. By default, the first argument
  13692. * provided to the memoized function is used as the map cache key. The `func`
  13693. * is invoked with the `this` binding of the memoized function.
  13694. *
  13695. * **Note:** The cache is exposed as the `cache` property on the memoized
  13696. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  13697. * constructor with one whose instances implement the
  13698. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  13699. * method interface of `delete`, `get`, `has`, and `set`.
  13700. *
  13701. * @static
  13702. * @memberOf _
  13703. * @since 0.1.0
  13704. * @category Function
  13705. * @param {Function} func The function to have its output memoized.
  13706. * @param {Function} [resolver] The function to resolve the cache key.
  13707. * @returns {Function} Returns the new memoized function.
  13708. * @example
  13709. *
  13710. * var object = { 'a': 1, 'b': 2 };
  13711. * var other = { 'c': 3, 'd': 4 };
  13712. *
  13713. * var values = _.memoize(_.values);
  13714. * values(object);
  13715. * // => [1, 2]
  13716. *
  13717. * values(other);
  13718. * // => [3, 4]
  13719. *
  13720. * object.a = 2;
  13721. * values(object);
  13722. * // => [1, 2]
  13723. *
  13724. * // Modify the result cache.
  13725. * values.cache.set(object, ['a', 'b']);
  13726. * values(object);
  13727. * // => ['a', 'b']
  13728. *
  13729. * // Replace `_.memoize.Cache`.
  13730. * _.memoize.Cache = WeakMap;
  13731. */
  13732. function memoize(func, resolver) {
  13733. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  13734. throw new TypeError(FUNC_ERROR_TEXT);
  13735. }
  13736. var memoized = function memoized() {
  13737. var args = arguments,
  13738. key = resolver ? resolver.apply(this, args) : args[0],
  13739. cache = memoized.cache;
  13740. if (cache.has(key)) {
  13741. return cache.get(key);
  13742. }
  13743. var result = func.apply(this, args);
  13744. memoized.cache = cache.set(key, result);
  13745. return result;
  13746. };
  13747. memoized.cache = new (memoize.Cache || MapCache)();
  13748. return memoized;
  13749. } // Assign cache to `_.memoize`.
  13750. memoize.Cache = MapCache;
  13751. /**
  13752. * Performs a
  13753. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  13754. * comparison between two values to determine if they are equivalent.
  13755. *
  13756. * @static
  13757. * @memberOf _
  13758. * @since 4.0.0
  13759. * @category Lang
  13760. * @param {*} value The value to compare.
  13761. * @param {*} other The other value to compare.
  13762. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  13763. * @example
  13764. *
  13765. * var object = { 'a': 1 };
  13766. * var other = { 'a': 1 };
  13767. *
  13768. * _.eq(object, object);
  13769. * // => true
  13770. *
  13771. * _.eq(object, other);
  13772. * // => false
  13773. *
  13774. * _.eq('a', 'a');
  13775. * // => true
  13776. *
  13777. * _.eq('a', Object('a'));
  13778. * // => false
  13779. *
  13780. * _.eq(NaN, NaN);
  13781. * // => true
  13782. */
  13783. function eq(value, other) {
  13784. return value === other || value !== value && other !== other;
  13785. }
  13786. /**
  13787. * Checks if `value` is likely an `arguments` object.
  13788. *
  13789. * @static
  13790. * @memberOf _
  13791. * @since 0.1.0
  13792. * @category Lang
  13793. * @param {*} value The value to check.
  13794. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  13795. * else `false`.
  13796. * @example
  13797. *
  13798. * _.isArguments(function() { return arguments; }());
  13799. * // => true
  13800. *
  13801. * _.isArguments([1, 2, 3]);
  13802. * // => false
  13803. */
  13804. function isArguments(value) {
  13805. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  13806. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  13807. }
  13808. /**
  13809. * Checks if `value` is classified as an `Array` object.
  13810. *
  13811. * @static
  13812. * @memberOf _
  13813. * @since 0.1.0
  13814. * @category Lang
  13815. * @param {*} value The value to check.
  13816. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  13817. * @example
  13818. *
  13819. * _.isArray([1, 2, 3]);
  13820. * // => true
  13821. *
  13822. * _.isArray(document.body.children);
  13823. * // => false
  13824. *
  13825. * _.isArray('abc');
  13826. * // => false
  13827. *
  13828. * _.isArray(_.noop);
  13829. * // => false
  13830. */
  13831. var isArray = Array.isArray;
  13832. /**
  13833. * Checks if `value` is array-like. A value is considered array-like if it's
  13834. * not a function and has a `value.length` that's an integer greater than or
  13835. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  13836. *
  13837. * @static
  13838. * @memberOf _
  13839. * @since 4.0.0
  13840. * @category Lang
  13841. * @param {*} value The value to check.
  13842. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  13843. * @example
  13844. *
  13845. * _.isArrayLike([1, 2, 3]);
  13846. * // => true
  13847. *
  13848. * _.isArrayLike(document.body.children);
  13849. * // => true
  13850. *
  13851. * _.isArrayLike('abc');
  13852. * // => true
  13853. *
  13854. * _.isArrayLike(_.noop);
  13855. * // => false
  13856. */
  13857. function isArrayLike(value) {
  13858. return value != null && isLength(value.length) && !isFunction(value);
  13859. }
  13860. /**
  13861. * This method is like `_.isArrayLike` except that it also checks if `value`
  13862. * is an object.
  13863. *
  13864. * @static
  13865. * @memberOf _
  13866. * @since 4.0.0
  13867. * @category Lang
  13868. * @param {*} value The value to check.
  13869. * @returns {boolean} Returns `true` if `value` is an array-like object,
  13870. * else `false`.
  13871. * @example
  13872. *
  13873. * _.isArrayLikeObject([1, 2, 3]);
  13874. * // => true
  13875. *
  13876. * _.isArrayLikeObject(document.body.children);
  13877. * // => true
  13878. *
  13879. * _.isArrayLikeObject('abc');
  13880. * // => false
  13881. *
  13882. * _.isArrayLikeObject(_.noop);
  13883. * // => false
  13884. */
  13885. function isArrayLikeObject(value) {
  13886. return isObjectLike(value) && isArrayLike(value);
  13887. }
  13888. /**
  13889. * Checks if `value` is classified as a `Function` object.
  13890. *
  13891. * @static
  13892. * @memberOf _
  13893. * @since 0.1.0
  13894. * @category Lang
  13895. * @param {*} value The value to check.
  13896. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  13897. * @example
  13898. *
  13899. * _.isFunction(_);
  13900. * // => true
  13901. *
  13902. * _.isFunction(/abc/);
  13903. * // => false
  13904. */
  13905. function isFunction(value) {
  13906. // The use of `Object#toString` avoids issues with the `typeof` operator
  13907. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  13908. var tag = isObject(value) ? objectToString.call(value) : '';
  13909. return tag == funcTag || tag == genTag;
  13910. }
  13911. /**
  13912. * Checks if `value` is a valid array-like length.
  13913. *
  13914. * **Note:** This method is loosely based on
  13915. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  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 a valid length, else `false`.
  13923. * @example
  13924. *
  13925. * _.isLength(3);
  13926. * // => true
  13927. *
  13928. * _.isLength(Number.MIN_VALUE);
  13929. * // => false
  13930. *
  13931. * _.isLength(Infinity);
  13932. * // => false
  13933. *
  13934. * _.isLength('3');
  13935. * // => false
  13936. */
  13937. function isLength(value) {
  13938. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  13939. }
  13940. /**
  13941. * Checks if `value` is the
  13942. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  13943. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  13944. *
  13945. * @static
  13946. * @memberOf _
  13947. * @since 0.1.0
  13948. * @category Lang
  13949. * @param {*} value The value to check.
  13950. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  13951. * @example
  13952. *
  13953. * _.isObject({});
  13954. * // => true
  13955. *
  13956. * _.isObject([1, 2, 3]);
  13957. * // => true
  13958. *
  13959. * _.isObject(_.noop);
  13960. * // => true
  13961. *
  13962. * _.isObject(null);
  13963. * // => false
  13964. */
  13965. function isObject(value) {
  13966. var type = typeof value;
  13967. return !!value && (type == 'object' || type == 'function');
  13968. }
  13969. /**
  13970. * Checks if `value` is object-like. A value is object-like if it's not `null`
  13971. * and has a `typeof` result of "object".
  13972. *
  13973. * @static
  13974. * @memberOf _
  13975. * @since 4.0.0
  13976. * @category Lang
  13977. * @param {*} value The value to check.
  13978. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  13979. * @example
  13980. *
  13981. * _.isObjectLike({});
  13982. * // => true
  13983. *
  13984. * _.isObjectLike([1, 2, 3]);
  13985. * // => true
  13986. *
  13987. * _.isObjectLike(_.noop);
  13988. * // => false
  13989. *
  13990. * _.isObjectLike(null);
  13991. * // => false
  13992. */
  13993. function isObjectLike(value) {
  13994. return !!value && typeof value == 'object';
  13995. }
  13996. /**
  13997. * Checks if `value` is classified as a `Symbol` primitive or object.
  13998. *
  13999. * @static
  14000. * @memberOf _
  14001. * @since 4.0.0
  14002. * @category Lang
  14003. * @param {*} value The value to check.
  14004. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  14005. * @example
  14006. *
  14007. * _.isSymbol(Symbol.iterator);
  14008. * // => true
  14009. *
  14010. * _.isSymbol('abc');
  14011. * // => false
  14012. */
  14013. function isSymbol(value) {
  14014. return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  14015. }
  14016. /**
  14017. * Checks if `value` is classified as a typed array.
  14018. *
  14019. * @static
  14020. * @memberOf _
  14021. * @since 3.0.0
  14022. * @category Lang
  14023. * @param {*} value The value to check.
  14024. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  14025. * @example
  14026. *
  14027. * _.isTypedArray(new Uint8Array);
  14028. * // => true
  14029. *
  14030. * _.isTypedArray([]);
  14031. * // => false
  14032. */
  14033. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  14034. /**
  14035. * Converts `value` to a string. An empty string is returned for `null`
  14036. * and `undefined` values. The sign of `-0` is preserved.
  14037. *
  14038. * @static
  14039. * @memberOf _
  14040. * @since 4.0.0
  14041. * @category Lang
  14042. * @param {*} value The value to process.
  14043. * @returns {string} Returns the string.
  14044. * @example
  14045. *
  14046. * _.toString(null);
  14047. * // => ''
  14048. *
  14049. * _.toString(-0);
  14050. * // => '-0'
  14051. *
  14052. * _.toString([1, 2, 3]);
  14053. * // => '1,2,3'
  14054. */
  14055. function toString(value) {
  14056. return value == null ? '' : baseToString(value);
  14057. }
  14058. /**
  14059. * Gets the value at `path` of `object`. If the resolved value is
  14060. * `undefined`, the `defaultValue` is returned in its place.
  14061. *
  14062. * @static
  14063. * @memberOf _
  14064. * @since 3.7.0
  14065. * @category Object
  14066. * @param {Object} object The object to query.
  14067. * @param {Array|string} path The path of the property to get.
  14068. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  14069. * @returns {*} Returns the resolved value.
  14070. * @example
  14071. *
  14072. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  14073. *
  14074. * _.get(object, 'a[0].b.c');
  14075. * // => 3
  14076. *
  14077. * _.get(object, ['a', '0', 'b', 'c']);
  14078. * // => 3
  14079. *
  14080. * _.get(object, 'a.b.c', 'default');
  14081. * // => 'default'
  14082. */
  14083. function get(object, path$$1, defaultValue) {
  14084. var result = object == null ? undefined : baseGet(object, path$$1);
  14085. return result === undefined ? defaultValue : result;
  14086. }
  14087. /**
  14088. * Checks if `path` is a direct or inherited property of `object`.
  14089. *
  14090. * @static
  14091. * @memberOf _
  14092. * @since 4.0.0
  14093. * @category Object
  14094. * @param {Object} object The object to query.
  14095. * @param {Array|string} path The path to check.
  14096. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  14097. * @example
  14098. *
  14099. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  14100. *
  14101. * _.hasIn(object, 'a');
  14102. * // => true
  14103. *
  14104. * _.hasIn(object, 'a.b');
  14105. * // => true
  14106. *
  14107. * _.hasIn(object, ['a', 'b']);
  14108. * // => true
  14109. *
  14110. * _.hasIn(object, 'b');
  14111. * // => false
  14112. */
  14113. function hasIn(object, path$$1) {
  14114. return object != null && hasPath(object, path$$1, baseHasIn);
  14115. }
  14116. /**
  14117. * Creates an array of the own enumerable property names of `object`.
  14118. *
  14119. * **Note:** Non-object values are coerced to objects. See the
  14120. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  14121. * for more details.
  14122. *
  14123. * @static
  14124. * @since 0.1.0
  14125. * @memberOf _
  14126. * @category Object
  14127. * @param {Object} object The object to query.
  14128. * @returns {Array} Returns the array of property names.
  14129. * @example
  14130. *
  14131. * function Foo() {
  14132. * this.a = 1;
  14133. * this.b = 2;
  14134. * }
  14135. *
  14136. * Foo.prototype.c = 3;
  14137. *
  14138. * _.keys(new Foo);
  14139. * // => ['a', 'b'] (iteration order is not guaranteed)
  14140. *
  14141. * _.keys('hi');
  14142. * // => ['0', '1']
  14143. */
  14144. function keys(object) {
  14145. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  14146. }
  14147. /**
  14148. * This method returns the first argument it receives.
  14149. *
  14150. * @static
  14151. * @since 0.1.0
  14152. * @memberOf _
  14153. * @category Util
  14154. * @param {*} value Any value.
  14155. * @returns {*} Returns `value`.
  14156. * @example
  14157. *
  14158. * var object = { 'a': 1 };
  14159. *
  14160. * console.log(_.identity(object) === object);
  14161. * // => true
  14162. */
  14163. function identity(value) {
  14164. return value;
  14165. }
  14166. /**
  14167. * This method returns `undefined`.
  14168. *
  14169. * @static
  14170. * @memberOf _
  14171. * @since 2.3.0
  14172. * @category Util
  14173. * @example
  14174. *
  14175. * _.times(2, _.noop);
  14176. * // => [undefined, undefined]
  14177. */
  14178. function noop() {} // No operation performed.
  14179. /**
  14180. * Creates a function that returns the value at `path` of a given object.
  14181. *
  14182. * @static
  14183. * @memberOf _
  14184. * @since 2.4.0
  14185. * @category Util
  14186. * @param {Array|string} path The path of the property to get.
  14187. * @returns {Function} Returns the new accessor function.
  14188. * @example
  14189. *
  14190. * var objects = [
  14191. * { 'a': { 'b': 2 } },
  14192. * { 'a': { 'b': 1 } }
  14193. * ];
  14194. *
  14195. * _.map(objects, _.property('a.b'));
  14196. * // => [2, 1]
  14197. *
  14198. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14199. * // => [1, 2]
  14200. */
  14201. function property(path$$1) {
  14202. return isKey(path$$1) ? baseProperty(toKey(path$$1)) : basePropertyDeep(path$$1);
  14203. }
  14204. module.exports = uniqBy;
  14205. });
  14206. var PENDING = 'pending';
  14207. var SETTLED = 'settled';
  14208. var FULFILLED = 'fulfilled';
  14209. var REJECTED = 'rejected';
  14210. var NOOP = function NOOP() {};
  14211. var isNode = typeof commonjsGlobal !== 'undefined' && typeof commonjsGlobal.process !== 'undefined' && typeof commonjsGlobal.process.emit === 'function';
  14212. var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
  14213. var asyncQueue = [];
  14214. var asyncTimer;
  14215. function asyncFlush() {
  14216. // run promise callbacks
  14217. for (var i = 0; i < asyncQueue.length; i++) {
  14218. asyncQueue[i][0](asyncQueue[i][1]);
  14219. } // reset async asyncQueue
  14220. asyncQueue = [];
  14221. asyncTimer = false;
  14222. }
  14223. function asyncCall(callback, arg) {
  14224. asyncQueue.push([callback, arg]);
  14225. if (!asyncTimer) {
  14226. asyncTimer = true;
  14227. asyncSetTimer(asyncFlush, 0);
  14228. }
  14229. }
  14230. function invokeResolver(resolver, promise) {
  14231. function resolvePromise(value) {
  14232. resolve(promise, value);
  14233. }
  14234. function rejectPromise(reason) {
  14235. reject(promise, reason);
  14236. }
  14237. try {
  14238. resolver(resolvePromise, rejectPromise);
  14239. } catch (e) {
  14240. rejectPromise(e);
  14241. }
  14242. }
  14243. function invokeCallback(subscriber) {
  14244. var owner = subscriber.owner;
  14245. var settled = owner._state;
  14246. var value = owner._data;
  14247. var callback = subscriber[settled];
  14248. var promise = subscriber.then;
  14249. if (typeof callback === 'function') {
  14250. settled = FULFILLED;
  14251. try {
  14252. value = callback(value);
  14253. } catch (e) {
  14254. reject(promise, e);
  14255. }
  14256. }
  14257. if (!handleThenable(promise, value)) {
  14258. if (settled === FULFILLED) {
  14259. resolve(promise, value);
  14260. }
  14261. if (settled === REJECTED) {
  14262. reject(promise, value);
  14263. }
  14264. }
  14265. }
  14266. function handleThenable(promise, value) {
  14267. var resolved;
  14268. try {
  14269. if (promise === value) {
  14270. throw new TypeError('A promises callback cannot return that same promise.');
  14271. }
  14272. if (value && (typeof value === 'function' || typeof value === 'object')) {
  14273. // then should be retrieved only once
  14274. var then = value.then;
  14275. if (typeof then === 'function') {
  14276. then.call(value, function (val) {
  14277. if (!resolved) {
  14278. resolved = true;
  14279. if (value === val) {
  14280. fulfill(promise, val);
  14281. } else {
  14282. resolve(promise, val);
  14283. }
  14284. }
  14285. }, function (reason) {
  14286. if (!resolved) {
  14287. resolved = true;
  14288. reject(promise, reason);
  14289. }
  14290. });
  14291. return true;
  14292. }
  14293. }
  14294. } catch (e) {
  14295. if (!resolved) {
  14296. reject(promise, e);
  14297. }
  14298. return true;
  14299. }
  14300. return false;
  14301. }
  14302. function resolve(promise, value) {
  14303. if (promise === value || !handleThenable(promise, value)) {
  14304. fulfill(promise, value);
  14305. }
  14306. }
  14307. function fulfill(promise, value) {
  14308. if (promise._state === PENDING) {
  14309. promise._state = SETTLED;
  14310. promise._data = value;
  14311. asyncCall(publishFulfillment, promise);
  14312. }
  14313. }
  14314. function reject(promise, reason) {
  14315. if (promise._state === PENDING) {
  14316. promise._state = SETTLED;
  14317. promise._data = reason;
  14318. asyncCall(publishRejection, promise);
  14319. }
  14320. }
  14321. function publish(promise) {
  14322. promise._then = promise._then.forEach(invokeCallback);
  14323. }
  14324. function publishFulfillment(promise) {
  14325. promise._state = FULFILLED;
  14326. publish(promise);
  14327. }
  14328. function publishRejection(promise) {
  14329. promise._state = REJECTED;
  14330. publish(promise);
  14331. if (!promise._handled && isNode) {
  14332. commonjsGlobal.process.emit('unhandledRejection', promise._data, promise);
  14333. }
  14334. }
  14335. function notifyRejectionHandled(promise) {
  14336. commonjsGlobal.process.emit('rejectionHandled', promise);
  14337. }
  14338. /**
  14339. * @class
  14340. */
  14341. function Promise$1(resolver) {
  14342. if (typeof resolver !== 'function') {
  14343. throw new TypeError('Promise resolver ' + resolver + ' is not a function');
  14344. }
  14345. if (this instanceof Promise$1 === false) {
  14346. throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
  14347. }
  14348. this._then = [];
  14349. invokeResolver(resolver, this);
  14350. }
  14351. Promise$1.prototype = {
  14352. constructor: Promise$1,
  14353. _state: PENDING,
  14354. _then: null,
  14355. _data: undefined,
  14356. _handled: false,
  14357. then: function then(onFulfillment, onRejection) {
  14358. var subscriber = {
  14359. owner: this,
  14360. then: new this.constructor(NOOP),
  14361. fulfilled: onFulfillment,
  14362. rejected: onRejection
  14363. };
  14364. if ((onRejection || onFulfillment) && !this._handled) {
  14365. this._handled = true;
  14366. if (this._state === REJECTED && isNode) {
  14367. asyncCall(notifyRejectionHandled, this);
  14368. }
  14369. }
  14370. if (this._state === FULFILLED || this._state === REJECTED) {
  14371. // already resolved, call callback async
  14372. asyncCall(invokeCallback, subscriber);
  14373. } else {
  14374. // subscribe
  14375. this._then.push(subscriber);
  14376. }
  14377. return subscriber.then;
  14378. },
  14379. catch: function _catch(onRejection) {
  14380. return this.then(null, onRejection);
  14381. }
  14382. };
  14383. Promise$1.all = function (promises) {
  14384. if (!Array.isArray(promises)) {
  14385. throw new TypeError('You must pass an array to Promise.all().');
  14386. }
  14387. return new Promise$1(function (resolve, reject) {
  14388. var results = [];
  14389. var remaining = 0;
  14390. function resolver(index) {
  14391. remaining++;
  14392. return function (value) {
  14393. results[index] = value;
  14394. if (! --remaining) {
  14395. resolve(results);
  14396. }
  14397. };
  14398. }
  14399. for (var i = 0, promise; i < promises.length; i++) {
  14400. promise = promises[i];
  14401. if (promise && typeof promise.then === 'function') {
  14402. promise.then(resolver(i), reject);
  14403. } else {
  14404. results[i] = promise;
  14405. }
  14406. }
  14407. if (!remaining) {
  14408. resolve(results);
  14409. }
  14410. });
  14411. };
  14412. Promise$1.race = function (promises) {
  14413. if (!Array.isArray(promises)) {
  14414. throw new TypeError('You must pass an array to Promise.race().');
  14415. }
  14416. return new Promise$1(function (resolve, reject) {
  14417. for (var i = 0, promise; i < promises.length; i++) {
  14418. promise = promises[i];
  14419. if (promise && typeof promise.then === 'function') {
  14420. promise.then(resolve, reject);
  14421. } else {
  14422. resolve(promise);
  14423. }
  14424. }
  14425. });
  14426. };
  14427. Promise$1.resolve = function (value) {
  14428. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  14429. return value;
  14430. }
  14431. return new Promise$1(function (resolve) {
  14432. resolve(value);
  14433. });
  14434. };
  14435. Promise$1.reject = function (reason) {
  14436. return new Promise$1(function (resolve, reject) {
  14437. reject(reason);
  14438. });
  14439. };
  14440. var pinkie = Promise$1;
  14441. var pinkiePromise = typeof Promise === 'function' ? Promise : pinkie;
  14442. var arrayUniq = createCommonjsModule(function (module) {
  14443. 'use strict'; // there's 3 implementations written in increasing order of efficiency
  14444. // 1 - no Set type is defined
  14445. function uniqNoSet(arr) {
  14446. var ret = [];
  14447. for (var i = 0; i < arr.length; i++) {
  14448. if (ret.indexOf(arr[i]) === -1) {
  14449. ret.push(arr[i]);
  14450. }
  14451. }
  14452. return ret;
  14453. } // 2 - a simple Set type is defined
  14454. function uniqSet(arr) {
  14455. var seen = new Set();
  14456. return arr.filter(function (el) {
  14457. if (!seen.has(el)) {
  14458. seen.add(el);
  14459. return true;
  14460. }
  14461. return false;
  14462. });
  14463. } // 3 - a standard Set type is defined and it has a forEach method
  14464. function uniqSetWithForEach(arr) {
  14465. var ret = [];
  14466. new Set(arr).forEach(function (el) {
  14467. ret.push(el);
  14468. });
  14469. return ret;
  14470. } // V8 currently has a broken implementation
  14471. // https://github.com/joyent/node/issues/8449
  14472. function doesForEachActuallyWork() {
  14473. var ret = false;
  14474. new Set([true]).forEach(function (el) {
  14475. ret = el;
  14476. });
  14477. return ret === true;
  14478. }
  14479. if ('Set' in commonjsGlobal) {
  14480. if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) {
  14481. module.exports = uniqSetWithForEach;
  14482. } else {
  14483. module.exports = uniqSet;
  14484. }
  14485. } else {
  14486. module.exports = uniqNoSet;
  14487. }
  14488. });
  14489. var arrayUnion = function arrayUnion() {
  14490. return arrayUniq([].concat.apply([], arguments));
  14491. };
  14492. /*
  14493. object-assign
  14494. (c) Sindre Sorhus
  14495. @license MIT
  14496. */
  14497. /* eslint-disable no-unused-vars */
  14498. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  14499. var hasOwnProperty = Object.prototype.hasOwnProperty;
  14500. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  14501. function toObject(val) {
  14502. if (val === null || val === undefined) {
  14503. throw new TypeError('Object.assign cannot be called with null or undefined');
  14504. }
  14505. return Object(val);
  14506. }
  14507. function shouldUseNative() {
  14508. try {
  14509. if (!Object.assign) {
  14510. return false;
  14511. } // Detect buggy property enumeration order in older V8 versions.
  14512. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  14513. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  14514. test1[5] = 'de';
  14515. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  14516. return false;
  14517. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  14518. var test2 = {};
  14519. for (var i = 0; i < 10; i++) {
  14520. test2['_' + String.fromCharCode(i)] = i;
  14521. }
  14522. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  14523. return test2[n];
  14524. });
  14525. if (order2.join('') !== '0123456789') {
  14526. return false;
  14527. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  14528. var test3 = {};
  14529. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  14530. test3[letter] = letter;
  14531. });
  14532. if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
  14533. return false;
  14534. }
  14535. return true;
  14536. } catch (err) {
  14537. // We don't expect any of the above to throw, but better to be safe.
  14538. return false;
  14539. }
  14540. }
  14541. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  14542. var from;
  14543. var to = toObject(target);
  14544. var symbols;
  14545. for (var s = 1; s < arguments.length; s++) {
  14546. from = Object(arguments[s]);
  14547. for (var key in from) {
  14548. if (hasOwnProperty.call(from, key)) {
  14549. to[key] = from[key];
  14550. }
  14551. }
  14552. if (getOwnPropertySymbols) {
  14553. symbols = getOwnPropertySymbols(from);
  14554. for (var i = 0; i < symbols.length; i++) {
  14555. if (propIsEnumerable.call(from, symbols[i])) {
  14556. to[symbols[i]] = from[symbols[i]];
  14557. }
  14558. }
  14559. }
  14560. }
  14561. return to;
  14562. };
  14563. //
  14564. // Permission is hereby granted, free of charge, to any person obtaining a
  14565. // copy of this software and associated documentation files (the
  14566. // "Software"), to deal in the Software without restriction, including
  14567. // without limitation the rights to use, copy, modify, merge, publish,
  14568. // distribute, sublicense, and/or sell copies of the Software, and to permit
  14569. // persons to whom the Software is furnished to do so, subject to the
  14570. // following conditions:
  14571. //
  14572. // The above copyright notice and this permission notice shall be included
  14573. // in all copies or substantial portions of the Software.
  14574. //
  14575. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14576. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14577. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  14578. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  14579. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  14580. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  14581. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  14582. var isWindows = process.platform === 'win32'; // JavaScript implementation of realpath, ported from node pre-v6
  14583. var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
  14584. function rethrow() {
  14585. // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
  14586. // is fairly slow to generate.
  14587. var callback;
  14588. if (DEBUG) {
  14589. var backtrace = new Error();
  14590. callback = debugCallback;
  14591. } else callback = missingCallback;
  14592. return callback;
  14593. function debugCallback(err) {
  14594. if (err) {
  14595. backtrace.message = err.message;
  14596. err = backtrace;
  14597. missingCallback(err);
  14598. }
  14599. }
  14600. function missingCallback(err) {
  14601. if (err) {
  14602. if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
  14603. else if (!process.noDeprecation) {
  14604. var msg = 'fs: missing callback ' + (err.stack || err.message);
  14605. if (process.traceDeprecation) console.trace(msg);else console.error(msg);
  14606. }
  14607. }
  14608. }
  14609. }
  14610. function maybeCallback(cb) {
  14611. return typeof cb === 'function' ? cb : rethrow();
  14612. }
  14613. // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
  14614. if (isWindows) {
  14615. var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
  14616. } else {
  14617. var nextPartRe = /(.*?)(?:[\/]+|$)/g;
  14618. } // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
  14619. if (isWindows) {
  14620. var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
  14621. } else {
  14622. var splitRootRe = /^[\/]*/;
  14623. }
  14624. var realpathSync$1 = function realpathSync(p, cache) {
  14625. // make p is absolute
  14626. p = path.resolve(p);
  14627. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  14628. return cache[p];
  14629. }
  14630. var original = p,
  14631. seenLinks = {},
  14632. knownHard = {}; // current character position in p
  14633. var pos; // the partial path so far, including a trailing slash if any
  14634. var current; // the partial path without a trailing slash (except when pointing at a root)
  14635. var base; // the partial path scanned in the previous round, with slash
  14636. var previous;
  14637. start();
  14638. function start() {
  14639. // Skip over roots
  14640. var m = splitRootRe.exec(p);
  14641. pos = m[0].length;
  14642. current = m[0];
  14643. base = m[0];
  14644. previous = ''; // On windows, check that the root exists. On unix there is no need.
  14645. if (isWindows && !knownHard[base]) {
  14646. fs.lstatSync(base);
  14647. knownHard[base] = true;
  14648. }
  14649. } // walk down the path, swapping out linked pathparts for their real
  14650. // values
  14651. // NB: p.length changes.
  14652. while (pos < p.length) {
  14653. // find the next part
  14654. nextPartRe.lastIndex = pos;
  14655. var result = nextPartRe.exec(p);
  14656. previous = current;
  14657. current += result[0];
  14658. base = previous + result[1];
  14659. pos = nextPartRe.lastIndex; // continue if not a symlink
  14660. if (knownHard[base] || cache && cache[base] === base) {
  14661. continue;
  14662. }
  14663. var resolvedLink;
  14664. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  14665. // some known symbolic link. no need to stat again.
  14666. resolvedLink = cache[base];
  14667. } else {
  14668. var stat = fs.lstatSync(base);
  14669. if (!stat.isSymbolicLink()) {
  14670. knownHard[base] = true;
  14671. if (cache) cache[base] = base;
  14672. continue;
  14673. } // read the link if it wasn't read before
  14674. // dev/ino always return 0 on windows, so skip the check.
  14675. var linkTarget = null;
  14676. if (!isWindows) {
  14677. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  14678. if (seenLinks.hasOwnProperty(id)) {
  14679. linkTarget = seenLinks[id];
  14680. }
  14681. }
  14682. if (linkTarget === null) {
  14683. fs.statSync(base);
  14684. linkTarget = fs.readlinkSync(base);
  14685. }
  14686. resolvedLink = path.resolve(previous, linkTarget); // track this, if given a cache.
  14687. if (cache) cache[base] = resolvedLink;
  14688. if (!isWindows) seenLinks[id] = linkTarget;
  14689. } // resolve the link, then start over
  14690. p = path.resolve(resolvedLink, p.slice(pos));
  14691. start();
  14692. }
  14693. if (cache) cache[original] = p;
  14694. return p;
  14695. };
  14696. var realpath$1 = function realpath(p, cache, cb) {
  14697. if (typeof cb !== 'function') {
  14698. cb = maybeCallback(cache);
  14699. cache = null;
  14700. } // make p is absolute
  14701. p = path.resolve(p);
  14702. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  14703. return process.nextTick(cb.bind(null, null, cache[p]));
  14704. }
  14705. var original = p,
  14706. seenLinks = {},
  14707. knownHard = {}; // current character position in p
  14708. var pos; // the partial path so far, including a trailing slash if any
  14709. var current; // the partial path without a trailing slash (except when pointing at a root)
  14710. var base; // the partial path scanned in the previous round, with slash
  14711. var previous;
  14712. start();
  14713. function start() {
  14714. // Skip over roots
  14715. var m = splitRootRe.exec(p);
  14716. pos = m[0].length;
  14717. current = m[0];
  14718. base = m[0];
  14719. previous = ''; // On windows, check that the root exists. On unix there is no need.
  14720. if (isWindows && !knownHard[base]) {
  14721. fs.lstat(base, function (err) {
  14722. if (err) return cb(err);
  14723. knownHard[base] = true;
  14724. LOOP();
  14725. });
  14726. } else {
  14727. process.nextTick(LOOP);
  14728. }
  14729. } // walk down the path, swapping out linked pathparts for their real
  14730. // values
  14731. function LOOP() {
  14732. // stop if scanned past end of path
  14733. if (pos >= p.length) {
  14734. if (cache) cache[original] = p;
  14735. return cb(null, p);
  14736. } // find the next part
  14737. nextPartRe.lastIndex = pos;
  14738. var result = nextPartRe.exec(p);
  14739. previous = current;
  14740. current += result[0];
  14741. base = previous + result[1];
  14742. pos = nextPartRe.lastIndex; // continue if not a symlink
  14743. if (knownHard[base] || cache && cache[base] === base) {
  14744. return process.nextTick(LOOP);
  14745. }
  14746. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  14747. // known symbolic link. no need to stat again.
  14748. return gotResolvedLink(cache[base]);
  14749. }
  14750. return fs.lstat(base, gotStat);
  14751. }
  14752. function gotStat(err, stat) {
  14753. if (err) return cb(err); // if not a symlink, skip to the next path part
  14754. if (!stat.isSymbolicLink()) {
  14755. knownHard[base] = true;
  14756. if (cache) cache[base] = base;
  14757. return process.nextTick(LOOP);
  14758. } // stat & read the link if not read before
  14759. // call gotTarget as soon as the link target is known
  14760. // dev/ino always return 0 on windows, so skip the check.
  14761. if (!isWindows) {
  14762. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  14763. if (seenLinks.hasOwnProperty(id)) {
  14764. return gotTarget(null, seenLinks[id], base);
  14765. }
  14766. }
  14767. fs.stat(base, function (err) {
  14768. if (err) return cb(err);
  14769. fs.readlink(base, function (err, target) {
  14770. if (!isWindows) seenLinks[id] = target;
  14771. gotTarget(err, target);
  14772. });
  14773. });
  14774. }
  14775. function gotTarget(err, target, base) {
  14776. if (err) return cb(err);
  14777. var resolvedLink = path.resolve(previous, target);
  14778. if (cache) cache[base] = resolvedLink;
  14779. gotResolvedLink(resolvedLink);
  14780. }
  14781. function gotResolvedLink(resolvedLink) {
  14782. // resolve the link, then start over
  14783. p = path.resolve(resolvedLink, p.slice(pos));
  14784. start();
  14785. }
  14786. };
  14787. var old = {
  14788. realpathSync: realpathSync$1,
  14789. realpath: realpath$1
  14790. };
  14791. var fs_realpath = realpath;
  14792. realpath.realpath = realpath;
  14793. realpath.sync = realpathSync;
  14794. realpath.realpathSync = realpathSync;
  14795. realpath.monkeypatch = monkeypatch;
  14796. realpath.unmonkeypatch = unmonkeypatch;
  14797. var origRealpath = fs.realpath;
  14798. var origRealpathSync = fs.realpathSync;
  14799. var version$2 = process.version;
  14800. var ok = /^v[0-5]\./.test(version$2);
  14801. function newError(er) {
  14802. return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
  14803. }
  14804. function realpath(p, cache, cb) {
  14805. if (ok) {
  14806. return origRealpath(p, cache, cb);
  14807. }
  14808. if (typeof cache === 'function') {
  14809. cb = cache;
  14810. cache = null;
  14811. }
  14812. origRealpath(p, cache, function (er, result) {
  14813. if (newError(er)) {
  14814. old.realpath(p, cache, cb);
  14815. } else {
  14816. cb(er, result);
  14817. }
  14818. });
  14819. }
  14820. function realpathSync(p, cache) {
  14821. if (ok) {
  14822. return origRealpathSync(p, cache);
  14823. }
  14824. try {
  14825. return origRealpathSync(p, cache);
  14826. } catch (er) {
  14827. if (newError(er)) {
  14828. return old.realpathSync(p, cache);
  14829. } else {
  14830. throw er;
  14831. }
  14832. }
  14833. }
  14834. function monkeypatch() {
  14835. fs.realpath = realpath;
  14836. fs.realpathSync = realpathSync;
  14837. }
  14838. function unmonkeypatch() {
  14839. fs.realpath = origRealpath;
  14840. fs.realpathSync = origRealpathSync;
  14841. }
  14842. var concatMap = function concatMap(xs, fn) {
  14843. var res = [];
  14844. for (var i = 0; i < xs.length; i++) {
  14845. var x = fn(xs[i], i);
  14846. if (isArray(x)) res.push.apply(res, x);else res.push(x);
  14847. }
  14848. return res;
  14849. };
  14850. var isArray = Array.isArray || function (xs) {
  14851. return Object.prototype.toString.call(xs) === '[object Array]';
  14852. };
  14853. var balancedMatch = balanced;
  14854. function balanced(a, b, str) {
  14855. if (a instanceof RegExp) a = maybeMatch(a, str);
  14856. if (b instanceof RegExp) b = maybeMatch(b, str);
  14857. var r = range(a, b, str);
  14858. return r && {
  14859. start: r[0],
  14860. end: r[1],
  14861. pre: str.slice(0, r[0]),
  14862. body: str.slice(r[0] + a.length, r[1]),
  14863. post: str.slice(r[1] + b.length)
  14864. };
  14865. }
  14866. function maybeMatch(reg, str) {
  14867. var m = str.match(reg);
  14868. return m ? m[0] : null;
  14869. }
  14870. balanced.range = range;
  14871. function range(a, b, str) {
  14872. var begs, beg, left, right, result;
  14873. var ai = str.indexOf(a);
  14874. var bi = str.indexOf(b, ai + 1);
  14875. var i = ai;
  14876. if (ai >= 0 && bi > 0) {
  14877. begs = [];
  14878. left = str.length;
  14879. while (i >= 0 && !result) {
  14880. if (i == ai) {
  14881. begs.push(i);
  14882. ai = str.indexOf(a, i + 1);
  14883. } else if (begs.length == 1) {
  14884. result = [begs.pop(), bi];
  14885. } else {
  14886. beg = begs.pop();
  14887. if (beg < left) {
  14888. left = beg;
  14889. right = bi;
  14890. }
  14891. bi = str.indexOf(b, i + 1);
  14892. }
  14893. i = ai < bi && ai >= 0 ? ai : bi;
  14894. }
  14895. if (begs.length) {
  14896. result = [left, right];
  14897. }
  14898. }
  14899. return result;
  14900. }
  14901. var braceExpansion = expandTop;
  14902. var escSlash = '\0SLASH' + Math.random() + '\0';
  14903. var escOpen = '\0OPEN' + Math.random() + '\0';
  14904. var escClose = '\0CLOSE' + Math.random() + '\0';
  14905. var escComma = '\0COMMA' + Math.random() + '\0';
  14906. var escPeriod = '\0PERIOD' + Math.random() + '\0';
  14907. function numeric(str) {
  14908. return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
  14909. }
  14910. function escapeBraces(str) {
  14911. return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
  14912. }
  14913. function unescapeBraces(str) {
  14914. return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
  14915. } // Basically just str.split(","), but handling cases
  14916. // where we have nested braced sections, which should be
  14917. // treated as individual members, like {a,{b,c},d}
  14918. function parseCommaParts(str) {
  14919. if (!str) return [''];
  14920. var parts = [];
  14921. var m = balancedMatch('{', '}', str);
  14922. if (!m) return str.split(',');
  14923. var pre = m.pre;
  14924. var body = m.body;
  14925. var post = m.post;
  14926. var p = pre.split(',');
  14927. p[p.length - 1] += '{' + body + '}';
  14928. var postParts = parseCommaParts(post);
  14929. if (post.length) {
  14930. p[p.length - 1] += postParts.shift();
  14931. p.push.apply(p, postParts);
  14932. }
  14933. parts.push.apply(parts, p);
  14934. return parts;
  14935. }
  14936. function expandTop(str) {
  14937. if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
  14938. // Anything starting with {} will have the first two bytes preserved
  14939. // but *only* at the top level, so {},a}b will not expand to anything,
  14940. // but a{},b}c will be expanded to [a}c,abc].
  14941. // One could argue that this is a bug in Bash, but since the goal of
  14942. // this module is to match Bash's rules, we escape a leading {}
  14943. if (str.substr(0, 2) === '{}') {
  14944. str = '\\{\\}' + str.substr(2);
  14945. }
  14946. return expand(escapeBraces(str), true).map(unescapeBraces);
  14947. }
  14948. function embrace(str) {
  14949. return '{' + str + '}';
  14950. }
  14951. function isPadded(el) {
  14952. return /^-?0\d/.test(el);
  14953. }
  14954. function lte(i, y) {
  14955. return i <= y;
  14956. }
  14957. function gte(i, y) {
  14958. return i >= y;
  14959. }
  14960. function expand(str, isTop) {
  14961. var expansions = [];
  14962. var m = balancedMatch('{', '}', str);
  14963. if (!m || /\$$/.test(m.pre)) return [str];
  14964. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  14965. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  14966. var isSequence = isNumericSequence || isAlphaSequence;
  14967. var isOptions = m.body.indexOf(',') >= 0;
  14968. if (!isSequence && !isOptions) {
  14969. // {a},b}
  14970. if (m.post.match(/,.*\}/)) {
  14971. str = m.pre + '{' + m.body + escClose + m.post;
  14972. return expand(str);
  14973. }
  14974. return [str];
  14975. }
  14976. var n;
  14977. if (isSequence) {
  14978. n = m.body.split(/\.\./);
  14979. } else {
  14980. n = parseCommaParts(m.body);
  14981. if (n.length === 1) {
  14982. // x{{a,b}}y ==> x{a}y x{b}y
  14983. n = expand(n[0], false).map(embrace);
  14984. if (n.length === 1) {
  14985. var post = m.post.length ? expand(m.post, false) : [''];
  14986. return post.map(function (p) {
  14987. return m.pre + n[0] + p;
  14988. });
  14989. }
  14990. }
  14991. } // at this point, n is the parts, and we know it's not a comma set
  14992. // with a single entry.
  14993. // no need to expand pre, since it is guaranteed to be free of brace-sets
  14994. var pre = m.pre;
  14995. var post = m.post.length ? expand(m.post, false) : [''];
  14996. var N;
  14997. if (isSequence) {
  14998. var x = numeric(n[0]);
  14999. var y = numeric(n[1]);
  15000. var width = Math.max(n[0].length, n[1].length);
  15001. var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
  15002. var test = lte;
  15003. var reverse = y < x;
  15004. if (reverse) {
  15005. incr *= -1;
  15006. test = gte;
  15007. }
  15008. var pad = n.some(isPadded);
  15009. N = [];
  15010. for (var i = x; test(i, y); i += incr) {
  15011. var c;
  15012. if (isAlphaSequence) {
  15013. c = String.fromCharCode(i);
  15014. if (c === '\\') c = '';
  15015. } else {
  15016. c = String(i);
  15017. if (pad) {
  15018. var need = width - c.length;
  15019. if (need > 0) {
  15020. var z = new Array(need + 1).join('0');
  15021. if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
  15022. }
  15023. }
  15024. }
  15025. N.push(c);
  15026. }
  15027. } else {
  15028. N = concatMap(n, function (el) {
  15029. return expand(el, false);
  15030. });
  15031. }
  15032. for (var j = 0; j < N.length; j++) {
  15033. for (var k = 0; k < post.length; k++) {
  15034. var expansion = pre + N[j] + post[k];
  15035. if (!isTop || isSequence || expansion) expansions.push(expansion);
  15036. }
  15037. }
  15038. return expansions;
  15039. }
  15040. var minimatch_1 = minimatch;
  15041. minimatch.Minimatch = Minimatch$1;
  15042. var path$2 = {
  15043. sep: '/'
  15044. };
  15045. try {
  15046. path$2 = path;
  15047. } catch (er) {}
  15048. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch$1.GLOBSTAR = {};
  15049. var plTypes = {
  15050. '!': {
  15051. open: '(?:(?!(?:',
  15052. close: '))[^/]*?)'
  15053. },
  15054. '?': {
  15055. open: '(?:',
  15056. close: ')?'
  15057. },
  15058. '+': {
  15059. open: '(?:',
  15060. close: ')+'
  15061. },
  15062. '*': {
  15063. open: '(?:',
  15064. close: ')*'
  15065. },
  15066. '@': {
  15067. open: '(?:',
  15068. close: ')'
  15069. } // any single thing other than /
  15070. // don't need to escape / when using new RegExp()
  15071. };
  15072. var qmark = '[^/]'; // * => any number of characters
  15073. var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
  15074. // not (^ or / followed by one or two dots followed by $ or /),
  15075. // followed by anything, any number of times.
  15076. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
  15077. // followed by anything, any number of times.
  15078. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
  15079. var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
  15080. function charSet(s) {
  15081. return s.split('').reduce(function (set, c) {
  15082. set[c] = true;
  15083. return set;
  15084. }, {});
  15085. } // normalizes slashes.
  15086. var slashSplit = /\/+/;
  15087. minimatch.filter = filter$1;
  15088. function filter$1(pattern, options) {
  15089. options = options || {};
  15090. return function (p, i, list) {
  15091. return minimatch(p, pattern, options);
  15092. };
  15093. }
  15094. function ext(a, b) {
  15095. a = a || {};
  15096. b = b || {};
  15097. var t = {};
  15098. Object.keys(b).forEach(function (k) {
  15099. t[k] = b[k];
  15100. });
  15101. Object.keys(a).forEach(function (k) {
  15102. t[k] = a[k];
  15103. });
  15104. return t;
  15105. }
  15106. minimatch.defaults = function (def) {
  15107. if (!def || !Object.keys(def).length) return minimatch;
  15108. var orig = minimatch;
  15109. var m = function minimatch(p, pattern, options) {
  15110. return orig.minimatch(p, pattern, ext(def, options));
  15111. };
  15112. m.Minimatch = function Minimatch(pattern, options) {
  15113. return new orig.Minimatch(pattern, ext(def, options));
  15114. };
  15115. return m;
  15116. };
  15117. Minimatch$1.defaults = function (def) {
  15118. if (!def || !Object.keys(def).length) return Minimatch$1;
  15119. return minimatch.defaults(def).Minimatch;
  15120. };
  15121. function minimatch(p, pattern, options) {
  15122. if (typeof pattern !== 'string') {
  15123. throw new TypeError('glob pattern string required');
  15124. }
  15125. if (!options) options = {}; // shortcut: comments match nothing.
  15126. if (!options.nocomment && pattern.charAt(0) === '#') {
  15127. return false;
  15128. } // "" only matches ""
  15129. if (pattern.trim() === '') return p === '';
  15130. return new Minimatch$1(pattern, options).match(p);
  15131. }
  15132. function Minimatch$1(pattern, options) {
  15133. if (!(this instanceof Minimatch$1)) {
  15134. return new Minimatch$1(pattern, options);
  15135. }
  15136. if (typeof pattern !== 'string') {
  15137. throw new TypeError('glob pattern string required');
  15138. }
  15139. if (!options) options = {};
  15140. pattern = pattern.trim(); // windows support: need to use /, not \
  15141. if (path$2.sep !== '/') {
  15142. pattern = pattern.split(path$2.sep).join('/');
  15143. }
  15144. this.options = options;
  15145. this.set = [];
  15146. this.pattern = pattern;
  15147. this.regexp = null;
  15148. this.negate = false;
  15149. this.comment = false;
  15150. this.empty = false; // make the set of regexps etc.
  15151. this.make();
  15152. }
  15153. Minimatch$1.prototype.debug = function () {};
  15154. Minimatch$1.prototype.make = make;
  15155. function make() {
  15156. // don't do it more than once.
  15157. if (this._made) return;
  15158. var pattern = this.pattern;
  15159. var options = this.options; // empty patterns and comments match nothing.
  15160. if (!options.nocomment && pattern.charAt(0) === '#') {
  15161. this.comment = true;
  15162. return;
  15163. }
  15164. if (!pattern) {
  15165. this.empty = true;
  15166. return;
  15167. } // step 1: figure out negation, etc.
  15168. this.parseNegate(); // step 2: expand braces
  15169. var set = this.globSet = this.braceExpand();
  15170. if (options.debug) this.debug = console.error;
  15171. this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  15172. // matching patterns.
  15173. // These will be regexps, except in the case of "**", which is
  15174. // set to the GLOBSTAR object for globstar behavior,
  15175. // and will not contain any / characters
  15176. set = this.globParts = set.map(function (s) {
  15177. return s.split(slashSplit);
  15178. });
  15179. this.debug(this.pattern, set); // glob --> regexps
  15180. set = set.map(function (s, si, set) {
  15181. return s.map(this.parse, this);
  15182. }, this);
  15183. this.debug(this.pattern, set); // filter out everything that didn't compile properly.
  15184. set = set.filter(function (s) {
  15185. return s.indexOf(false) === -1;
  15186. });
  15187. this.debug(this.pattern, set);
  15188. this.set = set;
  15189. }
  15190. Minimatch$1.prototype.parseNegate = parseNegate;
  15191. function parseNegate() {
  15192. var pattern = this.pattern;
  15193. var negate = false;
  15194. var options = this.options;
  15195. var negateOffset = 0;
  15196. if (options.nonegate) return;
  15197. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
  15198. negate = !negate;
  15199. negateOffset++;
  15200. }
  15201. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  15202. this.negate = negate;
  15203. } // Brace expansion:
  15204. // a{b,c}d -> abd acd
  15205. // a{b,}c -> abc ac
  15206. // a{0..3}d -> a0d a1d a2d a3d
  15207. // a{b,c{d,e}f}g -> abg acdfg acefg
  15208. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  15209. //
  15210. // Invalid sets are not expanded.
  15211. // a{2..}b -> a{2..}b
  15212. // a{b}c -> a{b}c
  15213. minimatch.braceExpand = function (pattern, options) {
  15214. return braceExpand(pattern, options);
  15215. };
  15216. Minimatch$1.prototype.braceExpand = braceExpand;
  15217. function braceExpand(pattern, options) {
  15218. if (!options) {
  15219. if (this instanceof Minimatch$1) {
  15220. options = this.options;
  15221. } else {
  15222. options = {};
  15223. }
  15224. }
  15225. pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
  15226. if (typeof pattern === 'undefined') {
  15227. throw new TypeError('undefined pattern');
  15228. }
  15229. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  15230. // shortcut. no need to expand.
  15231. return [pattern];
  15232. }
  15233. return braceExpansion(pattern);
  15234. } // parse a component of the expanded set.
  15235. // At this point, no pattern may contain "/" in it
  15236. // so we're going to return a 2d array, where each entry is the full
  15237. // pattern, split on '/', and then turned into a regular expression.
  15238. // A regexp is made at the end which joins each array with an
  15239. // escaped /, and another full one which joins each regexp with |.
  15240. //
  15241. // Following the lead of Bash 4.1, note that "**" only has special meaning
  15242. // when it is the *only* thing in a path portion. Otherwise, any series
  15243. // of * is equivalent to a single *. Globstar behavior is enabled by
  15244. // default, and can be disabled by setting options.noglobstar.
  15245. Minimatch$1.prototype.parse = parse$3;
  15246. var SUBPARSE = {};
  15247. function parse$3(pattern, isSub) {
  15248. if (pattern.length > 1024 * 64) {
  15249. throw new TypeError('pattern is too long');
  15250. }
  15251. var options = this.options; // shortcuts
  15252. if (!options.noglobstar && pattern === '**') return GLOBSTAR;
  15253. if (pattern === '') return '';
  15254. var re = '';
  15255. var hasMagic = !!options.nocase;
  15256. var escaping = false; // ? => one single character
  15257. var patternListStack = [];
  15258. var negativeLists = [];
  15259. var stateChar;
  15260. var inClass = false;
  15261. var reClassStart = -1;
  15262. var classStart = -1; // . and .. never match anything that doesn't start with .,
  15263. // even when options.dot is set.
  15264. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  15265. // not (start or / followed by . or .. followed by / or end)
  15266. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
  15267. var self = this;
  15268. function clearStateChar() {
  15269. if (stateChar) {
  15270. // we had some state-tracking character
  15271. // that wasn't consumed by this pass.
  15272. switch (stateChar) {
  15273. case '*':
  15274. re += star;
  15275. hasMagic = true;
  15276. break;
  15277. case '?':
  15278. re += qmark;
  15279. hasMagic = true;
  15280. break;
  15281. default:
  15282. re += '\\' + stateChar;
  15283. break;
  15284. }
  15285. self.debug('clearStateChar %j %j', stateChar, re);
  15286. stateChar = false;
  15287. }
  15288. }
  15289. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  15290. this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
  15291. if (escaping && reSpecials[c]) {
  15292. re += '\\' + c;
  15293. escaping = false;
  15294. continue;
  15295. }
  15296. switch (c) {
  15297. case '/':
  15298. // completely not allowed, even escaped.
  15299. // Should already be path-split by now.
  15300. return false;
  15301. case '\\':
  15302. clearStateChar();
  15303. escaping = true;
  15304. continue;
  15305. // the various stateChar values
  15306. // for the "extglob" stuff.
  15307. case '?':
  15308. case '*':
  15309. case '+':
  15310. case '@':
  15311. case '!':
  15312. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
  15313. // the glob [!a] means [^a] in regexp
  15314. if (inClass) {
  15315. this.debug(' in class');
  15316. if (c === '!' && i === classStart + 1) c = '^';
  15317. re += c;
  15318. continue;
  15319. } // if we already have a stateChar, then it means
  15320. // that there was something like ** or +? in there.
  15321. // Handle the stateChar, then proceed with this one.
  15322. self.debug('call clearStateChar %j', stateChar);
  15323. clearStateChar();
  15324. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  15325. // just clear the statechar *now*, rather than even diving into
  15326. // the patternList stuff.
  15327. if (options.noext) clearStateChar();
  15328. continue;
  15329. case '(':
  15330. if (inClass) {
  15331. re += '(';
  15332. continue;
  15333. }
  15334. if (!stateChar) {
  15335. re += '\\(';
  15336. continue;
  15337. }
  15338. patternListStack.push({
  15339. type: stateChar,
  15340. start: i - 1,
  15341. reStart: re.length,
  15342. open: plTypes[stateChar].open,
  15343. close: plTypes[stateChar].close
  15344. }); // negation is (?:(?!js)[^/]*)
  15345. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  15346. this.debug('plType %j %j', stateChar, re);
  15347. stateChar = false;
  15348. continue;
  15349. case ')':
  15350. if (inClass || !patternListStack.length) {
  15351. re += '\\)';
  15352. continue;
  15353. }
  15354. clearStateChar();
  15355. hasMagic = true;
  15356. var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
  15357. // The others are (?:<pattern>)<type>
  15358. re += pl.close;
  15359. if (pl.type === '!') {
  15360. negativeLists.push(pl);
  15361. }
  15362. pl.reEnd = re.length;
  15363. continue;
  15364. case '|':
  15365. if (inClass || !patternListStack.length || escaping) {
  15366. re += '\\|';
  15367. escaping = false;
  15368. continue;
  15369. }
  15370. clearStateChar();
  15371. re += '|';
  15372. continue;
  15373. // these are mostly the same in regexp and glob
  15374. case '[':
  15375. // swallow any state-tracking char before the [
  15376. clearStateChar();
  15377. if (inClass) {
  15378. re += '\\' + c;
  15379. continue;
  15380. }
  15381. inClass = true;
  15382. classStart = i;
  15383. reClassStart = re.length;
  15384. re += c;
  15385. continue;
  15386. case ']':
  15387. // a right bracket shall lose its special
  15388. // meaning and represent itself in
  15389. // a bracket expression if it occurs
  15390. // first in the list. -- POSIX.2 2.8.3.2
  15391. if (i === classStart + 1 || !inClass) {
  15392. re += '\\' + c;
  15393. escaping = false;
  15394. continue;
  15395. } // handle the case where we left a class open.
  15396. // "[z-a]" is valid, equivalent to "\[z-a\]"
  15397. if (inClass) {
  15398. // split where the last [ was, make sure we don't have
  15399. // an invalid re. if so, re-walk the contents of the
  15400. // would-be class to re-translate any characters that
  15401. // were passed through as-is
  15402. // TODO: It would probably be faster to determine this
  15403. // without a try/catch and a new RegExp, but it's tricky
  15404. // to do safely. For now, this is safe and works.
  15405. var cs = pattern.substring(classStart + 1, i);
  15406. try {
  15407. RegExp('[' + cs + ']');
  15408. } catch (er) {
  15409. // not a valid class!
  15410. var sp = this.parse(cs, SUBPARSE);
  15411. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  15412. hasMagic = hasMagic || sp[1];
  15413. inClass = false;
  15414. continue;
  15415. }
  15416. } // finish up the class.
  15417. hasMagic = true;
  15418. inClass = false;
  15419. re += c;
  15420. continue;
  15421. default:
  15422. // swallow any state char that wasn't consumed
  15423. clearStateChar();
  15424. if (escaping) {
  15425. // no need
  15426. escaping = false;
  15427. } else if (reSpecials[c] && !(c === '^' && inClass)) {
  15428. re += '\\';
  15429. }
  15430. re += c;
  15431. } // switch
  15432. } // for
  15433. // handle the case where we left a class open.
  15434. // "[abc" is valid, equivalent to "\[abc"
  15435. if (inClass) {
  15436. // split where the last [ was, and escape it
  15437. // this is a huge pita. We now have to re-walk
  15438. // the contents of the would-be class to re-translate
  15439. // any characters that were passed through as-is
  15440. cs = pattern.substr(classStart + 1);
  15441. sp = this.parse(cs, SUBPARSE);
  15442. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  15443. hasMagic = hasMagic || sp[1];
  15444. } // handle the case where we had a +( thing at the *end*
  15445. // of the pattern.
  15446. // each pattern list stack adds 3 chars, and we need to go through
  15447. // and escape any | chars that were passed through as-is for the regexp.
  15448. // Go through and escape them, taking care not to double-escape any
  15449. // | chars that were already escaped.
  15450. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  15451. var tail = re.slice(pl.reStart + pl.open.length);
  15452. this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
  15453. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  15454. if (!$2) {
  15455. // the | isn't already escaped, so escape it.
  15456. $2 = '\\';
  15457. } // need to escape all those slashes *again*, without escaping the
  15458. // one that we need for escaping the | character. As it works out,
  15459. // escaping an even number of slashes can be done by simply repeating
  15460. // it exactly after itself. That's why this trick works.
  15461. //
  15462. // I am sorry that you have to see this.
  15463. return $1 + $1 + $2 + '|';
  15464. });
  15465. this.debug('tail=%j\n %s', tail, tail, pl, re);
  15466. var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
  15467. hasMagic = true;
  15468. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  15469. } // handle trailing things that only matter at the very end.
  15470. clearStateChar();
  15471. if (escaping) {
  15472. // trailing \\
  15473. re += '\\\\';
  15474. } // only need to apply the nodot start if the re starts with
  15475. // something that could conceivably capture a dot
  15476. var addPatternStart = false;
  15477. switch (re.charAt(0)) {
  15478. case '.':
  15479. case '[':
  15480. case '(':
  15481. addPatternStart = true;
  15482. } // Hack to work around lack of negative lookbehind in JS
  15483. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  15484. // like 'a.xyz.yz' doesn't match. So, the first negative
  15485. // lookahead, has to look ALL the way ahead, to the end of
  15486. // the pattern.
  15487. for (var n = negativeLists.length - 1; n > -1; n--) {
  15488. var nl = negativeLists[n];
  15489. var nlBefore = re.slice(0, nl.reStart);
  15490. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  15491. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  15492. var nlAfter = re.slice(nl.reEnd);
  15493. nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
  15494. // mean that we should *not* include the ) in the bit that is considered
  15495. // "after" the negated section.
  15496. var openParensBefore = nlBefore.split('(').length - 1;
  15497. var cleanAfter = nlAfter;
  15498. for (i = 0; i < openParensBefore; i++) {
  15499. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  15500. }
  15501. nlAfter = cleanAfter;
  15502. var dollar = '';
  15503. if (nlAfter === '' && isSub !== SUBPARSE) {
  15504. dollar = '$';
  15505. }
  15506. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  15507. re = newRe;
  15508. } // if the re is not "" at this point, then we need to make sure
  15509. // it doesn't match against an empty path part.
  15510. // Otherwise a/* will match a/, which it should not.
  15511. if (re !== '' && hasMagic) {
  15512. re = '(?=.)' + re;
  15513. }
  15514. if (addPatternStart) {
  15515. re = patternStart + re;
  15516. } // parsing just a piece of a larger pattern.
  15517. if (isSub === SUBPARSE) {
  15518. return [re, hasMagic];
  15519. } // skip the regexp for non-magical patterns
  15520. // unescape anything in it, though, so that it'll be
  15521. // an exact match against a file etc.
  15522. if (!hasMagic) {
  15523. return globUnescape(pattern);
  15524. }
  15525. var flags = options.nocase ? 'i' : '';
  15526. try {
  15527. var regExp = new RegExp('^' + re + '$', flags);
  15528. } catch (er) {
  15529. // If it was an invalid regular expression, then it can't match
  15530. // anything. This trick looks for a character after the end of
  15531. // the string, which is of course impossible, except in multi-line
  15532. // mode, but it's not a /m regex.
  15533. return new RegExp('$.');
  15534. }
  15535. regExp._glob = pattern;
  15536. regExp._src = re;
  15537. return regExp;
  15538. }
  15539. minimatch.makeRe = function (pattern, options) {
  15540. return new Minimatch$1(pattern, options || {}).makeRe();
  15541. };
  15542. Minimatch$1.prototype.makeRe = makeRe;
  15543. function makeRe() {
  15544. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  15545. // pattern strings, or "**".
  15546. //
  15547. // It's better to use .match(). This function shouldn't
  15548. // be used, really, but it's pretty convenient sometimes,
  15549. // when you just want to work with a regex.
  15550. var set = this.set;
  15551. if (!set.length) {
  15552. this.regexp = false;
  15553. return this.regexp;
  15554. }
  15555. var options = this.options;
  15556. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
  15557. var flags = options.nocase ? 'i' : '';
  15558. var re = set.map(function (pattern) {
  15559. return pattern.map(function (p) {
  15560. return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
  15561. }).join('\\\/');
  15562. }).join('|'); // must match entire pattern
  15563. // ending in a * or ** will make it less strict.
  15564. re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
  15565. if (this.negate) re = '^(?!' + re + ').*$';
  15566. try {
  15567. this.regexp = new RegExp(re, flags);
  15568. } catch (ex) {
  15569. this.regexp = false;
  15570. }
  15571. return this.regexp;
  15572. }
  15573. minimatch.match = function (list, pattern, options) {
  15574. options = options || {};
  15575. var mm = new Minimatch$1(pattern, options);
  15576. list = list.filter(function (f) {
  15577. return mm.match(f);
  15578. });
  15579. if (mm.options.nonull && !list.length) {
  15580. list.push(pattern);
  15581. }
  15582. return list;
  15583. };
  15584. Minimatch$1.prototype.match = match;
  15585. function match(f, partial) {
  15586. this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
  15587. // comments, etc.
  15588. if (this.comment) return false;
  15589. if (this.empty) return f === '';
  15590. if (f === '/' && partial) return true;
  15591. var options = this.options; // windows: need to use /, not \
  15592. if (path$2.sep !== '/') {
  15593. f = f.split(path$2.sep).join('/');
  15594. } // treat the test path as a set of pathparts.
  15595. f = f.split(slashSplit);
  15596. this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
  15597. // in order for it to be valid. If negating, then just one
  15598. // match means that we have failed.
  15599. // Either way, return on the first hit.
  15600. var set = this.set;
  15601. this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
  15602. var filename;
  15603. var i;
  15604. for (i = f.length - 1; i >= 0; i--) {
  15605. filename = f[i];
  15606. if (filename) break;
  15607. }
  15608. for (i = 0; i < set.length; i++) {
  15609. var pattern = set[i];
  15610. var file = f;
  15611. if (options.matchBase && pattern.length === 1) {
  15612. file = [filename];
  15613. }
  15614. var hit = this.matchOne(file, pattern, partial);
  15615. if (hit) {
  15616. if (options.flipNegate) return true;
  15617. return !this.negate;
  15618. }
  15619. } // didn't get any hits. this is success if it's a negative
  15620. // pattern, failure otherwise.
  15621. if (options.flipNegate) return false;
  15622. return this.negate;
  15623. } // set partial to true to test if, for example,
  15624. // "/a/b" matches the start of "/*/b/*/d"
  15625. // Partial means, if you run out of file before you run
  15626. // out of pattern, then that's fine, as long as all
  15627. // the parts match.
  15628. Minimatch$1.prototype.matchOne = function (file, pattern, partial) {
  15629. var options = this.options;
  15630. this.debug('matchOne', {
  15631. 'this': this,
  15632. file: file,
  15633. pattern: pattern
  15634. });
  15635. this.debug('matchOne', file.length, pattern.length);
  15636. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  15637. this.debug('matchOne loop');
  15638. var p = pattern[pi];
  15639. var f = file[fi];
  15640. this.debug(pattern, p, f); // should be impossible.
  15641. // some invalid regexp stuff in the set.
  15642. if (p === false) return false;
  15643. if (p === GLOBSTAR) {
  15644. this.debug('GLOBSTAR', [pattern, p, f]); // "**"
  15645. // a/**/b/**/c would match the following:
  15646. // a/b/x/y/z/c
  15647. // a/x/y/z/b/c
  15648. // a/b/x/b/x/c
  15649. // a/b/c
  15650. // To do this, take the rest of the pattern after
  15651. // the **, and see if it would match the file remainder.
  15652. // If so, return success.
  15653. // If not, the ** "swallows" a segment, and try again.
  15654. // This is recursively awful.
  15655. //
  15656. // a/**/b/**/c matching a/b/x/y/z/c
  15657. // - a matches a
  15658. // - doublestar
  15659. // - matchOne(b/x/y/z/c, b/**/c)
  15660. // - b matches b
  15661. // - doublestar
  15662. // - matchOne(x/y/z/c, c) -> no
  15663. // - matchOne(y/z/c, c) -> no
  15664. // - matchOne(z/c, c) -> no
  15665. // - matchOne(c, c) yes, hit
  15666. var fr = fi;
  15667. var pr = pi + 1;
  15668. if (pr === pl) {
  15669. this.debug('** at the end'); // a ** at the end will just swallow the rest.
  15670. // We have found a match.
  15671. // however, it will not swallow /.x, unless
  15672. // options.dot is set.
  15673. // . and .. are *never* matched by **, for explosively
  15674. // exponential reasons.
  15675. for (; fi < fl; fi++) {
  15676. if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
  15677. }
  15678. return true;
  15679. } // ok, let's see if we can swallow whatever we can.
  15680. while (fr < fl) {
  15681. var swallowee = file[fr];
  15682. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
  15683. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  15684. this.debug('globstar found match!', fr, fl, swallowee); // found a match.
  15685. return true;
  15686. } else {
  15687. // can't swallow "." or ".." ever.
  15688. // can only swallow ".foo" when explicitly asked.
  15689. if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
  15690. this.debug('dot detected!', file, fr, pattern, pr);
  15691. break;
  15692. } // ** swallows a segment, and continue.
  15693. this.debug('globstar swallow a segment, and continue');
  15694. fr++;
  15695. }
  15696. } // no match was found.
  15697. // However, in partial mode, we can't say this is necessarily over.
  15698. // If there's more *pattern* left, then
  15699. if (partial) {
  15700. // ran out of file
  15701. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  15702. if (fr === fl) return true;
  15703. }
  15704. return false;
  15705. } // something other than **
  15706. // non-magic patterns just have to match exactly
  15707. // patterns with magic have been turned into regexps.
  15708. var hit;
  15709. if (typeof p === 'string') {
  15710. if (options.nocase) {
  15711. hit = f.toLowerCase() === p.toLowerCase();
  15712. } else {
  15713. hit = f === p;
  15714. }
  15715. this.debug('string match', p, f, hit);
  15716. } else {
  15717. hit = f.match(p);
  15718. this.debug('pattern match', p, f, hit);
  15719. }
  15720. if (!hit) return false;
  15721. } // Note: ending in / means that we'll get a final ""
  15722. // at the end of the pattern. This can only match a
  15723. // corresponding "" at the end of the file.
  15724. // If the file ends in /, then it can only match a
  15725. // a pattern that ends in /, unless the pattern just
  15726. // doesn't have any more for it. But, a/b/ should *not*
  15727. // match "a/b/*", even though "" matches against the
  15728. // [^/]*? pattern, except in partial mode, where it might
  15729. // simply not be reached yet.
  15730. // However, a/b/ should still satisfy a/*
  15731. // now either we fell off the end of the pattern, or we're done.
  15732. if (fi === fl && pi === pl) {
  15733. // ran out of pattern and filename at the same time.
  15734. // an exact hit!
  15735. return true;
  15736. } else if (fi === fl) {
  15737. // ran out of file, but still had pattern left.
  15738. // this is ok if we're doing the match as part of
  15739. // a glob fs traversal.
  15740. return partial;
  15741. } else if (pi === pl) {
  15742. // ran out of pattern, still have file left.
  15743. // this is only acceptable if we're on the very last
  15744. // empty segment of a file with a trailing slash.
  15745. // a/* should match a/b/
  15746. var emptyFileEnd = fi === fl - 1 && file[fi] === '';
  15747. return emptyFileEnd;
  15748. } // should be unreachable.
  15749. throw new Error('wtf?');
  15750. }; // replace stuff like \* with *
  15751. function globUnescape(s) {
  15752. return s.replace(/\\(.)/g, '$1');
  15753. }
  15754. function regExpEscape(s) {
  15755. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
  15756. }
  15757. var inherits_browser = createCommonjsModule(function (module) {
  15758. if (typeof Object.create === 'function') {
  15759. // implementation from standard node.js 'util' module
  15760. module.exports = function inherits(ctor, superCtor) {
  15761. ctor.super_ = superCtor;
  15762. ctor.prototype = Object.create(superCtor.prototype, {
  15763. constructor: {
  15764. value: ctor,
  15765. enumerable: false,
  15766. writable: true,
  15767. configurable: true
  15768. }
  15769. });
  15770. };
  15771. } else {
  15772. // old school shim for old browsers
  15773. module.exports = function inherits(ctor, superCtor) {
  15774. ctor.super_ = superCtor;
  15775. var TempCtor = function TempCtor() {};
  15776. TempCtor.prototype = superCtor.prototype;
  15777. ctor.prototype = new TempCtor();
  15778. ctor.prototype.constructor = ctor;
  15779. };
  15780. }
  15781. });
  15782. var inherits = createCommonjsModule(function (module) {
  15783. try {
  15784. var util$$1 = util;
  15785. if (typeof util$$1.inherits !== 'function') throw '';
  15786. module.exports = util$$1.inherits;
  15787. } catch (e) {
  15788. module.exports = inherits_browser;
  15789. }
  15790. });
  15791. function posix(path$$1) {
  15792. return path$$1.charAt(0) === '/';
  15793. }
  15794. function win32(path$$1) {
  15795. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  15796. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  15797. var result = splitDeviceRe.exec(path$$1);
  15798. var device = result[1] || '';
  15799. var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
  15800. return Boolean(result[2] || isUnc);
  15801. }
  15802. var pathIsAbsolute = process.platform === 'win32' ? win32 : posix;
  15803. var posix_1 = posix;
  15804. var win32_1 = win32;
  15805. pathIsAbsolute.posix = posix_1;
  15806. pathIsAbsolute.win32 = win32_1;
  15807. var alphasort_1 = alphasort$2;
  15808. var alphasorti_1 = alphasorti$2;
  15809. var setopts_1 = setopts$2;
  15810. var ownProp_1 = ownProp$2;
  15811. var makeAbs_1 = makeAbs;
  15812. var finish_1 = finish;
  15813. var mark_1 = mark;
  15814. var isIgnored_1 = isIgnored$2;
  15815. var childrenIgnored_1 = childrenIgnored$2;
  15816. function ownProp$2(obj, field) {
  15817. return Object.prototype.hasOwnProperty.call(obj, field);
  15818. }
  15819. var Minimatch$3 = minimatch_1.Minimatch;
  15820. function alphasorti$2(a, b) {
  15821. return a.toLowerCase().localeCompare(b.toLowerCase());
  15822. }
  15823. function alphasort$2(a, b) {
  15824. return a.localeCompare(b);
  15825. }
  15826. function setupIgnores(self, options) {
  15827. self.ignore = options.ignore || [];
  15828. if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
  15829. if (self.ignore.length) {
  15830. self.ignore = self.ignore.map(ignoreMap);
  15831. }
  15832. } // ignore patterns are always in dot:true mode.
  15833. function ignoreMap(pattern) {
  15834. var gmatcher = null;
  15835. if (pattern.slice(-3) === '/**') {
  15836. var gpattern = pattern.replace(/(\/\*\*)+$/, '');
  15837. gmatcher = new Minimatch$3(gpattern, {
  15838. dot: true
  15839. });
  15840. }
  15841. return {
  15842. matcher: new Minimatch$3(pattern, {
  15843. dot: true
  15844. }),
  15845. gmatcher: gmatcher
  15846. };
  15847. }
  15848. function setopts$2(self, pattern, options) {
  15849. if (!options) options = {}; // base-matching: just use globstar for that.
  15850. if (options.matchBase && -1 === pattern.indexOf("/")) {
  15851. if (options.noglobstar) {
  15852. throw new Error("base matching requires globstar");
  15853. }
  15854. pattern = "**/" + pattern;
  15855. }
  15856. self.silent = !!options.silent;
  15857. self.pattern = pattern;
  15858. self.strict = options.strict !== false;
  15859. self.realpath = !!options.realpath;
  15860. self.realpathCache = options.realpathCache || Object.create(null);
  15861. self.follow = !!options.follow;
  15862. self.dot = !!options.dot;
  15863. self.mark = !!options.mark;
  15864. self.nodir = !!options.nodir;
  15865. if (self.nodir) self.mark = true;
  15866. self.sync = !!options.sync;
  15867. self.nounique = !!options.nounique;
  15868. self.nonull = !!options.nonull;
  15869. self.nosort = !!options.nosort;
  15870. self.nocase = !!options.nocase;
  15871. self.stat = !!options.stat;
  15872. self.noprocess = !!options.noprocess;
  15873. self.absolute = !!options.absolute;
  15874. self.maxLength = options.maxLength || Infinity;
  15875. self.cache = options.cache || Object.create(null);
  15876. self.statCache = options.statCache || Object.create(null);
  15877. self.symlinks = options.symlinks || Object.create(null);
  15878. setupIgnores(self, options);
  15879. self.changedCwd = false;
  15880. var cwd = process.cwd();
  15881. if (!ownProp$2(options, "cwd")) self.cwd = cwd;else {
  15882. self.cwd = path.resolve(options.cwd);
  15883. self.changedCwd = self.cwd !== cwd;
  15884. }
  15885. self.root = options.root || path.resolve(self.cwd, "/");
  15886. self.root = path.resolve(self.root);
  15887. if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  15888. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  15889. self.cwdAbs = pathIsAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
  15890. if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
  15891. self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
  15892. // Note that they are not supported in Glob itself anyway.
  15893. options.nonegate = true;
  15894. options.nocomment = true;
  15895. self.minimatch = new Minimatch$3(pattern, options);
  15896. self.options = self.minimatch.options;
  15897. }
  15898. function finish(self) {
  15899. var nou = self.nounique;
  15900. var all = nou ? [] : Object.create(null);
  15901. for (var i = 0, l = self.matches.length; i < l; i++) {
  15902. var matches = self.matches[i];
  15903. if (!matches || Object.keys(matches).length === 0) {
  15904. if (self.nonull) {
  15905. // do like the shell, and spit out the literal glob
  15906. var literal = self.minimatch.globSet[i];
  15907. if (nou) all.push(literal);else all[literal] = true;
  15908. }
  15909. } else {
  15910. // had matches
  15911. var m = Object.keys(matches);
  15912. if (nou) all.push.apply(all, m);else m.forEach(function (m) {
  15913. all[m] = true;
  15914. });
  15915. }
  15916. }
  15917. if (!nou) all = Object.keys(all);
  15918. if (!self.nosort) all = all.sort(self.nocase ? alphasorti$2 : alphasort$2); // at *some* point we statted all of these
  15919. if (self.mark) {
  15920. for (var i = 0; i < all.length; i++) {
  15921. all[i] = self._mark(all[i]);
  15922. }
  15923. if (self.nodir) {
  15924. all = all.filter(function (e) {
  15925. var notDir = !/\/$/.test(e);
  15926. var c = self.cache[e] || self.cache[makeAbs(self, e)];
  15927. if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
  15928. return notDir;
  15929. });
  15930. }
  15931. }
  15932. if (self.ignore.length) all = all.filter(function (m) {
  15933. return !isIgnored$2(self, m);
  15934. });
  15935. self.found = all;
  15936. }
  15937. function mark(self, p) {
  15938. var abs = makeAbs(self, p);
  15939. var c = self.cache[abs];
  15940. var m = p;
  15941. if (c) {
  15942. var isDir = c === 'DIR' || Array.isArray(c);
  15943. var slash = p.slice(-1) === '/';
  15944. if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
  15945. if (m !== p) {
  15946. var mabs = makeAbs(self, m);
  15947. self.statCache[mabs] = self.statCache[abs];
  15948. self.cache[mabs] = self.cache[abs];
  15949. }
  15950. }
  15951. return m;
  15952. } // lotta situps...
  15953. function makeAbs(self, f) {
  15954. var abs = f;
  15955. if (f.charAt(0) === '/') {
  15956. abs = path.join(self.root, f);
  15957. } else if (pathIsAbsolute(f) || f === '') {
  15958. abs = f;
  15959. } else if (self.changedCwd) {
  15960. abs = path.resolve(self.cwd, f);
  15961. } else {
  15962. abs = path.resolve(f);
  15963. }
  15964. if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
  15965. return abs;
  15966. } // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  15967. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  15968. function isIgnored$2(self, path$$2) {
  15969. if (!self.ignore.length) return false;
  15970. return self.ignore.some(function (item) {
  15971. return item.matcher.match(path$$2) || !!(item.gmatcher && item.gmatcher.match(path$$2));
  15972. });
  15973. }
  15974. function childrenIgnored$2(self, path$$2) {
  15975. if (!self.ignore.length) return false;
  15976. return self.ignore.some(function (item) {
  15977. return !!(item.gmatcher && item.gmatcher.match(path$$2));
  15978. });
  15979. }
  15980. var common$4 = {
  15981. alphasort: alphasort_1,
  15982. alphasorti: alphasorti_1,
  15983. setopts: setopts_1,
  15984. ownProp: ownProp_1,
  15985. makeAbs: makeAbs_1,
  15986. finish: finish_1,
  15987. mark: mark_1,
  15988. isIgnored: isIgnored_1,
  15989. childrenIgnored: childrenIgnored_1
  15990. };
  15991. var sync$1 = globSync;
  15992. globSync.GlobSync = GlobSync$1;
  15993. var setopts$1 = common$4.setopts;
  15994. var ownProp$1 = common$4.ownProp;
  15995. var childrenIgnored$1 = common$4.childrenIgnored;
  15996. var isIgnored$1 = common$4.isIgnored;
  15997. function globSync(pattern, options) {
  15998. 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');
  15999. return new GlobSync$1(pattern, options).found;
  16000. }
  16001. function GlobSync$1(pattern, options) {
  16002. if (!pattern) throw new Error('must provide pattern');
  16003. 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');
  16004. if (!(this instanceof GlobSync$1)) return new GlobSync$1(pattern, options);
  16005. setopts$1(this, pattern, options);
  16006. if (this.noprocess) return this;
  16007. var n = this.minimatch.set.length;
  16008. this.matches = new Array(n);
  16009. for (var i = 0; i < n; i++) {
  16010. this._process(this.minimatch.set[i], i, false);
  16011. }
  16012. this._finish();
  16013. }
  16014. GlobSync$1.prototype._finish = function () {
  16015. assert(this instanceof GlobSync$1);
  16016. if (this.realpath) {
  16017. var self = this;
  16018. this.matches.forEach(function (matchset, index) {
  16019. var set = self.matches[index] = Object.create(null);
  16020. for (var p in matchset) {
  16021. try {
  16022. p = self._makeAbs(p);
  16023. var real = fs_realpath.realpathSync(p, self.realpathCache);
  16024. set[real] = true;
  16025. } catch (er) {
  16026. if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
  16027. }
  16028. }
  16029. });
  16030. }
  16031. common$4.finish(this);
  16032. };
  16033. GlobSync$1.prototype._process = function (pattern, index, inGlobStar) {
  16034. assert(this instanceof GlobSync$1); // Get the first [n] parts of pattern that are all strings.
  16035. var n = 0;
  16036. while (typeof pattern[n] === 'string') {
  16037. n++;
  16038. } // now n is the index of the first one that is *not* a string.
  16039. // See if there's anything else
  16040. var prefix;
  16041. switch (n) {
  16042. // if not, then this is rather simple
  16043. case pattern.length:
  16044. this._processSimple(pattern.join('/'), index);
  16045. return;
  16046. case 0:
  16047. // pattern *starts* with some non-trivial item.
  16048. // going to readdir(cwd), but not include the prefix in matches.
  16049. prefix = null;
  16050. break;
  16051. default:
  16052. // pattern has some string bits in the front.
  16053. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  16054. // or 'relative' like '../baz'
  16055. prefix = pattern.slice(0, n).join('/');
  16056. break;
  16057. }
  16058. var remain = pattern.slice(n); // get the list of entries.
  16059. var read;
  16060. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  16061. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  16062. read = prefix;
  16063. } else read = prefix;
  16064. var abs = this._makeAbs(read); //if ignored, skip processing
  16065. if (childrenIgnored$1(this, read)) return;
  16066. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  16067. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
  16068. };
  16069. GlobSync$1.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  16070. var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
  16071. if (!entries) return; // It will only match dot entries if it starts with a dot, or if
  16072. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  16073. var pn = remain[0];
  16074. var negate = !!this.minimatch.negate;
  16075. var rawGlob = pn._glob;
  16076. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  16077. var matchedEntries = [];
  16078. for (var i = 0; i < entries.length; i++) {
  16079. var e = entries[i];
  16080. if (e.charAt(0) !== '.' || dotOk) {
  16081. var m;
  16082. if (negate && !prefix) {
  16083. m = !e.match(pn);
  16084. } else {
  16085. m = e.match(pn);
  16086. }
  16087. if (m) matchedEntries.push(e);
  16088. }
  16089. }
  16090. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  16091. if (len === 0) return; // if this is the last remaining pattern bit, then no need for
  16092. // an additional stat *unless* the user has specified mark or
  16093. // stat explicitly. We know they exist, since readdir returned
  16094. // them.
  16095. if (remain.length === 1 && !this.mark && !this.stat) {
  16096. if (!this.matches[index]) this.matches[index] = Object.create(null);
  16097. for (var i = 0; i < len; i++) {
  16098. var e = matchedEntries[i];
  16099. if (prefix) {
  16100. if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
  16101. }
  16102. if (e.charAt(0) === '/' && !this.nomount) {
  16103. e = path.join(this.root, e);
  16104. }
  16105. this._emitMatch(index, e);
  16106. } // This was the last one, and no stats were needed
  16107. return;
  16108. } // now test all matched entries as stand-ins for that part
  16109. // of the pattern.
  16110. remain.shift();
  16111. for (var i = 0; i < len; i++) {
  16112. var e = matchedEntries[i];
  16113. var newPattern;
  16114. if (prefix) newPattern = [prefix, e];else newPattern = [e];
  16115. this._process(newPattern.concat(remain), index, inGlobStar);
  16116. }
  16117. };
  16118. GlobSync$1.prototype._emitMatch = function (index, e) {
  16119. if (isIgnored$1(this, e)) return;
  16120. var abs = this._makeAbs(e);
  16121. if (this.mark) e = this._mark(e);
  16122. if (this.absolute) {
  16123. e = abs;
  16124. }
  16125. if (this.matches[index][e]) return;
  16126. if (this.nodir) {
  16127. var c = this.cache[abs];
  16128. if (c === 'DIR' || Array.isArray(c)) return;
  16129. }
  16130. this.matches[index][e] = true;
  16131. if (this.stat) this._stat(e);
  16132. };
  16133. GlobSync$1.prototype._readdirInGlobStar = function (abs) {
  16134. // follow all symlinked directories forever
  16135. // just proceed as if this is a non-globstar situation
  16136. if (this.follow) return this._readdir(abs, false);
  16137. var entries;
  16138. var lstat;
  16139. var stat;
  16140. try {
  16141. lstat = fs.lstatSync(abs);
  16142. } catch (er) {
  16143. if (er.code === 'ENOENT') {
  16144. // lstat failed, doesn't exist
  16145. return null;
  16146. }
  16147. }
  16148. var isSym = lstat && lstat.isSymbolicLink();
  16149. this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  16150. // don't bother doing a readdir in that case.
  16151. if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
  16152. return entries;
  16153. };
  16154. GlobSync$1.prototype._readdir = function (abs, inGlobStar) {
  16155. var entries;
  16156. if (inGlobStar && !ownProp$1(this.symlinks, abs)) return this._readdirInGlobStar(abs);
  16157. if (ownProp$1(this.cache, abs)) {
  16158. var c = this.cache[abs];
  16159. if (!c || c === 'FILE') return null;
  16160. if (Array.isArray(c)) return c;
  16161. }
  16162. try {
  16163. return this._readdirEntries(abs, fs.readdirSync(abs));
  16164. } catch (er) {
  16165. this._readdirError(abs, er);
  16166. return null;
  16167. }
  16168. };
  16169. GlobSync$1.prototype._readdirEntries = function (abs, entries) {
  16170. // if we haven't asked to stat everything, then just
  16171. // assume that everything in there exists, so we can avoid
  16172. // having to stat it a second time.
  16173. if (!this.mark && !this.stat) {
  16174. for (var i = 0; i < entries.length; i++) {
  16175. var e = entries[i];
  16176. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  16177. this.cache[e] = true;
  16178. }
  16179. }
  16180. this.cache[abs] = entries; // mark and cache dir-ness
  16181. return entries;
  16182. };
  16183. GlobSync$1.prototype._readdirError = function (f, er) {
  16184. // handle errors, and cache the information
  16185. switch (er.code) {
  16186. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  16187. case 'ENOTDIR':
  16188. // totally normal. means it *does* exist.
  16189. var abs = this._makeAbs(f);
  16190. this.cache[abs] = 'FILE';
  16191. if (abs === this.cwdAbs) {
  16192. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  16193. error.path = this.cwd;
  16194. error.code = er.code;
  16195. throw error;
  16196. }
  16197. break;
  16198. case 'ENOENT': // not terribly unusual
  16199. case 'ELOOP':
  16200. case 'ENAMETOOLONG':
  16201. case 'UNKNOWN':
  16202. this.cache[this._makeAbs(f)] = false;
  16203. break;
  16204. default:
  16205. // some unusual error. Treat as failure.
  16206. this.cache[this._makeAbs(f)] = false;
  16207. if (this.strict) throw er;
  16208. if (!this.silent) console.error('glob error', er);
  16209. break;
  16210. }
  16211. };
  16212. GlobSync$1.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  16213. var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
  16214. // foo.txt/** doesn't match foo.txt
  16215. if (!entries) return; // test without the globstar, and with every child both below
  16216. // and replacing the globstar.
  16217. var remainWithoutGlobStar = remain.slice(1);
  16218. var gspref = prefix ? [prefix] : [];
  16219. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  16220. this._process(noGlobStar, index, false);
  16221. var len = entries.length;
  16222. var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
  16223. if (isSym && inGlobStar) return;
  16224. for (var i = 0; i < len; i++) {
  16225. var e = entries[i];
  16226. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  16227. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  16228. this._process(instead, index, true);
  16229. var below = gspref.concat(entries[i], remain);
  16230. this._process(below, index, true);
  16231. }
  16232. };
  16233. GlobSync$1.prototype._processSimple = function (prefix, index) {
  16234. // XXX review this. Shouldn't it be doing the mounting etc
  16235. // before doing stat? kinda weird?
  16236. var exists = this._stat(prefix);
  16237. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  16238. if (!exists) return;
  16239. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  16240. var trail = /[\/\\]$/.test(prefix);
  16241. if (prefix.charAt(0) === '/') {
  16242. prefix = path.join(this.root, prefix);
  16243. } else {
  16244. prefix = path.resolve(this.root, prefix);
  16245. if (trail) prefix += '/';
  16246. }
  16247. }
  16248. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  16249. this._emitMatch(index, prefix);
  16250. }; // Returns either 'DIR', 'FILE', or false
  16251. GlobSync$1.prototype._stat = function (f) {
  16252. var abs = this._makeAbs(f);
  16253. var needDir = f.slice(-1) === '/';
  16254. if (f.length > this.maxLength) return false;
  16255. if (!this.stat && ownProp$1(this.cache, abs)) {
  16256. var c = this.cache[abs];
  16257. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  16258. if (!needDir || c === 'DIR') return c;
  16259. if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
  16260. // if we know it exists, but not what it is.
  16261. }
  16262. var exists;
  16263. var stat = this.statCache[abs];
  16264. if (!stat) {
  16265. var lstat;
  16266. try {
  16267. lstat = fs.lstatSync(abs);
  16268. } catch (er) {
  16269. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  16270. this.statCache[abs] = false;
  16271. return false;
  16272. }
  16273. }
  16274. if (lstat && lstat.isSymbolicLink()) {
  16275. try {
  16276. stat = fs.statSync(abs);
  16277. } catch (er) {
  16278. stat = lstat;
  16279. }
  16280. } else {
  16281. stat = lstat;
  16282. }
  16283. }
  16284. this.statCache[abs] = stat;
  16285. var c = true;
  16286. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  16287. this.cache[abs] = this.cache[abs] || c;
  16288. if (needDir && c === 'FILE') return false;
  16289. return c;
  16290. };
  16291. GlobSync$1.prototype._mark = function (p) {
  16292. return common$4.mark(this, p);
  16293. };
  16294. GlobSync$1.prototype._makeAbs = function (f) {
  16295. return common$4.makeAbs(this, f);
  16296. };
  16297. // Returns a wrapper function that returns a wrapped callback
  16298. // The wrapper function should do some stuff, and return a
  16299. // presumably different callback function.
  16300. // This makes sure that own properties are retained, so that
  16301. // decorations and such are not lost along the way.
  16302. var wrappy_1 = wrappy;
  16303. function wrappy(fn, cb) {
  16304. if (fn && cb) return wrappy(fn)(cb);
  16305. if (typeof fn !== 'function') throw new TypeError('need wrapper function');
  16306. Object.keys(fn).forEach(function (k) {
  16307. wrapper[k] = fn[k];
  16308. });
  16309. return wrapper;
  16310. function wrapper() {
  16311. var args = new Array(arguments.length);
  16312. for (var i = 0; i < args.length; i++) {
  16313. args[i] = arguments[i];
  16314. }
  16315. var ret = fn.apply(this, args);
  16316. var cb = args[args.length - 1];
  16317. if (typeof ret === 'function' && ret !== cb) {
  16318. Object.keys(cb).forEach(function (k) {
  16319. ret[k] = cb[k];
  16320. });
  16321. }
  16322. return ret;
  16323. }
  16324. }
  16325. var once_1 = wrappy_1(once);
  16326. var strict = wrappy_1(onceStrict);
  16327. once.proto = once(function () {
  16328. Object.defineProperty(Function.prototype, 'once', {
  16329. value: function value() {
  16330. return once(this);
  16331. },
  16332. configurable: true
  16333. });
  16334. Object.defineProperty(Function.prototype, 'onceStrict', {
  16335. value: function value() {
  16336. return onceStrict(this);
  16337. },
  16338. configurable: true
  16339. });
  16340. });
  16341. function once(fn) {
  16342. var f = function f() {
  16343. if (f.called) return f.value;
  16344. f.called = true;
  16345. return f.value = fn.apply(this, arguments);
  16346. };
  16347. f.called = false;
  16348. return f;
  16349. }
  16350. function onceStrict(fn) {
  16351. var f = function f() {
  16352. if (f.called) throw new Error(f.onceError);
  16353. f.called = true;
  16354. return f.value = fn.apply(this, arguments);
  16355. };
  16356. var name = fn.name || 'Function wrapped with `once`';
  16357. f.onceError = name + " shouldn't be called more than once";
  16358. f.called = false;
  16359. return f;
  16360. }
  16361. once_1.strict = strict;
  16362. var reqs = Object.create(null);
  16363. var inflight_1 = wrappy_1(inflight);
  16364. function inflight(key, cb) {
  16365. if (reqs[key]) {
  16366. reqs[key].push(cb);
  16367. return null;
  16368. } else {
  16369. reqs[key] = [cb];
  16370. return makeres(key);
  16371. }
  16372. }
  16373. function makeres(key) {
  16374. return once_1(function RES() {
  16375. var cbs = reqs[key];
  16376. var len = cbs.length;
  16377. var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
  16378. // pass should be queued for later execution if something in the
  16379. // list of callbacks throws, or if it should just be discarded.
  16380. // However, it's such an edge case that it hardly matters, and either
  16381. // choice is likely as surprising as the other.
  16382. // As it happens, we do go ahead and schedule it for later execution.
  16383. try {
  16384. for (var i = 0; i < len; i++) {
  16385. cbs[i].apply(null, args);
  16386. }
  16387. } finally {
  16388. if (cbs.length > len) {
  16389. // added more in the interim.
  16390. // de-zalgo, just in case, but don't call again.
  16391. cbs.splice(0, len);
  16392. process.nextTick(function () {
  16393. RES.apply(null, args);
  16394. });
  16395. } else {
  16396. delete reqs[key];
  16397. }
  16398. }
  16399. });
  16400. }
  16401. function slice(args) {
  16402. var length = args.length;
  16403. var array = [];
  16404. for (var i = 0; i < length; i++) {
  16405. array[i] = args[i];
  16406. }
  16407. return array;
  16408. }
  16409. //
  16410. // 1. Get the minimatch set
  16411. // 2. For each pattern in the set, PROCESS(pattern, false)
  16412. // 3. Store matches per-set, then uniq them
  16413. //
  16414. // PROCESS(pattern, inGlobStar)
  16415. // Get the first [n] items from pattern that are all strings
  16416. // Join these together. This is PREFIX.
  16417. // If there is no more remaining, then stat(PREFIX) and
  16418. // add to matches if it succeeds. END.
  16419. //
  16420. // If inGlobStar and PREFIX is symlink and points to dir
  16421. // set ENTRIES = []
  16422. // else readdir(PREFIX) as ENTRIES
  16423. // If fail, END
  16424. //
  16425. // with ENTRIES
  16426. // If pattern[n] is GLOBSTAR
  16427. // // handle the case where the globstar match is empty
  16428. // // by pruning it out, and testing the resulting pattern
  16429. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  16430. // // handle other cases.
  16431. // for ENTRY in ENTRIES (not dotfiles)
  16432. // // attach globstar + tail onto the entry
  16433. // // Mark that this entry is a globstar match
  16434. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  16435. //
  16436. // else // not globstar
  16437. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  16438. // Test ENTRY against pattern[n]
  16439. // If fails, continue
  16440. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  16441. //
  16442. // Caveat:
  16443. // Cache all stats and readdirs results to minimize syscall. Since all
  16444. // we ever care about is existence and directory-ness, we can just keep
  16445. // `true` for files, and [children,...] for directories, or `false` for
  16446. // things that don't exist.
  16447. var glob_1 = glob;
  16448. var EE = events.EventEmitter;
  16449. var setopts = common$4.setopts;
  16450. var ownProp = common$4.ownProp;
  16451. var childrenIgnored = common$4.childrenIgnored;
  16452. var isIgnored = common$4.isIgnored;
  16453. function glob(pattern, options, cb) {
  16454. if (typeof options === 'function') cb = options, options = {};
  16455. if (!options) options = {};
  16456. if (options.sync) {
  16457. if (cb) throw new TypeError('callback provided to sync glob');
  16458. return sync$1(pattern, options);
  16459. }
  16460. return new Glob(pattern, options, cb);
  16461. }
  16462. glob.sync = sync$1;
  16463. var GlobSync = glob.GlobSync = sync$1.GlobSync; // old api surface
  16464. glob.glob = glob;
  16465. function extend(origin, add) {
  16466. if (add === null || typeof add !== 'object') {
  16467. return origin;
  16468. }
  16469. var keys = Object.keys(add);
  16470. var i = keys.length;
  16471. while (i--) {
  16472. origin[keys[i]] = add[keys[i]];
  16473. }
  16474. return origin;
  16475. }
  16476. glob.hasMagic = function (pattern, options_) {
  16477. var options = extend({}, options_);
  16478. options.noprocess = true;
  16479. var g = new Glob(pattern, options);
  16480. var set = g.minimatch.set;
  16481. if (!pattern) return false;
  16482. if (set.length > 1) return true;
  16483. for (var j = 0; j < set[0].length; j++) {
  16484. if (typeof set[0][j] !== 'string') return true;
  16485. }
  16486. return false;
  16487. };
  16488. glob.Glob = Glob;
  16489. inherits(Glob, EE);
  16490. function Glob(pattern, options, cb) {
  16491. if (typeof options === 'function') {
  16492. cb = options;
  16493. options = null;
  16494. }
  16495. if (options && options.sync) {
  16496. if (cb) throw new TypeError('callback provided to sync glob');
  16497. return new GlobSync(pattern, options);
  16498. }
  16499. if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
  16500. setopts(this, pattern, options);
  16501. this._didRealPath = false; // process each pattern in the minimatch set
  16502. var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
  16503. // duplicates are automagically pruned.
  16504. // Later, we do an Object.keys() on these.
  16505. // Keep them as a list so we can fill in when nonull is set.
  16506. this.matches = new Array(n);
  16507. if (typeof cb === 'function') {
  16508. cb = once_1(cb);
  16509. this.on('error', cb);
  16510. this.on('end', function (matches) {
  16511. cb(null, matches);
  16512. });
  16513. }
  16514. var self = this;
  16515. this._processing = 0;
  16516. this._emitQueue = [];
  16517. this._processQueue = [];
  16518. this.paused = false;
  16519. if (this.noprocess) return this;
  16520. if (n === 0) return done();
  16521. var sync = true;
  16522. for (var i = 0; i < n; i++) {
  16523. this._process(this.minimatch.set[i], i, false, done);
  16524. }
  16525. sync = false;
  16526. function done() {
  16527. --self._processing;
  16528. if (self._processing <= 0) {
  16529. if (sync) {
  16530. process.nextTick(function () {
  16531. self._finish();
  16532. });
  16533. } else {
  16534. self._finish();
  16535. }
  16536. }
  16537. }
  16538. }
  16539. Glob.prototype._finish = function () {
  16540. assert(this instanceof Glob);
  16541. if (this.aborted) return;
  16542. if (this.realpath && !this._didRealpath) return this._realpath();
  16543. common$4.finish(this);
  16544. this.emit('end', this.found);
  16545. };
  16546. Glob.prototype._realpath = function () {
  16547. if (this._didRealpath) return;
  16548. this._didRealpath = true;
  16549. var n = this.matches.length;
  16550. if (n === 0) return this._finish();
  16551. var self = this;
  16552. for (var i = 0; i < this.matches.length; i++) {
  16553. this._realpathSet(i, next);
  16554. }
  16555. function next() {
  16556. if (--n === 0) self._finish();
  16557. }
  16558. };
  16559. Glob.prototype._realpathSet = function (index, cb) {
  16560. var matchset = this.matches[index];
  16561. if (!matchset) return cb();
  16562. var found = Object.keys(matchset);
  16563. var self = this;
  16564. var n = found.length;
  16565. if (n === 0) return cb();
  16566. var set = this.matches[index] = Object.create(null);
  16567. found.forEach(function (p, i) {
  16568. // If there's a problem with the stat, then it means that
  16569. // one or more of the links in the realpath couldn't be
  16570. // resolved. just return the abs value in that case.
  16571. p = self._makeAbs(p);
  16572. fs_realpath.realpath(p, self.realpathCache, function (er, real) {
  16573. if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
  16574. if (--n === 0) {
  16575. self.matches[index] = set;
  16576. cb();
  16577. }
  16578. });
  16579. });
  16580. };
  16581. Glob.prototype._mark = function (p) {
  16582. return common$4.mark(this, p);
  16583. };
  16584. Glob.prototype._makeAbs = function (f) {
  16585. return common$4.makeAbs(this, f);
  16586. };
  16587. Glob.prototype.abort = function () {
  16588. this.aborted = true;
  16589. this.emit('abort');
  16590. };
  16591. Glob.prototype.pause = function () {
  16592. if (!this.paused) {
  16593. this.paused = true;
  16594. this.emit('pause');
  16595. }
  16596. };
  16597. Glob.prototype.resume = function () {
  16598. if (this.paused) {
  16599. this.emit('resume');
  16600. this.paused = false;
  16601. if (this._emitQueue.length) {
  16602. var eq = this._emitQueue.slice(0);
  16603. this._emitQueue.length = 0;
  16604. for (var i = 0; i < eq.length; i++) {
  16605. var e = eq[i];
  16606. this._emitMatch(e[0], e[1]);
  16607. }
  16608. }
  16609. if (this._processQueue.length) {
  16610. var pq = this._processQueue.slice(0);
  16611. this._processQueue.length = 0;
  16612. for (var i = 0; i < pq.length; i++) {
  16613. var p = pq[i];
  16614. this._processing--;
  16615. this._process(p[0], p[1], p[2], p[3]);
  16616. }
  16617. }
  16618. }
  16619. };
  16620. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  16621. assert(this instanceof Glob);
  16622. assert(typeof cb === 'function');
  16623. if (this.aborted) return;
  16624. this._processing++;
  16625. if (this.paused) {
  16626. this._processQueue.push([pattern, index, inGlobStar, cb]);
  16627. return;
  16628. } //console.error('PROCESS %d', this._processing, pattern)
  16629. // Get the first [n] parts of pattern that are all strings.
  16630. var n = 0;
  16631. while (typeof pattern[n] === 'string') {
  16632. n++;
  16633. } // now n is the index of the first one that is *not* a string.
  16634. // see if there's anything else
  16635. var prefix;
  16636. switch (n) {
  16637. // if not, then this is rather simple
  16638. case pattern.length:
  16639. this._processSimple(pattern.join('/'), index, cb);
  16640. return;
  16641. case 0:
  16642. // pattern *starts* with some non-trivial item.
  16643. // going to readdir(cwd), but not include the prefix in matches.
  16644. prefix = null;
  16645. break;
  16646. default:
  16647. // pattern has some string bits in the front.
  16648. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  16649. // or 'relative' like '../baz'
  16650. prefix = pattern.slice(0, n).join('/');
  16651. break;
  16652. }
  16653. var remain = pattern.slice(n); // get the list of entries.
  16654. var read;
  16655. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  16656. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  16657. read = prefix;
  16658. } else read = prefix;
  16659. var abs = this._makeAbs(read); //if ignored, skip _processing
  16660. if (childrenIgnored(this, read)) return cb();
  16661. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  16662. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
  16663. };
  16664. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  16665. var self = this;
  16666. this._readdir(abs, inGlobStar, function (er, entries) {
  16667. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  16668. });
  16669. };
  16670. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  16671. // if the abs isn't a dir, then nothing can match!
  16672. if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
  16673. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  16674. var pn = remain[0];
  16675. var negate = !!this.minimatch.negate;
  16676. var rawGlob = pn._glob;
  16677. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  16678. var matchedEntries = [];
  16679. for (var i = 0; i < entries.length; i++) {
  16680. var e = entries[i];
  16681. if (e.charAt(0) !== '.' || dotOk) {
  16682. var m;
  16683. if (negate && !prefix) {
  16684. m = !e.match(pn);
  16685. } else {
  16686. m = e.match(pn);
  16687. }
  16688. if (m) matchedEntries.push(e);
  16689. }
  16690. } //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  16691. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  16692. if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
  16693. // an additional stat *unless* the user has specified mark or
  16694. // stat explicitly. We know they exist, since readdir returned
  16695. // them.
  16696. if (remain.length === 1 && !this.mark && !this.stat) {
  16697. if (!this.matches[index]) this.matches[index] = Object.create(null);
  16698. for (var i = 0; i < len; i++) {
  16699. var e = matchedEntries[i];
  16700. if (prefix) {
  16701. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  16702. }
  16703. if (e.charAt(0) === '/' && !this.nomount) {
  16704. e = path.join(this.root, e);
  16705. }
  16706. this._emitMatch(index, e);
  16707. } // This was the last one, and no stats were needed
  16708. return cb();
  16709. } // now test all matched entries as stand-ins for that part
  16710. // of the pattern.
  16711. remain.shift();
  16712. for (var i = 0; i < len; i++) {
  16713. var e = matchedEntries[i];
  16714. var newPattern;
  16715. if (prefix) {
  16716. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  16717. }
  16718. this._process([e].concat(remain), index, inGlobStar, cb);
  16719. }
  16720. cb();
  16721. };
  16722. Glob.prototype._emitMatch = function (index, e) {
  16723. if (this.aborted) return;
  16724. if (isIgnored(this, e)) return;
  16725. if (this.paused) {
  16726. this._emitQueue.push([index, e]);
  16727. return;
  16728. }
  16729. var abs = pathIsAbsolute(e) ? e : this._makeAbs(e);
  16730. if (this.mark) e = this._mark(e);
  16731. if (this.absolute) e = abs;
  16732. if (this.matches[index][e]) return;
  16733. if (this.nodir) {
  16734. var c = this.cache[abs];
  16735. if (c === 'DIR' || Array.isArray(c)) return;
  16736. }
  16737. this.matches[index][e] = true;
  16738. var st = this.statCache[abs];
  16739. if (st) this.emit('stat', e, st);
  16740. this.emit('match', e);
  16741. };
  16742. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  16743. if (this.aborted) return; // follow all symlinked directories forever
  16744. // just proceed as if this is a non-globstar situation
  16745. if (this.follow) return this._readdir(abs, false, cb);
  16746. var lstatkey = 'lstat\0' + abs;
  16747. var self = this;
  16748. var lstatcb = inflight_1(lstatkey, lstatcb_);
  16749. if (lstatcb) fs.lstat(abs, lstatcb);
  16750. function lstatcb_(er, lstat) {
  16751. if (er && er.code === 'ENOENT') return cb();
  16752. var isSym = lstat && lstat.isSymbolicLink();
  16753. self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  16754. // don't bother doing a readdir in that case.
  16755. if (!isSym && lstat && !lstat.isDirectory()) {
  16756. self.cache[abs] = 'FILE';
  16757. cb();
  16758. } else self._readdir(abs, false, cb);
  16759. }
  16760. };
  16761. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  16762. if (this.aborted) return;
  16763. cb = inflight_1('readdir\0' + abs + '\0' + inGlobStar, cb);
  16764. if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
  16765. if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
  16766. if (ownProp(this.cache, abs)) {
  16767. var c = this.cache[abs];
  16768. if (!c || c === 'FILE') return cb();
  16769. if (Array.isArray(c)) return cb(null, c);
  16770. }
  16771. var self = this;
  16772. fs.readdir(abs, readdirCb(this, abs, cb));
  16773. };
  16774. function readdirCb(self, abs, cb) {
  16775. return function (er, entries) {
  16776. if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
  16777. };
  16778. }
  16779. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  16780. if (this.aborted) return; // if we haven't asked to stat everything, then just
  16781. // assume that everything in there exists, so we can avoid
  16782. // having to stat it a second time.
  16783. if (!this.mark && !this.stat) {
  16784. for (var i = 0; i < entries.length; i++) {
  16785. var e = entries[i];
  16786. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  16787. this.cache[e] = true;
  16788. }
  16789. }
  16790. this.cache[abs] = entries;
  16791. return cb(null, entries);
  16792. };
  16793. Glob.prototype._readdirError = function (f, er, cb) {
  16794. if (this.aborted) return; // handle errors, and cache the information
  16795. switch (er.code) {
  16796. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  16797. case 'ENOTDIR':
  16798. // totally normal. means it *does* exist.
  16799. var abs = this._makeAbs(f);
  16800. this.cache[abs] = 'FILE';
  16801. if (abs === this.cwdAbs) {
  16802. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  16803. error.path = this.cwd;
  16804. error.code = er.code;
  16805. this.emit('error', error);
  16806. this.abort();
  16807. }
  16808. break;
  16809. case 'ENOENT': // not terribly unusual
  16810. case 'ELOOP':
  16811. case 'ENAMETOOLONG':
  16812. case 'UNKNOWN':
  16813. this.cache[this._makeAbs(f)] = false;
  16814. break;
  16815. default:
  16816. // some unusual error. Treat as failure.
  16817. this.cache[this._makeAbs(f)] = false;
  16818. if (this.strict) {
  16819. this.emit('error', er); // If the error is handled, then we abort
  16820. // if not, we threw out of here
  16821. this.abort();
  16822. }
  16823. if (!this.silent) console.error('glob error', er);
  16824. break;
  16825. }
  16826. return cb();
  16827. };
  16828. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  16829. var self = this;
  16830. this._readdir(abs, inGlobStar, function (er, entries) {
  16831. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  16832. });
  16833. };
  16834. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  16835. //console.error('pgs2', prefix, remain[0], entries)
  16836. // no entries means not a dir, so it can never have matches
  16837. // foo.txt/** doesn't match foo.txt
  16838. if (!entries) return cb(); // test without the globstar, and with every child both below
  16839. // and replacing the globstar.
  16840. var remainWithoutGlobStar = remain.slice(1);
  16841. var gspref = prefix ? [prefix] : [];
  16842. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  16843. this._process(noGlobStar, index, false, cb);
  16844. var isSym = this.symlinks[abs];
  16845. var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
  16846. if (isSym && inGlobStar) return cb();
  16847. for (var i = 0; i < len; i++) {
  16848. var e = entries[i];
  16849. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  16850. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  16851. this._process(instead, index, true, cb);
  16852. var below = gspref.concat(entries[i], remain);
  16853. this._process(below, index, true, cb);
  16854. }
  16855. cb();
  16856. };
  16857. Glob.prototype._processSimple = function (prefix, index, cb) {
  16858. // XXX review this. Shouldn't it be doing the mounting etc
  16859. // before doing stat? kinda weird?
  16860. var self = this;
  16861. this._stat(prefix, function (er, exists) {
  16862. self._processSimple2(prefix, index, er, exists, cb);
  16863. });
  16864. };
  16865. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  16866. //console.error('ps2', prefix, exists)
  16867. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  16868. if (!exists) return cb();
  16869. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  16870. var trail = /[\/\\]$/.test(prefix);
  16871. if (prefix.charAt(0) === '/') {
  16872. prefix = path.join(this.root, prefix);
  16873. } else {
  16874. prefix = path.resolve(this.root, prefix);
  16875. if (trail) prefix += '/';
  16876. }
  16877. }
  16878. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  16879. this._emitMatch(index, prefix);
  16880. cb();
  16881. }; // Returns either 'DIR', 'FILE', or false
  16882. Glob.prototype._stat = function (f, cb) {
  16883. var abs = this._makeAbs(f);
  16884. var needDir = f.slice(-1) === '/';
  16885. if (f.length > this.maxLength) return cb();
  16886. if (!this.stat && ownProp(this.cache, abs)) {
  16887. var c = this.cache[abs];
  16888. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  16889. if (!needDir || c === 'DIR') return cb(null, c);
  16890. if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
  16891. // if we know it exists, but not what it is.
  16892. }
  16893. var exists;
  16894. var stat = this.statCache[abs];
  16895. if (stat !== undefined) {
  16896. if (stat === false) return cb(null, stat);else {
  16897. var type = stat.isDirectory() ? 'DIR' : 'FILE';
  16898. if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
  16899. }
  16900. }
  16901. var self = this;
  16902. var statcb = inflight_1('stat\0' + abs, lstatcb_);
  16903. if (statcb) fs.lstat(abs, statcb);
  16904. function lstatcb_(er, lstat) {
  16905. if (lstat && lstat.isSymbolicLink()) {
  16906. // If it's a symlink, then treat it as the target, unless
  16907. // the target does not exist, then treat it as a file.
  16908. return fs.stat(abs, function (er, stat) {
  16909. if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
  16910. });
  16911. } else {
  16912. self._stat2(f, abs, er, lstat, cb);
  16913. }
  16914. }
  16915. };
  16916. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  16917. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  16918. this.statCache[abs] = false;
  16919. return cb();
  16920. }
  16921. var needDir = f.slice(-1) === '/';
  16922. this.statCache[abs] = stat;
  16923. if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
  16924. var c = true;
  16925. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  16926. this.cache[abs] = this.cache[abs] || c;
  16927. if (needDir && c === 'FILE') return cb();
  16928. return cb(null, c, stat);
  16929. };
  16930. var pify_1 = createCommonjsModule(function (module) {
  16931. 'use strict';
  16932. var processFn = function processFn(fn, P, opts) {
  16933. return function () {
  16934. var that = this;
  16935. var args = new Array(arguments.length);
  16936. for (var i = 0; i < arguments.length; i++) {
  16937. args[i] = arguments[i];
  16938. }
  16939. return new P(function (resolve, reject) {
  16940. args.push(function (err, result) {
  16941. if (err) {
  16942. reject(err);
  16943. } else if (opts.multiArgs) {
  16944. var results = new Array(arguments.length - 1);
  16945. for (var i = 1; i < arguments.length; i++) {
  16946. results[i - 1] = arguments[i];
  16947. }
  16948. resolve(results);
  16949. } else {
  16950. resolve(result);
  16951. }
  16952. });
  16953. fn.apply(that, args);
  16954. });
  16955. };
  16956. };
  16957. var pify = module.exports = function (obj, P, opts) {
  16958. if (typeof P !== 'function') {
  16959. opts = P;
  16960. P = Promise;
  16961. }
  16962. opts = opts || {};
  16963. opts.exclude = opts.exclude || [/.+Sync$/];
  16964. var filter = function filter(key) {
  16965. var match = function match(pattern) {
  16966. return typeof pattern === 'string' ? key === pattern : pattern.test(key);
  16967. };
  16968. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  16969. };
  16970. var ret = typeof obj === 'function' ? function () {
  16971. if (opts.excludeMain) {
  16972. return obj.apply(this, arguments);
  16973. }
  16974. return processFn(obj, P, opts).apply(this, arguments);
  16975. } : {};
  16976. return Object.keys(obj).reduce(function (ret, key) {
  16977. var x = obj[key];
  16978. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
  16979. return ret;
  16980. }, ret);
  16981. };
  16982. pify.all = pify;
  16983. });
  16984. var globP = pify_1(glob_1, pinkiePromise).bind(glob_1);
  16985. function isNegative(pattern) {
  16986. return pattern[0] === '!';
  16987. }
  16988. function isString(value) {
  16989. return typeof value === 'string';
  16990. }
  16991. function assertPatternsInput(patterns) {
  16992. if (!patterns.every(isString)) {
  16993. throw new TypeError('patterns must be a string or an array of strings');
  16994. }
  16995. }
  16996. function generateGlobTasks(patterns, opts) {
  16997. patterns = [].concat(patterns);
  16998. assertPatternsInput(patterns);
  16999. var globTasks = [];
  17000. opts = objectAssign({
  17001. cache: Object.create(null),
  17002. statCache: Object.create(null),
  17003. realpathCache: Object.create(null),
  17004. symlinks: Object.create(null),
  17005. ignore: []
  17006. }, opts);
  17007. patterns.forEach(function (pattern, i) {
  17008. if (isNegative(pattern)) {
  17009. return;
  17010. }
  17011. var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) {
  17012. return pattern.slice(1);
  17013. });
  17014. globTasks.push({
  17015. pattern: pattern,
  17016. opts: objectAssign({}, opts, {
  17017. ignore: opts.ignore.concat(ignore)
  17018. })
  17019. });
  17020. });
  17021. return globTasks;
  17022. }
  17023. var globby = function globby(patterns, opts) {
  17024. var globTasks;
  17025. try {
  17026. globTasks = generateGlobTasks(patterns, opts);
  17027. } catch (err) {
  17028. return pinkiePromise.reject(err);
  17029. }
  17030. return pinkiePromise.all(globTasks.map(function (task) {
  17031. return globP(task.pattern, task.opts);
  17032. })).then(function (paths) {
  17033. return arrayUnion.apply(null, paths);
  17034. });
  17035. };
  17036. var sync = function sync(patterns, opts) {
  17037. var globTasks = generateGlobTasks(patterns, opts);
  17038. return globTasks.reduce(function (matches, task) {
  17039. return arrayUnion(matches, glob_1.sync(task.pattern, task.opts));
  17040. }, []);
  17041. };
  17042. var generateGlobTasks_1 = generateGlobTasks;
  17043. var hasMagic = function hasMagic(patterns, opts) {
  17044. return [].concat(patterns).some(function (pattern) {
  17045. return glob_1.hasMagic(pattern, opts);
  17046. });
  17047. };
  17048. globby.sync = sync;
  17049. globby.generateGlobTasks = generateGlobTasks_1;
  17050. globby.hasMagic = hasMagic;
  17051. var assert$2 = true;
  17052. var buffer_ieee754 = "< 0.9.7";
  17053. var buffer = true;
  17054. var child_process = true;
  17055. var cluster = true;
  17056. var console$1 = true;
  17057. var constants = true;
  17058. var crypto = true;
  17059. var _debugger = "< 8";
  17060. var dgram = true;
  17061. var dns = true;
  17062. var domain = true;
  17063. var events$1 = true;
  17064. var freelist = "< 6";
  17065. var fs$2 = true;
  17066. var http = true;
  17067. var http2 = ">= 8.8";
  17068. var https = true;
  17069. var _http_server = ">= 0.11";
  17070. var _linklist = "< 8";
  17071. var module$1 = true;
  17072. var net = true;
  17073. var os$1 = true;
  17074. var path$3 = true;
  17075. var perf_hooks = ">= 8.5";
  17076. var process$1 = ">= 1";
  17077. var punycode = true;
  17078. var querystring = true;
  17079. var readline$1 = true;
  17080. var repl = true;
  17081. var stream = true;
  17082. var string_decoder = true;
  17083. var sys = true;
  17084. var timers = true;
  17085. var tls = true;
  17086. var tty = true;
  17087. var url = true;
  17088. var util$4 = true;
  17089. var v8 = ">= 1";
  17090. var vm = true;
  17091. var zlib = true;
  17092. var core$3 = {
  17093. assert: assert$2,
  17094. buffer_ieee754: buffer_ieee754,
  17095. buffer: buffer,
  17096. child_process: child_process,
  17097. cluster: cluster,
  17098. console: console$1,
  17099. constants: constants,
  17100. crypto: crypto,
  17101. _debugger: _debugger,
  17102. dgram: dgram,
  17103. dns: dns,
  17104. domain: domain,
  17105. events: events$1,
  17106. freelist: freelist,
  17107. fs: fs$2,
  17108. http: http,
  17109. http2: http2,
  17110. https: https,
  17111. _http_server: _http_server,
  17112. _linklist: _linklist,
  17113. module: module$1,
  17114. net: net,
  17115. os: os$1,
  17116. path: path$3,
  17117. perf_hooks: perf_hooks,
  17118. process: process$1,
  17119. punycode: punycode,
  17120. querystring: querystring,
  17121. readline: readline$1,
  17122. repl: repl,
  17123. stream: stream,
  17124. string_decoder: string_decoder,
  17125. sys: sys,
  17126. timers: timers,
  17127. tls: tls,
  17128. tty: tty,
  17129. url: url,
  17130. util: util$4,
  17131. v8: v8,
  17132. vm: vm,
  17133. zlib: zlib
  17134. };
  17135. var core$4 = Object.freeze({
  17136. assert: assert$2,
  17137. buffer_ieee754: buffer_ieee754,
  17138. buffer: buffer,
  17139. child_process: child_process,
  17140. cluster: cluster,
  17141. console: console$1,
  17142. constants: constants,
  17143. crypto: crypto,
  17144. _debugger: _debugger,
  17145. dgram: dgram,
  17146. dns: dns,
  17147. domain: domain,
  17148. events: events$1,
  17149. freelist: freelist,
  17150. fs: fs$2,
  17151. http: http,
  17152. http2: http2,
  17153. https: https,
  17154. _http_server: _http_server,
  17155. _linklist: _linklist,
  17156. module: module$1,
  17157. net: net,
  17158. os: os$1,
  17159. path: path$3,
  17160. perf_hooks: perf_hooks,
  17161. process: process$1,
  17162. punycode: punycode,
  17163. querystring: querystring,
  17164. readline: readline$1,
  17165. repl: repl,
  17166. stream: stream,
  17167. string_decoder: string_decoder,
  17168. sys: sys,
  17169. timers: timers,
  17170. tls: tls,
  17171. tty: tty,
  17172. url: url,
  17173. util: util$4,
  17174. v8: v8,
  17175. vm: vm,
  17176. zlib: zlib,
  17177. default: core$3
  17178. });
  17179. var data = ( core$4 && core$3 ) || core$4;
  17180. var current = process.versions && process.versions.node && process.versions.node.split('.') || [];
  17181. function versionIncluded(specifier) {
  17182. if (specifier === true) {
  17183. return true;
  17184. }
  17185. var parts = specifier.split(' ');
  17186. var op = parts[0];
  17187. var versionParts = parts[1].split('.');
  17188. for (var i = 0; i < 3; ++i) {
  17189. var cur = Number(current[i] || 0);
  17190. var ver = Number(versionParts[i] || 0);
  17191. if (cur === ver) {
  17192. continue; // eslint-disable-line no-restricted-syntax, no-continue
  17193. }
  17194. if (op === '<') {
  17195. return cur < ver;
  17196. } else if (op === '>=') {
  17197. return cur >= ver;
  17198. } else {
  17199. return false;
  17200. }
  17201. }
  17202. return false;
  17203. }
  17204. var core$2 = {};
  17205. for (var mod in data) {
  17206. // eslint-disable-line no-restricted-syntax
  17207. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  17208. core$2[mod] = versionIncluded(data[mod]);
  17209. }
  17210. }
  17211. var core_1 = core$2;
  17212. var caller = function caller() {
  17213. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  17214. var origPrepareStackTrace = Error.prepareStackTrace;
  17215. Error.prepareStackTrace = function (_, stack) {
  17216. return stack;
  17217. };
  17218. var stack = new Error().stack;
  17219. Error.prepareStackTrace = origPrepareStackTrace;
  17220. return stack[2].getFileName();
  17221. };
  17222. var pathParse = createCommonjsModule(function (module) {
  17223. 'use strict';
  17224. var isWindows = process.platform === 'win32'; // Regex to split a windows path into three parts: [*, device, slash,
  17225. // tail] windows-only
  17226. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; // Regex to split the tail part of the above into [*, dir, basename, ext]
  17227. var splitTailRe = /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  17228. var win32 = {}; // Function to split a filename into [root, dir, basename, ext]
  17229. function win32SplitPath(filename) {
  17230. // Separate device+slash from tail
  17231. var result = splitDeviceRe.exec(filename),
  17232. device = (result[1] || '') + (result[2] || ''),
  17233. tail = result[3] || ''; // Split the tail into dir, basename and extension
  17234. var result2 = splitTailRe.exec(tail),
  17235. dir = result2[1],
  17236. basename = result2[2],
  17237. ext = result2[3];
  17238. return [device, dir, basename, ext];
  17239. }
  17240. win32.parse = function (pathString) {
  17241. if (typeof pathString !== 'string') {
  17242. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  17243. }
  17244. var allParts = win32SplitPath(pathString);
  17245. if (!allParts || allParts.length !== 4) {
  17246. throw new TypeError("Invalid path '" + pathString + "'");
  17247. }
  17248. return {
  17249. root: allParts[0],
  17250. dir: allParts[0] + allParts[1].slice(0, -1),
  17251. base: allParts[2],
  17252. ext: allParts[3],
  17253. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  17254. };
  17255. }; // Split a filename into [root, dir, basename, ext], unix version
  17256. // 'root' is just a slash, or nothing.
  17257. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  17258. var posix = {};
  17259. function posixSplitPath(filename) {
  17260. return splitPathRe.exec(filename).slice(1);
  17261. }
  17262. posix.parse = function (pathString) {
  17263. if (typeof pathString !== 'string') {
  17264. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  17265. }
  17266. var allParts = posixSplitPath(pathString);
  17267. if (!allParts || allParts.length !== 4) {
  17268. throw new TypeError("Invalid path '" + pathString + "'");
  17269. }
  17270. allParts[1] = allParts[1] || '';
  17271. allParts[2] = allParts[2] || '';
  17272. allParts[3] = allParts[3] || '';
  17273. return {
  17274. root: allParts[0],
  17275. dir: allParts[0] + allParts[1].slice(0, -1),
  17276. base: allParts[2],
  17277. ext: allParts[3],
  17278. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  17279. };
  17280. };
  17281. if (isWindows) module.exports = win32.parse;else
  17282. /* posix */
  17283. module.exports = posix.parse;
  17284. module.exports.posix = posix.parse;
  17285. module.exports.win32 = win32.parse;
  17286. });
  17287. var parse$4 = path.parse || pathParse;
  17288. var nodeModulesPaths = function nodeModulesPaths(start, opts) {
  17289. var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules']; // ensure that `start` is an absolute path at this point,
  17290. // resolving against the process' current working directory
  17291. var absoluteStart = path.resolve(start);
  17292. if (opts && opts.preserveSymlinks === false) {
  17293. try {
  17294. absoluteStart = fs.realpathSync(absoluteStart);
  17295. } catch (err) {
  17296. if (err.code !== 'ENOENT') {
  17297. throw err;
  17298. }
  17299. }
  17300. }
  17301. var prefix = '/';
  17302. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  17303. prefix = '';
  17304. } else if (/^\\\\/.test(absoluteStart)) {
  17305. prefix = '\\\\';
  17306. }
  17307. var paths = [absoluteStart];
  17308. var parsed = parse$4(absoluteStart);
  17309. while (parsed.dir !== paths[paths.length - 1]) {
  17310. paths.push(parsed.dir);
  17311. parsed = parse$4(parsed.dir);
  17312. }
  17313. var dirs = paths.reduce(function (dirs, aPath) {
  17314. return dirs.concat(modules.map(function (moduleDir) {
  17315. return path.join(prefix, aPath, moduleDir);
  17316. }));
  17317. }, []);
  17318. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  17319. };
  17320. var async = function resolve(x, options, callback) {
  17321. var cb = callback;
  17322. var opts = options || {};
  17323. if (typeof opts === 'function') {
  17324. cb = opts;
  17325. opts = {};
  17326. }
  17327. if (typeof x !== 'string') {
  17328. var err = new TypeError('Path must be a string.');
  17329. return process.nextTick(function () {
  17330. cb(err);
  17331. });
  17332. }
  17333. var isFile = opts.isFile || function (file, cb) {
  17334. fs.stat(file, function (err, stat) {
  17335. if (!err) {
  17336. return cb(null, stat.isFile() || stat.isFIFO());
  17337. }
  17338. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  17339. return cb(err);
  17340. });
  17341. };
  17342. var readFile = opts.readFile || fs.readFile;
  17343. var extensions = opts.extensions || ['.js'];
  17344. var y = opts.basedir || path.dirname(caller());
  17345. opts.paths = opts.paths || [];
  17346. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  17347. var res = path.resolve(y, x);
  17348. if (x === '..' || x.slice(-1) === '/') res += '/';
  17349. if (/\/$/.test(x) && res === y) {
  17350. loadAsDirectory(res, opts.package, onfile);
  17351. } else loadAsFile(res, opts.package, onfile);
  17352. } else loadNodeModules(x, y, function (err, n, pkg) {
  17353. if (err) cb(err);else if (n) cb(null, n, pkg);else if (core_1[x]) return cb(null, x);else {
  17354. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  17355. moduleError.code = 'MODULE_NOT_FOUND';
  17356. cb(moduleError);
  17357. }
  17358. });
  17359. function onfile(err, m, pkg) {
  17360. if (err) cb(err);else if (m) cb(null, m, pkg);else loadAsDirectory(res, function (err, d, pkg) {
  17361. if (err) cb(err);else if (d) cb(null, d, pkg);else {
  17362. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  17363. moduleError.code = 'MODULE_NOT_FOUND';
  17364. cb(moduleError);
  17365. }
  17366. });
  17367. }
  17368. function loadAsFile(x, thePackage, callback) {
  17369. var loadAsFilePackage = thePackage;
  17370. var cb = callback;
  17371. if (typeof loadAsFilePackage === 'function') {
  17372. cb = loadAsFilePackage;
  17373. loadAsFilePackage = undefined;
  17374. }
  17375. var exts = [''].concat(extensions);
  17376. load(exts, x, loadAsFilePackage);
  17377. function load(exts, x, loadPackage) {
  17378. if (exts.length === 0) return cb(null, undefined, loadPackage);
  17379. var file = x + exts[0];
  17380. var pkg = loadPackage;
  17381. if (pkg) onpkg(null, pkg);else loadpkg(path.dirname(file), onpkg);
  17382. function onpkg(err, pkg_, dir) {
  17383. pkg = pkg_;
  17384. if (err) return cb(err);
  17385. if (dir && pkg && opts.pathFilter) {
  17386. var rfile = path.relative(dir, file);
  17387. var rel = rfile.slice(0, rfile.length - exts[0].length);
  17388. var r = opts.pathFilter(pkg, x, rel);
  17389. if (r) return load([''].concat(extensions.slice()), path.resolve(dir, r), pkg);
  17390. }
  17391. isFile(file, onex);
  17392. }
  17393. function onex(err, ex) {
  17394. if (err) return cb(err);
  17395. if (ex) return cb(null, file, pkg);
  17396. load(exts.slice(1), x, pkg);
  17397. }
  17398. }
  17399. }
  17400. function loadpkg(dir, cb) {
  17401. if (dir === '' || dir === '/') return cb(null);
  17402. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  17403. return cb(null);
  17404. }
  17405. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  17406. var pkgfile = path.join(dir, 'package.json');
  17407. isFile(pkgfile, function (err, ex) {
  17408. // on err, ex is false
  17409. if (!ex) return loadpkg(path.dirname(dir), cb);
  17410. readFile(pkgfile, function (err, body) {
  17411. if (err) cb(err);
  17412. try {
  17413. var pkg = JSON.parse(body);
  17414. } catch (jsonErr) {}
  17415. if (pkg && opts.packageFilter) {
  17416. pkg = opts.packageFilter(pkg, pkgfile);
  17417. }
  17418. cb(null, pkg, dir);
  17419. });
  17420. });
  17421. }
  17422. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  17423. var cb = callback;
  17424. var fpkg = loadAsDirectoryPackage;
  17425. if (typeof fpkg === 'function') {
  17426. cb = fpkg;
  17427. fpkg = opts.package;
  17428. }
  17429. var pkgfile = path.join(x, 'package.json');
  17430. isFile(pkgfile, function (err, ex) {
  17431. if (err) return cb(err);
  17432. if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb);
  17433. readFile(pkgfile, function (err, body) {
  17434. if (err) return cb(err);
  17435. try {
  17436. var pkg = JSON.parse(body);
  17437. } catch (jsonErr) {}
  17438. if (opts.packageFilter) {
  17439. pkg = opts.packageFilter(pkg, pkgfile);
  17440. }
  17441. if (pkg.main) {
  17442. if (pkg.main === '.' || pkg.main === './') {
  17443. pkg.main = 'index';
  17444. }
  17445. loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
  17446. if (err) return cb(err);
  17447. if (m) return cb(null, m, pkg);
  17448. if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb);
  17449. var dir = path.resolve(x, pkg.main);
  17450. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  17451. if (err) return cb(err);
  17452. if (n) return cb(null, n, pkg);
  17453. loadAsFile(path.join(x, 'index'), pkg, cb);
  17454. });
  17455. });
  17456. return;
  17457. }
  17458. loadAsFile(path.join(x, '/index'), pkg, cb);
  17459. });
  17460. });
  17461. }
  17462. function processDirs(cb, dirs) {
  17463. if (dirs.length === 0) return cb(null, undefined);
  17464. var dir = dirs[0];
  17465. var file = path.join(dir, x);
  17466. loadAsFile(file, undefined, onfile);
  17467. function onfile(err, m, pkg) {
  17468. if (err) return cb(err);
  17469. if (m) return cb(null, m, pkg);
  17470. loadAsDirectory(path.join(dir, x), undefined, ondir);
  17471. }
  17472. function ondir(err, n, pkg) {
  17473. if (err) return cb(err);
  17474. if (n) return cb(null, n, pkg);
  17475. processDirs(cb, dirs.slice(1));
  17476. }
  17477. }
  17478. function loadNodeModules(x, start, cb) {
  17479. processDirs(cb, nodeModulesPaths(start, opts));
  17480. }
  17481. };
  17482. var sync$3 = function sync(x, options) {
  17483. if (typeof x !== 'string') {
  17484. throw new TypeError('Path must be a string.');
  17485. }
  17486. var opts = options || {};
  17487. var isFile = opts.isFile || function (file) {
  17488. try {
  17489. var stat = fs.statSync(file);
  17490. } catch (e) {
  17491. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  17492. throw e;
  17493. }
  17494. return stat.isFile() || stat.isFIFO();
  17495. };
  17496. var readFileSync = opts.readFileSync || fs.readFileSync;
  17497. var extensions = opts.extensions || ['.js'];
  17498. var y = opts.basedir || path.dirname(caller());
  17499. opts.paths = opts.paths || [];
  17500. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  17501. var res = path.resolve(y, x);
  17502. if (x === '..' || x.slice(-1) === '/') res += '/';
  17503. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  17504. if (m) return m;
  17505. } else {
  17506. var n = loadNodeModulesSync(x, y);
  17507. if (n) return n;
  17508. }
  17509. if (core_1[x]) return x;
  17510. var err = new Error("Cannot find module '" + x + "' from '" + y + "'");
  17511. err.code = 'MODULE_NOT_FOUND';
  17512. throw err;
  17513. function loadAsFileSync(x) {
  17514. if (isFile(x)) {
  17515. return x;
  17516. }
  17517. for (var i = 0; i < extensions.length; i++) {
  17518. var file = x + extensions[i];
  17519. if (isFile(file)) {
  17520. return file;
  17521. }
  17522. }
  17523. }
  17524. function loadAsDirectorySync(x) {
  17525. var pkgfile = path.join(x, '/package.json');
  17526. if (isFile(pkgfile)) {
  17527. try {
  17528. var body = readFileSync(pkgfile, 'UTF8');
  17529. var pkg = JSON.parse(body);
  17530. if (opts.packageFilter) {
  17531. pkg = opts.packageFilter(pkg, x);
  17532. }
  17533. if (pkg.main) {
  17534. if (pkg.main === '.' || pkg.main === './') {
  17535. pkg.main = 'index';
  17536. }
  17537. var m = loadAsFileSync(path.resolve(x, pkg.main));
  17538. if (m) return m;
  17539. var n = loadAsDirectorySync(path.resolve(x, pkg.main));
  17540. if (n) return n;
  17541. }
  17542. } catch (e) {}
  17543. }
  17544. return loadAsFileSync(path.join(x, '/index'));
  17545. }
  17546. function loadNodeModulesSync(x, start) {
  17547. var dirs = nodeModulesPaths(start, opts);
  17548. for (var i = 0; i < dirs.length; i++) {
  17549. var dir = dirs[i];
  17550. var m = loadAsFileSync(path.join(dir, '/', x));
  17551. if (m) return m;
  17552. var n = loadAsDirectorySync(path.join(dir, '/', x));
  17553. if (n) return n;
  17554. }
  17555. }
  17556. };
  17557. var resolve$1 = createCommonjsModule(function (module, exports) {
  17558. async.core = core_1;
  17559. async.isCore = function isCore(x) {
  17560. return core_1[x];
  17561. };
  17562. async.sync = sync$3;
  17563. exports = async;
  17564. module.exports = async;
  17565. });
  17566. var addLeadingComment$2 = utilShared.addLeadingComment;
  17567. var addTrailingComment$2 = utilShared.addTrailingComment;
  17568. var addDanglingComment$2 = utilShared.addDanglingComment;
  17569. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  17570. var precedingNode = comment.precedingNode,
  17571. enclosingNode = comment.enclosingNode,
  17572. followingNode = comment.followingNode;
  17573. 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)) {
  17574. return true;
  17575. }
  17576. return false;
  17577. }
  17578. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  17579. var precedingNode = comment.precedingNode,
  17580. enclosingNode = comment.enclosingNode,
  17581. followingNode = comment.followingNode;
  17582. 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)) {
  17583. return true;
  17584. }
  17585. return false;
  17586. }
  17587. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  17588. var precedingNode = comment.precedingNode,
  17589. enclosingNode = comment.enclosingNode,
  17590. followingNode = comment.followingNode;
  17591. 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)) {
  17592. return true;
  17593. }
  17594. return false;
  17595. }
  17596. function addBlockStatementFirstComment(node, comment) {
  17597. var body = node.body.filter(function (n) {
  17598. return n.type !== "EmptyStatement";
  17599. });
  17600. if (body.length === 0) {
  17601. addDanglingComment$2(node, comment);
  17602. } else {
  17603. addLeadingComment$2(body[0], comment);
  17604. }
  17605. }
  17606. function addBlockOrNotComment(node, comment) {
  17607. if (node.type === "BlockStatement") {
  17608. addBlockStatementFirstComment(node, comment);
  17609. } else {
  17610. addLeadingComment$2(node, comment);
  17611. }
  17612. } // There are often comments before the else clause of if statements like
  17613. //
  17614. // if (1) { ... }
  17615. // // comment
  17616. // else { ... }
  17617. //
  17618. // They are being attached as leading comments of the BlockExpression which
  17619. // is not well printed. What we want is to instead move the comment inside
  17620. // of the block and make it leadingComment of the first element of the block
  17621. // or dangling comment of the block if there is nothing inside
  17622. //
  17623. // if (1) { ... }
  17624. // else {
  17625. // // comment
  17626. // ...
  17627. // }
  17628. function handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  17629. if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) {
  17630. return false;
  17631. } // We unfortunately have no way using the AST or location of nodes to know
  17632. // if the comment is positioned before the condition parenthesis:
  17633. // if (a /* comment */) {}
  17634. // The only workaround I found is to look at the next character to see if
  17635. // it is a ).
  17636. var nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  17637. if (nextCharacter === ")") {
  17638. addTrailingComment$2(precedingNode, comment);
  17639. return true;
  17640. } // Comments before `else`:
  17641. // - treat as trailing comments of the consequent, if it's a BlockStatement
  17642. // - treat as a dangling comment otherwise
  17643. if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
  17644. if (precedingNode.type === "BlockStatement") {
  17645. addTrailingComment$2(precedingNode, comment);
  17646. } else {
  17647. addDanglingComment$2(enclosingNode, comment);
  17648. }
  17649. return true;
  17650. }
  17651. if (followingNode.type === "BlockStatement") {
  17652. addBlockStatementFirstComment(followingNode, comment);
  17653. return true;
  17654. }
  17655. if (followingNode.type === "IfStatement") {
  17656. addBlockOrNotComment(followingNode.consequent, comment);
  17657. return true;
  17658. } // For comments positioned after the condition parenthesis in an if statement
  17659. // before the consequent without brackets on, such as
  17660. // if (a) /* comment */ true,
  17661. // we look at the next character to see if the following node
  17662. // is the consequent for the if statement
  17663. if (enclosingNode.consequent === followingNode) {
  17664. addLeadingComment$2(followingNode, comment);
  17665. return true;
  17666. }
  17667. return false;
  17668. }
  17669. function handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  17670. if (!enclosingNode || enclosingNode.type !== "WhileStatement" || !followingNode) {
  17671. return false;
  17672. } // We unfortunately have no way using the AST or location of nodes to know
  17673. // if the comment is positioned before the condition parenthesis:
  17674. // while (a /* comment */) {}
  17675. // The only workaround I found is to look at the next character to see if
  17676. // it is a ).
  17677. var nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  17678. if (nextCharacter === ")") {
  17679. addTrailingComment$2(precedingNode, comment);
  17680. return true;
  17681. }
  17682. if (followingNode.type === "BlockStatement") {
  17683. addBlockStatementFirstComment(followingNode, comment);
  17684. return true;
  17685. }
  17686. return false;
  17687. } // Same as IfStatement but for TryStatement
  17688. function handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) {
  17689. if (!enclosingNode || enclosingNode.type !== "TryStatement" && enclosingNode.type !== "CatchClause" || !followingNode) {
  17690. return false;
  17691. }
  17692. if (enclosingNode.type === "CatchClause" && precedingNode) {
  17693. addTrailingComment$2(precedingNode, comment);
  17694. return true;
  17695. }
  17696. if (followingNode.type === "BlockStatement") {
  17697. addBlockStatementFirstComment(followingNode, comment);
  17698. return true;
  17699. }
  17700. if (followingNode.type === "TryStatement") {
  17701. addBlockOrNotComment(followingNode.finalizer, comment);
  17702. return true;
  17703. }
  17704. if (followingNode.type === "CatchClause") {
  17705. addBlockOrNotComment(followingNode.body, comment);
  17706. return true;
  17707. }
  17708. return false;
  17709. }
  17710. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  17711. if (enclosingNode && enclosingNode.type === "MemberExpression" && followingNode && followingNode.type === "Identifier") {
  17712. addLeadingComment$2(enclosingNode, comment);
  17713. return true;
  17714. }
  17715. return false;
  17716. }
  17717. function handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) {
  17718. var isSameLineAsPrecedingNode = precedingNode && !util$1.hasNewlineInRange(text, options.locEnd(precedingNode), options.locStart(comment));
  17719. if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && enclosingNode.type === "ConditionalExpression" && followingNode) {
  17720. addLeadingComment$2(followingNode, comment);
  17721. return true;
  17722. }
  17723. return false;
  17724. }
  17725. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  17726. if (enclosingNode && (enclosingNode.type === "ObjectProperty" || enclosingNode.type === "Property") && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === "AssignmentPattern") {
  17727. addTrailingComment$2(enclosingNode.value.left, comment);
  17728. return true;
  17729. }
  17730. return false;
  17731. }
  17732. function handleClassComments(enclosingNode, precedingNode, followingNode, comment) {
  17733. if (enclosingNode && (enclosingNode.type === "ClassDeclaration" || enclosingNode.type === "ClassExpression") && enclosingNode.decorators && enclosingNode.decorators.length > 0 && !(followingNode && followingNode.type === "Decorator")) {
  17734. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  17735. addLeadingComment$2(enclosingNode, comment);
  17736. } else {
  17737. addTrailingComment$2(enclosingNode.decorators[enclosingNode.decorators.length - 1], comment);
  17738. }
  17739. return true;
  17740. }
  17741. return false;
  17742. }
  17743. function handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) {
  17744. // This is only needed for estree parsers (flow, typescript) to attach
  17745. // after a method name:
  17746. // obj = { fn /*comment*/() {} };
  17747. if (enclosingNode && precedingNode && (enclosingNode.type === "Property" || enclosingNode.type === "MethodDefinition") && precedingNode.type === "Identifier" && enclosingNode.key === precedingNode && // special Property case: { key: /*comment*/(value) };
  17748. // comment should be attached to value instead of key
  17749. util$1.getNextNonSpaceNonCommentCharacter(text, precedingNode, options.locEnd) !== ":") {
  17750. addTrailingComment$2(precedingNode, comment);
  17751. return true;
  17752. } // Print comments between decorators and class methods as a trailing comment
  17753. // on the decorator node instead of the method node
  17754. if (precedingNode && enclosingNode && precedingNode.type === "Decorator" && (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "TSAbstractClassProperty" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "MethodDefinition")) {
  17755. addTrailingComment$2(precedingNode, comment);
  17756. return true;
  17757. }
  17758. return false;
  17759. }
  17760. function handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) {
  17761. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== "(") {
  17762. return false;
  17763. }
  17764. if (precedingNode && enclosingNode && (enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "MethodDefinition" || enclosingNode.type === "ObjectMethod")) {
  17765. addTrailingComment$2(precedingNode, comment);
  17766. return true;
  17767. }
  17768. return false;
  17769. }
  17770. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  17771. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  17772. return false;
  17773. }
  17774. var index = utilShared.getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
  17775. if (text.substr(index, 2) === "=>") {
  17776. addDanglingComment$2(enclosingNode, comment);
  17777. return true;
  17778. }
  17779. return false;
  17780. }
  17781. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  17782. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== ")") {
  17783. return false;
  17784. } // Only add dangling comments to fix the case when no params are present,
  17785. // i.e. a function without any argument.
  17786. if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" && (enclosingNode.body.type !== "CallExpression" || enclosingNode.body.arguments.length === 0) || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || (enclosingNode.type === "CallExpression" || enclosingNode.type === "NewExpression") && enclosingNode.arguments.length === 0)) {
  17787. addDanglingComment$2(enclosingNode, comment);
  17788. return true;
  17789. }
  17790. if (enclosingNode && enclosingNode.type === "MethodDefinition" && enclosingNode.value.params.length === 0) {
  17791. addDanglingComment$2(enclosingNode.value, comment);
  17792. return true;
  17793. }
  17794. return false;
  17795. }
  17796. function handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  17797. // Type definitions functions
  17798. if (precedingNode && precedingNode.type === "FunctionTypeParam" && enclosingNode && enclosingNode.type === "FunctionTypeAnnotation" && followingNode && followingNode.type !== "FunctionTypeParam") {
  17799. addTrailingComment$2(precedingNode, comment);
  17800. return true;
  17801. } // Real functions
  17802. 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) === ")") {
  17803. addTrailingComment$2(precedingNode, comment);
  17804. return true;
  17805. }
  17806. if (enclosingNode && enclosingNode.type === "FunctionDeclaration" && followingNode && followingNode.type === "BlockStatement") {
  17807. var functionParamRightParenIndex = function () {
  17808. if (enclosingNode.params.length !== 0) {
  17809. return util$1.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(util$1.getLast(enclosingNode.params)));
  17810. }
  17811. var functionParamLeftParenIndex = util$1.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(enclosingNode.id));
  17812. return util$1.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, functionParamLeftParenIndex + 1);
  17813. }();
  17814. if (options.locStart(comment) > functionParamRightParenIndex) {
  17815. addBlockStatementFirstComment(followingNode, comment);
  17816. return true;
  17817. }
  17818. }
  17819. return false;
  17820. }
  17821. function handleImportSpecifierComments(enclosingNode, comment) {
  17822. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  17823. addLeadingComment$2(enclosingNode, comment);
  17824. return true;
  17825. }
  17826. return false;
  17827. }
  17828. function handleLabeledStatementComments(enclosingNode, comment) {
  17829. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  17830. addLeadingComment$2(enclosingNode, comment);
  17831. return true;
  17832. }
  17833. return false;
  17834. }
  17835. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  17836. if (enclosingNode && (enclosingNode.type === "ContinueStatement" || enclosingNode.type === "BreakStatement") && !enclosingNode.label) {
  17837. addTrailingComment$2(enclosingNode, comment);
  17838. return true;
  17839. }
  17840. return false;
  17841. }
  17842. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  17843. if (enclosingNode && enclosingNode.type === "CallExpression" && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
  17844. addLeadingComment$2(enclosingNode.arguments[0], comment);
  17845. return true;
  17846. }
  17847. return false;
  17848. }
  17849. function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
  17850. if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
  17851. addTrailingComment$2(precedingNode, comment);
  17852. return true;
  17853. }
  17854. return false;
  17855. }
  17856. function handlePropertyComments(enclosingNode, comment) {
  17857. if (enclosingNode && (enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty")) {
  17858. addLeadingComment$2(enclosingNode, comment);
  17859. return true;
  17860. }
  17861. return false;
  17862. }
  17863. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  17864. // With Flow the enclosingNode is undefined so use the AST instead.
  17865. if (ast && ast.body && ast.body.length === 0) {
  17866. if (isLastComment) {
  17867. addDanglingComment$2(ast, comment);
  17868. } else {
  17869. addLeadingComment$2(ast, comment);
  17870. }
  17871. return true;
  17872. } else if (enclosingNode && enclosingNode.type === "Program" && enclosingNode.body.length === 0 && enclosingNode.directives && enclosingNode.directives.length === 0) {
  17873. if (isLastComment) {
  17874. addDanglingComment$2(enclosingNode, comment);
  17875. } else {
  17876. addLeadingComment$2(enclosingNode, comment);
  17877. }
  17878. return true;
  17879. }
  17880. return false;
  17881. }
  17882. function handleForComments(enclosingNode, precedingNode, comment) {
  17883. if (enclosingNode && (enclosingNode.type === "ForInStatement" || enclosingNode.type === "ForOfStatement")) {
  17884. addLeadingComment$2(enclosingNode, comment);
  17885. return true;
  17886. }
  17887. return false;
  17888. }
  17889. function handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) {
  17890. if (precedingNode && precedingNode.type === "ImportSpecifier" && enclosingNode && enclosingNode.type === "ImportDeclaration" && util$1.hasNewline(text, options.locEnd(comment))) {
  17891. addTrailingComment$2(precedingNode, comment);
  17892. return true;
  17893. }
  17894. return false;
  17895. }
  17896. function handleAssignmentPatternComments(enclosingNode, comment) {
  17897. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  17898. addLeadingComment$2(enclosingNode, comment);
  17899. return true;
  17900. }
  17901. return false;
  17902. }
  17903. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  17904. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  17905. addLeadingComment$2(enclosingNode, comment);
  17906. return true;
  17907. }
  17908. return false;
  17909. }
  17910. function handleVariableDeclaratorComments(enclosingNode, followingNode, comment) {
  17911. if (enclosingNode && (enclosingNode.type === "VariableDeclarator" || enclosingNode.type === "AssignmentExpression") && followingNode && (followingNode.type === "ObjectExpression" || followingNode.type === "ArrayExpression" || followingNode.type === "TemplateLiteral" || followingNode.type === "TaggedTemplateExpression")) {
  17912. addLeadingComment$2(followingNode, comment);
  17913. return true;
  17914. }
  17915. return false;
  17916. }
  17917. function handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) {
  17918. if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
  17919. return false;
  17920. }
  17921. if (followingNode && followingNode.type === "TSTypeParameter" && followingNode.name) {
  17922. addLeadingComment$2(followingNode.name, comment);
  17923. return true;
  17924. }
  17925. if (precedingNode && precedingNode.type === "TSTypeParameter" && precedingNode.constraint) {
  17926. addTrailingComment$2(precedingNode.constraint, comment);
  17927. return true;
  17928. }
  17929. return false;
  17930. }
  17931. function isBlockComment$1(comment) {
  17932. return comment.type === "Block" || comment.type === "CommentBlock";
  17933. }
  17934. function hasLeadingComment$2(node) {
  17935. var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  17936. return true;
  17937. };
  17938. if (node.leadingComments) {
  17939. return node.leadingComments.some(fn);
  17940. }
  17941. if (node.comments) {
  17942. return node.comments.some(function (comment) {
  17943. return comment.leading && fn(comment);
  17944. });
  17945. }
  17946. return false;
  17947. }
  17948. var comments$3 = {
  17949. handleOwnLineComment,
  17950. handleEndOfLineComment,
  17951. handleRemainingComment,
  17952. hasLeadingComment: hasLeadingComment$2,
  17953. isBlockComment: isBlockComment$1
  17954. };
  17955. var isBlockComment = comments$3.isBlockComment;
  17956. var hasLeadingComment$1 = comments$3.hasLeadingComment;
  17957. var _require$$1$builders = doc.builders;
  17958. var indent$3 = _require$$1$builders.indent;
  17959. var join$3 = _require$$1$builders.join;
  17960. var hardline$4 = _require$$1$builders.hardline;
  17961. var softline$2 = _require$$1$builders.softline;
  17962. var literalline$2 = _require$$1$builders.literalline;
  17963. var concat$5 = _require$$1$builders.concat;
  17964. var group$2 = _require$$1$builders.group;
  17965. var dedentToRoot$1 = _require$$1$builders.dedentToRoot;
  17966. var _require$$1$utils = doc.utils;
  17967. var mapDoc$3 = _require$$1$utils.mapDoc;
  17968. var stripTrailingHardline$1 = _require$$1$utils.stripTrailingHardline;
  17969. function embed(path$$1, print, textToDoc
  17970. /*, options */
  17971. ) {
  17972. var node = path$$1.getValue();
  17973. var parent = path$$1.getParentNode();
  17974. var parentParent = path$$1.getParentNode(1);
  17975. switch (node.type) {
  17976. case "TemplateLiteral":
  17977. {
  17978. var isCss = [isStyledJsx, isStyledComponents, isCssProp, isAngularComponentStyles].some(function (isIt) {
  17979. return isIt(path$$1);
  17980. });
  17981. if (isCss) {
  17982. // Get full template literal with expressions replaced by placeholders
  17983. var rawQuasis = node.quasis.map(function (q) {
  17984. return q.value.raw;
  17985. });
  17986. var placeholderID = 0;
  17987. var text = rawQuasis.reduce(function (prevVal, currVal, idx) {
  17988. return idx == 0 ? currVal : prevVal + "@prettier-placeholder-" + placeholderID++ + "-id" + currVal;
  17989. }, "");
  17990. var doc$$2 = textToDoc(text, {
  17991. parser: "css"
  17992. });
  17993. return transformCssDoc(doc$$2, path$$1, print);
  17994. }
  17995. /*
  17996. * react-relay and graphql-tag
  17997. * graphql`...`
  17998. * graphql.experimental`...`
  17999. * gql`...`
  18000. *
  18001. * This intentionally excludes Relay Classic tags, as Prettier does not
  18002. * support Relay Classic formatting.
  18003. */
  18004. if (isGraphQL(path$$1)) {
  18005. var expressionDocs = node.expressions ? path$$1.map(print, "expressions") : [];
  18006. var numQuasis = node.quasis.length;
  18007. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  18008. return "``";
  18009. }
  18010. var parts = [];
  18011. for (var i = 0; i < numQuasis; i++) {
  18012. var templateElement = node.quasis[i];
  18013. var isFirst = i === 0;
  18014. var isLast = i === numQuasis - 1;
  18015. var _text = templateElement.value.cooked; // Bail out if any of the quasis have an invalid escape sequence
  18016. // (which would make the `cooked` value be `null` or `undefined`)
  18017. if (typeof _text !== "string") {
  18018. return null;
  18019. }
  18020. var lines = _text.split("\n");
  18021. var numLines = lines.length;
  18022. var expressionDoc = expressionDocs[i];
  18023. var startsWithBlankLine = numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  18024. var endsWithBlankLine = numLines > 2 && lines[numLines - 1].trim() === "" && lines[numLines - 2].trim() === "";
  18025. var commentsAndWhitespaceOnly = lines.every(function (line) {
  18026. return /^\s*(?:#[^\r\n]*)?$/.test(line);
  18027. }); // Bail out if an interpolation occurs within a comment.
  18028. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  18029. return null;
  18030. }
  18031. var _doc = null;
  18032. if (commentsAndWhitespaceOnly) {
  18033. _doc = printGraphqlComments(lines);
  18034. } else {
  18035. _doc = stripTrailingHardline$1(textToDoc(_text, {
  18036. parser: "graphql"
  18037. }));
  18038. }
  18039. if (_doc) {
  18040. _doc = escapeTemplateCharacters(_doc, false);
  18041. if (!isFirst && startsWithBlankLine) {
  18042. parts.push("");
  18043. }
  18044. parts.push(_doc);
  18045. if (!isLast && endsWithBlankLine) {
  18046. parts.push("");
  18047. }
  18048. } else if (!isFirst && !isLast && startsWithBlankLine) {
  18049. parts.push("");
  18050. }
  18051. if (expressionDoc) {
  18052. parts.push(concat$5(["${", expressionDoc, "}"]));
  18053. }
  18054. }
  18055. return concat$5(["`", indent$3(concat$5([hardline$4, join$3(hardline$4, parts)])), hardline$4, "`"]);
  18056. }
  18057. if (isHtml(path$$1)) {
  18058. return printHtmlTemplateLiteral(path$$1, print, textToDoc, "html");
  18059. }
  18060. if (isAngularComponentTemplate(path$$1)) {
  18061. return printHtmlTemplateLiteral(path$$1, print, textToDoc, "angular");
  18062. }
  18063. break;
  18064. }
  18065. case "TemplateElement":
  18066. {
  18067. /**
  18068. * md`...`
  18069. * markdown`...`
  18070. */
  18071. if (parentParent && parentParent.type === "TaggedTemplateExpression" && parent.quasis.length === 1 && parentParent.tag.type === "Identifier" && (parentParent.tag.name === "md" || parentParent.tag.name === "markdown")) {
  18072. var _text2 = parent.quasis[0].value.raw.replace(/((?:\\\\)*)\\`/g, function (_, backslashes) {
  18073. return "\\".repeat(backslashes.length / 2) + "`";
  18074. });
  18075. var indentation = getIndentation(_text2);
  18076. var hasIndent = indentation !== "";
  18077. 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]);
  18078. }
  18079. break;
  18080. }
  18081. }
  18082. function printMarkdown(text) {
  18083. var doc$$2 = textToDoc(text, {
  18084. parser: "markdown",
  18085. __inJsTemplate: true
  18086. });
  18087. return stripTrailingHardline$1(escapeTemplateCharacters(doc$$2, true));
  18088. }
  18089. }
  18090. function getIndentation(str) {
  18091. var firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  18092. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  18093. }
  18094. function escapeTemplateCharacters(doc$$2, raw) {
  18095. return mapDoc$3(doc$$2, function (currentDoc) {
  18096. if (!currentDoc.parts) {
  18097. return currentDoc;
  18098. }
  18099. var parts = [];
  18100. currentDoc.parts.forEach(function (part) {
  18101. if (typeof part === "string") {
  18102. parts.push(raw ? part.replace(/(\\*)`/g, "$1$1\\`") : part.replace(/([\\`]|\$\{)/g, "\\$1"));
  18103. } else {
  18104. parts.push(part);
  18105. }
  18106. });
  18107. return Object.assign({}, currentDoc, {
  18108. parts
  18109. });
  18110. });
  18111. }
  18112. function transformCssDoc(quasisDoc, path$$1, print) {
  18113. var parentNode = path$$1.getValue();
  18114. var isEmpty = parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  18115. if (isEmpty) {
  18116. return "``";
  18117. }
  18118. var expressionDocs = parentNode.expressions ? path$$1.map(print, "expressions") : [];
  18119. var newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  18120. /* istanbul ignore if */
  18121. if (!newDoc) {
  18122. throw new Error("Couldn't insert all the expressions");
  18123. }
  18124. return concat$5(["`", indent$3(concat$5([hardline$4, stripTrailingHardline$1(newDoc)])), softline$2, "`"]);
  18125. } // Search all the placeholders in the quasisDoc tree
  18126. // and replace them with the expression docs one by one
  18127. // returns a new doc with all the placeholders replaced,
  18128. // or null if it couldn't replace any expression
  18129. function replacePlaceholders(quasisDoc, expressionDocs) {
  18130. if (!expressionDocs || !expressionDocs.length) {
  18131. return quasisDoc;
  18132. }
  18133. var expressions = expressionDocs.slice();
  18134. var replaceCounter = 0;
  18135. var newDoc = mapDoc$3(quasisDoc, function (doc$$2) {
  18136. if (!doc$$2 || !doc$$2.parts || !doc$$2.parts.length) {
  18137. return doc$$2;
  18138. }
  18139. var parts = doc$$2.parts;
  18140. var atIndex = parts.indexOf("@");
  18141. var placeholderIndex = atIndex + 1;
  18142. if (atIndex > -1 && typeof parts[placeholderIndex] === "string" && parts[placeholderIndex].startsWith("prettier-placeholder")) {
  18143. // If placeholder is split, join it
  18144. var at = parts[atIndex];
  18145. var placeholder = parts[placeholderIndex];
  18146. var rest = parts.slice(placeholderIndex + 1);
  18147. parts = parts.slice(0, atIndex).concat([at + placeholder]).concat(rest);
  18148. }
  18149. var atPlaceholderIndex = parts.findIndex(function (part) {
  18150. return typeof part === "string" && part.startsWith("@prettier-placeholder");
  18151. });
  18152. if (atPlaceholderIndex > -1) {
  18153. var _placeholder = parts[atPlaceholderIndex];
  18154. var _rest = parts.slice(atPlaceholderIndex + 1);
  18155. var placeholderMatch = _placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
  18156. var placeholderID = placeholderMatch[1]; // When the expression has a suffix appended, like:
  18157. // animation: linear ${time}s ease-out;
  18158. var suffix = placeholderMatch[2];
  18159. var expression = expressions[placeholderID];
  18160. replaceCounter++;
  18161. parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(_rest);
  18162. }
  18163. return Object.assign({}, doc$$2, {
  18164. parts: parts
  18165. });
  18166. });
  18167. return expressions.length === replaceCounter ? newDoc : null;
  18168. }
  18169. function printGraphqlComments(lines) {
  18170. var parts = [];
  18171. var seenComment = false;
  18172. lines.map(function (textLine) {
  18173. return textLine.trim();
  18174. }).forEach(function (textLine, i, array) {
  18175. // Lines are either whitespace only, or a comment (with poential whitespace
  18176. // around it). Drop whitespace-only lines.
  18177. if (textLine === "") {
  18178. return;
  18179. }
  18180. if (array[i - 1] === "" && seenComment) {
  18181. // If a non-first comment is preceded by a blank (whitespace only) line,
  18182. // add in a blank line.
  18183. parts.push(concat$5([hardline$4, textLine]));
  18184. } else {
  18185. parts.push(textLine);
  18186. }
  18187. seenComment = true;
  18188. }); // If `lines` was whitespace only, return `null`.
  18189. return parts.length === 0 ? null : join$3(hardline$4, parts);
  18190. }
  18191. /**
  18192. * Template literal in this context:
  18193. * <style jsx>{`div{color:red}`}</style>
  18194. */
  18195. function isStyledJsx(path$$1) {
  18196. var node = path$$1.getValue();
  18197. var parent = path$$1.getParentNode();
  18198. var parentParent = path$$1.getParentNode(1);
  18199. return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(function (attribute) {
  18200. return attribute.name.name === "jsx";
  18201. });
  18202. }
  18203. /**
  18204. * Angular Components can have:
  18205. * - Inline HTML template
  18206. * - Inline CSS styles
  18207. *
  18208. * ...which are both within template literals somewhere
  18209. * inside of the Component decorator factory.
  18210. *
  18211. * E.g.
  18212. * @Component({
  18213. * template: `<div>...</div>`,
  18214. * styles: [`h1 { color: blue; }`]
  18215. * })
  18216. */
  18217. function isAngularComponentStyles(path$$1) {
  18218. return isPathMatch(path$$1, [function (node) {
  18219. return node.type === "TemplateLiteral";
  18220. }, function (node, name) {
  18221. return node.type === "ArrayExpression" && name === "elements";
  18222. }, function (node, name) {
  18223. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "styles" && name === "value";
  18224. }].concat(getAngularComponentObjectExpressionPredicates()));
  18225. }
  18226. function isAngularComponentTemplate(path$$1) {
  18227. return isPathMatch(path$$1, [function (node) {
  18228. return node.type === "TemplateLiteral";
  18229. }, function (node, name) {
  18230. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "template" && name === "value";
  18231. }].concat(getAngularComponentObjectExpressionPredicates()));
  18232. }
  18233. function getAngularComponentObjectExpressionPredicates() {
  18234. return [function (node, name) {
  18235. return node.type === "ObjectExpression" && name === "properties";
  18236. }, function (node, name) {
  18237. return node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "Component" && name === "arguments";
  18238. }, function (node, name) {
  18239. return node.type === "Decorator" && name === "expression";
  18240. }];
  18241. }
  18242. /**
  18243. * styled-components template literals
  18244. */
  18245. function isStyledComponents(path$$1) {
  18246. var parent = path$$1.getParentNode();
  18247. if (!parent || parent.type !== "TaggedTemplateExpression") {
  18248. return false;
  18249. }
  18250. var tag = parent.tag;
  18251. switch (tag.type) {
  18252. case "MemberExpression":
  18253. return (// styled.foo``
  18254. isStyledIdentifier(tag.object) || // Component.extend``
  18255. isStyledExtend(tag)
  18256. );
  18257. case "CallExpression":
  18258. return (// styled(Component)``
  18259. isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attr({})``
  18260. isStyledIdentifier(tag.callee.object.object) || // Component.extend.attr({)``
  18261. isStyledExtend(tag.callee.object)) || // styled(Component).attr({})``
  18262. tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
  18263. );
  18264. case "Identifier":
  18265. // css``
  18266. return tag.name === "css";
  18267. default:
  18268. return false;
  18269. }
  18270. }
  18271. /**
  18272. * JSX element with CSS prop
  18273. */
  18274. function isCssProp(path$$1) {
  18275. var parent = path$$1.getParentNode();
  18276. var parentParent = path$$1.getParentNode(1);
  18277. return parentParent && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" && parentParent.name.type === "JSXIdentifier" && parentParent.name.name === "css";
  18278. }
  18279. function isStyledIdentifier(node) {
  18280. return node.type === "Identifier" && node.name === "styled";
  18281. }
  18282. function isStyledExtend(node) {
  18283. return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
  18284. }
  18285. /*
  18286. * react-relay and graphql-tag
  18287. * graphql`...`
  18288. * graphql.experimental`...`
  18289. * gql`...`
  18290. * GraphQL comment block
  18291. *
  18292. * This intentionally excludes Relay Classic tags, as Prettier does not
  18293. * support Relay Classic formatting.
  18294. */
  18295. function isGraphQL(path$$1) {
  18296. var node = path$$1.getValue();
  18297. var parent = path$$1.getParentNode();
  18298. 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");
  18299. }
  18300. function hasLanguageComment(node, languageName) {
  18301. // This checks for a leading comment that is exactly `/* GraphQL */`
  18302. // In order to be in line with other implementations of this comment tag
  18303. // we will not trim the comment value and we will expect exactly one space on
  18304. // either side of the GraphQL string
  18305. // Also see ./clean.js
  18306. return hasLeadingComment$1(node, function (comment) {
  18307. return isBlockComment(comment) && comment.value === ` ${languageName} `;
  18308. });
  18309. }
  18310. function isPathMatch(path$$1, predicateStack) {
  18311. var stack = path$$1.stack.slice();
  18312. var name = null;
  18313. var node = stack.pop();
  18314. var _iteratorNormalCompletion = true;
  18315. var _didIteratorError = false;
  18316. var _iteratorError = undefined;
  18317. try {
  18318. for (var _iterator = predicateStack[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  18319. var predicate = _step.value;
  18320. if (node === undefined) {
  18321. return false;
  18322. } // skip index/array
  18323. if (typeof name === "number") {
  18324. name = stack.pop();
  18325. node = stack.pop();
  18326. }
  18327. if (!predicate(node, name)) {
  18328. return false;
  18329. }
  18330. name = stack.pop();
  18331. node = stack.pop();
  18332. }
  18333. } catch (err) {
  18334. _didIteratorError = true;
  18335. _iteratorError = err;
  18336. } finally {
  18337. try {
  18338. if (!_iteratorNormalCompletion && _iterator.return != null) {
  18339. _iterator.return();
  18340. }
  18341. } finally {
  18342. if (_didIteratorError) {
  18343. throw _iteratorError;
  18344. }
  18345. }
  18346. }
  18347. return true;
  18348. }
  18349. /**
  18350. * - html`...`
  18351. * - HTML comment block
  18352. */
  18353. function isHtml(path$$1) {
  18354. var node = path$$1.getValue();
  18355. return hasLanguageComment(node, "HTML") || isPathMatch(path$$1, [function (node) {
  18356. return node.type === "TemplateLiteral";
  18357. }, function (node, name) {
  18358. return node.type === "TaggedTemplateExpression" && node.tag.type === "Identifier" && node.tag.name === "html" && name === "quasi";
  18359. }]);
  18360. }
  18361. function printHtmlTemplateLiteral(path$$1, print, textToDoc, parser) {
  18362. var node = path$$1.getValue();
  18363. var placeholderPattern = "PRETTIER_HTML_PLACEHOLDER_(\\d+)_IN_JS";
  18364. var placeholders = node.expressions.map(function (_, i) {
  18365. return `PRETTIER_HTML_PLACEHOLDER_${i}_IN_JS`;
  18366. });
  18367. var text = node.quasis.map(function (quasi, index, quasis) {
  18368. return index === quasis.length - 1 ? quasi.value.raw : quasi.value.raw + placeholders[index];
  18369. }).join("");
  18370. var expressionDocs = path$$1.map(print, "expressions");
  18371. if (expressionDocs.length === 0 && text.trim().length === 0) {
  18372. return "``";
  18373. }
  18374. var contentDoc = mapDoc$3(stripTrailingHardline$1(textToDoc(text, {
  18375. parser
  18376. })), function (doc$$2) {
  18377. var placeholderRegex = new RegExp(placeholderPattern, "g");
  18378. var hasPlaceholder = typeof doc$$2 === "string" && placeholderRegex.test(doc$$2);
  18379. if (!hasPlaceholder) {
  18380. return doc$$2;
  18381. }
  18382. var parts = [];
  18383. var components = doc$$2.split(placeholderRegex);
  18384. for (var i = 0; i < components.length; i++) {
  18385. var component = components[i];
  18386. if (i % 2 === 0) {
  18387. if (component) {
  18388. parts.push(component);
  18389. }
  18390. continue;
  18391. }
  18392. var placeholderIndex = +component;
  18393. parts.push(concat$5(["${", group$2(expressionDocs[placeholderIndex]), "}"]));
  18394. }
  18395. return concat$5(parts);
  18396. });
  18397. return group$2(concat$5(["`", indent$3(concat$5([hardline$4, group$2(contentDoc)])), softline$2, "`"]));
  18398. }
  18399. var embed_1 = embed;
  18400. function clean(ast, newObj, parent) {
  18401. ["range", "raw", "comments", "leadingComments", "trailingComments", "extra", "start", "end", "flags"].forEach(function (name) {
  18402. delete newObj[name];
  18403. });
  18404. if (ast.type === "BigIntLiteral") {
  18405. newObj.value = newObj.value.toLowerCase();
  18406. } // We remove extra `;` and add them when needed
  18407. if (ast.type === "EmptyStatement") {
  18408. return null;
  18409. } // We move text around, including whitespaces and add {" "}
  18410. if (ast.type === "JSXText") {
  18411. return null;
  18412. }
  18413. if (ast.type === "JSXExpressionContainer" && ast.expression.type === "Literal" && ast.expression.value === " ") {
  18414. return null;
  18415. } // (TypeScript) Ignore `static` in `constructor(static p) {}`
  18416. // and `export` in `constructor(export p) {}`
  18417. if (ast.type === "TSParameterProperty" && ast.accessibility === null && !ast.readonly) {
  18418. return {
  18419. type: "Identifier",
  18420. name: ast.parameter.name,
  18421. typeAnnotation: newObj.parameter.typeAnnotation,
  18422. decorators: newObj.decorators
  18423. };
  18424. } // (TypeScript) ignore empty `specifiers` array
  18425. if (ast.type === "TSNamespaceExportDeclaration" && ast.specifiers && ast.specifiers.length === 0) {
  18426. delete newObj.specifiers;
  18427. } // (TypeScript) bypass TSParenthesizedType
  18428. if (ast.type === "TSParenthesizedType") {
  18429. return newObj.typeAnnotation;
  18430. } // We convert <div></div> to <div />
  18431. if (ast.type === "JSXOpeningElement") {
  18432. delete newObj.selfClosing;
  18433. }
  18434. if (ast.type === "JSXElement") {
  18435. delete newObj.closingElement;
  18436. } // We change {'key': value} into {key: value}
  18437. 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")) {
  18438. delete newObj.key;
  18439. }
  18440. if (ast.type === "OptionalMemberExpression" && ast.optional === false) {
  18441. newObj.type = "MemberExpression";
  18442. delete newObj.optional;
  18443. } // Remove raw and cooked values from TemplateElement when it's CSS
  18444. // styled-jsx
  18445. if (ast.type === "JSXElement" && ast.openingElement.name.name === "style" && ast.openingElement.attributes.some(function (attr) {
  18446. return attr.name.name === "jsx";
  18447. })) {
  18448. var templateLiterals = newObj.children.filter(function (child) {
  18449. return child.type === "JSXExpressionContainer" && child.expression.type === "TemplateLiteral";
  18450. }).map(function (container) {
  18451. return container.expression;
  18452. });
  18453. var quasis = templateLiterals.reduce(function (quasis, templateLiteral) {
  18454. return quasis.concat(templateLiteral.quasis);
  18455. }, []);
  18456. quasis.forEach(function (q) {
  18457. return delete q.value;
  18458. });
  18459. } // CSS template literals in css prop
  18460. if (ast.type === "JSXAttribute" && ast.name.name === "css" && ast.value.type === "JSXExpressionContainer" && ast.value.expression.type === "TemplateLiteral") {
  18461. newObj.value.expression.quasis.forEach(function (q) {
  18462. return delete q.value;
  18463. });
  18464. } // Angular Components: Inline HTML template and Inline CSS styles
  18465. var expression = ast.expression || ast.callee;
  18466. if (ast.type === "Decorator" && expression.type === "CallExpression" && expression.callee.name === "Component" && expression.arguments.length === 1) {
  18467. var astProps = ast.expression.arguments[0].properties;
  18468. newObj.expression.arguments[0].properties.forEach(function (prop, index) {
  18469. var templateLiteral = null;
  18470. switch (astProps[index].key.name) {
  18471. case "styles":
  18472. if (prop.value.type === "ArrayExpression") {
  18473. templateLiteral = prop.value.elements[0];
  18474. }
  18475. break;
  18476. case "template":
  18477. if (prop.value.type === "TemplateLiteral") {
  18478. templateLiteral = prop.value;
  18479. }
  18480. break;
  18481. }
  18482. if (templateLiteral) {
  18483. templateLiteral.quasis.forEach(function (q) {
  18484. return delete q.value;
  18485. });
  18486. }
  18487. });
  18488. } // styled-components, graphql, markdown
  18489. 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")) {
  18490. newObj.quasi.quasis.forEach(function (quasi) {
  18491. return delete quasi.value;
  18492. });
  18493. }
  18494. if (ast.type === "TemplateLiteral") {
  18495. // This checks for a leading comment that is exactly `/* GraphQL */`
  18496. // In order to be in line with other implementations of this comment tag
  18497. // we will not trim the comment value and we will expect exactly one space on
  18498. // either side of the GraphQL string
  18499. // Also see ./embed.js
  18500. var hasLanguageComment = ast.leadingComments && ast.leadingComments.some(function (comment) {
  18501. return comment.type === "CommentBlock" && ["GraphQL", "HTML"].some(function (languageName) {
  18502. return comment.value === ` ${languageName} `;
  18503. });
  18504. });
  18505. if (hasLanguageComment || parent.type === "CallExpression" && parent.callee.name === "graphql") {
  18506. newObj.quasis.forEach(function (quasi) {
  18507. return delete quasi.value;
  18508. });
  18509. }
  18510. }
  18511. }
  18512. var clean_1 = clean;
  18513. var detectNewline = createCommonjsModule(function (module) {
  18514. 'use strict';
  18515. module.exports = function (str) {
  18516. if (typeof str !== 'string') {
  18517. throw new TypeError('Expected a string');
  18518. }
  18519. var newlines = str.match(/(?:\r?\n)/g) || [];
  18520. if (newlines.length === 0) {
  18521. return null;
  18522. }
  18523. var crlf = newlines.filter(function (el) {
  18524. return el === '\r\n';
  18525. }).length;
  18526. var lf = newlines.length - crlf;
  18527. return crlf > lf ? '\r\n' : '\n';
  18528. };
  18529. module.exports.graceful = function (str) {
  18530. return module.exports(str) || '\n';
  18531. };
  18532. });
  18533. var build$1 = createCommonjsModule(function (module, exports) {
  18534. 'use strict';
  18535. Object.defineProperty(exports, '__esModule', {
  18536. value: true
  18537. });
  18538. exports.extract = extract;
  18539. exports.strip = strip;
  18540. exports.parse = parse;
  18541. exports.parseWithComments = parseWithComments;
  18542. exports.print = print;
  18543. var _detectNewline;
  18544. function _load_detectNewline() {
  18545. return _detectNewline = _interopRequireDefault(detectNewline);
  18546. }
  18547. var _os;
  18548. function _load_os() {
  18549. return _os = os;
  18550. }
  18551. function _interopRequireDefault(obj) {
  18552. return obj && obj.__esModule ? obj : {
  18553. default: obj
  18554. };
  18555. }
  18556. /**
  18557. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  18558. *
  18559. * This source code is licensed under the MIT license found in the
  18560. * LICENSE file in the root directory of this source tree.
  18561. *
  18562. *
  18563. */
  18564. var commentEndRe = /\*\/$/;
  18565. var commentStartRe = /^\/\*\*/;
  18566. var docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
  18567. var lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
  18568. var ltrimNewlineRe = /^(\r?\n)+/;
  18569. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  18570. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  18571. var stringStartRe = /(\r?\n|^) *\* ?/g;
  18572. function extract(contents) {
  18573. var match = contents.match(docblockRe);
  18574. return match ? match[0].trimLeft() : '';
  18575. }
  18576. function strip(contents) {
  18577. var match = contents.match(docblockRe);
  18578. return match && match[0] ? contents.substring(match[0].length) : contents;
  18579. }
  18580. function parse(docblock) {
  18581. return parseWithComments(docblock).pragmas;
  18582. }
  18583. function parseWithComments(docblock) {
  18584. var line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL;
  18585. docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  18586. var prev = '';
  18587. while (prev !== docblock) {
  18588. prev = docblock;
  18589. docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);
  18590. }
  18591. docblock = docblock.replace(ltrimNewlineRe, '').trimRight();
  18592. var result = Object.create(null);
  18593. var comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').trimRight();
  18594. var match;
  18595. while (match = propertyRe.exec(docblock)) {
  18596. // strip linecomments from pragmas
  18597. var nextPragma = match[2].replace(lineCommentRe, '');
  18598. if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
  18599. result[match[1]] = [].concat(result[match[1]], nextPragma);
  18600. } else {
  18601. result[match[1]] = nextPragma;
  18602. }
  18603. }
  18604. return {
  18605. comments,
  18606. pragmas: result
  18607. };
  18608. }
  18609. function print(_ref) {
  18610. var _ref$comments = _ref.comments;
  18611. var comments = _ref$comments === undefined ? '' : _ref$comments;
  18612. var _ref$pragmas = _ref.pragmas;
  18613. var pragmas = _ref$pragmas === undefined ? {} : _ref$pragmas;
  18614. var line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL;
  18615. var head = '/**';
  18616. var start = ' *';
  18617. var tail = ' */';
  18618. var keys = Object.keys(pragmas);
  18619. var printedObject = keys.map(function (key) {
  18620. return printKeyValues(key, pragmas[key]);
  18621. }).reduce(function (arr, next) {
  18622. return arr.concat(next);
  18623. }, []).map(function (keyValue) {
  18624. return start + ' ' + keyValue + line;
  18625. }).join('');
  18626. if (!comments) {
  18627. if (keys.length === 0) {
  18628. return '';
  18629. }
  18630. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  18631. var value = pragmas[keys[0]];
  18632. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  18633. }
  18634. }
  18635. var printedComments = comments.split(line).map(function (textLine) {
  18636. return `${start} ${textLine}`;
  18637. }).join(line) + line;
  18638. return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail;
  18639. }
  18640. function printKeyValues(key, valueOrArray) {
  18641. return [].concat(valueOrArray).map(function (value) {
  18642. return `@${key} ${value}`.trim();
  18643. });
  18644. }
  18645. });
  18646. unwrapExports(build$1);
  18647. function hasPragma(text) {
  18648. var pragmas = Object.keys(build$1.parse(build$1.extract(text)));
  18649. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  18650. }
  18651. function insertPragma$1(text) {
  18652. var parsedDocblock = build$1.parseWithComments(build$1.extract(text));
  18653. var pragmas = Object.assign({
  18654. format: ""
  18655. }, parsedDocblock.pragmas);
  18656. var newDocblock = build$1.print({
  18657. pragmas,
  18658. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  18659. }).replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
  18660. var strippedText = build$1.strip(text);
  18661. var separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  18662. return newDocblock + separatingNewlines + strippedText;
  18663. }
  18664. var pragma = {
  18665. hasPragma,
  18666. insertPragma: insertPragma$1
  18667. };
  18668. // Flow annotation comments cannot be split across lines. For example:
  18669. //
  18670. // (this /*
  18671. // : any */).foo = 5;
  18672. //
  18673. // is not picked up by Flow (see https://github.com/facebook/flow/issues/7050), so
  18674. // removing the newline would create a type annotation that the user did not intend
  18675. // to create.
  18676. var NON_LINE_TERMINATING_WHITE_SPACE = "(?:(?=.)\\s)";
  18677. var FLOW_SHORTHAND_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*:`);
  18678. var FLOW_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*::`);
  18679. function hasFlowShorthandAnnotationComment$2(node) {
  18680. // https://flow.org/en/docs/types/comments/
  18681. // Syntax example: const r = new (window.Request /*: Class<Request> */)("");
  18682. return node.extra && node.extra.parenthesized && node.trailingComments && node.trailingComments[0].value.match(FLOW_SHORTHAND_ANNOTATION);
  18683. }
  18684. function hasFlowAnnotationComment$1(comments) {
  18685. return comments && comments[0].value.match(FLOW_ANNOTATION);
  18686. }
  18687. function hasNode$1(node, fn) {
  18688. if (!node || typeof node !== "object") {
  18689. return false;
  18690. }
  18691. if (Array.isArray(node)) {
  18692. return node.some(function (value) {
  18693. return hasNode$1(value, fn);
  18694. });
  18695. }
  18696. var result = fn(node);
  18697. return typeof result === "boolean" ? result : Object.keys(node).some(function (key) {
  18698. return hasNode$1(node[key], fn);
  18699. });
  18700. }
  18701. var utils$4 = {
  18702. hasNode: hasNode$1,
  18703. hasFlowShorthandAnnotationComment: hasFlowShorthandAnnotationComment$2,
  18704. hasFlowAnnotationComment: hasFlowAnnotationComment$1
  18705. };
  18706. var hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment;
  18707. function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
  18708. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  18709. // Syntax example: var x = /** @type {string} */ (fruit);
  18710. var n = path$$1.getValue();
  18711. return util$1.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
  18712. function hasAncestorTypeCastComment(index) {
  18713. var ancestor = path$$1.getParentNode(index);
  18714. return ancestor && util$1.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
  18715. }
  18716. function hasTypeCastComment(node) {
  18717. return node.comments && node.comments.some(function (comment) {
  18718. return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
  18719. });
  18720. }
  18721. function isTypeCastComment(comment) {
  18722. var trimmed = comment.trim();
  18723. if (!/^\*\s*@type\s*\{[^]+\}$/.test(trimmed)) {
  18724. return false;
  18725. }
  18726. var isCompletelyClosed = false;
  18727. var unpairedBracketCount = 0;
  18728. var _iteratorNormalCompletion = true;
  18729. var _didIteratorError = false;
  18730. var _iteratorError = undefined;
  18731. try {
  18732. for (var _iterator = trimmed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  18733. var char = _step.value;
  18734. if (char === "{") {
  18735. if (isCompletelyClosed) {
  18736. return false;
  18737. }
  18738. unpairedBracketCount++;
  18739. } else if (char === "}") {
  18740. if (unpairedBracketCount === 0) {
  18741. return false;
  18742. }
  18743. unpairedBracketCount--;
  18744. if (unpairedBracketCount === 0) {
  18745. isCompletelyClosed = true;
  18746. }
  18747. }
  18748. }
  18749. } catch (err) {
  18750. _didIteratorError = true;
  18751. _iteratorError = err;
  18752. } finally {
  18753. try {
  18754. if (!_iteratorNormalCompletion && _iterator.return != null) {
  18755. _iterator.return();
  18756. }
  18757. } finally {
  18758. if (_didIteratorError) {
  18759. throw _iteratorError;
  18760. }
  18761. }
  18762. }
  18763. return unpairedBracketCount === 0;
  18764. }
  18765. }
  18766. function needsParens(path$$1, options) {
  18767. var parent = path$$1.getParentNode();
  18768. if (!parent) {
  18769. return false;
  18770. }
  18771. var name = path$$1.getName();
  18772. var node = path$$1.getNode(); // If the value of this path is some child of a Node and not a Node
  18773. // itself, then it doesn't need parentheses. Only Node objects (in
  18774. // fact, only Expression nodes) need parentheses.
  18775. if (path$$1.getValue() !== node) {
  18776. return false;
  18777. } // to avoid unexpected `}}` in HTML interpolations
  18778. if (options.__isInHtmlInterpolation && !options.bracketSpacing && endsWithRightBracket(node) && isFollowedByRightBracket(path$$1)) {
  18779. return true;
  18780. } // Only statements don't need parentheses.
  18781. if (isStatement(node)) {
  18782. return false;
  18783. } // Closure compiler requires that type casted expressions to be surrounded by
  18784. // parentheses.
  18785. if (hasClosureCompilerTypeCastComment(options.originalText, path$$1, options.locStart, options.locEnd)) {
  18786. return true;
  18787. }
  18788. if ( // Preserve parens if we have a Flow annotation comment, unless we're using the Flow
  18789. // parser. The Flow parser turns Flow comments into type annotation nodes in its
  18790. // AST, which we handle separately.
  18791. options.parser !== "flow" && hasFlowShorthandAnnotationComment$1(path$$1.getValue())) {
  18792. return true;
  18793. } // Identifiers never need parentheses.
  18794. if (node.type === "Identifier") {
  18795. return false;
  18796. }
  18797. if (parent.type === "ParenthesizedExpression") {
  18798. return false;
  18799. } // Add parens around the extends clause of a class. It is needed for almost
  18800. // all expressions.
  18801. 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")) {
  18802. return true;
  18803. }
  18804. if (parent.type === "Decorator" && parent.expression === node) {
  18805. var hasCallExpression = false;
  18806. var hasMemberExpression = false;
  18807. var current = node;
  18808. while (current) {
  18809. switch (current.type) {
  18810. case "MemberExpression":
  18811. hasMemberExpression = true;
  18812. current = current.object;
  18813. break;
  18814. case "CallExpression":
  18815. if (
  18816. /** @(x().y) */
  18817. hasMemberExpression ||
  18818. /** @(x().y()) */
  18819. hasCallExpression) {
  18820. return true;
  18821. }
  18822. hasCallExpression = true;
  18823. current = current.callee;
  18824. break;
  18825. case "Identifier":
  18826. return false;
  18827. default:
  18828. return true;
  18829. }
  18830. }
  18831. return true;
  18832. }
  18833. if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
  18834. util$1.startsWithNoLookaheadToken(node,
  18835. /* forbidFunctionClassAndDoExpr */
  18836. false) || parent.type === "ExpressionStatement" && util$1.startsWithNoLookaheadToken(node,
  18837. /* forbidFunctionClassAndDoExpr */
  18838. true)) {
  18839. return true;
  18840. }
  18841. switch (node.type) {
  18842. case "CallExpression":
  18843. {
  18844. var firstParentNotMemberExpression = parent;
  18845. var i = 0;
  18846. while (firstParentNotMemberExpression && firstParentNotMemberExpression.type === "MemberExpression") {
  18847. firstParentNotMemberExpression = path$$1.getParentNode(++i);
  18848. }
  18849. if (firstParentNotMemberExpression.type === "NewExpression" && firstParentNotMemberExpression.callee === path$$1.getParentNode(i - 1)) {
  18850. return true;
  18851. }
  18852. if (parent.type === "BindExpression" && parent.callee === node) {
  18853. return true;
  18854. }
  18855. return false;
  18856. }
  18857. case "SpreadElement":
  18858. case "SpreadProperty":
  18859. return parent.type === "MemberExpression" && name === "object" && parent.object === node;
  18860. case "UpdateExpression":
  18861. if (parent.type === "UnaryExpression") {
  18862. return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-");
  18863. }
  18864. // else fallthrough
  18865. case "UnaryExpression":
  18866. switch (parent.type) {
  18867. case "UnaryExpression":
  18868. return node.operator === parent.operator && (node.operator === "+" || node.operator === "-");
  18869. case "BindExpression":
  18870. return true;
  18871. case "MemberExpression":
  18872. return name === "object" && parent.object === node;
  18873. case "TaggedTemplateExpression":
  18874. return true;
  18875. case "NewExpression":
  18876. case "CallExpression":
  18877. return name === "callee" && parent.callee === node;
  18878. case "BinaryExpression":
  18879. return parent.operator === "**" && name === "left";
  18880. case "TSNonNullExpression":
  18881. return true;
  18882. default:
  18883. return false;
  18884. }
  18885. case "BinaryExpression":
  18886. {
  18887. if (parent.type === "UpdateExpression") {
  18888. return true;
  18889. }
  18890. var isLeftOfAForStatement = function isLeftOfAForStatement(node) {
  18891. var i = 0;
  18892. while (node) {
  18893. var _parent = path$$1.getParentNode(i++);
  18894. if (!_parent) {
  18895. return false;
  18896. }
  18897. if (_parent.type === "ForStatement" && _parent.init === node) {
  18898. return true;
  18899. }
  18900. node = _parent;
  18901. }
  18902. return false;
  18903. };
  18904. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  18905. return true;
  18906. }
  18907. }
  18908. // fallthrough
  18909. case "TSTypeAssertion":
  18910. case "TSAsExpression":
  18911. case "LogicalExpression":
  18912. switch (parent.type) {
  18913. case "ConditionalExpression":
  18914. return node.type === "TSAsExpression";
  18915. case "CallExpression":
  18916. case "NewExpression":
  18917. return name === "callee" && parent.callee === node;
  18918. case "ClassExpression":
  18919. case "ClassDeclaration":
  18920. case "TSAbstractClassDeclaration":
  18921. return name === "superClass" && parent.superClass === node;
  18922. case "TSTypeAssertion":
  18923. case "TaggedTemplateExpression":
  18924. case "UnaryExpression":
  18925. case "SpreadElement":
  18926. case "SpreadProperty":
  18927. case "BindExpression":
  18928. case "AwaitExpression":
  18929. case "TSAsExpression":
  18930. case "TSNonNullExpression":
  18931. case "UpdateExpression":
  18932. return true;
  18933. case "MemberExpression":
  18934. case "OptionalMemberExpression":
  18935. return name === "object" && parent.object === node;
  18936. case "AssignmentExpression":
  18937. return parent.left === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression");
  18938. case "BinaryExpression":
  18939. case "LogicalExpression":
  18940. {
  18941. if (!node.operator && node.type !== "TSTypeAssertion") {
  18942. return true;
  18943. }
  18944. var po = parent.operator;
  18945. var pp = util$1.getPrecedence(po);
  18946. var no = node.operator;
  18947. var np = util$1.getPrecedence(no);
  18948. if (pp > np) {
  18949. return true;
  18950. }
  18951. if ((po === "||" || po === "??") && no === "&&") {
  18952. return true;
  18953. }
  18954. if (pp === np && name === "right") {
  18955. assert.strictEqual(parent.right, node);
  18956. return true;
  18957. }
  18958. if (pp === np && !util$1.shouldFlatten(po, no)) {
  18959. return true;
  18960. }
  18961. if (pp < np && no === "%") {
  18962. return po === "+" || po === "-";
  18963. } // Add parenthesis when working with bitwise operators
  18964. // It's not stricly needed but helps with code understanding
  18965. if (util$1.isBitwiseOperator(po)) {
  18966. return true;
  18967. }
  18968. return false;
  18969. }
  18970. default:
  18971. return false;
  18972. }
  18973. case "TSParenthesizedType":
  18974. {
  18975. var grandParent = path$$1.getParentNode(1);
  18976. /**
  18977. * const foo = (): (() => void) => (): void => null;
  18978. * ^ ^
  18979. */
  18980. if (getUnparenthesizedNode(node).type === "TSFunctionType" && parent.type === "TSTypeAnnotation" && grandParent.type === "ArrowFunctionExpression" && grandParent.returnType === parent) {
  18981. return true;
  18982. }
  18983. 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") {
  18984. return false;
  18985. } // Delegate to inner TSParenthesizedType
  18986. if (node.typeAnnotation.type === "TSParenthesizedType") {
  18987. return false;
  18988. }
  18989. return true;
  18990. }
  18991. case "SequenceExpression":
  18992. switch (parent.type) {
  18993. case "ReturnStatement":
  18994. return false;
  18995. case "ForStatement":
  18996. // Although parentheses wouldn't hurt around sequence
  18997. // expressions in the head of for loops, traditional style
  18998. // dictates that e.g. i++, j++ should not be wrapped with
  18999. // parentheses.
  19000. return false;
  19001. case "ExpressionStatement":
  19002. return name !== "expression";
  19003. case "ArrowFunctionExpression":
  19004. // We do need parentheses, but SequenceExpressions are handled
  19005. // specially when printing bodies of arrow functions.
  19006. return name !== "body";
  19007. default:
  19008. // Otherwise err on the side of overparenthesization, adding
  19009. // explicit exceptions above if this proves overzealous.
  19010. return true;
  19011. }
  19012. case "YieldExpression":
  19013. if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") {
  19014. return true;
  19015. }
  19016. // else fallthrough
  19017. case "AwaitExpression":
  19018. switch (parent.type) {
  19019. case "TaggedTemplateExpression":
  19020. case "UnaryExpression":
  19021. case "BinaryExpression":
  19022. case "LogicalExpression":
  19023. case "SpreadElement":
  19024. case "SpreadProperty":
  19025. case "TSAsExpression":
  19026. case "TSNonNullExpression":
  19027. case "BindExpression":
  19028. return true;
  19029. case "MemberExpression":
  19030. return parent.object === node;
  19031. case "NewExpression":
  19032. case "CallExpression":
  19033. return parent.callee === node;
  19034. case "ConditionalExpression":
  19035. return parent.test === node;
  19036. default:
  19037. return false;
  19038. }
  19039. case "ArrayTypeAnnotation":
  19040. return parent.type === "NullableTypeAnnotation";
  19041. case "IntersectionTypeAnnotation":
  19042. case "UnionTypeAnnotation":
  19043. return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation";
  19044. case "NullableTypeAnnotation":
  19045. return parent.type === "ArrayTypeAnnotation";
  19046. case "FunctionTypeAnnotation":
  19047. {
  19048. var ancestor = parent.type === "NullableTypeAnnotation" ? path$$1.getParentNode(1) : parent;
  19049. return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses
  19050. // are really needed, but since ??T doesn't make sense this check
  19051. // will almost never be true.
  19052. ancestor.type === "NullableTypeAnnotation";
  19053. }
  19054. case "StringLiteral":
  19055. case "NumericLiteral":
  19056. case "Literal":
  19057. if (typeof node.value === "string" && parent.type === "ExpressionStatement" && ( // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  19058. // See corresponding workaround in printer.js case: "Literal"
  19059. options.parser !== "typescript" && !parent.directive || options.parser === "typescript" && options.originalText.substr(options.locStart(node) - 1, 1) === "(")) {
  19060. // To avoid becoming a directive
  19061. var _grandParent = path$$1.getParentNode(1);
  19062. return _grandParent.type === "Program" || _grandParent.type === "BlockStatement";
  19063. }
  19064. return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node;
  19065. case "AssignmentExpression":
  19066. {
  19067. var _grandParent2 = path$$1.getParentNode(1);
  19068. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  19069. return true;
  19070. } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) {
  19071. return false;
  19072. } else if (parent.type === "TSPropertySignature" && parent.name === node) {
  19073. return false;
  19074. } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) {
  19075. return false;
  19076. } else if (parent.type === "ExpressionStatement") {
  19077. return node.left.type === "ObjectPattern";
  19078. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  19079. return false;
  19080. } else if (parent.type === "AssignmentExpression") {
  19081. return false;
  19082. } else if (parent.type === "SequenceExpression" && _grandParent2 && _grandParent2.type === "ForStatement" && (_grandParent2.init === parent || _grandParent2.update === parent)) {
  19083. return false;
  19084. } else if (parent.type === "Property" && parent.value === node) {
  19085. return false;
  19086. } else if (parent.type === "NGChainedExpression") {
  19087. return false;
  19088. }
  19089. return true;
  19090. }
  19091. case "ConditionalExpression":
  19092. switch (parent.type) {
  19093. case "TaggedTemplateExpression":
  19094. case "UnaryExpression":
  19095. case "SpreadElement":
  19096. case "SpreadProperty":
  19097. case "BinaryExpression":
  19098. case "LogicalExpression":
  19099. case "NGPipeExpression":
  19100. case "ExportDefaultDeclaration":
  19101. case "AwaitExpression":
  19102. case "JSXSpreadAttribute":
  19103. case "TSTypeAssertion":
  19104. case "TypeCastExpression":
  19105. case "TSAsExpression":
  19106. case "TSNonNullExpression":
  19107. case "OptionalMemberExpression":
  19108. return true;
  19109. case "NewExpression":
  19110. case "CallExpression":
  19111. return name === "callee" && parent.callee === node;
  19112. case "ConditionalExpression":
  19113. return name === "test" && parent.test === node;
  19114. case "MemberExpression":
  19115. return name === "object" && parent.object === node;
  19116. default:
  19117. return false;
  19118. }
  19119. case "FunctionExpression":
  19120. switch (parent.type) {
  19121. case "CallExpression":
  19122. return name === "callee";
  19123. // Not strictly necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  19124. case "TaggedTemplateExpression":
  19125. return true;
  19126. // This is basically a kind of IIFE.
  19127. case "ExportDefaultDeclaration":
  19128. return true;
  19129. default:
  19130. return false;
  19131. }
  19132. case "ArrowFunctionExpression":
  19133. switch (parent.type) {
  19134. case "CallExpression":
  19135. return name === "callee";
  19136. case "NewExpression":
  19137. return name === "callee";
  19138. case "MemberExpression":
  19139. return name === "object";
  19140. case "TSAsExpression":
  19141. case "BindExpression":
  19142. case "TaggedTemplateExpression":
  19143. case "UnaryExpression":
  19144. case "LogicalExpression":
  19145. case "BinaryExpression":
  19146. case "AwaitExpression":
  19147. case "TSTypeAssertion":
  19148. return true;
  19149. case "ConditionalExpression":
  19150. return name === "test";
  19151. default:
  19152. return false;
  19153. }
  19154. case "ClassExpression":
  19155. return parent.type === "ExportDefaultDeclaration";
  19156. case "OptionalMemberExpression":
  19157. return parent.type === "MemberExpression";
  19158. case "MemberExpression":
  19159. if (parent.type === "BindExpression" && name === "callee" && parent.callee === node) {
  19160. var object = node.object;
  19161. while (object) {
  19162. if (object.type === "CallExpression") {
  19163. return true;
  19164. }
  19165. if (object.type !== "MemberExpression" && object.type !== "BindExpression") {
  19166. break;
  19167. }
  19168. object = object.object;
  19169. }
  19170. }
  19171. return false;
  19172. case "BindExpression":
  19173. if (parent.type === "BindExpression" && name === "callee" && parent.callee === node || parent.type === "MemberExpression") {
  19174. return true;
  19175. }
  19176. return false;
  19177. case "NGPipeExpression":
  19178. if (parent.type === "NGRoot" || 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") {
  19179. return false;
  19180. }
  19181. return true;
  19182. }
  19183. return false;
  19184. }
  19185. function isStatement(node) {
  19186. return node.type === "BlockStatement" || node.type === "BreakStatement" || node.type === "ClassBody" || node.type === "ClassDeclaration" || node.type === "ClassMethod" || node.type === "ClassProperty" || node.type === "ClassPrivateProperty" || node.type === "ContinueStatement" || node.type === "DebuggerStatement" || node.type === "DeclareClass" || node.type === "DeclareExportAllDeclaration" || node.type === "DeclareExportDeclaration" || node.type === "DeclareFunction" || node.type === "DeclareInterface" || node.type === "DeclareModule" || node.type === "DeclareModuleExports" || node.type === "DeclareVariable" || node.type === "DoWhileStatement" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExpressionStatement" || node.type === "ForAwaitStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || node.type === "FunctionDeclaration" || node.type === "IfStatement" || node.type === "ImportDeclaration" || node.type === "InterfaceDeclaration" || node.type === "LabeledStatement" || node.type === "MethodDefinition" || node.type === "ReturnStatement" || node.type === "SwitchStatement" || node.type === "ThrowStatement" || node.type === "TryStatement" || node.type === "TSAbstractClassDeclaration" || node.type === "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";
  19187. }
  19188. function getUnparenthesizedNode(node) {
  19189. return node.type === "TSParenthesizedType" ? getUnparenthesizedNode(node.typeAnnotation) : node;
  19190. }
  19191. function endsWithRightBracket(node) {
  19192. switch (node.type) {
  19193. case "ObjectExpression":
  19194. return true;
  19195. default:
  19196. return false;
  19197. }
  19198. }
  19199. function isFollowedByRightBracket(path$$1) {
  19200. var node = path$$1.getValue();
  19201. var parent = path$$1.getParentNode();
  19202. var name = path$$1.getName();
  19203. switch (parent.type) {
  19204. case "NGPipeExpression":
  19205. if (typeof name === "number" && parent.arguments[name] === node && parent.arguments.length - 1 === name) {
  19206. return path$$1.callParent(isFollowedByRightBracket);
  19207. }
  19208. break;
  19209. case "ObjectProperty":
  19210. if (name === "value") {
  19211. var parentParent = path$$1.getParentNode(1);
  19212. return parentParent.properties[parentParent.properties.length - 1] === parent;
  19213. }
  19214. break;
  19215. case "BinaryExpression":
  19216. case "LogicalExpression":
  19217. if (name === "right") {
  19218. return path$$1.callParent(isFollowedByRightBracket);
  19219. }
  19220. break;
  19221. case "ConditionalExpression":
  19222. if (name === "alternate") {
  19223. return path$$1.callParent(isFollowedByRightBracket);
  19224. }
  19225. break;
  19226. case "UnaryExpression":
  19227. if (parent.prefix) {
  19228. return path$$1.callParent(isFollowedByRightBracket);
  19229. }
  19230. break;
  19231. }
  19232. return false;
  19233. }
  19234. var needsParens_1 = needsParens;
  19235. var _require$$0$builders$1 = doc.builders;
  19236. var concat$6 = _require$$0$builders$1.concat;
  19237. var join$4 = _require$$0$builders$1.join;
  19238. var line$4 = _require$$0$builders$1.line;
  19239. function printHtmlBinding$1(path$$1, options, print) {
  19240. var node = path$$1.getValue();
  19241. if (options.__onHtmlBindingRoot && path$$1.getName() === null) {
  19242. options.__onHtmlBindingRoot(node);
  19243. }
  19244. if (node.type !== "File") {
  19245. return;
  19246. }
  19247. if (options.__isVueForBindingLeft) {
  19248. return path$$1.call(function (functionDeclarationPath) {
  19249. var _functionDeclarationP = functionDeclarationPath.getValue(),
  19250. params = _functionDeclarationP.params;
  19251. return concat$6([params.length > 1 ? "(" : "", join$4(concat$6([",", line$4]), functionDeclarationPath.map(print, "params")), params.length > 1 ? ")" : ""]);
  19252. }, "program", "body", 0);
  19253. }
  19254. if (options.__isVueSlotScope) {
  19255. return path$$1.call(function (functionDeclarationPath) {
  19256. return join$4(concat$6([",", line$4]), functionDeclarationPath.map(print, "params"));
  19257. }, "program", "body", 0);
  19258. }
  19259. } // based on https://github.com/prettier/prettier/blob/master/src/language-html/syntax-vue.js isVueEventBindingExpression()
  19260. function isVueEventBindingExpression$1(node) {
  19261. switch (node.type) {
  19262. case "MemberExpression":
  19263. switch (node.property.type) {
  19264. case "Identifier":
  19265. case "NumericLiteral":
  19266. case "StringLiteral":
  19267. return isVueEventBindingExpression$1(node.object);
  19268. }
  19269. return false;
  19270. case "Identifier":
  19271. return true;
  19272. default:
  19273. return false;
  19274. }
  19275. }
  19276. var htmlBinding = {
  19277. isVueEventBindingExpression: isVueEventBindingExpression$1,
  19278. printHtmlBinding: printHtmlBinding$1
  19279. };
  19280. function preprocess(ast, options) {
  19281. switch (options.parser) {
  19282. case "json":
  19283. case "json5":
  19284. case "json-stringify":
  19285. case "__js_expression":
  19286. case "__vue_expression":
  19287. return Object.assign({}, ast, {
  19288. type: options.parser.startsWith("__") ? "JsExpressionRoot" : "JsonRoot",
  19289. node: ast,
  19290. comments: []
  19291. });
  19292. default:
  19293. return ast;
  19294. }
  19295. }
  19296. var preprocess_1 = preprocess;
  19297. var getParentExportDeclaration$1 = util$1.getParentExportDeclaration;
  19298. var isExportDeclaration$1 = util$1.isExportDeclaration;
  19299. var shouldFlatten$1 = util$1.shouldFlatten;
  19300. var getNextNonSpaceNonCommentCharacter$1 = util$1.getNextNonSpaceNonCommentCharacter;
  19301. var hasNewline$2 = util$1.hasNewline;
  19302. var hasNewlineInRange$1 = util$1.hasNewlineInRange;
  19303. var getLast$4 = util$1.getLast;
  19304. var getStringWidth$2 = util$1.getStringWidth;
  19305. var printString$1 = util$1.printString;
  19306. var printNumber$1 = util$1.printNumber;
  19307. var hasIgnoreComment$1 = util$1.hasIgnoreComment;
  19308. var skipWhitespace$1 = util$1.skipWhitespace;
  19309. var hasNodeIgnoreComment$1 = util$1.hasNodeIgnoreComment;
  19310. var getPenultimate$1 = util$1.getPenultimate;
  19311. var startsWithNoLookaheadToken$1 = util$1.startsWithNoLookaheadToken;
  19312. var getIndentSize$1 = util$1.getIndentSize;
  19313. var matchAncestorTypes$1 = util$1.matchAncestorTypes;
  19314. var getPreferredQuote$1 = util$1.getPreferredQuote;
  19315. var isNextLineEmpty$2 = utilShared.isNextLineEmpty;
  19316. var isNextLineEmptyAfterIndex$1 = utilShared.isNextLineEmptyAfterIndex;
  19317. var getNextNonSpaceNonCommentCharacterIndex$2 = utilShared.getNextNonSpaceNonCommentCharacterIndex;
  19318. var isIdentifierName = utils$2.keyword.isIdentifierNameES5;
  19319. var insertPragma = pragma.insertPragma;
  19320. var printHtmlBinding = htmlBinding.printHtmlBinding;
  19321. var isVueEventBindingExpression = htmlBinding.isVueEventBindingExpression;
  19322. var hasNode = utils$4.hasNode;
  19323. var hasFlowAnnotationComment = utils$4.hasFlowAnnotationComment;
  19324. var hasFlowShorthandAnnotationComment = utils$4.hasFlowShorthandAnnotationComment;
  19325. var _require$$6$builders = doc.builders;
  19326. var concat$4 = _require$$6$builders.concat;
  19327. var join$2 = _require$$6$builders.join;
  19328. var line$3 = _require$$6$builders.line;
  19329. var hardline$3 = _require$$6$builders.hardline;
  19330. var softline$1 = _require$$6$builders.softline;
  19331. var literalline$1 = _require$$6$builders.literalline;
  19332. var group$1 = _require$$6$builders.group;
  19333. var indent$2 = _require$$6$builders.indent;
  19334. var align$1 = _require$$6$builders.align;
  19335. var conditionalGroup$1 = _require$$6$builders.conditionalGroup;
  19336. var fill$2 = _require$$6$builders.fill;
  19337. var ifBreak$1 = _require$$6$builders.ifBreak;
  19338. var breakParent$2 = _require$$6$builders.breakParent;
  19339. var lineSuffixBoundary$1 = _require$$6$builders.lineSuffixBoundary;
  19340. var addAlignmentToDoc$2 = _require$$6$builders.addAlignmentToDoc;
  19341. var dedent$2 = _require$$6$builders.dedent;
  19342. var _require$$6$utils = doc.utils;
  19343. var willBreak$1 = _require$$6$utils.willBreak;
  19344. var isLineNext$1 = _require$$6$utils.isLineNext;
  19345. var isEmpty$1 = _require$$6$utils.isEmpty;
  19346. var removeLines$1 = _require$$6$utils.removeLines;
  19347. var printDocToString$2 = doc.printer.printDocToString;
  19348. var uid = 0;
  19349. function shouldPrintComma(options, level) {
  19350. level = level || "es5";
  19351. switch (options.trailingComma) {
  19352. case "all":
  19353. if (level === "all") {
  19354. return true;
  19355. }
  19356. // fallthrough
  19357. case "es5":
  19358. if (level === "es5") {
  19359. return true;
  19360. }
  19361. // fallthrough
  19362. case "none":
  19363. default:
  19364. return false;
  19365. }
  19366. }
  19367. function genericPrint(path$$1, options, printPath, args) {
  19368. var node = path$$1.getValue();
  19369. var needsParens = false;
  19370. var linesWithoutParens = printPathNoParens(path$$1, options, printPath, args);
  19371. if (!node || isEmpty$1(linesWithoutParens)) {
  19372. return linesWithoutParens;
  19373. }
  19374. var parentExportDecl = getParentExportDeclaration$1(path$$1);
  19375. var decorators = [];
  19376. 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
  19377. } else if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration and the decorator
  19378. // was written before the export, the export will be responsible
  19379. // for printing the decorators.
  19380. !(parentExportDecl && options.locStart(parentExportDecl, {
  19381. ignoreDecorators: true
  19382. }) > options.locStart(node.decorators[0]))) {
  19383. var shouldBreak = node.type === "ClassExpression" || node.type === "ClassDeclaration" || hasNewlineBetweenOrAfterDecorators(node, options);
  19384. var separator = shouldBreak ? hardline$3 : line$3;
  19385. path$$1.each(function (decoratorPath) {
  19386. var decorator = decoratorPath.getValue();
  19387. if (decorator.expression) {
  19388. decorator = decorator.expression;
  19389. } else {
  19390. decorator = decorator.callee;
  19391. }
  19392. decorators.push(printPath(decoratorPath), separator);
  19393. }, "decorators");
  19394. if (parentExportDecl) {
  19395. decorators.unshift(hardline$3);
  19396. }
  19397. } 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,
  19398. // otherwise they are printed by the node.declaration
  19399. options.locStart(node, {
  19400. ignoreDecorators: true
  19401. }) > options.locStart(node.declaration.decorators[0])) {
  19402. // Export declarations are responsible for printing any decorators
  19403. // that logically apply to node.declaration.
  19404. path$$1.each(function (decoratorPath) {
  19405. var decorator = decoratorPath.getValue();
  19406. var prefix = decorator.type === "Decorator" ? "" : "@";
  19407. decorators.push(prefix, printPath(decoratorPath), hardline$3);
  19408. }, "declaration", "decorators");
  19409. } else {
  19410. // Nodes with decorators can't have parentheses, so we can avoid
  19411. // computing pathNeedsParens() except in this case.
  19412. needsParens = needsParens_1(path$$1, options);
  19413. }
  19414. var parts = [];
  19415. if (needsParens) {
  19416. parts.unshift("(");
  19417. }
  19418. parts.push(linesWithoutParens);
  19419. if (needsParens) {
  19420. var _node = path$$1.getValue();
  19421. if (hasFlowShorthandAnnotationComment(_node)) {
  19422. parts.push(" /*");
  19423. parts.push(_node.trailingComments[0].value.trimLeft());
  19424. parts.push("*/");
  19425. _node.trailingComments[0].printed = true;
  19426. }
  19427. parts.push(")");
  19428. }
  19429. if (decorators.length > 0) {
  19430. return group$1(concat$4(decorators.concat(parts)));
  19431. }
  19432. return concat$4(parts);
  19433. }
  19434. function hasNewlineBetweenOrAfterDecorators(node, options) {
  19435. return hasNewlineInRange$1(options.originalText, options.locStart(node.decorators[0]), options.locEnd(getLast$4(node.decorators))) || hasNewline$2(options.originalText, options.locEnd(getLast$4(node.decorators)));
  19436. }
  19437. function printDecorators(path$$1, options, print) {
  19438. var node = path$$1.getValue();
  19439. return group$1(concat$4([join$2(line$3, path$$1.map(print, "decorators")), hasNewlineBetweenOrAfterDecorators(node, options) ? hardline$3 : line$3]));
  19440. }
  19441. function hasPrettierIgnore(path$$1) {
  19442. return hasIgnoreComment$1(path$$1) || hasJsxIgnoreComment(path$$1);
  19443. }
  19444. function hasJsxIgnoreComment(path$$1) {
  19445. var node = path$$1.getValue();
  19446. var parent = path$$1.getParentNode();
  19447. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  19448. return false;
  19449. } // Lookup the previous sibling, ignoring any empty JSXText elements
  19450. var index = parent.children.indexOf(node);
  19451. var prevSibling = null;
  19452. for (var i = index; i > 0; i--) {
  19453. var candidate = parent.children[i - 1];
  19454. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  19455. continue;
  19456. }
  19457. prevSibling = candidate;
  19458. break;
  19459. }
  19460. return prevSibling && prevSibling.type === "JSXExpressionContainer" && prevSibling.expression.type === "JSXEmptyExpression" && prevSibling.expression.comments && prevSibling.expression.comments.find(function (comment) {
  19461. return comment.value.trim() === "prettier-ignore";
  19462. });
  19463. }
  19464. /**
  19465. * The following is the shared logic for
  19466. * ternary operators, namely ConditionalExpression
  19467. * and TSConditionalType
  19468. * @typedef {Object} OperatorOptions
  19469. * @property {() => Array<string | Doc>} beforeParts - Parts to print before the `?`.
  19470. * @property {(breakClosingParen: boolean) => Array<string | Doc>} afterParts - Parts to print after the conditional expression.
  19471. * @property {boolean} shouldCheckJsx - Whether to check for and print in JSX mode.
  19472. * @property {string} conditionalNodeType - The type of the conditional expression node, ie "ConditionalExpression" or "TSConditionalType".
  19473. * @property {string} consequentNodePropertyName - The property at which the consequent node can be found on the main node, eg "consequent".
  19474. * @property {string} alternateNodePropertyName - The property at which the alternate node can be found on the main node, eg "alternate".
  19475. * @property {string} testNodePropertyName - The property at which the test node can be found on the main node, eg "test".
  19476. * @property {boolean} breakNested - Whether to break all nested ternaries when one breaks.
  19477. * @param {FastPath} path - The path to the ConditionalExpression/TSConditionalType node.
  19478. * @param {Options} options - Prettier options
  19479. * @param {Function} print - Print function to call recursively
  19480. * @param {OperatorOptions} operatorOptions
  19481. * @returns Doc
  19482. */
  19483. function printTernaryOperator(path$$1, options, print, operatorOptions) {
  19484. var node = path$$1.getValue();
  19485. var testNode = node[operatorOptions.testNodePropertyName];
  19486. var consequentNode = node[operatorOptions.consequentNodePropertyName];
  19487. var alternateNode = node[operatorOptions.alternateNodePropertyName];
  19488. var parts = []; // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  19489. // See tests/jsx/conditional-expression.js for more info.
  19490. var jsxMode = false;
  19491. var parent = path$$1.getParentNode();
  19492. var forceNoIndent = parent.type === operatorOptions.conditionalNodeType; // Find the outermost non-ConditionalExpression parent, and the outermost
  19493. // ConditionalExpression parent. We'll use these to determine if we should
  19494. // print in JSX mode.
  19495. var currentParent;
  19496. var previousParent;
  19497. var i = 0;
  19498. do {
  19499. previousParent = currentParent || node;
  19500. currentParent = path$$1.getParentNode(i);
  19501. i++;
  19502. } while (currentParent && currentParent.type === operatorOptions.conditionalNodeType);
  19503. var firstNonConditionalParent = currentParent || parent;
  19504. var lastConditionalParent = previousParent;
  19505. if (operatorOptions.shouldCheckJsx && (isJSXNode(testNode) || isJSXNode(consequentNode) || isJSXNode(alternateNode) || conditionalExpressionChainContainsJSX(lastConditionalParent))) {
  19506. jsxMode = true;
  19507. forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in
  19508. // parens when using ?: within JSX, because the parens are analogous to
  19509. // curly braces in an if statement.
  19510. var wrap = function wrap(doc$$2) {
  19511. return concat$4([ifBreak$1("(", ""), indent$2(concat$4([softline$1, doc$$2])), softline$1, ifBreak$1(")", "")]);
  19512. }; // The only things we don't wrap are:
  19513. // * Nested conditional expressions in alternates
  19514. // * null
  19515. var isNull = function isNull(node) {
  19516. return node.type === "NullLiteral" || node.type === "Literal" && node.value === null;
  19517. };
  19518. 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)));
  19519. } else {
  19520. // normal mode
  19521. 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))]);
  19522. 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));
  19523. } // We want a whole chain of ConditionalExpressions to all
  19524. // break if any of them break. That means we should only group around the
  19525. // outer-most ConditionalExpression.
  19526. var maybeGroup = function maybeGroup(doc$$2) {
  19527. return operatorOptions.breakNested ? parent === firstNonConditionalParent ? group$1(doc$$2) : doc$$2 : group$1(doc$$2);
  19528. }; // Break the closing paren to keep the chain right after it:
  19529. // (a
  19530. // ? b
  19531. // : c
  19532. // ).call()
  19533. var breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && !parent.computed;
  19534. return maybeGroup(concat$4([].concat(function (testDoc) {
  19535. return (
  19536. /**
  19537. * a
  19538. * ? b
  19539. * : multiline
  19540. * test
  19541. * node
  19542. * ^^ align(2)
  19543. * ? d
  19544. * : e
  19545. */
  19546. parent.type === operatorOptions.conditionalNodeType && parent[operatorOptions.alternateNodePropertyName] === node ? align$1(2, testDoc) : testDoc
  19547. );
  19548. }(concat$4(operatorOptions.beforeParts())), forceNoIndent ? concat$4(parts) : indent$2(concat$4(parts)), operatorOptions.afterParts(breakClosingParen))));
  19549. }
  19550. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  19551. if (tokenNode === "+") {
  19552. return "+" + keyword;
  19553. } else if (tokenNode === "-") {
  19554. return "-" + keyword;
  19555. }
  19556. return keyword;
  19557. }
  19558. function printPathNoParens(path$$1, options, print, args) {
  19559. var n = path$$1.getValue();
  19560. var semi = options.semi ? ";" : "";
  19561. if (!n) {
  19562. return "";
  19563. }
  19564. if (typeof n === "string") {
  19565. return n;
  19566. }
  19567. var htmlBinding$$1 = printHtmlBinding(path$$1, options, print);
  19568. if (htmlBinding$$1) {
  19569. return htmlBinding$$1;
  19570. }
  19571. var parts = [];
  19572. switch (n.type) {
  19573. case "JsExpressionRoot":
  19574. return path$$1.call(print, "node");
  19575. case "JsonRoot":
  19576. return concat$4([path$$1.call(print, "node"), hardline$3]);
  19577. case "File":
  19578. // Print @babel/parser's InterpreterDirective here so that
  19579. // leading comments on the `Program` node get printed after the hashbang.
  19580. if (n.program && n.program.interpreter) {
  19581. parts.push(path$$1.call(function (programPath) {
  19582. return programPath.call(print, "interpreter");
  19583. }, "program"));
  19584. }
  19585. parts.push(path$$1.call(print, "program"));
  19586. return concat$4(parts);
  19587. case "Program":
  19588. // Babel 6
  19589. if (n.directives) {
  19590. path$$1.each(function (childPath) {
  19591. parts.push(print(childPath), semi, hardline$3);
  19592. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  19593. parts.push(hardline$3);
  19594. }
  19595. }, "directives");
  19596. }
  19597. parts.push(path$$1.call(function (bodyPath) {
  19598. return printStatementSequence(bodyPath, options, print);
  19599. }, "body"));
  19600. parts.push(comments.printDanglingComments(path$$1, options,
  19601. /* sameIndent */
  19602. true)); // Only force a trailing newline if there were any contents.
  19603. if (n.body.length || n.comments) {
  19604. parts.push(hardline$3);
  19605. }
  19606. return concat$4(parts);
  19607. // Babel extension.
  19608. case "EmptyStatement":
  19609. return "";
  19610. case "ExpressionStatement":
  19611. // Detect Flow-parsed directives
  19612. if (n.directive) {
  19613. return concat$4([nodeStr(n.expression, options, true), semi]);
  19614. }
  19615. if (options.parser === "__vue_event_binding") {
  19616. var parent = path$$1.getParentNode();
  19617. if (parent.type === "Program" && parent.body.length === 1 && parent.body[0] === n) {
  19618. return concat$4([path$$1.call(print, "expression"), isVueEventBindingExpression(n.expression) ? ";" : ""]);
  19619. }
  19620. } // Do not append semicolon after the only JSX element in a program
  19621. return concat$4([path$$1.call(print, "expression"), isTheOnlyJSXElementInMarkdown(options, path$$1) ? "" : semi]);
  19622. // Babel extension.
  19623. case "ParenthesizedExpression":
  19624. return concat$4(["(", path$$1.call(print, "expression"), ")"]);
  19625. case "AssignmentExpression":
  19626. return printAssignment(n.left, path$$1.call(print, "left"), concat$4([" ", n.operator]), n.right, path$$1.call(print, "right"), options);
  19627. case "BinaryExpression":
  19628. case "LogicalExpression":
  19629. case "NGPipeExpression":
  19630. {
  19631. var _parent = path$$1.getParentNode();
  19632. var parentParent = path$$1.getParentNode(1);
  19633. var isInsideParenthesis = n !== _parent.body && (_parent.type === "IfStatement" || _parent.type === "WhileStatement" || _parent.type === "DoWhileStatement");
  19634. var _parts = printBinaryishExpressions(path$$1, print, options,
  19635. /* isNested */
  19636. false, isInsideParenthesis); // if (
  19637. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  19638. // ) {
  19639. //
  19640. // looks super weird, we want to break the children if the parent breaks
  19641. //
  19642. // if (
  19643. // this.hasPlugin("dynamicImports") &&
  19644. // this.lookahead().type === tt.parenLeft
  19645. // ) {
  19646. if (isInsideParenthesis) {
  19647. return concat$4(_parts);
  19648. } // Break between the parens in unaries or in a member expression, i.e.
  19649. //
  19650. // (
  19651. // a &&
  19652. // b &&
  19653. // c
  19654. // ).call()
  19655. if (_parent.type === "UnaryExpression" || (_parent.type === "MemberExpression" || _parent.type === "OptionalMemberExpression") && !_parent.computed) {
  19656. return group$1(concat$4([indent$2(concat$4([softline$1, concat$4(_parts)])), softline$1]));
  19657. } // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  19658. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  19659. 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";
  19660. var shouldIndentIfInlining = _parent.type === "AssignmentExpression" || _parent.type === "VariableDeclarator" || _parent.type === "ClassProperty" || _parent.type === "TSAbstractClassProperty" || _parent.type === "ClassPrivateProperty" || _parent.type === "ObjectProperty" || _parent.type === "Property";
  19661. var samePrecedenceSubExpression = isBinaryish(n.left) && shouldFlatten$1(n.operator, n.left.operator);
  19662. if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
  19663. return group$1(concat$4(_parts));
  19664. }
  19665. if (_parts.length === 0) {
  19666. return "";
  19667. } // If the right part is a JSX node, we include it in a separate group to
  19668. // prevent it breaking the whole chain, so we can print the expression like:
  19669. //
  19670. // foo && bar && (
  19671. // <Foo>
  19672. // <Bar />
  19673. // </Foo>
  19674. // )
  19675. var hasJSX = isJSXNode(n.right);
  19676. var rest = concat$4(hasJSX ? _parts.slice(1, -1) : _parts.slice(1));
  19677. var groupId = Symbol("logicalChain-" + ++uid);
  19678. var chain = group$1(concat$4([// Don't include the initial expression in the indentation
  19679. // level. The first item is guaranteed to be the first
  19680. // left-most expression.
  19681. _parts.length > 0 ? _parts[0] : "", indent$2(rest)]), {
  19682. id: groupId
  19683. });
  19684. if (!hasJSX) {
  19685. return chain;
  19686. }
  19687. var jsxPart = getLast$4(_parts);
  19688. return group$1(concat$4([chain, ifBreak$1(indent$2(jsxPart), jsxPart, {
  19689. groupId
  19690. })]));
  19691. }
  19692. case "AssignmentPattern":
  19693. return concat$4([path$$1.call(print, "left"), " = ", path$$1.call(print, "right")]);
  19694. case "TSTypeAssertion":
  19695. {
  19696. var shouldBreakAfterCast = !(n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression");
  19697. var castGroup = group$1(concat$4(["<", indent$2(concat$4([softline$1, path$$1.call(print, "typeAnnotation")])), softline$1, ">"]));
  19698. var exprContents = concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, ifBreak$1(")")]);
  19699. if (shouldBreakAfterCast) {
  19700. return conditionalGroup$1([concat$4([castGroup, path$$1.call(print, "expression")]), concat$4([castGroup, group$1(exprContents, {
  19701. shouldBreak: true
  19702. })]), concat$4([castGroup, path$$1.call(print, "expression")])]);
  19703. }
  19704. return group$1(concat$4([castGroup, path$$1.call(print, "expression")]));
  19705. }
  19706. case "OptionalMemberExpression":
  19707. case "MemberExpression":
  19708. {
  19709. var _parent2 = path$$1.getParentNode();
  19710. var firstNonMemberParent;
  19711. var i = 0;
  19712. do {
  19713. firstNonMemberParent = path$$1.getParentNode(i);
  19714. i++;
  19715. } while (firstNonMemberParent && (firstNonMemberParent.type === "MemberExpression" || firstNonMemberParent.type === "OptionalMemberExpression" || firstNonMemberParent.type === "TSNonNullExpression"));
  19716. 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";
  19717. 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)])))]);
  19718. }
  19719. case "MetaProperty":
  19720. return concat$4([path$$1.call(print, "meta"), ".", path$$1.call(print, "property")]);
  19721. case "BindExpression":
  19722. if (n.object) {
  19723. parts.push(path$$1.call(print, "object"));
  19724. }
  19725. parts.push(group$1(indent$2(concat$4([softline$1, printBindExpressionCallee(path$$1, options, print)]))));
  19726. return concat$4(parts);
  19727. case "Identifier":
  19728. {
  19729. return concat$4([n.name, printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print)]);
  19730. }
  19731. case "SpreadElement":
  19732. case "SpreadElementPattern":
  19733. case "RestProperty":
  19734. case "SpreadProperty":
  19735. case "SpreadPropertyPattern":
  19736. case "RestElement":
  19737. case "ObjectTypeSpreadProperty":
  19738. return concat$4(["...", path$$1.call(print, "argument"), printTypeAnnotation(path$$1, options, print)]);
  19739. case "FunctionDeclaration":
  19740. case "FunctionExpression":
  19741. parts.push(printFunctionDeclaration(path$$1, print, options));
  19742. if (!n.body) {
  19743. parts.push(semi);
  19744. }
  19745. return concat$4(parts);
  19746. case "ArrowFunctionExpression":
  19747. {
  19748. if (n.async) {
  19749. parts.push("async ");
  19750. }
  19751. if (shouldPrintParamsWithoutParens(path$$1, options)) {
  19752. parts.push(path$$1.call(print, "params", 0));
  19753. } else {
  19754. parts.push(group$1(concat$4([printFunctionParams(path$$1, print, options,
  19755. /* expandLast */
  19756. args && (args.expandLastArg || args.expandFirstArg),
  19757. /* printTypeParams */
  19758. true), printReturnType(path$$1, print, options)])));
  19759. }
  19760. var dangling = comments.printDanglingComments(path$$1, options,
  19761. /* sameIndent */
  19762. true, function (comment) {
  19763. var nextCharacter = getNextNonSpaceNonCommentCharacterIndex$2(options.originalText, comment, options);
  19764. return options.originalText.substr(nextCharacter, 2) === "=>";
  19765. });
  19766. if (dangling) {
  19767. parts.push(" ", dangling);
  19768. }
  19769. parts.push(" =>");
  19770. var body = path$$1.call(function (bodyPath) {
  19771. return print(bodyPath, args);
  19772. }, "body"); // We want to always keep these types of nodes on the same line
  19773. // as the arrow.
  19774. 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")) {
  19775. return group$1(concat$4([concat$4(parts), " ", body]));
  19776. } // We handle sequence expressions as the body of arrows specially,
  19777. // so that the required parentheses end up on their own lines.
  19778. if (n.body.type === "SequenceExpression") {
  19779. return group$1(concat$4([concat$4(parts), group$1(concat$4([" (", indent$2(concat$4([softline$1, body])), softline$1, ")"]))]));
  19780. } // if the arrow function is expanded as last argument, we are adding a
  19781. // level of indentation and need to add a softline to align the closing )
  19782. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  19783. // we should align the expression's closing } with the line with the opening {.
  19784. var shouldAddSoftLine = (args && args.expandLastArg || path$$1.getParentNode().type === "JSXExpressionContainer") && !(n.comments && n.comments.length);
  19785. var printTrailingComma = args && args.expandLastArg && shouldPrintComma(options, "all"); // In order to avoid confusion between
  19786. // a => a ? a : a
  19787. // a <= a ? a : a
  19788. var shouldAddParens = n.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken$1(n.body,
  19789. /* forbidFunctionAndClass */
  19790. false);
  19791. 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]) : ""]))]));
  19792. }
  19793. case "MethodDefinition":
  19794. case "TSAbstractMethodDefinition":
  19795. if (n.decorators && n.decorators.length !== 0) {
  19796. parts.push(printDecorators(path$$1, options, print));
  19797. }
  19798. if (n.accessibility) {
  19799. parts.push(n.accessibility + " ");
  19800. }
  19801. if (n.static) {
  19802. parts.push("static ");
  19803. }
  19804. if (n.type === "TSAbstractMethodDefinition") {
  19805. parts.push("abstract ");
  19806. }
  19807. parts.push(printMethod(path$$1, options, print));
  19808. return concat$4(parts);
  19809. case "YieldExpression":
  19810. parts.push("yield");
  19811. if (n.delegate) {
  19812. parts.push("*");
  19813. }
  19814. if (n.argument) {
  19815. parts.push(" ", path$$1.call(print, "argument"));
  19816. }
  19817. return concat$4(parts);
  19818. case "AwaitExpression":
  19819. return concat$4(["await ", path$$1.call(print, "argument")]);
  19820. case "ImportSpecifier":
  19821. if (n.importKind) {
  19822. parts.push(path$$1.call(print, "importKind"), " ");
  19823. }
  19824. parts.push(path$$1.call(print, "imported"));
  19825. if (n.local && n.local.name !== n.imported.name) {
  19826. parts.push(" as ", path$$1.call(print, "local"));
  19827. }
  19828. return concat$4(parts);
  19829. case "ExportSpecifier":
  19830. parts.push(path$$1.call(print, "local"));
  19831. if (n.exported && n.exported.name !== n.local.name) {
  19832. parts.push(" as ", path$$1.call(print, "exported"));
  19833. }
  19834. return concat$4(parts);
  19835. case "ImportNamespaceSpecifier":
  19836. parts.push("* as ");
  19837. parts.push(path$$1.call(print, "local"));
  19838. return concat$4(parts);
  19839. case "ImportDefaultSpecifier":
  19840. return path$$1.call(print, "local");
  19841. case "TSExportAssignment":
  19842. return concat$4(["export = ", path$$1.call(print, "expression"), semi]);
  19843. case "ExportDefaultDeclaration":
  19844. case "ExportNamedDeclaration":
  19845. return printExportDeclaration(path$$1, options, print);
  19846. case "ExportAllDeclaration":
  19847. parts.push("export ");
  19848. if (n.exportKind === "type") {
  19849. parts.push("type ");
  19850. }
  19851. parts.push("* from ", path$$1.call(print, "source"), semi);
  19852. return concat$4(parts);
  19853. case "ExportNamespaceSpecifier":
  19854. case "ExportDefaultSpecifier":
  19855. return path$$1.call(print, "exported");
  19856. case "ImportDeclaration":
  19857. {
  19858. parts.push("import ");
  19859. if (n.importKind && n.importKind !== "value") {
  19860. parts.push(n.importKind + " ");
  19861. }
  19862. var standalones = [];
  19863. var grouped = [];
  19864. if (n.specifiers && n.specifiers.length > 0) {
  19865. path$$1.each(function (specifierPath) {
  19866. var value = specifierPath.getValue();
  19867. if (value.type === "ImportDefaultSpecifier" || value.type === "ImportNamespaceSpecifier") {
  19868. standalones.push(print(specifierPath));
  19869. } else {
  19870. grouped.push(print(specifierPath));
  19871. }
  19872. }, "specifiers");
  19873. if (standalones.length > 0) {
  19874. parts.push(join$2(", ", standalones));
  19875. }
  19876. if (standalones.length > 0 && grouped.length > 0) {
  19877. parts.push(", ");
  19878. }
  19879. if (grouped.length === 1 && standalones.length === 0 && n.specifiers && !n.specifiers.some(function (node) {
  19880. return node.comments;
  19881. })) {
  19882. parts.push(concat$4(["{", options.bracketSpacing ? " " : "", concat$4(grouped), options.bracketSpacing ? " " : "", "}"]));
  19883. } else if (grouped.length >= 1) {
  19884. 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, "}"])));
  19885. }
  19886. parts.push(" from ");
  19887. } else if (n.importKind && n.importKind === "type" || // import {} from 'x'
  19888. /{\s*}/.test(options.originalText.slice(options.locStart(n), options.locStart(n.source)))) {
  19889. parts.push("{} from ");
  19890. }
  19891. parts.push(path$$1.call(print, "source"), semi);
  19892. return concat$4(parts);
  19893. }
  19894. case "Import":
  19895. return "import";
  19896. case "TSModuleBlock":
  19897. case "BlockStatement":
  19898. {
  19899. var naked = path$$1.call(function (bodyPath) {
  19900. return printStatementSequence(bodyPath, options, print);
  19901. }, "body");
  19902. var hasContent = n.body.find(function (node) {
  19903. return node.type !== "EmptyStatement";
  19904. });
  19905. var hasDirectives = n.directives && n.directives.length > 0;
  19906. var _parent3 = path$$1.getParentNode();
  19907. var _parentParent = path$$1.getParentNode(1);
  19908. 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")) {
  19909. return "{}";
  19910. }
  19911. parts.push("{"); // Babel 6
  19912. if (hasDirectives) {
  19913. path$$1.each(function (childPath) {
  19914. parts.push(indent$2(concat$4([hardline$3, print(childPath), semi])));
  19915. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  19916. parts.push(hardline$3);
  19917. }
  19918. }, "directives");
  19919. }
  19920. if (hasContent) {
  19921. parts.push(indent$2(concat$4([hardline$3, naked])));
  19922. }
  19923. parts.push(comments.printDanglingComments(path$$1, options));
  19924. parts.push(hardline$3, "}");
  19925. return concat$4(parts);
  19926. }
  19927. case "ReturnStatement":
  19928. parts.push("return");
  19929. if (n.argument) {
  19930. if (returnArgumentHasLeadingComment(options, n.argument)) {
  19931. parts.push(concat$4([" (", indent$2(concat$4([hardline$3, path$$1.call(print, "argument")])), hardline$3, ")"]));
  19932. } else if (n.argument.type === "LogicalExpression" || n.argument.type === "BinaryExpression" || n.argument.type === "SequenceExpression") {
  19933. parts.push(group$1(concat$4([ifBreak$1(" (", " "), indent$2(concat$4([softline$1, path$$1.call(print, "argument")])), softline$1, ifBreak$1(")")])));
  19934. } else {
  19935. parts.push(" ", path$$1.call(print, "argument"));
  19936. }
  19937. }
  19938. if (hasDanglingComments(n)) {
  19939. parts.push(" ", comments.printDanglingComments(path$$1, options,
  19940. /* sameIndent */
  19941. true));
  19942. }
  19943. parts.push(semi);
  19944. return concat$4(parts);
  19945. case "NewExpression":
  19946. case "OptionalCallExpression":
  19947. case "CallExpression":
  19948. {
  19949. var isNew = n.type === "NewExpression";
  19950. var optional = printOptionalToken(path$$1);
  19951. if ( // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  19952. // define calls, as a unit.
  19953. // e.g. `define(["some/lib", (lib) => {`
  19954. !isNew && n.callee.type === "Identifier" && (n.callee.name === "require" || n.callee.name === "define") || n.callee.type === "Import" || // Template literals as single arguments
  19955. n.arguments.length === 1 && isTemplateOnItsOwnLine(n.arguments[0], options.originalText, options) || // Keep test declarations on a single line
  19956. // e.g. `it('long name', () => {`
  19957. !isNew && isTestCall(n, path$$1.getParentNode())) {
  19958. 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")), ")"])]);
  19959. } // Inline Flow annotation comments following Identifiers in Call nodes need to
  19960. // stay with the Identifier. For example:
  19961. //
  19962. // foo /*:: <SomeGeneric> */(bar);
  19963. //
  19964. // Here, we ensure that such comments stay between the Identifier and the Callee.
  19965. var isIdentifierWithFlowAnnotation = n.callee.type === "Identifier" && hasFlowAnnotationComment(n.callee.trailingComments);
  19966. if (isIdentifierWithFlowAnnotation) {
  19967. n.callee.trailingComments[0].printed = true;
  19968. } // We detect calls on member lookups and possibly print them in a
  19969. // special chain format. See `printMemberChain` for more info.
  19970. if (!isNew && isMemberish(n.callee)) {
  19971. return printMemberChain(path$$1, options, print);
  19972. }
  19973. 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)]);
  19974. }
  19975. case "TSInterfaceDeclaration":
  19976. if (isNodeStartingWithDeclare(n, options)) {
  19977. parts.push("declare ");
  19978. }
  19979. parts.push(n.abstract ? "abstract " : "", printTypeScriptModifiers(path$$1, options, print), "interface ", path$$1.call(print, "id"), n.typeParameters ? path$$1.call(print, "typeParameters") : "", " ");
  19980. if (n.extends && n.extends.length) {
  19981. 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"))), " "]))));
  19982. }
  19983. parts.push(path$$1.call(print, "body"));
  19984. return concat$4(parts);
  19985. case "ObjectTypeInternalSlot":
  19986. return concat$4([n.static ? "static " : "", "[[", path$$1.call(print, "id"), "]]", printOptionalToken(path$$1), n.method ? "" : ": ", path$$1.call(print, "value")]);
  19987. case "ObjectExpression":
  19988. case "ObjectPattern":
  19989. case "ObjectTypeAnnotation":
  19990. case "TSInterfaceBody":
  19991. case "TSTypeLiteral":
  19992. {
  19993. var propertiesField;
  19994. if (n.type === "TSTypeLiteral") {
  19995. propertiesField = "members";
  19996. } else if (n.type === "TSInterfaceBody") {
  19997. propertiesField = "body";
  19998. } else {
  19999. propertiesField = "properties";
  20000. }
  20001. var isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  20002. var fields = [];
  20003. if (isTypeAnnotation) {
  20004. fields.push("indexers", "callProperties", "internalSlots");
  20005. }
  20006. fields.push(propertiesField);
  20007. var firstProperty = fields.map(function (field) {
  20008. return n[field][0];
  20009. }).sort(function (a, b) {
  20010. return options.locStart(a) - options.locStart(b);
  20011. })[0];
  20012. var _parent4 = path$$1.getParentNode(0);
  20013. var isFlowInterfaceLikeBody = isTypeAnnotation && _parent4 && (_parent4.type === "InterfaceDeclaration" || _parent4.type === "DeclareInterface" || _parent4.type === "DeclareClass") && path$$1.getName() === "body";
  20014. 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) {
  20015. return property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern");
  20016. }) || n.type !== "ObjectPattern" && firstProperty && hasNewlineInRange$1(options.originalText, options.locStart(n), options.locStart(firstProperty));
  20017. var separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" ? ifBreak$1(semi, ";") : ",";
  20018. var leftBrace = n.exact ? "{|" : "{";
  20019. var rightBrace = n.exact ? "|}" : "}"; // Unfortunately, things are grouped together in the ast can be
  20020. // interleaved in the source code. So we need to reorder them before
  20021. // printing them.
  20022. var propsAndLoc = [];
  20023. fields.forEach(function (field) {
  20024. path$$1.each(function (childPath) {
  20025. var node = childPath.getValue();
  20026. propsAndLoc.push({
  20027. node: node,
  20028. printed: print(childPath),
  20029. loc: options.locStart(node)
  20030. });
  20031. }, field);
  20032. });
  20033. var separatorParts = [];
  20034. var props = propsAndLoc.sort(function (a, b) {
  20035. return a.loc - b.loc;
  20036. }).map(function (prop) {
  20037. var result = concat$4(separatorParts.concat(group$1(prop.printed)));
  20038. separatorParts = [separator, line$3];
  20039. if ((prop.node.type === "TSPropertySignature" || prop.node.type === "TSMethodSignature" || prop.node.type === "TSConstructSignatureDeclaration") && hasNodeIgnoreComment$1(prop.node)) {
  20040. separatorParts.shift();
  20041. }
  20042. if (isNextLineEmpty$2(options.originalText, prop.node, options)) {
  20043. separatorParts.push(hardline$3);
  20044. }
  20045. return result;
  20046. });
  20047. if (n.inexact) {
  20048. props.push(concat$4(separatorParts.concat(group$1("..."))));
  20049. }
  20050. var lastElem = getLast$4(n[propertiesField]);
  20051. var canHaveTrailingSeparator = !(lastElem && (lastElem.type === "RestProperty" || lastElem.type === "RestElement" || hasNodeIgnoreComment$1(lastElem) || n.inexact));
  20052. var content;
  20053. if (props.length === 0 && !n.typeAnnotation) {
  20054. if (!hasDanglingComments(n)) {
  20055. return concat$4([leftBrace, rightBrace]);
  20056. }
  20057. content = group$1(concat$4([leftBrace, comments.printDanglingComments(path$$1, options), softline$1, rightBrace, printOptionalToken(path$$1)]));
  20058. } else {
  20059. 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)]);
  20060. } // If we inline the object as first argument of the parent, we don't want
  20061. // to create another group so that the object breaks before the return
  20062. // type
  20063. var parentParentParent = path$$1.getParentNode(2);
  20064. 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) {
  20065. return content;
  20066. }
  20067. return group$1(content, {
  20068. shouldBreak
  20069. });
  20070. }
  20071. // Babel 6
  20072. case "ObjectProperty": // Non-standard AST node type.
  20073. case "Property":
  20074. if (n.method || n.kind === "get" || n.kind === "set") {
  20075. return printMethod(path$$1, options, print);
  20076. }
  20077. if (n.shorthand) {
  20078. parts.push(path$$1.call(print, "value"));
  20079. } else {
  20080. var printedLeft;
  20081. if (n.computed) {
  20082. printedLeft = concat$4(["[", path$$1.call(print, "key"), "]"]);
  20083. } else {
  20084. printedLeft = printPropertyKey(path$$1, options, print);
  20085. }
  20086. parts.push(printAssignment(n.key, printedLeft, ":", n.value, path$$1.call(print, "value"), options));
  20087. }
  20088. return concat$4(parts);
  20089. // Babel 6
  20090. case "ClassMethod":
  20091. case "ClassPrivateMethod":
  20092. if (n.decorators && n.decorators.length !== 0) {
  20093. parts.push(printDecorators(path$$1, options, print));
  20094. }
  20095. if (n.static) {
  20096. parts.push("static ");
  20097. }
  20098. parts = parts.concat(printObjectMethod(path$$1, options, print));
  20099. return concat$4(parts);
  20100. // Babel 6
  20101. case "ObjectMethod":
  20102. return printObjectMethod(path$$1, options, print);
  20103. case "Decorator":
  20104. return concat$4(["@", path$$1.call(print, "expression"), path$$1.call(print, "callee")]);
  20105. case "ArrayExpression":
  20106. case "ArrayPattern":
  20107. if (n.elements.length === 0) {
  20108. if (!hasDanglingComments(n)) {
  20109. parts.push("[]");
  20110. } else {
  20111. parts.push(group$1(concat$4(["[", comments.printDanglingComments(path$$1, options), softline$1, "]"])));
  20112. }
  20113. } else {
  20114. var _lastElem = getLast$4(n.elements);
  20115. var canHaveTrailingComma = !(_lastElem && _lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which
  20116. // changes its length based on the number of commas. The algorithm
  20117. // is that if the last argument is null, we need to force insert
  20118. // a comma to ensure JavaScript recognizes it.
  20119. // [,].length === 1
  20120. // [1,].length === 1
  20121. // [1,,].length === 2
  20122. //
  20123. // Note that getLast returns null if the array is empty, but
  20124. // we already check for an empty array just above so we are safe
  20125. var needsForcedTrailingComma = canHaveTrailingComma && _lastElem === null;
  20126. 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,
  20127. /* sameIndent */
  20128. true), softline$1, "]"])));
  20129. }
  20130. parts.push(printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print));
  20131. return concat$4(parts);
  20132. case "SequenceExpression":
  20133. {
  20134. var _parent5 = path$$1.getParentNode(0);
  20135. if (_parent5.type === "ExpressionStatement" || _parent5.type === "ForStatement") {
  20136. // For ExpressionStatements and for-loop heads, which are among
  20137. // the few places a SequenceExpression appears unparenthesized, we want
  20138. // to indent expressions after the first.
  20139. var _parts2 = [];
  20140. path$$1.each(function (p) {
  20141. if (p.getName() === 0) {
  20142. _parts2.push(print(p));
  20143. } else {
  20144. _parts2.push(",", indent$2(concat$4([line$3, print(p)])));
  20145. }
  20146. }, "expressions");
  20147. return group$1(concat$4(_parts2));
  20148. }
  20149. return group$1(concat$4([join$2(concat$4([",", line$3]), path$$1.map(print, "expressions"))]));
  20150. }
  20151. case "ThisExpression":
  20152. return "this";
  20153. case "Super":
  20154. return "super";
  20155. case "NullLiteral":
  20156. // Babel 6 Literal split
  20157. return "null";
  20158. case "RegExpLiteral":
  20159. // Babel 6 Literal split
  20160. return printRegex(n);
  20161. case "NumericLiteral":
  20162. // Babel 6 Literal split
  20163. return printNumber$1(n.extra.raw);
  20164. case "BigIntLiteral":
  20165. return concat$4([printNumber$1(n.extra ? n.extra.rawValue : // TypeScript
  20166. n.value), "n"]);
  20167. case "BooleanLiteral": // Babel 6 Literal split
  20168. case "StringLiteral": // Babel 6 Literal split
  20169. case "Literal":
  20170. {
  20171. if (n.regex) {
  20172. return printRegex(n.regex);
  20173. }
  20174. if (typeof n.value === "number") {
  20175. return printNumber$1(n.raw);
  20176. }
  20177. if (typeof n.value !== "string") {
  20178. return "" + n.value;
  20179. } // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  20180. // See corresponding workaround in needs-parens.js
  20181. var grandParent = path$$1.getParentNode(1);
  20182. var isTypeScriptDirective = options.parser === "typescript" && typeof n.value === "string" && grandParent && (grandParent.type === "Program" || grandParent.type === "BlockStatement");
  20183. return nodeStr(n, options, isTypeScriptDirective);
  20184. }
  20185. case "Directive":
  20186. return path$$1.call(print, "value");
  20187. // Babel 6
  20188. case "DirectiveLiteral":
  20189. return nodeStr(n, options);
  20190. case "UnaryExpression":
  20191. parts.push(n.operator);
  20192. if (/[a-z]$/.test(n.operator)) {
  20193. parts.push(" ");
  20194. }
  20195. parts.push(path$$1.call(print, "argument"));
  20196. return concat$4(parts);
  20197. case "UpdateExpression":
  20198. parts.push(path$$1.call(print, "argument"), n.operator);
  20199. if (n.prefix) {
  20200. parts.reverse();
  20201. }
  20202. return concat$4(parts);
  20203. case "ConditionalExpression":
  20204. return printTernaryOperator(path$$1, options, print, {
  20205. beforeParts: function beforeParts() {
  20206. return [path$$1.call(print, "test")];
  20207. },
  20208. afterParts: function afterParts(breakClosingParen) {
  20209. return [breakClosingParen ? softline$1 : ""];
  20210. },
  20211. shouldCheckJsx: true,
  20212. conditionalNodeType: "ConditionalExpression",
  20213. consequentNodePropertyName: "consequent",
  20214. alternateNodePropertyName: "alternate",
  20215. testNodePropertyName: "test",
  20216. breakNested: true
  20217. });
  20218. case "VariableDeclaration":
  20219. {
  20220. var printed = path$$1.map(function (childPath) {
  20221. return print(childPath);
  20222. }, "declarations"); // We generally want to terminate all variable declarations with a
  20223. // semicolon, except when they in the () part of for loops.
  20224. var parentNode = path$$1.getParentNode();
  20225. var isParentForLoop = parentNode.type === "ForStatement" || parentNode.type === "ForInStatement" || parentNode.type === "ForOfStatement" || parentNode.type === "ForAwaitStatement";
  20226. var hasValue = n.declarations.some(function (decl) {
  20227. return decl.init;
  20228. });
  20229. var firstVariable;
  20230. if (printed.length === 1 && !n.declarations[0].comments) {
  20231. firstVariable = printed[0];
  20232. } else if (printed.length > 0) {
  20233. // Indent first var to comply with eslint one-var rule
  20234. firstVariable = indent$2(printed[0]);
  20235. }
  20236. parts = [isNodeStartingWithDeclare(n, options) ? "declare " : "", n.kind, firstVariable ? concat$4([" ", firstVariable]) : "", indent$2(concat$4(printed.slice(1).map(function (p) {
  20237. return concat$4([",", hasValue && !isParentForLoop ? hardline$3 : line$3, p]);
  20238. })))];
  20239. if (!(isParentForLoop && parentNode.body !== n)) {
  20240. parts.push(semi);
  20241. }
  20242. return group$1(concat$4(parts));
  20243. }
  20244. case "TSTypeAliasDeclaration":
  20245. {
  20246. if (n.declare) {
  20247. parts.push("declare ");
  20248. }
  20249. var _printed = printAssignmentRight(n.id, n.typeAnnotation, n.typeAnnotation && path$$1.call(print, "typeAnnotation"), options);
  20250. parts.push("type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"), " =", _printed, semi);
  20251. return group$1(concat$4(parts));
  20252. }
  20253. case "VariableDeclarator":
  20254. return printAssignment(n.id, path$$1.call(print, "id"), " =", n.init, n.init && path$$1.call(print, "init"), options);
  20255. case "WithStatement":
  20256. return group$1(concat$4(["with (", path$$1.call(print, "object"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  20257. case "IfStatement":
  20258. {
  20259. var con = adjustClause(n.consequent, path$$1.call(print, "consequent"));
  20260. 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]));
  20261. parts.push(opening);
  20262. if (n.alternate) {
  20263. var commentOnOwnLine = hasTrailingComment(n.consequent) && n.consequent.comments.some(function (comment) {
  20264. return comment.trailing && !comments$3.isBlockComment(comment);
  20265. }) || needsHardlineAfterDanglingComment(n);
  20266. var elseOnSameLine = n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  20267. parts.push(elseOnSameLine ? " " : hardline$3);
  20268. if (hasDanglingComments(n)) {
  20269. parts.push(comments.printDanglingComments(path$$1, options, true), commentOnOwnLine ? hardline$3 : " ");
  20270. }
  20271. parts.push("else", group$1(adjustClause(n.alternate, path$$1.call(print, "alternate"), n.alternate.type === "IfStatement")));
  20272. }
  20273. return concat$4(parts);
  20274. }
  20275. case "ForStatement":
  20276. {
  20277. var _body = adjustClause(n.body, path$$1.call(print, "body")); // We want to keep dangling comments above the loop to stay consistent.
  20278. // Any comment positioned between the for statement and the parentheses
  20279. // is going to be printed before the statement.
  20280. var _dangling = comments.printDanglingComments(path$$1, options,
  20281. /* sameLine */
  20282. true);
  20283. var printedComments = _dangling ? concat$4([_dangling, softline$1]) : "";
  20284. if (!n.init && !n.test && !n.update) {
  20285. return concat$4([printedComments, group$1(concat$4(["for (;;)", _body]))]);
  20286. }
  20287. 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]))]);
  20288. }
  20289. case "WhileStatement":
  20290. 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"))]));
  20291. case "ForInStatement":
  20292. // Note: esprima can't actually parse "for each (".
  20293. 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"))]));
  20294. case "ForOfStatement":
  20295. case "ForAwaitStatement":
  20296. {
  20297. // Babel 7 removed ForAwaitStatement in favor of ForOfStatement
  20298. // with `"await": true`:
  20299. // https://github.com/estree/estree/pull/138
  20300. var isAwait = n.type === "ForAwaitStatement" || n.await;
  20301. 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"))]));
  20302. }
  20303. case "DoWhileStatement":
  20304. {
  20305. var clause = adjustClause(n.body, path$$1.call(print, "body"));
  20306. var doBody = group$1(concat$4(["do", clause]));
  20307. parts = [doBody];
  20308. if (n.body.type === "BlockStatement") {
  20309. parts.push(" ");
  20310. } else {
  20311. parts.push(hardline$3);
  20312. }
  20313. parts.push("while (");
  20314. parts.push(group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", semi);
  20315. return concat$4(parts);
  20316. }
  20317. case "DoExpression":
  20318. return concat$4(["do ", path$$1.call(print, "body")]);
  20319. case "BreakStatement":
  20320. parts.push("break");
  20321. if (n.label) {
  20322. parts.push(" ", path$$1.call(print, "label"));
  20323. }
  20324. parts.push(semi);
  20325. return concat$4(parts);
  20326. case "ContinueStatement":
  20327. parts.push("continue");
  20328. if (n.label) {
  20329. parts.push(" ", path$$1.call(print, "label"));
  20330. }
  20331. parts.push(semi);
  20332. return concat$4(parts);
  20333. case "LabeledStatement":
  20334. if (n.body.type === "EmptyStatement") {
  20335. return concat$4([path$$1.call(print, "label"), ":;"]);
  20336. }
  20337. return concat$4([path$$1.call(print, "label"), ": ", path$$1.call(print, "body")]);
  20338. case "TryStatement":
  20339. 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")]) : ""]);
  20340. case "CatchClause":
  20341. if (n.param) {
  20342. var hasComments = n.param.comments && n.param.comments.some(function (comment) {
  20343. return !comments$3.isBlockComment(comment) || comment.leading && hasNewline$2(options.originalText, options.locEnd(comment)) || comment.trailing && hasNewline$2(options.originalText, options.locStart(comment), {
  20344. backwards: true
  20345. });
  20346. });
  20347. var param = path$$1.call(print, "param");
  20348. return concat$4(["catch ", hasComments ? concat$4(["(", indent$2(concat$4([softline$1, param])), softline$1, ") "]) : concat$4(["(", param, ") "]), path$$1.call(print, "body")]);
  20349. }
  20350. return concat$4(["catch ", path$$1.call(print, "body")]);
  20351. case "ThrowStatement":
  20352. return concat$4(["throw ", path$$1.call(print, "argument"), semi]);
  20353. // Note: ignoring n.lexical because it has no printing consequences.
  20354. case "SwitchStatement":
  20355. 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) {
  20356. var caseNode = casePath.getValue();
  20357. return concat$4([casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && isNextLineEmpty$2(options.originalText, caseNode, options) ? hardline$3 : ""]);
  20358. }, "cases"))])) : "", hardline$3, "}"]);
  20359. case "SwitchCase":
  20360. {
  20361. if (n.test) {
  20362. parts.push("case ", path$$1.call(print, "test"), ":");
  20363. } else {
  20364. parts.push("default:");
  20365. }
  20366. var consequent = n.consequent.filter(function (node) {
  20367. return node.type !== "EmptyStatement";
  20368. });
  20369. if (consequent.length > 0) {
  20370. var cons = path$$1.call(function (consequentPath) {
  20371. return printStatementSequence(consequentPath, options, print);
  20372. }, "consequent");
  20373. parts.push(consequent.length === 1 && consequent[0].type === "BlockStatement" ? concat$4([" ", cons]) : indent$2(concat$4([hardline$3, cons])));
  20374. }
  20375. return concat$4(parts);
  20376. }
  20377. // JSX extensions below.
  20378. case "DebuggerStatement":
  20379. return concat$4(["debugger", semi]);
  20380. case "JSXAttribute":
  20381. parts.push(path$$1.call(print, "name"));
  20382. if (n.value) {
  20383. var res;
  20384. if (isStringLiteral(n.value)) {
  20385. var raw = rawText(n.value); // Unescape all quotes so we get an accurate preferred quote
  20386. var final = raw.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  20387. var quote = getPreferredQuote$1(final, options.jsxSingleQuote ? "'" : '"');
  20388. var _escape = quote === "'" ? "&apos;" : "&quot;";
  20389. final = final.slice(1, -1).replace(new RegExp(quote, "g"), _escape);
  20390. res = concat$4([quote, final, quote]);
  20391. } else {
  20392. res = path$$1.call(print, "value");
  20393. }
  20394. parts.push("=", res);
  20395. }
  20396. return concat$4(parts);
  20397. case "JSXIdentifier":
  20398. return "" + n.name;
  20399. case "JSXNamespacedName":
  20400. return join$2(":", [path$$1.call(print, "namespace"), path$$1.call(print, "name")]);
  20401. case "JSXMemberExpression":
  20402. return join$2(".", [path$$1.call(print, "object"), path$$1.call(print, "property")]);
  20403. case "TSQualifiedName":
  20404. return join$2(".", [path$$1.call(print, "left"), path$$1.call(print, "right")]);
  20405. case "JSXSpreadAttribute":
  20406. case "JSXSpreadChild":
  20407. {
  20408. return concat$4(["{", path$$1.call(function (p) {
  20409. var printed = concat$4(["...", print(p)]);
  20410. var n = p.getValue();
  20411. if (!n.comments || !n.comments.length) {
  20412. return printed;
  20413. }
  20414. return concat$4([indent$2(concat$4([softline$1, comments.printComments(p, function () {
  20415. return printed;
  20416. }, options)])), softline$1]);
  20417. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), "}"]);
  20418. }
  20419. case "JSXExpressionContainer":
  20420. {
  20421. var _parent6 = path$$1.getParentNode(0);
  20422. var preventInline = _parent6.type === "JSXAttribute" && n.expression.comments && n.expression.comments.length > 0;
  20423. 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)));
  20424. if (_shouldInline) {
  20425. return group$1(concat$4(["{", path$$1.call(print, "expression"), lineSuffixBoundary$1, "}"]));
  20426. }
  20427. return group$1(concat$4(["{", indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, lineSuffixBoundary$1, "}"]));
  20428. }
  20429. case "JSXFragment":
  20430. case "JSXElement":
  20431. {
  20432. var elem = comments.printComments(path$$1, function () {
  20433. return printJSXElement(path$$1, options, print);
  20434. }, options);
  20435. return maybeWrapJSXElementInParens(path$$1, elem);
  20436. }
  20437. case "JSXOpeningElement":
  20438. {
  20439. var _n = path$$1.getValue();
  20440. var nameHasComments = _n.name && _n.name.comments && _n.name.comments.length > 0; // Don't break self-closing elements with no attributes and no comments
  20441. if (_n.selfClosing && !_n.attributes.length && !nameHasComments) {
  20442. return concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " />"]);
  20443. } // don't break up opening elements with a single long text attribute
  20444. 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:
  20445. // <div
  20446. // // comment
  20447. // attr="value"
  20448. // >
  20449. // <div
  20450. // attr="value"
  20451. // // comment
  20452. // >
  20453. !nameHasComments && (!_n.attributes[0].comments || !_n.attributes[0].comments.length)) {
  20454. return group$1(concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " ", concat$4(path$$1.map(print, "attributes")), _n.selfClosing ? " />" : ">"]));
  20455. }
  20456. var lastAttrHasTrailingComments = _n.attributes.length && hasTrailingComment(getLast$4(_n.attributes));
  20457. var bracketSameLine = // Simple tags (no attributes and no comment in tag name) should be
  20458. // kept unbroken regardless of `jsxBracketSameLine`
  20459. !_n.attributes.length && !nameHasComments || options.jsxBracketSameLine && ( // We should print the bracket in a new line for the following cases:
  20460. // <div
  20461. // // comment
  20462. // >
  20463. // <div
  20464. // attr // comment
  20465. // >
  20466. !nameHasComments || _n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
  20467. // string literal with newlines
  20468. var _shouldBreak = _n.attributes && _n.attributes.some(function (attr) {
  20469. return attr.value && isStringLiteral(attr.value) && attr.value.value.includes("\n");
  20470. });
  20471. 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) {
  20472. return concat$4([line$3, print(attr)]);
  20473. }, "attributes"))), _n.selfClosing ? line$3 : bracketSameLine ? ">" : softline$1]), _n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
  20474. shouldBreak: _shouldBreak
  20475. });
  20476. }
  20477. case "JSXClosingElement":
  20478. return concat$4(["</", path$$1.call(print, "name"), ">"]);
  20479. case "JSXOpeningFragment":
  20480. case "JSXClosingFragment":
  20481. {
  20482. var hasComment = n.comments && n.comments.length;
  20483. var hasOwnLineComment = hasComment && !n.comments.every(comments$3.isBlockComment);
  20484. var isOpeningFragment = n.type === "JSXOpeningFragment";
  20485. return concat$4([isOpeningFragment ? "<" : "</", indent$2(concat$4([hasOwnLineComment ? hardline$3 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path$$1, options, true)])), hasOwnLineComment ? hardline$3 : "", ">"]);
  20486. }
  20487. case "JSXText":
  20488. /* istanbul ignore next */
  20489. throw new Error("JSXTest should be handled by JSXElement");
  20490. case "JSXEmptyExpression":
  20491. {
  20492. var requiresHardline = n.comments && !n.comments.every(comments$3.isBlockComment);
  20493. return concat$4([comments.printDanglingComments(path$$1, options,
  20494. /* sameIndent */
  20495. !requiresHardline), requiresHardline ? hardline$3 : ""]);
  20496. }
  20497. case "ClassBody":
  20498. if (!n.comments && n.body.length === 0) {
  20499. return "{}";
  20500. }
  20501. return concat$4(["{", n.body.length > 0 ? indent$2(concat$4([hardline$3, path$$1.call(function (bodyPath) {
  20502. return printStatementSequence(bodyPath, options, print);
  20503. }, "body")])) : comments.printDanglingComments(path$$1, options), hardline$3, "}"]);
  20504. case "ClassProperty":
  20505. case "TSAbstractClassProperty":
  20506. case "ClassPrivateProperty":
  20507. {
  20508. if (n.decorators && n.decorators.length !== 0) {
  20509. parts.push(printDecorators(path$$1, options, print));
  20510. }
  20511. if (n.accessibility) {
  20512. parts.push(n.accessibility + " ");
  20513. }
  20514. if (n.static) {
  20515. parts.push("static ");
  20516. }
  20517. if (n.type === "TSAbstractClassProperty") {
  20518. parts.push("abstract ");
  20519. }
  20520. if (n.readonly) {
  20521. parts.push("readonly ");
  20522. }
  20523. var variance = getFlowVariance(n);
  20524. if (variance) {
  20525. parts.push(variance);
  20526. }
  20527. if (n.computed) {
  20528. parts.push("[", path$$1.call(print, "key"), "]");
  20529. } else {
  20530. parts.push(printPropertyKey(path$$1, options, print));
  20531. }
  20532. parts.push(printOptionalToken(path$$1));
  20533. parts.push(printTypeAnnotation(path$$1, options, print));
  20534. if (n.value) {
  20535. parts.push(" =", printAssignmentRight(n.key, n.value, path$$1.call(print, "value"), options));
  20536. }
  20537. parts.push(semi);
  20538. return group$1(concat$4(parts));
  20539. }
  20540. case "ClassDeclaration":
  20541. case "ClassExpression":
  20542. case "TSAbstractClassDeclaration":
  20543. if (isNodeStartingWithDeclare(n, options)) {
  20544. parts.push("declare ");
  20545. }
  20546. parts.push(concat$4(printClass(path$$1, options, print)));
  20547. return concat$4(parts);
  20548. case "TSInterfaceHeritage":
  20549. parts.push(path$$1.call(print, "expression"));
  20550. if (n.typeParameters) {
  20551. parts.push(path$$1.call(print, "typeParameters"));
  20552. }
  20553. return concat$4(parts);
  20554. case "TemplateElement":
  20555. return join$2(literalline$1, n.value.raw.split(/\r?\n/g));
  20556. case "TemplateLiteral":
  20557. {
  20558. var expressions = path$$1.map(print, "expressions");
  20559. var _parentNode = path$$1.getParentNode();
  20560. /**
  20561. * describe.each`table`(name, fn)
  20562. * describe.only.each`table`(name, fn)
  20563. * describe.skip.each`table`(name, fn)
  20564. * test.each`table`(name, fn)
  20565. * test.only.each`table`(name, fn)
  20566. * test.skip.each`table`(name, fn)
  20567. *
  20568. * Ref: https://github.com/facebook/jest/pull/6102
  20569. */
  20570. var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
  20571. if (_parentNode.type === "TaggedTemplateExpression" && _parentNode.quasi === n && _parentNode.tag.type === "MemberExpression" && _parentNode.tag.property.type === "Identifier" && _parentNode.tag.property.name === "each" && (_parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.name) || _parentNode.tag.object.type === "MemberExpression" && _parentNode.tag.object.property.type === "Identifier" && (_parentNode.tag.object.property.name === "only" || _parentNode.tag.object.property.name === "skip") && _parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.object.name))) {
  20572. /**
  20573. * a | b | expected
  20574. * ${1} | ${1} | ${2}
  20575. * ${1} | ${2} | ${3}
  20576. * ${2} | ${1} | ${3}
  20577. */
  20578. var headerNames = n.quasis[0].value.raw.trim().split(/\s*\|\s*/);
  20579. if (headerNames.length > 1 || headerNames.some(function (headerName) {
  20580. return headerName.length !== 0;
  20581. })) {
  20582. var stringifiedExpressions = expressions.map(function (doc$$2) {
  20583. return "${" + printDocToString$2(doc$$2, Object.assign({}, options, {
  20584. printWidth: Infinity,
  20585. endOfLine: "lf"
  20586. })).formatted + "}";
  20587. });
  20588. var tableBody = [{
  20589. hasLineBreak: false,
  20590. cells: []
  20591. }];
  20592. for (var _i = 1; _i < n.quasis.length; _i++) {
  20593. var row = tableBody[tableBody.length - 1];
  20594. var correspondingExpression = stringifiedExpressions[_i - 1];
  20595. row.cells.push(correspondingExpression);
  20596. if (correspondingExpression.indexOf("\n") !== -1) {
  20597. row.hasLineBreak = true;
  20598. }
  20599. if (n.quasis[_i].value.raw.indexOf("\n") !== -1) {
  20600. tableBody.push({
  20601. hasLineBreak: false,
  20602. cells: []
  20603. });
  20604. }
  20605. }
  20606. var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
  20607. return Math.max(maxColumnCount, row.cells.length);
  20608. }, headerNames.length);
  20609. var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
  20610. return 0;
  20611. });
  20612. var table = [{
  20613. cells: headerNames
  20614. }].concat(tableBody.filter(function (row) {
  20615. return row.cells.length !== 0;
  20616. }));
  20617. table.filter(function (row) {
  20618. return !row.hasLineBreak;
  20619. }).forEach(function (row) {
  20620. row.cells.forEach(function (cell, index) {
  20621. maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$2(cell));
  20622. });
  20623. });
  20624. parts.push("`", indent$2(concat$4([hardline$3, join$2(hardline$3, table.map(function (row) {
  20625. return join$2(" | ", row.cells.map(function (cell, index) {
  20626. return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$2(cell));
  20627. }));
  20628. }))])), hardline$3, "`");
  20629. return concat$4(parts);
  20630. }
  20631. }
  20632. parts.push("`");
  20633. path$$1.each(function (childPath) {
  20634. var i = childPath.getName();
  20635. parts.push(print(childPath));
  20636. if (i < expressions.length) {
  20637. // For a template literal of the following form:
  20638. // `someQuery {
  20639. // ${call({
  20640. // a,
  20641. // b,
  20642. // })}
  20643. // }`
  20644. // the expression is on its own line (there is a \n in the previous
  20645. // quasi literal), therefore we want to indent the JavaScript
  20646. // expression inside at the beginning of ${ instead of the beginning
  20647. // of the `.
  20648. var tabWidth = options.tabWidth;
  20649. var quasi = childPath.getValue();
  20650. var indentSize = getIndentSize$1(quasi.value.raw, tabWidth);
  20651. var _printed2 = expressions[i];
  20652. 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") {
  20653. _printed2 = concat$4([indent$2(concat$4([softline$1, _printed2])), softline$1]);
  20654. }
  20655. var aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$1(-Infinity, _printed2) : addAlignmentToDoc$2(_printed2, indentSize, tabWidth);
  20656. parts.push(group$1(concat$4(["${", aligned, lineSuffixBoundary$1, "}"])));
  20657. }
  20658. }, "quasis");
  20659. parts.push("`");
  20660. return concat$4(parts);
  20661. }
  20662. // These types are unprintable because they serve as abstract
  20663. // supertypes for other (printable) types.
  20664. case "TaggedTemplateExpression":
  20665. return concat$4([path$$1.call(print, "tag"), path$$1.call(print, "typeParameters"), path$$1.call(print, "quasi")]);
  20666. case "Node":
  20667. case "Printable":
  20668. case "SourceLocation":
  20669. case "Position":
  20670. case "Statement":
  20671. case "Function":
  20672. case "Pattern":
  20673. case "Expression":
  20674. case "Declaration":
  20675. case "Specifier":
  20676. case "NamedSpecifier":
  20677. case "Comment":
  20678. case "MemberTypeAnnotation": // Flow
  20679. case "Type":
  20680. /* istanbul ignore next */
  20681. throw new Error("unprintable type: " + JSON.stringify(n.type));
  20682. // Type Annotations for Facebook Flow, typically stripped out or
  20683. // transformed away before printing.
  20684. case "TypeAnnotation":
  20685. case "TSTypeAnnotation":
  20686. if (n.typeAnnotation) {
  20687. return path$$1.call(print, "typeAnnotation");
  20688. }
  20689. /* istanbul ignore next */
  20690. return "";
  20691. case "TSTupleType":
  20692. case "TupleTypeAnnotation":
  20693. {
  20694. var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  20695. return group$1(concat$4(["[", indent$2(concat$4([softline$1, printArrayItems(path$$1, options, typesField, print)])), // TypeScript doesn't support trailing commas in tuple types
  20696. n.type === "TSTupleType" ? "" : ifBreak$1(shouldPrintComma(options) ? "," : ""), comments.printDanglingComments(path$$1, options,
  20697. /* sameIndent */
  20698. true), softline$1, "]"]));
  20699. }
  20700. case "ExistsTypeAnnotation":
  20701. return "*";
  20702. case "EmptyTypeAnnotation":
  20703. return "empty";
  20704. case "AnyTypeAnnotation":
  20705. return "any";
  20706. case "MixedTypeAnnotation":
  20707. return "mixed";
  20708. case "ArrayTypeAnnotation":
  20709. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  20710. case "BooleanTypeAnnotation":
  20711. return "boolean";
  20712. case "BooleanLiteralTypeAnnotation":
  20713. return "" + n.value;
  20714. case "DeclareClass":
  20715. return printFlowDeclaration(path$$1, printClass(path$$1, options, print));
  20716. case "TSDeclareFunction":
  20717. // For TypeScript the TSDeclareFunction node shares the AST
  20718. // structure with FunctionDeclaration
  20719. return concat$4([n.declare ? "declare " : "", printFunctionDeclaration(path$$1, print, options), semi]);
  20720. case "DeclareFunction":
  20721. return printFlowDeclaration(path$$1, ["function ", path$$1.call(print, "id"), n.predicate ? " " : "", path$$1.call(print, "predicate"), semi]);
  20722. case "DeclareModule":
  20723. return printFlowDeclaration(path$$1, ["module ", path$$1.call(print, "id"), " ", path$$1.call(print, "body")]);
  20724. case "DeclareModuleExports":
  20725. return printFlowDeclaration(path$$1, ["module.exports", ": ", path$$1.call(print, "typeAnnotation"), semi]);
  20726. case "DeclareVariable":
  20727. return printFlowDeclaration(path$$1, ["var ", path$$1.call(print, "id"), semi]);
  20728. case "DeclareExportAllDeclaration":
  20729. return concat$4(["declare export * from ", path$$1.call(print, "source")]);
  20730. case "DeclareExportDeclaration":
  20731. return concat$4(["declare ", printExportDeclaration(path$$1, options, print)]);
  20732. case "DeclareOpaqueType":
  20733. case "OpaqueType":
  20734. {
  20735. parts.push("opaque type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  20736. if (n.supertype) {
  20737. parts.push(": ", path$$1.call(print, "supertype"));
  20738. }
  20739. if (n.impltype) {
  20740. parts.push(" = ", path$$1.call(print, "impltype"));
  20741. }
  20742. parts.push(semi);
  20743. if (n.type === "DeclareOpaqueType") {
  20744. return printFlowDeclaration(path$$1, parts);
  20745. }
  20746. return concat$4(parts);
  20747. }
  20748. case "FunctionTypeAnnotation":
  20749. case "TSFunctionType":
  20750. {
  20751. // FunctionTypeAnnotation is ambiguous:
  20752. // declare function foo(a: B): void; OR
  20753. // var A: (a: B) => void;
  20754. var _parent7 = path$$1.getParentNode(0);
  20755. var _parentParent2 = path$$1.getParentNode(1);
  20756. var _parentParentParent = path$$1.getParentNode(2);
  20757. 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");
  20758. var needsColon = isArrowFunctionTypeAnnotation && (_parent7.type === "TypeAnnotation" || _parent7.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
  20759. // printing ":" as part of the expression and it would put parenthesis
  20760. // around :(
  20761. var needsParens = needsColon && isArrowFunctionTypeAnnotation && (_parent7.type === "TypeAnnotation" || _parent7.type === "TSTypeAnnotation") && _parentParent2.type === "ArrowFunctionExpression";
  20762. if (isObjectTypePropertyAFunction(_parent7, options)) {
  20763. isArrowFunctionTypeAnnotation = true;
  20764. needsColon = true;
  20765. }
  20766. if (needsParens) {
  20767. parts.push("(");
  20768. }
  20769. parts.push(printFunctionParams(path$$1, print, options,
  20770. /* expandArg */
  20771. false,
  20772. /* printTypeParams */
  20773. true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
  20774. // needs to be added separately.
  20775. if (n.returnType || n.predicate || n.typeAnnotation) {
  20776. parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path$$1.call(print, "returnType"), path$$1.call(print, "predicate"), path$$1.call(print, "typeAnnotation"));
  20777. }
  20778. if (needsParens) {
  20779. parts.push(")");
  20780. }
  20781. return group$1(concat$4(parts));
  20782. }
  20783. case "TSRestType":
  20784. return concat$4(["...", path$$1.call(print, "typeAnnotation")]);
  20785. case "TSOptionalType":
  20786. return concat$4([path$$1.call(print, "typeAnnotation"), "?"]);
  20787. case "FunctionTypeParam":
  20788. return concat$4([path$$1.call(print, "name"), printOptionalToken(path$$1), n.name ? ": " : "", path$$1.call(print, "typeAnnotation")]);
  20789. case "GenericTypeAnnotation":
  20790. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  20791. case "DeclareInterface":
  20792. case "InterfaceDeclaration":
  20793. case "InterfaceTypeAnnotation":
  20794. {
  20795. if (n.type === "DeclareInterface" || isNodeStartingWithDeclare(n, options)) {
  20796. parts.push("declare ");
  20797. }
  20798. parts.push("interface");
  20799. if (n.type === "DeclareInterface" || n.type === "InterfaceDeclaration") {
  20800. parts.push(" ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  20801. }
  20802. if (n["extends"].length > 0) {
  20803. 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")))]))));
  20804. }
  20805. parts.push(" ", path$$1.call(print, "body"));
  20806. return group$1(concat$4(parts));
  20807. }
  20808. case "ClassImplements":
  20809. case "InterfaceExtends":
  20810. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  20811. case "TSClassImplements":
  20812. return concat$4([path$$1.call(print, "expression"), path$$1.call(print, "typeParameters")]);
  20813. case "TSIntersectionType":
  20814. case "IntersectionTypeAnnotation":
  20815. {
  20816. var types = path$$1.map(print, "types");
  20817. var result = [];
  20818. var wasIndented = false;
  20819. for (var _i2 = 0; _i2 < types.length; ++_i2) {
  20820. if (_i2 === 0) {
  20821. result.push(types[_i2]);
  20822. } else if (isObjectType(n.types[_i2 - 1]) && isObjectType(n.types[_i2])) {
  20823. // If both are objects, don't indent
  20824. result.push(concat$4([" & ", wasIndented ? indent$2(types[_i2]) : types[_i2]]));
  20825. } else if (!isObjectType(n.types[_i2 - 1]) && !isObjectType(n.types[_i2])) {
  20826. // If no object is involved, go to the next line if it breaks
  20827. result.push(indent$2(concat$4([" &", line$3, types[_i2]])));
  20828. } else {
  20829. // If you go from object to non-object or vis-versa, then inline it
  20830. if (_i2 > 1) {
  20831. wasIndented = true;
  20832. }
  20833. result.push(" & ", _i2 > 1 ? indent$2(types[_i2]) : types[_i2]);
  20834. }
  20835. }
  20836. return group$1(concat$4(result));
  20837. }
  20838. case "TSUnionType":
  20839. case "UnionTypeAnnotation":
  20840. {
  20841. // single-line variation
  20842. // A | B | C
  20843. // multi-line variation
  20844. // | A
  20845. // | B
  20846. // | C
  20847. var _parent8 = path$$1.getParentNode(); // If there's a leading comment, the parent is doing the indentation
  20848. 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)); // {
  20849. // a: string
  20850. // } | null | void
  20851. // should be inlined and not be printed in the multi-line variant
  20852. var shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
  20853. // | child1
  20854. // // comment
  20855. // | child2
  20856. var _printed3 = path$$1.map(function (typePath) {
  20857. var printedType = typePath.call(print);
  20858. if (!shouldHug) {
  20859. printedType = align$1(2, printedType);
  20860. }
  20861. return comments.printComments(typePath, function () {
  20862. return printedType;
  20863. }, options);
  20864. }, "types");
  20865. if (shouldHug) {
  20866. return join$2(" | ", _printed3);
  20867. }
  20868. var shouldAddStartLine = shouldIndent && !hasLeadingOwnLineComment(options.originalText, n, options);
  20869. var code = concat$4([ifBreak$1(concat$4([shouldAddStartLine ? line$3 : "", "| "])), join$2(concat$4([line$3, "| "]), _printed3)]);
  20870. var hasParens;
  20871. if (n.type === "TSUnionType") {
  20872. var greatGrandParent = path$$1.getParentNode(2);
  20873. var greatGreatGrandParent = path$$1.getParentNode(3);
  20874. hasParens = greatGrandParent && greatGrandParent.type === "TSParenthesizedType" && greatGreatGrandParent && (greatGreatGrandParent.type === "TSUnionType" || greatGreatGrandParent.type === "TSIntersectionType");
  20875. } else {
  20876. hasParens = needsParens_1(path$$1, options);
  20877. }
  20878. if (hasParens) {
  20879. return group$1(concat$4([indent$2(code), softline$1]));
  20880. }
  20881. return group$1(shouldIndent ? indent$2(code) : code);
  20882. }
  20883. case "NullableTypeAnnotation":
  20884. return concat$4(["?", path$$1.call(print, "typeAnnotation")]);
  20885. case "TSNullKeyword":
  20886. case "NullLiteralTypeAnnotation":
  20887. return "null";
  20888. case "ThisTypeAnnotation":
  20889. return "this";
  20890. case "NumberTypeAnnotation":
  20891. return "number";
  20892. case "ObjectTypeCallProperty":
  20893. if (n.static) {
  20894. parts.push("static ");
  20895. }
  20896. parts.push(path$$1.call(print, "value"));
  20897. return concat$4(parts);
  20898. case "ObjectTypeIndexer":
  20899. {
  20900. var _variance = getFlowVariance(n);
  20901. return concat$4([_variance || "", "[", path$$1.call(print, "id"), n.id ? ": " : "", path$$1.call(print, "key"), "]: ", path$$1.call(print, "value")]);
  20902. }
  20903. case "ObjectTypeProperty":
  20904. {
  20905. var _variance2 = getFlowVariance(n);
  20906. var modifier = "";
  20907. if (n.proto) {
  20908. modifier = "proto ";
  20909. } else if (n.static) {
  20910. modifier = "static ";
  20911. }
  20912. 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")]);
  20913. }
  20914. case "QualifiedTypeIdentifier":
  20915. return concat$4([path$$1.call(print, "qualification"), ".", path$$1.call(print, "id")]);
  20916. case "StringLiteralTypeAnnotation":
  20917. return nodeStr(n, options);
  20918. case "NumberLiteralTypeAnnotation":
  20919. assert.strictEqual(typeof n.value, "number");
  20920. if (n.extra != null) {
  20921. return printNumber$1(n.extra.raw);
  20922. }
  20923. return printNumber$1(n.raw);
  20924. case "StringTypeAnnotation":
  20925. return "string";
  20926. case "DeclareTypeAlias":
  20927. case "TypeAlias":
  20928. {
  20929. if (n.type === "DeclareTypeAlias" || isNodeStartingWithDeclare(n, options)) {
  20930. parts.push("declare ");
  20931. }
  20932. var _printed4 = printAssignmentRight(n.id, n.right, path$$1.call(print, "right"), options);
  20933. parts.push("type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"), " =", _printed4, semi);
  20934. return group$1(concat$4(parts));
  20935. }
  20936. case "TypeCastExpression":
  20937. {
  20938. var value = path$$1.getValue(); // Flow supports a comment syntax for specifying type annotations: https://flow.org/en/docs/types/comments/.
  20939. // Unfortunately, its parser doesn't differentiate between comment annotations and regular
  20940. // annotations when producing an AST. So to preserve parentheses around type casts that use
  20941. // the comment syntax, we need to hackily read the source itself to see if the code contains
  20942. // a type annotation comment.
  20943. //
  20944. // Note that we're able to use the normal whitespace regex here because the Flow parser has
  20945. // already deemed this AST node to be a type cast. Only the Babel parser needs the
  20946. // non-line-break whitespace regex, which is why hasFlowShorthandAnnotationComment() is
  20947. // implemented differently.
  20948. var commentSyntax = value && value.typeAnnotation && value.typeAnnotation.range && options.originalText.substring(value.typeAnnotation.range[0]).match(/^\/\*\s*:/);
  20949. return concat$4(["(", path$$1.call(print, "expression"), commentSyntax ? " /*" : "", ": ", path$$1.call(print, "typeAnnotation"), commentSyntax ? " */" : "", ")"]);
  20950. }
  20951. case "TypeParameterDeclaration":
  20952. case "TypeParameterInstantiation":
  20953. {
  20954. var _value = path$$1.getValue();
  20955. 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
  20956. // because we know for sure that this is a type definition.
  20957. var _commentSyntax = commentStart >= 0 && options.originalText.substring(commentStart).match(/^\/\*\s*::/);
  20958. if (_commentSyntax) {
  20959. return concat$4(["/*:: ", printTypeParameters(path$$1, options, print, "params"), " */"]);
  20960. }
  20961. return printTypeParameters(path$$1, options, print, "params");
  20962. }
  20963. case "TSTypeParameterDeclaration":
  20964. case "TSTypeParameterInstantiation":
  20965. return printTypeParameters(path$$1, options, print, "params");
  20966. case "TSTypeParameter":
  20967. case "TypeParameter":
  20968. {
  20969. var _parent9 = path$$1.getParentNode();
  20970. if (_parent9.type === "TSMappedType") {
  20971. parts.push("[", path$$1.call(print, "name"));
  20972. if (n.constraint) {
  20973. parts.push(" in ", path$$1.call(print, "constraint"));
  20974. }
  20975. parts.push("]");
  20976. return concat$4(parts);
  20977. }
  20978. var _variance3 = getFlowVariance(n);
  20979. if (_variance3) {
  20980. parts.push(_variance3);
  20981. }
  20982. parts.push(path$$1.call(print, "name"));
  20983. if (n.bound) {
  20984. parts.push(": ");
  20985. parts.push(path$$1.call(print, "bound"));
  20986. }
  20987. if (n.constraint) {
  20988. parts.push(" extends ", path$$1.call(print, "constraint"));
  20989. }
  20990. if (n["default"]) {
  20991. parts.push(" = ", path$$1.call(print, "default"));
  20992. }
  20993. return concat$4(parts);
  20994. }
  20995. case "TypeofTypeAnnotation":
  20996. return concat$4(["typeof ", path$$1.call(print, "argument")]);
  20997. case "VoidTypeAnnotation":
  20998. return "void";
  20999. case "InferredPredicate":
  21000. return "%checks";
  21001. // Unhandled types below. If encountered, nodes of these types should
  21002. // be either left alone or desugared into AST types that are fully
  21003. // supported by the pretty-printer.
  21004. case "DeclaredPredicate":
  21005. return concat$4(["%checks(", path$$1.call(print, "value"), ")"]);
  21006. case "TSAbstractKeyword":
  21007. return "abstract";
  21008. case "TSAnyKeyword":
  21009. return "any";
  21010. case "TSAsyncKeyword":
  21011. return "async";
  21012. case "TSBooleanKeyword":
  21013. return "boolean";
  21014. case "TSBigIntKeyword":
  21015. return "bigint";
  21016. case "TSConstKeyword":
  21017. return "const";
  21018. case "TSDeclareKeyword":
  21019. return "declare";
  21020. case "TSExportKeyword":
  21021. return "export";
  21022. case "TSNeverKeyword":
  21023. return "never";
  21024. case "TSNumberKeyword":
  21025. return "number";
  21026. case "TSObjectKeyword":
  21027. return "object";
  21028. case "TSProtectedKeyword":
  21029. return "protected";
  21030. case "TSPrivateKeyword":
  21031. return "private";
  21032. case "TSPublicKeyword":
  21033. return "public";
  21034. case "TSReadonlyKeyword":
  21035. return "readonly";
  21036. case "TSSymbolKeyword":
  21037. return "symbol";
  21038. case "TSStaticKeyword":
  21039. return "static";
  21040. case "TSStringKeyword":
  21041. return "string";
  21042. case "TSUndefinedKeyword":
  21043. return "undefined";
  21044. case "TSUnknownKeyword":
  21045. return "unknown";
  21046. case "TSVoidKeyword":
  21047. return "void";
  21048. case "TSAsExpression":
  21049. return concat$4([path$$1.call(print, "expression"), " as ", path$$1.call(print, "typeAnnotation")]);
  21050. case "TSArrayType":
  21051. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  21052. case "TSPropertySignature":
  21053. {
  21054. if (n.export) {
  21055. parts.push("export ");
  21056. }
  21057. if (n.accessibility) {
  21058. parts.push(n.accessibility + " ");
  21059. }
  21060. if (n.static) {
  21061. parts.push("static ");
  21062. }
  21063. if (n.readonly) {
  21064. parts.push("readonly ");
  21065. }
  21066. if (n.computed) {
  21067. parts.push("[");
  21068. }
  21069. parts.push(printPropertyKey(path$$1, options, print));
  21070. if (n.computed) {
  21071. parts.push("]");
  21072. }
  21073. parts.push(printOptionalToken(path$$1));
  21074. if (n.typeAnnotation) {
  21075. parts.push(": ");
  21076. parts.push(path$$1.call(print, "typeAnnotation"));
  21077. } // This isn't valid semantically, but it's in the AST so we can print it.
  21078. if (n.initializer) {
  21079. parts.push(" = ", path$$1.call(print, "initializer"));
  21080. }
  21081. return concat$4(parts);
  21082. }
  21083. case "TSParameterProperty":
  21084. if (n.accessibility) {
  21085. parts.push(n.accessibility + " ");
  21086. }
  21087. if (n.export) {
  21088. parts.push("export ");
  21089. }
  21090. if (n.static) {
  21091. parts.push("static ");
  21092. }
  21093. if (n.readonly) {
  21094. parts.push("readonly ");
  21095. }
  21096. parts.push(path$$1.call(print, "parameter"));
  21097. return concat$4(parts);
  21098. case "TSTypeReference":
  21099. return concat$4([path$$1.call(print, "typeName"), printTypeParameters(path$$1, options, print, "typeParameters")]);
  21100. case "TSTypeQuery":
  21101. return concat$4(["typeof ", path$$1.call(print, "exprName")]);
  21102. case "TSParenthesizedType":
  21103. {
  21104. return path$$1.call(print, "typeAnnotation");
  21105. }
  21106. case "TSIndexSignature":
  21107. {
  21108. var _parent10 = path$$1.getParentNode();
  21109. 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 : ""]);
  21110. }
  21111. case "TSTypePredicate":
  21112. return concat$4([path$$1.call(print, "parameterName"), " is ", path$$1.call(print, "typeAnnotation")]);
  21113. case "TSNonNullExpression":
  21114. return concat$4([path$$1.call(print, "expression"), "!"]);
  21115. case "TSThisType":
  21116. return "this";
  21117. case "TSImportType":
  21118. 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")]);
  21119. case "TSLiteralType":
  21120. return path$$1.call(print, "literal");
  21121. case "TSIndexedAccessType":
  21122. return concat$4([path$$1.call(print, "objectType"), "[", path$$1.call(print, "indexType"), "]"]);
  21123. case "TSConstructSignatureDeclaration":
  21124. case "TSCallSignatureDeclaration":
  21125. case "TSConstructorType":
  21126. {
  21127. if (n.type !== "TSCallSignatureDeclaration") {
  21128. parts.push("new ");
  21129. }
  21130. parts.push(group$1(printFunctionParams(path$$1, print, options,
  21131. /* expandArg */
  21132. false,
  21133. /* printTypeParams */
  21134. true)));
  21135. if (n.returnType) {
  21136. var isType = n.type === "TSConstructorType";
  21137. parts.push(isType ? " => " : ": ", path$$1.call(print, "returnType"));
  21138. }
  21139. return concat$4(parts);
  21140. }
  21141. case "TSTypeOperator":
  21142. return concat$4([n.operator, " ", path$$1.call(print, "typeAnnotation")]);
  21143. case "TSMappedType":
  21144. 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")])), comments.printDanglingComments(path$$1, options,
  21145. /* sameIndent */
  21146. true), options.bracketSpacing ? line$3 : softline$1, "}"]));
  21147. case "TSMethodSignature":
  21148. 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,
  21149. /* expandArg */
  21150. false,
  21151. /* printTypeParams */
  21152. true));
  21153. if (n.returnType) {
  21154. parts.push(": ", path$$1.call(print, "returnType"));
  21155. }
  21156. return group$1(concat$4(parts));
  21157. case "TSNamespaceExportDeclaration":
  21158. parts.push("export as namespace ", path$$1.call(print, "id"));
  21159. if (options.semi) {
  21160. parts.push(";");
  21161. }
  21162. return group$1(concat$4(parts));
  21163. case "TSEnumDeclaration":
  21164. if (isNodeStartingWithDeclare(n, options)) {
  21165. parts.push("declare ");
  21166. }
  21167. if (n.modifiers) {
  21168. parts.push(printTypeScriptModifiers(path$$1, options, print));
  21169. }
  21170. if (n.const) {
  21171. parts.push("const ");
  21172. }
  21173. parts.push("enum ", path$$1.call(print, "id"), " ");
  21174. if (n.members.length === 0) {
  21175. parts.push(group$1(concat$4(["{", comments.printDanglingComments(path$$1, options), softline$1, "}"])));
  21176. } else {
  21177. 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,
  21178. /* sameIndent */
  21179. true), hardline$3, "}"])));
  21180. }
  21181. return concat$4(parts);
  21182. case "TSEnumMember":
  21183. parts.push(path$$1.call(print, "id"));
  21184. if (n.initializer) {
  21185. parts.push(" = ", path$$1.call(print, "initializer"));
  21186. }
  21187. return concat$4(parts);
  21188. case "TSImportEqualsDeclaration":
  21189. if (n.isExport) {
  21190. parts.push("export ");
  21191. }
  21192. parts.push("import ", path$$1.call(print, "id"), " = ", path$$1.call(print, "moduleReference"));
  21193. if (options.semi) {
  21194. parts.push(";");
  21195. }
  21196. return group$1(concat$4(parts));
  21197. case "TSExternalModuleReference":
  21198. return concat$4(["require(", path$$1.call(print, "expression"), ")"]);
  21199. case "TSModuleDeclaration":
  21200. {
  21201. var _parent11 = path$$1.getParentNode();
  21202. var isExternalModule = isLiteral(n.id);
  21203. var parentIsDeclaration = _parent11.type === "TSModuleDeclaration";
  21204. var bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  21205. if (parentIsDeclaration) {
  21206. parts.push(".");
  21207. } else {
  21208. if (n.declare === true) {
  21209. parts.push("declare ");
  21210. }
  21211. parts.push(printTypeScriptModifiers(path$$1, options, print));
  21212. var textBetweenNodeAndItsId = options.originalText.slice(options.locStart(n), options.locStart(n.id)); // Global declaration looks like this:
  21213. // (declare)? global { ... }
  21214. var isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(textBetweenNodeAndItsId);
  21215. if (!isGlobalDeclaration) {
  21216. parts.push(isExternalModule || /(^|\s)module(\s|$)/.test(textBetweenNodeAndItsId) ? "module " : "namespace ");
  21217. }
  21218. }
  21219. parts.push(path$$1.call(print, "id"));
  21220. if (bodyIsDeclaration) {
  21221. parts.push(path$$1.call(print, "body"));
  21222. } else if (n.body) {
  21223. parts.push(" ", group$1(path$$1.call(print, "body")));
  21224. } else {
  21225. parts.push(semi);
  21226. }
  21227. return concat$4(parts);
  21228. }
  21229. case "PrivateName":
  21230. return concat$4(["#", path$$1.call(print, "id")]);
  21231. case "TSConditionalType":
  21232. return printTernaryOperator(path$$1, options, print, {
  21233. beforeParts: function beforeParts() {
  21234. return [path$$1.call(print, "checkType"), " ", "extends", " ", path$$1.call(print, "extendsType")];
  21235. },
  21236. afterParts: function afterParts() {
  21237. return [];
  21238. },
  21239. shouldCheckJsx: false,
  21240. conditionalNodeType: "TSConditionalType",
  21241. consequentNodePropertyName: "trueType",
  21242. alternateNodePropertyName: "falseType",
  21243. testNodePropertyName: "checkType",
  21244. breakNested: true
  21245. });
  21246. case "TSInferType":
  21247. return concat$4(["infer", " ", path$$1.call(print, "typeParameter")]);
  21248. case "InterpreterDirective":
  21249. parts.push("#!", n.value, hardline$3);
  21250. if (isNextLineEmpty$2(options.originalText, n, options)) {
  21251. parts.push(hardline$3);
  21252. }
  21253. return concat$4(parts);
  21254. case "NGRoot":
  21255. 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()])));
  21256. case "NGChainedExpression":
  21257. return group$1(join$2(concat$4([";", line$3]), path$$1.map(function (childPath) {
  21258. return hasNgSideEffect(childPath) ? print(childPath) : concat$4(["(", print(childPath), ")"]);
  21259. }, "expressions")));
  21260. case "NGEmptyExpression":
  21261. return "";
  21262. case "NGQuotedExpression":
  21263. return concat$4([n.prefix, ":", n.value]);
  21264. case "NGMicrosyntax":
  21265. return concat$4(path$$1.map(function (childPath, index) {
  21266. return concat$4([index === 0 ? "" : isNgForOf(childPath.getValue(), index, n) ? " " : concat$4([";", line$3]), print(childPath)]);
  21267. }, "body"));
  21268. case "NGMicrosyntaxKey":
  21269. return /^[a-z_$][a-z0-9_$]*(-[a-z_$][a-z0-9_$])*$/i.test(n.name) ? n.name : JSON.stringify(n.name);
  21270. case "NGMicrosyntaxExpression":
  21271. return concat$4([path$$1.call(print, "expression"), n.alias === null ? "" : concat$4([" as ", path$$1.call(print, "alias")])]);
  21272. case "NGMicrosyntaxKeyedExpression":
  21273. {
  21274. var index = path$$1.getName();
  21275. var _parentNode2 = path$$1.getParentNode();
  21276. 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";
  21277. return concat$4([path$$1.call(print, "key"), shouldNotPrintColon ? " " : ": ", path$$1.call(print, "expression")]);
  21278. }
  21279. case "NGMicrosyntaxLet":
  21280. return concat$4(["let ", path$$1.call(print, "key"), n.value === null ? "" : concat$4([" = ", path$$1.call(print, "value")])]);
  21281. case "NGMicrosyntaxAs":
  21282. return concat$4([path$$1.call(print, "key"), " as ", path$$1.call(print, "alias")]);
  21283. default:
  21284. /* istanbul ignore next */
  21285. throw new Error("unknown type: " + JSON.stringify(n.type));
  21286. }
  21287. }
  21288. function isNgForOf(node, index, parentNode) {
  21289. return node.type === "NGMicrosyntaxKeyedExpression" && node.key.name === "of" && index === 1 && parentNode.body[0].type === "NGMicrosyntaxLet" && parentNode.body[0].value === null;
  21290. }
  21291. /** identify if an angular expression seems to have side effects */
  21292. function hasNgSideEffect(path$$1) {
  21293. return hasNode(path$$1.getValue(), function (node) {
  21294. switch (node.type) {
  21295. case undefined:
  21296. return false;
  21297. case "CallExpression":
  21298. case "OptionalCallExpression":
  21299. case "AssignmentExpression":
  21300. return true;
  21301. }
  21302. });
  21303. }
  21304. function printStatementSequence(path$$1, options, print) {
  21305. var printed = [];
  21306. var bodyNode = path$$1.getNode();
  21307. var isClass = bodyNode.type === "ClassBody";
  21308. path$$1.map(function (stmtPath, i) {
  21309. var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
  21310. // "statements," it's safer simply to skip them.
  21311. /* istanbul ignore if */
  21312. if (!stmt) {
  21313. return;
  21314. } // Skip printing EmptyStatement nodes to avoid leaving stray
  21315. // semicolons lying around.
  21316. if (stmt.type === "EmptyStatement") {
  21317. return;
  21318. }
  21319. var stmtPrinted = print(stmtPath);
  21320. var text = options.originalText;
  21321. var parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
  21322. // don't prepend the only JSX element in a program with semicolon
  21323. if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
  21324. if (stmt.comments && stmt.comments.some(function (comment) {
  21325. return comment.leading;
  21326. })) {
  21327. parts.push(print(stmtPath, {
  21328. needsSemi: true
  21329. }));
  21330. } else {
  21331. parts.push(";", stmtPrinted);
  21332. }
  21333. } else {
  21334. parts.push(stmtPrinted);
  21335. }
  21336. if (!options.semi && isClass) {
  21337. if (classPropMayCauseASIProblems(stmtPath)) {
  21338. parts.push(";");
  21339. } else if (stmt.type === "ClassProperty") {
  21340. var nextChild = bodyNode.body[i + 1];
  21341. if (classChildNeedsASIProtection(nextChild)) {
  21342. parts.push(";");
  21343. }
  21344. }
  21345. }
  21346. if (isNextLineEmpty$2(text, stmt, options) && !isLastStatement(stmtPath)) {
  21347. parts.push(hardline$3);
  21348. }
  21349. printed.push(concat$4(parts));
  21350. });
  21351. return join$2(hardline$3, printed);
  21352. }
  21353. function printPropertyKey(path$$1, options, print) {
  21354. var node = path$$1.getNode();
  21355. var key = node.key;
  21356. if (key.type === "Identifier" && !node.computed && options.parser === "json") {
  21357. // a -> "a"
  21358. return path$$1.call(function (keyPath) {
  21359. return comments.printComments(keyPath, function () {
  21360. return JSON.stringify(key.name);
  21361. }, options);
  21362. }, "key");
  21363. }
  21364. if (isStringLiteral(key) && isIdentifierName(key.value) && !node.computed && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty")) {
  21365. // 'a' -> a
  21366. return path$$1.call(function (keyPath) {
  21367. return comments.printComments(keyPath, function () {
  21368. return key.value;
  21369. }, options);
  21370. }, "key");
  21371. }
  21372. return path$$1.call(print, "key");
  21373. }
  21374. function printMethod(path$$1, options, print) {
  21375. var node = path$$1.getNode();
  21376. var semi = options.semi ? ";" : "";
  21377. var kind = node.kind;
  21378. var parts = [];
  21379. if (node.type === "ObjectMethod" || node.type === "ClassMethod" || node.type === "ClassPrivateMethod") {
  21380. node.value = node;
  21381. }
  21382. if (node.value.async) {
  21383. parts.push("async ");
  21384. }
  21385. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  21386. if (node.value.generator) {
  21387. parts.push("*");
  21388. }
  21389. } else {
  21390. assert.ok(kind === "get" || kind === "set");
  21391. parts.push(kind, " ");
  21392. }
  21393. var key = printPropertyKey(path$$1, options, print);
  21394. if (node.computed) {
  21395. key = concat$4(["[", key, "]"]);
  21396. }
  21397. parts.push(key, concat$4(path$$1.call(function (valuePath) {
  21398. return [printFunctionTypeParameters(valuePath, options, print), group$1(concat$4([printFunctionParams(valuePath, print, options), printReturnType(valuePath, print, options)]))];
  21399. }, "value")));
  21400. if (!node.value.body || node.value.body.length === 0) {
  21401. parts.push(semi);
  21402. } else {
  21403. parts.push(" ", path$$1.call(print, "value", "body"));
  21404. }
  21405. return concat$4(parts);
  21406. }
  21407. function couldGroupArg(arg) {
  21408. 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" && !arg.returnType && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode(arg.body));
  21409. }
  21410. function shouldGroupLastArg(args) {
  21411. var lastArg = getLast$4(args);
  21412. var penultimateArg = getPenultimate$1(args);
  21413. return !hasLeadingComment(lastArg) && !hasTrailingComment(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
  21414. // disable last element expansion.
  21415. !penultimateArg || penultimateArg.type !== lastArg.type);
  21416. }
  21417. function shouldGroupFirstArg(args) {
  21418. if (args.length !== 2) {
  21419. return false;
  21420. }
  21421. var firstArg = args[0];
  21422. var secondArg = args[1];
  21423. 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);
  21424. }
  21425. function isSimpleFlowType(node) {
  21426. var flowTypeAnnotations = ["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"];
  21427. return node && flowTypeAnnotations.indexOf(node.type) !== -1 && !(node.type === "GenericTypeAnnotation" && node.typeParameters);
  21428. }
  21429. var functionCompositionFunctionNames = new Set(["pipe", // RxJS, Ramda
  21430. "pipeP", // Ramda
  21431. "pipeK", // Ramda
  21432. "compose", // Ramda, Redux
  21433. "composeFlipped", // Not from any library, but common in Haskell, so supported
  21434. "composeP", // Ramda
  21435. "composeK", // Ramda
  21436. "flow", // Lodash
  21437. "flowRight", // Lodash
  21438. "connect", // Redux
  21439. "createSelector" // Reselect
  21440. ]);
  21441. var ordinaryMethodNames = new Set(["connect" // GObject, MongoDB
  21442. ]);
  21443. function isFunctionCompositionFunction(node) {
  21444. switch (node.type) {
  21445. case "OptionalMemberExpression":
  21446. case "MemberExpression":
  21447. {
  21448. return isFunctionCompositionFunction(node.property) && !ordinaryMethodNames.has(node.property.name);
  21449. }
  21450. case "Identifier":
  21451. {
  21452. return functionCompositionFunctionNames.has(node.name);
  21453. }
  21454. case "StringLiteral":
  21455. case "Literal":
  21456. {
  21457. return functionCompositionFunctionNames.has(node.value);
  21458. }
  21459. }
  21460. }
  21461. function printArgumentsList(path$$1, options, print) {
  21462. var node = path$$1.getValue();
  21463. var args = node.arguments;
  21464. if (args.length === 0) {
  21465. return concat$4(["(", comments.printDanglingComments(path$$1, options,
  21466. /* sameIndent */
  21467. true), ")"]);
  21468. } // useEffect(() => { ... }, [foo, bar, baz])
  21469. 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) {
  21470. return arg.leadingComments || arg.trailingComments;
  21471. })) {
  21472. return concat$4(["(", path$$1.call(print, "arguments", 0), ", ", path$$1.call(print, "arguments", 1), ")"]);
  21473. }
  21474. var anyArgEmptyLine = false;
  21475. var hasEmptyLineFollowingFirstArg = false;
  21476. var lastArgIndex = args.length - 1;
  21477. var printedArguments = path$$1.map(function (argPath, index) {
  21478. var arg = argPath.getNode();
  21479. var parts = [print(argPath)];
  21480. if (index === lastArgIndex) {// do nothing
  21481. } else if (isNextLineEmpty$2(options.originalText, arg, options)) {
  21482. if (index === 0) {
  21483. hasEmptyLineFollowingFirstArg = true;
  21484. }
  21485. anyArgEmptyLine = true;
  21486. parts.push(",", hardline$3, hardline$3);
  21487. } else {
  21488. parts.push(",", line$3);
  21489. }
  21490. return concat$4(parts);
  21491. }, "arguments");
  21492. var maybeTrailingComma = shouldPrintComma(options, "all") ? "," : "";
  21493. function allArgsBrokenOut() {
  21494. return group$1(concat$4(["(", indent$2(concat$4([line$3, concat$4(printedArguments)])), maybeTrailingComma, line$3, ")"]), {
  21495. shouldBreak: true
  21496. });
  21497. } // We want to get
  21498. // pipe(
  21499. // x => x + 1,
  21500. // x => x - 1
  21501. // )
  21502. // here, but not
  21503. // process.stdout.pipe(socket)
  21504. if (isFunctionCompositionFunction(node.callee) && args.length > 1) {
  21505. return allArgsBrokenOut();
  21506. }
  21507. var shouldGroupFirst = shouldGroupFirstArg(args);
  21508. var shouldGroupLast = shouldGroupLastArg(args);
  21509. if (shouldGroupFirst || shouldGroupLast) {
  21510. 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
  21511. var printedExpanded;
  21512. var i = 0;
  21513. path$$1.each(function (argPath) {
  21514. if (shouldGroupFirst && i === 0) {
  21515. printedExpanded = [concat$4([argPath.call(function (p) {
  21516. return print(p, {
  21517. expandFirstArg: true
  21518. });
  21519. }), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$3 : line$3, hasEmptyLineFollowingFirstArg ? hardline$3 : ""])].concat(printedArguments.slice(1));
  21520. }
  21521. if (shouldGroupLast && i === args.length - 1) {
  21522. printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(function (p) {
  21523. return print(p, {
  21524. expandLastArg: true
  21525. });
  21526. }));
  21527. }
  21528. i++;
  21529. }, "arguments");
  21530. var somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  21531. 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], {
  21532. shouldBreak: true
  21533. }), concat$4(printedExpanded.slice(1)), ")"]) : concat$4(["(", concat$4(printedArguments.slice(0, -1)), group$1(getLast$4(printedExpanded), {
  21534. shouldBreak: true
  21535. }), ")"]), allArgsBrokenOut()], {
  21536. shouldBreak
  21537. })]);
  21538. }
  21539. return group$1(concat$4(["(", indent$2(concat$4([softline$1, concat$4(printedArguments)])), ifBreak$1(shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]), {
  21540. shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
  21541. });
  21542. }
  21543. function printTypeAnnotation(path$$1, options, print) {
  21544. var node = path$$1.getValue();
  21545. if (!node.typeAnnotation) {
  21546. return "";
  21547. }
  21548. var parentNode = path$$1.getParentNode();
  21549. var isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
  21550. var isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
  21551. if (isFlowAnnotationComment(options.originalText, node.typeAnnotation, options)) {
  21552. return concat$4([" /*: ", path$$1.call(print, "typeAnnotation"), " */"]);
  21553. }
  21554. return concat$4([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path$$1.call(print, "typeAnnotation")]);
  21555. }
  21556. function printFunctionTypeParameters(path$$1, options, print) {
  21557. var fun = path$$1.getValue();
  21558. if (fun.typeArguments) {
  21559. return path$$1.call(print, "typeArguments");
  21560. }
  21561. if (fun.typeParameters) {
  21562. return path$$1.call(print, "typeParameters");
  21563. }
  21564. return "";
  21565. }
  21566. function printFunctionParams(path$$1, print, options, expandArg, printTypeParams) {
  21567. var fun = path$$1.getValue();
  21568. var paramsField = fun.parameters ? "parameters" : "params";
  21569. var typeParams = printTypeParams ? printFunctionTypeParameters(path$$1, options, print) : "";
  21570. var printed = [];
  21571. if (fun[paramsField]) {
  21572. printed = path$$1.map(print, paramsField);
  21573. }
  21574. if (fun.rest) {
  21575. printed.push(concat$4(["...", path$$1.call(print, "rest")]));
  21576. }
  21577. if (printed.length === 0) {
  21578. return concat$4([typeParams, "(", comments.printDanglingComments(path$$1, options,
  21579. /* sameIndent */
  21580. true, function (comment) {
  21581. return getNextNonSpaceNonCommentCharacter$1(options.originalText, comment, options.locEnd) === ")";
  21582. }), ")"]);
  21583. }
  21584. var lastParam = getLast$4(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
  21585. // params of the first/last argument, we dont want the arguments to break and instead
  21586. // want the whole expression to be on a new line.
  21587. //
  21588. // Good: Bad:
  21589. // verylongcall( verylongcall((
  21590. // (a, b) => { a,
  21591. // } b,
  21592. // }) ) => {
  21593. // })
  21594. if (expandArg && !(fun[paramsField] && fun[paramsField].some(function (n) {
  21595. return n.comments;
  21596. }))) {
  21597. return group$1(concat$4([removeLines$1(typeParams), "(", join$2(", ", printed.map(removeLines$1)), ")"]));
  21598. } // Single object destructuring should hug
  21599. //
  21600. // function({
  21601. // a,
  21602. // b,
  21603. // c
  21604. // }) {}
  21605. if (shouldHugArguments(fun)) {
  21606. return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
  21607. }
  21608. var parent = path$$1.getParentNode(); // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  21609. if (isTestCall(parent)) {
  21610. return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
  21611. }
  21612. 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;
  21613. if (isFlowShorthandWithOneArg) {
  21614. if (options.arrowParens === "always") {
  21615. return concat$4(["(", concat$4(printed), ")"]);
  21616. }
  21617. return concat$4(printed);
  21618. }
  21619. var canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  21620. return concat$4([typeParams, "(", indent$2(concat$4([softline$1, join$2(concat$4([",", line$3]), printed)])), ifBreak$1(canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]);
  21621. }
  21622. function shouldPrintParamsWithoutParens(path$$1, options) {
  21623. if (options.arrowParens === "always") {
  21624. return false;
  21625. }
  21626. if (options.arrowParens === "avoid") {
  21627. var node = path$$1.getValue();
  21628. return canPrintParamsWithoutParens(node);
  21629. } // Fallback default; should be unreachable
  21630. return false;
  21631. }
  21632. function canPrintParamsWithoutParens(node) {
  21633. 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;
  21634. }
  21635. function printFunctionDeclaration(path$$1, print, options) {
  21636. var n = path$$1.getValue();
  21637. var parts = [];
  21638. if (n.async) {
  21639. parts.push("async ");
  21640. }
  21641. parts.push("function");
  21642. if (n.generator) {
  21643. parts.push("*");
  21644. }
  21645. if (n.id) {
  21646. parts.push(" ", path$$1.call(print, "id"));
  21647. }
  21648. 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"));
  21649. return concat$4(parts);
  21650. }
  21651. function printObjectMethod(path$$1, options, print) {
  21652. var objMethod = path$$1.getValue();
  21653. var parts = [];
  21654. if (objMethod.async) {
  21655. parts.push("async ");
  21656. }
  21657. if (objMethod.generator) {
  21658. parts.push("*");
  21659. }
  21660. if (objMethod.method || objMethod.kind === "get" || objMethod.kind === "set") {
  21661. return printMethod(path$$1, options, print);
  21662. }
  21663. var key = printPropertyKey(path$$1, options, print);
  21664. if (objMethod.computed) {
  21665. parts.push("[", key, "]");
  21666. } else {
  21667. parts.push(key);
  21668. }
  21669. 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"));
  21670. return concat$4(parts);
  21671. }
  21672. function printReturnType(path$$1, print, options) {
  21673. var n = path$$1.getValue();
  21674. var returnType = path$$1.call(print, "returnType");
  21675. if (n.returnType && isFlowAnnotationComment(options.originalText, n.returnType, options)) {
  21676. return concat$4([" /*: ", returnType, " */"]);
  21677. }
  21678. var parts = [returnType]; // prepend colon to TypeScript type annotation
  21679. if (n.returnType && n.returnType.typeAnnotation) {
  21680. parts.unshift(": ");
  21681. }
  21682. if (n.predicate) {
  21683. // The return type will already add the colon, but otherwise we
  21684. // need to do it ourselves
  21685. parts.push(n.returnType ? " " : ": ", path$$1.call(print, "predicate"));
  21686. }
  21687. return concat$4(parts);
  21688. }
  21689. function printExportDeclaration(path$$1, options, print) {
  21690. var decl = path$$1.getValue();
  21691. var semi = options.semi ? ";" : "";
  21692. var parts = ["export "];
  21693. var isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  21694. if (isDefault) {
  21695. parts.push("default ");
  21696. }
  21697. parts.push(comments.printDanglingComments(path$$1, options,
  21698. /* sameIndent */
  21699. true));
  21700. if (needsHardlineAfterDanglingComment(decl)) {
  21701. parts.push(hardline$3);
  21702. }
  21703. if (decl.declaration) {
  21704. parts.push(path$$1.call(print, "declaration"));
  21705. if (isDefault && decl.declaration.type !== "ClassDeclaration" && decl.declaration.type !== "FunctionDeclaration" && decl.declaration.type !== "TSAbstractClassDeclaration" && decl.declaration.type !== "TSInterfaceDeclaration" && decl.declaration.type !== "DeclareClass" && decl.declaration.type !== "DeclareFunction" && decl.declaration.type !== "TSDeclareFunction") {
  21706. parts.push(semi);
  21707. }
  21708. } else {
  21709. if (decl.specifiers && decl.specifiers.length > 0) {
  21710. var specifiers = [];
  21711. var defaultSpecifiers = [];
  21712. var namespaceSpecifiers = [];
  21713. path$$1.each(function (specifierPath) {
  21714. var specifierType = path$$1.getValue().type;
  21715. if (specifierType === "ExportSpecifier") {
  21716. specifiers.push(print(specifierPath));
  21717. } else if (specifierType === "ExportDefaultSpecifier") {
  21718. defaultSpecifiers.push(print(specifierPath));
  21719. } else if (specifierType === "ExportNamespaceSpecifier") {
  21720. namespaceSpecifiers.push(concat$4(["* as ", print(specifierPath)]));
  21721. }
  21722. }, "specifiers");
  21723. var isNamespaceFollowed = namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  21724. var isDefaultFollowed = defaultSpecifiers.length !== 0 && (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  21725. 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, "}"])) : "");
  21726. } else {
  21727. parts.push("{}");
  21728. }
  21729. if (decl.source) {
  21730. parts.push(" from ", path$$1.call(print, "source"));
  21731. }
  21732. parts.push(semi);
  21733. }
  21734. return concat$4(parts);
  21735. }
  21736. function printFlowDeclaration(path$$1, parts) {
  21737. var parentExportDecl = getParentExportDeclaration$1(path$$1);
  21738. if (parentExportDecl) {
  21739. assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  21740. } else {
  21741. // If the parent node has type DeclareExportDeclaration, then it
  21742. // will be responsible for printing the "declare" token. Otherwise
  21743. // it needs to be printed with this non-exported declaration node.
  21744. parts.unshift("declare ");
  21745. }
  21746. return concat$4(parts);
  21747. }
  21748. function getFlowVariance(path$$1) {
  21749. if (!path$$1.variance) {
  21750. return null;
  21751. } // Babel 7.0 currently uses variance node type, and flow should
  21752. // follow suit soon:
  21753. // https://github.com/babel/babel/issues/4722
  21754. var variance = path$$1.variance.kind || path$$1.variance;
  21755. switch (variance) {
  21756. case "plus":
  21757. return "+";
  21758. case "minus":
  21759. return "-";
  21760. default:
  21761. /* istanbul ignore next */
  21762. return variance;
  21763. }
  21764. }
  21765. function printTypeScriptModifiers(path$$1, options, print) {
  21766. var n = path$$1.getValue();
  21767. if (!n.modifiers || !n.modifiers.length) {
  21768. return "";
  21769. }
  21770. return concat$4([join$2(" ", path$$1.map(print, "modifiers")), " "]);
  21771. }
  21772. function printTypeParameters(path$$1, options, print, paramsKey) {
  21773. var n = path$$1.getValue();
  21774. if (!n[paramsKey]) {
  21775. return "";
  21776. } // for TypeParameterDeclaration typeParameters is a single node
  21777. if (!Array.isArray(n[paramsKey])) {
  21778. return path$$1.call(print, paramsKey);
  21779. }
  21780. var grandparent = path$$1.getNode(2);
  21781. var isParameterInTestCall = grandparent != null && isTestCall(grandparent);
  21782. 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");
  21783. if (shouldInline) {
  21784. return concat$4(["<", join$2(", ", path$$1.map(print, paramsKey)), ">"]);
  21785. }
  21786. 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, ">"]));
  21787. }
  21788. function printClass(path$$1, options, print) {
  21789. var n = path$$1.getValue();
  21790. var parts = [];
  21791. if (n.type === "TSAbstractClassDeclaration") {
  21792. parts.push("abstract ");
  21793. }
  21794. parts.push("class");
  21795. if (n.id) {
  21796. parts.push(" ", path$$1.call(print, "id"));
  21797. }
  21798. parts.push(path$$1.call(print, "typeParameters"));
  21799. var partsGroup = [];
  21800. if (n.superClass) {
  21801. var printed = concat$4(["extends ", path$$1.call(print, "superClass"), path$$1.call(print, "superTypeParameters")]); // Keep old behaviour of extends in same line
  21802. // If there is only on extends and there are not comments
  21803. if ((!n.implements || n.implements.length === 0) && (!n.superClass.comments || n.superClass.comments.length === 0)) {
  21804. parts.push(concat$4([" ", path$$1.call(function (superClass) {
  21805. return comments.printComments(superClass, function () {
  21806. return printed;
  21807. }, options);
  21808. }, "superClass")]));
  21809. } else {
  21810. partsGroup.push(group$1(concat$4([line$3, path$$1.call(function (superClass) {
  21811. return comments.printComments(superClass, function () {
  21812. return printed;
  21813. }, options);
  21814. }, "superClass")])));
  21815. }
  21816. } else if (n.extends && n.extends.length > 0) {
  21817. parts.push(" extends ", join$2(", ", path$$1.map(print, "extends")));
  21818. }
  21819. if (n["mixins"] && n["mixins"].length > 0) {
  21820. partsGroup.push(line$3, "mixins ", group$1(indent$2(join$2(concat$4([",", line$3]), path$$1.map(print, "mixins")))));
  21821. }
  21822. if (n["implements"] && n["implements"].length > 0) {
  21823. partsGroup.push(line$3, "implements", group$1(indent$2(concat$4([line$3, join$2(concat$4([",", line$3]), path$$1.map(print, "implements"))]))));
  21824. }
  21825. if (partsGroup.length > 0) {
  21826. parts.push(group$1(indent$2(concat$4(partsGroup))));
  21827. }
  21828. if (n.body && n.body.comments && hasLeadingOwnLineComment(options.originalText, n.body, options)) {
  21829. parts.push(hardline$3);
  21830. } else {
  21831. parts.push(" ");
  21832. }
  21833. parts.push(path$$1.call(print, "body"));
  21834. return parts;
  21835. }
  21836. function printOptionalToken(path$$1) {
  21837. var node = path$$1.getValue();
  21838. if (!node.optional) {
  21839. return "";
  21840. }
  21841. if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
  21842. return "?.";
  21843. }
  21844. return "?";
  21845. }
  21846. function printMemberLookup(path$$1, options, print) {
  21847. var property = path$$1.call(print, "property");
  21848. var n = path$$1.getValue();
  21849. var optional = printOptionalToken(path$$1);
  21850. if (!n.computed) {
  21851. return concat$4([optional, ".", property]);
  21852. }
  21853. if (!n.property || isNumericLiteral(n.property)) {
  21854. return concat$4([optional, "[", property, "]"]);
  21855. }
  21856. return group$1(concat$4([optional, "[", indent$2(concat$4([softline$1, property])), softline$1, "]"]));
  21857. }
  21858. function printBindExpressionCallee(path$$1, options, print) {
  21859. return concat$4(["::", path$$1.call(print, "callee")]);
  21860. } // We detect calls on member expressions specially to format a
  21861. // common pattern better. The pattern we are looking for is this:
  21862. //
  21863. // arr
  21864. // .map(x => x + 1)
  21865. // .filter(x => x > 10)
  21866. // .some(x => x % 2)
  21867. //
  21868. // The way it is structured in the AST is via a nested sequence of
  21869. // MemberExpression and CallExpression. We need to traverse the AST
  21870. // and make groups out of it to print it in the desired way.
  21871. function printMemberChain(path$$1, options, print) {
  21872. // The first phase is to linearize the AST by traversing it down.
  21873. //
  21874. // a().b()
  21875. // has the following AST structure:
  21876. // CallExpression(MemberExpression(CallExpression(Identifier)))
  21877. // and we transform it into
  21878. // [Identifier, CallExpression, MemberExpression, CallExpression]
  21879. var printedNodes = []; // Here we try to retain one typed empty line after each call expression or
  21880. // the first group whether it is in parentheses or not
  21881. function shouldInsertEmptyLineAfter(node) {
  21882. var originalText = options.originalText;
  21883. var nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$2(originalText, node, options);
  21884. var nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
  21885. // line after that parenthesis
  21886. if (nextChar == ")") {
  21887. return isNextLineEmptyAfterIndex$1(originalText, nextCharIndex + 1, options);
  21888. }
  21889. return isNextLineEmpty$2(originalText, node, options);
  21890. }
  21891. function rec(path$$1) {
  21892. var node = path$$1.getValue();
  21893. if ((node.type === "CallExpression" || node.type === "OptionalCallExpression") && (isMemberish(node.callee) || node.callee.type === "CallExpression" || node.callee.type === "OptionalCallExpression")) {
  21894. printedNodes.unshift({
  21895. node: node,
  21896. printed: concat$4([comments.printComments(path$$1, function () {
  21897. return concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
  21898. }, options), shouldInsertEmptyLineAfter(node) ? hardline$3 : ""])
  21899. });
  21900. path$$1.call(function (callee) {
  21901. return rec(callee);
  21902. }, "callee");
  21903. } else if (isMemberish(node)) {
  21904. printedNodes.unshift({
  21905. node: node,
  21906. needsParens: needsParens_1(path$$1, options),
  21907. printed: comments.printComments(path$$1, function () {
  21908. return node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup(path$$1, options, print) : printBindExpressionCallee(path$$1, options, print);
  21909. }, options)
  21910. });
  21911. path$$1.call(function (object) {
  21912. return rec(object);
  21913. }, "object");
  21914. } else if (node.type === "TSNonNullExpression") {
  21915. printedNodes.unshift({
  21916. node: node,
  21917. printed: comments.printComments(path$$1, function () {
  21918. return "!";
  21919. }, options)
  21920. });
  21921. path$$1.call(function (expression) {
  21922. return rec(expression);
  21923. }, "expression");
  21924. } else {
  21925. printedNodes.unshift({
  21926. node: node,
  21927. printed: path$$1.call(print)
  21928. });
  21929. }
  21930. } // Note: the comments of the root node have already been printed, so we
  21931. // need to extract this first call without printing them as they would
  21932. // if handled inside of the recursive call.
  21933. var node = path$$1.getValue();
  21934. printedNodes.unshift({
  21935. node,
  21936. printed: concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)])
  21937. });
  21938. path$$1.call(function (callee) {
  21939. return rec(callee);
  21940. }, "callee"); // Once we have a linear list of printed nodes, we want to create groups out
  21941. // of it.
  21942. //
  21943. // a().b.c().d().e
  21944. // will be grouped as
  21945. // [
  21946. // [Identifier, CallExpression],
  21947. // [MemberExpression, MemberExpression, CallExpression],
  21948. // [MemberExpression, CallExpression],
  21949. // [MemberExpression],
  21950. // ]
  21951. // so that we can print it as
  21952. // a()
  21953. // .b.c()
  21954. // .d()
  21955. // .e
  21956. // The first group is the first node followed by
  21957. // - as many CallExpression as possible
  21958. // < fn()()() >.something()
  21959. // - as many array acessors as possible
  21960. // < fn()[0][1][2] >.something()
  21961. // - then, as many MemberExpression as possible but the last one
  21962. // < this.items >.something()
  21963. var groups = [];
  21964. var currentGroup = [printedNodes[0]];
  21965. var i = 1;
  21966. for (; i < printedNodes.length; ++i) {
  21967. 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)) {
  21968. currentGroup.push(printedNodes[i]);
  21969. } else {
  21970. break;
  21971. }
  21972. }
  21973. if (printedNodes[0].node.type !== "CallExpression" && printedNodes[0].node.type !== "OptionalCallExpression") {
  21974. for (; i + 1 < printedNodes.length; ++i) {
  21975. if (isMemberish(printedNodes[i].node) && isMemberish(printedNodes[i + 1].node)) {
  21976. currentGroup.push(printedNodes[i]);
  21977. } else {
  21978. break;
  21979. }
  21980. }
  21981. }
  21982. groups.push(currentGroup);
  21983. currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
  21984. // a sequence of CallExpression. To compute it, we keep adding things to the
  21985. // group until we has seen a CallExpression in the past and reach a
  21986. // MemberExpression
  21987. var hasSeenCallExpression = false;
  21988. for (; i < printedNodes.length; ++i) {
  21989. if (hasSeenCallExpression && isMemberish(printedNodes[i].node)) {
  21990. // [0] should be appended at the end of the group instead of the
  21991. // beginning of the next one
  21992. if (printedNodes[i].node.computed && isNumericLiteral(printedNodes[i].node.property)) {
  21993. currentGroup.push(printedNodes[i]);
  21994. continue;
  21995. }
  21996. groups.push(currentGroup);
  21997. currentGroup = [];
  21998. hasSeenCallExpression = false;
  21999. }
  22000. if (printedNodes[i].node.type === "CallExpression" || printedNodes[i].node.type === "OptionalCallExpression") {
  22001. hasSeenCallExpression = true;
  22002. }
  22003. currentGroup.push(printedNodes[i]);
  22004. if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(function (comment) {
  22005. return comment.trailing;
  22006. })) {
  22007. groups.push(currentGroup);
  22008. currentGroup = [];
  22009. hasSeenCallExpression = false;
  22010. }
  22011. }
  22012. if (currentGroup.length > 0) {
  22013. groups.push(currentGroup);
  22014. } // There are cases like Object.keys(), Observable.of(), _.values() where
  22015. // they are the subject of all the chained calls and therefore should
  22016. // be kept on the same line:
  22017. //
  22018. // Object.keys(items)
  22019. // .filter(x => x)
  22020. // .map(x => x)
  22021. //
  22022. // In order to detect those cases, we use an heuristic: if the first
  22023. // node is an identifier with the name starting with a capital
  22024. // letter or just a sequence of _$. The rationale is that they are
  22025. // likely to be factories.
  22026. function isFactory(name) {
  22027. return /^[A-Z]|^[_$]+$/.test(name);
  22028. } // In case the Identifier is shorter than tab width, we can keep the
  22029. // first call in a single line, if it's an ExpressionStatement.
  22030. //
  22031. // d3.scaleLinear()
  22032. // .domain([0, 100])
  22033. // .range([0, width]);
  22034. //
  22035. function isShort(name) {
  22036. return name.length <= options.tabWidth;
  22037. }
  22038. function shouldNotWrap(groups) {
  22039. var parent = path$$1.getParentNode();
  22040. var isExpression = parent && parent.type === "ExpressionStatement";
  22041. var hasComputed = groups[1].length && groups[1][0].node.computed;
  22042. if (groups[0].length === 1) {
  22043. var firstNode = groups[0][0].node;
  22044. return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpression && isShort(firstNode.name) || hasComputed);
  22045. }
  22046. var lastNode = getLast$4(groups[0]).node;
  22047. return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
  22048. }
  22049. var shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
  22050. function printGroup(printedGroup) {
  22051. var result = [];
  22052. for (var _i3 = 0; _i3 < printedGroup.length; _i3++) {
  22053. // Checks if the next node (i.e. the parent node) needs parens
  22054. // and print accordingly
  22055. if (printedGroup[_i3 + 1] && printedGroup[_i3 + 1].needsParens) {
  22056. result.push("(", printedGroup[_i3].printed, printedGroup[_i3 + 1].printed, ")");
  22057. _i3++;
  22058. } else {
  22059. result.push(printedGroup[_i3].printed);
  22060. }
  22061. }
  22062. return concat$4(result);
  22063. }
  22064. function printIndentedGroup(groups) {
  22065. if (groups.length === 0) {
  22066. return "";
  22067. }
  22068. return indent$2(group$1(concat$4([hardline$3, join$2(hardline$3, groups.map(printGroup))])));
  22069. }
  22070. var printedGroups = groups.map(printGroup);
  22071. var oneLine = concat$4(printedGroups);
  22072. var cutoff = shouldMerge ? 3 : 2;
  22073. var flatGroups = groups.slice(0, cutoff).reduce(function (res, group) {
  22074. return res.concat(group);
  22075. }, []);
  22076. var hasComment = flatGroups.slice(1, -1).some(function (node) {
  22077. return hasLeadingComment(node.node);
  22078. }) || flatGroups.slice(0, -1).some(function (node) {
  22079. return hasTrailingComment(node.node);
  22080. }) || groups[cutoff] && hasLeadingComment(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
  22081. // render everything concatenated together.
  22082. if (groups.length <= cutoff && !hasComment) {
  22083. return group$1(oneLine);
  22084. } // Find out the last node in the first group and check if it has an
  22085. // empty line after
  22086. var lastNodeBeforeIndent = getLast$4(shouldMerge ? groups.slice(1, 2)[0] : groups[0]).node;
  22087. var shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "CallExpression" && lastNodeBeforeIndent.type !== "OptionalCallExpression" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  22088. 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))]);
  22089. var callExpressions = printedNodes.map(function (_ref) {
  22090. var node = _ref.node;
  22091. return node;
  22092. }).filter(isCallOrOptionalCallExpression); // We don't want to print in one line if there's:
  22093. // * A comment.
  22094. // * 3 or more chained calls.
  22095. // * Any group but the last one has a hard line.
  22096. // If the last group is a function it's okay to inline if it fits.
  22097. if (hasComment || callExpressions.length >= 3 || printedGroups.slice(0, -1).some(willBreak$1) ||
  22098. /**
  22099. * scopes.filter(scope => scope.value !== '').map((scope, i) => {
  22100. * // multi line content
  22101. * })
  22102. */
  22103. function (lastGroupDoc, lastGroupNode) {
  22104. return isCallOrOptionalCallExpression(lastGroupNode) && willBreak$1(lastGroupDoc);
  22105. }(getLast$4(printedGroups), getLast$4(getLast$4(groups)).node) && callExpressions.slice(0, -1).some(function (n) {
  22106. return n.arguments.some(isFunctionOrArrowExpression);
  22107. })) {
  22108. return group$1(expanded);
  22109. }
  22110. return concat$4([// We only need to check `oneLine` because if `expanded` is chosen
  22111. // that means that the parent group has already been broken
  22112. // naturally
  22113. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$2 : "", conditionalGroup$1([oneLine, expanded])]);
  22114. }
  22115. function isCallOrOptionalCallExpression(node) {
  22116. return node.type === "CallExpression" || node.type === "OptionalCallExpression";
  22117. }
  22118. function isJSXNode(node) {
  22119. return node.type === "JSXElement" || node.type === "JSXFragment";
  22120. }
  22121. function isEmptyJSXElement(node) {
  22122. if (node.children.length === 0) {
  22123. return true;
  22124. }
  22125. if (node.children.length > 1) {
  22126. return false;
  22127. } // if there is one text child and does not contain any meaningful text
  22128. // we can treat the element as empty.
  22129. var child = node.children[0];
  22130. return isLiteral(child) && !isMeaningfulJSXText(child);
  22131. } // Only space, newline, carriage return, and tab are treated as whitespace
  22132. // inside JSX.
  22133. var jsxWhitespaceChars = " \n\r\t";
  22134. var containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]");
  22135. var matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)"); // Meaningful if it contains non-whitespace characters,
  22136. // or it contains whitespace without a new line.
  22137. function isMeaningfulJSXText(node) {
  22138. return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
  22139. }
  22140. function conditionalExpressionChainContainsJSX(node) {
  22141. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  22142. } // If we have nested conditional expressions, we want to print them in JSX mode
  22143. // if there's at least one JSXElement somewhere in the tree.
  22144. //
  22145. // A conditional expression chain like this should be printed in normal mode,
  22146. // because there aren't JSXElements anywhere in it:
  22147. //
  22148. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  22149. //
  22150. // But a conditional expression chain like this should be printed in JSX mode,
  22151. // because there is a JSXElement in the last ConditionalExpression:
  22152. //
  22153. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  22154. //
  22155. // This type of ConditionalExpression chain is structured like this in the AST:
  22156. //
  22157. // ConditionalExpression {
  22158. // test: ...,
  22159. // consequent: ...,
  22160. // alternate: ConditionalExpression {
  22161. // test: ...,
  22162. // consequent: ...,
  22163. // alternate: ConditionalExpression {
  22164. // test: ...,
  22165. // consequent: ...,
  22166. // alternate: ...,
  22167. // }
  22168. // }
  22169. // }
  22170. //
  22171. // We want to traverse over that shape and convert it into a flat structure so
  22172. // that we can find if there's a JSXElement somewhere inside.
  22173. function getConditionalChainContents(node) {
  22174. // Given this code:
  22175. //
  22176. // // Using a ConditionalExpression as the consequent is uncommon, but should
  22177. // // be handled.
  22178. // A ? B : C ? D : E ? F ? G : H : I
  22179. //
  22180. // which has this AST:
  22181. //
  22182. // ConditionalExpression {
  22183. // test: Identifier(A),
  22184. // consequent: Identifier(B),
  22185. // alternate: ConditionalExpression {
  22186. // test: Identifier(C),
  22187. // consequent: Identifier(D),
  22188. // alternate: ConditionalExpression {
  22189. // test: Identifier(E),
  22190. // consequent: ConditionalExpression {
  22191. // test: Identifier(F),
  22192. // consequent: Identifier(G),
  22193. // alternate: Identifier(H),
  22194. // },
  22195. // alternate: Identifier(I),
  22196. // }
  22197. // }
  22198. // }
  22199. //
  22200. // we should return this Array:
  22201. //
  22202. // [
  22203. // Identifier(A),
  22204. // Identifier(B),
  22205. // Identifier(C),
  22206. // Identifier(D),
  22207. // Identifier(E),
  22208. // Identifier(F),
  22209. // Identifier(G),
  22210. // Identifier(H),
  22211. // Identifier(I)
  22212. // ];
  22213. //
  22214. // This loses the information about whether each node was the test,
  22215. // consequent, or alternate, but we don't care about that here- we are only
  22216. // flattening this structure to find if there's any JSXElements inside.
  22217. var nonConditionalExpressions = [];
  22218. function recurse(node) {
  22219. if (node.type === "ConditionalExpression") {
  22220. recurse(node.test);
  22221. recurse(node.consequent);
  22222. recurse(node.alternate);
  22223. } else {
  22224. nonConditionalExpressions.push(node);
  22225. }
  22226. }
  22227. recurse(node);
  22228. return nonConditionalExpressions;
  22229. } // Detect an expression node representing `{" "}`
  22230. function isJSXWhitespaceExpression(node) {
  22231. return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
  22232. }
  22233. function separatorNoWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  22234. if (isFacebookTranslationTag) {
  22235. return "";
  22236. }
  22237. if (childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement) {
  22238. return child.length === 1 ? softline$1 : hardline$3;
  22239. }
  22240. return softline$1;
  22241. }
  22242. function separatorWithWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  22243. if (isFacebookTranslationTag) {
  22244. return hardline$3;
  22245. }
  22246. if (child.length === 1) {
  22247. return childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement ? hardline$3 : softline$1;
  22248. }
  22249. return hardline$3;
  22250. } // JSX Children are strange, mostly for two reasons:
  22251. // 1. JSX reads newlines into string values, instead of skipping them like JS
  22252. // 2. up to one whitespace between elements within a line is significant,
  22253. // but not between lines.
  22254. //
  22255. // Leading, trailing, and lone whitespace all need to
  22256. // turn themselves into the rather ugly `{' '}` when breaking.
  22257. //
  22258. // We print JSX using the `fill` doc primitive.
  22259. // This requires that we give it an array of alternating
  22260. // content and whitespace elements.
  22261. // To ensure this we add dummy `""` content elements as needed.
  22262. function printJSXChildren(path$$1, options, print, jsxWhitespace, isFacebookTranslationTag) {
  22263. var n = path$$1.getValue();
  22264. var children = []; // using `map` instead of `each` because it provides `i`
  22265. path$$1.map(function (childPath, i) {
  22266. var child = childPath.getValue();
  22267. if (isLiteral(child)) {
  22268. var text = rawText(child); // Contains a non-whitespace character
  22269. if (isMeaningfulJSXText(child)) {
  22270. var words = text.split(matchJsxWhitespaceRegex); // Starts with whitespace
  22271. if (words[0] === "") {
  22272. children.push("");
  22273. words.shift();
  22274. if (/\n/.test(words[0])) {
  22275. var next = n.children[i + 1];
  22276. children.push(separatorWithWhitespace(isFacebookTranslationTag, words[1], child, next));
  22277. } else {
  22278. children.push(jsxWhitespace);
  22279. }
  22280. words.shift();
  22281. }
  22282. var endWhitespace; // Ends with whitespace
  22283. if (getLast$4(words) === "") {
  22284. words.pop();
  22285. endWhitespace = words.pop();
  22286. } // This was whitespace only without a new line.
  22287. if (words.length === 0) {
  22288. return;
  22289. }
  22290. words.forEach(function (word, i) {
  22291. if (i % 2 === 1) {
  22292. children.push(line$3);
  22293. } else {
  22294. children.push(word);
  22295. }
  22296. });
  22297. if (endWhitespace !== undefined) {
  22298. if (/\n/.test(endWhitespace)) {
  22299. var _next = n.children[i + 1];
  22300. children.push(separatorWithWhitespace(isFacebookTranslationTag, getLast$4(children), child, _next));
  22301. } else {
  22302. children.push(jsxWhitespace);
  22303. }
  22304. } else {
  22305. var _next2 = n.children[i + 1];
  22306. children.push(separatorNoWhitespace(isFacebookTranslationTag, getLast$4(children), child, _next2));
  22307. }
  22308. } else if (/\n/.test(text)) {
  22309. // Keep (up to one) blank line between tags/expressions/text.
  22310. // Note: We don't keep blank lines between text elements.
  22311. if (text.match(/\n/g).length > 1) {
  22312. children.push("");
  22313. children.push(hardline$3);
  22314. }
  22315. } else {
  22316. children.push("");
  22317. children.push(jsxWhitespace);
  22318. }
  22319. } else {
  22320. var printedChild = print(childPath);
  22321. children.push(printedChild);
  22322. var _next3 = n.children[i + 1];
  22323. var directlyFollowedByMeaningfulText = _next3 && isMeaningfulJSXText(_next3);
  22324. if (directlyFollowedByMeaningfulText) {
  22325. var firstWord = rawText(_next3).trim().split(matchJsxWhitespaceRegex)[0];
  22326. children.push(separatorNoWhitespace(isFacebookTranslationTag, firstWord, child, _next3));
  22327. } else {
  22328. children.push(hardline$3);
  22329. }
  22330. }
  22331. }, "children");
  22332. return children;
  22333. } // JSX expands children from the inside-out, instead of the outside-in.
  22334. // This is both to break children before attributes,
  22335. // and to ensure that when children break, their parents do as well.
  22336. //
  22337. // Any element that is written without any newlines and fits on a single line
  22338. // is left that way.
  22339. // Not only that, any user-written-line containing multiple JSX siblings
  22340. // should also be kept on one line if possible,
  22341. // so each user-written-line is wrapped in its own group.
  22342. //
  22343. // Elements that contain newlines or don't fit on a single line (recursively)
  22344. // are fully-split, using hardline and shouldBreak: true.
  22345. //
  22346. // To support that case properly, all leading and trailing spaces
  22347. // are stripped from the list of children, and replaced with a single hardline.
  22348. function printJSXElement(path$$1, options, print) {
  22349. var n = path$$1.getValue(); // Turn <div></div> into <div />
  22350. if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
  22351. n.openingElement.selfClosing = true;
  22352. return path$$1.call(print, "openingElement");
  22353. }
  22354. var openingLines = n.type === "JSXElement" ? path$$1.call(print, "openingElement") : path$$1.call(print, "openingFragment");
  22355. var closingLines = n.type === "JSXElement" ? path$$1.call(print, "closingElement") : path$$1.call(print, "closingFragment");
  22356. if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
  22357. return concat$4([openingLines, concat$4(path$$1.map(print, "children")), closingLines]);
  22358. } // Convert `{" "}` to text nodes containing a space.
  22359. // This makes it easy to turn them into `jsxWhitespace` which
  22360. // can then print as either a space or `{" "}` when breaking.
  22361. n.children = n.children.map(function (child) {
  22362. if (isJSXWhitespaceExpression(child)) {
  22363. return {
  22364. type: "JSXText",
  22365. value: " ",
  22366. raw: " "
  22367. };
  22368. }
  22369. return child;
  22370. });
  22371. var containsTag = n.children.filter(isJSXNode).length > 0;
  22372. var containsMultipleExpressions = n.children.filter(function (child) {
  22373. return child.type === "JSXExpressionContainer";
  22374. }).length > 1;
  22375. var containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
  22376. var forcedBreak = willBreak$1(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
  22377. var rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  22378. var jsxWhitespace = ifBreak$1(concat$4([rawJsxWhitespace, softline$1]), " ");
  22379. var isFacebookTranslationTag = n.openingElement && n.openingElement.name && n.openingElement.name.name === "fbt";
  22380. var children = printJSXChildren(path$$1, options, print, jsxWhitespace, isFacebookTranslationTag);
  22381. var containsText = n.children.filter(function (child) {
  22382. return isMeaningfulJSXText(child);
  22383. }).length > 0; // We can end up we multiple whitespace elements with empty string
  22384. // content between them.
  22385. // We need to remove empty whitespace and softlines before JSX whitespace
  22386. // to get the correct output.
  22387. for (var i = children.length - 2; i >= 0; i--) {
  22388. var isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  22389. var isPairOfHardlines = children[i] === hardline$3 && children[i + 1] === "" && children[i + 2] === hardline$3;
  22390. var isLineFollowedByJSXWhitespace = (children[i] === softline$1 || children[i] === hardline$3) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  22391. var isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$1 || children[i + 2] === hardline$3);
  22392. var isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  22393. 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;
  22394. if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace || isPairOfHardOrSoftLines) {
  22395. children.splice(i, 2);
  22396. } else if (isJSXWhitespaceFollowedByLine) {
  22397. children.splice(i + 1, 2);
  22398. }
  22399. } // Trim trailing lines (or empty strings)
  22400. while (children.length && (isLineNext$1(getLast$4(children)) || isEmpty$1(getLast$4(children)))) {
  22401. children.pop();
  22402. } // Trim leading lines (or empty strings)
  22403. while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
  22404. children.shift();
  22405. children.shift();
  22406. } // Tweak how we format children if outputting this element over multiple lines.
  22407. // Also detect whether we will force this element to output over multiple lines.
  22408. var multilineChildren = [];
  22409. children.forEach(function (child, i) {
  22410. // There are a number of situations where we need to ensure we display
  22411. // whitespace as `{" "}` when outputting this element over multiple lines.
  22412. if (child === jsxWhitespace) {
  22413. if (i === 1 && children[i - 1] === "") {
  22414. if (children.length === 2) {
  22415. // Solitary whitespace
  22416. multilineChildren.push(rawJsxWhitespace);
  22417. return;
  22418. } // Leading whitespace
  22419. multilineChildren.push(concat$4([rawJsxWhitespace, hardline$3]));
  22420. return;
  22421. } else if (i === children.length - 1) {
  22422. // Trailing whitespace
  22423. multilineChildren.push(rawJsxWhitespace);
  22424. return;
  22425. } else if (children[i - 1] === "" && children[i - 2] === hardline$3) {
  22426. // Whitespace after line break
  22427. multilineChildren.push(rawJsxWhitespace);
  22428. return;
  22429. }
  22430. }
  22431. multilineChildren.push(child);
  22432. if (willBreak$1(child)) {
  22433. forcedBreak = true;
  22434. }
  22435. }); // If there is text we use `fill` to fit as much onto each line as possible.
  22436. // When there is no text (just tags and expressions) we use `group`
  22437. // to output each on a separate line.
  22438. var content = containsText ? fill$2(multilineChildren) : group$1(concat$4(multilineChildren), {
  22439. shouldBreak: true
  22440. });
  22441. var multiLineElem = group$1(concat$4([openingLines, indent$2(concat$4([hardline$3, content])), hardline$3, closingLines]));
  22442. if (forcedBreak) {
  22443. return multiLineElem;
  22444. }
  22445. return conditionalGroup$1([group$1(concat$4([openingLines, concat$4(children), closingLines])), multiLineElem]);
  22446. }
  22447. function maybeWrapJSXElementInParens(path$$1, elem) {
  22448. var parent = path$$1.getParentNode();
  22449. if (!parent) {
  22450. return elem;
  22451. }
  22452. var NO_WRAP_PARENTS = {
  22453. ArrayExpression: true,
  22454. JSXAttribute: true,
  22455. JSXElement: true,
  22456. JSXExpressionContainer: true,
  22457. JSXFragment: true,
  22458. ExpressionStatement: true,
  22459. CallExpression: true,
  22460. OptionalCallExpression: true,
  22461. ConditionalExpression: true,
  22462. JsExpressionRoot: true
  22463. };
  22464. if (NO_WRAP_PARENTS[parent.type]) {
  22465. return elem;
  22466. }
  22467. var shouldBreak = matchAncestorTypes$1(path$$1, ["ArrowFunctionExpression", "CallExpression", "JSXExpressionContainer"]);
  22468. return group$1(concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, elem])), softline$1, ifBreak$1(")")]), {
  22469. shouldBreak
  22470. });
  22471. }
  22472. function isBinaryish(node) {
  22473. return node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression";
  22474. }
  22475. function isMemberish(node) {
  22476. return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && node.object;
  22477. }
  22478. function shouldInlineLogicalExpression(node) {
  22479. if (node.type !== "LogicalExpression") {
  22480. return false;
  22481. }
  22482. if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
  22483. return true;
  22484. }
  22485. if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
  22486. return true;
  22487. }
  22488. if (isJSXNode(node.right)) {
  22489. return true;
  22490. }
  22491. return false;
  22492. } // For binary expressions to be consistent, we need to group
  22493. // subsequent operators with the same precedence level under a single
  22494. // group. Otherwise they will be nested such that some of them break
  22495. // onto new lines but not all. Operators with the same precedence
  22496. // level should either all break or not. Because we group them by
  22497. // precedence level and the AST is structured based on precedence
  22498. // level, things are naturally broken up correctly, i.e. `&&` is
  22499. // broken before `+`.
  22500. function printBinaryishExpressions(path$$1, print, options, isNested, isInsideParenthesis) {
  22501. var parts = [];
  22502. var node = path$$1.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
  22503. if (isBinaryish(node)) {
  22504. // Put all operators with the same precedence level in the same
  22505. // group. The reason we only need to do this with the `left`
  22506. // expression is because given an expression like `1 + 2 - 3`, it
  22507. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  22508. // is where the rest of the expression will exist. Binary
  22509. // expressions on the right side mean they have a difference
  22510. // precedence level and should be treated as a separate group, so
  22511. // print them normally. (This doesn't hold for the `**` operator,
  22512. // which is unique in that it is right-associative.)
  22513. if (shouldFlatten$1(node.operator, node.left.operator)) {
  22514. // Flatten them out by recursively calling this function.
  22515. parts = parts.concat(path$$1.call(function (left) {
  22516. return printBinaryishExpressions(left, print, options,
  22517. /* isNested */
  22518. true, isInsideParenthesis);
  22519. }, "left"));
  22520. } else {
  22521. parts.push(path$$1.call(print, "left"));
  22522. }
  22523. var shouldInline = shouldInlineLogicalExpression(node);
  22524. var lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment(options.originalText, node.right, options);
  22525. var operator = node.type === "NGPipeExpression" ? "|" : node.operator;
  22526. 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) {
  22527. return align$1(2, group$1(arg));
  22528. }))]))) : "";
  22529. 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
  22530. // in order to avoid having a small right part like -1 be on its own line.
  22531. var parent = path$$1.getParentNode();
  22532. var shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
  22533. parts.push(" ", shouldGroup ? group$1(right) : right); // The root comments are already printed, but we need to manually print
  22534. // the other ones since we don't call the normal print on BinaryExpression,
  22535. // only for the left and right parts
  22536. if (isNested && node.comments) {
  22537. parts = comments.printComments(path$$1, function () {
  22538. return concat$4(parts);
  22539. }, options);
  22540. }
  22541. } else {
  22542. // Our stopping case. Simply print the node normally.
  22543. parts.push(path$$1.call(print));
  22544. }
  22545. return parts;
  22546. }
  22547. function printAssignmentRight(leftNode, rightNode, printedRight, options) {
  22548. if (hasLeadingOwnLineComment(options.originalText, rightNode, options)) {
  22549. return indent$2(concat$4([hardline$3, printedRight]));
  22550. }
  22551. 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
  22552. options.parser !== "json" && options.parser !== "json5";
  22553. if (canBreak) {
  22554. return group$1(indent$2(concat$4([line$3, printedRight])));
  22555. }
  22556. return concat$4([" ", printedRight]);
  22557. }
  22558. function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
  22559. if (!rightNode) {
  22560. return printedLeft;
  22561. }
  22562. var printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
  22563. return group$1(concat$4([printedLeft, operator, printed]));
  22564. }
  22565. function adjustClause(node, clause, forceSpace) {
  22566. if (node.type === "EmptyStatement") {
  22567. return ";";
  22568. }
  22569. if (node.type === "BlockStatement" || forceSpace) {
  22570. return concat$4([" ", clause]);
  22571. }
  22572. return indent$2(concat$4([line$3, clause]));
  22573. }
  22574. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  22575. var raw = rawText(node);
  22576. var isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  22577. return printString$1(raw, options, isDirectiveLiteral);
  22578. }
  22579. function printRegex(node) {
  22580. var flags = node.flags.split("").sort().join("");
  22581. return `/${node.pattern}/${flags}`;
  22582. }
  22583. function isLastStatement(path$$1) {
  22584. var parent = path$$1.getParentNode();
  22585. if (!parent) {
  22586. return true;
  22587. }
  22588. var node = path$$1.getValue();
  22589. var body = (parent.body || parent.consequent).filter(function (stmt) {
  22590. return stmt.type !== "EmptyStatement";
  22591. });
  22592. return body && body[body.length - 1] === node;
  22593. }
  22594. function hasLeadingComment(node) {
  22595. return node.comments && node.comments.some(function (comment) {
  22596. return comment.leading;
  22597. });
  22598. }
  22599. function hasTrailingComment(node) {
  22600. return node.comments && node.comments.some(function (comment) {
  22601. return comment.trailing;
  22602. });
  22603. }
  22604. function hasLeadingOwnLineComment(text, node, options) {
  22605. if (isJSXNode(node)) {
  22606. return hasNodeIgnoreComment$1(node);
  22607. }
  22608. var res = node.comments && node.comments.some(function (comment) {
  22609. return comment.leading && hasNewline$2(text, options.locEnd(comment));
  22610. });
  22611. return res;
  22612. }
  22613. function hasNakedLeftSide(node) {
  22614. 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 === "TSNonNullExpression";
  22615. }
  22616. function isFlowAnnotationComment(text, typeAnnotation, options) {
  22617. var start = options.locStart(typeAnnotation);
  22618. var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
  22619. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  22620. }
  22621. function getLeftSide(node) {
  22622. if (node.expressions) {
  22623. return node.expressions[0];
  22624. }
  22625. return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
  22626. }
  22627. function getLeftSidePathName(path$$1, node) {
  22628. if (node.expressions) {
  22629. return ["expressions", 0];
  22630. }
  22631. if (node.left) {
  22632. return ["left"];
  22633. }
  22634. if (node.test) {
  22635. return ["test"];
  22636. }
  22637. if (node.object) {
  22638. return ["object"];
  22639. }
  22640. if (node.callee) {
  22641. return ["callee"];
  22642. }
  22643. if (node.tag) {
  22644. return ["tag"];
  22645. }
  22646. if (node.argument) {
  22647. return ["argument"];
  22648. }
  22649. if (node.expression) {
  22650. return ["expression"];
  22651. }
  22652. throw new Error("Unexpected node has no left side", node);
  22653. }
  22654. function exprNeedsASIProtection(path$$1, options) {
  22655. var node = path$$1.getValue();
  22656. 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;
  22657. if (maybeASIProblem) {
  22658. return true;
  22659. }
  22660. if (!hasNakedLeftSide(node)) {
  22661. return false;
  22662. }
  22663. return path$$1.call.apply(path$$1, [function (childPath) {
  22664. return exprNeedsASIProtection(childPath, options);
  22665. }].concat(getLeftSidePathName(path$$1, node)));
  22666. }
  22667. function stmtNeedsASIProtection(path$$1, options) {
  22668. var node = path$$1.getNode();
  22669. if (node.type !== "ExpressionStatement") {
  22670. return false;
  22671. }
  22672. return path$$1.call(function (childPath) {
  22673. return exprNeedsASIProtection(childPath, options);
  22674. }, "expression");
  22675. }
  22676. function classPropMayCauseASIProblems(path$$1) {
  22677. var node = path$$1.getNode();
  22678. if (node.type !== "ClassProperty") {
  22679. return false;
  22680. }
  22681. var name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
  22682. // so isn't properly tested yet.
  22683. if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
  22684. return true;
  22685. }
  22686. }
  22687. function classChildNeedsASIProtection(node) {
  22688. if (!node) {
  22689. return;
  22690. }
  22691. if (node.static || node.accessibility // TypeScript
  22692. ) {
  22693. return false;
  22694. }
  22695. if (!node.computed) {
  22696. var name = node.key && node.key.name;
  22697. if (name === "in" || name === "instanceof") {
  22698. return true;
  22699. }
  22700. }
  22701. switch (node.type) {
  22702. case "ClassProperty":
  22703. case "TSAbstractClassProperty":
  22704. return node.computed;
  22705. case "MethodDefinition": // Flow
  22706. case "TSAbstractMethodDefinition": // TypeScript
  22707. case "ClassMethod":
  22708. case "ClassPrivateMethod":
  22709. {
  22710. // Babel
  22711. var isAsync = node.value ? node.value.async : node.async;
  22712. var isGenerator = node.value ? node.value.generator : node.generator;
  22713. if (isAsync || node.kind === "get" || node.kind === "set") {
  22714. return false;
  22715. }
  22716. if (node.computed || isGenerator) {
  22717. return true;
  22718. }
  22719. return false;
  22720. }
  22721. default:
  22722. /* istanbul ignore next */
  22723. return false;
  22724. }
  22725. } // This recurses the return argument, looking for the first token
  22726. // (the leftmost leaf node) and, if it (or its parents) has any
  22727. // leadingComments, returns true (so it can be wrapped in parens).
  22728. function returnArgumentHasLeadingComment(options, argument) {
  22729. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  22730. return true;
  22731. }
  22732. if (hasNakedLeftSide(argument)) {
  22733. var leftMost = argument;
  22734. var newLeftMost;
  22735. while (newLeftMost = getLeftSide(leftMost)) {
  22736. leftMost = newLeftMost;
  22737. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  22738. return true;
  22739. }
  22740. }
  22741. }
  22742. return false;
  22743. }
  22744. function isMemberExpressionChain(node) {
  22745. if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
  22746. return false;
  22747. }
  22748. if (node.object.type === "Identifier") {
  22749. return true;
  22750. }
  22751. return isMemberExpressionChain(node.object);
  22752. } // Hack to differentiate between the following two which have the same ast
  22753. // type T = { method: () => void };
  22754. // type T = { method(): void };
  22755. function isObjectTypePropertyAFunction(node, options) {
  22756. return (node.type === "ObjectTypeProperty" || node.type === "ObjectTypeInternalSlot") && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
  22757. } // TODO: This is a bad hack and we need a better way to distinguish between
  22758. // arrow functions and otherwise
  22759. function isFunctionNotation(node, options) {
  22760. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  22761. }
  22762. function isGetterOrSetter(node) {
  22763. return node.kind === "get" || node.kind === "set";
  22764. }
  22765. function sameLocStart(nodeA, nodeB, options) {
  22766. return options.locStart(nodeA) === options.locStart(nodeB);
  22767. } // Hack to differentiate between the following two which have the same ast
  22768. // declare function f(a): void;
  22769. // var f: (a) => void;
  22770. function isTypeAnnotationAFunction(node, options) {
  22771. return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
  22772. }
  22773. function isNodeStartingWithDeclare(node, options) {
  22774. if (!(options.parser === "flow" || options.parser === "typescript")) {
  22775. return false;
  22776. }
  22777. return options.originalText.slice(0, options.locStart(node)).match(/declare[ \t]*$/) || options.originalText.slice(node.range[0], node.range[1]).startsWith("declare ");
  22778. }
  22779. function shouldHugType(node) {
  22780. if (isSimpleFlowType(node) || isObjectType(node)) {
  22781. return true;
  22782. }
  22783. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  22784. var voidCount = node.types.filter(function (n) {
  22785. return n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword";
  22786. }).length;
  22787. var objectCount = node.types.filter(function (n) {
  22788. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
  22789. n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference";
  22790. }).length;
  22791. if (node.types.length - 1 === voidCount && objectCount > 0) {
  22792. return true;
  22793. }
  22794. }
  22795. return false;
  22796. }
  22797. function shouldHugArguments(fun) {
  22798. 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;
  22799. }
  22800. function templateLiteralHasNewLines(template) {
  22801. return template.quasis.some(function (quasi) {
  22802. return quasi.value.raw.includes("\n");
  22803. });
  22804. }
  22805. function isTemplateOnItsOwnLine(n, text, options) {
  22806. return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$2(text, options.locStart(n), {
  22807. backwards: true
  22808. });
  22809. }
  22810. function printArrayItems(path$$1, options, printPath, print) {
  22811. var printedElements = [];
  22812. var separatorParts = [];
  22813. path$$1.each(function (childPath) {
  22814. printedElements.push(concat$4(separatorParts));
  22815. printedElements.push(group$1(print(childPath)));
  22816. separatorParts = [",", line$3];
  22817. if (childPath.getValue() && isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  22818. separatorParts.push(softline$1);
  22819. }
  22820. }, printPath);
  22821. return concat$4(printedElements);
  22822. }
  22823. function hasDanglingComments(node) {
  22824. return node.comments && node.comments.some(function (comment) {
  22825. return !comment.leading && !comment.trailing;
  22826. });
  22827. }
  22828. function needsHardlineAfterDanglingComment(node) {
  22829. if (!node.comments) {
  22830. return false;
  22831. }
  22832. var lastDanglingComment = getLast$4(node.comments.filter(function (comment) {
  22833. return !comment.leading && !comment.trailing;
  22834. }));
  22835. return lastDanglingComment && !comments$3.isBlockComment(lastDanglingComment);
  22836. }
  22837. function isLiteral(node) {
  22838. 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";
  22839. }
  22840. function isNumericLiteral(node) {
  22841. return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
  22842. }
  22843. function isStringLiteral(node) {
  22844. return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
  22845. }
  22846. function isObjectType(n) {
  22847. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  22848. }
  22849. var unitTestRe = /^(skip|[fx]?(it|describe|test))$/; // eg; `describe("some string", (done) => {})`
  22850. function isTestCall(n, parent) {
  22851. if (n.type !== "CallExpression") {
  22852. return false;
  22853. }
  22854. if (n.arguments.length === 1) {
  22855. if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
  22856. return isFunctionOrArrowExpression(n.arguments[0]);
  22857. }
  22858. if (isUnitTestSetUp(n)) {
  22859. return isAngularTestWrapper(n.arguments[0]);
  22860. }
  22861. } else if (n.arguments.length === 2 || n.arguments.length === 3) {
  22862. if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
  22863. // it("name", () => { ... }, 2500)
  22864. if (n.arguments[2] && !isNumericLiteral(n.arguments[2])) {
  22865. return false;
  22866. }
  22867. return (n.arguments.length === 2 ? isFunctionOrArrowExpression(n.arguments[1]) : isFunctionOrArrowExpressionWithBody(n.arguments[1]) && n.arguments[1].params.length <= 1) || isAngularTestWrapper(n.arguments[1]);
  22868. }
  22869. }
  22870. return false;
  22871. }
  22872. function isSkipOrOnlyBlock(node) {
  22873. 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");
  22874. }
  22875. function isTemplateLiteral(node) {
  22876. return node.type === "TemplateLiteral";
  22877. } // `inject` is used in AngularJS 1.x, `async` in Angular 2+
  22878. // example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
  22879. function isAngularTestWrapper(node) {
  22880. return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject" || node.callee.name === "fakeAsync");
  22881. }
  22882. function isFunctionOrArrowExpression(node) {
  22883. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
  22884. }
  22885. function isFunctionOrArrowExpressionWithBody(node) {
  22886. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement";
  22887. }
  22888. function isUnitTestSetUp(n) {
  22889. var unitTestSetUpRe = /^(before|after)(Each|All)$/;
  22890. return n.callee.type === "Identifier" && unitTestSetUpRe.test(n.callee.name) && n.arguments.length === 1;
  22891. }
  22892. function isTheOnlyJSXElementInMarkdown(options, path$$1) {
  22893. if (options.parentParser !== "markdown" && options.parentParser !== "mdx") {
  22894. return false;
  22895. }
  22896. var node = path$$1.getNode();
  22897. if (!node.expression || !isJSXNode(node.expression)) {
  22898. return false;
  22899. }
  22900. var parent = path$$1.getParentNode();
  22901. return parent.type === "Program" && parent.body.length == 1;
  22902. }
  22903. function willPrintOwnComments(path$$1) {
  22904. var node = path$$1.getValue();
  22905. var parent = path$$1.getParentNode();
  22906. 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);
  22907. }
  22908. function canAttachComment(node) {
  22909. return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import" && !(node.callee && node.callee.type === "Import");
  22910. }
  22911. function printComment$1(commentPath, options) {
  22912. var comment = commentPath.getValue();
  22913. switch (comment.type) {
  22914. case "CommentBlock":
  22915. case "Block":
  22916. {
  22917. if (isIndentableBlockComment(comment)) {
  22918. var printed = printIndentableBlockComment(comment); // We need to prevent an edge case of a previous trailing comment
  22919. // printed as a `lineSuffix` which causes the comments to be
  22920. // interleaved. See https://github.com/prettier/prettier/issues/4412
  22921. if (comment.trailing && !hasNewline$2(options.originalText, options.locStart(comment), {
  22922. backwards: true
  22923. })) {
  22924. return concat$4([hardline$3, printed]);
  22925. }
  22926. return printed;
  22927. }
  22928. var isInsideFlowComment = options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  22929. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  22930. }
  22931. case "CommentLine":
  22932. case "Line":
  22933. // Print shebangs with the proper comment characters
  22934. if (options.originalText.slice(options.locStart(comment)).startsWith("#!")) {
  22935. return "#!" + comment.value.trimRight();
  22936. }
  22937. return "//" + comment.value.trimRight();
  22938. default:
  22939. throw new Error("Not a comment: " + JSON.stringify(comment));
  22940. }
  22941. }
  22942. function isIndentableBlockComment(comment) {
  22943. // If the comment has multiple lines and every line starts with a star
  22944. // we can fix the indentation of each line. The stars in the `/*` and
  22945. // `*/` delimiters are not included in the comment value, so add them
  22946. // back first.
  22947. var lines = `*${comment.value}*`.split("\n");
  22948. return lines.length > 1 && lines.every(function (line) {
  22949. return line.trim()[0] === "*";
  22950. });
  22951. }
  22952. function printIndentableBlockComment(comment) {
  22953. var lines = comment.value.split("\n");
  22954. return concat$4(["/*", join$2(hardline$3, lines.map(function (line, index) {
  22955. return index === 0 ? line.trimRight() : " " + (index < lines.length - 1 ? line.trim() : line.trimLeft());
  22956. })), "*/"]);
  22957. }
  22958. function rawText(node) {
  22959. return node.extra ? node.extra.raw : node.raw;
  22960. }
  22961. function identity$1(x) {
  22962. return x;
  22963. }
  22964. var printerEstree = {
  22965. preprocess: preprocess_1,
  22966. print: genericPrint,
  22967. embed: embed_1,
  22968. insertPragma,
  22969. massageAstNode: clean_1,
  22970. hasPrettierIgnore,
  22971. willPrintOwnComments,
  22972. canAttachComment,
  22973. printComment: printComment$1,
  22974. isBlockComment: comments$3.isBlockComment,
  22975. handleComments: {
  22976. ownLine: comments$3.handleOwnLineComment,
  22977. endOfLine: comments$3.handleEndOfLineComment,
  22978. remaining: comments$3.handleRemainingComment
  22979. }
  22980. };
  22981. var _require$$0$builders$2 = doc.builders;
  22982. var concat$7 = _require$$0$builders$2.concat;
  22983. var hardline$5 = _require$$0$builders$2.hardline;
  22984. var indent$4 = _require$$0$builders$2.indent;
  22985. var join$5 = _require$$0$builders$2.join;
  22986. function genericPrint$1(path$$1, options, print) {
  22987. var node = path$$1.getValue();
  22988. switch (node.type) {
  22989. case "JsonRoot":
  22990. return concat$7([path$$1.call(print, "node"), hardline$5]);
  22991. case "ArrayExpression":
  22992. 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, "]"]);
  22993. case "ObjectExpression":
  22994. 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, "}"]);
  22995. case "ObjectProperty":
  22996. return concat$7([path$$1.call(print, "key"), ": ", path$$1.call(print, "value")]);
  22997. case "UnaryExpression":
  22998. return concat$7([node.operator === "+" ? "" : node.operator, path$$1.call(print, "argument")]);
  22999. case "NullLiteral":
  23000. return "null";
  23001. case "BooleanLiteral":
  23002. return node.value ? "true" : "false";
  23003. case "StringLiteral":
  23004. case "NumericLiteral":
  23005. return JSON.stringify(node.value);
  23006. case "Identifier":
  23007. return JSON.stringify(node.name);
  23008. default:
  23009. /* istanbul ignore next */
  23010. throw new Error("unknown type: " + JSON.stringify(node.type));
  23011. }
  23012. }
  23013. function clean$2(node, newNode
  23014. /*, parent*/
  23015. ) {
  23016. delete newNode.start;
  23017. delete newNode.end;
  23018. delete newNode.extra;
  23019. delete newNode.loc;
  23020. delete newNode.comments;
  23021. if (node.type === "Identifier") {
  23022. return {
  23023. type: "StringLiteral",
  23024. value: node.name
  23025. };
  23026. }
  23027. if (node.type === "UnaryExpression" && node.operator === "+") {
  23028. return newNode.argument;
  23029. }
  23030. }
  23031. var printerEstreeJson = {
  23032. preprocess: preprocess_1,
  23033. print: genericPrint$1,
  23034. massageAstNode: clean$2
  23035. };
  23036. var CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  23037. var commonOptions = {
  23038. bracketSpacing: {
  23039. since: "0.0.0",
  23040. category: CATEGORY_COMMON,
  23041. type: "boolean",
  23042. default: true,
  23043. description: "Print spaces between brackets.",
  23044. oppositeDescription: "Do not print spaces between brackets."
  23045. },
  23046. singleQuote: {
  23047. since: "0.0.0",
  23048. category: CATEGORY_COMMON,
  23049. type: "boolean",
  23050. default: false,
  23051. description: "Use single quotes instead of double quotes."
  23052. },
  23053. proseWrap: {
  23054. since: "1.8.2",
  23055. category: CATEGORY_COMMON,
  23056. type: "choice",
  23057. default: [{
  23058. since: "1.8.2",
  23059. value: true
  23060. }, {
  23061. since: "1.9.0",
  23062. value: "preserve"
  23063. }],
  23064. description: "How to wrap prose.",
  23065. choices: [{
  23066. since: "1.9.0",
  23067. value: "always",
  23068. description: "Wrap prose if it exceeds the print width."
  23069. }, {
  23070. since: "1.9.0",
  23071. value: "never",
  23072. description: "Do not wrap prose."
  23073. }, {
  23074. since: "1.9.0",
  23075. value: "preserve",
  23076. description: "Wrap prose as-is."
  23077. }, {
  23078. value: false,
  23079. deprecated: "1.9.0",
  23080. redirect: "never"
  23081. }, {
  23082. value: true,
  23083. deprecated: "1.9.0",
  23084. redirect: "always"
  23085. }]
  23086. }
  23087. };
  23088. var CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  23089. var options$3 = {
  23090. arrowParens: {
  23091. since: "1.9.0",
  23092. category: CATEGORY_JAVASCRIPT,
  23093. type: "choice",
  23094. default: "avoid",
  23095. description: "Include parentheses around a sole arrow function parameter.",
  23096. choices: [{
  23097. value: "avoid",
  23098. description: "Omit parens when possible. Example: `x => x`"
  23099. }, {
  23100. value: "always",
  23101. description: "Always include parens. Example: `(x) => x`"
  23102. }]
  23103. },
  23104. bracketSpacing: commonOptions.bracketSpacing,
  23105. jsxBracketSameLine: {
  23106. since: "0.17.0",
  23107. category: CATEGORY_JAVASCRIPT,
  23108. type: "boolean",
  23109. default: false,
  23110. description: "Put > on the last line instead of at a new line."
  23111. },
  23112. semi: {
  23113. since: "1.0.0",
  23114. category: CATEGORY_JAVASCRIPT,
  23115. type: "boolean",
  23116. default: true,
  23117. description: "Print semicolons.",
  23118. oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
  23119. },
  23120. singleQuote: commonOptions.singleQuote,
  23121. jsxSingleQuote: {
  23122. since: "1.15.0",
  23123. category: CATEGORY_JAVASCRIPT,
  23124. type: "boolean",
  23125. default: false,
  23126. description: "Use single quotes in JSX."
  23127. },
  23128. trailingComma: {
  23129. since: "0.0.0",
  23130. category: CATEGORY_JAVASCRIPT,
  23131. type: "choice",
  23132. default: [{
  23133. since: "0.0.0",
  23134. value: false
  23135. }, {
  23136. since: "0.19.0",
  23137. value: "none"
  23138. }],
  23139. description: "Print trailing commas wherever possible when multi-line.",
  23140. choices: [{
  23141. value: "none",
  23142. description: "No trailing commas."
  23143. }, {
  23144. value: "es5",
  23145. description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  23146. }, {
  23147. value: "all",
  23148. description: "Trailing commas wherever possible (including function arguments)."
  23149. }, {
  23150. value: true,
  23151. deprecated: "0.19.0",
  23152. redirect: "es5"
  23153. }, {
  23154. value: false,
  23155. deprecated: "0.19.0",
  23156. redirect: "none"
  23157. }]
  23158. }
  23159. };
  23160. var createLanguage = function createLanguage(linguistData, _ref) {
  23161. var extend = _ref.extend,
  23162. override = _ref.override;
  23163. var language = {};
  23164. for (var key in linguistData) {
  23165. var newKey = key === "languageId" ? "linguistLanguageId" : key;
  23166. language[newKey] = linguistData[key];
  23167. }
  23168. if (extend) {
  23169. for (var _key in extend) {
  23170. language[_key] = (language[_key] || []).concat(extend[_key]);
  23171. }
  23172. }
  23173. for (var _key2 in override) {
  23174. language[_key2] = override[_key2];
  23175. }
  23176. return language;
  23177. };
  23178. var name$1 = "JavaScript";
  23179. var type = "programming";
  23180. var tmScope = "source.js";
  23181. var aceMode = "javascript";
  23182. var codemirrorMode = "javascript";
  23183. var codemirrorMimeType = "text/javascript";
  23184. var color = "#f1e05a";
  23185. var aliases = ["js", "node"];
  23186. var extensions = [".js", "._js", ".bones", ".es", ".es6", ".frag", ".gs", ".jake", ".jsb", ".jscad", ".jsfl", ".jsm", ".jss", ".mjs", ".njs", ".pac", ".sjs", ".ssjs", ".xsjs", ".xsjslib"];
  23187. var filenames = ["Jakefile"];
  23188. var interpreters = ["node"];
  23189. var languageId = 183;
  23190. var javascript = {
  23191. name: name$1,
  23192. type: type,
  23193. tmScope: tmScope,
  23194. aceMode: aceMode,
  23195. codemirrorMode: codemirrorMode,
  23196. codemirrorMimeType: codemirrorMimeType,
  23197. color: color,
  23198. aliases: aliases,
  23199. extensions: extensions,
  23200. filenames: filenames,
  23201. interpreters: interpreters,
  23202. languageId: languageId
  23203. };
  23204. var javascript$1 = Object.freeze({
  23205. name: name$1,
  23206. type: type,
  23207. tmScope: tmScope,
  23208. aceMode: aceMode,
  23209. codemirrorMode: codemirrorMode,
  23210. codemirrorMimeType: codemirrorMimeType,
  23211. color: color,
  23212. aliases: aliases,
  23213. extensions: extensions,
  23214. filenames: filenames,
  23215. interpreters: interpreters,
  23216. languageId: languageId,
  23217. default: javascript
  23218. });
  23219. var name$2 = "JSX";
  23220. var type$1 = "programming";
  23221. var group$3 = "JavaScript";
  23222. var extensions$1 = [".jsx"];
  23223. var tmScope$1 = "source.js.jsx";
  23224. var aceMode$1 = "javascript";
  23225. var codemirrorMode$1 = "jsx";
  23226. var codemirrorMimeType$1 = "text/jsx";
  23227. var languageId$1 = 178;
  23228. var jsx = {
  23229. name: name$2,
  23230. type: type$1,
  23231. group: group$3,
  23232. extensions: extensions$1,
  23233. tmScope: tmScope$1,
  23234. aceMode: aceMode$1,
  23235. codemirrorMode: codemirrorMode$1,
  23236. codemirrorMimeType: codemirrorMimeType$1,
  23237. languageId: languageId$1
  23238. };
  23239. var jsx$1 = Object.freeze({
  23240. name: name$2,
  23241. type: type$1,
  23242. group: group$3,
  23243. extensions: extensions$1,
  23244. tmScope: tmScope$1,
  23245. aceMode: aceMode$1,
  23246. codemirrorMode: codemirrorMode$1,
  23247. codemirrorMimeType: codemirrorMimeType$1,
  23248. languageId: languageId$1,
  23249. default: jsx
  23250. });
  23251. var name$3 = "TypeScript";
  23252. var type$2 = "programming";
  23253. var color$1 = "#2b7489";
  23254. var aliases$1 = ["ts"];
  23255. var extensions$2 = [".ts", ".tsx"];
  23256. var tmScope$2 = "source.ts";
  23257. var aceMode$2 = "typescript";
  23258. var codemirrorMode$2 = "javascript";
  23259. var codemirrorMimeType$2 = "application/typescript";
  23260. var languageId$2 = 378;
  23261. var typescript = {
  23262. name: name$3,
  23263. type: type$2,
  23264. color: color$1,
  23265. aliases: aliases$1,
  23266. extensions: extensions$2,
  23267. tmScope: tmScope$2,
  23268. aceMode: aceMode$2,
  23269. codemirrorMode: codemirrorMode$2,
  23270. codemirrorMimeType: codemirrorMimeType$2,
  23271. languageId: languageId$2
  23272. };
  23273. var typescript$1 = Object.freeze({
  23274. name: name$3,
  23275. type: type$2,
  23276. color: color$1,
  23277. aliases: aliases$1,
  23278. extensions: extensions$2,
  23279. tmScope: tmScope$2,
  23280. aceMode: aceMode$2,
  23281. codemirrorMode: codemirrorMode$2,
  23282. codemirrorMimeType: codemirrorMimeType$2,
  23283. languageId: languageId$2,
  23284. default: typescript
  23285. });
  23286. var name$4 = "JSON";
  23287. var type$3 = "data";
  23288. var tmScope$3 = "source.json";
  23289. var group$4 = "JavaScript";
  23290. var aceMode$3 = "json";
  23291. var codemirrorMode$3 = "javascript";
  23292. var codemirrorMimeType$3 = "application/json";
  23293. var searchable = false;
  23294. var extensions$3 = [".json", ".avsc", ".geojson", ".gltf", ".JSON-tmLanguage", ".jsonl", ".tfstate", ".tfstate.backup", ".topojson", ".webapp", ".webmanifest"];
  23295. var filenames$1 = [".arcconfig", ".htmlhintrc", ".tern-config", ".tern-project", "composer.lock", "mcmod.info"];
  23296. var languageId$3 = 174;
  23297. var json$2 = {
  23298. name: name$4,
  23299. type: type$3,
  23300. tmScope: tmScope$3,
  23301. group: group$4,
  23302. aceMode: aceMode$3,
  23303. codemirrorMode: codemirrorMode$3,
  23304. codemirrorMimeType: codemirrorMimeType$3,
  23305. searchable: searchable,
  23306. extensions: extensions$3,
  23307. filenames: filenames$1,
  23308. languageId: languageId$3
  23309. };
  23310. var json$3 = Object.freeze({
  23311. name: name$4,
  23312. type: type$3,
  23313. tmScope: tmScope$3,
  23314. group: group$4,
  23315. aceMode: aceMode$3,
  23316. codemirrorMode: codemirrorMode$3,
  23317. codemirrorMimeType: codemirrorMimeType$3,
  23318. searchable: searchable,
  23319. extensions: extensions$3,
  23320. filenames: filenames$1,
  23321. languageId: languageId$3,
  23322. default: json$2
  23323. });
  23324. var name$5 = "JSON with Comments";
  23325. var type$4 = "data";
  23326. var group$5 = "JSON";
  23327. var tmScope$4 = "source.js";
  23328. var aceMode$4 = "javascript";
  23329. var codemirrorMode$4 = "javascript";
  23330. var codemirrorMimeType$4 = "text/javascript";
  23331. var aliases$2 = ["jsonc"];
  23332. 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"];
  23333. var filenames$2 = [".babelrc", ".eslintrc.json", ".jscsrc", ".jshintrc", ".jslintrc", "tsconfig.json"];
  23334. var languageId$4 = 423;
  23335. var jsonWithComments = {
  23336. name: name$5,
  23337. type: type$4,
  23338. group: group$5,
  23339. tmScope: tmScope$4,
  23340. aceMode: aceMode$4,
  23341. codemirrorMode: codemirrorMode$4,
  23342. codemirrorMimeType: codemirrorMimeType$4,
  23343. aliases: aliases$2,
  23344. extensions: extensions$4,
  23345. filenames: filenames$2,
  23346. languageId: languageId$4
  23347. };
  23348. var jsonWithComments$1 = Object.freeze({
  23349. name: name$5,
  23350. type: type$4,
  23351. group: group$5,
  23352. tmScope: tmScope$4,
  23353. aceMode: aceMode$4,
  23354. codemirrorMode: codemirrorMode$4,
  23355. codemirrorMimeType: codemirrorMimeType$4,
  23356. aliases: aliases$2,
  23357. extensions: extensions$4,
  23358. filenames: filenames$2,
  23359. languageId: languageId$4,
  23360. default: jsonWithComments
  23361. });
  23362. var name$6 = "JSON5";
  23363. var type$5 = "data";
  23364. var extensions$5 = [".json5"];
  23365. var tmScope$5 = "source.js";
  23366. var aceMode$5 = "javascript";
  23367. var codemirrorMode$5 = "javascript";
  23368. var codemirrorMimeType$5 = "application/json";
  23369. var languageId$5 = 175;
  23370. var json5 = {
  23371. name: name$6,
  23372. type: type$5,
  23373. extensions: extensions$5,
  23374. tmScope: tmScope$5,
  23375. aceMode: aceMode$5,
  23376. codemirrorMode: codemirrorMode$5,
  23377. codemirrorMimeType: codemirrorMimeType$5,
  23378. languageId: languageId$5
  23379. };
  23380. var json5$1 = Object.freeze({
  23381. name: name$6,
  23382. type: type$5,
  23383. extensions: extensions$5,
  23384. tmScope: tmScope$5,
  23385. aceMode: aceMode$5,
  23386. codemirrorMode: codemirrorMode$5,
  23387. codemirrorMimeType: codemirrorMimeType$5,
  23388. languageId: languageId$5,
  23389. default: json5
  23390. });
  23391. var require$$0$21 = ( javascript$1 && javascript ) || javascript$1;
  23392. var require$$1$8 = ( jsx$1 && jsx ) || jsx$1;
  23393. var require$$2$10 = ( typescript$1 && typescript ) || typescript$1;
  23394. var require$$3$3 = ( json$3 && json$2 ) || json$3;
  23395. var require$$4$2 = ( jsonWithComments$1 && jsonWithComments ) || jsonWithComments$1;
  23396. var require$$5$1 = ( json5$1 && json5 ) || json5$1;
  23397. var languages = [createLanguage(require$$0$21, {
  23398. override: {
  23399. since: "0.0.0",
  23400. parsers: ["babel", "flow"],
  23401. vscodeLanguageIds: ["javascript"]
  23402. },
  23403. extend: {
  23404. interpreters: ["nodejs"]
  23405. }
  23406. }), createLanguage(require$$0$21, {
  23407. override: {
  23408. name: "Flow",
  23409. since: "0.0.0",
  23410. parsers: ["babel", "flow"],
  23411. vscodeLanguageIds: ["javascript"],
  23412. aliases: [],
  23413. filenames: [],
  23414. extensions: [".js.flow"]
  23415. }
  23416. }), createLanguage(require$$1$8, {
  23417. override: {
  23418. since: "0.0.0",
  23419. parsers: ["babel", "flow"],
  23420. vscodeLanguageIds: ["javascriptreact"]
  23421. }
  23422. }), createLanguage(require$$2$10, {
  23423. override: {
  23424. since: "1.4.0",
  23425. parsers: ["typescript"],
  23426. vscodeLanguageIds: ["typescript", "typescriptreact"]
  23427. }
  23428. }), createLanguage(require$$3$3, {
  23429. override: {
  23430. name: "JSON.stringify",
  23431. since: "1.13.0",
  23432. parsers: ["json-stringify"],
  23433. vscodeLanguageIds: ["json"],
  23434. extensions: [],
  23435. // .json file defaults to json instead of json-stringify
  23436. filenames: ["package.json", "package-lock.json", "composer.json"]
  23437. }
  23438. }), createLanguage(require$$3$3, {
  23439. override: {
  23440. since: "1.5.0",
  23441. parsers: ["json"],
  23442. vscodeLanguageIds: ["json"]
  23443. },
  23444. extend: {
  23445. filenames: [".prettierrc"]
  23446. }
  23447. }), createLanguage(require$$4$2, {
  23448. override: {
  23449. since: "1.5.0",
  23450. parsers: ["json"],
  23451. vscodeLanguageIds: ["jsonc"]
  23452. },
  23453. extend: {
  23454. filenames: [".eslintrc"]
  23455. }
  23456. }), createLanguage(require$$5$1, {
  23457. override: {
  23458. since: "1.13.0",
  23459. parsers: ["json5"],
  23460. vscodeLanguageIds: ["json5"]
  23461. }
  23462. })];
  23463. var printers = {
  23464. estree: printerEstree,
  23465. "estree-json": printerEstreeJson
  23466. };
  23467. var languageJs = {
  23468. languages,
  23469. options: options$3,
  23470. printers
  23471. };
  23472. 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"];
  23473. var htmlTagNames = Object.freeze({
  23474. default: index$12
  23475. });
  23476. var htmlTagNames$1 = ( htmlTagNames && index$12 ) || htmlTagNames;
  23477. function clean$3(ast, newObj, parent) {
  23478. ["raw", // front-matter
  23479. "raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(function (name) {
  23480. delete newObj[name];
  23481. });
  23482. if (ast.type === "yaml") {
  23483. delete newObj.value;
  23484. } // --insert-pragma
  23485. if (ast.type === "css-comment" && parent.type === "css-root" && parent.nodes.length !== 0 && ( // first non-front-matter comment
  23486. parent.nodes[0] === ast || (parent.nodes[0].type === "yaml" || parent.nodes[0].type === "toml") && parent.nodes[1] === ast)) {
  23487. /**
  23488. * something
  23489. *
  23490. * @format
  23491. */
  23492. delete newObj.text; // standalone pragma
  23493. if (/^\*\s*@(format|prettier)\s*$/.test(ast.text)) {
  23494. return null;
  23495. }
  23496. }
  23497. if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
  23498. delete newObj.value;
  23499. }
  23500. if (ast.type === "css-rule") {
  23501. delete newObj.params;
  23502. }
  23503. if (ast.type === "selector-combinator") {
  23504. newObj.value = newObj.value.replace(/\s+/g, " ");
  23505. }
  23506. if (ast.type === "media-feature") {
  23507. newObj.value = newObj.value.replace(/ /g, "");
  23508. }
  23509. 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") {
  23510. newObj.value = newObj.value.toLowerCase();
  23511. }
  23512. if (ast.type === "css-decl") {
  23513. newObj.prop = newObj.prop.toLowerCase();
  23514. }
  23515. if (ast.type === "css-atrule" || ast.type === "css-import") {
  23516. newObj.name = newObj.name.toLowerCase();
  23517. }
  23518. if (ast.type === "value-number") {
  23519. newObj.unit = newObj.unit.toLowerCase();
  23520. }
  23521. 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) {
  23522. newObj.value = cleanCSSStrings(newObj.value);
  23523. }
  23524. if (ast.type === "selector-attribute") {
  23525. newObj.attribute = newObj.attribute.trim();
  23526. if (newObj.namespace) {
  23527. if (typeof newObj.namespace === "string") {
  23528. newObj.namespace = newObj.namespace.trim();
  23529. if (newObj.namespace.length === 0) {
  23530. newObj.namespace = true;
  23531. }
  23532. }
  23533. }
  23534. if (newObj.value) {
  23535. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  23536. delete newObj.quoted;
  23537. }
  23538. }
  23539. 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) {
  23540. newObj.value = newObj.value.replace(/([\d.eE+-]+)([a-zA-Z]*)/g, function (match, numStr, unit) {
  23541. var num = Number(numStr);
  23542. return isNaN(num) ? match : num + unit.toLowerCase();
  23543. });
  23544. }
  23545. if (ast.type === "selector-tag") {
  23546. var lowercasedValue = ast.value.toLowerCase();
  23547. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  23548. newObj.value = lowercasedValue;
  23549. }
  23550. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  23551. newObj.value = lowercasedValue;
  23552. }
  23553. } // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
  23554. if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
  23555. delete newObj.value;
  23556. } // Workaround for SCSS nested properties
  23557. if (ast.type === "selector-unknown") {
  23558. delete newObj.value;
  23559. }
  23560. }
  23561. function cleanCSSStrings(value) {
  23562. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  23563. }
  23564. var clean_1$2 = clean$3;
  23565. var _require$$0$builders$3 = doc.builders;
  23566. var hardline$7 = _require$$0$builders$3.hardline;
  23567. var literalline$3 = _require$$0$builders$3.literalline;
  23568. var concat$9 = _require$$0$builders$3.concat;
  23569. var markAsRoot$1 = _require$$0$builders$3.markAsRoot;
  23570. var mapDoc$4 = doc.utils.mapDoc;
  23571. function embed$2(path$$1, print, textToDoc
  23572. /*, options */
  23573. ) {
  23574. var node = path$$1.getValue();
  23575. if (node.type === "yaml") {
  23576. return markAsRoot$1(concat$9(["---", hardline$7, node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  23577. parser: "yaml"
  23578. })) : "", "---", hardline$7]));
  23579. }
  23580. return null;
  23581. function replaceNewlinesWithLiterallines(doc$$2) {
  23582. return mapDoc$4(doc$$2, function (currentDoc) {
  23583. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$9(currentDoc.split(/(\n)/g).map(function (v, i) {
  23584. return i % 2 === 0 ? v : literalline$3;
  23585. })) : currentDoc;
  23586. });
  23587. }
  23588. }
  23589. var embed_1$2 = embed$2;
  23590. var DELIMITER_MAP = {
  23591. "---": "yaml",
  23592. "+++": "toml"
  23593. };
  23594. function parse$5(text) {
  23595. var delimiterRegex = Object.keys(DELIMITER_MAP).map(escapeStringRegexp).join("|");
  23596. var match = text.match( // trailing spaces after delimiters are allowed
  23597. new RegExp(`^(${delimiterRegex})[^\\n\\S]*\\n(?:([\\s\\S]*?)\\n)?\\1[^\\n\\S]*(\\n|$)`));
  23598. if (match === null) {
  23599. return {
  23600. frontMatter: null,
  23601. content: text
  23602. };
  23603. }
  23604. var raw = match[0].replace(/\n$/, "");
  23605. var delimiter = match[1];
  23606. var value = match[2];
  23607. return {
  23608. frontMatter: {
  23609. type: DELIMITER_MAP[delimiter],
  23610. value,
  23611. raw
  23612. },
  23613. content: match[0].replace(/[^\n]/g, " ") + text.slice(match[0].length)
  23614. };
  23615. }
  23616. var frontMatter = parse$5;
  23617. function hasPragma$1(text) {
  23618. return pragma.hasPragma(frontMatter(text).content);
  23619. }
  23620. function insertPragma$3(text) {
  23621. var _parseFrontMatter = frontMatter(text),
  23622. frontMatter$$1 = _parseFrontMatter.frontMatter,
  23623. content = _parseFrontMatter.content;
  23624. return (frontMatter$$1 ? frontMatter$$1.raw + "\n\n" : "") + pragma.insertPragma(content);
  23625. }
  23626. var pragma$2 = {
  23627. hasPragma: hasPragma$1,
  23628. insertPragma: insertPragma$3
  23629. };
  23630. 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"];
  23631. function getAncestorCounter(path$$1, typeOrTypes) {
  23632. var types = [].concat(typeOrTypes);
  23633. var counter = -1;
  23634. var ancestorNode;
  23635. while (ancestorNode = path$$1.getParentNode(++counter)) {
  23636. if (types.indexOf(ancestorNode.type) !== -1) {
  23637. return counter;
  23638. }
  23639. }
  23640. return -1;
  23641. }
  23642. function getAncestorNode$1(path$$1, typeOrTypes) {
  23643. var counter = getAncestorCounter(path$$1, typeOrTypes);
  23644. return counter === -1 ? null : path$$1.getParentNode(counter);
  23645. }
  23646. function getPropOfDeclNode$1(path$$1) {
  23647. var declAncestorNode = getAncestorNode$1(path$$1, "css-decl");
  23648. return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
  23649. }
  23650. function isSCSS$1(parser, text) {
  23651. var hasExplicitParserChoice = parser === "less" || parser === "scss";
  23652. var IS_POSSIBLY_SCSS = /(\w\s*: [^}:]+|#){|@import[^\n]+(url|,)/;
  23653. return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
  23654. }
  23655. function isWideKeywords$1(value) {
  23656. return ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== -1;
  23657. }
  23658. function isKeyframeAtRuleKeywords$1(path$$1, value) {
  23659. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  23660. return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].indexOf(value.toLowerCase()) !== -1;
  23661. }
  23662. function maybeToLowerCase$1(value) {
  23663. return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
  23664. }
  23665. function insideValueFunctionNode$1(path$$1, functionName) {
  23666. var funcAncestorNode = getAncestorNode$1(path$$1, "value-func");
  23667. return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
  23668. }
  23669. function insideICSSRuleNode$1(path$$1) {
  23670. var ruleAncestorNode = getAncestorNode$1(path$$1, "css-rule");
  23671. return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
  23672. }
  23673. function insideAtRuleNode$1(path$$1, atRuleNameOrAtRuleNames) {
  23674. var atRuleNames = [].concat(atRuleNameOrAtRuleNames);
  23675. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  23676. return atRuleAncestorNode && atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1;
  23677. }
  23678. function insideURLFunctionInImportAtRuleNode$1(path$$1) {
  23679. var node = path$$1.getValue();
  23680. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  23681. return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
  23682. }
  23683. function isURLFunctionNode$1(node) {
  23684. return node.type === "value-func" && node.value.toLowerCase() === "url";
  23685. }
  23686. function isLastNode$1(path$$1, node) {
  23687. var parentNode = path$$1.getParentNode();
  23688. if (!parentNode) {
  23689. return false;
  23690. }
  23691. var nodes = parentNode.nodes;
  23692. return nodes && nodes.indexOf(node) === nodes.length - 1;
  23693. }
  23694. function isHTMLTag$1(value) {
  23695. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  23696. }
  23697. function isDetachedRulesetDeclarationNode$1(node) {
  23698. // If a Less file ends up being parsed with the SCSS parser, Less
  23699. // variable declarations will be parsed as atrules with names ending
  23700. // with a colon, so keep the original case then.
  23701. if (!node.selector) {
  23702. return false;
  23703. }
  23704. return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
  23705. }
  23706. function isForKeywordNode$1(node) {
  23707. return node.type === "value-word" && ["from", "through", "end"].indexOf(node.value) !== -1;
  23708. }
  23709. function isIfElseKeywordNode$1(node) {
  23710. return node.type === "value-word" && ["and", "or", "not"].indexOf(node.value) !== -1;
  23711. }
  23712. function isEachKeywordNode$1(node) {
  23713. return node.type === "value-word" && node.value === "in";
  23714. }
  23715. function isMultiplicationNode$1(node) {
  23716. return node.type === "value-operator" && node.value === "*";
  23717. }
  23718. function isDivisionNode$1(node) {
  23719. return node.type === "value-operator" && node.value === "/";
  23720. }
  23721. function isAdditionNode$1(node) {
  23722. return node.type === "value-operator" && node.value === "+";
  23723. }
  23724. function isSubtractionNode$1(node) {
  23725. return node.type === "value-operator" && node.value === "-";
  23726. }
  23727. function isModuloNode(node) {
  23728. return node.type === "value-operator" && node.value === "%";
  23729. }
  23730. function isMathOperatorNode$1(node) {
  23731. return isMultiplicationNode$1(node) || isDivisionNode$1(node) || isAdditionNode$1(node) || isSubtractionNode$1(node) || isModuloNode(node);
  23732. }
  23733. function isEqualityOperatorNode$1(node) {
  23734. return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1;
  23735. }
  23736. function isRelationalOperatorNode$1(node) {
  23737. return node.type === "value-word" && ["<", ">", "<=", ">="].indexOf(node.value) !== -1;
  23738. }
  23739. function isSCSSControlDirectiveNode$1(node) {
  23740. return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1;
  23741. }
  23742. function isSCSSNestedPropertyNode(node) {
  23743. if (!node.selector) {
  23744. return false;
  23745. }
  23746. return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
  23747. }
  23748. function isDetachedRulesetCallNode$1(node) {
  23749. return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
  23750. }
  23751. function isTemplatePlaceholderNode$1(node) {
  23752. return node.name.startsWith("prettier-placeholder");
  23753. }
  23754. function isTemplatePropNode$1(node) {
  23755. return node.prop.startsWith("@prettier-placeholder");
  23756. }
  23757. function isPostcssSimpleVarNode$1(currentNode, nextNode) {
  23758. return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
  23759. }
  23760. function hasComposesNode$1(node) {
  23761. return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
  23762. }
  23763. function hasParensAroundNode$1(node) {
  23764. 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;
  23765. }
  23766. function hasEmptyRawBefore$1(node) {
  23767. return node.raws && node.raws.before === "";
  23768. }
  23769. function isKeyValuePairNode$1(node) {
  23770. return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
  23771. }
  23772. function isKeyValuePairInParenGroupNode(node) {
  23773. return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode$1(node.groups[0]);
  23774. }
  23775. function isSCSSMapItemNode$1(path$$1) {
  23776. var node = path$$1.getValue(); // Ignore empty item (i.e. `$key: ()`)
  23777. if (node.groups.length === 0) {
  23778. return false;
  23779. }
  23780. var parentParentNode = path$$1.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
  23781. if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
  23782. return false;
  23783. }
  23784. var declNode = getAncestorNode$1(path$$1, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
  23785. if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
  23786. return true;
  23787. } // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
  23788. if (isKeyValuePairInParenGroupNode(parentParentNode)) {
  23789. return true;
  23790. } // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
  23791. if (parentParentNode.type === "value-func") {
  23792. return true;
  23793. }
  23794. return false;
  23795. }
  23796. function isInlineValueCommentNode$1(node) {
  23797. return node.type === "value-comment" && node.inline;
  23798. }
  23799. function isHashNode$1(node) {
  23800. return node.type === "value-word" && node.value === "#";
  23801. }
  23802. function isLeftCurlyBraceNode$1(node) {
  23803. return node.type === "value-word" && node.value === "{";
  23804. }
  23805. function isRightCurlyBraceNode$1(node) {
  23806. return node.type === "value-word" && node.value === "}";
  23807. }
  23808. function isWordNode$1(node) {
  23809. return ["value-word", "value-atword"].indexOf(node.type) !== -1;
  23810. }
  23811. function isColonNode$1(node) {
  23812. return node.type === "value-colon";
  23813. }
  23814. function isMediaAndSupportsKeywords$1(node) {
  23815. return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
  23816. }
  23817. function isColorAdjusterFuncNode$1(node) {
  23818. if (node.type !== "value-func") {
  23819. return false;
  23820. }
  23821. return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
  23822. }
  23823. var utils$6 = {
  23824. getAncestorCounter,
  23825. getAncestorNode: getAncestorNode$1,
  23826. getPropOfDeclNode: getPropOfDeclNode$1,
  23827. maybeToLowerCase: maybeToLowerCase$1,
  23828. insideValueFunctionNode: insideValueFunctionNode$1,
  23829. insideICSSRuleNode: insideICSSRuleNode$1,
  23830. insideAtRuleNode: insideAtRuleNode$1,
  23831. insideURLFunctionInImportAtRuleNode: insideURLFunctionInImportAtRuleNode$1,
  23832. isKeyframeAtRuleKeywords: isKeyframeAtRuleKeywords$1,
  23833. isHTMLTag: isHTMLTag$1,
  23834. isWideKeywords: isWideKeywords$1,
  23835. isSCSS: isSCSS$1,
  23836. isLastNode: isLastNode$1,
  23837. isSCSSControlDirectiveNode: isSCSSControlDirectiveNode$1,
  23838. isDetachedRulesetDeclarationNode: isDetachedRulesetDeclarationNode$1,
  23839. isRelationalOperatorNode: isRelationalOperatorNode$1,
  23840. isEqualityOperatorNode: isEqualityOperatorNode$1,
  23841. isMultiplicationNode: isMultiplicationNode$1,
  23842. isDivisionNode: isDivisionNode$1,
  23843. isAdditionNode: isAdditionNode$1,
  23844. isSubtractionNode: isSubtractionNode$1,
  23845. isModuloNode,
  23846. isMathOperatorNode: isMathOperatorNode$1,
  23847. isEachKeywordNode: isEachKeywordNode$1,
  23848. isForKeywordNode: isForKeywordNode$1,
  23849. isURLFunctionNode: isURLFunctionNode$1,
  23850. isIfElseKeywordNode: isIfElseKeywordNode$1,
  23851. hasComposesNode: hasComposesNode$1,
  23852. hasParensAroundNode: hasParensAroundNode$1,
  23853. hasEmptyRawBefore: hasEmptyRawBefore$1,
  23854. isSCSSNestedPropertyNode,
  23855. isDetachedRulesetCallNode: isDetachedRulesetCallNode$1,
  23856. isTemplatePlaceholderNode: isTemplatePlaceholderNode$1,
  23857. isTemplatePropNode: isTemplatePropNode$1,
  23858. isPostcssSimpleVarNode: isPostcssSimpleVarNode$1,
  23859. isKeyValuePairNode: isKeyValuePairNode$1,
  23860. isKeyValuePairInParenGroupNode,
  23861. isSCSSMapItemNode: isSCSSMapItemNode$1,
  23862. isInlineValueCommentNode: isInlineValueCommentNode$1,
  23863. isHashNode: isHashNode$1,
  23864. isLeftCurlyBraceNode: isLeftCurlyBraceNode$1,
  23865. isRightCurlyBraceNode: isRightCurlyBraceNode$1,
  23866. isWordNode: isWordNode$1,
  23867. isColonNode: isColonNode$1,
  23868. isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1,
  23869. isColorAdjusterFuncNode: isColorAdjusterFuncNode$1
  23870. };
  23871. var insertPragma$2 = pragma$2.insertPragma;
  23872. var printNumber$2 = util$1.printNumber;
  23873. var printString$2 = util$1.printString;
  23874. var hasIgnoreComment$2 = util$1.hasIgnoreComment;
  23875. var hasNewline$3 = util$1.hasNewline;
  23876. var isNextLineEmpty$3 = utilShared.isNextLineEmpty;
  23877. var _require$$3$builders = doc.builders;
  23878. var concat$8 = _require$$3$builders.concat;
  23879. var join$6 = _require$$3$builders.join;
  23880. var line$5 = _require$$3$builders.line;
  23881. var hardline$6 = _require$$3$builders.hardline;
  23882. var softline$3 = _require$$3$builders.softline;
  23883. var group$6 = _require$$3$builders.group;
  23884. var fill$3 = _require$$3$builders.fill;
  23885. var indent$5 = _require$$3$builders.indent;
  23886. var dedent$3 = _require$$3$builders.dedent;
  23887. var ifBreak$2 = _require$$3$builders.ifBreak;
  23888. var removeLines$2 = doc.utils.removeLines;
  23889. var getAncestorNode = utils$6.getAncestorNode;
  23890. var getPropOfDeclNode = utils$6.getPropOfDeclNode;
  23891. var maybeToLowerCase = utils$6.maybeToLowerCase;
  23892. var insideValueFunctionNode = utils$6.insideValueFunctionNode;
  23893. var insideICSSRuleNode = utils$6.insideICSSRuleNode;
  23894. var insideAtRuleNode = utils$6.insideAtRuleNode;
  23895. var insideURLFunctionInImportAtRuleNode = utils$6.insideURLFunctionInImportAtRuleNode;
  23896. var isKeyframeAtRuleKeywords = utils$6.isKeyframeAtRuleKeywords;
  23897. var isHTMLTag = utils$6.isHTMLTag;
  23898. var isWideKeywords = utils$6.isWideKeywords;
  23899. var isSCSS = utils$6.isSCSS;
  23900. var isLastNode = utils$6.isLastNode;
  23901. var isSCSSControlDirectiveNode = utils$6.isSCSSControlDirectiveNode;
  23902. var isDetachedRulesetDeclarationNode = utils$6.isDetachedRulesetDeclarationNode;
  23903. var isRelationalOperatorNode = utils$6.isRelationalOperatorNode;
  23904. var isEqualityOperatorNode = utils$6.isEqualityOperatorNode;
  23905. var isMultiplicationNode = utils$6.isMultiplicationNode;
  23906. var isDivisionNode = utils$6.isDivisionNode;
  23907. var isAdditionNode = utils$6.isAdditionNode;
  23908. var isSubtractionNode = utils$6.isSubtractionNode;
  23909. var isMathOperatorNode = utils$6.isMathOperatorNode;
  23910. var isEachKeywordNode = utils$6.isEachKeywordNode;
  23911. var isForKeywordNode = utils$6.isForKeywordNode;
  23912. var isURLFunctionNode = utils$6.isURLFunctionNode;
  23913. var isIfElseKeywordNode = utils$6.isIfElseKeywordNode;
  23914. var hasComposesNode = utils$6.hasComposesNode;
  23915. var hasParensAroundNode = utils$6.hasParensAroundNode;
  23916. var hasEmptyRawBefore = utils$6.hasEmptyRawBefore;
  23917. var isKeyValuePairNode = utils$6.isKeyValuePairNode;
  23918. var isDetachedRulesetCallNode = utils$6.isDetachedRulesetCallNode;
  23919. var isTemplatePlaceholderNode = utils$6.isTemplatePlaceholderNode;
  23920. var isTemplatePropNode = utils$6.isTemplatePropNode;
  23921. var isPostcssSimpleVarNode = utils$6.isPostcssSimpleVarNode;
  23922. var isSCSSMapItemNode = utils$6.isSCSSMapItemNode;
  23923. var isInlineValueCommentNode = utils$6.isInlineValueCommentNode;
  23924. var isHashNode = utils$6.isHashNode;
  23925. var isLeftCurlyBraceNode = utils$6.isLeftCurlyBraceNode;
  23926. var isRightCurlyBraceNode = utils$6.isRightCurlyBraceNode;
  23927. var isWordNode = utils$6.isWordNode;
  23928. var isColonNode = utils$6.isColonNode;
  23929. var isMediaAndSupportsKeywords = utils$6.isMediaAndSupportsKeywords;
  23930. var isColorAdjusterFuncNode = utils$6.isColorAdjusterFuncNode;
  23931. function shouldPrintComma$1(options) {
  23932. switch (options.trailingComma) {
  23933. case "all":
  23934. case "es5":
  23935. return true;
  23936. case "none":
  23937. default:
  23938. return false;
  23939. }
  23940. }
  23941. function genericPrint$2(path$$1, options, print) {
  23942. var node = path$$1.getValue();
  23943. /* istanbul ignore if */
  23944. if (!node) {
  23945. return "";
  23946. }
  23947. if (typeof node === "string") {
  23948. return node;
  23949. }
  23950. switch (node.type) {
  23951. case "yaml":
  23952. case "toml":
  23953. return concat$8([node.raw, hardline$6]);
  23954. case "css-root":
  23955. {
  23956. var nodes = printNodeSequence(path$$1, options, print);
  23957. if (nodes.parts.length) {
  23958. return concat$8([nodes, hardline$6]);
  23959. }
  23960. return nodes;
  23961. }
  23962. case "css-comment":
  23963. {
  23964. if (node.raws.content) {
  23965. return node.raws.content;
  23966. }
  23967. var text = options.originalText.slice(options.locStart(node), options.locEnd(node));
  23968. var rawText = node.raws.text || node.text; // Workaround a bug where the location is off.
  23969. // https://github.com/postcss/postcss-scss/issues/63
  23970. if (text.indexOf(rawText) === -1) {
  23971. if (node.raws.inline) {
  23972. return concat$8(["// ", rawText]);
  23973. }
  23974. return concat$8(["/* ", rawText, " */"]);
  23975. }
  23976. return text;
  23977. }
  23978. case "css-rule":
  23979. {
  23980. 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) ? ";" : ""]) : ";"]);
  23981. }
  23982. case "css-decl":
  23983. {
  23984. var parentNode = path$$1.getParentNode();
  23985. 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] !== ";" ? "" : ";"]);
  23986. }
  23987. case "css-atrule":
  23988. {
  23989. var _parentNode = path$$1.getParentNode();
  23990. return concat$8(["@", // If a Less file ends up being parsed with the SCSS parser, Less
  23991. // variable declarations will be parsed as at-rules with names ending
  23992. // with a colon, so keep the original case then.
  23993. 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] !== ";" ? "" : ";"]);
  23994. }
  23995. // postcss-media-query-parser
  23996. case "media-query-list":
  23997. {
  23998. var parts = [];
  23999. path$$1.each(function (childPath) {
  24000. var node = childPath.getValue();
  24001. if (node.type === "media-query" && node.value === "") {
  24002. return;
  24003. }
  24004. parts.push(childPath.call(print));
  24005. }, "nodes");
  24006. return group$6(indent$5(join$6(line$5, parts)));
  24007. }
  24008. case "media-query":
  24009. {
  24010. return concat$8([join$6(" ", path$$1.map(print, "nodes")), isLastNode(path$$1, node) ? "" : ","]);
  24011. }
  24012. case "media-type":
  24013. {
  24014. return adjustNumbers(adjustStrings(node.value, options));
  24015. }
  24016. case "media-feature-expression":
  24017. {
  24018. if (!node.nodes) {
  24019. return node.value;
  24020. }
  24021. return concat$8(["(", concat$8(path$$1.map(print, "nodes")), ")"]);
  24022. }
  24023. case "media-feature":
  24024. {
  24025. return maybeToLowerCase(adjustStrings(node.value.replace(/ +/g, " "), options));
  24026. }
  24027. case "media-colon":
  24028. {
  24029. return concat$8([node.value, " "]);
  24030. }
  24031. case "media-value":
  24032. {
  24033. return adjustNumbers(adjustStrings(node.value, options));
  24034. }
  24035. case "media-keyword":
  24036. {
  24037. return adjustStrings(node.value, options);
  24038. }
  24039. case "media-url":
  24040. {
  24041. return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
  24042. }
  24043. case "media-unknown":
  24044. {
  24045. return node.value;
  24046. }
  24047. // postcss-selector-parser
  24048. case "selector-root":
  24049. {
  24050. 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"))]));
  24051. }
  24052. case "selector-selector":
  24053. {
  24054. return group$6(indent$5(concat$8(path$$1.map(print, "nodes"))));
  24055. }
  24056. case "selector-comment":
  24057. {
  24058. return node.value;
  24059. }
  24060. case "selector-string":
  24061. {
  24062. return adjustStrings(node.value, options);
  24063. }
  24064. case "selector-tag":
  24065. {
  24066. var _parentNode2 = path$$1.getParentNode();
  24067. var index = _parentNode2 && _parentNode2.nodes.indexOf(node);
  24068. var prevNode = index && _parentNode2.nodes[index - 1];
  24069. 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)]);
  24070. }
  24071. case "selector-id":
  24072. {
  24073. return concat$8(["#", node.value]);
  24074. }
  24075. case "selector-class":
  24076. {
  24077. return concat$8([".", adjustNumbers(adjustStrings(node.value, options))]);
  24078. }
  24079. case "selector-attribute":
  24080. {
  24081. 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" : "", "]"]);
  24082. }
  24083. case "selector-combinator":
  24084. {
  24085. if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
  24086. var _parentNode3 = path$$1.getParentNode();
  24087. var _leading = _parentNode3.type === "selector-selector" && _parentNode3.nodes[0] === node ? "" : line$5;
  24088. return concat$8([_leading, node.value, isLastNode(path$$1, node) ? "" : " "]);
  24089. }
  24090. var leading = node.value.trim().startsWith("(") ? line$5 : "";
  24091. var value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$5;
  24092. return concat$8([leading, value]);
  24093. }
  24094. case "selector-universal":
  24095. {
  24096. return concat$8([node.namespace ? concat$8([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.value]);
  24097. }
  24098. case "selector-pseudo":
  24099. {
  24100. return concat$8([maybeToLowerCase(node.value), node.nodes && node.nodes.length > 0 ? concat$8(["(", join$6(", ", path$$1.map(print, "nodes")), ")"]) : ""]);
  24101. }
  24102. case "selector-nesting":
  24103. {
  24104. return node.value;
  24105. }
  24106. case "selector-unknown":
  24107. {
  24108. var ruleAncestorNode = getAncestorNode(path$$1, "css-rule"); // Nested SCSS property
  24109. if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
  24110. return adjustNumbers(adjustStrings(maybeToLowerCase(node.value), options));
  24111. }
  24112. return node.value;
  24113. }
  24114. // postcss-values-parser
  24115. case "value-value":
  24116. case "value-root":
  24117. {
  24118. return path$$1.call(print, "group");
  24119. }
  24120. case "value-comment":
  24121. {
  24122. return concat$8([node.inline ? "//" : "/*", node.value, node.inline ? "" : "*/"]);
  24123. }
  24124. case "value-comma_group":
  24125. {
  24126. var _parentNode4 = path$$1.getParentNode();
  24127. var parentParentNode = path$$1.getParentNode(1);
  24128. var declAncestorProp = getPropOfDeclNode(path$$1);
  24129. var isGridValue = declAncestorProp && _parentNode4.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
  24130. var atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  24131. var isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode(atRuleAncestorNode);
  24132. var printed = path$$1.map(print, "groups");
  24133. var _parts = [];
  24134. var insideURLFunction = insideValueFunctionNode(path$$1, "url");
  24135. var insideSCSSInterpolationInString = false;
  24136. var didBreak = false;
  24137. for (var i = 0; i < node.groups.length; ++i) {
  24138. _parts.push(printed[i]); // Ignore value inside `url()`
  24139. if (insideURLFunction) {
  24140. continue;
  24141. }
  24142. var iPrevNode = node.groups[i - 1];
  24143. var iNode = node.groups[i];
  24144. var iNextNode = node.groups[i + 1];
  24145. var iNextNextNode = node.groups[i + 2]; // Ignore after latest node (i.e. before semicolon)
  24146. if (!iNextNode) {
  24147. continue;
  24148. } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
  24149. var isStartSCSSinterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
  24150. var isEndingSCSSinterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
  24151. if (isStartSCSSinterpolationInString || isEndingSCSSinterpolationInString) {
  24152. insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
  24153. continue;
  24154. }
  24155. if (insideSCSSInterpolationInString) {
  24156. continue;
  24157. } // Ignore colon (i.e. `:`)
  24158. if (isColonNode(iNode) || isColonNode(iNextNode)) {
  24159. continue;
  24160. } // Ignore `@` in Less (i.e. `@@var;`)
  24161. if (iNode.type === "value-atword" && iNode.value === "") {
  24162. continue;
  24163. } // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  24164. if (iNode.value === "~") {
  24165. continue;
  24166. } // Ignore escape `\`
  24167. if (iNode.value && iNode.value.indexOf("\\") !== -1 && iNextNode && iNextNode.type !== "value-comment") {
  24168. continue;
  24169. } // Ignore escaped `/`
  24170. if (iPrevNode && iPrevNode.value && iPrevNode.value.indexOf("\\") === iPrevNode.value.length - 1 && iNode.type === "value-operator" && iNode.value === "/") {
  24171. continue;
  24172. } // Ignore `\` (i.e. `$variable: \@small;`)
  24173. if (iNode.value === "\\") {
  24174. continue;
  24175. } // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
  24176. if (isPostcssSimpleVarNode(iNode, iNextNode)) {
  24177. continue;
  24178. } // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
  24179. if (isHashNode(iNode) || isLeftCurlyBraceNode(iNode) || isRightCurlyBraceNode(iNextNode) || isLeftCurlyBraceNode(iNextNode) && hasEmptyRawBefore(iNextNode) || isRightCurlyBraceNode(iNode) && hasEmptyRawBefore(iNextNode)) {
  24180. continue;
  24181. } // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
  24182. if (iNode.value === "--" && isHashNode(iNextNode)) {
  24183. continue;
  24184. } // Formatting math operations
  24185. var isMathOperator = isMathOperatorNode(iNode);
  24186. var isNextMathOperator = isMathOperatorNode(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
  24187. // (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
  24188. // (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
  24189. if ((isMathOperator && isHashNode(iNextNode) || isNextMathOperator && isRightCurlyBraceNode(iNode)) && hasEmptyRawBefore(iNextNode)) {
  24190. continue;
  24191. } // Print spaces before and after addition and subtraction math operators as is in `calc` function
  24192. // due to the fact that it is not valid syntax
  24193. // (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
  24194. if (insideValueFunctionNode(path$$1, "calc") && (isAdditionNode(iNode) || isAdditionNode(iNextNode) || isSubtractionNode(iNode) || isSubtractionNode(iNextNode)) && hasEmptyRawBefore(iNextNode)) {
  24195. continue;
  24196. } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
  24197. // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
  24198. var isColorAdjusterNode = (isAdditionNode(iNode) || isSubtractionNode(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode(parentParentNode) && !hasEmptyRawBefore(iNextNode);
  24199. var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode(iNextNextNode) || iNode.type === "value-func" || isWordNode(iNode);
  24200. var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode(iPrevNode); // Formatting `/`, `+`, `-` sign
  24201. 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)))) {
  24202. continue;
  24203. } // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
  24204. if (isInlineValueCommentNode(iNode)) {
  24205. _parts.push(hardline$6);
  24206. continue;
  24207. } // Handle keywords in SCSS control directive
  24208. if (isControlDirective && (isEqualityOperatorNode(iNextNode) || isRelationalOperatorNode(iNextNode) || isIfElseKeywordNode(iNextNode) || isEachKeywordNode(iNode) || isForKeywordNode(iNode))) {
  24209. _parts.push(" ");
  24210. continue;
  24211. } // At-rule `namespace` should be in one line
  24212. if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
  24213. _parts.push(" ");
  24214. continue;
  24215. } // Formatting `grid` property
  24216. if (isGridValue) {
  24217. if (iNode.source && iNextNode.source && iNode.source.start.line !== iNextNode.source.start.line) {
  24218. _parts.push(hardline$6);
  24219. didBreak = true;
  24220. } else {
  24221. _parts.push(" ");
  24222. }
  24223. continue;
  24224. } // Add `space` before next math operation
  24225. // Note: `grip` property have `/` delimiter and it is not math operation, so
  24226. // `grid` property handles above
  24227. if (isNextMathOperator) {
  24228. _parts.push(" ");
  24229. continue;
  24230. } // Be default all values go through `line`
  24231. _parts.push(line$5);
  24232. }
  24233. if (didBreak) {
  24234. _parts.unshift(hardline$6);
  24235. }
  24236. if (isControlDirective) {
  24237. return group$6(indent$5(concat$8(_parts)));
  24238. } // Indent is not needed for import url when url is very long
  24239. // and node has two groups
  24240. // when type is value-comma_group
  24241. // example @import url("verylongurl") projection,tv
  24242. if (insideURLFunctionInImportAtRuleNode(path$$1)) {
  24243. return group$6(fill$3(_parts));
  24244. }
  24245. return group$6(indent$5(fill$3(_parts)));
  24246. }
  24247. case "value-paren_group":
  24248. {
  24249. var _parentNode5 = path$$1.getParentNode();
  24250. 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:"))) {
  24251. return concat$8([node.open ? path$$1.call(print, "open") : "", join$6(",", path$$1.map(print, "groups")), node.close ? path$$1.call(print, "close") : ""]);
  24252. }
  24253. if (!node.open) {
  24254. var _printed = path$$1.map(print, "groups");
  24255. var res = [];
  24256. for (var _i = 0; _i < _printed.length; _i++) {
  24257. if (_i !== 0) {
  24258. res.push(concat$8([",", line$5]));
  24259. }
  24260. res.push(_printed[_i]);
  24261. }
  24262. return group$6(indent$5(fill$3(res)));
  24263. }
  24264. var isSCSSMapItem = isSCSSMapItemNode(path$$1);
  24265. 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) {
  24266. var node = childPath.getValue();
  24267. var printed = print(childPath); // Key/Value pair in open paren already indented
  24268. if (isKeyValuePairNode(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
  24269. printed.contents.contents.parts[1] = group$6(printed.contents.contents.parts[1]);
  24270. return group$6(dedent$3(printed));
  24271. }
  24272. return printed;
  24273. }, "groups"))])), ifBreak$2(isSCSS(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma$1(options) ? "," : ""), softline$3, node.close ? path$$1.call(print, "close") : ""]), {
  24274. shouldBreak: isSCSSMapItem
  24275. });
  24276. }
  24277. case "value-func":
  24278. {
  24279. return concat$8([node.value, insideAtRuleNode(path$$1, "supports") && isMediaAndSupportsKeywords(node) ? " " : "", path$$1.call(print, "group")]);
  24280. }
  24281. case "value-paren":
  24282. {
  24283. return node.value;
  24284. }
  24285. case "value-number":
  24286. {
  24287. return concat$8([printCssNumber(node.value), maybeToLowerCase(node.unit)]);
  24288. }
  24289. case "value-operator":
  24290. {
  24291. return node.value;
  24292. }
  24293. case "value-word":
  24294. {
  24295. if (node.isColor && node.isHex || isWideKeywords(node.value)) {
  24296. return node.value.toLowerCase();
  24297. }
  24298. return node.value;
  24299. }
  24300. case "value-colon":
  24301. {
  24302. return concat$8([node.value, // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
  24303. insideValueFunctionNode(path$$1, "url") ? "" : line$5]);
  24304. }
  24305. case "value-comma":
  24306. {
  24307. return concat$8([node.value, " "]);
  24308. }
  24309. case "value-string":
  24310. {
  24311. return printString$2(node.raws.quote + node.value + node.raws.quote, options);
  24312. }
  24313. case "value-atword":
  24314. {
  24315. return concat$8(["@", node.value]);
  24316. }
  24317. case "value-unicode-range":
  24318. {
  24319. return node.value;
  24320. }
  24321. case "value-unknown":
  24322. {
  24323. return node.value;
  24324. }
  24325. default:
  24326. /* istanbul ignore next */
  24327. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  24328. }
  24329. }
  24330. function printNodeSequence(path$$1, options, print) {
  24331. var node = path$$1.getValue();
  24332. var parts = [];
  24333. var i = 0;
  24334. path$$1.map(function (pathChild) {
  24335. var prevNode = node.nodes[i - 1];
  24336. if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
  24337. var childNode = pathChild.getValue();
  24338. parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
  24339. } else {
  24340. parts.push(pathChild.call(print));
  24341. }
  24342. if (i !== node.nodes.length - 1) {
  24343. if (node.nodes[i + 1].type === "css-comment" && !hasNewline$3(options.originalText, options.locStart(node.nodes[i + 1]), {
  24344. backwards: true
  24345. }) && 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") {
  24346. parts.push(" ");
  24347. } else {
  24348. parts.push(hardline$6);
  24349. if (isNextLineEmpty$3(options.originalText, pathChild.getValue(), options) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml") {
  24350. parts.push(hardline$6);
  24351. }
  24352. }
  24353. }
  24354. i++;
  24355. }, "nodes");
  24356. return concat$8(parts);
  24357. }
  24358. var STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  24359. var NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  24360. var STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  24361. var WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  24362. var ADJUST_NUMBERS_REGEX = RegExp(STRING_REGEX.source + `|` + `(${WORD_PART_REGEX.source})?` + `(${NUMBER_REGEX.source})` + `(${STANDARD_UNIT_REGEX.source})?`, "g");
  24363. function adjustStrings(value, options) {
  24364. return value.replace(STRING_REGEX, function (match) {
  24365. return printString$2(match, options);
  24366. });
  24367. }
  24368. function quoteAttributeValue(value, options) {
  24369. var quote = options.singleQuote ? "'" : '"';
  24370. return value.includes('"') || value.includes("'") ? value : quote + value + quote;
  24371. }
  24372. function adjustNumbers(value) {
  24373. return value.replace(ADJUST_NUMBERS_REGEX, function (match, quote, wordPart, number, unit) {
  24374. return !wordPart && number ? (wordPart || "") + printCssNumber(number) + maybeToLowerCase(unit || "") : match;
  24375. });
  24376. }
  24377. function printCssNumber(rawNumber) {
  24378. return printNumber$2(rawNumber) // Remove trailing `.0`.
  24379. .replace(/\.0(?=$|e)/, "");
  24380. }
  24381. var printerPostcss = {
  24382. print: genericPrint$2,
  24383. embed: embed_1$2,
  24384. insertPragma: insertPragma$2,
  24385. hasPrettierIgnore: hasIgnoreComment$2,
  24386. massageAstNode: clean_1$2
  24387. };
  24388. var options$6 = {
  24389. singleQuote: commonOptions.singleQuote
  24390. };
  24391. var name$7 = "CSS";
  24392. var type$6 = "markup";
  24393. var tmScope$6 = "source.css";
  24394. var aceMode$6 = "css";
  24395. var codemirrorMode$6 = "css";
  24396. var codemirrorMimeType$6 = "text/css";
  24397. var color$2 = "#563d7c";
  24398. var extensions$6 = [".css"];
  24399. var languageId$6 = 50;
  24400. var css$2 = {
  24401. name: name$7,
  24402. type: type$6,
  24403. tmScope: tmScope$6,
  24404. aceMode: aceMode$6,
  24405. codemirrorMode: codemirrorMode$6,
  24406. codemirrorMimeType: codemirrorMimeType$6,
  24407. color: color$2,
  24408. extensions: extensions$6,
  24409. languageId: languageId$6
  24410. };
  24411. var css$3 = Object.freeze({
  24412. name: name$7,
  24413. type: type$6,
  24414. tmScope: tmScope$6,
  24415. aceMode: aceMode$6,
  24416. codemirrorMode: codemirrorMode$6,
  24417. codemirrorMimeType: codemirrorMimeType$6,
  24418. color: color$2,
  24419. extensions: extensions$6,
  24420. languageId: languageId$6,
  24421. default: css$2
  24422. });
  24423. var name$8 = "PostCSS";
  24424. var type$7 = "markup";
  24425. var tmScope$7 = "source.postcss";
  24426. var group$7 = "CSS";
  24427. var extensions$7 = [".pcss"];
  24428. var aceMode$7 = "text";
  24429. var languageId$7 = 262764437;
  24430. var postcss = {
  24431. name: name$8,
  24432. type: type$7,
  24433. tmScope: tmScope$7,
  24434. group: group$7,
  24435. extensions: extensions$7,
  24436. aceMode: aceMode$7,
  24437. languageId: languageId$7
  24438. };
  24439. var postcss$1 = Object.freeze({
  24440. name: name$8,
  24441. type: type$7,
  24442. tmScope: tmScope$7,
  24443. group: group$7,
  24444. extensions: extensions$7,
  24445. aceMode: aceMode$7,
  24446. languageId: languageId$7,
  24447. default: postcss
  24448. });
  24449. var name$9 = "Less";
  24450. var type$8 = "markup";
  24451. var group$8 = "CSS";
  24452. var extensions$8 = [".less"];
  24453. var tmScope$8 = "source.css.less";
  24454. var aceMode$8 = "less";
  24455. var codemirrorMode$7 = "css";
  24456. var codemirrorMimeType$7 = "text/css";
  24457. var languageId$8 = 198;
  24458. var less = {
  24459. name: name$9,
  24460. type: type$8,
  24461. group: group$8,
  24462. extensions: extensions$8,
  24463. tmScope: tmScope$8,
  24464. aceMode: aceMode$8,
  24465. codemirrorMode: codemirrorMode$7,
  24466. codemirrorMimeType: codemirrorMimeType$7,
  24467. languageId: languageId$8
  24468. };
  24469. var less$1 = Object.freeze({
  24470. name: name$9,
  24471. type: type$8,
  24472. group: group$8,
  24473. extensions: extensions$8,
  24474. tmScope: tmScope$8,
  24475. aceMode: aceMode$8,
  24476. codemirrorMode: codemirrorMode$7,
  24477. codemirrorMimeType: codemirrorMimeType$7,
  24478. languageId: languageId$8,
  24479. default: less
  24480. });
  24481. var name$10 = "SCSS";
  24482. var type$9 = "markup";
  24483. var tmScope$9 = "source.scss";
  24484. var group$9 = "CSS";
  24485. var aceMode$9 = "scss";
  24486. var codemirrorMode$8 = "css";
  24487. var codemirrorMimeType$8 = "text/x-scss";
  24488. var extensions$9 = [".scss"];
  24489. var languageId$9 = 329;
  24490. var scss = {
  24491. name: name$10,
  24492. type: type$9,
  24493. tmScope: tmScope$9,
  24494. group: group$9,
  24495. aceMode: aceMode$9,
  24496. codemirrorMode: codemirrorMode$8,
  24497. codemirrorMimeType: codemirrorMimeType$8,
  24498. extensions: extensions$9,
  24499. languageId: languageId$9
  24500. };
  24501. var scss$1 = Object.freeze({
  24502. name: name$10,
  24503. type: type$9,
  24504. tmScope: tmScope$9,
  24505. group: group$9,
  24506. aceMode: aceMode$9,
  24507. codemirrorMode: codemirrorMode$8,
  24508. codemirrorMimeType: codemirrorMimeType$8,
  24509. extensions: extensions$9,
  24510. languageId: languageId$9,
  24511. default: scss
  24512. });
  24513. var require$$0$23 = ( css$3 && css$2 ) || css$3;
  24514. var require$$1$9 = ( postcss$1 && postcss ) || postcss$1;
  24515. var require$$2$11 = ( less$1 && less ) || less$1;
  24516. var require$$3$4 = ( scss$1 && scss ) || scss$1;
  24517. var languages$1 = [createLanguage(require$$0$23, {
  24518. override: {
  24519. since: "1.4.0",
  24520. parsers: ["css"],
  24521. vscodeLanguageIds: ["css"]
  24522. }
  24523. }), createLanguage(require$$1$9, {
  24524. override: {
  24525. since: "1.4.0",
  24526. parsers: ["css"],
  24527. vscodeLanguageIds: ["postcss"]
  24528. },
  24529. extend: {
  24530. extensions: [".postcss"]
  24531. }
  24532. }), createLanguage(require$$2$11, {
  24533. override: {
  24534. since: "1.4.0",
  24535. parsers: ["less"],
  24536. vscodeLanguageIds: ["less"]
  24537. }
  24538. }), createLanguage(require$$3$4, {
  24539. override: {
  24540. since: "1.4.0",
  24541. parsers: ["scss"],
  24542. vscodeLanguageIds: ["scss"]
  24543. }
  24544. })];
  24545. var printers$1 = {
  24546. postcss: printerPostcss
  24547. };
  24548. var languageCss = {
  24549. languages: languages$1,
  24550. options: options$6,
  24551. printers: printers$1
  24552. };
  24553. var _require$$0$builders$4 = doc.builders;
  24554. var concat$10 = _require$$0$builders$4.concat;
  24555. var join$7 = _require$$0$builders$4.join;
  24556. var softline$4 = _require$$0$builders$4.softline;
  24557. var hardline$8 = _require$$0$builders$4.hardline;
  24558. var line$6 = _require$$0$builders$4.line;
  24559. var group$10 = _require$$0$builders$4.group;
  24560. var indent$6 = _require$$0$builders$4.indent;
  24561. var ifBreak$3 = _require$$0$builders$4.ifBreak; // http://w3c.github.io/html/single-page.html#void-elements
  24562. 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:
  24563. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  24564. function print(path$$1, options, print) {
  24565. var n = path$$1.getValue();
  24566. /* istanbul ignore if*/
  24567. if (!n) {
  24568. return "";
  24569. }
  24570. switch (n.type) {
  24571. case "Program":
  24572. {
  24573. return group$10(join$7(softline$4, path$$1.map(print, "body").filter(function (text) {
  24574. return text !== "";
  24575. })));
  24576. }
  24577. case "ElementNode":
  24578. {
  24579. var tagFirstChar = n.tag[0];
  24580. var isLocal = n.tag.indexOf(".") !== -1;
  24581. var isGlimmerComponent = tagFirstChar.toUpperCase() === tagFirstChar || isLocal;
  24582. var hasChildren = n.children.length > 0;
  24583. var isVoid = isGlimmerComponent && !hasChildren || voidTags.indexOf(n.tag) !== -1;
  24584. var closeTag = isVoid ? concat$10([" />", softline$4]) : ">";
  24585. var _getParams = function _getParams(path$$1, print) {
  24586. 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"))]));
  24587. }; // The problem here is that I want to not break at all if the children
  24588. // would not break but I need to force an indent, so I use a hardline.
  24589. /**
  24590. * What happens now:
  24591. * <div>
  24592. * Hello
  24593. * </div>
  24594. * ==>
  24595. * <div>Hello</div>
  24596. * This is due to me using hasChildren to decide to put the hardline in.
  24597. * I would rather use a {DOES THE WHOLE THING NEED TO BREAK}
  24598. */
  24599. return concat$10([group$10(concat$10(["<", n.tag, _getParams(path$$1, print), n.blockParams.length ? ` as |${n.blockParams.join(" ")}|` : "", ifBreak$3(softline$4, ""), closeTag])), 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, ">"]) : ""]))]);
  24600. }
  24601. case "BlockStatement":
  24602. {
  24603. var pp = path$$1.getParentNode(1);
  24604. var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
  24605. var hasElseIf = n.inverse && n.inverse.body[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
  24606. var indentElse = hasElseIf ? function (a) {
  24607. return a;
  24608. } : indent$6;
  24609. if (n.inverse) {
  24610. 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)])]);
  24611. } else if (isElseIf) {
  24612. return concat$10([concat$10(["{{else ", printPathParams(path$$1, print), "}}"]), indent$6(concat$10([hardline$8, path$$1.call(print, "program")]))]);
  24613. }
  24614. /**
  24615. * I want this boolean to be: if params are going to cause a break,
  24616. * not that it has params.
  24617. */
  24618. var hasParams = n.params.length > 0 || n.hash.pairs.length > 0;
  24619. var _hasChildren = n.program.body.length > 0;
  24620. 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)]))]);
  24621. }
  24622. case "ElementModifierStatement":
  24623. case "MustacheStatement":
  24624. {
  24625. var _pp = path$$1.getParentNode(1);
  24626. var isConcat = _pp && _pp.type === "ConcatStatement";
  24627. return group$10(concat$10([n.escaped === false ? "{{{" : "{{", printPathParams(path$$1, print), isConcat ? "" : softline$4, n.escaped === false ? "}}}" : "}}"]));
  24628. }
  24629. case "SubExpression":
  24630. {
  24631. var params = getParams(path$$1, print);
  24632. var printedParams = params.length > 0 ? indent$6(concat$10([line$6, group$10(join$7(line$6, params))])) : "";
  24633. return group$10(concat$10(["(", printPath(path$$1, print), printedParams, softline$4, ")"]));
  24634. }
  24635. case "AttrNode":
  24636. {
  24637. var isText = n.value.type === "TextNode";
  24638. if (isText && n.value.loc.start.column === n.value.loc.end.column) {
  24639. return concat$10([n.name]);
  24640. }
  24641. var quote = isText ? '"' : "";
  24642. return concat$10([n.name, "=", quote, path$$1.call(print, "value"), quote]);
  24643. }
  24644. case "ConcatStatement":
  24645. {
  24646. return concat$10(['"', group$10(indent$6(join$7(softline$4, path$$1.map(function (partPath) {
  24647. return print(partPath);
  24648. }, "parts").filter(function (a) {
  24649. return a !== "";
  24650. })))), '"']);
  24651. }
  24652. case "Hash":
  24653. {
  24654. return concat$10([join$7(line$6, path$$1.map(print, "pairs"))]);
  24655. }
  24656. case "HashPair":
  24657. {
  24658. return concat$10([n.key, "=", path$$1.call(print, "value")]);
  24659. }
  24660. case "TextNode":
  24661. {
  24662. var leadingSpace = "";
  24663. var trailingSpace = ""; // preserve a space inside of an attribute node where whitespace present, when next to mustache statement.
  24664. var inAttrNode = path$$1.stack.indexOf("attributes") >= 0;
  24665. if (inAttrNode) {
  24666. var parentNode = path$$1.getParentNode(0);
  24667. var _isConcat = parentNode.type === "ConcatStatement";
  24668. if (_isConcat) {
  24669. var parts = parentNode.parts;
  24670. var partIndex = parts.indexOf(n);
  24671. if (partIndex > 0) {
  24672. var partType = parts[partIndex - 1].type;
  24673. var isMustache = partType === "MustacheStatement";
  24674. if (isMustache) {
  24675. leadingSpace = " ";
  24676. }
  24677. }
  24678. if (partIndex < parts.length - 1) {
  24679. var _partType = parts[partIndex + 1].type;
  24680. var _isMustache = _partType === "MustacheStatement";
  24681. if (_isMustache) {
  24682. trailingSpace = " ";
  24683. }
  24684. }
  24685. }
  24686. }
  24687. return n.chars.replace(/^\s+/, leadingSpace).replace(/\s+$/, trailingSpace);
  24688. }
  24689. case "MustacheCommentStatement":
  24690. {
  24691. var dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  24692. return concat$10(["{{!", dashes, n.value, dashes, "}}"]);
  24693. }
  24694. case "PathExpression":
  24695. {
  24696. return n.original;
  24697. }
  24698. case "BooleanLiteral":
  24699. {
  24700. return String(n.value);
  24701. }
  24702. case "CommentStatement":
  24703. {
  24704. return concat$10(["<!--", n.value, "-->"]);
  24705. }
  24706. case "StringLiteral":
  24707. {
  24708. return printStringLiteral(n.value, options);
  24709. }
  24710. case "NumberLiteral":
  24711. {
  24712. return String(n.value);
  24713. }
  24714. case "UndefinedLiteral":
  24715. {
  24716. return "undefined";
  24717. }
  24718. case "NullLiteral":
  24719. {
  24720. return "null";
  24721. }
  24722. /* istanbul ignore next */
  24723. default:
  24724. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  24725. }
  24726. }
  24727. /**
  24728. * Prints a string literal with the correct surrounding quotes based on
  24729. * `options.singleQuote` and the number of escaped quotes contained in
  24730. * the string literal. This function is the glimmer equivalent of `printString`
  24731. * in `common/util`, but has differences because of the way escaped characters
  24732. * are treated in hbs string literals.
  24733. * @param {string} stringLiteral - the string literal value
  24734. * @param {object} options - the prettier options object
  24735. */
  24736. function printStringLiteral(stringLiteral, options) {
  24737. var double = {
  24738. quote: '"',
  24739. regex: /"/g
  24740. };
  24741. var single = {
  24742. quote: "'",
  24743. regex: /'/g
  24744. };
  24745. var preferred = options.singleQuote ? single : double;
  24746. var alternate = preferred === single ? double : single;
  24747. var shouldUseAlternateQuote = false; // If `stringLiteral` contains at least one of the quote preferred for
  24748. // enclosing the string, we might want to enclose with the alternate quote
  24749. // instead, to minimize the number of escaped quotes.
  24750. if (stringLiteral.includes(preferred.quote) || stringLiteral.includes(alternate.quote)) {
  24751. var numPreferredQuotes = (stringLiteral.match(preferred.regex) || []).length;
  24752. var numAlternateQuotes = (stringLiteral.match(alternate.regex) || []).length;
  24753. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  24754. }
  24755. var enclosingQuote = shouldUseAlternateQuote ? alternate : preferred;
  24756. var escapedStringLiteral = stringLiteral.replace(enclosingQuote.regex, `\\${enclosingQuote.quote}`);
  24757. return `${enclosingQuote.quote}${escapedStringLiteral}${enclosingQuote.quote}`;
  24758. }
  24759. function printPath(path$$1, print) {
  24760. return path$$1.call(print, "path");
  24761. }
  24762. function getParams(path$$1, print) {
  24763. var node = path$$1.getValue();
  24764. var parts = [];
  24765. if (node.params.length > 0) {
  24766. parts = parts.concat(path$$1.map(print, "params"));
  24767. }
  24768. if (node.hash && node.hash.pairs.length > 0) {
  24769. parts.push(path$$1.call(print, "hash"));
  24770. }
  24771. return parts;
  24772. }
  24773. function printPathParams(path$$1, print) {
  24774. var parts = [];
  24775. parts.push(printPath(path$$1, print));
  24776. parts = parts.concat(getParams(path$$1, print));
  24777. return indent$6(group$10(join$7(line$6, parts)));
  24778. }
  24779. function printBlockParams(path$$1) {
  24780. var block = path$$1.getValue();
  24781. if (!block.program || !block.program.blockParams.length) {
  24782. return "";
  24783. }
  24784. return concat$10([" as |", block.program.blockParams.join(" "), "|"]);
  24785. }
  24786. function printOpenBlock(path$$1, print) {
  24787. return group$10(concat$10(["{{#", printPathParams(path$$1, print), printBlockParams(path$$1), softline$4, "}}"]));
  24788. }
  24789. function printCloseBlock(path$$1, print) {
  24790. return concat$10(["{{/", path$$1.call(print, "path"), "}}"]);
  24791. }
  24792. function clean$5(ast, newObj) {
  24793. delete newObj.loc; // (Glimmer/HTML) ignore TextNode whitespace
  24794. if (ast.type === "TextNode") {
  24795. if (ast.chars.replace(/\s+/, "") === "") {
  24796. return null;
  24797. }
  24798. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  24799. }
  24800. }
  24801. var printerGlimmer = {
  24802. print,
  24803. massageAstNode: clean$5
  24804. };
  24805. var name$11 = "Handlebars";
  24806. var type$10 = "markup";
  24807. var group$11 = "HTML";
  24808. var aliases$3 = ["hbs", "htmlbars"];
  24809. var extensions$10 = [".handlebars", ".hbs"];
  24810. var tmScope$10 = "text.html.handlebars";
  24811. var aceMode$10 = "handlebars";
  24812. var languageId$10 = 155;
  24813. var handlebars = {
  24814. name: name$11,
  24815. type: type$10,
  24816. group: group$11,
  24817. aliases: aliases$3,
  24818. extensions: extensions$10,
  24819. tmScope: tmScope$10,
  24820. aceMode: aceMode$10,
  24821. languageId: languageId$10
  24822. };
  24823. var handlebars$1 = Object.freeze({
  24824. name: name$11,
  24825. type: type$10,
  24826. group: group$11,
  24827. aliases: aliases$3,
  24828. extensions: extensions$10,
  24829. tmScope: tmScope$10,
  24830. aceMode: aceMode$10,
  24831. languageId: languageId$10,
  24832. default: handlebars
  24833. });
  24834. var require$$0$24 = ( handlebars$1 && handlebars ) || handlebars$1;
  24835. var languages$2 = [createLanguage(require$$0$24, {
  24836. override: {
  24837. since: null,
  24838. // unreleased
  24839. parsers: ["glimmer"],
  24840. vscodeLanguageIds: ["handlebars"]
  24841. }
  24842. })];
  24843. var printers$2 = {
  24844. glimmer: printerGlimmer
  24845. };
  24846. var languageHandlebars = {
  24847. languages: languages$2,
  24848. printers: printers$2
  24849. };
  24850. function hasPragma$2(text) {
  24851. return /^\s*#[^\n\S]*@(format|prettier)\s*(\n|$)/.test(text);
  24852. }
  24853. function insertPragma$5(text) {
  24854. return "# @format\n\n" + text;
  24855. }
  24856. var pragma$4 = {
  24857. hasPragma: hasPragma$2,
  24858. insertPragma: insertPragma$5
  24859. };
  24860. var _require$$0$builders$5 = doc.builders;
  24861. var concat$11 = _require$$0$builders$5.concat;
  24862. var join$8 = _require$$0$builders$5.join;
  24863. var hardline$9 = _require$$0$builders$5.hardline;
  24864. var line$7 = _require$$0$builders$5.line;
  24865. var softline$5 = _require$$0$builders$5.softline;
  24866. var group$12 = _require$$0$builders$5.group;
  24867. var indent$7 = _require$$0$builders$5.indent;
  24868. var ifBreak$4 = _require$$0$builders$5.ifBreak;
  24869. var hasIgnoreComment$3 = util$1.hasIgnoreComment;
  24870. var isNextLineEmpty$4 = utilShared.isNextLineEmpty;
  24871. var insertPragma$4 = pragma$4.insertPragma;
  24872. function genericPrint$3(path$$1, options, print) {
  24873. var n = path$$1.getValue();
  24874. if (!n) {
  24875. return "";
  24876. }
  24877. if (typeof n === "string") {
  24878. return n;
  24879. }
  24880. switch (n.kind) {
  24881. case "Document":
  24882. {
  24883. var parts = [];
  24884. path$$1.map(function (pathChild, index) {
  24885. parts.push(concat$11([pathChild.call(print)]));
  24886. if (index !== n.definitions.length - 1) {
  24887. parts.push(hardline$9);
  24888. if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
  24889. parts.push(hardline$9);
  24890. }
  24891. }
  24892. }, "definitions");
  24893. return concat$11([concat$11(parts), hardline$9]);
  24894. }
  24895. case "OperationDefinition":
  24896. {
  24897. var hasOperation = options.originalText[options.locStart(n)] !== "{";
  24898. var hasName = !!n.name;
  24899. 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")]);
  24900. }
  24901. case "FragmentDefinition":
  24902. {
  24903. return concat$11(["fragment ", path$$1.call(print, "name"), " on ", path$$1.call(print, "typeCondition"), printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  24904. }
  24905. case "SelectionSet":
  24906. {
  24907. return concat$11(["{", indent$7(concat$11([hardline$9, join$8(hardline$9, path$$1.call(function (selectionsPath) {
  24908. return printSequence(selectionsPath, options, print);
  24909. }, "selections"))])), hardline$9, "}"]);
  24910. }
  24911. case "Field":
  24912. {
  24913. 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) {
  24914. return printSequence(argsPath, options, print);
  24915. }, "arguments"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? " " : "", path$$1.call(print, "selectionSet")]));
  24916. }
  24917. case "Name":
  24918. {
  24919. return n.value;
  24920. }
  24921. case "StringValue":
  24922. {
  24923. if (n.block) {
  24924. return concat$11(['"""', hardline$9, join$8(hardline$9, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$9, '"""']);
  24925. }
  24926. return concat$11(['"', n.value.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\n"), '"']);
  24927. }
  24928. case "IntValue":
  24929. case "FloatValue":
  24930. case "EnumValue":
  24931. {
  24932. return n.value;
  24933. }
  24934. case "BooleanValue":
  24935. {
  24936. return n.value ? "true" : "false";
  24937. }
  24938. case "NullValue":
  24939. {
  24940. return "null";
  24941. }
  24942. case "Variable":
  24943. {
  24944. return concat$11(["$", path$$1.call(print, "name")]);
  24945. }
  24946. case "ListValue":
  24947. {
  24948. 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, "]"]));
  24949. }
  24950. case "ObjectValue":
  24951. {
  24952. 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 ? " " : ""), "}"]));
  24953. }
  24954. case "ObjectField":
  24955. case "Argument":
  24956. {
  24957. return concat$11([path$$1.call(print, "name"), ": ", path$$1.call(print, "value")]);
  24958. }
  24959. case "Directive":
  24960. {
  24961. 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) {
  24962. return printSequence(argsPath, options, print);
  24963. }, "arguments"))])), softline$5, ")"])) : ""]);
  24964. }
  24965. case "NamedType":
  24966. {
  24967. return path$$1.call(print, "name");
  24968. }
  24969. case "VariableDefinition":
  24970. {
  24971. return concat$11([path$$1.call(print, "variable"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$11([" = ", path$$1.call(print, "defaultValue")]) : ""]);
  24972. }
  24973. case "TypeExtensionDefinition":
  24974. {
  24975. return concat$11(["extend ", path$$1.call(print, "definition")]);
  24976. }
  24977. case "ObjectTypeExtension":
  24978. case "ObjectTypeDefinition":
  24979. {
  24980. 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) {
  24981. return printSequence(fieldsPath, options, print);
  24982. }, "fields"))])), hardline$9, "}"]) : ""]);
  24983. }
  24984. case "FieldDefinition":
  24985. {
  24986. 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) {
  24987. return printSequence(argsPath, options, print);
  24988. }, "arguments"))])), softline$5, ")"])) : "", ": ", path$$1.call(print, "type"), printDirectives(path$$1, print, n)]);
  24989. }
  24990. case "DirectiveDefinition":
  24991. {
  24992. 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) {
  24993. return printSequence(argsPath, options, print);
  24994. }, "arguments"))])), softline$5, ")"])) : "", concat$11([" on ", join$8(" | ", path$$1.map(print, "locations"))])]);
  24995. }
  24996. case "EnumTypeExtension":
  24997. case "EnumTypeDefinition":
  24998. {
  24999. 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) {
  25000. return printSequence(valuesPath, options, print);
  25001. }, "values"))])), hardline$9, "}"]) : ""]);
  25002. }
  25003. case "EnumValueDefinition":
  25004. {
  25005. return concat$11([path$$1.call(print, "description"), n.description ? hardline$9 : "", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  25006. }
  25007. case "InputValueDefinition":
  25008. {
  25009. 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)]);
  25010. }
  25011. case "InputObjectTypeExtension":
  25012. case "InputObjectTypeDefinition":
  25013. {
  25014. 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) {
  25015. return printSequence(fieldsPath, options, print);
  25016. }, "fields"))])), hardline$9, "}"]) : ""]);
  25017. }
  25018. case "SchemaDefinition":
  25019. {
  25020. 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) {
  25021. return printSequence(opsPath, options, print);
  25022. }, "operationTypes"))])) : "", hardline$9, "}"]);
  25023. }
  25024. case "OperationTypeDefinition":
  25025. {
  25026. return concat$11([path$$1.call(print, "operation"), ": ", path$$1.call(print, "type")]);
  25027. }
  25028. case "InterfaceTypeExtension":
  25029. case "InterfaceTypeDefinition":
  25030. {
  25031. 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) {
  25032. return printSequence(fieldsPath, options, print);
  25033. }, "fields"))])), hardline$9, "}"]) : ""]);
  25034. }
  25035. case "FragmentSpread":
  25036. {
  25037. return concat$11(["...", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  25038. }
  25039. case "InlineFragment":
  25040. {
  25041. return concat$11(["...", n.typeCondition ? concat$11([" on ", path$$1.call(print, "typeCondition")]) : "", printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  25042. }
  25043. case "UnionTypeExtension":
  25044. case "UnionTypeDefinition":
  25045. {
  25046. 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"))]))]) : ""]))]));
  25047. }
  25048. case "ScalarTypeExtension":
  25049. case "ScalarTypeDefinition":
  25050. {
  25051. 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)]);
  25052. }
  25053. case "NonNullType":
  25054. {
  25055. return concat$11([path$$1.call(print, "type"), "!"]);
  25056. }
  25057. case "ListType":
  25058. {
  25059. return concat$11(["[", path$$1.call(print, "type"), "]"]);
  25060. }
  25061. default:
  25062. /* istanbul ignore next */
  25063. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  25064. }
  25065. }
  25066. function printDirectives(path$$1, print, n) {
  25067. if (n.directives.length === 0) {
  25068. return "";
  25069. }
  25070. return concat$11([" ", group$12(indent$7(concat$11([softline$5, join$8(concat$11([ifBreak$4("", " "), softline$5]), path$$1.map(print, "directives"))])))]);
  25071. }
  25072. function printSequence(sequencePath, options, print) {
  25073. var count = sequencePath.getValue().length;
  25074. return sequencePath.map(function (path$$1, i) {
  25075. var printed = print(path$$1);
  25076. if (isNextLineEmpty$4(options.originalText, path$$1.getValue(), options) && i < count - 1) {
  25077. return concat$11([printed, hardline$9]);
  25078. }
  25079. return printed;
  25080. });
  25081. }
  25082. function canAttachComment$1(node) {
  25083. return node.kind && node.kind !== "Comment";
  25084. }
  25085. function printComment$2(commentPath) {
  25086. var comment = commentPath.getValue();
  25087. if (comment.kind === "Comment") {
  25088. return "#" + comment.value.trimRight();
  25089. }
  25090. throw new Error("Not a comment: " + JSON.stringify(comment));
  25091. }
  25092. function determineInterfaceSeparator(originalSource) {
  25093. var start = originalSource.indexOf("implements");
  25094. if (start === -1) {
  25095. throw new Error("Must implement interfaces: " + originalSource);
  25096. }
  25097. var end = originalSource.indexOf("{");
  25098. if (end === -1) {
  25099. end = originalSource.length;
  25100. }
  25101. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  25102. }
  25103. function clean$6(node, newNode
  25104. /*, parent*/
  25105. ) {
  25106. delete newNode.loc;
  25107. delete newNode.comments;
  25108. }
  25109. var printerGraphql = {
  25110. print: genericPrint$3,
  25111. massageAstNode: clean$6,
  25112. hasPrettierIgnore: hasIgnoreComment$3,
  25113. insertPragma: insertPragma$4,
  25114. printComment: printComment$2,
  25115. canAttachComment: canAttachComment$1
  25116. };
  25117. var options$9 = {
  25118. bracketSpacing: commonOptions.bracketSpacing
  25119. };
  25120. var name$12 = "GraphQL";
  25121. var type$11 = "data";
  25122. var extensions$11 = [".graphql", ".gql"];
  25123. var tmScope$11 = "source.graphql";
  25124. var aceMode$11 = "text";
  25125. var languageId$11 = 139;
  25126. var graphql = {
  25127. name: name$12,
  25128. type: type$11,
  25129. extensions: extensions$11,
  25130. tmScope: tmScope$11,
  25131. aceMode: aceMode$11,
  25132. languageId: languageId$11
  25133. };
  25134. var graphql$1 = Object.freeze({
  25135. name: name$12,
  25136. type: type$11,
  25137. extensions: extensions$11,
  25138. tmScope: tmScope$11,
  25139. aceMode: aceMode$11,
  25140. languageId: languageId$11,
  25141. default: graphql
  25142. });
  25143. var require$$0$25 = ( graphql$1 && graphql ) || graphql$1;
  25144. var languages$3 = [createLanguage(require$$0$25, {
  25145. override: {
  25146. since: "1.5.0",
  25147. parsers: ["graphql"],
  25148. vscodeLanguageIds: ["graphql"]
  25149. }
  25150. })];
  25151. var printers$3 = {
  25152. graphql: printerGraphql
  25153. };
  25154. var languageGraphql = {
  25155. languages: languages$3,
  25156. options: options$9,
  25157. printers: printers$3
  25158. };
  25159. 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]"};
  25160. var cjkPattern = json$6.cjkPattern;
  25161. var kPattern = json$6.kPattern;
  25162. var punctuationPattern$1 = json$6.punctuationPattern;
  25163. var getLast$5 = util$1.getLast;
  25164. var INLINE_NODE_TYPES$1 = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
  25165. var INLINE_NODE_WRAPPER_TYPES$1 = INLINE_NODE_TYPES$1.concat(["tableCell", "paragraph", "heading"]);
  25166. var kRegex = new RegExp(kPattern);
  25167. var punctuationRegex = new RegExp(punctuationPattern$1);
  25168. /**
  25169. * split text into whitespaces and words
  25170. * @param {string} text
  25171. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  25172. */
  25173. function splitText$1(text, options) {
  25174. var KIND_NON_CJK = "non-cjk";
  25175. var KIND_CJ_LETTER = "cj-letter";
  25176. var KIND_K_LETTER = "k-letter";
  25177. var KIND_CJK_PUNCTUATION = "cjk-punctuation";
  25178. var nodes = [];
  25179. (options.proseWrap === "preserve" ? text : text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")).split(/([ \t\n]+)/).forEach(function (token, index, tokens) {
  25180. // whitespace
  25181. if (index % 2 === 1) {
  25182. nodes.push({
  25183. type: "whitespace",
  25184. value: /\n/.test(token) ? "\n" : " "
  25185. });
  25186. return;
  25187. } // word separated by whitespace
  25188. if ((index === 0 || index === tokens.length - 1) && token === "") {
  25189. return;
  25190. }
  25191. token.split(new RegExp(`(${cjkPattern})`)).forEach(function (innerToken, innerIndex, innerTokens) {
  25192. if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
  25193. return;
  25194. } // non-CJK word
  25195. if (innerIndex % 2 === 0) {
  25196. if (innerToken !== "") {
  25197. appendNode({
  25198. type: "word",
  25199. value: innerToken,
  25200. kind: KIND_NON_CJK,
  25201. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  25202. hasTrailingPunctuation: punctuationRegex.test(getLast$5(innerToken))
  25203. });
  25204. }
  25205. return;
  25206. } // CJK character
  25207. appendNode(punctuationRegex.test(innerToken) ? {
  25208. type: "word",
  25209. value: innerToken,
  25210. kind: KIND_CJK_PUNCTUATION,
  25211. hasLeadingPunctuation: true,
  25212. hasTrailingPunctuation: true
  25213. } : {
  25214. type: "word",
  25215. value: innerToken,
  25216. kind: kRegex.test(innerToken) ? KIND_K_LETTER : KIND_CJ_LETTER,
  25217. hasLeadingPunctuation: false,
  25218. hasTrailingPunctuation: false
  25219. });
  25220. });
  25221. });
  25222. return nodes;
  25223. function appendNode(node) {
  25224. var lastNode = getLast$5(nodes);
  25225. if (lastNode && lastNode.type === "word") {
  25226. 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) {
  25227. nodes.push({
  25228. type: "whitespace",
  25229. value: " "
  25230. });
  25231. } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
  25232. ![lastNode.value, node.value].some(function (value) {
  25233. return /\u3000/.test(value);
  25234. })) {
  25235. nodes.push({
  25236. type: "whitespace",
  25237. value: ""
  25238. });
  25239. }
  25240. }
  25241. nodes.push(node);
  25242. function isBetween(kind1, kind2) {
  25243. return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
  25244. }
  25245. }
  25246. }
  25247. function getOrderedListItemInfo$1(orderListItem, originalText) {
  25248. var _originalText$slice$m = originalText.slice(orderListItem.position.start.offset, orderListItem.position.end.offset).match(/^\s*(\d+)(\.|\))(\s*)/),
  25249. _originalText$slice$m2 = _slicedToArray(_originalText$slice$m, 4),
  25250. numberText = _originalText$slice$m2[1],
  25251. marker = _originalText$slice$m2[2],
  25252. leadingSpaces = _originalText$slice$m2[3];
  25253. return {
  25254. numberText,
  25255. marker,
  25256. leadingSpaces
  25257. };
  25258. } // workaround for https://github.com/remarkjs/remark/issues/351
  25259. // leading and trailing newlines are stripped by remark
  25260. function getFencedCodeBlockValue$2(node, originalText) {
  25261. var text = originalText.slice(node.position.start.offset, node.position.end.offset);
  25262. var leadingSpaceCount = text.match(/^\s*/)[0].length;
  25263. var replaceRegex = new RegExp(`^\\s{0,${leadingSpaceCount}}`);
  25264. var lineContents = text.split("\n");
  25265. var markerStyle = text[leadingSpaceCount]; // ` or ~
  25266. 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
  25267. // https://spec.commonmark.org/0.28/#example-93: The closing code fence must be at least as long as the opening fence
  25268. var hasEndMarker = new RegExp(`^\\s{0,3}${marker}`).test(lineContents[lineContents.length - 1].slice(getIndent(lineContents.length - 1)));
  25269. return lineContents.slice(1, hasEndMarker ? -1 : undefined).map(function (x, i) {
  25270. return x.slice(getIndent(i + 1)).replace(replaceRegex, "");
  25271. }).join("\n");
  25272. function getIndent(lineIndex) {
  25273. return node.position.indent[lineIndex - 1] - 1;
  25274. }
  25275. }
  25276. function mapAst(ast, handler) {
  25277. return function preorder(node, index, parentStack) {
  25278. parentStack = parentStack || [];
  25279. var newNode = Object.assign({}, handler(node, index, parentStack));
  25280. if (newNode.children) {
  25281. newNode.children = newNode.children.map(function (child, index) {
  25282. return preorder(child, index, [newNode].concat(parentStack));
  25283. });
  25284. }
  25285. return newNode;
  25286. }(ast, null, null);
  25287. }
  25288. var utils$8 = {
  25289. mapAst,
  25290. splitText: splitText$1,
  25291. punctuationPattern: punctuationPattern$1,
  25292. getFencedCodeBlockValue: getFencedCodeBlockValue$2,
  25293. getOrderedListItemInfo: getOrderedListItemInfo$1,
  25294. INLINE_NODE_TYPES: INLINE_NODE_TYPES$1,
  25295. INLINE_NODE_WRAPPER_TYPES: INLINE_NODE_WRAPPER_TYPES$1
  25296. };
  25297. var _require$$0$builders$7 = doc.builders;
  25298. var hardline$11 = _require$$0$builders$7.hardline;
  25299. var literalline$5 = _require$$0$builders$7.literalline;
  25300. var concat$13 = _require$$0$builders$7.concat;
  25301. var markAsRoot$3 = _require$$0$builders$7.markAsRoot;
  25302. var mapDoc$6 = doc.utils.mapDoc;
  25303. var getFencedCodeBlockValue$1 = utils$8.getFencedCodeBlockValue;
  25304. function embed$4(path$$1, print, textToDoc, options) {
  25305. var node = path$$1.getValue();
  25306. if (node.type === "code" && node.lang !== null) {
  25307. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  25308. var langMatch = node.lang.match(/^[A-Za-z0-9_-]+/);
  25309. var lang = langMatch ? langMatch[0] : "";
  25310. var parser = getParserName(lang);
  25311. if (parser) {
  25312. var styleUnit = options.__inJsTemplate ? "~" : "`";
  25313. var style = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  25314. var doc$$2 = textToDoc(getFencedCodeBlockValue$1(node, options.originalText), {
  25315. parser
  25316. });
  25317. return markAsRoot$3(concat$13([style, node.lang, hardline$11, replaceNewlinesWithLiterallines(doc$$2), style]));
  25318. }
  25319. }
  25320. if (node.type === "yaml") {
  25321. return markAsRoot$3(concat$13(["---", hardline$11, node.value && node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  25322. parser: "yaml"
  25323. })) : "", "---"]));
  25324. } // MDX
  25325. switch (node.type) {
  25326. case "importExport":
  25327. return textToDoc(node.value, {
  25328. parser: "babel"
  25329. });
  25330. case "jsx":
  25331. return textToDoc(node.value, {
  25332. parser: "__js_expression"
  25333. });
  25334. }
  25335. return null;
  25336. function getParserName(lang) {
  25337. var supportInfo = support.getSupportInfo(null, {
  25338. plugins: options.plugins
  25339. });
  25340. var language = supportInfo.languages.find(function (language) {
  25341. return language.name.toLowerCase() === lang || language.aliases && language.aliases.indexOf(lang) !== -1 || language.extensions && language.extensions.find(function (ext) {
  25342. return ext.substring(1) === lang;
  25343. });
  25344. });
  25345. if (language) {
  25346. return language.parsers[0];
  25347. }
  25348. return null;
  25349. }
  25350. function replaceNewlinesWithLiterallines(doc$$2) {
  25351. return mapDoc$6(doc$$2, function (currentDoc) {
  25352. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$13(currentDoc.split(/(\n)/g).map(function (v, i) {
  25353. return i % 2 === 0 ? v : literalline$5;
  25354. })) : currentDoc;
  25355. });
  25356. }
  25357. }
  25358. var embed_1$4 = embed$4;
  25359. var pragma$6 = createCommonjsModule(function (module) {
  25360. "use strict";
  25361. var pragmas = ["format", "prettier"];
  25362. function startWithPragma(text) {
  25363. var pragma = `@(${pragmas.join("|")})`;
  25364. var regex = new RegExp([`<!--\\s*${pragma}\\s*-->`, `<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`].join("|"), "m");
  25365. var matched = text.match(regex);
  25366. return matched && matched.index === 0;
  25367. }
  25368. module.exports = {
  25369. startWithPragma,
  25370. hasPragma: function hasPragma(text) {
  25371. return startWithPragma(frontMatter(text).content.trimLeft());
  25372. },
  25373. insertPragma: function insertPragma(text) {
  25374. var extracted = frontMatter(text);
  25375. var pragma = `<!-- @${pragmas[0]} -->`;
  25376. return extracted.frontMatter ? `${extracted.frontMatter.raw}\n\n${pragma}\n\n${extracted.content}` : `${pragma}\n\n${extracted.content}`;
  25377. }
  25378. };
  25379. });
  25380. var getOrderedListItemInfo$2 = utils$8.getOrderedListItemInfo;
  25381. var mapAst$1 = utils$8.mapAst;
  25382. var splitText$2 = utils$8.splitText; // 0x0 ~ 0x10ffff
  25383. var isSingleCharRegex = /^([\u0000-\uffff]|[\ud800-\udbff][\udc00-\udfff])$/;
  25384. function preprocess$2(ast, options) {
  25385. ast = restoreUnescapedCharacter(ast, options);
  25386. ast = mergeContinuousTexts(ast);
  25387. ast = transformInlineCode(ast);
  25388. ast = transformIndentedCodeblockAndMarkItsParentList(ast, options);
  25389. ast = markAlignedList(ast, options);
  25390. ast = splitTextIntoSentences(ast, options);
  25391. ast = transformImportExport(ast);
  25392. ast = mergeContinuousImportExport(ast);
  25393. return ast;
  25394. }
  25395. function transformImportExport(ast) {
  25396. return mapAst$1(ast, function (node) {
  25397. if (node.type !== "import" && node.type !== "export") {
  25398. return node;
  25399. }
  25400. return Object.assign({}, node, {
  25401. type: "importExport"
  25402. });
  25403. });
  25404. }
  25405. function transformInlineCode(ast) {
  25406. return mapAst$1(ast, function (node) {
  25407. if (node.type !== "inlineCode") {
  25408. return node;
  25409. }
  25410. return Object.assign({}, node, {
  25411. value: node.value.replace(/\s+/g, " ")
  25412. });
  25413. });
  25414. }
  25415. function restoreUnescapedCharacter(ast, options) {
  25416. return mapAst$1(ast, function (node) {
  25417. return node.type !== "text" ? node : Object.assign({}, node, {
  25418. value: node.value !== "*" && node.value !== "_" && node.value !== "$" && // handle these cases in printer
  25419. 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
  25420. });
  25421. });
  25422. }
  25423. function mergeContinuousImportExport(ast) {
  25424. return mergeChildren(ast, function (prevNode, node) {
  25425. return prevNode.type === "importExport" && node.type === "importExport";
  25426. }, function (prevNode, node) {
  25427. return {
  25428. type: "importExport",
  25429. value: prevNode.value + "\n\n" + node.value,
  25430. position: {
  25431. start: prevNode.position.start,
  25432. end: node.position.end
  25433. }
  25434. };
  25435. });
  25436. }
  25437. function mergeChildren(ast, shouldMerge, mergeNode) {
  25438. return mapAst$1(ast, function (node) {
  25439. if (!node.children) {
  25440. return node;
  25441. }
  25442. var children = node.children.reduce(function (current, child) {
  25443. var lastChild = current[current.length - 1];
  25444. if (lastChild && shouldMerge(lastChild, child)) {
  25445. current.splice(-1, 1, mergeNode(lastChild, child));
  25446. } else {
  25447. current.push(child);
  25448. }
  25449. return current;
  25450. }, []);
  25451. return Object.assign({}, node, {
  25452. children
  25453. });
  25454. });
  25455. }
  25456. function mergeContinuousTexts(ast) {
  25457. return mergeChildren(ast, function (prevNode, node) {
  25458. return prevNode.type === "text" && node.type === "text";
  25459. }, function (prevNode, node) {
  25460. return {
  25461. type: "text",
  25462. value: prevNode.value + node.value,
  25463. position: {
  25464. start: prevNode.position.start,
  25465. end: node.position.end
  25466. }
  25467. };
  25468. });
  25469. }
  25470. function splitTextIntoSentences(ast, options) {
  25471. return mapAst$1(ast, function (node, index, _ref) {
  25472. var _ref2 = _slicedToArray(_ref, 1),
  25473. parentNode = _ref2[0];
  25474. if (node.type !== "text") {
  25475. return node;
  25476. }
  25477. var value = node.value;
  25478. if (parentNode.type === "paragraph") {
  25479. if (index === 0) {
  25480. value = value.trimLeft();
  25481. }
  25482. if (index === parentNode.children.length - 1) {
  25483. value = value.trimRight();
  25484. }
  25485. }
  25486. return {
  25487. type: "sentence",
  25488. position: node.position,
  25489. children: splitText$2(value, options)
  25490. };
  25491. });
  25492. }
  25493. function transformIndentedCodeblockAndMarkItsParentList(ast, options) {
  25494. return mapAst$1(ast, function (node, index, parentStack) {
  25495. if (node.type === "code") {
  25496. // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  25497. var isIndented = /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset));
  25498. node.isIndented = isIndented;
  25499. if (isIndented) {
  25500. for (var i = 0; i < parentStack.length; i++) {
  25501. var parent = parentStack[i]; // no need to check checked items
  25502. if (parent.hasIndentedCodeblock) {
  25503. break;
  25504. }
  25505. if (parent.type === "list") {
  25506. parent.hasIndentedCodeblock = true;
  25507. }
  25508. }
  25509. }
  25510. }
  25511. return node;
  25512. });
  25513. }
  25514. function markAlignedList(ast, options) {
  25515. return mapAst$1(ast, function (node, index, parentStack) {
  25516. if (node.type === "list" && node.children.length !== 0) {
  25517. // if one of its parents is not aligned, it's not possible to be aligned in sub-lists
  25518. for (var i = 0; i < parentStack.length; i++) {
  25519. var parent = parentStack[i];
  25520. if (parent.type === "list" && !parent.isAligned) {
  25521. node.isAligned = false;
  25522. return node;
  25523. }
  25524. }
  25525. node.isAligned = isAligned(node);
  25526. }
  25527. return node;
  25528. });
  25529. function getListItemStart(listItem) {
  25530. return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1;
  25531. }
  25532. function isAligned(list) {
  25533. if (!list.ordered) {
  25534. /**
  25535. * - 123
  25536. * - 123
  25537. */
  25538. return true;
  25539. }
  25540. var _list$children = _slicedToArray(list.children, 2),
  25541. firstItem = _list$children[0],
  25542. secondItem = _list$children[1];
  25543. var firstInfo = getOrderedListItemInfo$2(firstItem, options.originalText);
  25544. if (firstInfo.leadingSpaces.length > 1) {
  25545. /**
  25546. * 1. 123
  25547. *
  25548. * 1. 123
  25549. * 1. 123
  25550. */
  25551. return true;
  25552. }
  25553. var firstStart = getListItemStart(firstItem);
  25554. if (firstStart === -1) {
  25555. /**
  25556. * 1.
  25557. *
  25558. * 1.
  25559. * 1.
  25560. */
  25561. return false;
  25562. }
  25563. if (list.children.length === 1) {
  25564. /**
  25565. * aligned:
  25566. *
  25567. * 11. 123
  25568. *
  25569. * not aligned:
  25570. *
  25571. * 1. 123
  25572. */
  25573. return firstStart % options.tabWidth === 0;
  25574. }
  25575. var secondStart = getListItemStart(secondItem);
  25576. if (firstStart !== secondStart) {
  25577. /**
  25578. * 11. 123
  25579. * 1. 123
  25580. *
  25581. * 1. 123
  25582. * 11. 123
  25583. */
  25584. return false;
  25585. }
  25586. if (firstStart % options.tabWidth === 0) {
  25587. /**
  25588. * 11. 123
  25589. * 12. 123
  25590. */
  25591. return true;
  25592. }
  25593. /**
  25594. * aligned:
  25595. *
  25596. * 11. 123
  25597. * 1. 123
  25598. *
  25599. * not aligned:
  25600. *
  25601. * 1. 123
  25602. * 2. 123
  25603. */
  25604. var secondInfo = getOrderedListItemInfo$2(secondItem, options.originalText);
  25605. return secondInfo.leadingSpaces.length > 1;
  25606. }
  25607. }
  25608. var preprocess_1$2 = preprocess$2;
  25609. var _require$$0$builders$6 = doc.builders;
  25610. var concat$12 = _require$$0$builders$6.concat;
  25611. var join$9 = _require$$0$builders$6.join;
  25612. var line$8 = _require$$0$builders$6.line;
  25613. var literalline$4 = _require$$0$builders$6.literalline;
  25614. var markAsRoot$2 = _require$$0$builders$6.markAsRoot;
  25615. var hardline$10 = _require$$0$builders$6.hardline;
  25616. var softline$6 = _require$$0$builders$6.softline;
  25617. var fill$4 = _require$$0$builders$6.fill;
  25618. var align$2 = _require$$0$builders$6.align;
  25619. var indent$8 = _require$$0$builders$6.indent;
  25620. var group$13 = _require$$0$builders$6.group;
  25621. var mapDoc$5 = doc.utils.mapDoc;
  25622. var printDocToString$3 = doc.printer.printDocToString;
  25623. var getFencedCodeBlockValue = utils$8.getFencedCodeBlockValue;
  25624. var getOrderedListItemInfo = utils$8.getOrderedListItemInfo;
  25625. var splitText = utils$8.splitText;
  25626. var punctuationPattern = utils$8.punctuationPattern;
  25627. var INLINE_NODE_TYPES = utils$8.INLINE_NODE_TYPES;
  25628. var INLINE_NODE_WRAPPER_TYPES = utils$8.INLINE_NODE_WRAPPER_TYPES;
  25629. var replaceEndOfLineWith$1 = util$1.replaceEndOfLineWith;
  25630. var TRAILING_HARDLINE_NODES = ["importExport"];
  25631. var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  25632. var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
  25633. function genericPrint$4(path$$1, options, print) {
  25634. var node = path$$1.getValue();
  25635. if (shouldRemainTheSameContent(path$$1)) {
  25636. return concat$12(splitText(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(function (node) {
  25637. return node.type === "word" ? node.value : node.value === "" ? "" : printLine(path$$1, node.value, options);
  25638. }));
  25639. }
  25640. switch (node.type) {
  25641. case "root":
  25642. if (node.children.length === 0) {
  25643. return "";
  25644. }
  25645. return concat$12([normalizeDoc(printRoot(path$$1, options, print)), TRAILING_HARDLINE_NODES.indexOf(getLastDescendantNode(node).type) === -1 ? hardline$10 : ""]);
  25646. case "paragraph":
  25647. return printChildren(path$$1, options, print, {
  25648. postprocessor: fill$4
  25649. });
  25650. case "sentence":
  25651. return printChildren(path$$1, options, print);
  25652. case "word":
  25653. return node.value.replace(/[*$]/g, "\\$&") // escape all `*` and `$` (math)
  25654. .replace(new RegExp([`(^|${punctuationPattern})(_+)`, `(_+)(${punctuationPattern}|$)`].join("|"), "g"), function (_, text1, underscore1, underscore2, text2) {
  25655. return (underscore1 ? `${text1}${underscore1}` : `${underscore2}${text2}`).replace(/_/g, "\\_");
  25656. });
  25657. // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  25658. case "whitespace":
  25659. {
  25660. var parentNode = path$$1.getParentNode();
  25661. var index = parentNode.children.indexOf(node);
  25662. var nextNode = parentNode.children[index + 1];
  25663. var proseWrap = // leading char that may cause different syntax
  25664. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value) ? "never" : options.proseWrap;
  25665. return printLine(path$$1, node.value, {
  25666. proseWrap
  25667. });
  25668. }
  25669. case "emphasis":
  25670. {
  25671. var _parentNode = path$$1.getParentNode();
  25672. var _index = _parentNode.children.indexOf(node);
  25673. var prevNode = _parentNode.children[_index - 1];
  25674. var _nextNode = _parentNode.children[_index + 1];
  25675. var hasPrevOrNextWord = // `1*2*3` is considered emphais but `1_2_3` is not
  25676. 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;
  25677. var style = hasPrevOrNextWord || getAncestorNode$2(path$$1, "emphasis") ? "*" : "_";
  25678. return concat$12([style, printChildren(path$$1, options, print), style]);
  25679. }
  25680. case "strong":
  25681. return concat$12(["**", printChildren(path$$1, options, print), "**"]);
  25682. case "delete":
  25683. return concat$12(["~~", printChildren(path$$1, options, print), "~~"]);
  25684. case "inlineCode":
  25685. {
  25686. var backtickCount = util$1.getMaxContinuousCount(node.value, "`");
  25687. var _style = backtickCount === 1 ? "``" : "`";
  25688. var gap = backtickCount ? " " : "";
  25689. return concat$12([_style, gap, node.value, gap, _style]);
  25690. }
  25691. case "link":
  25692. switch (options.originalText[node.position.start.offset]) {
  25693. case "<":
  25694. {
  25695. var mailto = "mailto:";
  25696. var url = // <hello@example.com> is parsed as { url: "mailto:hello@example.com" }
  25697. 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;
  25698. return concat$12(["<", url, ">"]);
  25699. }
  25700. case "[":
  25701. return concat$12(["[", printChildren(path$$1, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  25702. default:
  25703. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  25704. }
  25705. case "image":
  25706. return concat$12(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  25707. case "blockquote":
  25708. return concat$12(["> ", align$2("> ", printChildren(path$$1, options, print))]);
  25709. case "heading":
  25710. return concat$12(["#".repeat(node.depth) + " ", printChildren(path$$1, options, print)]);
  25711. case "code":
  25712. {
  25713. if (node.isIndented) {
  25714. // indented code block
  25715. var alignment = " ".repeat(4);
  25716. return align$2(alignment, concat$12([alignment, concat$12(replaceEndOfLineWith$1(node.value, hardline$10))]));
  25717. } // fenced code block
  25718. var styleUnit = options.__inJsTemplate ? "~" : "`";
  25719. var _style2 = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  25720. return concat$12([_style2, node.lang || "", hardline$10, concat$12(replaceEndOfLineWith$1(getFencedCodeBlockValue(node, options.originalText), hardline$10)), hardline$10, _style2]);
  25721. }
  25722. case "yaml":
  25723. case "toml":
  25724. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  25725. case "html":
  25726. {
  25727. var _parentNode2 = path$$1.getParentNode();
  25728. var value = _parentNode2.type === "root" && util$1.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
  25729. var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
  25730. return concat$12(replaceEndOfLineWith$1(value, isHtmlComment ? hardline$10 : markAsRoot$2(literalline$4)));
  25731. }
  25732. case "list":
  25733. {
  25734. var nthSiblingIndex = getNthListSiblingIndex(node, path$$1.getParentNode());
  25735. var isGitDiffFriendlyOrderedList = node.ordered && node.children.length > 1 && +getOrderedListItemInfo(node.children[1], options.originalText).numberText === 1;
  25736. return printChildren(path$$1, options, print, {
  25737. processor: function processor(childPath, index) {
  25738. var prefix = getPrefix();
  25739. return concat$12([prefix, align$2(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
  25740. function getPrefix() {
  25741. var rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* ";
  25742. return node.isAligned ||
  25743. /* workaround for https://github.com/remarkjs/remark/issues/315 */
  25744. node.hasIndentedCodeblock ? alignListPrefix(rawPrefix, options) : rawPrefix;
  25745. }
  25746. }
  25747. });
  25748. }
  25749. case "thematicBreak":
  25750. {
  25751. var counter = getAncestorCounter$1(path$$1, "list");
  25752. if (counter === -1) {
  25753. return "---";
  25754. }
  25755. var _nthSiblingIndex = getNthListSiblingIndex(path$$1.getParentNode(counter), path$$1.getParentNode(counter + 1));
  25756. return _nthSiblingIndex % 2 === 0 ? "***" : "---";
  25757. }
  25758. case "linkReference":
  25759. return concat$12(["[", printChildren(path$$1, options, print), "]", node.referenceType === "full" ? concat$12(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
  25760. case "imageReference":
  25761. switch (node.referenceType) {
  25762. case "full":
  25763. return concat$12(["![", node.alt || "", "][", node.identifier, "]"]);
  25764. default:
  25765. return concat$12(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
  25766. }
  25767. case "definition":
  25768. {
  25769. var lineOrSpace = options.proseWrap === "always" ? line$8 : " ";
  25770. 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)])]))]));
  25771. }
  25772. case "footnote":
  25773. return concat$12(["[^", printChildren(path$$1, options, print), "]"]);
  25774. case "footnoteReference":
  25775. return concat$12(["[^", node.identifier, "]"]);
  25776. case "footnoteDefinition":
  25777. {
  25778. var _nextNode2 = path$$1.getParentNode().children[path$$1.getName() + 1];
  25779. 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);
  25780. 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, {
  25781. processor: function processor(childPath, index) {
  25782. return index === 0 ? group$13(concat$12([softline$6, softline$6, childPath.call(print)])) : childPath.call(print);
  25783. }
  25784. })), _nextNode2 && _nextNode2.type === "footnoteDefinition" ? softline$6 : ""]))]);
  25785. }
  25786. case "table":
  25787. return printTable(path$$1, options, print);
  25788. case "tableCell":
  25789. return printChildren(path$$1, options, print);
  25790. case "break":
  25791. return /\s/.test(options.originalText[node.position.start.offset]) ? concat$12([" ", markAsRoot$2(literalline$4)]) : concat$12(["\\", hardline$10]);
  25792. case "liquidNode":
  25793. return concat$12(replaceEndOfLineWith$1(node.value, hardline$10));
  25794. // MDX
  25795. case "importExport":
  25796. case "jsx":
  25797. return node.value;
  25798. // fallback to the original text if multiparser failed
  25799. case "math":
  25800. return concat$12(["$$", hardline$10, node.value ? concat$12([concat$12(replaceEndOfLineWith$1(node.value, hardline$10)), hardline$10]) : "", "$$"]);
  25801. case "inlineMath":
  25802. {
  25803. // remark-math trims content but we don't want to remove whitespaces
  25804. // since it's very possible that it's recognized as math accidentally
  25805. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  25806. }
  25807. case "tableRow": // handled in "table"
  25808. case "listItem": // handled in "list"
  25809. default:
  25810. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  25811. }
  25812. }
  25813. function printListItem(path$$1, options, print, listPrefix) {
  25814. var node = path$$1.getValue();
  25815. var prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  25816. return concat$12([prefix, printChildren(path$$1, options, print, {
  25817. processor: function processor(childPath, index) {
  25818. if (index === 0 && childPath.getValue().type !== "list") {
  25819. return align$2(" ".repeat(prefix.length), childPath.call(print));
  25820. }
  25821. var alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  25822. );
  25823. return concat$12([alignment, align$2(alignment, childPath.call(print))]);
  25824. }
  25825. })]);
  25826. }
  25827. function alignListPrefix(prefix, options) {
  25828. var additionalSpaces = getAdditionalSpaces();
  25829. return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  25830. );
  25831. function getAdditionalSpaces() {
  25832. var restSpaces = prefix.length % options.tabWidth;
  25833. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  25834. }
  25835. }
  25836. function getNthListSiblingIndex(node, parentNode) {
  25837. return getNthSiblingIndex(node, parentNode, function (siblingNode) {
  25838. return siblingNode.ordered === node.ordered;
  25839. });
  25840. }
  25841. function getNthSiblingIndex(node, parentNode, condition) {
  25842. condition = condition || function () {
  25843. return true;
  25844. };
  25845. var index = -1;
  25846. var _iteratorNormalCompletion = true;
  25847. var _didIteratorError = false;
  25848. var _iteratorError = undefined;
  25849. try {
  25850. for (var _iterator = parentNode.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  25851. var childNode = _step.value;
  25852. if (childNode.type === node.type && condition(childNode)) {
  25853. index++;
  25854. } else {
  25855. index = -1;
  25856. }
  25857. if (childNode === node) {
  25858. return index;
  25859. }
  25860. }
  25861. } catch (err) {
  25862. _didIteratorError = true;
  25863. _iteratorError = err;
  25864. } finally {
  25865. try {
  25866. if (!_iteratorNormalCompletion && _iterator.return != null) {
  25867. _iterator.return();
  25868. }
  25869. } finally {
  25870. if (_didIteratorError) {
  25871. throw _iteratorError;
  25872. }
  25873. }
  25874. }
  25875. }
  25876. function getAncestorCounter$1(path$$1, typeOrTypes) {
  25877. var types = [].concat(typeOrTypes);
  25878. var counter = -1;
  25879. var ancestorNode;
  25880. while (ancestorNode = path$$1.getParentNode(++counter)) {
  25881. if (types.indexOf(ancestorNode.type) !== -1) {
  25882. return counter;
  25883. }
  25884. }
  25885. return -1;
  25886. }
  25887. function getAncestorNode$2(path$$1, typeOrTypes) {
  25888. var counter = getAncestorCounter$1(path$$1, typeOrTypes);
  25889. return counter === -1 ? null : path$$1.getParentNode(counter);
  25890. }
  25891. function printLine(path$$1, value, options) {
  25892. if (options.proseWrap === "preserve" && value === "\n") {
  25893. return hardline$10;
  25894. }
  25895. var isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path$$1, SINGLE_LINE_NODE_TYPES);
  25896. return value !== "" ? isBreakable ? line$8 : " " : isBreakable ? softline$6 : "";
  25897. }
  25898. function printTable(path$$1, options, print) {
  25899. var node = path$$1.getValue();
  25900. var contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  25901. path$$1.map(function (rowPath) {
  25902. var rowContents = [];
  25903. rowPath.map(function (cellPath) {
  25904. rowContents.push(printDocToString$3(cellPath.call(print), options).formatted);
  25905. }, "children");
  25906. contents.push(rowContents);
  25907. }, "children");
  25908. var columnMaxWidths = contents.reduce(function (currentWidths, rowContents) {
  25909. return currentWidths.map(function (width, columnIndex) {
  25910. return Math.max(width, util$1.getStringWidth(rowContents[columnIndex]));
  25911. });
  25912. }, contents[0].map(function () {
  25913. return 3;
  25914. }) // minimum width = 3 (---, :--, :-:, --:)
  25915. );
  25916. return join$9(hardline$10, [printRow(contents[0]), printSeparator(), join$9(hardline$10, contents.slice(1).map(printRow))]);
  25917. function printSeparator() {
  25918. return concat$12(["| ", join$9(" | ", columnMaxWidths.map(function (width, index) {
  25919. switch (node.align[index]) {
  25920. case "left":
  25921. return ":" + "-".repeat(width - 1);
  25922. case "right":
  25923. return "-".repeat(width - 1) + ":";
  25924. case "center":
  25925. return ":" + "-".repeat(width - 2) + ":";
  25926. default:
  25927. return "-".repeat(width);
  25928. }
  25929. })), " |"]);
  25930. }
  25931. function printRow(rowContents) {
  25932. return concat$12(["| ", join$9(" | ", rowContents.map(function (rowContent, columnIndex) {
  25933. switch (node.align[columnIndex]) {
  25934. case "right":
  25935. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  25936. case "center":
  25937. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  25938. default:
  25939. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  25940. }
  25941. })), " |"]);
  25942. }
  25943. function alignLeft(text, width) {
  25944. return concat$12([text, " ".repeat(width - util$1.getStringWidth(text))]);
  25945. }
  25946. function alignRight(text, width) {
  25947. return concat$12([" ".repeat(width - util$1.getStringWidth(text)), text]);
  25948. }
  25949. function alignCenter(text, width) {
  25950. var spaces = width - util$1.getStringWidth(text);
  25951. var left = Math.floor(spaces / 2);
  25952. var right = spaces - left;
  25953. return concat$12([" ".repeat(left), text, " ".repeat(right)]);
  25954. }
  25955. }
  25956. function printRoot(path$$1, options, print) {
  25957. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  25958. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  25959. var ignoreRanges = [];
  25960. /** @type {IgnorePosition | null} */
  25961. var ignoreStart = null;
  25962. var children = path$$1.getValue().children;
  25963. children.forEach(function (childNode, index) {
  25964. switch (isPrettierIgnore(childNode)) {
  25965. case "start":
  25966. if (ignoreStart === null) {
  25967. ignoreStart = {
  25968. index,
  25969. offset: childNode.position.end.offset
  25970. };
  25971. }
  25972. break;
  25973. case "end":
  25974. if (ignoreStart !== null) {
  25975. ignoreRanges.push({
  25976. start: ignoreStart,
  25977. end: {
  25978. index,
  25979. offset: childNode.position.start.offset
  25980. }
  25981. });
  25982. ignoreStart = null;
  25983. }
  25984. break;
  25985. default:
  25986. // do nothing
  25987. break;
  25988. }
  25989. });
  25990. return printChildren(path$$1, options, print, {
  25991. processor: function processor(childPath, index) {
  25992. if (ignoreRanges.length !== 0) {
  25993. var ignoreRange = ignoreRanges[0];
  25994. if (index === ignoreRange.start.index) {
  25995. return concat$12([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
  25996. }
  25997. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  25998. return false;
  25999. }
  26000. if (index === ignoreRange.end.index) {
  26001. ignoreRanges.shift();
  26002. return false;
  26003. }
  26004. }
  26005. return childPath.call(print);
  26006. }
  26007. });
  26008. }
  26009. function printChildren(path$$1, options, print, events$$1) {
  26010. events$$1 = events$$1 || {};
  26011. var postprocessor = events$$1.postprocessor || concat$12;
  26012. var processor = events$$1.processor || function (childPath) {
  26013. return childPath.call(print);
  26014. };
  26015. var node = path$$1.getValue();
  26016. var parts = [];
  26017. var lastChildNode;
  26018. path$$1.map(function (childPath, index) {
  26019. var childNode = childPath.getValue();
  26020. var result = processor(childPath, index);
  26021. if (result !== false) {
  26022. var data = {
  26023. parts,
  26024. prevNode: lastChildNode,
  26025. parentNode: node,
  26026. options
  26027. };
  26028. if (!shouldNotPrePrintHardline(childNode, data)) {
  26029. parts.push(hardline$10);
  26030. if (lastChildNode && TRAILING_HARDLINE_NODES.indexOf(lastChildNode.type) !== -1) {
  26031. if (shouldPrePrintTripleHardline(childNode, data)) {
  26032. parts.push(hardline$10);
  26033. }
  26034. } else {
  26035. if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
  26036. parts.push(hardline$10);
  26037. }
  26038. if (shouldPrePrintTripleHardline(childNode, data)) {
  26039. parts.push(hardline$10);
  26040. }
  26041. }
  26042. }
  26043. parts.push(result);
  26044. lastChildNode = childNode;
  26045. }
  26046. }, "children");
  26047. return postprocessor(parts);
  26048. }
  26049. function getLastDescendantNode(node) {
  26050. var current = node;
  26051. while (current.children && current.children.length !== 0) {
  26052. current = current.children[current.children.length - 1];
  26053. }
  26054. return current;
  26055. }
  26056. /** @return {false | 'next' | 'start' | 'end'} */
  26057. function isPrettierIgnore(node) {
  26058. if (node.type !== "html") {
  26059. return false;
  26060. }
  26061. var match = node.value.match(/^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/);
  26062. return match === null ? false : match[1] ? match[1] : "next";
  26063. }
  26064. function shouldNotPrePrintHardline(node, data) {
  26065. var isFirstNode = data.parts.length === 0;
  26066. var isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1;
  26067. var isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1;
  26068. return isFirstNode || isInlineNode || isInlineHTML;
  26069. }
  26070. function shouldPrePrintDoubleHardline(node, data) {
  26071. var isSequence = (data.prevNode && data.prevNode.type) === node.type;
  26072. var isSiblingNode = isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1;
  26073. var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
  26074. var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
  26075. var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
  26076. var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
  26077. return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
  26078. }
  26079. function shouldPrePrintTripleHardline(node, data) {
  26080. var isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  26081. var isIndentedCode = node.type === "code" && node.isIndented;
  26082. return isPrevNodeList && isIndentedCode;
  26083. }
  26084. function shouldRemainTheSameContent(path$$1) {
  26085. var ancestorNode = getAncestorNode$2(path$$1, ["linkReference", "imageReference"]);
  26086. return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
  26087. }
  26088. function normalizeDoc(doc$$2) {
  26089. return mapDoc$5(doc$$2, function (currentDoc) {
  26090. if (!currentDoc.parts) {
  26091. return currentDoc;
  26092. }
  26093. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  26094. return currentDoc.parts[0];
  26095. }
  26096. var parts = [];
  26097. currentDoc.parts.forEach(function (part) {
  26098. if (part.type === "concat") {
  26099. parts.push.apply(parts, part.parts);
  26100. } else if (part !== "") {
  26101. parts.push(part);
  26102. }
  26103. });
  26104. return Object.assign({}, currentDoc, {
  26105. parts: normalizeParts(parts)
  26106. });
  26107. });
  26108. }
  26109. function printUrl(url, dangerousCharOrChars) {
  26110. var dangerousChars = [" "].concat(dangerousCharOrChars || []);
  26111. return new RegExp(dangerousChars.map(function (x) {
  26112. return `\\${x}`;
  26113. }).join("|")).test(url) ? `<${url}>` : url;
  26114. }
  26115. function printTitle(title, options, printSpace) {
  26116. if (printSpace == null) {
  26117. printSpace = true;
  26118. }
  26119. if (!title) {
  26120. return "";
  26121. }
  26122. if (printSpace) {
  26123. return " " + printTitle(title, options, false);
  26124. }
  26125. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  26126. return `(${title})`; // avoid escaped quotes
  26127. } // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  26128. var singleCount = title.split("'").length - 1;
  26129. var doubleCount = title.split('"').length - 1;
  26130. var quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
  26131. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  26132. return `${quote}${title}${quote}`;
  26133. }
  26134. function normalizeParts(parts) {
  26135. return parts.reduce(function (current, part) {
  26136. var lastPart = util$1.getLast(current);
  26137. if (typeof lastPart === "string" && typeof part === "string") {
  26138. current.splice(-1, 1, lastPart + part);
  26139. } else {
  26140. current.push(part);
  26141. }
  26142. return current;
  26143. }, []);
  26144. }
  26145. function clamp(value, min, max) {
  26146. return value < min ? min : value > max ? max : value;
  26147. }
  26148. function clean$7(ast, newObj, parent) {
  26149. delete newObj.position;
  26150. delete newObj.raw; // front-matter
  26151. // for codeblock
  26152. if (ast.type === "code" || ast.type === "yaml" || ast.type === "import" || ast.type === "export" || ast.type === "jsx") {
  26153. delete newObj.value;
  26154. }
  26155. if (ast.type === "list") {
  26156. delete newObj.isAligned;
  26157. } // texts can be splitted or merged
  26158. if (ast.type === "text") {
  26159. return null;
  26160. }
  26161. if (ast.type === "inlineCode") {
  26162. newObj.value = ast.value.replace(/[ \t\n]+/g, " ");
  26163. } // for insert pragma
  26164. 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)) {
  26165. return null;
  26166. }
  26167. }
  26168. function hasPrettierIgnore$1(path$$1) {
  26169. var index = +path$$1.getName();
  26170. if (index === 0) {
  26171. return false;
  26172. }
  26173. var prevNode = path$$1.getParentNode().children[index - 1];
  26174. return isPrettierIgnore(prevNode) === "next";
  26175. }
  26176. var printerMarkdown = {
  26177. preprocess: preprocess_1$2,
  26178. print: genericPrint$4,
  26179. embed: embed_1$4,
  26180. massageAstNode: clean$7,
  26181. hasPrettierIgnore: hasPrettierIgnore$1,
  26182. insertPragma: pragma$6.insertPragma
  26183. };
  26184. var options$12 = {
  26185. proseWrap: commonOptions.proseWrap,
  26186. singleQuote: commonOptions.singleQuote
  26187. };
  26188. var name$13 = "Markdown";
  26189. var type$12 = "prose";
  26190. var aliases$4 = ["pandoc"];
  26191. var aceMode$12 = "markdown";
  26192. var codemirrorMode$9 = "gfm";
  26193. var codemirrorMimeType$9 = "text/x-gfm";
  26194. var wrap = true;
  26195. var extensions$12 = [".md", ".markdown", ".mdown", ".mdwn", ".mkd", ".mkdn", ".mkdown", ".ronn", ".workbook"];
  26196. var tmScope$12 = "source.gfm";
  26197. var languageId$12 = 222;
  26198. var markdown = {
  26199. name: name$13,
  26200. type: type$12,
  26201. aliases: aliases$4,
  26202. aceMode: aceMode$12,
  26203. codemirrorMode: codemirrorMode$9,
  26204. codemirrorMimeType: codemirrorMimeType$9,
  26205. wrap: wrap,
  26206. extensions: extensions$12,
  26207. tmScope: tmScope$12,
  26208. languageId: languageId$12
  26209. };
  26210. var markdown$1 = Object.freeze({
  26211. name: name$13,
  26212. type: type$12,
  26213. aliases: aliases$4,
  26214. aceMode: aceMode$12,
  26215. codemirrorMode: codemirrorMode$9,
  26216. codemirrorMimeType: codemirrorMimeType$9,
  26217. wrap: wrap,
  26218. extensions: extensions$12,
  26219. tmScope: tmScope$12,
  26220. languageId: languageId$12,
  26221. default: markdown
  26222. });
  26223. var require$$0$28 = ( markdown$1 && markdown ) || markdown$1;
  26224. var languages$4 = [createLanguage(require$$0$28, {
  26225. override: {
  26226. since: "1.8.0",
  26227. parsers: ["remark"],
  26228. vscodeLanguageIds: ["markdown"]
  26229. },
  26230. extend: {
  26231. filenames: ["README"]
  26232. }
  26233. }), createLanguage({
  26234. name: "MDX",
  26235. extensions: [".mdx"]
  26236. }, // TODO: use linguist data
  26237. {
  26238. override: {
  26239. since: "1.15.0",
  26240. parsers: ["mdx"],
  26241. vscodeLanguageIds: ["mdx"]
  26242. }
  26243. })];
  26244. var printers$4 = {
  26245. mdast: printerMarkdown
  26246. };
  26247. var languageMarkdown = {
  26248. languages: languages$4,
  26249. options: options$12,
  26250. printers: printers$4
  26251. };
  26252. var clean$8 = function clean(ast, newNode) {
  26253. delete newNode.sourceSpan;
  26254. delete newNode.startSourceSpan;
  26255. delete newNode.endSourceSpan;
  26256. delete newNode.nameSpan;
  26257. delete newNode.valueSpan;
  26258. if (ast.type === "text" || ast.type === "comment") {
  26259. return null;
  26260. } // may be formatted by multiparser
  26261. if (ast.type === "yaml" || ast.type === "toml") {
  26262. return null;
  26263. }
  26264. if (ast.type === "attribute") {
  26265. delete newNode.value;
  26266. }
  26267. if (ast.type === "docType") {
  26268. delete newNode.value;
  26269. }
  26270. };
  26271. var a = ["accesskey", "charset", "coords", "download", "href", "hreflang", "name", "ping", "referrerpolicy", "rel", "rev", "shape", "tabindex", "target", "type"];
  26272. var abbr = ["title"];
  26273. var applet = ["align", "alt", "archive", "code", "codebase", "height", "hspace", "name", "object", "vspace", "width"];
  26274. var area = ["accesskey", "alt", "coords", "download", "href", "hreflang", "nohref", "ping", "referrerpolicy", "rel", "shape", "tabindex", "target", "type"];
  26275. var audio = ["autoplay", "controls", "crossorigin", "loop", "muted", "preload", "src"];
  26276. var base$2 = ["href", "target"];
  26277. var basefont = ["color", "face", "size"];
  26278. var bdo = ["dir"];
  26279. var blockquote = ["cite"];
  26280. var body = ["alink", "background", "bgcolor", "link", "text", "vlink"];
  26281. var br = ["clear"];
  26282. var button = ["accesskey", "autofocus", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "name", "tabindex", "type", "value"];
  26283. var canvas = ["height", "width"];
  26284. var caption = ["align"];
  26285. var col = ["align", "char", "charoff", "span", "valign", "width"];
  26286. var colgroup = ["align", "char", "charoff", "span", "valign", "width"];
  26287. var data$1 = ["value"];
  26288. var del = ["cite", "datetime"];
  26289. var details = ["open"];
  26290. var dfn = ["title"];
  26291. var dialog = ["open"];
  26292. var dir = ["compact"];
  26293. var div = ["align"];
  26294. var dl = ["compact"];
  26295. var embed$7 = ["height", "src", "type", "width"];
  26296. var fieldset = ["disabled", "form", "name"];
  26297. var font = ["color", "face", "size"];
  26298. var form = ["accept", "accept-charset", "action", "autocomplete", "enctype", "method", "name", "novalidate", "target"];
  26299. var frame = ["frameborder", "longdesc", "marginheight", "marginwidth", "name", "noresize", "scrolling", "src"];
  26300. var frameset = ["cols", "rows"];
  26301. var h1 = ["align"];
  26302. var h2 = ["align"];
  26303. var h3 = ["align"];
  26304. var h4 = ["align"];
  26305. var h5 = ["align"];
  26306. var h6 = ["align"];
  26307. var head = ["profile"];
  26308. var hr = ["align", "noshade", "size", "width"];
  26309. var html = ["manifest", "version"];
  26310. var iframe = ["align", "allowfullscreen", "allowpaymentrequest", "allowusermedia", "frameborder", "height", "longdesc", "marginheight", "marginwidth", "name", "referrerpolicy", "sandbox", "scrolling", "src", "srcdoc", "width"];
  26311. var img = ["align", "alt", "border", "crossorigin", "decoding", "height", "hspace", "ismap", "longdesc", "name", "referrerpolicy", "sizes", "src", "srcset", "usemap", "vspace", "width"];
  26312. 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"];
  26313. var ins = ["cite", "datetime"];
  26314. var isindex = ["prompt"];
  26315. var label = ["accesskey", "for", "form"];
  26316. var legend = ["accesskey", "align"];
  26317. var li = ["type", "value"];
  26318. var link$1 = ["as", "charset", "color", "crossorigin", "href", "hreflang", "integrity", "media", "nonce", "referrerpolicy", "rel", "rev", "sizes", "target", "title", "type"];
  26319. var map = ["name"];
  26320. var menu = ["compact"];
  26321. var meta = ["charset", "content", "http-equiv", "name", "scheme"];
  26322. var meter = ["high", "low", "max", "min", "optimum", "value"];
  26323. var object = ["align", "archive", "border", "classid", "codebase", "codetype", "data", "declare", "form", "height", "hspace", "name", "standby", "tabindex", "type", "typemustmatch", "usemap", "vspace", "width"];
  26324. var ol = ["compact", "reversed", "start", "type"];
  26325. var optgroup = ["disabled", "label"];
  26326. var option = ["disabled", "label", "selected", "value"];
  26327. var output = ["for", "form", "name"];
  26328. var p = ["align"];
  26329. var param = ["name", "type", "value", "valuetype"];
  26330. var pre = ["width"];
  26331. var progress = ["max", "value"];
  26332. var q = ["cite"];
  26333. var script = ["async", "charset", "crossorigin", "defer", "integrity", "language", "nomodule", "nonce", "referrerpolicy", "src", "type"];
  26334. var select = ["autocomplete", "autofocus", "disabled", "form", "multiple", "name", "required", "size", "tabindex"];
  26335. var slot = ["name"];
  26336. var source = ["media", "sizes", "src", "srcset", "type"];
  26337. var style = ["media", "nonce", "title", "type"];
  26338. var table = ["align", "bgcolor", "border", "cellpadding", "cellspacing", "frame", "rules", "summary", "width"];
  26339. var tbody = ["align", "char", "charoff", "valign"];
  26340. var td = ["abbr", "align", "axis", "bgcolor", "char", "charoff", "colspan", "headers", "height", "nowrap", "rowspan", "scope", "valign", "width"];
  26341. var textarea = ["accesskey", "autocomplete", "autofocus", "cols", "dirname", "disabled", "form", "maxlength", "minlength", "name", "placeholder", "readonly", "required", "rows", "tabindex", "wrap"];
  26342. var tfoot = ["align", "char", "charoff", "valign"];
  26343. var th = ["abbr", "align", "axis", "bgcolor", "char", "charoff", "colspan", "headers", "height", "nowrap", "rowspan", "scope", "valign", "width"];
  26344. var thead = ["align", "char", "charoff", "valign"];
  26345. var time = ["datetime"];
  26346. var tr = ["align", "bgcolor", "char", "charoff", "valign"];
  26347. var track = ["default", "kind", "label", "src", "srclang"];
  26348. var ul = ["compact", "type"];
  26349. var video = ["autoplay", "controls", "crossorigin", "height", "loop", "muted", "playsinline", "poster", "preload", "src", "width"];
  26350. var index$13 = {
  26351. a: a,
  26352. abbr: abbr,
  26353. applet: applet,
  26354. area: area,
  26355. audio: audio,
  26356. base: base$2,
  26357. basefont: basefont,
  26358. bdo: bdo,
  26359. blockquote: blockquote,
  26360. body: body,
  26361. br: br,
  26362. button: button,
  26363. canvas: canvas,
  26364. caption: caption,
  26365. col: col,
  26366. colgroup: colgroup,
  26367. data: data$1,
  26368. del: del,
  26369. details: details,
  26370. dfn: dfn,
  26371. dialog: dialog,
  26372. dir: dir,
  26373. div: div,
  26374. dl: dl,
  26375. embed: embed$7,
  26376. fieldset: fieldset,
  26377. font: font,
  26378. form: form,
  26379. frame: frame,
  26380. frameset: frameset,
  26381. h1: h1,
  26382. h2: h2,
  26383. h3: h3,
  26384. h4: h4,
  26385. h5: h5,
  26386. h6: h6,
  26387. head: head,
  26388. hr: hr,
  26389. html: html,
  26390. iframe: iframe,
  26391. img: img,
  26392. input: input,
  26393. ins: ins,
  26394. isindex: isindex,
  26395. label: label,
  26396. legend: legend,
  26397. li: li,
  26398. link: link$1,
  26399. map: map,
  26400. menu: menu,
  26401. meta: meta,
  26402. meter: meter,
  26403. object: object,
  26404. ol: ol,
  26405. optgroup: optgroup,
  26406. option: option,
  26407. output: output,
  26408. p: p,
  26409. param: param,
  26410. pre: pre,
  26411. progress: progress,
  26412. q: q,
  26413. script: script,
  26414. select: select,
  26415. slot: slot,
  26416. source: source,
  26417. style: style,
  26418. table: table,
  26419. tbody: tbody,
  26420. td: td,
  26421. textarea: textarea,
  26422. tfoot: tfoot,
  26423. th: th,
  26424. thead: thead,
  26425. time: time,
  26426. tr: tr,
  26427. track: track,
  26428. ul: ul,
  26429. video: video,
  26430. "*": ["accesskey", "autocapitalize", "class", "contenteditable", "dir", "draggable", "hidden", "id", "inputmode", "is", "itemid", "itemprop", "itemref", "itemscope", "itemtype", "lang", "nonce", "slot", "spellcheck", "style", "tabindex", "title", "translate"]
  26431. };
  26432. var htmlElementAttributes = Object.freeze({
  26433. a: a,
  26434. abbr: abbr,
  26435. applet: applet,
  26436. area: area,
  26437. audio: audio,
  26438. base: base$2,
  26439. basefont: basefont,
  26440. bdo: bdo,
  26441. blockquote: blockquote,
  26442. body: body,
  26443. br: br,
  26444. button: button,
  26445. canvas: canvas,
  26446. caption: caption,
  26447. col: col,
  26448. colgroup: colgroup,
  26449. data: data$1,
  26450. del: del,
  26451. details: details,
  26452. dfn: dfn,
  26453. dialog: dialog,
  26454. dir: dir,
  26455. div: div,
  26456. dl: dl,
  26457. embed: embed$7,
  26458. fieldset: fieldset,
  26459. font: font,
  26460. form: form,
  26461. frame: frame,
  26462. frameset: frameset,
  26463. h1: h1,
  26464. h2: h2,
  26465. h3: h3,
  26466. h4: h4,
  26467. h5: h5,
  26468. h6: h6,
  26469. head: head,
  26470. hr: hr,
  26471. html: html,
  26472. iframe: iframe,
  26473. img: img,
  26474. input: input,
  26475. ins: ins,
  26476. isindex: isindex,
  26477. label: label,
  26478. legend: legend,
  26479. li: li,
  26480. link: link$1,
  26481. map: map,
  26482. menu: menu,
  26483. meta: meta,
  26484. meter: meter,
  26485. object: object,
  26486. ol: ol,
  26487. optgroup: optgroup,
  26488. option: option,
  26489. output: output,
  26490. p: p,
  26491. param: param,
  26492. pre: pre,
  26493. progress: progress,
  26494. q: q,
  26495. script: script,
  26496. select: select,
  26497. slot: slot,
  26498. source: source,
  26499. style: style,
  26500. table: table,
  26501. tbody: tbody,
  26502. td: td,
  26503. textarea: textarea,
  26504. tfoot: tfoot,
  26505. th: th,
  26506. thead: thead,
  26507. time: time,
  26508. tr: tr,
  26509. track: track,
  26510. ul: ul,
  26511. video: video,
  26512. default: index$13
  26513. });
  26514. 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"};
  26515. var htmlElementAttributes$1 = ( htmlElementAttributes && index$13 ) || htmlElementAttributes;
  26516. var CSS_DISPLAY_TAGS = json$9.CSS_DISPLAY_TAGS;
  26517. var CSS_DISPLAY_DEFAULT = json$9.CSS_DISPLAY_DEFAULT;
  26518. var CSS_WHITE_SPACE_TAGS = json$9.CSS_WHITE_SPACE_TAGS;
  26519. var CSS_WHITE_SPACE_DEFAULT = json$9.CSS_WHITE_SPACE_DEFAULT;
  26520. var HTML_TAGS = arrayToMap(htmlTagNames$1);
  26521. var HTML_ELEMENT_ATTRIBUTES = mapObject(htmlElementAttributes$1, arrayToMap);
  26522. function arrayToMap(array) {
  26523. var map = Object.create(null);
  26524. var _iteratorNormalCompletion = true;
  26525. var _didIteratorError = false;
  26526. var _iteratorError = undefined;
  26527. try {
  26528. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  26529. var value = _step.value;
  26530. map[value] = true;
  26531. }
  26532. } catch (err) {
  26533. _didIteratorError = true;
  26534. _iteratorError = err;
  26535. } finally {
  26536. try {
  26537. if (!_iteratorNormalCompletion && _iterator.return != null) {
  26538. _iterator.return();
  26539. }
  26540. } finally {
  26541. if (_didIteratorError) {
  26542. throw _iteratorError;
  26543. }
  26544. }
  26545. }
  26546. return map;
  26547. }
  26548. function mapObject(object, fn) {
  26549. var newObject = Object.create(null);
  26550. var _arr = Object.keys(object);
  26551. for (var _i = 0; _i < _arr.length; _i++) {
  26552. var key = _arr[_i];
  26553. newObject[key] = fn(object[key], key);
  26554. }
  26555. return newObject;
  26556. }
  26557. function shouldPreserveContent$1(node, options) {
  26558. if (node.type === "element" && node.fullName === "template" && node.attrMap.lang && node.attrMap.lang !== "html") {
  26559. return true;
  26560. } // unterminated node in ie conditional comment
  26561. // e.g. <!--[if lt IE 9]><html><![endif]-->
  26562. if (node.type === "ieConditionalComment" && node.lastChild && !node.lastChild.isSelfClosing && !node.lastChild.endSourceSpan) {
  26563. return true;
  26564. } // incomplete html in ie conditional comment
  26565. // e.g. <!--[if lt IE 9]></div><![endif]-->
  26566. if (node.type === "ieConditionalComment" && !node.complete) {
  26567. return true;
  26568. } // top-level elements (excluding <template>, <style> and <script>) in Vue SFC are considered custom block
  26569. // custom blocks can be written in other languages so we should preserve them to not break the code
  26570. 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>
  26571. "html"].indexOf(node.fullName) === -1) {
  26572. return true;
  26573. } // TODO: handle non-text children in <pre>
  26574. if (isPreLikeNode(node) && node.children.some(function (child) {
  26575. return child.type !== "text" && child.type !== "interpolation";
  26576. })) {
  26577. return true;
  26578. }
  26579. return false;
  26580. }
  26581. function hasPrettierIgnore$3(node) {
  26582. if (node.type === "attribute" || isTextLikeNode$1(node)) {
  26583. return false;
  26584. }
  26585. if (!node.parent) {
  26586. return false;
  26587. }
  26588. if (typeof node.index !== "number" || node.index === 0) {
  26589. return false;
  26590. }
  26591. var prevNode = node.parent.children[node.index - 1];
  26592. return isPrettierIgnore$1(prevNode);
  26593. }
  26594. function isPrettierIgnore$1(node) {
  26595. return node.type === "comment" && node.value.trim() === "prettier-ignore";
  26596. }
  26597. function getPrettierIgnoreAttributeCommentData$1(value) {
  26598. var match = value.trim().match(/^prettier-ignore-attribute(?:\s+([^]+))?$/);
  26599. if (!match) {
  26600. return false;
  26601. }
  26602. if (!match[1]) {
  26603. return true;
  26604. }
  26605. return match[1].split(/\s+/);
  26606. }
  26607. /** there's no opening/closing tag or it's considered not breakable */
  26608. function isTextLikeNode$1(node) {
  26609. return node.type === "text" || node.type === "comment";
  26610. }
  26611. function isScriptLikeTag$1(node) {
  26612. return node.type === "element" && (node.fullName === "script" || node.fullName === "style" || node.fullName === "svg:style");
  26613. }
  26614. function isFrontMatterNode(node) {
  26615. return node.type === "yaml" || node.type === "toml";
  26616. }
  26617. function canHaveInterpolation(node) {
  26618. return node.children && !isScriptLikeTag$1(node);
  26619. }
  26620. function isWhitespaceSensitiveNode(node) {
  26621. return isScriptLikeTag$1(node) || node.type === "interpolation" || isIndentationSensitiveNode(node);
  26622. }
  26623. function isIndentationSensitiveNode(node) {
  26624. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  26625. }
  26626. function isLeadingSpaceSensitiveNode(node) {
  26627. var isLeadingSpaceSensitive = _isLeadingSpaceSensitiveNode();
  26628. if (isLeadingSpaceSensitive && !node.prev && node.parent && node.parent.tagDefinition && node.parent.tagDefinition.ignoreFirstLf) {
  26629. return node.type === "interpolation";
  26630. }
  26631. return isLeadingSpaceSensitive;
  26632. function _isLeadingSpaceSensitiveNode() {
  26633. if (isFrontMatterNode(node)) {
  26634. return false;
  26635. }
  26636. if ((node.type === "text" || node.type === "interpolation") && node.prev && (node.prev.type === "text" || node.prev.type === "interpolation")) {
  26637. return true;
  26638. }
  26639. if (!node.parent || node.parent.cssDisplay === "none") {
  26640. return false;
  26641. }
  26642. if (isPreLikeNode(node.parent)) {
  26643. return true;
  26644. }
  26645. if (!node.prev && (node.parent.type === "root" || isScriptLikeTag$1(node.parent) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  26646. return false;
  26647. }
  26648. if (node.prev && !isNextLeadingSpaceSensitiveCssDisplay(node.prev.cssDisplay)) {
  26649. return false;
  26650. }
  26651. return true;
  26652. }
  26653. }
  26654. function isTrailingSpaceSensitiveNode(node) {
  26655. if (isFrontMatterNode(node)) {
  26656. return false;
  26657. }
  26658. if ((node.type === "text" || node.type === "interpolation") && node.next && (node.next.type === "text" || node.next.type === "interpolation")) {
  26659. return true;
  26660. }
  26661. if (!node.parent || node.parent.cssDisplay === "none") {
  26662. return false;
  26663. }
  26664. if (isPreLikeNode(node.parent)) {
  26665. return true;
  26666. }
  26667. if (!node.next && (node.parent.type === "root" || isScriptLikeTag$1(node.parent) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  26668. return false;
  26669. }
  26670. if (node.next && !isPrevTrailingSpaceSensitiveCssDisplay(node.next.cssDisplay)) {
  26671. return false;
  26672. }
  26673. return true;
  26674. }
  26675. function isDanglingSpaceSensitiveNode(node) {
  26676. return isDanglingSpaceSensitiveCssDisplay(node.cssDisplay) && !isScriptLikeTag$1(node);
  26677. }
  26678. function forceNextEmptyLine$1(node) {
  26679. return isFrontMatterNode(node) || node.next && node.sourceSpan.end.line + 1 < node.next.sourceSpan.start.line;
  26680. }
  26681. /** firstChild leadingSpaces and lastChild trailingSpaces */
  26682. function forceBreakContent$1(node) {
  26683. return forceBreakChildren$1(node) || node.type === "element" && node.children.length !== 0 && (["body", "template", "script", "style"].indexOf(node.name) !== -1 || node.children.some(function (child) {
  26684. return hasNonTextChild(child);
  26685. })) || node.firstChild && node.firstChild === node.lastChild && hasLeadingLineBreak(node.firstChild) && (!node.lastChild.isTrailingSpaceSensitive || hasTrailingLineBreak(node.lastChild));
  26686. }
  26687. /** spaces between children */
  26688. function forceBreakChildren$1(node) {
  26689. 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");
  26690. }
  26691. function preferHardlineAsLeadingSpaces$1(node) {
  26692. return preferHardlineAsSurroundingSpaces(node) || node.prev && preferHardlineAsTrailingSpaces(node.prev) || hasSurroundingLineBreak(node);
  26693. }
  26694. function preferHardlineAsTrailingSpaces(node) {
  26695. return preferHardlineAsSurroundingSpaces(node) || node.type === "element" && node.fullName === "br" || hasSurroundingLineBreak(node);
  26696. }
  26697. function hasSurroundingLineBreak(node) {
  26698. return hasLeadingLineBreak(node) && hasTrailingLineBreak(node);
  26699. }
  26700. function hasLeadingLineBreak(node) {
  26701. 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);
  26702. }
  26703. function hasTrailingLineBreak(node) {
  26704. 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);
  26705. }
  26706. function preferHardlineAsSurroundingSpaces(node) {
  26707. switch (node.type) {
  26708. case "ieConditionalComment":
  26709. case "comment":
  26710. case "directive":
  26711. return true;
  26712. case "element":
  26713. return ["script", "select"].indexOf(node.name) !== -1;
  26714. }
  26715. return false;
  26716. }
  26717. function getLastDescendant$1(node) {
  26718. return node.lastChild ? getLastDescendant$1(node.lastChild) : node;
  26719. }
  26720. function hasNonTextChild(node) {
  26721. return node.children && node.children.some(function (child) {
  26722. return child.type !== "text";
  26723. });
  26724. }
  26725. function inferScriptParser$1(node) {
  26726. if (node.name === "script" && !node.attrMap.src) {
  26727. 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") {
  26728. return "babel";
  26729. }
  26730. if (node.attrMap.type === "application/x-typescript" || node.attrMap.lang === "ts" || node.attrMap.lang === "tsx") {
  26731. return "typescript";
  26732. }
  26733. if (node.attrMap.type === "text/markdown") {
  26734. return "markdown";
  26735. }
  26736. if (node.attrMap.type === "application/ld+json") {
  26737. return "json";
  26738. }
  26739. }
  26740. if (node.name === "style") {
  26741. if (!node.attrMap.lang || node.attrMap.lang === "postcss") {
  26742. return "css";
  26743. }
  26744. if (node.attrMap.lang === "scss") {
  26745. return "scss";
  26746. }
  26747. if (node.attrMap.lang === "less") {
  26748. return "less";
  26749. }
  26750. }
  26751. return null;
  26752. }
  26753. function isBlockLikeCssDisplay(cssDisplay) {
  26754. return cssDisplay === "block" || cssDisplay === "list-item" || cssDisplay.startsWith("table");
  26755. }
  26756. function isFirstChildLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  26757. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  26758. }
  26759. function isLastChildTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  26760. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  26761. }
  26762. function isPrevTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  26763. return !isBlockLikeCssDisplay(cssDisplay);
  26764. }
  26765. function isNextLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  26766. return !isBlockLikeCssDisplay(cssDisplay);
  26767. }
  26768. function isDanglingSpaceSensitiveCssDisplay(cssDisplay) {
  26769. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  26770. }
  26771. function isPreLikeNode(node) {
  26772. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  26773. }
  26774. function countParents$1(path$$1) {
  26775. var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  26776. return true;
  26777. };
  26778. var counter = 0;
  26779. for (var i = path$$1.stack.length - 1; i >= 0; i--) {
  26780. var value = path$$1.stack[i];
  26781. if (value && typeof value === "object" && !Array.isArray(value) && predicate(value)) {
  26782. counter++;
  26783. }
  26784. }
  26785. return counter;
  26786. }
  26787. function hasParent(node, fn) {
  26788. var current = node;
  26789. while (current) {
  26790. if (fn(current)) {
  26791. return true;
  26792. }
  26793. current = current.parent;
  26794. }
  26795. return false;
  26796. }
  26797. function getNodeCssStyleDisplay(node, options) {
  26798. if (node.prev && node.prev.type === "comment") {
  26799. // <!-- display: block -->
  26800. var match = node.prev.value.match(/^\s*display:\s*([a-z]+)\s*$/);
  26801. if (match) {
  26802. return match[1];
  26803. }
  26804. }
  26805. var isInSvgForeignObject = false;
  26806. if (node.type === "element" && node.namespace === "svg") {
  26807. if (hasParent(node, function (parent) {
  26808. return parent.fullName === "svg:foreignObject";
  26809. })) {
  26810. isInSvgForeignObject = true;
  26811. } else {
  26812. return node.name === "svg" ? "inline-block" : "block";
  26813. }
  26814. }
  26815. switch (options.htmlWhitespaceSensitivity) {
  26816. case "strict":
  26817. return "inline";
  26818. case "ignore":
  26819. return "block";
  26820. default:
  26821. return node.type === "element" && (!node.namespace || isInSvgForeignObject) && CSS_DISPLAY_TAGS[node.name] || CSS_DISPLAY_DEFAULT;
  26822. }
  26823. }
  26824. function getNodeCssStyleWhiteSpace(node) {
  26825. return node.type === "element" && !node.namespace && CSS_WHITE_SPACE_TAGS[node.name] || CSS_WHITE_SPACE_DEFAULT;
  26826. }
  26827. function getMinIndentation(text) {
  26828. var minIndentation = Infinity;
  26829. var _iteratorNormalCompletion2 = true;
  26830. var _didIteratorError2 = false;
  26831. var _iteratorError2 = undefined;
  26832. try {
  26833. for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  26834. var lineText = _step2.value;
  26835. if (lineText.length === 0) {
  26836. continue;
  26837. }
  26838. if (/\S/.test(lineText[0])) {
  26839. return 0;
  26840. }
  26841. var indentation = lineText.match(/^\s*/)[0].length;
  26842. if (lineText.length === indentation) {
  26843. continue;
  26844. }
  26845. if (indentation < minIndentation) {
  26846. minIndentation = indentation;
  26847. }
  26848. }
  26849. } catch (err) {
  26850. _didIteratorError2 = true;
  26851. _iteratorError2 = err;
  26852. } finally {
  26853. try {
  26854. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  26855. _iterator2.return();
  26856. }
  26857. } finally {
  26858. if (_didIteratorError2) {
  26859. throw _iteratorError2;
  26860. }
  26861. }
  26862. }
  26863. return minIndentation === Infinity ? 0 : minIndentation;
  26864. }
  26865. function dedentString$1(text) {
  26866. var minIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getMinIndentation(text);
  26867. return minIndent === 0 ? text : text.split("\n").map(function (lineText) {
  26868. return lineText.slice(minIndent);
  26869. }).join("\n");
  26870. }
  26871. function normalizeParts$2(parts) {
  26872. var newParts = [];
  26873. var restParts = parts.slice();
  26874. while (restParts.length !== 0) {
  26875. var part = restParts.shift();
  26876. if (!part) {
  26877. continue;
  26878. }
  26879. if (part.type === "concat") {
  26880. Array.prototype.unshift.apply(restParts, part.parts);
  26881. continue;
  26882. }
  26883. if (newParts.length !== 0 && typeof newParts[newParts.length - 1] === "string" && typeof part === "string") {
  26884. newParts.push(newParts.pop() + part);
  26885. continue;
  26886. }
  26887. newParts.push(part);
  26888. }
  26889. return newParts;
  26890. }
  26891. function identity$2(x) {
  26892. return x;
  26893. }
  26894. function shouldNotPrintClosingTag$1(node, options) {
  26895. return !node.isSelfClosing && !node.endSourceSpan && (hasPrettierIgnore$3(node) || shouldPreserveContent$1(node.parent, options));
  26896. }
  26897. function countChars$1(text, char) {
  26898. var counter = 0;
  26899. for (var i = 0; i < text.length; i++) {
  26900. if (text[i] === char) {
  26901. counter++;
  26902. }
  26903. }
  26904. return counter;
  26905. }
  26906. function unescapeQuoteEntities$1(text) {
  26907. return text.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  26908. }
  26909. var utils$10 = {
  26910. HTML_ELEMENT_ATTRIBUTES,
  26911. HTML_TAGS,
  26912. canHaveInterpolation,
  26913. countChars: countChars$1,
  26914. countParents: countParents$1,
  26915. dedentString: dedentString$1,
  26916. forceBreakChildren: forceBreakChildren$1,
  26917. forceBreakContent: forceBreakContent$1,
  26918. forceNextEmptyLine: forceNextEmptyLine$1,
  26919. getLastDescendant: getLastDescendant$1,
  26920. getNodeCssStyleDisplay,
  26921. getNodeCssStyleWhiteSpace,
  26922. getPrettierIgnoreAttributeCommentData: getPrettierIgnoreAttributeCommentData$1,
  26923. hasPrettierIgnore: hasPrettierIgnore$3,
  26924. identity: identity$2,
  26925. inferScriptParser: inferScriptParser$1,
  26926. isDanglingSpaceSensitiveNode,
  26927. isFrontMatterNode,
  26928. isIndentationSensitiveNode,
  26929. isLeadingSpaceSensitiveNode,
  26930. isPreLikeNode,
  26931. isScriptLikeTag: isScriptLikeTag$1,
  26932. isTextLikeNode: isTextLikeNode$1,
  26933. isTrailingSpaceSensitiveNode,
  26934. isWhitespaceSensitiveNode,
  26935. normalizeParts: normalizeParts$2,
  26936. preferHardlineAsLeadingSpaces: preferHardlineAsLeadingSpaces$1,
  26937. preferHardlineAsTrailingSpaces,
  26938. shouldNotPrintClosingTag: shouldNotPrintClosingTag$1,
  26939. shouldPreserveContent: shouldPreserveContent$1,
  26940. unescapeQuoteEntities: unescapeQuoteEntities$1
  26941. };
  26942. var canHaveInterpolation$1 = utils$10.canHaveInterpolation;
  26943. var getNodeCssStyleDisplay$1 = utils$10.getNodeCssStyleDisplay;
  26944. var isDanglingSpaceSensitiveNode$1 = utils$10.isDanglingSpaceSensitiveNode;
  26945. var isIndentationSensitiveNode$1 = utils$10.isIndentationSensitiveNode;
  26946. var isLeadingSpaceSensitiveNode$1 = utils$10.isLeadingSpaceSensitiveNode;
  26947. var isTrailingSpaceSensitiveNode$1 = utils$10.isTrailingSpaceSensitiveNode;
  26948. var isWhitespaceSensitiveNode$1 = utils$10.isWhitespaceSensitiveNode;
  26949. var PREPROCESS_PIPELINE = [removeIgnorableFirstLf, mergeIeConditonalStartEndCommentIntoElementOpeningTag, mergeCdataIntoText, extractInterpolation, extractWhitespaces, addCssDisplay, addIsSelfClosing, addHasHtmComponentClosingTag, addIsSpaceSensitive, mergeSimpleElementIntoText];
  26950. function preprocess$4(ast, options) {
  26951. for (var _i = 0; _i < PREPROCESS_PIPELINE.length; _i++) {
  26952. var fn = PREPROCESS_PIPELINE[_i];
  26953. ast = fn(ast, options);
  26954. }
  26955. return ast;
  26956. }
  26957. function removeIgnorableFirstLf(ast
  26958. /*, options */
  26959. ) {
  26960. return ast.map(function (node) {
  26961. if (node.type === "element" && node.tagDefinition.ignoreFirstLf && node.children.length !== 0 && node.children[0].type === "text" && node.children[0].value[0] === "\n") {
  26962. var text = node.children[0];
  26963. return node.clone({
  26964. children: text.value.length === 1 ? node.children.slice(1) : [].concat(text.clone({
  26965. value: text.value.slice(1)
  26966. }), node.children.slice(1))
  26967. });
  26968. }
  26969. return node;
  26970. });
  26971. }
  26972. function mergeIeConditonalStartEndCommentIntoElementOpeningTag(ast
  26973. /*, options */
  26974. ) {
  26975. /**
  26976. * <!--[if ...]><!--><target><!--<![endif]-->
  26977. */
  26978. var isTarget = function isTarget(node) {
  26979. 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;
  26980. };
  26981. return ast.map(function (node) {
  26982. if (node.children) {
  26983. var isTargetResults = node.children.map(isTarget);
  26984. if (isTargetResults.some(Boolean)) {
  26985. var newChildren = [];
  26986. for (var i = 0; i < node.children.length; i++) {
  26987. var child = node.children[i];
  26988. if (isTargetResults[i + 1]) {
  26989. // ieConditionalStartComment
  26990. continue;
  26991. }
  26992. if (isTargetResults[i]) {
  26993. var ieConditionalStartComment = child.prev;
  26994. var ieConditionalEndComment = child.firstChild;
  26995. var ParseSourceSpan = child.sourceSpan.constructor;
  26996. var startSourceSpan = new ParseSourceSpan(ieConditionalStartComment.sourceSpan.start, ieConditionalEndComment.sourceSpan.end);
  26997. var sourceSpan = new ParseSourceSpan(startSourceSpan.start, child.sourceSpan.end);
  26998. newChildren.push(child.clone({
  26999. condition: ieConditionalStartComment.condition,
  27000. sourceSpan,
  27001. startSourceSpan,
  27002. children: child.children.slice(1)
  27003. }));
  27004. continue;
  27005. }
  27006. newChildren.push(child);
  27007. }
  27008. return node.clone({
  27009. children: newChildren
  27010. });
  27011. }
  27012. }
  27013. return node;
  27014. });
  27015. }
  27016. function mergeNodeIntoText(ast, shouldMerge, getValue) {
  27017. return ast.map(function (node) {
  27018. if (node.children) {
  27019. var shouldMergeResults = node.children.map(shouldMerge);
  27020. if (shouldMergeResults.some(Boolean)) {
  27021. var newChildren = [];
  27022. for (var i = 0; i < node.children.length; i++) {
  27023. var child = node.children[i];
  27024. if (child.type !== "text" && !shouldMergeResults[i]) {
  27025. newChildren.push(child);
  27026. continue;
  27027. }
  27028. var newChild = child.type === "text" ? child : child.clone({
  27029. type: "text",
  27030. value: getValue(child)
  27031. });
  27032. if (newChildren.length === 0 || newChildren[newChildren.length - 1].type !== "text") {
  27033. newChildren.push(newChild);
  27034. continue;
  27035. }
  27036. var lastChild = newChildren.pop();
  27037. var ParseSourceSpan = lastChild.sourceSpan.constructor;
  27038. newChildren.push(lastChild.clone({
  27039. value: lastChild.value + newChild.value,
  27040. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, newChild.sourceSpan.end)
  27041. }));
  27042. }
  27043. return node.clone({
  27044. children: newChildren
  27045. });
  27046. }
  27047. }
  27048. return node;
  27049. });
  27050. }
  27051. function mergeCdataIntoText(ast
  27052. /*, options */
  27053. ) {
  27054. return mergeNodeIntoText(ast, function (node) {
  27055. return node.type === "cdata";
  27056. }, function (node) {
  27057. return `<![CDATA[${node.value}]]>`;
  27058. });
  27059. }
  27060. function mergeSimpleElementIntoText(ast
  27061. /*, options */
  27062. ) {
  27063. var isSimpleElement = function isSimpleElement(node) {
  27064. return node.type === "element" && node.attrs.length === 0 && node.children.length === 1 && node.firstChild.type === "text" && // \xA0: non-breaking whitespace
  27065. !/[^\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";
  27066. };
  27067. return ast.map(function (node) {
  27068. if (node.children) {
  27069. var isSimpleElementResults = node.children.map(isSimpleElement);
  27070. if (isSimpleElementResults.some(Boolean)) {
  27071. var newChildren = [];
  27072. for (var i = 0; i < node.children.length; i++) {
  27073. var child = node.children[i];
  27074. if (isSimpleElementResults[i]) {
  27075. var lastChild = newChildren.pop();
  27076. var nextChild = node.children[++i];
  27077. var ParseSourceSpan = node.sourceSpan.constructor;
  27078. var isTrailingSpaceSensitive = nextChild.isTrailingSpaceSensitive,
  27079. hasTrailingSpaces = nextChild.hasTrailingSpaces;
  27080. newChildren.push(lastChild.clone({
  27081. value: lastChild.value + `<${child.rawName}>` + child.firstChild.value + `</${child.rawName}>` + nextChild.value,
  27082. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, nextChild.sourceSpan.end),
  27083. isTrailingSpaceSensitive,
  27084. hasTrailingSpaces
  27085. }));
  27086. } else {
  27087. newChildren.push(child);
  27088. }
  27089. }
  27090. return node.clone({
  27091. children: newChildren
  27092. });
  27093. }
  27094. }
  27095. return node;
  27096. });
  27097. }
  27098. function extractInterpolation(ast, options) {
  27099. if (options.parser === "html") {
  27100. return ast;
  27101. }
  27102. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  27103. return ast.map(function (node) {
  27104. if (!canHaveInterpolation$1(node)) {
  27105. return node;
  27106. }
  27107. var newChildren = [];
  27108. var _iteratorNormalCompletion = true;
  27109. var _didIteratorError = false;
  27110. var _iteratorError = undefined;
  27111. try {
  27112. for (var _iterator = node.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  27113. var child = _step.value;
  27114. if (child.type !== "text") {
  27115. newChildren.push(child);
  27116. continue;
  27117. }
  27118. var ParseSourceSpan = child.sourceSpan.constructor;
  27119. var startSourceSpan = child.sourceSpan.start;
  27120. var endSourceSpan = null;
  27121. var components = child.value.split(interpolationRegex);
  27122. for (var i = 0; i < components.length; i++, startSourceSpan = endSourceSpan) {
  27123. var value = components[i];
  27124. if (i % 2 === 0) {
  27125. endSourceSpan = startSourceSpan.moveBy(value.length);
  27126. if (value.length !== 0) {
  27127. newChildren.push({
  27128. type: "text",
  27129. value,
  27130. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan)
  27131. });
  27132. }
  27133. continue;
  27134. }
  27135. endSourceSpan = startSourceSpan.moveBy(value.length + 4); // `{{` + `}}`
  27136. newChildren.push({
  27137. type: "interpolation",
  27138. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan),
  27139. children: value.length === 0 ? [] : [{
  27140. type: "text",
  27141. value,
  27142. sourceSpan: new ParseSourceSpan(startSourceSpan.moveBy(2), endSourceSpan.moveBy(-2))
  27143. }]
  27144. });
  27145. }
  27146. }
  27147. } catch (err) {
  27148. _didIteratorError = true;
  27149. _iteratorError = err;
  27150. } finally {
  27151. try {
  27152. if (!_iteratorNormalCompletion && _iterator.return != null) {
  27153. _iterator.return();
  27154. }
  27155. } finally {
  27156. if (_didIteratorError) {
  27157. throw _iteratorError;
  27158. }
  27159. }
  27160. }
  27161. return node.clone({
  27162. children: newChildren
  27163. });
  27164. });
  27165. }
  27166. /**
  27167. * - add `hasLeadingSpaces` field
  27168. * - add `hasTrailingSpaces` field
  27169. * - add `hasDanglingSpaces` field for parent nodes
  27170. * - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes
  27171. * - remove insensitive whitespaces
  27172. */
  27173. function extractWhitespaces(ast
  27174. /*, options*/
  27175. ) {
  27176. var TYPE_WHITESPACE = "whitespace";
  27177. return ast.map(function (node) {
  27178. if (!node.children) {
  27179. return node;
  27180. }
  27181. if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "text" && node.children[0].value.trim().length === 0) {
  27182. return node.clone({
  27183. children: [],
  27184. hasDanglingSpaces: node.children.length !== 0
  27185. });
  27186. }
  27187. var isWhitespaceSensitive = isWhitespaceSensitiveNode$1(node);
  27188. var isIndentationSensitive = isIndentationSensitiveNode$1(node);
  27189. return node.clone({
  27190. isWhitespaceSensitive,
  27191. isIndentationSensitive,
  27192. children: node.children // extract whitespace nodes
  27193. .reduce(function (newChildren, child) {
  27194. if (child.type !== "text" || isWhitespaceSensitive) {
  27195. return newChildren.concat(child);
  27196. }
  27197. var localChildren = [];
  27198. var _child$value$match = child.value.match(/^(\s*)([\s\S]*?)(\s*)$/),
  27199. _child$value$match2 = _slicedToArray(_child$value$match, 4),
  27200. leadingSpaces = _child$value$match2[1],
  27201. text = _child$value$match2[2],
  27202. trailingSpaces = _child$value$match2[3];
  27203. if (leadingSpaces) {
  27204. localChildren.push({
  27205. type: TYPE_WHITESPACE
  27206. });
  27207. }
  27208. var ParseSourceSpan = child.sourceSpan.constructor;
  27209. if (text) {
  27210. localChildren.push({
  27211. type: "text",
  27212. value: text,
  27213. sourceSpan: new ParseSourceSpan(child.sourceSpan.start.moveBy(leadingSpaces.length), child.sourceSpan.end.moveBy(-trailingSpaces.length))
  27214. });
  27215. }
  27216. if (trailingSpaces) {
  27217. localChildren.push({
  27218. type: TYPE_WHITESPACE
  27219. });
  27220. }
  27221. return newChildren.concat(localChildren);
  27222. }, []) // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes
  27223. .reduce(function (newChildren, child, i, children) {
  27224. if (child.type === TYPE_WHITESPACE) {
  27225. return newChildren;
  27226. }
  27227. var hasLeadingSpaces = i !== 0 && children[i - 1].type === TYPE_WHITESPACE;
  27228. var hasTrailingSpaces = i !== children.length - 1 && children[i + 1].type === TYPE_WHITESPACE;
  27229. return newChildren.concat(Object.assign({}, child, {
  27230. hasLeadingSpaces,
  27231. hasTrailingSpaces
  27232. }));
  27233. }, [])
  27234. });
  27235. });
  27236. }
  27237. function addIsSelfClosing(ast
  27238. /*, options */
  27239. ) {
  27240. return ast.map(function (node) {
  27241. return Object.assign(node, {
  27242. isSelfClosing: !node.children || node.type === "element" && (node.tagDefinition.isVoid || // self-closing
  27243. node.startSourceSpan === node.endSourceSpan)
  27244. });
  27245. });
  27246. }
  27247. function addHasHtmComponentClosingTag(ast, options) {
  27248. return ast.map(function (node) {
  27249. return node.type !== "element" ? node : Object.assign(node, {
  27250. hasHtmComponentClosingTag: node.endSourceSpan && /^<\s*\/\s*\/\s*>$/.test(options.originalText.slice(node.endSourceSpan.start.offset, node.endSourceSpan.end.offset))
  27251. });
  27252. });
  27253. }
  27254. function addCssDisplay(ast, options) {
  27255. return ast.map(function (node) {
  27256. return Object.assign(node, {
  27257. cssDisplay: getNodeCssStyleDisplay$1(node, options)
  27258. });
  27259. });
  27260. }
  27261. /**
  27262. * - add `isLeadingSpaceSensitive` field
  27263. * - add `isTrailingSpaceSensitive` field
  27264. * - add `isDanglingSpaceSensitive` field for parent nodes
  27265. */
  27266. function addIsSpaceSensitive(ast
  27267. /*, options */
  27268. ) {
  27269. return ast.map(function (node) {
  27270. if (!node.children) {
  27271. return node;
  27272. }
  27273. if (node.children.length === 0) {
  27274. return node.clone({
  27275. isDanglingSpaceSensitive: isDanglingSpaceSensitiveNode$1(node)
  27276. });
  27277. }
  27278. return node.clone({
  27279. children: node.children.map(function (child) {
  27280. return Object.assign({}, child, {
  27281. isLeadingSpaceSensitive: isLeadingSpaceSensitiveNode$1(child),
  27282. isTrailingSpaceSensitive: isTrailingSpaceSensitiveNode$1(child)
  27283. });
  27284. }).map(function (child, index, children) {
  27285. return Object.assign({}, child, {
  27286. isLeadingSpaceSensitive: index === 0 ? child.isLeadingSpaceSensitive : children[index - 1].isTrailingSpaceSensitive && child.isLeadingSpaceSensitive,
  27287. isTrailingSpaceSensitive: index === children.length - 1 ? child.isTrailingSpaceSensitive : children[index + 1].isLeadingSpaceSensitive && child.isTrailingSpaceSensitive
  27288. });
  27289. })
  27290. });
  27291. });
  27292. }
  27293. var preprocess_1$4 = preprocess$4;
  27294. function hasPragma$3(text) {
  27295. return /^\s*<!--\s*@(format|prettier)\s*-->/.test(text);
  27296. }
  27297. function insertPragma$7(text) {
  27298. return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, "");
  27299. }
  27300. var pragma$9 = {
  27301. hasPragma: hasPragma$3,
  27302. insertPragma: insertPragma$7
  27303. };
  27304. var _require$$0$builders$8 = doc.builders;
  27305. var concat$15 = _require$$0$builders$8.concat;
  27306. var group$15 = _require$$0$builders$8.group;
  27307. /**
  27308. * v-for="... in ..."
  27309. * v-for="... of ..."
  27310. * v-for="(..., ...) in ..."
  27311. * v-for="(..., ...) of ..."
  27312. */
  27313. function printVueFor$1(value, textToDoc) {
  27314. var _parseVueFor = parseVueFor(value),
  27315. left = _parseVueFor.left,
  27316. operator = _parseVueFor.operator,
  27317. right = _parseVueFor.right;
  27318. return concat$15([group$15(textToDoc(`function _(${left}) {}`, {
  27319. parser: "babel",
  27320. __isVueForBindingLeft: true
  27321. })), " ", operator, " ", textToDoc(right, {
  27322. parser: "__js_expression"
  27323. })]);
  27324. } // modified from https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/parser/index.js#L370-L387
  27325. function parseVueFor(value) {
  27326. var forAliasRE = /([^]*?)\s+(in|of)\s+([^]*)/;
  27327. var forIteratorRE = /,([^,}\]]*)(?:,([^,}\]]*))?$/;
  27328. var stripParensRE = /^\(|\)$/g;
  27329. var inMatch = value.match(forAliasRE);
  27330. if (!inMatch) {
  27331. return;
  27332. }
  27333. var res = {};
  27334. res.for = inMatch[3].trim();
  27335. var alias = inMatch[1].trim().replace(stripParensRE, "");
  27336. var iteratorMatch = alias.match(forIteratorRE);
  27337. if (iteratorMatch) {
  27338. res.alias = alias.replace(forIteratorRE, "");
  27339. res.iterator1 = iteratorMatch[1].trim();
  27340. if (iteratorMatch[2]) {
  27341. res.iterator2 = iteratorMatch[2].trim();
  27342. }
  27343. } else {
  27344. res.alias = alias;
  27345. }
  27346. return {
  27347. left: `${[res.alias, res.iterator1, res.iterator2].filter(Boolean).join(",")}`,
  27348. operator: inMatch[2],
  27349. right: res.for
  27350. };
  27351. }
  27352. function printVueSlotScope$1(value, textToDoc) {
  27353. return textToDoc(`function _(${value}) {}`, {
  27354. parser: "babel",
  27355. __isVueSlotScope: true
  27356. });
  27357. }
  27358. function isVueEventBindingExpression$3(eventBindingValue) {
  27359. // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/codegen/events.js#L3-L4
  27360. // arrow function or anonymous function
  27361. var fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/; // simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b])
  27362. 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
  27363. var value = eventBindingValue.trim();
  27364. return fnExpRE.test(value) || simplePathRE.test(value);
  27365. }
  27366. var syntaxVue = {
  27367. isVueEventBindingExpression: isVueEventBindingExpression$3,
  27368. printVueFor: printVueFor$1,
  27369. printVueSlotScope: printVueSlotScope$1
  27370. };
  27371. var parseSrcset = createCommonjsModule(function (module) {
  27372. /**
  27373. * Srcset Parser
  27374. *
  27375. * By Alex Bell | MIT License
  27376. *
  27377. * JS Parser for the string value that appears in markup <img srcset="here">
  27378. *
  27379. * @returns Array [{url: _, d: _, w: _, h:_}, ...]
  27380. *
  27381. * Based super duper closely on the reference algorithm at:
  27382. * https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute
  27383. *
  27384. * Most comments are copied in directly from the spec
  27385. * (except for comments in parens).
  27386. */
  27387. (function (root, factory) {
  27388. if (typeof undefined === 'function' && undefined.amd) {
  27389. // AMD. Register as an anonymous module.
  27390. undefined([], factory);
  27391. } else if ('object' === 'object' && module.exports) {
  27392. // Node. Does not work with strict CommonJS, but
  27393. // only CommonJS-like environments that support module.exports,
  27394. // like Node.
  27395. module.exports = factory();
  27396. } else {
  27397. // Browser globals (root is window)
  27398. root.parseSrcset = factory();
  27399. }
  27400. })(commonjsGlobal, function () {
  27401. // 1. Let input be the value passed to this algorithm.
  27402. return function (input, options) {
  27403. var logger = options && options.logger || console; // UTILITY FUNCTIONS
  27404. // Manual is faster than RegEx
  27405. // http://bjorn.tipling.com/state-and-regular-expressions-in-javascript
  27406. // http://jsperf.com/whitespace-character/5
  27407. function isSpace(c) {
  27408. return c === "\u0020" || // space
  27409. c === "\u0009" || // horizontal tab
  27410. c === "\u000A" || // new line
  27411. c === "\u000C" || // form feed
  27412. c === "\u000D"; // carriage return
  27413. }
  27414. function collectCharacters(regEx) {
  27415. var chars,
  27416. match = regEx.exec(input.substring(pos));
  27417. if (match) {
  27418. chars = match[0];
  27419. pos += chars.length;
  27420. return chars;
  27421. }
  27422. }
  27423. var inputLength = input.length,
  27424. // (Don't use \s, to avoid matching non-breaking space)
  27425. regexLeadingSpaces = /^[ \t\n\r\u000c]+/,
  27426. regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/,
  27427. regexLeadingNotSpaces = /^[^ \t\n\r\u000c]+/,
  27428. regexTrailingCommas = /[,]+$/,
  27429. regexNonNegativeInteger = /^\d+$/,
  27430. // ( Positive or negative or unsigned integers or decimals, without or without exponents.
  27431. // Must include at least one digit.
  27432. // According to spec tests any decimal point must be followed by a digit.
  27433. // No leading plus sign is allowed.)
  27434. // https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
  27435. regexFloatingPoint = /^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,
  27436. url,
  27437. descriptors,
  27438. currentDescriptor,
  27439. state,
  27440. c,
  27441. // 2. Let position be a pointer into input, initially pointing at the start
  27442. // of the string.
  27443. pos = 0,
  27444. // 3. Let candidates be an initially empty source set.
  27445. candidates = []; // 4. Splitting loop: Collect a sequence of characters that are space
  27446. // characters or U+002C COMMA characters. If any U+002C COMMA characters
  27447. // were collected, that is a parse error.
  27448. while (true) {
  27449. collectCharacters(regexLeadingCommasOrSpaces); // 5. If position is past the end of input, return candidates and abort these steps.
  27450. if (pos >= inputLength) {
  27451. return candidates; // (we're done, this is the sole return path)
  27452. } // 6. Collect a sequence of characters that are not space characters,
  27453. // and let that be url.
  27454. url = collectCharacters(regexLeadingNotSpaces); // 7. Let descriptors be a new empty list.
  27455. descriptors = []; // 8. If url ends with a U+002C COMMA character (,), follow these substeps:
  27456. // (1). Remove all trailing U+002C COMMA characters from url. If this removed
  27457. // more than one character, that is a parse error.
  27458. if (url.slice(-1) === ",") {
  27459. url = url.replace(regexTrailingCommas, ""); // (Jump ahead to step 9 to skip tokenization and just push the candidate).
  27460. parseDescriptors(); // Otherwise, follow these substeps:
  27461. } else {
  27462. tokenize();
  27463. } // (close else of step 8)
  27464. // 16. Return to the step labeled splitting loop.
  27465. } // (Close of big while loop.)
  27466. /**
  27467. * Tokenizes descriptor properties prior to parsing
  27468. * Returns undefined.
  27469. */
  27470. function tokenize() {
  27471. // 8.1. Descriptor tokeniser: Skip whitespace
  27472. collectCharacters(regexLeadingSpaces); // 8.2. Let current descriptor be the empty string.
  27473. currentDescriptor = ""; // 8.3. Let state be in descriptor.
  27474. state = "in descriptor";
  27475. while (true) {
  27476. // 8.4. Let c be the character at position.
  27477. c = input.charAt(pos); // Do the following depending on the value of state.
  27478. // For the purpose of this step, "EOF" is a special character representing
  27479. // that position is past the end of input.
  27480. // In descriptor
  27481. if (state === "in descriptor") {
  27482. // Do the following, depending on the value of c:
  27483. // Space character
  27484. // If current descriptor is not empty, append current descriptor to
  27485. // descriptors and let current descriptor be the empty string.
  27486. // Set state to after descriptor.
  27487. if (isSpace(c)) {
  27488. if (currentDescriptor) {
  27489. descriptors.push(currentDescriptor);
  27490. currentDescriptor = "";
  27491. state = "after descriptor";
  27492. } // U+002C COMMA (,)
  27493. // Advance position to the next character in input. If current descriptor
  27494. // is not empty, append current descriptor to descriptors. Jump to the step
  27495. // labeled descriptor parser.
  27496. } else if (c === ",") {
  27497. pos += 1;
  27498. if (currentDescriptor) {
  27499. descriptors.push(currentDescriptor);
  27500. }
  27501. parseDescriptors();
  27502. return; // U+0028 LEFT PARENTHESIS (()
  27503. // Append c to current descriptor. Set state to in parens.
  27504. } else if (c === "\u0028") {
  27505. currentDescriptor = currentDescriptor + c;
  27506. state = "in parens"; // EOF
  27507. // If current descriptor is not empty, append current descriptor to
  27508. // descriptors. Jump to the step labeled descriptor parser.
  27509. } else if (c === "") {
  27510. if (currentDescriptor) {
  27511. descriptors.push(currentDescriptor);
  27512. }
  27513. parseDescriptors();
  27514. return; // Anything else
  27515. // Append c to current descriptor.
  27516. } else {
  27517. currentDescriptor = currentDescriptor + c;
  27518. } // (end "in descriptor"
  27519. // In parens
  27520. } else if (state === "in parens") {
  27521. // U+0029 RIGHT PARENTHESIS ())
  27522. // Append c to current descriptor. Set state to in descriptor.
  27523. if (c === ")") {
  27524. currentDescriptor = currentDescriptor + c;
  27525. state = "in descriptor"; // EOF
  27526. // Append current descriptor to descriptors. Jump to the step labeled
  27527. // descriptor parser.
  27528. } else if (c === "") {
  27529. descriptors.push(currentDescriptor);
  27530. parseDescriptors();
  27531. return; // Anything else
  27532. // Append c to current descriptor.
  27533. } else {
  27534. currentDescriptor = currentDescriptor + c;
  27535. } // After descriptor
  27536. } else if (state === "after descriptor") {
  27537. // Do the following, depending on the value of c:
  27538. // Space character: Stay in this state.
  27539. if (isSpace(c)) {// EOF: Jump to the step labeled descriptor parser.
  27540. } else if (c === "") {
  27541. parseDescriptors();
  27542. return; // Anything else
  27543. // Set state to in descriptor. Set position to the previous character in input.
  27544. } else {
  27545. state = "in descriptor";
  27546. pos -= 1;
  27547. }
  27548. } // Advance position to the next character in input.
  27549. pos += 1; // Repeat this step.
  27550. } // (close while true loop)
  27551. }
  27552. /**
  27553. * Adds descriptor properties to a candidate, pushes to the candidates array
  27554. * @return undefined
  27555. */
  27556. // Declared outside of the while loop so that it's only created once.
  27557. function parseDescriptors() {
  27558. // 9. Descriptor parser: Let error be no.
  27559. var pError = false,
  27560. // 10. Let width be absent.
  27561. // 11. Let density be absent.
  27562. // 12. Let future-compat-h be absent. (We're implementing it now as h)
  27563. w,
  27564. d,
  27565. h,
  27566. i,
  27567. candidate = {},
  27568. desc,
  27569. lastChar,
  27570. value,
  27571. intVal,
  27572. floatVal; // 13. For each descriptor in descriptors, run the appropriate set of steps
  27573. // from the following list:
  27574. for (i = 0; i < descriptors.length; i++) {
  27575. desc = descriptors[i];
  27576. lastChar = desc[desc.length - 1];
  27577. value = desc.substring(0, desc.length - 1);
  27578. intVal = parseInt(value, 10);
  27579. floatVal = parseFloat(value); // If the descriptor consists of a valid non-negative integer followed by
  27580. // a U+0077 LATIN SMALL LETTER W character
  27581. if (regexNonNegativeInteger.test(value) && lastChar === "w") {
  27582. // If width and density are not both absent, then let error be yes.
  27583. if (w || d) {
  27584. pError = true;
  27585. } // Apply the rules for parsing non-negative integers to the descriptor.
  27586. // If the result is zero, let error be yes.
  27587. // Otherwise, let width be the result.
  27588. if (intVal === 0) {
  27589. pError = true;
  27590. } else {
  27591. w = intVal;
  27592. } // If the descriptor consists of a valid floating-point number followed by
  27593. // a U+0078 LATIN SMALL LETTER X character
  27594. } else if (regexFloatingPoint.test(value) && lastChar === "x") {
  27595. // If width, density and future-compat-h are not all absent, then let error
  27596. // be yes.
  27597. if (w || d || h) {
  27598. pError = true;
  27599. } // Apply the rules for parsing floating-point number values to the descriptor.
  27600. // If the result is less than zero, let error be yes. Otherwise, let density
  27601. // be the result.
  27602. if (floatVal < 0) {
  27603. pError = true;
  27604. } else {
  27605. d = floatVal;
  27606. } // If the descriptor consists of a valid non-negative integer followed by
  27607. // a U+0068 LATIN SMALL LETTER H character
  27608. } else if (regexNonNegativeInteger.test(value) && lastChar === "h") {
  27609. // If height and density are not both absent, then let error be yes.
  27610. if (h || d) {
  27611. pError = true;
  27612. } // Apply the rules for parsing non-negative integers to the descriptor.
  27613. // If the result is zero, let error be yes. Otherwise, let future-compat-h
  27614. // be the result.
  27615. if (intVal === 0) {
  27616. pError = true;
  27617. } else {
  27618. h = intVal;
  27619. } // Anything else, Let error be yes.
  27620. } else {
  27621. pError = true;
  27622. }
  27623. } // (close step 13 for loop)
  27624. // 15. If error is still no, then append a new image source to candidates whose
  27625. // URL is url, associated with a width width if not absent and a pixel
  27626. // density density if not absent. Otherwise, there is a parse error.
  27627. if (!pError) {
  27628. candidate.url = url;
  27629. if (w) {
  27630. candidate.w = w;
  27631. }
  27632. if (d) {
  27633. candidate.d = d;
  27634. }
  27635. if (h) {
  27636. candidate.h = h;
  27637. }
  27638. candidates.push(candidate);
  27639. } else if (logger && logger.error) {
  27640. logger.error("Invalid srcset descriptor found in '" + input + "' at '" + desc + "'.");
  27641. }
  27642. } // (close parseDescriptors fn)
  27643. };
  27644. });
  27645. });
  27646. var _require$$0$builders$9 = doc.builders;
  27647. var concat$16 = _require$$0$builders$9.concat;
  27648. var ifBreak$6 = _require$$0$builders$9.ifBreak;
  27649. var join$11 = _require$$0$builders$9.join;
  27650. var line$10 = _require$$0$builders$9.line;
  27651. function printImgSrcset$1(value) {
  27652. var srcset = parseSrcset(value, {
  27653. logger: {
  27654. error(message) {
  27655. throw new Error(message);
  27656. }
  27657. }
  27658. });
  27659. var hasW = srcset.some(function (src) {
  27660. return src.w;
  27661. });
  27662. var hasH = srcset.some(function (src) {
  27663. return src.h;
  27664. });
  27665. var hasX = srcset.some(function (src) {
  27666. return src.d;
  27667. });
  27668. if (hasW + hasH + hasX !== 1) {
  27669. throw new Error(`Mixed descriptor in srcset is not supported`);
  27670. }
  27671. var key = hasW ? "w" : hasH ? "h" : "d";
  27672. var unit = hasW ? "w" : hasH ? "h" : "x";
  27673. var getMax = function getMax(values) {
  27674. return Math.max.apply(Math, values);
  27675. };
  27676. var urls = srcset.map(function (src) {
  27677. return src.url;
  27678. });
  27679. var maxUrlLength = getMax(urls.map(function (url) {
  27680. return url.length;
  27681. }));
  27682. var descriptors = srcset.map(function (src) {
  27683. return src[key];
  27684. }).map(function (descriptor) {
  27685. return descriptor ? descriptor.toString() : "";
  27686. });
  27687. var descriptorLeftLengths = descriptors.map(function (descriptor) {
  27688. var index = descriptor.indexOf(".");
  27689. return index === -1 ? descriptor.length : index;
  27690. });
  27691. var maxDescriptorLeftLength = getMax(descriptorLeftLengths);
  27692. return join$11(concat$16([",", line$10]), urls.map(function (url, index) {
  27693. var parts = [url];
  27694. var descriptor = descriptors[index];
  27695. if (descriptor) {
  27696. var urlPadding = maxUrlLength - url.length + 1;
  27697. var descriptorPadding = maxDescriptorLeftLength - descriptorLeftLengths[index];
  27698. var alignment = " ".repeat(urlPadding + descriptorPadding);
  27699. parts.push(ifBreak$6(alignment, " "), descriptor + unit);
  27700. }
  27701. return concat$16(parts);
  27702. }));
  27703. }
  27704. var syntaxAttribute = {
  27705. printImgSrcset: printImgSrcset$1
  27706. };
  27707. var builders = doc.builders;
  27708. var _require$$0$utils = doc.utils;
  27709. var stripTrailingHardline$2 = _require$$0$utils.stripTrailingHardline;
  27710. var mapDoc$7 = _require$$0$utils.mapDoc;
  27711. var breakParent$3 = builders.breakParent;
  27712. var dedentToRoot$2 = builders.dedentToRoot;
  27713. var fill$5 = builders.fill;
  27714. var group$14 = builders.group;
  27715. var hardline$12 = builders.hardline;
  27716. var ifBreak$5 = builders.ifBreak;
  27717. var indent$9 = builders.indent;
  27718. var join$10 = builders.join;
  27719. var line$9 = builders.line;
  27720. var literalline$6 = builders.literalline;
  27721. var markAsRoot$4 = builders.markAsRoot;
  27722. var softline$7 = builders.softline;
  27723. var countChars = utils$10.countChars;
  27724. var countParents = utils$10.countParents;
  27725. var dedentString = utils$10.dedentString;
  27726. var forceBreakChildren = utils$10.forceBreakChildren;
  27727. var forceBreakContent = utils$10.forceBreakContent;
  27728. var forceNextEmptyLine = utils$10.forceNextEmptyLine;
  27729. var getLastDescendant = utils$10.getLastDescendant;
  27730. var getPrettierIgnoreAttributeCommentData = utils$10.getPrettierIgnoreAttributeCommentData;
  27731. var hasPrettierIgnore$2 = utils$10.hasPrettierIgnore;
  27732. var inferScriptParser = utils$10.inferScriptParser;
  27733. var isScriptLikeTag = utils$10.isScriptLikeTag;
  27734. var isTextLikeNode = utils$10.isTextLikeNode;
  27735. var normalizeParts$1 = utils$10.normalizeParts;
  27736. var preferHardlineAsLeadingSpaces = utils$10.preferHardlineAsLeadingSpaces;
  27737. var shouldNotPrintClosingTag = utils$10.shouldNotPrintClosingTag;
  27738. var shouldPreserveContent = utils$10.shouldPreserveContent;
  27739. var unescapeQuoteEntities = utils$10.unescapeQuoteEntities;
  27740. var replaceEndOfLineWith$2 = util$1.replaceEndOfLineWith;
  27741. var insertPragma$6 = pragma$9.insertPragma;
  27742. var printVueFor = syntaxVue.printVueFor;
  27743. var printVueSlotScope = syntaxVue.printVueSlotScope;
  27744. var isVueEventBindingExpression$2 = syntaxVue.isVueEventBindingExpression;
  27745. var printImgSrcset = syntaxAttribute.printImgSrcset;
  27746. function concat$14(parts) {
  27747. var newParts = normalizeParts$1(parts);
  27748. return newParts.length === 0 ? "" : newParts.length === 1 ? newParts[0] : builders.concat(newParts);
  27749. }
  27750. function embed$6(path$$1, print, textToDoc, options) {
  27751. var node = path$$1.getValue();
  27752. switch (node.type) {
  27753. case "text":
  27754. {
  27755. if (isScriptLikeTag(node.parent)) {
  27756. var parser = inferScriptParser(node.parent);
  27757. if (parser) {
  27758. var value = parser === "markdown" ? dedentString(node.value.replace(/^[^\S\n]*?\n/, "")) : node.value;
  27759. return builders.concat([concat$14([breakParent$3, printOpeningTagPrefix(node, options), stripTrailingHardline$2(textToDoc(value, {
  27760. parser
  27761. })), printClosingTagSuffix(node, options)])]);
  27762. }
  27763. } else if (node.parent.type === "interpolation") {
  27764. return concat$14([indent$9(concat$14([line$9, textToDoc(node.value, Object.assign({
  27765. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  27766. }, options.parser === "angular" ? {
  27767. parser: "__ng_interpolation",
  27768. trailingComma: "none"
  27769. } : options.parser === "vue" ? {
  27770. parser: "__vue_expression"
  27771. } : {
  27772. parser: "__js_expression"
  27773. }))])), node.parent.next && needsToBorrowPrevClosingTagEndMarker(node.parent.next) ? " " : line$9]);
  27774. }
  27775. break;
  27776. }
  27777. case "attribute":
  27778. {
  27779. if (!node.value) {
  27780. break;
  27781. } // lit-html: html`<my-element obj=${obj}></my-element>`
  27782. if (/^PRETTIER_HTML_PLACEHOLDER_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  27783. return concat$14([node.rawName, "=", node.value]);
  27784. }
  27785. var embeddedAttributeValueDoc = printEmbeddedAttributeValue(node, function (code, opts) {
  27786. return (// strictly prefer single quote to avoid unnecessary html entity escape
  27787. textToDoc(code, Object.assign({
  27788. __isInHtmlAttribute: true
  27789. }, opts))
  27790. );
  27791. }, options);
  27792. if (embeddedAttributeValueDoc) {
  27793. return concat$14([node.rawName, '="', group$14(mapDoc$7(embeddedAttributeValueDoc, function (doc$$2) {
  27794. return typeof doc$$2 === "string" ? doc$$2.replace(/"/g, "&quot;") : doc$$2;
  27795. })), '"']);
  27796. }
  27797. break;
  27798. }
  27799. case "yaml":
  27800. return markAsRoot$4(concat$14(["---", hardline$12, node.value.trim().length === 0 ? "" : textToDoc(node.value, {
  27801. parser: "yaml"
  27802. }), "---"]));
  27803. }
  27804. }
  27805. function genericPrint$5(path$$1, options, print) {
  27806. var node = path$$1.getValue();
  27807. switch (node.type) {
  27808. case "root":
  27809. // use original concat to not break stripTrailingHardline
  27810. return builders.concat([group$14(printChildren$1(path$$1, options, print)), hardline$12]);
  27811. case "element":
  27812. case "ieConditionalComment":
  27813. {
  27814. /**
  27815. * do not break:
  27816. *
  27817. * <div>{{
  27818. * ~
  27819. * interpolation
  27820. * }}</div>
  27821. * ~
  27822. *
  27823. * exception: break if the opening tag breaks
  27824. *
  27825. * <div
  27826. * long
  27827. * ~
  27828. * >{{
  27829. * interpolation
  27830. * }}</div
  27831. * ~
  27832. * >
  27833. */
  27834. var shouldHugContent = node.children.length === 1 && node.firstChild.type === "interpolation" && node.firstChild.isLeadingSpaceSensitive && !node.firstChild.hasLeadingSpaces && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces;
  27835. var attrGroupId = Symbol("element-attr-group-id");
  27836. return concat$14([group$14(concat$14([group$14(printOpeningTag(path$$1, options, print), {
  27837. id: attrGroupId
  27838. }), node.children.length === 0 ? node.hasDanglingSpaces && node.isDanglingSpaceSensitive ? line$9 : "" : concat$14([forceBreakContent(node) ? breakParent$3 : "", function (childrenDoc) {
  27839. return shouldHugContent ? ifBreak$5(indent$9(childrenDoc), childrenDoc, {
  27840. groupId: attrGroupId
  27841. }) : isScriptLikeTag(node) && node.parent.type === "root" && options.parser === "vue" ? childrenDoc : indent$9(childrenDoc);
  27842. }(concat$14([shouldHugContent ? ifBreak$5(softline$7, "", {
  27843. groupId: attrGroupId
  27844. }) : 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$5(softline$7, "", {
  27845. groupId: attrGroupId
  27846. }) : 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) {
  27847. return n.parent && n.parent.type !== "root";
  27848. })}}$`).test(node.lastChild.value) ?
  27849. /**
  27850. * <div>
  27851. * <pre>
  27852. * something
  27853. * </pre>
  27854. * ~
  27855. * </div>
  27856. */
  27857. "" : softline$7])])), printClosingTag(node, options)]);
  27858. }
  27859. case "ieConditionalStartComment":
  27860. case "ieConditionalEndComment":
  27861. return concat$14([printOpeningTagStart(node), printClosingTagEnd(node)]);
  27862. case "interpolation":
  27863. return concat$14([printOpeningTagStart(node, options), concat$14(path$$1.map(print, "children")), printClosingTagEnd(node, options)]);
  27864. case "text":
  27865. {
  27866. if (node.parent.type === "interpolation") {
  27867. // replace the trailing literalline with hardline for better readability
  27868. var trailingNewlineRegex = /\n[^\S\n]*?$/;
  27869. var hasTrailingNewline = trailingNewlineRegex.test(node.value);
  27870. var value = hasTrailingNewline ? node.value.replace(trailingNewlineRegex, "") : node.value;
  27871. return concat$14([concat$14(replaceEndOfLineWith$2(value, literalline$6)), hasTrailingNewline ? hardline$12 : ""]);
  27872. }
  27873. return fill$5(normalizeParts$1([].concat(printOpeningTagPrefix(node, options), getTextValueParts(node), printClosingTagSuffix(node, options))));
  27874. }
  27875. case "docType":
  27876. return concat$14([group$14(concat$14([printOpeningTagStart(node, options), " ", node.value.replace(/^html\b/i, "html").replace(/\s+/g, " ")])), printClosingTagEnd(node, options)]);
  27877. case "comment":
  27878. {
  27879. return concat$14([printOpeningTagPrefix(node, options), concat$14(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(node), options.locEnd(node)), literalline$6)), printClosingTagSuffix(node, options)]);
  27880. }
  27881. case "attribute":
  27882. {
  27883. if (node.value === null) {
  27884. return node.rawName;
  27885. }
  27886. var _value = unescapeQuoteEntities(node.value);
  27887. var singleQuoteCount = countChars(_value, "'");
  27888. var doubleQuoteCount = countChars(_value, '"');
  27889. var quote = singleQuoteCount < doubleQuoteCount ? "'" : '"';
  27890. return concat$14([node.rawName, concat$14(["=", quote, concat$14(replaceEndOfLineWith$2(quote === '"' ? _value.replace(/"/g, "&quot;") : _value.replace(/'/g, "&apos;"), literalline$6)), quote])]);
  27891. }
  27892. case "yaml":
  27893. case "toml":
  27894. return concat$14(replaceEndOfLineWith$2(node.raw, literalline$6));
  27895. default:
  27896. throw new Error(`Unexpected node type ${node.type}`);
  27897. }
  27898. }
  27899. function printChildren$1(path$$1, options, print) {
  27900. var node = path$$1.getValue();
  27901. if (forceBreakChildren(node)) {
  27902. return concat$14([breakParent$3, concat$14(path$$1.map(function (childPath) {
  27903. var childNode = childPath.getValue();
  27904. var prevBetweenLine = !childNode.prev ? "" : printBetweenLine(childNode.prev, childNode);
  27905. return concat$14([!prevBetweenLine ? "" : concat$14([prevBetweenLine, forceNextEmptyLine(childNode.prev) ? hardline$12 : ""]), printChild(childPath)]);
  27906. }, "children"))]);
  27907. }
  27908. var groupIds = node.children.map(function () {
  27909. return Symbol("");
  27910. });
  27911. return concat$14(path$$1.map(function (childPath, childIndex) {
  27912. var childNode = childPath.getValue();
  27913. if (isTextLikeNode(childNode)) {
  27914. if (childNode.prev && isTextLikeNode(childNode.prev)) {
  27915. var _prevBetweenLine = printBetweenLine(childNode.prev, childNode);
  27916. if (_prevBetweenLine) {
  27917. if (forceNextEmptyLine(childNode.prev)) {
  27918. return concat$14([hardline$12, hardline$12, printChild(childPath)]);
  27919. }
  27920. return concat$14([_prevBetweenLine, printChild(childPath)]);
  27921. }
  27922. }
  27923. return printChild(childPath);
  27924. }
  27925. var prevParts = [];
  27926. var leadingParts = [];
  27927. var trailingParts = [];
  27928. var nextParts = [];
  27929. var prevBetweenLine = childNode.prev ? printBetweenLine(childNode.prev, childNode) : "";
  27930. var nextBetweenLine = childNode.next ? printBetweenLine(childNode, childNode.next) : "";
  27931. if (prevBetweenLine) {
  27932. if (forceNextEmptyLine(childNode.prev)) {
  27933. prevParts.push(hardline$12, hardline$12);
  27934. } else if (prevBetweenLine === hardline$12) {
  27935. prevParts.push(hardline$12);
  27936. } else {
  27937. if (isTextLikeNode(childNode.prev)) {
  27938. leadingParts.push(prevBetweenLine);
  27939. } else {
  27940. leadingParts.push(ifBreak$5("", softline$7, {
  27941. groupId: groupIds[childIndex - 1]
  27942. }));
  27943. }
  27944. }
  27945. }
  27946. if (nextBetweenLine) {
  27947. if (forceNextEmptyLine(childNode)) {
  27948. if (isTextLikeNode(childNode.next)) {
  27949. nextParts.push(hardline$12, hardline$12);
  27950. }
  27951. } else if (nextBetweenLine === hardline$12) {
  27952. if (isTextLikeNode(childNode.next)) {
  27953. nextParts.push(hardline$12);
  27954. }
  27955. } else {
  27956. trailingParts.push(nextBetweenLine);
  27957. }
  27958. }
  27959. return concat$14([].concat(prevParts, group$14(concat$14([concat$14(leadingParts), group$14(concat$14([printChild(childPath), concat$14(trailingParts)]), {
  27960. id: groupIds[childIndex]
  27961. })])), nextParts));
  27962. }, "children"));
  27963. function printChild(childPath) {
  27964. var child = childPath.getValue();
  27965. if (hasPrettierIgnore$2(child)) {
  27966. 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)));
  27967. }
  27968. if (shouldPreserveContent(child, options)) {
  27969. 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)));
  27970. }
  27971. return print(childPath);
  27972. }
  27973. function printBetweenLine(prevNode, nextNode) {
  27974. return isTextLikeNode(prevNode) && isTextLikeNode(nextNode) ? prevNode.isTrailingSpaceSensitive ? prevNode.hasTrailingSpaces ? preferHardlineAsLeadingSpaces(nextNode) ? hardline$12 : line$9 : "" : preferHardlineAsLeadingSpaces(nextNode) ? hardline$12 : softline$7 : needsToBorrowNextOpeningTagStartMarker(prevNode) && (
  27975. /**
  27976. * 123<a
  27977. * ~
  27978. * ><b>
  27979. */
  27980. nextNode.firstChild ||
  27981. /**
  27982. * 123<!--
  27983. * ~
  27984. * -->
  27985. */
  27986. nextNode.isSelfClosing ||
  27987. /**
  27988. * 123<span
  27989. * ~
  27990. * attr
  27991. */
  27992. nextNode.type === "element" && nextNode.attrs.length !== 0) ||
  27993. /**
  27994. * <img
  27995. * src="long"
  27996. * ~
  27997. * />123
  27998. */
  27999. prevNode.type === "element" && prevNode.isSelfClosing && needsToBorrowPrevClosingTagEndMarker(nextNode) ? "" : !nextNode.isLeadingSpaceSensitive || preferHardlineAsLeadingSpaces(nextNode) ||
  28000. /**
  28001. * Want to write us a letter? Use our<a
  28002. * ><b><a>mailing address</a></b></a
  28003. * ~
  28004. * >.
  28005. */
  28006. needsToBorrowPrevClosingTagEndMarker(nextNode) && prevNode.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild) && prevNode.lastChild.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild.lastChild) ? hardline$12 : nextNode.hasLeadingSpaces ? line$9 : softline$7;
  28007. }
  28008. }
  28009. function printOpeningTag(path$$1, options, print) {
  28010. var node = path$$1.getValue();
  28011. var forceNotToBreakAttrContent = node.type === "element" && node.fullName === "script" && node.attrs.length === 1 && node.attrs[0].fullName === "src" && node.children.length === 0;
  28012. return concat$14([printOpeningTagStart(node, options), !node.attrs || node.attrs.length === 0 ? node.isSelfClosing ?
  28013. /**
  28014. * <br />
  28015. * ^
  28016. */
  28017. " " : "" : concat$14([indent$9(concat$14([forceNotToBreakAttrContent ? " " : line$9, join$10(line$9, function (ignoreAttributeData) {
  28018. var hasPrettierIgnoreAttribute = typeof ignoreAttributeData === "boolean" ? function () {
  28019. return ignoreAttributeData;
  28020. } : Array.isArray(ignoreAttributeData) ? function (attr) {
  28021. return ignoreAttributeData.indexOf(attr.rawName) !== -1;
  28022. } : function () {
  28023. return false;
  28024. };
  28025. return path$$1.map(function (attrPath) {
  28026. var attr = attrPath.getValue();
  28027. return hasPrettierIgnoreAttribute(attr) ? concat$14(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(attr), options.locEnd(attr)), literalline$6)) : print(attrPath);
  28028. }, "attrs");
  28029. }(node.prev && node.prev.type === "comment" && getPrettierIgnoreAttributeCommentData(node.prev.value)))])),
  28030. /**
  28031. * 123<a
  28032. * attr
  28033. * ~
  28034. * >456
  28035. */
  28036. node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ||
  28037. /**
  28038. * <span
  28039. * >123<meta
  28040. * ~
  28041. * /></span>
  28042. */
  28043. node.isSelfClosing && needsToBorrowLastChildClosingTagEndMarker(node.parent) ? "" : node.isSelfClosing ? forceNotToBreakAttrContent ? " " : line$9 : forceNotToBreakAttrContent ? "" : softline$7]), node.isSelfClosing ? "" : printOpeningTagEnd(node)]);
  28044. }
  28045. function printOpeningTagStart(node, options) {
  28046. return node.prev && needsToBorrowNextOpeningTagStartMarker(node.prev) ? "" : concat$14([printOpeningTagPrefix(node, options), printOpeningTagStartMarker(node)]);
  28047. }
  28048. function printOpeningTagEnd(node) {
  28049. return node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ? "" : printOpeningTagEndMarker(node);
  28050. }
  28051. function printClosingTag(node, options) {
  28052. return concat$14([node.isSelfClosing ? "" : printClosingTagStart(node, options), printClosingTagEnd(node, options)]);
  28053. }
  28054. function printClosingTagStart(node, options) {
  28055. return node.lastChild && needsToBorrowParentClosingTagStartMarker(node.lastChild) ? "" : concat$14([printClosingTagPrefix(node, options), printClosingTagStartMarker(node, options)]);
  28056. }
  28057. function printClosingTagEnd(node, options) {
  28058. return (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? "" : concat$14([printClosingTagEndMarker(node, options), printClosingTagSuffix(node, options)]);
  28059. }
  28060. function needsToBorrowNextOpeningTagStartMarker(node) {
  28061. /**
  28062. * 123<p
  28063. * ^^
  28064. * >
  28065. */
  28066. return node.next && !isTextLikeNode(node.next) && isTextLikeNode(node) && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces;
  28067. }
  28068. function needsToBorrowParentOpeningTagEndMarker(node) {
  28069. /**
  28070. * <p
  28071. * >123
  28072. * ^
  28073. *
  28074. * <p
  28075. * ><a
  28076. * ^
  28077. */
  28078. return !node.prev && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  28079. }
  28080. function needsToBorrowPrevClosingTagEndMarker(node) {
  28081. /**
  28082. * <p></p
  28083. * >123
  28084. * ^
  28085. *
  28086. * <p></p
  28087. * ><a
  28088. * ^
  28089. */
  28090. return node.prev && !isTextLikeNode(node.prev) && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  28091. }
  28092. function needsToBorrowLastChildClosingTagEndMarker(node) {
  28093. /**
  28094. * <p
  28095. * ><a></a
  28096. * ></p
  28097. * ^
  28098. * >
  28099. */
  28100. return node.lastChild && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces && !isTextLikeNode(getLastDescendant(node.lastChild));
  28101. }
  28102. function needsToBorrowParentClosingTagStartMarker(node) {
  28103. /**
  28104. * <p>
  28105. * 123</p
  28106. * ^^^
  28107. * >
  28108. *
  28109. * 123</b
  28110. * ></a
  28111. * ^^^
  28112. * >
  28113. */
  28114. return !node.next && !node.hasTrailingSpaces && node.isTrailingSpaceSensitive && isTextLikeNode(getLastDescendant(node));
  28115. }
  28116. function printOpeningTagPrefix(node, options) {
  28117. return needsToBorrowParentOpeningTagEndMarker(node) ? printOpeningTagEndMarker(node.parent) : needsToBorrowPrevClosingTagEndMarker(node) ? printClosingTagEndMarker(node.prev, options) : "";
  28118. }
  28119. function printClosingTagPrefix(node, options) {
  28120. return needsToBorrowLastChildClosingTagEndMarker(node) ? printClosingTagEndMarker(node.lastChild, options) : "";
  28121. }
  28122. function printClosingTagSuffix(node, options) {
  28123. return needsToBorrowParentClosingTagStartMarker(node) ? printClosingTagStartMarker(node.parent, options) : needsToBorrowNextOpeningTagStartMarker(node) ? printOpeningTagStartMarker(node.next) : "";
  28124. }
  28125. function printOpeningTagStartMarker(node) {
  28126. switch (node.type) {
  28127. case "ieConditionalComment":
  28128. case "ieConditionalStartComment":
  28129. return `<!--[if ${node.condition}`;
  28130. case "ieConditionalEndComment":
  28131. return `<!--<!`;
  28132. case "interpolation":
  28133. return "{{";
  28134. case "docType":
  28135. return "<!DOCTYPE";
  28136. case "element":
  28137. if (node.condition) {
  28138. return `<!--[if ${node.condition}]><!--><${node.rawName}`;
  28139. }
  28140. // fall through
  28141. default:
  28142. return `<${node.rawName}`;
  28143. }
  28144. }
  28145. function printOpeningTagEndMarker(node) {
  28146. assert(!node.isSelfClosing);
  28147. switch (node.type) {
  28148. case "ieConditionalComment":
  28149. return "]>";
  28150. case "element":
  28151. if (node.condition) {
  28152. return `><!--<![endif]-->`;
  28153. }
  28154. // fall through
  28155. default:
  28156. return `>`;
  28157. }
  28158. }
  28159. function printClosingTagStartMarker(node, options) {
  28160. assert(!node.isSelfClosing);
  28161. if (shouldNotPrintClosingTag(node, options)) {
  28162. return "";
  28163. }
  28164. switch (node.type) {
  28165. case "ieConditionalComment":
  28166. return "<!";
  28167. case "element":
  28168. if (node.hasHtmComponentClosingTag) {
  28169. return "<//";
  28170. }
  28171. // fall through
  28172. default:
  28173. return `</${node.rawName}`;
  28174. }
  28175. }
  28176. function printClosingTagEndMarker(node, options) {
  28177. if (shouldNotPrintClosingTag(node, options)) {
  28178. return "";
  28179. }
  28180. switch (node.type) {
  28181. case "ieConditionalComment":
  28182. case "ieConditionalEndComment":
  28183. return `[endif]-->`;
  28184. case "ieConditionalStartComment":
  28185. return `]><!-->`;
  28186. case "interpolation":
  28187. return "}}";
  28188. case "element":
  28189. if (node.isSelfClosing) {
  28190. return "/>";
  28191. }
  28192. // fall through
  28193. default:
  28194. return ">";
  28195. }
  28196. }
  28197. function getTextValueParts(node) {
  28198. var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : node.value;
  28199. 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
  28200. join$10(line$9, value.split(/[\t\n\f\r ]+/)).parts;
  28201. }
  28202. function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
  28203. var isKeyMatched = function isKeyMatched(patterns) {
  28204. return new RegExp(patterns.join("|")).test(node.fullName);
  28205. };
  28206. var getValue = function getValue() {
  28207. return unescapeQuoteEntities(node.value);
  28208. };
  28209. var shouldHug = false;
  28210. var __onHtmlBindingRoot = function __onHtmlBindingRoot(root) {
  28211. 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;
  28212. if (rootNode && (rootNode.type === "ObjectExpression" || rootNode.type === "ArrayExpression")) {
  28213. shouldHug = true;
  28214. }
  28215. };
  28216. var printHug = function printHug(doc$$2) {
  28217. return group$14(doc$$2);
  28218. };
  28219. var printExpand = function printExpand(doc$$2) {
  28220. return group$14(concat$14([indent$9(concat$14([softline$7, doc$$2])), softline$7]));
  28221. };
  28222. var printMaybeHug = function printMaybeHug(doc$$2) {
  28223. return shouldHug ? printHug(doc$$2) : printExpand(doc$$2);
  28224. };
  28225. var textToDoc = function textToDoc(code, opts) {
  28226. return originalTextToDoc(code, Object.assign({
  28227. __onHtmlBindingRoot
  28228. }, opts));
  28229. };
  28230. if (node.fullName === "srcset" && (node.parent.fullName === "img" || node.parent.fullName === "source")) {
  28231. return printExpand(printImgSrcset(getValue()));
  28232. }
  28233. if (options.parser === "vue") {
  28234. if (node.fullName === "v-for") {
  28235. return printVueFor(getValue(), textToDoc);
  28236. }
  28237. if (node.fullName === "slot-scope") {
  28238. return printVueSlotScope(getValue(), textToDoc);
  28239. }
  28240. /**
  28241. * @click="jsStatement"
  28242. * @click="jsExpression"
  28243. * v-on:click="jsStatement"
  28244. * v-on:click="jsExpression"
  28245. */
  28246. var vueEventBindingPatterns = ["^@", "^v-on:"];
  28247. /**
  28248. * :class="vueExpression"
  28249. * v-bind:id="vueExpression"
  28250. */
  28251. var vueExpressionBindingPatterns = ["^:", "^v-bind:"];
  28252. /**
  28253. * v-if="jsExpression"
  28254. */
  28255. var jsExpressionBindingPatterns = ["^v-"];
  28256. if (isKeyMatched(vueEventBindingPatterns)) {
  28257. var value = getValue();
  28258. return printMaybeHug(isVueEventBindingExpression$2(value) ? textToDoc(value, {
  28259. parser: "__js_expression"
  28260. }) : stripTrailingHardline$2(textToDoc(value, {
  28261. parser: "__vue_event_binding"
  28262. })));
  28263. }
  28264. if (isKeyMatched(vueExpressionBindingPatterns)) {
  28265. return printMaybeHug(textToDoc(getValue(), {
  28266. parser: "__vue_expression"
  28267. }));
  28268. }
  28269. if (isKeyMatched(jsExpressionBindingPatterns)) {
  28270. return printMaybeHug(textToDoc(getValue(), {
  28271. parser: "__js_expression"
  28272. }));
  28273. }
  28274. }
  28275. if (options.parser === "angular") {
  28276. var ngTextToDoc = function ngTextToDoc(code, opts) {
  28277. return (// angular does not allow trailing comma
  28278. textToDoc(code, Object.assign({
  28279. trailingComma: "none"
  28280. }, opts))
  28281. );
  28282. };
  28283. /**
  28284. * *directive="angularDirective"
  28285. */
  28286. var ngDirectiveBindingPatterns = ["^\\*"];
  28287. /**
  28288. * (click)="angularStatement"
  28289. * on-click="angularStatement"
  28290. */
  28291. var ngStatementBindingPatterns = ["^\\(.+\\)$", "^on-"];
  28292. /**
  28293. * [target]="angularExpression"
  28294. * bind-target="angularExpression"
  28295. * [(target)]="angularExpression"
  28296. * bindon-target="angularExpression"
  28297. */
  28298. var ngExpressionBindingPatterns = ["^\\[.+\\]$", "^bind(on)?-"];
  28299. if (isKeyMatched(ngStatementBindingPatterns)) {
  28300. return printMaybeHug(ngTextToDoc(getValue(), {
  28301. parser: "__ng_action"
  28302. }));
  28303. }
  28304. if (isKeyMatched(ngExpressionBindingPatterns)) {
  28305. return printMaybeHug(ngTextToDoc(getValue(), {
  28306. parser: "__ng_binding"
  28307. }));
  28308. }
  28309. if (isKeyMatched(ngDirectiveBindingPatterns)) {
  28310. return printMaybeHug(ngTextToDoc(getValue(), {
  28311. parser: "__ng_directive"
  28312. }));
  28313. }
  28314. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  28315. var _value2 = getValue();
  28316. if (interpolationRegex.test(_value2)) {
  28317. var parts = [];
  28318. _value2.split(interpolationRegex).forEach(function (part, index) {
  28319. if (index % 2 === 0) {
  28320. parts.push(concat$14(replaceEndOfLineWith$2(part, literalline$6)));
  28321. } else {
  28322. try {
  28323. parts.push(group$14(concat$14(["{{", indent$9(concat$14([line$9, ngTextToDoc(part, {
  28324. parser: "__ng_interpolation",
  28325. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  28326. })])), line$9, "}}"])));
  28327. } catch (e) {
  28328. parts.push("{{", concat$14(replaceEndOfLineWith$2(part, literalline$6)), "}}");
  28329. }
  28330. }
  28331. });
  28332. return group$14(concat$14(parts));
  28333. }
  28334. }
  28335. return null;
  28336. }
  28337. var printerHtml = {
  28338. preprocess: preprocess_1$4,
  28339. print: genericPrint$5,
  28340. insertPragma: insertPragma$6,
  28341. massageAstNode: clean$8,
  28342. embed: embed$6
  28343. };
  28344. var CATEGORY_HTML = "HTML"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  28345. var options$15 = {
  28346. htmlWhitespaceSensitivity: {
  28347. since: "1.15.0",
  28348. category: CATEGORY_HTML,
  28349. type: "choice",
  28350. default: "css",
  28351. description: "How to handle whitespaces in HTML.",
  28352. choices: [{
  28353. value: "css",
  28354. description: "Respect the default value of CSS display property."
  28355. }, {
  28356. value: "strict",
  28357. description: "Whitespaces are considered sensitive."
  28358. }, {
  28359. value: "ignore",
  28360. description: "Whitespaces are considered insensitive."
  28361. }]
  28362. }
  28363. };
  28364. var name$14 = "HTML";
  28365. var type$13 = "markup";
  28366. var tmScope$13 = "text.html.basic";
  28367. var aceMode$13 = "html";
  28368. var codemirrorMode$10 = "htmlmixed";
  28369. var codemirrorMimeType$10 = "text/html";
  28370. var color$3 = "#e34c26";
  28371. var aliases$5 = ["xhtml"];
  28372. var extensions$13 = [".html", ".htm", ".html.hl", ".inc", ".st", ".xht", ".xhtml"];
  28373. var languageId$13 = 146;
  28374. var html$1 = {
  28375. name: name$14,
  28376. type: type$13,
  28377. tmScope: tmScope$13,
  28378. aceMode: aceMode$13,
  28379. codemirrorMode: codemirrorMode$10,
  28380. codemirrorMimeType: codemirrorMimeType$10,
  28381. color: color$3,
  28382. aliases: aliases$5,
  28383. extensions: extensions$13,
  28384. languageId: languageId$13
  28385. };
  28386. var html$2 = Object.freeze({
  28387. name: name$14,
  28388. type: type$13,
  28389. tmScope: tmScope$13,
  28390. aceMode: aceMode$13,
  28391. codemirrorMode: codemirrorMode$10,
  28392. codemirrorMimeType: codemirrorMimeType$10,
  28393. color: color$3,
  28394. aliases: aliases$5,
  28395. extensions: extensions$13,
  28396. languageId: languageId$13,
  28397. default: html$1
  28398. });
  28399. var name$15 = "Vue";
  28400. var type$14 = "markup";
  28401. var color$4 = "#2c3e50";
  28402. var extensions$14 = [".vue"];
  28403. var tmScope$14 = "text.html.vue";
  28404. var aceMode$14 = "html";
  28405. var languageId$14 = 391;
  28406. var vue = {
  28407. name: name$15,
  28408. type: type$14,
  28409. color: color$4,
  28410. extensions: extensions$14,
  28411. tmScope: tmScope$14,
  28412. aceMode: aceMode$14,
  28413. languageId: languageId$14
  28414. };
  28415. var vue$1 = Object.freeze({
  28416. name: name$15,
  28417. type: type$14,
  28418. color: color$4,
  28419. extensions: extensions$14,
  28420. tmScope: tmScope$14,
  28421. aceMode: aceMode$14,
  28422. languageId: languageId$14,
  28423. default: vue
  28424. });
  28425. var require$$0$31 = ( html$2 && html$1 ) || html$2;
  28426. var require$$1$10 = ( vue$1 && vue ) || vue$1;
  28427. var languages$5 = [createLanguage(require$$0$31, {
  28428. override: {
  28429. name: "Angular",
  28430. since: "1.15.0",
  28431. parsers: ["angular"],
  28432. vscodeLanguageIds: ["html"],
  28433. extensions: [".component.html"],
  28434. filenames: []
  28435. }
  28436. }), createLanguage(require$$0$31, {
  28437. override: {
  28438. since: "1.15.0",
  28439. parsers: ["html"],
  28440. vscodeLanguageIds: ["html"]
  28441. },
  28442. extend: {
  28443. extensions: [".mjml" // MJML is considered XML in Linguist but it should be formatted as HTML
  28444. ]
  28445. }
  28446. }), createLanguage(require$$1$10, {
  28447. override: {
  28448. since: "1.10.0",
  28449. parsers: ["vue"],
  28450. vscodeLanguageIds: ["vue"]
  28451. }
  28452. })];
  28453. var printers$5 = {
  28454. html: printerHtml
  28455. };
  28456. var languageHtml = {
  28457. languages: languages$5,
  28458. printers: printers$5,
  28459. options: options$15
  28460. };
  28461. function isPragma$1(text) {
  28462. return /^\s*@(prettier|format)\s*$/.test(text);
  28463. }
  28464. function hasPragma$4(text) {
  28465. return /^\s*#[^\n\S]*@(prettier|format)\s*?(\n|$)/.test(text);
  28466. }
  28467. function insertPragma$9(text) {
  28468. return `# @format\n\n${text}`;
  28469. }
  28470. var pragma$11 = {
  28471. isPragma: isPragma$1,
  28472. hasPragma: hasPragma$4,
  28473. insertPragma: insertPragma$9
  28474. };
  28475. var getLast$7 = util$1.getLast;
  28476. function getAncestorCount$1(path$$1, filter) {
  28477. var counter = 0;
  28478. var pathStackLength = path$$1.stack.length - 1;
  28479. for (var i = 0; i < pathStackLength; i++) {
  28480. var value = path$$1.stack[i];
  28481. if (isNode$2(value) && filter(value)) {
  28482. counter++;
  28483. }
  28484. }
  28485. return counter;
  28486. }
  28487. /**
  28488. * @param {any} value
  28489. * @param {string[]=} types
  28490. */
  28491. function isNode$2(value, types) {
  28492. return value && typeof value.type === "string" && (!types || types.indexOf(value.type) !== -1);
  28493. }
  28494. function mapNode$1(node, callback, parent) {
  28495. return callback("children" in node ? Object.assign({}, node, {
  28496. children: node.children.map(function (childNode) {
  28497. return mapNode$1(childNode, callback, node);
  28498. })
  28499. }) : node, parent);
  28500. }
  28501. function defineShortcut$1(x, key, getter) {
  28502. Object.defineProperty(x, key, {
  28503. get: getter,
  28504. enumerable: false
  28505. });
  28506. }
  28507. function isNextLineEmpty$6(node, text) {
  28508. var newlineCount = 0;
  28509. var textLength = text.length;
  28510. for (var i = node.position.end.offset - 1; i < textLength; i++) {
  28511. var char = text[i];
  28512. if (char === "\n") {
  28513. newlineCount++;
  28514. }
  28515. if (newlineCount === 1 && /\S/.test(char)) {
  28516. return false;
  28517. }
  28518. if (newlineCount === 2) {
  28519. return true;
  28520. }
  28521. }
  28522. return false;
  28523. }
  28524. function isLastDescendantNode$1(path$$1) {
  28525. var node = path$$1.getValue();
  28526. switch (node.type) {
  28527. case "tag":
  28528. case "anchor":
  28529. case "comment":
  28530. return false;
  28531. }
  28532. var pathStackLength = path$$1.stack.length;
  28533. for (var i = 1; i < pathStackLength; i++) {
  28534. var item = path$$1.stack[i];
  28535. var parentItem = path$$1.stack[i - 1];
  28536. if (Array.isArray(parentItem) && typeof item === "number" && item !== parentItem.length - 1) {
  28537. return false;
  28538. }
  28539. }
  28540. return true;
  28541. }
  28542. function getLastDescendantNode$2(node) {
  28543. return "children" in node && node.children.length !== 0 ? getLastDescendantNode$2(getLast$7(node.children)) : node;
  28544. }
  28545. function isPrettierIgnore$2(comment) {
  28546. return comment.value.trim() === "prettier-ignore";
  28547. }
  28548. function hasPrettierIgnore$5(path$$1) {
  28549. var node = path$$1.getValue();
  28550. if (node.type === "documentBody") {
  28551. var document = path$$1.getParentNode();
  28552. return hasEndComments$1(document.head) && isPrettierIgnore$2(getLast$7(document.head.endComments));
  28553. }
  28554. return hasLeadingComments$1(node) && isPrettierIgnore$2(getLast$7(node.leadingComments));
  28555. }
  28556. function isEmptyNode$1(node) {
  28557. return (!node.children || node.children.length === 0) && !hasComments(node);
  28558. }
  28559. function hasComments(node) {
  28560. return hasLeadingComments$1(node) || hasMiddleComments$1(node) || hasIndicatorComment$1(node) || hasTrailingComment$2(node) || hasEndComments$1(node);
  28561. }
  28562. function hasLeadingComments$1(node) {
  28563. return node && node.leadingComments && node.leadingComments.length !== 0;
  28564. }
  28565. function hasMiddleComments$1(node) {
  28566. return node && node.middleComments && node.middleComments.length !== 0;
  28567. }
  28568. function hasIndicatorComment$1(node) {
  28569. return node && node.indicatorComment;
  28570. }
  28571. function hasTrailingComment$2(node) {
  28572. return node && node.trailingComment;
  28573. }
  28574. function hasEndComments$1(node) {
  28575. return node && node.endComments && node.endComments.length !== 0;
  28576. }
  28577. /**
  28578. * " a b c d e f " -> [" a b", "c d", "e f "]
  28579. */
  28580. function splitWithSingleSpace(text) {
  28581. var parts = [];
  28582. var lastPart = undefined;
  28583. var _iteratorNormalCompletion = true;
  28584. var _didIteratorError = false;
  28585. var _iteratorError = undefined;
  28586. try {
  28587. for (var _iterator = text.split(/( +)/g)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  28588. var part = _step.value;
  28589. if (part !== " ") {
  28590. if (lastPart === " ") {
  28591. parts.push(part);
  28592. } else {
  28593. parts.push((parts.pop() || "") + part);
  28594. }
  28595. } else if (lastPart === undefined) {
  28596. parts.unshift("");
  28597. }
  28598. lastPart = part;
  28599. }
  28600. } catch (err) {
  28601. _didIteratorError = true;
  28602. _iteratorError = err;
  28603. } finally {
  28604. try {
  28605. if (!_iteratorNormalCompletion && _iterator.return != null) {
  28606. _iterator.return();
  28607. }
  28608. } finally {
  28609. if (_didIteratorError) {
  28610. throw _iteratorError;
  28611. }
  28612. }
  28613. }
  28614. if (lastPart === " ") {
  28615. parts.push((parts.pop() || "") + " ");
  28616. }
  28617. if (parts[0] === "") {
  28618. parts.shift();
  28619. parts.unshift(" " + (parts.shift() || ""));
  28620. }
  28621. return parts;
  28622. }
  28623. function getFlowScalarLineContents$1(nodeType, content, options) {
  28624. var rawLineContents = content.split("\n").map(function (lineContent, index, lineContents) {
  28625. return index === 0 && index === lineContents.length - 1 ? lineContent : index !== 0 && index !== lineContents.length - 1 ? lineContent.trim() : index === 0 ? lineContent.trimRight() : lineContent.trimLeft();
  28626. });
  28627. if (options.proseWrap === "preserve") {
  28628. return rawLineContents.map(function (lineContent) {
  28629. return lineContent.length === 0 ? [] : [lineContent];
  28630. });
  28631. }
  28632. return rawLineContents.map(function (lineContent) {
  28633. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  28634. }).reduce(function (reduced, lineContentWords, index) {
  28635. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !( // trailing backslash in quoteDouble should be preserved
  28636. nodeType === "quoteDouble" && getLast$7(getLast$7(reduced)).endsWith("\\")) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  28637. }, []).map(function (lineContentWords) {
  28638. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  28639. });
  28640. }
  28641. function getBlockValueLineContents$1(node, _ref) {
  28642. var parentIndent = _ref.parentIndent,
  28643. isLastDescendant = _ref.isLastDescendant,
  28644. options = _ref.options;
  28645. 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 `|`
  28646. .match(/^[^\n]*?\n([\s\S]*)$/)[1];
  28647. var leadingSpaceCount = node.indent === null ? function (match) {
  28648. return match ? match[1].length : Infinity;
  28649. }(content.match(/^( *)\S/m)) : node.indent - 1 + parentIndent;
  28650. var rawLineContents = content.split("\n").map(function (lineContent) {
  28651. return lineContent.slice(leadingSpaceCount);
  28652. });
  28653. if (options.proseWrap === "preserve" || node.type === "blockLiteral") {
  28654. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  28655. return lineContent.length === 0 ? [] : [lineContent];
  28656. }));
  28657. }
  28658. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  28659. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  28660. }).reduce(function (reduced, lineContentWords, index) {
  28661. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !/^\s/.test(lineContentWords[0]) && !/^\s|\s$/.test(getLast$7(reduced)) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  28662. }, []).map(function (lineContentWords) {
  28663. return lineContentWords.reduce(function (reduced, word) {
  28664. return (// disallow trailing spaces
  28665. reduced.length !== 0 && /\s$/.test(getLast$7(reduced)) ? reduced.concat(reduced.pop() + " " + word) : reduced.concat(word)
  28666. );
  28667. }, []);
  28668. }).map(function (lineContentWords) {
  28669. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  28670. }));
  28671. function removeUnnecessaryTrailingNewlines(lineContents) {
  28672. if (node.chomping === "keep") {
  28673. return getLast$7(lineContents).length === 0 ? lineContents.slice(0, -1) : lineContents;
  28674. }
  28675. var trailingNewlineCount = 0;
  28676. for (var i = lineContents.length - 1; i >= 0; i--) {
  28677. if (lineContents[i].length === 0) {
  28678. trailingNewlineCount++;
  28679. } else {
  28680. break;
  28681. }
  28682. }
  28683. return trailingNewlineCount === 0 ? lineContents : trailingNewlineCount >= 2 && !isLastDescendant ? // next empty line
  28684. lineContents.slice(0, -(trailingNewlineCount - 1)) : lineContents.slice(0, -trailingNewlineCount);
  28685. }
  28686. }
  28687. var utils$12 = {
  28688. getLast: getLast$7,
  28689. getAncestorCount: getAncestorCount$1,
  28690. isNode: isNode$2,
  28691. isEmptyNode: isEmptyNode$1,
  28692. mapNode: mapNode$1,
  28693. defineShortcut: defineShortcut$1,
  28694. isNextLineEmpty: isNextLineEmpty$6,
  28695. isLastDescendantNode: isLastDescendantNode$1,
  28696. getBlockValueLineContents: getBlockValueLineContents$1,
  28697. getFlowScalarLineContents: getFlowScalarLineContents$1,
  28698. getLastDescendantNode: getLastDescendantNode$2,
  28699. hasPrettierIgnore: hasPrettierIgnore$5,
  28700. hasLeadingComments: hasLeadingComments$1,
  28701. hasMiddleComments: hasMiddleComments$1,
  28702. hasIndicatorComment: hasIndicatorComment$1,
  28703. hasTrailingComment: hasTrailingComment$2,
  28704. hasEndComments: hasEndComments$1
  28705. };
  28706. var insertPragma$8 = pragma$11.insertPragma;
  28707. var isPragma = pragma$11.isPragma;
  28708. var getAncestorCount = utils$12.getAncestorCount;
  28709. var getBlockValueLineContents = utils$12.getBlockValueLineContents;
  28710. var getFlowScalarLineContents = utils$12.getFlowScalarLineContents;
  28711. var getLast$6 = utils$12.getLast;
  28712. var getLastDescendantNode$1 = utils$12.getLastDescendantNode;
  28713. var hasLeadingComments = utils$12.hasLeadingComments;
  28714. var hasMiddleComments = utils$12.hasMiddleComments;
  28715. var hasIndicatorComment = utils$12.hasIndicatorComment;
  28716. var hasTrailingComment$1 = utils$12.hasTrailingComment;
  28717. var hasEndComments = utils$12.hasEndComments;
  28718. var hasPrettierIgnore$4 = utils$12.hasPrettierIgnore;
  28719. var isLastDescendantNode = utils$12.isLastDescendantNode;
  28720. var isNextLineEmpty$5 = utils$12.isNextLineEmpty;
  28721. var isNode$1 = utils$12.isNode;
  28722. var isEmptyNode = utils$12.isEmptyNode;
  28723. var defineShortcut = utils$12.defineShortcut;
  28724. var mapNode = utils$12.mapNode;
  28725. var docBuilders$3 = doc.builders;
  28726. var conditionalGroup$2 = docBuilders$3.conditionalGroup;
  28727. var breakParent$4 = docBuilders$3.breakParent;
  28728. var concat$17 = docBuilders$3.concat;
  28729. var dedent$4 = docBuilders$3.dedent;
  28730. var dedentToRoot$3 = docBuilders$3.dedentToRoot;
  28731. var fill$6 = docBuilders$3.fill;
  28732. var group$16 = docBuilders$3.group;
  28733. var hardline$13 = docBuilders$3.hardline;
  28734. var ifBreak$7 = docBuilders$3.ifBreak;
  28735. var join$12 = docBuilders$3.join;
  28736. var line$11 = docBuilders$3.line;
  28737. var lineSuffix$2 = docBuilders$3.lineSuffix;
  28738. var literalline$7 = docBuilders$3.literalline;
  28739. var markAsRoot$5 = docBuilders$3.markAsRoot;
  28740. var softline$8 = docBuilders$3.softline;
  28741. var replaceEndOfLineWith$3 = util$1.replaceEndOfLineWith;
  28742. function preprocess$6(ast) {
  28743. return mapNode(ast, defineShortcuts);
  28744. }
  28745. function defineShortcuts(node) {
  28746. switch (node.type) {
  28747. case "document":
  28748. defineShortcut(node, "head", function () {
  28749. return node.children[0];
  28750. });
  28751. defineShortcut(node, "body", function () {
  28752. return node.children[1];
  28753. });
  28754. break;
  28755. case "documentBody":
  28756. case "sequenceItem":
  28757. case "flowSequenceItem":
  28758. case "mappingKey":
  28759. case "mappingValue":
  28760. defineShortcut(node, "content", function () {
  28761. return node.children[0];
  28762. });
  28763. break;
  28764. case "mappingItem":
  28765. case "flowMappingItem":
  28766. defineShortcut(node, "key", function () {
  28767. return node.children[0];
  28768. });
  28769. defineShortcut(node, "value", function () {
  28770. return node.children[1];
  28771. });
  28772. break;
  28773. }
  28774. return node;
  28775. }
  28776. function genericPrint$6(path$$1, options, print) {
  28777. var node = path$$1.getValue();
  28778. var parentNode = path$$1.getParentNode();
  28779. var tag = !node.tag ? "" : path$$1.call(print, "tag");
  28780. var anchor = !node.anchor ? "" : path$$1.call(print, "anchor");
  28781. var nextEmptyLine = isNode$1(node, ["mapping", "sequence", "comment", "directive", "mappingItem", "sequenceItem"]) && !isLastDescendantNode(path$$1) ? printNextEmptyLine(path$$1, options.originalText) : "";
  28782. 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$4, 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"))])) : ""]);
  28783. }
  28784. function _print(node, parentNode, path$$1, options, print) {
  28785. switch (node.type) {
  28786. case "root":
  28787. return concat$17([join$12(hardline$13, path$$1.map(function (childPath, index) {
  28788. var document = node.children[index];
  28789. var nextDocument = node.children[index + 1];
  28790. 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, "---"])]);
  28791. }, "children")), node.children.length === 0 || function (lastDescendantNode) {
  28792. return isNode$1(lastDescendantNode, ["blockLiteral", "blockFolded"]) && lastDescendantNode.chomping === "keep";
  28793. }(getLastDescendantNode$1(node)) ? "" : hardline$13]);
  28794. case "document":
  28795. {
  28796. var nextDocument = parentNode.children[path$$1.getName() + 1];
  28797. 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));
  28798. }
  28799. case "documentHead":
  28800. return join$12(hardline$13, [].concat(path$$1.map(print, "children"), path$$1.map(print, "endComments")));
  28801. case "documentBody":
  28802. {
  28803. var children = join$12(hardline$13, path$$1.map(print, "children")).parts;
  28804. var endComments = join$12(hardline$13, path$$1.map(print, "endComments")).parts;
  28805. var separator = children.length === 0 || endComments.length === 0 ? "" : function (lastDescendantNode) {
  28806. return isNode$1(lastDescendantNode, ["blockFolded", "blockLiteral"]) ? lastDescendantNode.chomping === "keep" ? // there's already a newline printed at the end of blockValue (chomping=keep, lastDescendant=true)
  28807. "" : // an extra newline for better readability
  28808. concat$17([hardline$13, hardline$13]) : hardline$13;
  28809. }(getLastDescendantNode$1(node));
  28810. return concat$17([].concat(children, separator, endComments));
  28811. }
  28812. case "directive":
  28813. return concat$17(["%", join$12(" ", [node.name].concat(node.parameters))]);
  28814. case "comment":
  28815. return concat$17(["#", node.value]);
  28816. case "alias":
  28817. return concat$17(["*", node.value]);
  28818. case "tag":
  28819. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  28820. case "anchor":
  28821. return concat$17(["&", node.value]);
  28822. case "plain":
  28823. return printFlowScalarContent(node.type, options.originalText.slice(node.position.start.offset, node.position.end.offset), options);
  28824. case "quoteDouble":
  28825. case "quoteSingle":
  28826. {
  28827. var singleQuote = "'";
  28828. var doubleQuote = '"';
  28829. var raw = options.originalText.slice(node.position.start.offset + 1, node.position.end.offset - 1);
  28830. if (node.type === "quoteSingle" && raw.includes("\\") || node.type === "quoteDouble" && /\\[^"]/.test(raw)) {
  28831. // only quoteDouble can use escape chars
  28832. // and quoteSingle do not need to escape backslashes
  28833. var originalQuote = node.type === "quoteDouble" ? doubleQuote : singleQuote;
  28834. return concat$17([originalQuote, printFlowScalarContent(node.type, raw, options), originalQuote]);
  28835. } else if (raw.includes(doubleQuote)) {
  28836. return concat$17([singleQuote, printFlowScalarContent(node.type, node.type === "quoteDouble" ? raw // double quote needs to be escaped by backslash in quoteDouble
  28837. .replace(/\\"/g, doubleQuote).replace(/'/g, singleQuote.repeat(2)) : raw, options), singleQuote]);
  28838. }
  28839. if (raw.includes(singleQuote)) {
  28840. return concat$17([doubleQuote, printFlowScalarContent(node.type, node.type === "quoteSingle" ? // single quote needs to be escaped by 2 single quotes in quoteSingle
  28841. raw.replace(/''/g, singleQuote) : raw, options), doubleQuote]);
  28842. }
  28843. var quote = options.singleQuote ? singleQuote : doubleQuote;
  28844. return concat$17([quote, printFlowScalarContent(node.type, raw, options), quote]);
  28845. }
  28846. case "blockFolded":
  28847. case "blockLiteral":
  28848. {
  28849. var parentIndent = getAncestorCount(path$$1, function (ancestorNode) {
  28850. return isNode$1(ancestorNode, ["sequence", "mapping"]);
  28851. });
  28852. var isLastDescendant = isLastDescendantNode(path$$1);
  28853. 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, {
  28854. parentIndent,
  28855. isLastDescendant,
  28856. options
  28857. }).reduce(function (reduced, lineWords, index, lineContents) {
  28858. 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) : "");
  28859. }, []))))]);
  28860. }
  28861. case "sequence":
  28862. return join$12(hardline$13, path$$1.map(print, "children"));
  28863. case "sequenceItem":
  28864. return concat$17(["- ", align$3(2, !node.content ? "" : path$$1.call(print, "content"))]);
  28865. case "mappingKey":
  28866. return !node.content ? "" : path$$1.call(print, "content");
  28867. case "mappingValue":
  28868. return !node.content ? "" : path$$1.call(print, "content");
  28869. case "mapping":
  28870. return join$12(hardline$13, path$$1.map(print, "children"));
  28871. case "mappingItem":
  28872. case "flowMappingItem":
  28873. {
  28874. var isEmptyMappingKey = isEmptyNode(node.key);
  28875. var isEmptyMappingValue = isEmptyNode(node.value);
  28876. if (isEmptyMappingKey && isEmptyMappingValue) {
  28877. return concat$17([": "]);
  28878. }
  28879. var key = path$$1.call(print, "key");
  28880. var value = path$$1.call(print, "value");
  28881. if (isEmptyMappingValue) {
  28882. 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)]);
  28883. }
  28884. if (isEmptyMappingKey) {
  28885. return concat$17([": ", align$3(2, value)]);
  28886. }
  28887. var groupId = Symbol("mappingKey");
  28888. var forceExplicitKey = hasLeadingComments(node.value) || !isInlineNode(node.key.content);
  28889. return forceExplicitKey ? concat$17(["? ", align$3(2, key), hardline$13, join$12("", path$$1.map(print, "value", "leadingComments").map(function (comment) {
  28890. return concat$17([comment, hardline$13]);
  28891. })), ": ", align$3(2, value)]) : // force singleline
  28892. 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$7("? "), group$16(align$3(2, key), {
  28893. id: groupId
  28894. })])), ifBreak$7(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])), {
  28895. groupId
  28896. })])]);
  28897. }
  28898. case "flowMapping":
  28899. case "flowSequence":
  28900. {
  28901. var openMarker = node.type === "flowMapping" ? "{" : "[";
  28902. var closeMarker = node.type === "flowMapping" ? "}" : "]";
  28903. var bracketSpacing = node.type === "flowMapping" && node.children.length !== 0 && options.bracketSpacing ? line$11 : softline$8;
  28904. var isLastItemEmptyMappingItem = node.children.length !== 0 && function (lastItem) {
  28905. return lastItem.type === "flowMappingItem" && isEmptyNode(lastItem.key) && isEmptyNode(lastItem.value);
  28906. }(getLast$6(node.children));
  28907. return concat$17([openMarker, indent(concat$17([bracketSpacing, concat$17(path$$1.map(function (childPath, index) {
  28908. 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) : ""])]);
  28909. }, "children")), ifBreak$7(",", "")])), isLastItemEmptyMappingItem ? "" : bracketSpacing, closeMarker]);
  28910. }
  28911. case "flowSequenceItem":
  28912. return path$$1.call(print, "content");
  28913. // istanbul ignore next
  28914. default:
  28915. throw new Error(`Unexpected node type ${node.type}`);
  28916. }
  28917. function indent(doc$$2) {
  28918. return docBuilders$3.align(" ".repeat(options.tabWidth), doc$$2);
  28919. }
  28920. }
  28921. function align$3(n, doc$$2) {
  28922. return typeof n === "number" && n > 0 ? docBuilders$3.align(" ".repeat(n), doc$$2) : docBuilders$3.align(n, doc$$2);
  28923. }
  28924. function isInlineNode(node) {
  28925. if (!node) {
  28926. return true;
  28927. }
  28928. switch (node.type) {
  28929. case "plain":
  28930. case "quoteDouble":
  28931. case "quoteSingle":
  28932. case "alias":
  28933. case "flowMapping":
  28934. case "flowSequence":
  28935. return true;
  28936. default:
  28937. return false;
  28938. }
  28939. }
  28940. function isSingleLineNode(node) {
  28941. if (!node) {
  28942. return true;
  28943. }
  28944. switch (node.type) {
  28945. case "plain":
  28946. case "quoteDouble":
  28947. case "quoteSingle":
  28948. return node.position.start.line === node.position.end.line;
  28949. case "alias":
  28950. return true;
  28951. default:
  28952. return false;
  28953. }
  28954. }
  28955. function shouldPrintDocumentBody(document) {
  28956. return document.body.children.length !== 0 || hasEndComments(document.body);
  28957. }
  28958. function shouldPrintDocumentEndMarker(document, nextDocument) {
  28959. return (
  28960. /**
  28961. *... # trailingComment
  28962. */
  28963. hasTrailingComment$1(document) || nextDocument && (
  28964. /**
  28965. * ...
  28966. * %DIRECTIVE
  28967. * ---
  28968. */
  28969. nextDocument.head.children.length !== 0 ||
  28970. /**
  28971. * ...
  28972. * # endComment
  28973. * ---
  28974. */
  28975. hasEndComments(nextDocument.head))
  28976. );
  28977. }
  28978. function shouldPrintDocumentHeadEndMarker(document, nextDocument, root, options) {
  28979. if (
  28980. /**
  28981. * ---
  28982. * preserve the first document head end marker
  28983. */
  28984. root.children[0] === document && /---(\s|$)/.test(options.originalText.slice(options.locStart(document), options.locStart(document) + 4)) ||
  28985. /**
  28986. * %DIRECTIVE
  28987. * ---
  28988. */
  28989. document.head.children.length !== 0 ||
  28990. /**
  28991. * # end comment
  28992. * ---
  28993. */
  28994. hasEndComments(document.head) ||
  28995. /**
  28996. * --- # trailing comment
  28997. */
  28998. hasTrailingComment$1(document.head)) {
  28999. return "head";
  29000. }
  29001. if (shouldPrintDocumentEndMarker(document, nextDocument)) {
  29002. return false;
  29003. }
  29004. return nextDocument ? "root" : false;
  29005. }
  29006. function isAbsolutelyPrintedAsSingleLineNode(node, options) {
  29007. if (!node) {
  29008. return true;
  29009. }
  29010. switch (node.type) {
  29011. case "plain":
  29012. case "quoteSingle":
  29013. case "quoteDouble":
  29014. break;
  29015. case "alias":
  29016. return true;
  29017. default:
  29018. return false;
  29019. }
  29020. if (options.proseWrap === "preserve") {
  29021. return node.position.start.line === node.position.end.line;
  29022. }
  29023. if ( // backslash-newline
  29024. /\\$/m.test(options.originalText.slice(node.position.start.offset, node.position.end.offset))) {
  29025. return false;
  29026. }
  29027. switch (options.proseWrap) {
  29028. case "never":
  29029. return node.value.indexOf("\n") === -1;
  29030. case "always":
  29031. return !/[\n ]/.test(node.value);
  29032. // istanbul ignore next
  29033. default:
  29034. return false;
  29035. }
  29036. }
  29037. function needsSpaceInFrontOfMappingValue(node) {
  29038. return node.key.content && node.key.content.type === "alias";
  29039. }
  29040. function printNextEmptyLine(path$$1, originalText) {
  29041. var node = path$$1.getValue();
  29042. var root = path$$1.stack[0];
  29043. root.isNextEmptyLinePrintedChecklist = root.isNextEmptyLinePrintedChecklist || [];
  29044. if (!root.isNextEmptyLinePrintedChecklist[node.position.end.line]) {
  29045. if (isNextLineEmpty$5(node, originalText)) {
  29046. root.isNextEmptyLinePrintedChecklist[node.position.end.line] = true;
  29047. return softline$8;
  29048. }
  29049. }
  29050. return "";
  29051. }
  29052. function printFlowScalarContent(nodeType, content, options) {
  29053. var lineContents = getFlowScalarLineContents(nodeType, content, options);
  29054. return join$12(hardline$13, lineContents.map(function (lineContentWords) {
  29055. return fill$6(join$12(line$11, lineContentWords).parts);
  29056. }));
  29057. }
  29058. function clean$11(node, newNode
  29059. /*, parent */
  29060. ) {
  29061. if (isNode$1(newNode)) {
  29062. delete newNode.position;
  29063. switch (newNode.type) {
  29064. case "comment":
  29065. // insert pragma
  29066. if (isPragma(newNode.value)) {
  29067. return null;
  29068. }
  29069. break;
  29070. case "quoteDouble":
  29071. case "quoteSingle":
  29072. newNode.type = "quote";
  29073. break;
  29074. }
  29075. }
  29076. }
  29077. var printerYaml = {
  29078. preprocess: preprocess$6,
  29079. print: genericPrint$6,
  29080. massageAstNode: clean$11,
  29081. insertPragma: insertPragma$8
  29082. };
  29083. var options$18 = {
  29084. bracketSpacing: commonOptions.bracketSpacing,
  29085. singleQuote: commonOptions.singleQuote,
  29086. proseWrap: commonOptions.proseWrap
  29087. };
  29088. var name$16 = "YAML";
  29089. var type$15 = "data";
  29090. var tmScope$15 = "source.yaml";
  29091. var aliases$6 = ["yml"];
  29092. var extensions$15 = [".yml", ".mir", ".reek", ".rviz", ".sublime-syntax", ".syntax", ".yaml", ".yaml-tmlanguage", ".yml.mysql"];
  29093. var filenames$3 = [".clang-format", ".clang-tidy", ".gemrc", "glide.lock"];
  29094. var aceMode$15 = "yaml";
  29095. var codemirrorMode$11 = "yaml";
  29096. var codemirrorMimeType$11 = "text/x-yaml";
  29097. var languageId$15 = 407;
  29098. var yaml = {
  29099. name: name$16,
  29100. type: type$15,
  29101. tmScope: tmScope$15,
  29102. aliases: aliases$6,
  29103. extensions: extensions$15,
  29104. filenames: filenames$3,
  29105. aceMode: aceMode$15,
  29106. codemirrorMode: codemirrorMode$11,
  29107. codemirrorMimeType: codemirrorMimeType$11,
  29108. languageId: languageId$15
  29109. };
  29110. var yaml$1 = Object.freeze({
  29111. name: name$16,
  29112. type: type$15,
  29113. tmScope: tmScope$15,
  29114. aliases: aliases$6,
  29115. extensions: extensions$15,
  29116. filenames: filenames$3,
  29117. aceMode: aceMode$15,
  29118. codemirrorMode: codemirrorMode$11,
  29119. codemirrorMimeType: codemirrorMimeType$11,
  29120. languageId: languageId$15,
  29121. default: yaml
  29122. });
  29123. var require$$0$33 = ( yaml$1 && yaml ) || yaml$1;
  29124. var languages$6 = [createLanguage(require$$0$33, {
  29125. override: {
  29126. since: "1.14.0",
  29127. parsers: ["yaml"],
  29128. vscodeLanguageIds: ["yaml"]
  29129. }
  29130. })];
  29131. var languageYaml = {
  29132. languages: languages$6,
  29133. printers: {
  29134. yaml: printerYaml
  29135. },
  29136. options: options$18
  29137. };
  29138. // plugin will look for `eval("require")()` and transform to `require()` in the bundle,
  29139. // and rewrite the paths to require from the top-level.
  29140. // We need to list the parsers and getters so we can load them only when necessary.
  29141. var internalPlugins = [// JS
  29142. languageJs, {
  29143. parsers: {
  29144. // JS - Babel
  29145. get babel() {
  29146. return require("./parser-babylon").parsers.babel;
  29147. },
  29148. get "babel-flow"() {
  29149. return require("./parser-babylon").parsers["babel-flow"];
  29150. },
  29151. get babylon() {
  29152. return require("./parser-babylon").parsers.babel;
  29153. },
  29154. get json() {
  29155. return require("./parser-babylon").parsers.json;
  29156. },
  29157. get json5() {
  29158. return require("./parser-babylon").parsers.json5;
  29159. },
  29160. get "json-stringify"() {
  29161. return require("./parser-babylon").parsers["json-stringify"];
  29162. },
  29163. get __js_expression() {
  29164. return require("./parser-babylon").parsers.__js_expression;
  29165. },
  29166. get __vue_expression() {
  29167. return require("./parser-babylon").parsers.__vue_expression;
  29168. },
  29169. get __vue_event_binding() {
  29170. return require("./parser-babylon").parsers.__vue_event_binding;
  29171. },
  29172. // JS - Flow
  29173. get flow() {
  29174. return require("./parser-flow").parsers.flow;
  29175. },
  29176. // JS - TypeScript
  29177. get typescript() {
  29178. return require("./parser-typescript").parsers.typescript;
  29179. },
  29180. /**
  29181. * TODO: Remove this old alias in a major version
  29182. */
  29183. get "typescript-eslint"() {
  29184. return require("./parser-typescript").parsers.typescript;
  29185. },
  29186. // JS - Angular Action
  29187. get __ng_action() {
  29188. return require("./parser-angular").parsers.__ng_action;
  29189. },
  29190. // JS - Angular Binding
  29191. get __ng_binding() {
  29192. return require("./parser-angular").parsers.__ng_binding;
  29193. },
  29194. // JS - Angular Interpolation
  29195. get __ng_interpolation() {
  29196. return require("./parser-angular").parsers.__ng_interpolation;
  29197. },
  29198. // JS - Angular Directive
  29199. get __ng_directive() {
  29200. return require("./parser-angular").parsers.__ng_directive;
  29201. }
  29202. }
  29203. }, // CSS
  29204. languageCss, {
  29205. parsers: {
  29206. // TODO: switch these to just `postcss` and use `language` instead.
  29207. get css() {
  29208. return require("./parser-postcss").parsers.css;
  29209. },
  29210. get less() {
  29211. return require("./parser-postcss").parsers.css;
  29212. },
  29213. get scss() {
  29214. return require("./parser-postcss").parsers.css;
  29215. }
  29216. }
  29217. }, // Handlebars
  29218. languageHandlebars, {
  29219. parsers: {
  29220. get glimmer() {
  29221. return require("./parser-glimmer").parsers.glimmer;
  29222. }
  29223. }
  29224. }, // GraphQL
  29225. languageGraphql, {
  29226. parsers: {
  29227. get graphql() {
  29228. return require("./parser-graphql").parsers.graphql;
  29229. }
  29230. }
  29231. }, // Markdown
  29232. languageMarkdown, {
  29233. parsers: {
  29234. get remark() {
  29235. return require("./parser-markdown").parsers.remark;
  29236. },
  29237. // TODO: Delete this in 2.0
  29238. get markdown() {
  29239. return require("./parser-markdown").parsers.remark;
  29240. },
  29241. get mdx() {
  29242. return require("./parser-markdown").parsers.mdx;
  29243. }
  29244. }
  29245. }, languageHtml, {
  29246. parsers: {
  29247. // HTML
  29248. get html() {
  29249. return require("./parser-html").parsers.html;
  29250. },
  29251. // Vue
  29252. get vue() {
  29253. return require("./parser-html").parsers.vue;
  29254. },
  29255. // Angular
  29256. get angular() {
  29257. return require("./parser-html").parsers.angular;
  29258. }
  29259. }
  29260. }, // YAML
  29261. languageYaml, {
  29262. parsers: {
  29263. get yaml() {
  29264. return require("./parser-yaml").parsers.yaml;
  29265. }
  29266. }
  29267. }];
  29268. var partition = function partition(array, fn) {
  29269. var a = [];
  29270. var b = [];
  29271. array.forEach(function (item) {
  29272. if (fn(item)) {
  29273. a.push(item);
  29274. } else {
  29275. b.push(item);
  29276. }
  29277. });
  29278. return [a, b];
  29279. };
  29280. var thirdParty$1 = ( thirdParty && thirdParty__default ) || thirdParty;
  29281. function loadPlugins(plugins, pluginSearchDirs) {
  29282. if (!plugins) {
  29283. plugins = [];
  29284. }
  29285. if (!pluginSearchDirs) {
  29286. pluginSearchDirs = [];
  29287. } // unless pluginSearchDirs are provided, auto-load plugins from node_modules that are parent to Prettier
  29288. if (!pluginSearchDirs.length) {
  29289. var autoLoadDir = thirdParty$1.findParentDir(__dirname, "node_modules");
  29290. if (autoLoadDir) {
  29291. pluginSearchDirs = [autoLoadDir];
  29292. }
  29293. }
  29294. var _partition = partition(plugins, function (plugin) {
  29295. return typeof plugin === "string";
  29296. }),
  29297. _partition2 = _slicedToArray(_partition, 2),
  29298. externalPluginNames = _partition2[0],
  29299. externalPluginInstances = _partition2[1];
  29300. var externalManualLoadPluginInfos = externalPluginNames.map(function (pluginName) {
  29301. var requirePath;
  29302. try {
  29303. // try local files
  29304. requirePath = resolve$1.sync(path.resolve(process.cwd(), pluginName));
  29305. } catch (e) {
  29306. // try node modules
  29307. requirePath = resolve$1.sync(pluginName, {
  29308. basedir: process.cwd()
  29309. });
  29310. }
  29311. return {
  29312. name: pluginName,
  29313. requirePath
  29314. };
  29315. });
  29316. var externalAutoLoadPluginInfos = pluginSearchDirs.map(function (pluginSearchDir) {
  29317. var resolvedPluginSearchDir = path.resolve(process.cwd(), pluginSearchDir);
  29318. if (!isDirectory(resolvedPluginSearchDir)) {
  29319. throw new Error(`${pluginSearchDir} does not exist or is not a directory`);
  29320. }
  29321. var nodeModulesDir = path.resolve(resolvedPluginSearchDir, "node_modules");
  29322. return findPluginsInNodeModules(nodeModulesDir).map(function (pluginName) {
  29323. return {
  29324. name: pluginName,
  29325. requirePath: resolve$1.sync(pluginName, {
  29326. basedir: resolvedPluginSearchDir
  29327. })
  29328. };
  29329. });
  29330. }).reduce(function (a, b) {
  29331. return a.concat(b);
  29332. }, []);
  29333. var externalPlugins = lodash_uniqby(externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), "requirePath").map(function (externalPluginInfo) {
  29334. return Object.assign({
  29335. name: externalPluginInfo.name
  29336. }, require(externalPluginInfo.requirePath));
  29337. }).concat(externalPluginInstances);
  29338. return internalPlugins.concat(externalPlugins);
  29339. }
  29340. function findPluginsInNodeModules(nodeModulesDir) {
  29341. var pluginPackageJsonPaths = globby.sync(["prettier-plugin-*/package.json", "@prettier/plugin-*/package.json"], {
  29342. cwd: nodeModulesDir
  29343. });
  29344. return pluginPackageJsonPaths.map(path.dirname);
  29345. }
  29346. function isDirectory(dir) {
  29347. try {
  29348. return fs.statSync(dir).isDirectory();
  29349. } catch (e) {
  29350. return false;
  29351. }
  29352. }
  29353. var loadPlugins_1 = loadPlugins;
  29354. var mimicFn = function mimicFn(to, from) {
  29355. // TODO: use `Reflect.ownKeys()` when targeting Node.js 6
  29356. var _iteratorNormalCompletion = true;
  29357. var _didIteratorError = false;
  29358. var _iteratorError = undefined;
  29359. try {
  29360. for (var _iterator = Object.getOwnPropertyNames(from).concat(Object.getOwnPropertySymbols(from))[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  29361. var prop = _step.value;
  29362. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  29363. }
  29364. } catch (err) {
  29365. _didIteratorError = true;
  29366. _iteratorError = err;
  29367. } finally {
  29368. try {
  29369. if (!_iteratorNormalCompletion && _iterator.return != null) {
  29370. _iterator.return();
  29371. }
  29372. } finally {
  29373. if (_didIteratorError) {
  29374. throw _iteratorError;
  29375. }
  29376. }
  29377. }
  29378. };
  29379. var mem = createCommonjsModule(function (module) {
  29380. 'use strict';
  29381. var cacheStore = new WeakMap();
  29382. var defaultCacheKey = function defaultCacheKey(x) {
  29383. if (arguments.length === 1 && (x === null || x === undefined || typeof x !== 'function' && typeof x !== 'object')) {
  29384. return x;
  29385. }
  29386. return JSON.stringify(arguments);
  29387. };
  29388. module.exports = function (fn, opts) {
  29389. opts = Object.assign({
  29390. cacheKey: defaultCacheKey,
  29391. cache: new Map()
  29392. }, opts);
  29393. var memoized = function memoized() {
  29394. var cache = cacheStore.get(memoized);
  29395. var key = opts.cacheKey.apply(null, arguments);
  29396. if (cache.has(key)) {
  29397. var c = cache.get(key);
  29398. if (typeof opts.maxAge !== 'number' || Date.now() < c.maxAge) {
  29399. return c.data;
  29400. }
  29401. }
  29402. var ret = fn.apply(null, arguments);
  29403. cache.set(key, {
  29404. data: ret,
  29405. maxAge: Date.now() + (opts.maxAge || 0)
  29406. });
  29407. return ret;
  29408. };
  29409. mimicFn(memoized, fn);
  29410. cacheStore.set(memoized, opts.cache);
  29411. return memoized;
  29412. };
  29413. module.exports.clear = function (fn) {
  29414. var cache = cacheStore.get(fn);
  29415. if (cache && typeof cache.clear === 'function') {
  29416. cache.clear();
  29417. }
  29418. };
  29419. });
  29420. var semver$3 = createCommonjsModule(function (module, exports) {
  29421. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  29422. /* nomin */
  29423. var debug;
  29424. /* nomin */
  29425. if (typeof process === 'object' &&
  29426. /* nomin */
  29427. process.env &&
  29428. /* nomin */
  29429. process.env.NODE_DEBUG &&
  29430. /* nomin */
  29431. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  29432. /* nomin */
  29433. debug = function debug() {
  29434. /* nomin */
  29435. var args = Array.prototype.slice.call(arguments, 0);
  29436. /* nomin */
  29437. args.unshift('SEMVER');
  29438. /* nomin */
  29439. console.log.apply(console, args);
  29440. /* nomin */
  29441. };
  29442. /* nomin */
  29443. else
  29444. /* nomin */
  29445. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  29446. // Not necessarily the package version of this code.
  29447. exports.SEMVER_SPEC_VERSION = '2.0.0';
  29448. var MAX_LENGTH = 256;
  29449. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // Max safe segment length for coercion.
  29450. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  29451. var re = exports.re = [];
  29452. var src = exports.src = [];
  29453. var R = 0; // The following Regular Expressions can be used for tokenizing,
  29454. // validating, and parsing SemVer version strings.
  29455. // ## Numeric Identifier
  29456. // A single `0`, or a non-zero digit followed by zero or more digits.
  29457. var NUMERICIDENTIFIER = R++;
  29458. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  29459. var NUMERICIDENTIFIERLOOSE = R++;
  29460. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  29461. // Zero or more digits, followed by a letter or hyphen, and then zero or
  29462. // more letters, digits, or hyphens.
  29463. var NONNUMERICIDENTIFIER = R++;
  29464. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  29465. // Three dot-separated numeric identifiers.
  29466. var MAINVERSION = R++;
  29467. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  29468. var MAINVERSIONLOOSE = R++;
  29469. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  29470. // A numeric identifier, or a non-numeric identifier.
  29471. var PRERELEASEIDENTIFIER = R++;
  29472. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  29473. var PRERELEASEIDENTIFIERLOOSE = R++;
  29474. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  29475. // Hyphen, followed by one or more dot-separated pre-release version
  29476. // identifiers.
  29477. var PRERELEASE = R++;
  29478. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  29479. var PRERELEASELOOSE = R++;
  29480. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  29481. // Any combination of digits, letters, or hyphens.
  29482. var BUILDIDENTIFIER = R++;
  29483. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  29484. // Plus sign, followed by one or more period-separated build metadata
  29485. // identifiers.
  29486. var BUILD = R++;
  29487. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  29488. // A main version, followed optionally by a pre-release version and
  29489. // build metadata.
  29490. // Note that the only major, minor, patch, and pre-release sections of
  29491. // the version string are capturing groups. The build metadata is not a
  29492. // capturing group, because it should not ever be used in version
  29493. // comparison.
  29494. var FULL = R++;
  29495. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  29496. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  29497. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  29498. // common in the npm registry.
  29499. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  29500. var LOOSE = R++;
  29501. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  29502. var GTLT = R++;
  29503. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  29504. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  29505. // Only the first item is strictly required.
  29506. var XRANGEIDENTIFIERLOOSE = R++;
  29507. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  29508. var XRANGEIDENTIFIER = R++;
  29509. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  29510. var XRANGEPLAIN = R++;
  29511. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  29512. var XRANGEPLAINLOOSE = R++;
  29513. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  29514. var XRANGE = R++;
  29515. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  29516. var XRANGELOOSE = R++;
  29517. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Coercion.
  29518. // Extract anything that could conceivably be a part of a valid semver
  29519. var COERCE = R++;
  29520. src[COERCE] = '(?:^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])'; // Tilde ranges.
  29521. // Meaning is "reasonably at or greater than"
  29522. var LONETILDE = R++;
  29523. src[LONETILDE] = '(?:~>?)';
  29524. var TILDETRIM = R++;
  29525. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  29526. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  29527. var tildeTrimReplace = '$1~';
  29528. var TILDE = R++;
  29529. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  29530. var TILDELOOSE = R++;
  29531. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  29532. // Meaning is "at least and backwards compatible with"
  29533. var LONECARET = R++;
  29534. src[LONECARET] = '(?:\\^)';
  29535. var CARETTRIM = R++;
  29536. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  29537. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  29538. var caretTrimReplace = '$1^';
  29539. var CARET = R++;
  29540. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  29541. var CARETLOOSE = R++;
  29542. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  29543. var COMPARATORLOOSE = R++;
  29544. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  29545. var COMPARATOR = R++;
  29546. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  29547. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  29548. var COMPARATORTRIM = R++;
  29549. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  29550. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  29551. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  29552. // Note that these all use the loose form, because they'll be
  29553. // checked against either the strict or loose comparator form
  29554. // later.
  29555. var HYPHENRANGE = R++;
  29556. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  29557. var HYPHENRANGELOOSE = R++;
  29558. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  29559. var STAR = R++;
  29560. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  29561. // All are flag-free, unless they were created above with a flag.
  29562. for (var i = 0; i < R; i++) {
  29563. debug(i, src[i]);
  29564. if (!re[i]) re[i] = new RegExp(src[i]);
  29565. }
  29566. exports.parse = parse;
  29567. function parse(version, options) {
  29568. if (!options || typeof options !== 'object') options = {
  29569. loose: !!options,
  29570. includePrerelease: false
  29571. };
  29572. if (version instanceof SemVer) return version;
  29573. if (typeof version !== 'string') return null;
  29574. if (version.length > MAX_LENGTH) return null;
  29575. var r = options.loose ? re[LOOSE] : re[FULL];
  29576. if (!r.test(version)) return null;
  29577. try {
  29578. return new SemVer(version, options);
  29579. } catch (er) {
  29580. return null;
  29581. }
  29582. }
  29583. exports.valid = valid;
  29584. function valid(version, options) {
  29585. var v = parse(version, options);
  29586. return v ? v.version : null;
  29587. }
  29588. exports.clean = clean;
  29589. function clean(version, options) {
  29590. var s = parse(version.trim().replace(/^[=v]+/, ''), options);
  29591. return s ? s.version : null;
  29592. }
  29593. exports.SemVer = SemVer;
  29594. function SemVer(version, options) {
  29595. if (!options || typeof options !== 'object') options = {
  29596. loose: !!options,
  29597. includePrerelease: false
  29598. };
  29599. if (version instanceof SemVer) {
  29600. if (version.loose === options.loose) return version;else version = version.version;
  29601. } else if (typeof version !== 'string') {
  29602. throw new TypeError('Invalid Version: ' + version);
  29603. }
  29604. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  29605. if (!(this instanceof SemVer)) return new SemVer(version, options);
  29606. debug('SemVer', version, options);
  29607. this.options = options;
  29608. this.loose = !!options.loose;
  29609. var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL]);
  29610. if (!m) throw new TypeError('Invalid Version: ' + version);
  29611. this.raw = version; // these are actually numbers
  29612. this.major = +m[1];
  29613. this.minor = +m[2];
  29614. this.patch = +m[3];
  29615. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  29616. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  29617. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  29618. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  29619. if (/^[0-9]+$/.test(id)) {
  29620. var num = +id;
  29621. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  29622. }
  29623. return id;
  29624. });
  29625. this.build = m[5] ? m[5].split('.') : [];
  29626. this.format();
  29627. }
  29628. SemVer.prototype.format = function () {
  29629. this.version = this.major + '.' + this.minor + '.' + this.patch;
  29630. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  29631. return this.version;
  29632. };
  29633. SemVer.prototype.toString = function () {
  29634. return this.version;
  29635. };
  29636. SemVer.prototype.compare = function (other) {
  29637. debug('SemVer.compare', this.version, this.options, other);
  29638. if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
  29639. return this.compareMain(other) || this.comparePre(other);
  29640. };
  29641. SemVer.prototype.compareMain = function (other) {
  29642. if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
  29643. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  29644. };
  29645. SemVer.prototype.comparePre = function (other) {
  29646. if (!(other instanceof SemVer)) other = new SemVer(other, this.options); // NOT having a prerelease is > having one
  29647. 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;
  29648. var i = 0;
  29649. do {
  29650. var a = this.prerelease[i];
  29651. var b = other.prerelease[i];
  29652. debug('prerelease compare', i, a, b);
  29653. 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);
  29654. } while (++i);
  29655. }; // preminor will bump the version up to the next minor release, and immediately
  29656. // down to pre-release. premajor and prepatch work the same way.
  29657. SemVer.prototype.inc = function (release, identifier) {
  29658. switch (release) {
  29659. case 'premajor':
  29660. this.prerelease.length = 0;
  29661. this.patch = 0;
  29662. this.minor = 0;
  29663. this.major++;
  29664. this.inc('pre', identifier);
  29665. break;
  29666. case 'preminor':
  29667. this.prerelease.length = 0;
  29668. this.patch = 0;
  29669. this.minor++;
  29670. this.inc('pre', identifier);
  29671. break;
  29672. case 'prepatch':
  29673. // If this is already a prerelease, it will bump to the next version
  29674. // drop any prereleases that might already exist, since they are not
  29675. // relevant at this point.
  29676. this.prerelease.length = 0;
  29677. this.inc('patch', identifier);
  29678. this.inc('pre', identifier);
  29679. break;
  29680. // If the input is a non-prerelease version, this acts the same as
  29681. // prepatch.
  29682. case 'prerelease':
  29683. if (this.prerelease.length === 0) this.inc('patch', identifier);
  29684. this.inc('pre', identifier);
  29685. break;
  29686. case 'major':
  29687. // If this is a pre-major version, bump up to the same major version.
  29688. // Otherwise increment major.
  29689. // 1.0.0-5 bumps to 1.0.0
  29690. // 1.1.0 bumps to 2.0.0
  29691. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  29692. this.minor = 0;
  29693. this.patch = 0;
  29694. this.prerelease = [];
  29695. break;
  29696. case 'minor':
  29697. // If this is a pre-minor version, bump up to the same minor version.
  29698. // Otherwise increment minor.
  29699. // 1.2.0-5 bumps to 1.2.0
  29700. // 1.2.1 bumps to 1.3.0
  29701. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  29702. this.patch = 0;
  29703. this.prerelease = [];
  29704. break;
  29705. case 'patch':
  29706. // If this is not a pre-release version, it will increment the patch.
  29707. // If it is a pre-release it will bump up to the same patch version.
  29708. // 1.2.0-5 patches to 1.2.0
  29709. // 1.2.0 patches to 1.2.1
  29710. if (this.prerelease.length === 0) this.patch++;
  29711. this.prerelease = [];
  29712. break;
  29713. // This probably shouldn't be used publicly.
  29714. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  29715. case 'pre':
  29716. if (this.prerelease.length === 0) this.prerelease = [0];else {
  29717. var i = this.prerelease.length;
  29718. while (--i >= 0) {
  29719. if (typeof this.prerelease[i] === 'number') {
  29720. this.prerelease[i]++;
  29721. i = -2;
  29722. }
  29723. }
  29724. if (i === -1) // didn't increment anything
  29725. this.prerelease.push(0);
  29726. }
  29727. if (identifier) {
  29728. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  29729. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  29730. if (this.prerelease[0] === identifier) {
  29731. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  29732. } else this.prerelease = [identifier, 0];
  29733. }
  29734. break;
  29735. default:
  29736. throw new Error('invalid increment argument: ' + release);
  29737. }
  29738. this.format();
  29739. this.raw = this.version;
  29740. return this;
  29741. };
  29742. exports.inc = inc;
  29743. function inc(version, release, loose, identifier) {
  29744. if (typeof loose === 'string') {
  29745. identifier = loose;
  29746. loose = undefined;
  29747. }
  29748. try {
  29749. return new SemVer(version, loose).inc(release, identifier).version;
  29750. } catch (er) {
  29751. return null;
  29752. }
  29753. }
  29754. exports.diff = diff;
  29755. function diff(version1, version2) {
  29756. if (eq(version1, version2)) {
  29757. return null;
  29758. } else {
  29759. var v1 = parse(version1);
  29760. var v2 = parse(version2);
  29761. if (v1.prerelease.length || v2.prerelease.length) {
  29762. for (var key in v1) {
  29763. if (key === 'major' || key === 'minor' || key === 'patch') {
  29764. if (v1[key] !== v2[key]) {
  29765. return 'pre' + key;
  29766. }
  29767. }
  29768. }
  29769. return 'prerelease';
  29770. }
  29771. for (var key in v1) {
  29772. if (key === 'major' || key === 'minor' || key === 'patch') {
  29773. if (v1[key] !== v2[key]) {
  29774. return key;
  29775. }
  29776. }
  29777. }
  29778. }
  29779. }
  29780. exports.compareIdentifiers = compareIdentifiers;
  29781. var numeric = /^[0-9]+$/;
  29782. function compareIdentifiers(a, b) {
  29783. var anum = numeric.test(a);
  29784. var bnum = numeric.test(b);
  29785. if (anum && bnum) {
  29786. a = +a;
  29787. b = +b;
  29788. }
  29789. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  29790. }
  29791. exports.rcompareIdentifiers = rcompareIdentifiers;
  29792. function rcompareIdentifiers(a, b) {
  29793. return compareIdentifiers(b, a);
  29794. }
  29795. exports.major = major;
  29796. function major(a, loose) {
  29797. return new SemVer(a, loose).major;
  29798. }
  29799. exports.minor = minor;
  29800. function minor(a, loose) {
  29801. return new SemVer(a, loose).minor;
  29802. }
  29803. exports.patch = patch;
  29804. function patch(a, loose) {
  29805. return new SemVer(a, loose).patch;
  29806. }
  29807. exports.compare = compare;
  29808. function compare(a, b, loose) {
  29809. return new SemVer(a, loose).compare(new SemVer(b, loose));
  29810. }
  29811. exports.compareLoose = compareLoose;
  29812. function compareLoose(a, b) {
  29813. return compare(a, b, true);
  29814. }
  29815. exports.rcompare = rcompare;
  29816. function rcompare(a, b, loose) {
  29817. return compare(b, a, loose);
  29818. }
  29819. exports.sort = sort;
  29820. function sort(list, loose) {
  29821. return list.sort(function (a, b) {
  29822. return exports.compare(a, b, loose);
  29823. });
  29824. }
  29825. exports.rsort = rsort;
  29826. function rsort(list, loose) {
  29827. return list.sort(function (a, b) {
  29828. return exports.rcompare(a, b, loose);
  29829. });
  29830. }
  29831. exports.gt = gt;
  29832. function gt(a, b, loose) {
  29833. return compare(a, b, loose) > 0;
  29834. }
  29835. exports.lt = lt;
  29836. function lt(a, b, loose) {
  29837. return compare(a, b, loose) < 0;
  29838. }
  29839. exports.eq = eq;
  29840. function eq(a, b, loose) {
  29841. return compare(a, b, loose) === 0;
  29842. }
  29843. exports.neq = neq;
  29844. function neq(a, b, loose) {
  29845. return compare(a, b, loose) !== 0;
  29846. }
  29847. exports.gte = gte;
  29848. function gte(a, b, loose) {
  29849. return compare(a, b, loose) >= 0;
  29850. }
  29851. exports.lte = lte;
  29852. function lte(a, b, loose) {
  29853. return compare(a, b, loose) <= 0;
  29854. }
  29855. exports.cmp = cmp;
  29856. function cmp(a, op, b, loose) {
  29857. var ret;
  29858. switch (op) {
  29859. case '===':
  29860. if (typeof a === 'object') a = a.version;
  29861. if (typeof b === 'object') b = b.version;
  29862. ret = a === b;
  29863. break;
  29864. case '!==':
  29865. if (typeof a === 'object') a = a.version;
  29866. if (typeof b === 'object') b = b.version;
  29867. ret = a !== b;
  29868. break;
  29869. case '':
  29870. case '=':
  29871. case '==':
  29872. ret = eq(a, b, loose);
  29873. break;
  29874. case '!=':
  29875. ret = neq(a, b, loose);
  29876. break;
  29877. case '>':
  29878. ret = gt(a, b, loose);
  29879. break;
  29880. case '>=':
  29881. ret = gte(a, b, loose);
  29882. break;
  29883. case '<':
  29884. ret = lt(a, b, loose);
  29885. break;
  29886. case '<=':
  29887. ret = lte(a, b, loose);
  29888. break;
  29889. default:
  29890. throw new TypeError('Invalid operator: ' + op);
  29891. }
  29892. return ret;
  29893. }
  29894. exports.Comparator = Comparator;
  29895. function Comparator(comp, options) {
  29896. if (!options || typeof options !== 'object') options = {
  29897. loose: !!options,
  29898. includePrerelease: false
  29899. };
  29900. if (comp instanceof Comparator) {
  29901. if (comp.loose === !!options.loose) return comp;else comp = comp.value;
  29902. }
  29903. if (!(this instanceof Comparator)) return new Comparator(comp, options);
  29904. debug('comparator', comp, options);
  29905. this.options = options;
  29906. this.loose = !!options.loose;
  29907. this.parse(comp);
  29908. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  29909. debug('comp', this);
  29910. }
  29911. var ANY = {};
  29912. Comparator.prototype.parse = function (comp) {
  29913. var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  29914. var m = comp.match(r);
  29915. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  29916. this.operator = m[1];
  29917. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  29918. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.options.loose);
  29919. };
  29920. Comparator.prototype.toString = function () {
  29921. return this.value;
  29922. };
  29923. Comparator.prototype.test = function (version) {
  29924. debug('Comparator.test', version, this.options.loose);
  29925. if (this.semver === ANY) return true;
  29926. if (typeof version === 'string') version = new SemVer(version, this.options);
  29927. return cmp(version, this.operator, this.semver, this.options);
  29928. };
  29929. Comparator.prototype.intersects = function (comp, options) {
  29930. if (!(comp instanceof Comparator)) {
  29931. throw new TypeError('a Comparator is required');
  29932. }
  29933. if (!options || typeof options !== 'object') options = {
  29934. loose: !!options,
  29935. includePrerelease: false
  29936. };
  29937. var rangeTmp;
  29938. if (this.operator === '') {
  29939. rangeTmp = new Range(comp.value, options);
  29940. return satisfies(this.value, rangeTmp, options);
  29941. } else if (comp.operator === '') {
  29942. rangeTmp = new Range(this.value, options);
  29943. return satisfies(comp.semver, rangeTmp, options);
  29944. }
  29945. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  29946. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  29947. var sameSemVer = this.semver.version === comp.semver.version;
  29948. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  29949. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, options) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  29950. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, options) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  29951. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  29952. };
  29953. exports.Range = Range;
  29954. function Range(range, options) {
  29955. if (!options || typeof options !== 'object') options = {
  29956. loose: !!options,
  29957. includePrerelease: false
  29958. };
  29959. if (range instanceof Range) {
  29960. if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
  29961. return range;
  29962. } else {
  29963. return new Range(range.raw, options);
  29964. }
  29965. }
  29966. if (range instanceof Comparator) {
  29967. return new Range(range.value, options);
  29968. }
  29969. if (!(this instanceof Range)) return new Range(range, options);
  29970. this.options = options;
  29971. this.loose = !!options.loose;
  29972. this.includePrerelease = !!options.includePrerelease; // First, split based on boolean or ||
  29973. this.raw = range;
  29974. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  29975. return this.parseRange(range.trim());
  29976. }, this).filter(function (c) {
  29977. // throw out any that are not relevant for whatever reason
  29978. return c.length;
  29979. });
  29980. if (!this.set.length) {
  29981. throw new TypeError('Invalid SemVer Range: ' + range);
  29982. }
  29983. this.format();
  29984. }
  29985. Range.prototype.format = function () {
  29986. this.range = this.set.map(function (comps) {
  29987. return comps.join(' ').trim();
  29988. }).join('||').trim();
  29989. return this.range;
  29990. };
  29991. Range.prototype.toString = function () {
  29992. return this.range;
  29993. };
  29994. Range.prototype.parseRange = function (range) {
  29995. var loose = this.options.loose;
  29996. range = range.trim(); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  29997. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  29998. range = range.replace(hr, hyphenReplace);
  29999. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  30000. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  30001. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  30002. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  30003. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  30004. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  30005. // ready to be split into comparators.
  30006. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  30007. var set = range.split(' ').map(function (comp) {
  30008. return parseComparator(comp, this.options);
  30009. }, this).join(' ').split(/\s+/);
  30010. if (this.options.loose) {
  30011. // in loose mode, throw out any that are not valid comparators
  30012. set = set.filter(function (comp) {
  30013. return !!comp.match(compRe);
  30014. });
  30015. }
  30016. set = set.map(function (comp) {
  30017. return new Comparator(comp, this.options);
  30018. }, this);
  30019. return set;
  30020. };
  30021. Range.prototype.intersects = function (range, options) {
  30022. if (!(range instanceof Range)) {
  30023. throw new TypeError('a Range is required');
  30024. }
  30025. return this.set.some(function (thisComparators) {
  30026. return thisComparators.every(function (thisComparator) {
  30027. return range.set.some(function (rangeComparators) {
  30028. return rangeComparators.every(function (rangeComparator) {
  30029. return thisComparator.intersects(rangeComparator, options);
  30030. });
  30031. });
  30032. });
  30033. });
  30034. }; // Mostly just for testing and legacy API reasons
  30035. exports.toComparators = toComparators;
  30036. function toComparators(range, options) {
  30037. return new Range(range, options).set.map(function (comp) {
  30038. return comp.map(function (c) {
  30039. return c.value;
  30040. }).join(' ').trim().split(' ');
  30041. });
  30042. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  30043. // already replaced the hyphen ranges
  30044. // turn into a set of JUST comparators.
  30045. function parseComparator(comp, options) {
  30046. debug('comp', comp, options);
  30047. comp = replaceCarets(comp, options);
  30048. debug('caret', comp);
  30049. comp = replaceTildes(comp, options);
  30050. debug('tildes', comp);
  30051. comp = replaceXRanges(comp, options);
  30052. debug('xrange', comp);
  30053. comp = replaceStars(comp, options);
  30054. debug('stars', comp);
  30055. return comp;
  30056. }
  30057. function isX(id) {
  30058. return !id || id.toLowerCase() === 'x' || id === '*';
  30059. } // ~, ~> --> * (any, kinda silly)
  30060. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  30061. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  30062. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  30063. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  30064. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  30065. function replaceTildes(comp, options) {
  30066. return comp.trim().split(/\s+/).map(function (comp) {
  30067. return replaceTilde(comp, options);
  30068. }).join(' ');
  30069. }
  30070. function replaceTilde(comp, options) {
  30071. if (!options || typeof options !== 'object') options = {
  30072. loose: !!options,
  30073. includePrerelease: false
  30074. };
  30075. var r = options.loose ? re[TILDELOOSE] : re[TILDE];
  30076. return comp.replace(r, function (_, M, m, p, pr) {
  30077. debug('tilde', comp, _, M, m, p, pr);
  30078. var ret;
  30079. 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
  30080. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  30081. debug('replaceTilde pr', pr);
  30082. if (pr.charAt(0) !== '-') pr = '-' + pr;
  30083. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  30084. } else // ~1.2.3 == >=1.2.3 <1.3.0
  30085. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  30086. debug('tilde return', ret);
  30087. return ret;
  30088. });
  30089. } // ^ --> * (any, kinda silly)
  30090. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  30091. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  30092. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  30093. // ^1.2.3 --> >=1.2.3 <2.0.0
  30094. // ^1.2.0 --> >=1.2.0 <2.0.0
  30095. function replaceCarets(comp, options) {
  30096. return comp.trim().split(/\s+/).map(function (comp) {
  30097. return replaceCaret(comp, options);
  30098. }).join(' ');
  30099. }
  30100. function replaceCaret(comp, options) {
  30101. debug('caret', comp, options);
  30102. if (!options || typeof options !== 'object') options = {
  30103. loose: !!options,
  30104. includePrerelease: false
  30105. };
  30106. var r = options.loose ? re[CARETLOOSE] : re[CARET];
  30107. return comp.replace(r, function (_, M, m, p, pr) {
  30108. debug('caret', comp, _, M, m, p, pr);
  30109. var ret;
  30110. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  30111. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  30112. } else if (pr) {
  30113. debug('replaceCaret pr', pr);
  30114. if (pr.charAt(0) !== '-') pr = '-' + pr;
  30115. if (M === '0') {
  30116. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  30117. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  30118. } else {
  30119. debug('no pr');
  30120. if (M === '0') {
  30121. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  30122. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  30123. }
  30124. debug('caret return', ret);
  30125. return ret;
  30126. });
  30127. }
  30128. function replaceXRanges(comp, options) {
  30129. debug('replaceXRanges', comp, options);
  30130. return comp.split(/\s+/).map(function (comp) {
  30131. return replaceXRange(comp, options);
  30132. }).join(' ');
  30133. }
  30134. function replaceXRange(comp, options) {
  30135. comp = comp.trim();
  30136. if (!options || typeof options !== 'object') options = {
  30137. loose: !!options,
  30138. includePrerelease: false
  30139. };
  30140. var r = options.loose ? re[XRANGELOOSE] : re[XRANGE];
  30141. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  30142. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  30143. var xM = isX(M);
  30144. var xm = xM || isX(m);
  30145. var xp = xm || isX(p);
  30146. var anyX = xp;
  30147. if (gtlt === '=' && anyX) gtlt = '';
  30148. if (xM) {
  30149. if (gtlt === '>' || gtlt === '<') {
  30150. // nothing is allowed
  30151. ret = '<0.0.0';
  30152. } else {
  30153. // nothing is forbidden
  30154. ret = '*';
  30155. }
  30156. } else if (gtlt && anyX) {
  30157. // replace X with 0
  30158. if (xm) m = 0;
  30159. if (xp) p = 0;
  30160. if (gtlt === '>') {
  30161. // >1 => >=2.0.0
  30162. // >1.2 => >=1.3.0
  30163. // >1.2.3 => >= 1.2.4
  30164. gtlt = '>=';
  30165. if (xm) {
  30166. M = +M + 1;
  30167. m = 0;
  30168. p = 0;
  30169. } else if (xp) {
  30170. m = +m + 1;
  30171. p = 0;
  30172. }
  30173. } else if (gtlt === '<=') {
  30174. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  30175. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  30176. gtlt = '<';
  30177. if (xm) M = +M + 1;else m = +m + 1;
  30178. }
  30179. ret = gtlt + M + '.' + m + '.' + p;
  30180. } else if (xm) {
  30181. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  30182. } else if (xp) {
  30183. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  30184. }
  30185. debug('xRange return', ret);
  30186. return ret;
  30187. });
  30188. } // Because * is AND-ed with everything else in the comparator,
  30189. // and '' means "any version", just remove the *s entirely.
  30190. function replaceStars(comp, options) {
  30191. debug('replaceStars', comp, options); // Looseness is ignored here. star is always as loose as it gets!
  30192. return comp.trim().replace(re[STAR], '');
  30193. } // This function is passed to string.replace(re[HYPHENRANGE])
  30194. // M, m, patch, prerelease, build
  30195. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  30196. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  30197. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  30198. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  30199. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  30200. 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;
  30201. return (from + ' ' + to).trim();
  30202. } // if ANY of the sets match ALL of its comparators, then pass
  30203. Range.prototype.test = function (version) {
  30204. if (!version) return false;
  30205. if (typeof version === 'string') version = new SemVer(version, this.options);
  30206. for (var i = 0; i < this.set.length; i++) {
  30207. if (testSet(this.set[i], version, this.options)) return true;
  30208. }
  30209. return false;
  30210. };
  30211. function testSet(set, version, options) {
  30212. for (var i = 0; i < set.length; i++) {
  30213. if (!set[i].test(version)) return false;
  30214. }
  30215. if (!options) options = {};
  30216. if (version.prerelease.length && !options.includePrerelease) {
  30217. // Find the set of versions that are allowed to have prereleases
  30218. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  30219. // That should allow `1.2.3-pr.2` to pass.
  30220. // However, `1.2.4-alpha.notready` should NOT be allowed,
  30221. // even though it's within the range set by the comparators.
  30222. for (var i = 0; i < set.length; i++) {
  30223. debug(set[i].semver);
  30224. if (set[i].semver === ANY) continue;
  30225. if (set[i].semver.prerelease.length > 0) {
  30226. var allowed = set[i].semver;
  30227. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  30228. }
  30229. } // Version has a -pre, but it's not one of the ones we like.
  30230. return false;
  30231. }
  30232. return true;
  30233. }
  30234. exports.satisfies = satisfies;
  30235. function satisfies(version, range, options) {
  30236. try {
  30237. range = new Range(range, options);
  30238. } catch (er) {
  30239. return false;
  30240. }
  30241. return range.test(version);
  30242. }
  30243. exports.maxSatisfying = maxSatisfying;
  30244. function maxSatisfying(versions, range, options) {
  30245. var max = null;
  30246. var maxSV = null;
  30247. try {
  30248. var rangeObj = new Range(range, options);
  30249. } catch (er) {
  30250. return null;
  30251. }
  30252. versions.forEach(function (v) {
  30253. if (rangeObj.test(v)) {
  30254. // satisfies(v, range, options)
  30255. if (!max || maxSV.compare(v) === -1) {
  30256. // compare(max, v, true)
  30257. max = v;
  30258. maxSV = new SemVer(max, options);
  30259. }
  30260. }
  30261. });
  30262. return max;
  30263. }
  30264. exports.minSatisfying = minSatisfying;
  30265. function minSatisfying(versions, range, options) {
  30266. var min = null;
  30267. var minSV = null;
  30268. try {
  30269. var rangeObj = new Range(range, options);
  30270. } catch (er) {
  30271. return null;
  30272. }
  30273. versions.forEach(function (v) {
  30274. if (rangeObj.test(v)) {
  30275. // satisfies(v, range, options)
  30276. if (!min || minSV.compare(v) === 1) {
  30277. // compare(min, v, true)
  30278. min = v;
  30279. minSV = new SemVer(min, options);
  30280. }
  30281. }
  30282. });
  30283. return min;
  30284. }
  30285. exports.validRange = validRange;
  30286. function validRange(range, options) {
  30287. try {
  30288. // Return '*' instead of '' so that truthiness works.
  30289. // This will throw if it's invalid anyway
  30290. return new Range(range, options).range || '*';
  30291. } catch (er) {
  30292. return null;
  30293. }
  30294. } // Determine if version is less than all the versions possible in the range
  30295. exports.ltr = ltr;
  30296. function ltr(version, range, options) {
  30297. return outside(version, range, '<', options);
  30298. } // Determine if version is greater than all the versions possible in the range.
  30299. exports.gtr = gtr;
  30300. function gtr(version, range, options) {
  30301. return outside(version, range, '>', options);
  30302. }
  30303. exports.outside = outside;
  30304. function outside(version, range, hilo, options) {
  30305. version = new SemVer(version, options);
  30306. range = new Range(range, options);
  30307. var gtfn, ltefn, ltfn, comp, ecomp;
  30308. switch (hilo) {
  30309. case '>':
  30310. gtfn = gt;
  30311. ltefn = lte;
  30312. ltfn = lt;
  30313. comp = '>';
  30314. ecomp = '>=';
  30315. break;
  30316. case '<':
  30317. gtfn = lt;
  30318. ltefn = gte;
  30319. ltfn = gt;
  30320. comp = '<';
  30321. ecomp = '<=';
  30322. break;
  30323. default:
  30324. throw new TypeError('Must provide a hilo val of "<" or ">"');
  30325. } // If it satisifes the range it is not outside
  30326. if (satisfies(version, range, options)) {
  30327. return false;
  30328. } // From now on, variable terms are as if we're in "gtr" mode.
  30329. // but note that everything is flipped for the "ltr" function.
  30330. for (var i = 0; i < range.set.length; ++i) {
  30331. var comparators = range.set[i];
  30332. var high = null;
  30333. var low = null;
  30334. comparators.forEach(function (comparator) {
  30335. if (comparator.semver === ANY) {
  30336. comparator = new Comparator('>=0.0.0');
  30337. }
  30338. high = high || comparator;
  30339. low = low || comparator;
  30340. if (gtfn(comparator.semver, high.semver, options)) {
  30341. high = comparator;
  30342. } else if (ltfn(comparator.semver, low.semver, options)) {
  30343. low = comparator;
  30344. }
  30345. }); // If the edge version comparator has a operator then our version
  30346. // isn't outside it
  30347. if (high.operator === comp || high.operator === ecomp) {
  30348. return false;
  30349. } // If the lowest version comparator has an operator and our version
  30350. // is less than it then it isn't higher than the range
  30351. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  30352. return false;
  30353. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  30354. return false;
  30355. }
  30356. }
  30357. return true;
  30358. }
  30359. exports.prerelease = prerelease;
  30360. function prerelease(version, options) {
  30361. var parsed = parse(version, options);
  30362. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  30363. }
  30364. exports.intersects = intersects;
  30365. function intersects(r1, r2, options) {
  30366. r1 = new Range(r1, options);
  30367. r2 = new Range(r2, options);
  30368. return r1.intersects(r2);
  30369. }
  30370. exports.coerce = coerce;
  30371. function coerce(version) {
  30372. if (version instanceof SemVer) return version;
  30373. if (typeof version !== 'string') return null;
  30374. var match = version.match(re[COERCE]);
  30375. if (match == null) return null;
  30376. return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  30377. }
  30378. });
  30379. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  30380. var pseudomap = PseudoMap;
  30381. function PseudoMap(set) {
  30382. if (!(this instanceof PseudoMap)) // whyyyyyyy
  30383. throw new TypeError("Constructor PseudoMap requires 'new'");
  30384. this.clear();
  30385. if (set) {
  30386. if (set instanceof PseudoMap || typeof Map === 'function' && set instanceof Map) set.forEach(function (value, key) {
  30387. this.set(key, value);
  30388. }, this);else if (Array.isArray(set)) set.forEach(function (kv) {
  30389. this.set(kv[0], kv[1]);
  30390. }, this);else throw new TypeError('invalid argument');
  30391. }
  30392. }
  30393. PseudoMap.prototype.forEach = function (fn, thisp) {
  30394. thisp = thisp || this;
  30395. Object.keys(this._data).forEach(function (k) {
  30396. if (k !== 'size') fn.call(thisp, this._data[k].value, this._data[k].key);
  30397. }, this);
  30398. };
  30399. PseudoMap.prototype.has = function (k) {
  30400. return !!find(this._data, k);
  30401. };
  30402. PseudoMap.prototype.get = function (k) {
  30403. var res = find(this._data, k);
  30404. return res && res.value;
  30405. };
  30406. PseudoMap.prototype.set = function (k, v) {
  30407. set$1(this._data, k, v);
  30408. };
  30409. PseudoMap.prototype.delete = function (k) {
  30410. var res = find(this._data, k);
  30411. if (res) {
  30412. delete this._data[res._index];
  30413. this._data.size--;
  30414. }
  30415. };
  30416. PseudoMap.prototype.clear = function () {
  30417. var data = Object.create(null);
  30418. data.size = 0;
  30419. Object.defineProperty(this, '_data', {
  30420. value: data,
  30421. enumerable: false,
  30422. configurable: true,
  30423. writable: false
  30424. });
  30425. };
  30426. Object.defineProperty(PseudoMap.prototype, 'size', {
  30427. get: function get() {
  30428. return this._data.size;
  30429. },
  30430. set: function set(n) {},
  30431. enumerable: true,
  30432. configurable: true
  30433. });
  30434. PseudoMap.prototype.values = PseudoMap.prototype.keys = PseudoMap.prototype.entries = function () {
  30435. throw new Error('iterators are not implemented in this version');
  30436. }; // Either identical, or both NaN
  30437. function same(a, b) {
  30438. return a === b || a !== a && b !== b;
  30439. }
  30440. function Entry$1(k, v, i) {
  30441. this.key = k;
  30442. this.value = v;
  30443. this._index = i;
  30444. }
  30445. function find(data, k) {
  30446. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  30447. if (same(data[key].key, k)) return data[key];
  30448. }
  30449. }
  30450. function set$1(data, k, v) {
  30451. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  30452. if (same(data[key].key, k)) {
  30453. data[key].value = v;
  30454. return;
  30455. }
  30456. }
  30457. data.size++;
  30458. data[key] = new Entry$1(k, v, key);
  30459. }
  30460. var map$1 = createCommonjsModule(function (module) {
  30461. if (process.env.npm_package_name === 'pseudomap' && process.env.npm_lifecycle_script === 'test') process.env.TEST_PSEUDOMAP = 'true';
  30462. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  30463. module.exports = Map;
  30464. } else {
  30465. module.exports = pseudomap;
  30466. }
  30467. });
  30468. var yallist = Yallist;
  30469. Yallist.Node = Node;
  30470. Yallist.create = Yallist;
  30471. function Yallist(list) {
  30472. var self = this;
  30473. if (!(self instanceof Yallist)) {
  30474. self = new Yallist();
  30475. }
  30476. self.tail = null;
  30477. self.head = null;
  30478. self.length = 0;
  30479. if (list && typeof list.forEach === 'function') {
  30480. list.forEach(function (item) {
  30481. self.push(item);
  30482. });
  30483. } else if (arguments.length > 0) {
  30484. for (var i = 0, l = arguments.length; i < l; i++) {
  30485. self.push(arguments[i]);
  30486. }
  30487. }
  30488. return self;
  30489. }
  30490. Yallist.prototype.removeNode = function (node) {
  30491. if (node.list !== this) {
  30492. throw new Error('removing node which does not belong to this list');
  30493. }
  30494. var next = node.next;
  30495. var prev = node.prev;
  30496. if (next) {
  30497. next.prev = prev;
  30498. }
  30499. if (prev) {
  30500. prev.next = next;
  30501. }
  30502. if (node === this.head) {
  30503. this.head = next;
  30504. }
  30505. if (node === this.tail) {
  30506. this.tail = prev;
  30507. }
  30508. node.list.length--;
  30509. node.next = null;
  30510. node.prev = null;
  30511. node.list = null;
  30512. };
  30513. Yallist.prototype.unshiftNode = function (node) {
  30514. if (node === this.head) {
  30515. return;
  30516. }
  30517. if (node.list) {
  30518. node.list.removeNode(node);
  30519. }
  30520. var head = this.head;
  30521. node.list = this;
  30522. node.next = head;
  30523. if (head) {
  30524. head.prev = node;
  30525. }
  30526. this.head = node;
  30527. if (!this.tail) {
  30528. this.tail = node;
  30529. }
  30530. this.length++;
  30531. };
  30532. Yallist.prototype.pushNode = function (node) {
  30533. if (node === this.tail) {
  30534. return;
  30535. }
  30536. if (node.list) {
  30537. node.list.removeNode(node);
  30538. }
  30539. var tail = this.tail;
  30540. node.list = this;
  30541. node.prev = tail;
  30542. if (tail) {
  30543. tail.next = node;
  30544. }
  30545. this.tail = node;
  30546. if (!this.head) {
  30547. this.head = node;
  30548. }
  30549. this.length++;
  30550. };
  30551. Yallist.prototype.push = function () {
  30552. for (var i = 0, l = arguments.length; i < l; i++) {
  30553. push(this, arguments[i]);
  30554. }
  30555. return this.length;
  30556. };
  30557. Yallist.prototype.unshift = function () {
  30558. for (var i = 0, l = arguments.length; i < l; i++) {
  30559. unshift(this, arguments[i]);
  30560. }
  30561. return this.length;
  30562. };
  30563. Yallist.prototype.pop = function () {
  30564. if (!this.tail) {
  30565. return undefined;
  30566. }
  30567. var res = this.tail.value;
  30568. this.tail = this.tail.prev;
  30569. if (this.tail) {
  30570. this.tail.next = null;
  30571. } else {
  30572. this.head = null;
  30573. }
  30574. this.length--;
  30575. return res;
  30576. };
  30577. Yallist.prototype.shift = function () {
  30578. if (!this.head) {
  30579. return undefined;
  30580. }
  30581. var res = this.head.value;
  30582. this.head = this.head.next;
  30583. if (this.head) {
  30584. this.head.prev = null;
  30585. } else {
  30586. this.tail = null;
  30587. }
  30588. this.length--;
  30589. return res;
  30590. };
  30591. Yallist.prototype.forEach = function (fn, thisp) {
  30592. thisp = thisp || this;
  30593. for (var walker = this.head, i = 0; walker !== null; i++) {
  30594. fn.call(thisp, walker.value, i, this);
  30595. walker = walker.next;
  30596. }
  30597. };
  30598. Yallist.prototype.forEachReverse = function (fn, thisp) {
  30599. thisp = thisp || this;
  30600. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  30601. fn.call(thisp, walker.value, i, this);
  30602. walker = walker.prev;
  30603. }
  30604. };
  30605. Yallist.prototype.get = function (n) {
  30606. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  30607. // abort out of the list early if we hit a cycle
  30608. walker = walker.next;
  30609. }
  30610. if (i === n && walker !== null) {
  30611. return walker.value;
  30612. }
  30613. };
  30614. Yallist.prototype.getReverse = function (n) {
  30615. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  30616. // abort out of the list early if we hit a cycle
  30617. walker = walker.prev;
  30618. }
  30619. if (i === n && walker !== null) {
  30620. return walker.value;
  30621. }
  30622. };
  30623. Yallist.prototype.map = function (fn, thisp) {
  30624. thisp = thisp || this;
  30625. var res = new Yallist();
  30626. for (var walker = this.head; walker !== null;) {
  30627. res.push(fn.call(thisp, walker.value, this));
  30628. walker = walker.next;
  30629. }
  30630. return res;
  30631. };
  30632. Yallist.prototype.mapReverse = function (fn, thisp) {
  30633. thisp = thisp || this;
  30634. var res = new Yallist();
  30635. for (var walker = this.tail; walker !== null;) {
  30636. res.push(fn.call(thisp, walker.value, this));
  30637. walker = walker.prev;
  30638. }
  30639. return res;
  30640. };
  30641. Yallist.prototype.reduce = function (fn, initial) {
  30642. var acc;
  30643. var walker = this.head;
  30644. if (arguments.length > 1) {
  30645. acc = initial;
  30646. } else if (this.head) {
  30647. walker = this.head.next;
  30648. acc = this.head.value;
  30649. } else {
  30650. throw new TypeError('Reduce of empty list with no initial value');
  30651. }
  30652. for (var i = 0; walker !== null; i++) {
  30653. acc = fn(acc, walker.value, i);
  30654. walker = walker.next;
  30655. }
  30656. return acc;
  30657. };
  30658. Yallist.prototype.reduceReverse = function (fn, initial) {
  30659. var acc;
  30660. var walker = this.tail;
  30661. if (arguments.length > 1) {
  30662. acc = initial;
  30663. } else if (this.tail) {
  30664. walker = this.tail.prev;
  30665. acc = this.tail.value;
  30666. } else {
  30667. throw new TypeError('Reduce of empty list with no initial value');
  30668. }
  30669. for (var i = this.length - 1; walker !== null; i--) {
  30670. acc = fn(acc, walker.value, i);
  30671. walker = walker.prev;
  30672. }
  30673. return acc;
  30674. };
  30675. Yallist.prototype.toArray = function () {
  30676. var arr = new Array(this.length);
  30677. for (var i = 0, walker = this.head; walker !== null; i++) {
  30678. arr[i] = walker.value;
  30679. walker = walker.next;
  30680. }
  30681. return arr;
  30682. };
  30683. Yallist.prototype.toArrayReverse = function () {
  30684. var arr = new Array(this.length);
  30685. for (var i = 0, walker = this.tail; walker !== null; i++) {
  30686. arr[i] = walker.value;
  30687. walker = walker.prev;
  30688. }
  30689. return arr;
  30690. };
  30691. Yallist.prototype.slice = function (from, to) {
  30692. to = to || this.length;
  30693. if (to < 0) {
  30694. to += this.length;
  30695. }
  30696. from = from || 0;
  30697. if (from < 0) {
  30698. from += this.length;
  30699. }
  30700. var ret = new Yallist();
  30701. if (to < from || to < 0) {
  30702. return ret;
  30703. }
  30704. if (from < 0) {
  30705. from = 0;
  30706. }
  30707. if (to > this.length) {
  30708. to = this.length;
  30709. }
  30710. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  30711. walker = walker.next;
  30712. }
  30713. for (; walker !== null && i < to; i++, walker = walker.next) {
  30714. ret.push(walker.value);
  30715. }
  30716. return ret;
  30717. };
  30718. Yallist.prototype.sliceReverse = function (from, to) {
  30719. to = to || this.length;
  30720. if (to < 0) {
  30721. to += this.length;
  30722. }
  30723. from = from || 0;
  30724. if (from < 0) {
  30725. from += this.length;
  30726. }
  30727. var ret = new Yallist();
  30728. if (to < from || to < 0) {
  30729. return ret;
  30730. }
  30731. if (from < 0) {
  30732. from = 0;
  30733. }
  30734. if (to > this.length) {
  30735. to = this.length;
  30736. }
  30737. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  30738. walker = walker.prev;
  30739. }
  30740. for (; walker !== null && i > from; i--, walker = walker.prev) {
  30741. ret.push(walker.value);
  30742. }
  30743. return ret;
  30744. };
  30745. Yallist.prototype.reverse = function () {
  30746. var head = this.head;
  30747. var tail = this.tail;
  30748. for (var walker = head; walker !== null; walker = walker.prev) {
  30749. var p = walker.prev;
  30750. walker.prev = walker.next;
  30751. walker.next = p;
  30752. }
  30753. this.head = tail;
  30754. this.tail = head;
  30755. return this;
  30756. };
  30757. function push(self, item) {
  30758. self.tail = new Node(item, self.tail, null, self);
  30759. if (!self.head) {
  30760. self.head = self.tail;
  30761. }
  30762. self.length++;
  30763. }
  30764. function unshift(self, item) {
  30765. self.head = new Node(item, null, self.head, self);
  30766. if (!self.tail) {
  30767. self.tail = self.head;
  30768. }
  30769. self.length++;
  30770. }
  30771. function Node(value, prev, next, list) {
  30772. if (!(this instanceof Node)) {
  30773. return new Node(value, prev, next, list);
  30774. }
  30775. this.list = list;
  30776. this.value = value;
  30777. if (prev) {
  30778. prev.next = this;
  30779. this.prev = prev;
  30780. } else {
  30781. this.prev = null;
  30782. }
  30783. if (next) {
  30784. next.prev = this;
  30785. this.next = next;
  30786. } else {
  30787. this.next = null;
  30788. }
  30789. }
  30790. var lruCache = LRUCache; // This will be a proper iterable 'Map' in engines that support it,
  30791. // or a fakey-fake PseudoMap in older versions.
  30792. // A linked list to keep track of recently-used-ness
  30793. // use symbols if possible, otherwise just _props
  30794. var hasSymbol = typeof Symbol === 'function';
  30795. var makeSymbol;
  30796. if (hasSymbol) {
  30797. makeSymbol = function makeSymbol(key) {
  30798. return Symbol(key);
  30799. };
  30800. } else {
  30801. makeSymbol = function makeSymbol(key) {
  30802. return '_' + key;
  30803. };
  30804. }
  30805. var MAX = makeSymbol('max');
  30806. var LENGTH = makeSymbol('length');
  30807. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  30808. var ALLOW_STALE = makeSymbol('allowStale');
  30809. var MAX_AGE = makeSymbol('maxAge');
  30810. var DISPOSE = makeSymbol('dispose');
  30811. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  30812. var LRU_LIST = makeSymbol('lruList');
  30813. var CACHE = makeSymbol('cache');
  30814. function naiveLength() {
  30815. return 1;
  30816. } // lruList is a yallist where the head is the youngest
  30817. // item, and the tail is the oldest. the list contains the Hit
  30818. // objects as the entries.
  30819. // Each Hit object has a reference to its Yallist.Node. This
  30820. // never changes.
  30821. //
  30822. // cache is a Map (or PseudoMap) that matches the keys to
  30823. // the Yallist.Node object.
  30824. function LRUCache(options) {
  30825. if (!(this instanceof LRUCache)) {
  30826. return new LRUCache(options);
  30827. }
  30828. if (typeof options === 'number') {
  30829. options = {
  30830. max: options
  30831. };
  30832. }
  30833. if (!options) {
  30834. options = {};
  30835. }
  30836. var max = this[MAX] = options.max; // Kind of weird to have a default max of Infinity, but oh well.
  30837. if (!max || !(typeof max === 'number') || max <= 0) {
  30838. this[MAX] = Infinity;
  30839. }
  30840. var lc = options.length || naiveLength;
  30841. if (typeof lc !== 'function') {
  30842. lc = naiveLength;
  30843. }
  30844. this[LENGTH_CALCULATOR] = lc;
  30845. this[ALLOW_STALE] = options.stale || false;
  30846. this[MAX_AGE] = options.maxAge || 0;
  30847. this[DISPOSE] = options.dispose;
  30848. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  30849. this.reset();
  30850. } // resize the cache when the max changes.
  30851. Object.defineProperty(LRUCache.prototype, 'max', {
  30852. set: function set(mL) {
  30853. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  30854. mL = Infinity;
  30855. }
  30856. this[MAX] = mL;
  30857. trim$2(this);
  30858. },
  30859. get: function get() {
  30860. return this[MAX];
  30861. },
  30862. enumerable: true
  30863. });
  30864. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  30865. set: function set(allowStale) {
  30866. this[ALLOW_STALE] = !!allowStale;
  30867. },
  30868. get: function get() {
  30869. return this[ALLOW_STALE];
  30870. },
  30871. enumerable: true
  30872. });
  30873. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  30874. set: function set(mA) {
  30875. if (!mA || !(typeof mA === 'number') || mA < 0) {
  30876. mA = 0;
  30877. }
  30878. this[MAX_AGE] = mA;
  30879. trim$2(this);
  30880. },
  30881. get: function get() {
  30882. return this[MAX_AGE];
  30883. },
  30884. enumerable: true
  30885. }); // resize the cache when the lengthCalculator changes.
  30886. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  30887. set: function set(lC) {
  30888. if (typeof lC !== 'function') {
  30889. lC = naiveLength;
  30890. }
  30891. if (lC !== this[LENGTH_CALCULATOR]) {
  30892. this[LENGTH_CALCULATOR] = lC;
  30893. this[LENGTH] = 0;
  30894. this[LRU_LIST].forEach(function (hit) {
  30895. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  30896. this[LENGTH] += hit.length;
  30897. }, this);
  30898. }
  30899. trim$2(this);
  30900. },
  30901. get: function get() {
  30902. return this[LENGTH_CALCULATOR];
  30903. },
  30904. enumerable: true
  30905. });
  30906. Object.defineProperty(LRUCache.prototype, 'length', {
  30907. get: function get() {
  30908. return this[LENGTH];
  30909. },
  30910. enumerable: true
  30911. });
  30912. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  30913. get: function get() {
  30914. return this[LRU_LIST].length;
  30915. },
  30916. enumerable: true
  30917. });
  30918. LRUCache.prototype.rforEach = function (fn, thisp) {
  30919. thisp = thisp || this;
  30920. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  30921. var prev = walker.prev;
  30922. forEachStep(this, fn, walker, thisp);
  30923. walker = prev;
  30924. }
  30925. };
  30926. function forEachStep(self, fn, node, thisp) {
  30927. var hit = node.value;
  30928. if (isStale(self, hit)) {
  30929. del$1(self, node);
  30930. if (!self[ALLOW_STALE]) {
  30931. hit = undefined;
  30932. }
  30933. }
  30934. if (hit) {
  30935. fn.call(thisp, hit.value, hit.key, self);
  30936. }
  30937. }
  30938. LRUCache.prototype.forEach = function (fn, thisp) {
  30939. thisp = thisp || this;
  30940. for (var walker = this[LRU_LIST].head; walker !== null;) {
  30941. var next = walker.next;
  30942. forEachStep(this, fn, walker, thisp);
  30943. walker = next;
  30944. }
  30945. };
  30946. LRUCache.prototype.keys = function () {
  30947. return this[LRU_LIST].toArray().map(function (k) {
  30948. return k.key;
  30949. }, this);
  30950. };
  30951. LRUCache.prototype.values = function () {
  30952. return this[LRU_LIST].toArray().map(function (k) {
  30953. return k.value;
  30954. }, this);
  30955. };
  30956. LRUCache.prototype.reset = function () {
  30957. if (this[DISPOSE] && this[LRU_LIST] && this[LRU_LIST].length) {
  30958. this[LRU_LIST].forEach(function (hit) {
  30959. this[DISPOSE](hit.key, hit.value);
  30960. }, this);
  30961. }
  30962. this[CACHE] = new map$1(); // hash of items by key
  30963. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  30964. this[LENGTH] = 0; // length of items in the list
  30965. };
  30966. LRUCache.prototype.dump = function () {
  30967. return this[LRU_LIST].map(function (hit) {
  30968. if (!isStale(this, hit)) {
  30969. return {
  30970. k: hit.key,
  30971. v: hit.value,
  30972. e: hit.now + (hit.maxAge || 0)
  30973. };
  30974. }
  30975. }, this).toArray().filter(function (h) {
  30976. return h;
  30977. });
  30978. };
  30979. LRUCache.prototype.dumpLru = function () {
  30980. return this[LRU_LIST];
  30981. };
  30982. LRUCache.prototype.inspect = function (n, opts) {
  30983. var str = 'LRUCache {';
  30984. var extras = false;
  30985. var as = this[ALLOW_STALE];
  30986. if (as) {
  30987. str += '\n allowStale: true';
  30988. extras = true;
  30989. }
  30990. var max = this[MAX];
  30991. if (max && max !== Infinity) {
  30992. if (extras) {
  30993. str += ',';
  30994. }
  30995. str += '\n max: ' + util.inspect(max, opts);
  30996. extras = true;
  30997. }
  30998. var maxAge = this[MAX_AGE];
  30999. if (maxAge) {
  31000. if (extras) {
  31001. str += ',';
  31002. }
  31003. str += '\n maxAge: ' + util.inspect(maxAge, opts);
  31004. extras = true;
  31005. }
  31006. var lc = this[LENGTH_CALCULATOR];
  31007. if (lc && lc !== naiveLength) {
  31008. if (extras) {
  31009. str += ',';
  31010. }
  31011. str += '\n length: ' + util.inspect(this[LENGTH], opts);
  31012. extras = true;
  31013. }
  31014. var didFirst = false;
  31015. this[LRU_LIST].forEach(function (item) {
  31016. if (didFirst) {
  31017. str += ',\n ';
  31018. } else {
  31019. if (extras) {
  31020. str += ',\n';
  31021. }
  31022. didFirst = true;
  31023. str += '\n ';
  31024. }
  31025. var key = util.inspect(item.key).split('\n').join('\n ');
  31026. var val = {
  31027. value: item.value
  31028. };
  31029. if (item.maxAge !== maxAge) {
  31030. val.maxAge = item.maxAge;
  31031. }
  31032. if (lc !== naiveLength) {
  31033. val.length = item.length;
  31034. }
  31035. if (isStale(this, item)) {
  31036. val.stale = true;
  31037. }
  31038. val = util.inspect(val, opts).split('\n').join('\n ');
  31039. str += key + ' => ' + val;
  31040. });
  31041. if (didFirst || extras) {
  31042. str += '\n';
  31043. }
  31044. str += '}';
  31045. return str;
  31046. };
  31047. LRUCache.prototype.set = function (key, value, maxAge) {
  31048. maxAge = maxAge || this[MAX_AGE];
  31049. var now = maxAge ? Date.now() : 0;
  31050. var len = this[LENGTH_CALCULATOR](value, key);
  31051. if (this[CACHE].has(key)) {
  31052. if (len > this[MAX]) {
  31053. del$1(this, this[CACHE].get(key));
  31054. return false;
  31055. }
  31056. var node = this[CACHE].get(key);
  31057. var item = node.value; // dispose of the old one before overwriting
  31058. // split out into 2 ifs for better coverage tracking
  31059. if (this[DISPOSE]) {
  31060. if (!this[NO_DISPOSE_ON_SET]) {
  31061. this[DISPOSE](key, item.value);
  31062. }
  31063. }
  31064. item.now = now;
  31065. item.maxAge = maxAge;
  31066. item.value = value;
  31067. this[LENGTH] += len - item.length;
  31068. item.length = len;
  31069. this.get(key);
  31070. trim$2(this);
  31071. return true;
  31072. }
  31073. var hit = new Entry(key, value, len, now, maxAge); // oversized objects fall out of cache automatically.
  31074. if (hit.length > this[MAX]) {
  31075. if (this[DISPOSE]) {
  31076. this[DISPOSE](key, value);
  31077. }
  31078. return false;
  31079. }
  31080. this[LENGTH] += hit.length;
  31081. this[LRU_LIST].unshift(hit);
  31082. this[CACHE].set(key, this[LRU_LIST].head);
  31083. trim$2(this);
  31084. return true;
  31085. };
  31086. LRUCache.prototype.has = function (key) {
  31087. if (!this[CACHE].has(key)) return false;
  31088. var hit = this[CACHE].get(key).value;
  31089. if (isStale(this, hit)) {
  31090. return false;
  31091. }
  31092. return true;
  31093. };
  31094. LRUCache.prototype.get = function (key) {
  31095. return get(this, key, true);
  31096. };
  31097. LRUCache.prototype.peek = function (key) {
  31098. return get(this, key, false);
  31099. };
  31100. LRUCache.prototype.pop = function () {
  31101. var node = this[LRU_LIST].tail;
  31102. if (!node) return null;
  31103. del$1(this, node);
  31104. return node.value;
  31105. };
  31106. LRUCache.prototype.del = function (key) {
  31107. del$1(this, this[CACHE].get(key));
  31108. };
  31109. LRUCache.prototype.load = function (arr) {
  31110. // reset the cache
  31111. this.reset();
  31112. var now = Date.now(); // A previous serialized cache has the most recent items first
  31113. for (var l = arr.length - 1; l >= 0; l--) {
  31114. var hit = arr[l];
  31115. var expiresAt = hit.e || 0;
  31116. if (expiresAt === 0) {
  31117. // the item was created without expiration in a non aged cache
  31118. this.set(hit.k, hit.v);
  31119. } else {
  31120. var maxAge = expiresAt - now; // dont add already expired items
  31121. if (maxAge > 0) {
  31122. this.set(hit.k, hit.v, maxAge);
  31123. }
  31124. }
  31125. }
  31126. };
  31127. LRUCache.prototype.prune = function () {
  31128. var self = this;
  31129. this[CACHE].forEach(function (value, key) {
  31130. get(self, key, false);
  31131. });
  31132. };
  31133. function get(self, key, doUse) {
  31134. var node = self[CACHE].get(key);
  31135. if (node) {
  31136. var hit = node.value;
  31137. if (isStale(self, hit)) {
  31138. del$1(self, node);
  31139. if (!self[ALLOW_STALE]) hit = undefined;
  31140. } else {
  31141. if (doUse) {
  31142. self[LRU_LIST].unshiftNode(node);
  31143. }
  31144. }
  31145. if (hit) hit = hit.value;
  31146. }
  31147. return hit;
  31148. }
  31149. function isStale(self, hit) {
  31150. if (!hit || !hit.maxAge && !self[MAX_AGE]) {
  31151. return false;
  31152. }
  31153. var stale = false;
  31154. var diff = Date.now() - hit.now;
  31155. if (hit.maxAge) {
  31156. stale = diff > hit.maxAge;
  31157. } else {
  31158. stale = self[MAX_AGE] && diff > self[MAX_AGE];
  31159. }
  31160. return stale;
  31161. }
  31162. function trim$2(self) {
  31163. if (self[LENGTH] > self[MAX]) {
  31164. for (var walker = self[LRU_LIST].tail; self[LENGTH] > self[MAX] && walker !== null;) {
  31165. // We know that we're about to delete this one, and also
  31166. // what the next least recently used key will be, so just
  31167. // go ahead and set it now.
  31168. var prev = walker.prev;
  31169. del$1(self, walker);
  31170. walker = prev;
  31171. }
  31172. }
  31173. }
  31174. function del$1(self, node) {
  31175. if (node) {
  31176. var hit = node.value;
  31177. if (self[DISPOSE]) {
  31178. self[DISPOSE](hit.key, hit.value);
  31179. }
  31180. self[LENGTH] -= hit.length;
  31181. self[CACHE].delete(hit.key);
  31182. self[LRU_LIST].removeNode(node);
  31183. }
  31184. } // classy, since V8 prefers predictable objects.
  31185. function Entry(key, value, length, now, maxAge) {
  31186. this.key = key;
  31187. this.value = value;
  31188. this.length = length;
  31189. this.now = now;
  31190. this.maxAge = maxAge || 0;
  31191. }
  31192. var sigmund_1 = sigmund;
  31193. function sigmund(subject, maxSessions) {
  31194. maxSessions = maxSessions || 10;
  31195. var notes = [];
  31196. var analysis = '';
  31197. var RE = RegExp;
  31198. function psychoAnalyze(subject, session) {
  31199. if (session > maxSessions) return;
  31200. if (typeof subject === 'function' || typeof subject === 'undefined') {
  31201. return;
  31202. }
  31203. if (typeof subject !== 'object' || !subject || subject instanceof RE) {
  31204. analysis += subject;
  31205. return;
  31206. }
  31207. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  31208. notes.push(subject);
  31209. analysis += '{';
  31210. Object.keys(subject).forEach(function (issue, _, __) {
  31211. // pseudo-private values. skip those.
  31212. if (issue.charAt(0) === '_') return;
  31213. var to = typeof subject[issue];
  31214. if (to === 'function' || to === 'undefined') return;
  31215. analysis += issue;
  31216. psychoAnalyze(subject[issue], session + 1);
  31217. });
  31218. }
  31219. psychoAnalyze(subject, 0);
  31220. return analysis;
  31221. } // vim: set softtabstop=4 shiftwidth=4:
  31222. var fnmatch = createCommonjsModule(function (module, exports) {
  31223. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  31224. var platform = typeof process === "object" ? process.platform : "win32";
  31225. if (module) module.exports = minimatch;else exports.minimatch = minimatch;
  31226. minimatch.Minimatch = Minimatch;
  31227. var cache = minimatch.cache = new lruCache({
  31228. max: 100
  31229. }),
  31230. GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  31231. var qmark = "[^/]" // * => any number of characters
  31232. ,
  31233. star = qmark + "*?" // ** when dots are allowed. Anything goes, except .. and .
  31234. // not (^ or / followed by one or two dots followed by $ or /),
  31235. // followed by anything, any number of times.
  31236. ,
  31237. twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" // not a ^ or / followed by a dot,
  31238. // followed by anything, any number of times.
  31239. ,
  31240. twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" // characters that need to be escaped in RegExp.
  31241. ,
  31242. reSpecials = charSet("().*{}+?[]^$\\!"); // "abc" -> { a:true, b:true, c:true }
  31243. function charSet(s) {
  31244. return s.split("").reduce(function (set, c) {
  31245. set[c] = true;
  31246. return set;
  31247. }, {});
  31248. } // normalizes slashes.
  31249. var slashSplit = /\/+/;
  31250. minimatch.monkeyPatch = monkeyPatch;
  31251. function monkeyPatch() {
  31252. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  31253. var orig = desc.value;
  31254. desc.value = function (p) {
  31255. if (p instanceof Minimatch) return p.match(this);
  31256. return orig.call(this, p);
  31257. };
  31258. Object.defineProperty(String.prototype, desc);
  31259. }
  31260. minimatch.filter = filter;
  31261. function filter(pattern, options) {
  31262. options = options || {};
  31263. return function (p, i, list) {
  31264. return minimatch(p, pattern, options);
  31265. };
  31266. }
  31267. function ext(a, b) {
  31268. a = a || {};
  31269. b = b || {};
  31270. var t = {};
  31271. Object.keys(b).forEach(function (k) {
  31272. t[k] = b[k];
  31273. });
  31274. Object.keys(a).forEach(function (k) {
  31275. t[k] = a[k];
  31276. });
  31277. return t;
  31278. }
  31279. minimatch.defaults = function (def) {
  31280. if (!def || !Object.keys(def).length) return minimatch;
  31281. var orig = minimatch;
  31282. var m = function minimatch(p, pattern, options) {
  31283. return orig.minimatch(p, pattern, ext(def, options));
  31284. };
  31285. m.Minimatch = function Minimatch(pattern, options) {
  31286. return new orig.Minimatch(pattern, ext(def, options));
  31287. };
  31288. return m;
  31289. };
  31290. Minimatch.defaults = function (def) {
  31291. if (!def || !Object.keys(def).length) return Minimatch;
  31292. return minimatch.defaults(def).Minimatch;
  31293. };
  31294. function minimatch(p, pattern, options) {
  31295. if (typeof pattern !== "string") {
  31296. throw new TypeError("glob pattern string required");
  31297. }
  31298. if (!options) options = {}; // shortcut: comments match nothing.
  31299. if (!options.nocomment && pattern.charAt(0) === "#") {
  31300. return false;
  31301. } // "" only matches ""
  31302. if (pattern.trim() === "") return p === "";
  31303. return new Minimatch(pattern, options).match(p);
  31304. }
  31305. function Minimatch(pattern, options) {
  31306. if (!(this instanceof Minimatch)) {
  31307. return new Minimatch(pattern, options, cache);
  31308. }
  31309. if (typeof pattern !== "string") {
  31310. throw new TypeError("glob pattern string required");
  31311. }
  31312. if (!options) options = {}; // windows: need to use /, not \
  31313. // On other platforms, \ is a valid (albeit bad) filename char.
  31314. if (platform === "win32") {
  31315. pattern = pattern.split("\\").join("/");
  31316. } // lru storage.
  31317. // these things aren't particularly big, but walking down the string
  31318. // and turning it into a regexp can get pretty costly.
  31319. var cacheKey = pattern + "\n" + sigmund_1(options);
  31320. var cached = minimatch.cache.get(cacheKey);
  31321. if (cached) return cached;
  31322. minimatch.cache.set(cacheKey, this);
  31323. this.options = options;
  31324. this.set = [];
  31325. this.pattern = pattern;
  31326. this.regexp = null;
  31327. this.negate = false;
  31328. this.comment = false;
  31329. this.empty = false; // make the set of regexps etc.
  31330. this.make();
  31331. }
  31332. Minimatch.prototype.make = make;
  31333. function make() {
  31334. // don't do it more than once.
  31335. if (this._made) return;
  31336. var pattern = this.pattern;
  31337. var options = this.options; // empty patterns and comments match nothing.
  31338. if (!options.nocomment && pattern.charAt(0) === "#") {
  31339. this.comment = true;
  31340. return;
  31341. }
  31342. if (!pattern) {
  31343. this.empty = true;
  31344. return;
  31345. } // step 1: figure out negation, etc.
  31346. this.parseNegate(); // step 2: expand braces
  31347. var set = this.globSet = this.braceExpand();
  31348. 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
  31349. // matching patterns.
  31350. // These will be regexps, except in the case of "**", which is
  31351. // set to the GLOBSTAR object for globstar behavior,
  31352. // and will not contain any / characters
  31353. set = this.globParts = set.map(function (s) {
  31354. return s.split(slashSplit);
  31355. });
  31356. if (options.debug) console.error(this.pattern, set); // glob --> regexps
  31357. set = set.map(function (s, si, set) {
  31358. return s.map(this.parse, this);
  31359. }, this);
  31360. if (options.debug) console.error(this.pattern, set); // filter out everything that didn't compile properly.
  31361. set = set.filter(function (s) {
  31362. return -1 === s.indexOf(false);
  31363. });
  31364. if (options.debug) console.error(this.pattern, set);
  31365. this.set = set;
  31366. }
  31367. Minimatch.prototype.parseNegate = parseNegate;
  31368. function parseNegate() {
  31369. var pattern = this.pattern,
  31370. negate = false,
  31371. options = this.options,
  31372. negateOffset = 0;
  31373. if (options.nonegate) return;
  31374. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === "!"; i++) {
  31375. negate = !negate;
  31376. negateOffset++;
  31377. }
  31378. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  31379. this.negate = negate;
  31380. } // Brace expansion:
  31381. // a{b,c}d -> abd acd
  31382. // a{b,}c -> abc ac
  31383. // a{0..3}d -> a0d a1d a2d a3d
  31384. // a{b,c{d,e}f}g -> abg acdfg acefg
  31385. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  31386. //
  31387. // Invalid sets are not expanded.
  31388. // a{2..}b -> a{2..}b
  31389. // a{b}c -> a{b}c
  31390. minimatch.braceExpand = function (pattern, options) {
  31391. return new Minimatch(pattern, options).braceExpand();
  31392. };
  31393. Minimatch.prototype.braceExpand = braceExpand;
  31394. function braceExpand(pattern, options) {
  31395. options = options || this.options;
  31396. pattern = typeof pattern === "undefined" ? this.pattern : pattern;
  31397. if (typeof pattern === "undefined") {
  31398. throw new Error("undefined pattern");
  31399. }
  31400. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  31401. // shortcut. no need to expand.
  31402. return [pattern];
  31403. }
  31404. var escaping = false; // examples and comments refer to this crazy pattern:
  31405. // a{b,c{d,e},{f,g}h}x{y,z}
  31406. // expected:
  31407. // abxy
  31408. // abxz
  31409. // acdxy
  31410. // acdxz
  31411. // acexy
  31412. // acexz
  31413. // afhxy
  31414. // afhxz
  31415. // aghxy
  31416. // aghxz
  31417. // everything before the first \{ is just a prefix.
  31418. // So, we pluck that off, and work with the rest,
  31419. // and then prepend it to everything we find.
  31420. if (pattern.charAt(0) !== "{") {
  31421. // console.error(pattern)
  31422. var prefix = null;
  31423. for (var i = 0, l = pattern.length; i < l; i++) {
  31424. var c = pattern.charAt(i); // console.error(i, c)
  31425. if (c === "\\") {
  31426. escaping = !escaping;
  31427. } else if (c === "{" && !escaping) {
  31428. prefix = pattern.substr(0, i);
  31429. break;
  31430. }
  31431. } // actually no sets, all { were escaped.
  31432. if (prefix === null) {
  31433. // console.error("no sets")
  31434. return [pattern];
  31435. }
  31436. var tail = braceExpand(pattern.substr(i), options);
  31437. return tail.map(function (t) {
  31438. return prefix + t;
  31439. });
  31440. } // now we have something like:
  31441. // {b,c{d,e},{f,g}h}x{y,z}
  31442. // walk through the set, expanding each part, until
  31443. // the set ends. then, we'll expand the suffix.
  31444. // If the set only has a single member, then'll put the {} back
  31445. // first, handle numeric sets, since they're easier
  31446. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  31447. if (numset) {
  31448. // console.error("numset", numset[1], numset[2])
  31449. var suf = braceExpand(pattern.substr(numset[0].length), options),
  31450. start = +numset[1],
  31451. end = +numset[2],
  31452. inc = start > end ? -1 : 1,
  31453. set = [];
  31454. for (var i = start; i != end + inc; i += inc) {
  31455. // append all the suffixes
  31456. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  31457. set.push(i + suf[ii]);
  31458. }
  31459. }
  31460. return set;
  31461. } // ok, walk through the set
  31462. // We hope, somewhat optimistically, that there
  31463. // will be a } at the end.
  31464. // If the closing brace isn't found, then the pattern is
  31465. // interpreted as braceExpand("\\" + pattern) so that
  31466. // the leading \{ will be interpreted literally.
  31467. var i = 1 // skip the \{
  31468. ,
  31469. depth = 1,
  31470. set = [],
  31471. member = "",
  31472. sawEnd = false,
  31473. escaping = false;
  31474. function addMember() {
  31475. set.push(member);
  31476. member = "";
  31477. } // console.error("Entering for")
  31478. FOR: for (i = 1, l = pattern.length; i < l; i++) {
  31479. var c = pattern.charAt(i); // console.error("", i, c)
  31480. if (escaping) {
  31481. escaping = false;
  31482. member += "\\" + c;
  31483. } else {
  31484. switch (c) {
  31485. case "\\":
  31486. escaping = true;
  31487. continue;
  31488. case "{":
  31489. depth++;
  31490. member += "{";
  31491. continue;
  31492. case "}":
  31493. depth--; // if this closes the actual set, then we're done
  31494. if (depth === 0) {
  31495. addMember(); // pluck off the close-brace
  31496. i++;
  31497. break FOR;
  31498. } else {
  31499. member += c;
  31500. continue;
  31501. }
  31502. case ",":
  31503. if (depth === 1) {
  31504. addMember();
  31505. } else {
  31506. member += c;
  31507. }
  31508. continue;
  31509. default:
  31510. member += c;
  31511. continue;
  31512. } // switch
  31513. } // else
  31514. } // for
  31515. // now we've either finished the set, and the suffix is
  31516. // pattern.substr(i), or we have *not* closed the set,
  31517. // and need to escape the leading brace
  31518. if (depth !== 0) {
  31519. // console.error("didn't close", pattern)
  31520. return braceExpand("\\" + pattern, options);
  31521. } // x{y,z} -> ["xy", "xz"]
  31522. // console.error("set", set)
  31523. // console.error("suffix", pattern.substr(i))
  31524. var suf = braceExpand(pattern.substr(i), options); // ["b", "c{d,e}","{f,g}h"] ->
  31525. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  31526. var addBraces = set.length === 1; // console.error("set pre-expanded", set)
  31527. set = set.map(function (p) {
  31528. return braceExpand(p, options);
  31529. }); // console.error("set expanded", set)
  31530. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  31531. // ["b", "cd", "ce", "fh", "gh"]
  31532. set = set.reduce(function (l, r) {
  31533. return l.concat(r);
  31534. });
  31535. if (addBraces) {
  31536. set = set.map(function (s) {
  31537. return "{" + s + "}";
  31538. });
  31539. } // now attach the suffixes.
  31540. var ret = [];
  31541. for (var i = 0, l = set.length; i < l; i++) {
  31542. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  31543. ret.push(set[i] + suf[ii]);
  31544. }
  31545. }
  31546. return ret;
  31547. } // parse a component of the expanded set.
  31548. // At this point, no pattern may contain "/" in it
  31549. // so we're going to return a 2d array, where each entry is the full
  31550. // pattern, split on '/', and then turned into a regular expression.
  31551. // A regexp is made at the end which joins each array with an
  31552. // escaped /, and another full one which joins each regexp with |.
  31553. //
  31554. // Following the lead of Bash 4.1, note that "**" only has special meaning
  31555. // when it is the *only* thing in a path portion. Otherwise, any series
  31556. // of * is equivalent to a single *. Globstar behavior is enabled by
  31557. // default, and can be disabled by setting options.noglobstar.
  31558. Minimatch.prototype.parse = parse;
  31559. var SUBPARSE = {};
  31560. function parse(pattern, isSub) {
  31561. var options = this.options; // shortcuts
  31562. if (!options.noglobstar && pattern === "**") return GLOBSTAR;
  31563. if (pattern === "") return "";
  31564. var re = "",
  31565. hasMagic = !!options.nocase,
  31566. escaping = false // ? => one single character
  31567. ,
  31568. patternListStack = [],
  31569. plType,
  31570. stateChar,
  31571. inClass = false,
  31572. reClassStart = -1,
  31573. classStart = -1 // . and .. never match anything that doesn't start with .,
  31574. // even when options.dot is set.
  31575. ,
  31576. patternStart = pattern.charAt(0) === "." ? "" // anything
  31577. // not (start or / followed by . or .. followed by / or end)
  31578. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" : "(?!\\.)";
  31579. function clearStateChar() {
  31580. if (stateChar) {
  31581. // we had some state-tracking character
  31582. // that wasn't consumed by this pass.
  31583. switch (stateChar) {
  31584. case "*":
  31585. re += star;
  31586. hasMagic = true;
  31587. break;
  31588. case "?":
  31589. re += qmark;
  31590. hasMagic = true;
  31591. break;
  31592. default:
  31593. re += "\\" + stateChar;
  31594. break;
  31595. }
  31596. stateChar = false;
  31597. }
  31598. }
  31599. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  31600. if (options.debug) {
  31601. console.error("%s\t%s %s %j", pattern, i, re, c);
  31602. } // skip over any that are escaped.
  31603. if (escaping && reSpecials[c]) {
  31604. re += "\\" + c;
  31605. escaping = false;
  31606. continue;
  31607. }
  31608. SWITCH: switch (c) {
  31609. case "/":
  31610. // completely not allowed, even escaped.
  31611. // Should already be path-split by now.
  31612. return false;
  31613. case "\\":
  31614. clearStateChar();
  31615. escaping = true;
  31616. continue;
  31617. // the various stateChar values
  31618. // for the "extglob" stuff.
  31619. case "?":
  31620. case "*":
  31621. case "+":
  31622. case "@":
  31623. case "!":
  31624. if (options.debug) {
  31625. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  31626. } // all of those are literals inside a class, except that
  31627. // the glob [!a] means [^a] in regexp
  31628. if (inClass) {
  31629. if (c === "!" && i === classStart + 1) c = "^";
  31630. re += c;
  31631. continue;
  31632. } // if we already have a stateChar, then it means
  31633. // that there was something like ** or +? in there.
  31634. // Handle the stateChar, then proceed with this one.
  31635. clearStateChar();
  31636. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  31637. // just clear the statechar *now*, rather than even diving into
  31638. // the patternList stuff.
  31639. if (options.noext) clearStateChar();
  31640. continue;
  31641. case "(":
  31642. if (inClass) {
  31643. re += "(";
  31644. continue;
  31645. }
  31646. if (!stateChar) {
  31647. re += "\\(";
  31648. continue;
  31649. }
  31650. plType = stateChar;
  31651. patternListStack.push({
  31652. type: plType,
  31653. start: i - 1,
  31654. reStart: re.length
  31655. }); // negation is (?:(?!js)[^/]*)
  31656. re += stateChar === "!" ? "(?:(?!" : "(?:";
  31657. stateChar = false;
  31658. continue;
  31659. case ")":
  31660. if (inClass || !patternListStack.length) {
  31661. re += "\\)";
  31662. continue;
  31663. }
  31664. hasMagic = true;
  31665. re += ")";
  31666. plType = patternListStack.pop().type; // negation is (?:(?!js)[^/]*)
  31667. // The others are (?:<pattern>)<type>
  31668. switch (plType) {
  31669. case "!":
  31670. re += "[^/]*?)";
  31671. break;
  31672. case "?":
  31673. case "+":
  31674. case "*":
  31675. re += plType;
  31676. case "@":
  31677. break;
  31678. // the default anyway
  31679. }
  31680. continue;
  31681. case "|":
  31682. if (inClass || !patternListStack.length || escaping) {
  31683. re += "\\|";
  31684. escaping = false;
  31685. continue;
  31686. }
  31687. re += "|";
  31688. continue;
  31689. // these are mostly the same in regexp and glob
  31690. case "[":
  31691. // swallow any state-tracking char before the [
  31692. clearStateChar();
  31693. if (inClass) {
  31694. re += "\\" + c;
  31695. continue;
  31696. }
  31697. inClass = true;
  31698. classStart = i;
  31699. reClassStart = re.length;
  31700. re += c;
  31701. continue;
  31702. case "]":
  31703. // a right bracket shall lose its special
  31704. // meaning and represent itself in
  31705. // a bracket expression if it occurs
  31706. // first in the list. -- POSIX.2 2.8.3.2
  31707. if (i === classStart + 1 || !inClass) {
  31708. re += "\\" + c;
  31709. escaping = false;
  31710. continue;
  31711. } // finish up the class.
  31712. hasMagic = true;
  31713. inClass = false;
  31714. re += c;
  31715. continue;
  31716. default:
  31717. // swallow any state char that wasn't consumed
  31718. clearStateChar();
  31719. if (escaping) {
  31720. // no need
  31721. escaping = false;
  31722. } else if (reSpecials[c] && !(c === "^" && inClass)) {
  31723. re += "\\";
  31724. }
  31725. re += c;
  31726. } // switch
  31727. } // for
  31728. // handle the case where we left a class open.
  31729. // "[abc" is valid, equivalent to "\[abc"
  31730. if (inClass) {
  31731. // split where the last [ was, and escape it
  31732. // this is a huge pita. We now have to re-walk
  31733. // the contents of the would-be class to re-translate
  31734. // any characters that were passed through as-is
  31735. var cs = pattern.substr(classStart + 1),
  31736. sp = this.parse(cs, SUBPARSE);
  31737. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  31738. hasMagic = hasMagic || sp[1];
  31739. } // handle the case where we had a +( thing at the *end*
  31740. // of the pattern.
  31741. // each pattern list stack adds 3 chars, and we need to go through
  31742. // and escape any | chars that were passed through as-is for the regexp.
  31743. // Go through and escape them, taking care not to double-escape any
  31744. // | chars that were already escaped.
  31745. var pl;
  31746. while (pl = patternListStack.pop()) {
  31747. var tail = re.slice(pl.reStart + 3); // maybe some even number of \, then maybe 1 \, followed by a |
  31748. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  31749. if (!$2) {
  31750. // the | isn't already escaped, so escape it.
  31751. $2 = "\\";
  31752. } // need to escape all those slashes *again*, without escaping the
  31753. // one that we need for escaping the | character. As it works out,
  31754. // escaping an even number of slashes can be done by simply repeating
  31755. // it exactly after itself. That's why this trick works.
  31756. //
  31757. // I am sorry that you have to see this.
  31758. return $1 + $1 + $2 + "|";
  31759. }); // console.error("tail=%j\n %s", tail, tail)
  31760. var t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
  31761. hasMagic = true;
  31762. re = re.slice(0, pl.reStart) + t + "\\(" + tail;
  31763. } // handle trailing things that only matter at the very end.
  31764. clearStateChar();
  31765. if (escaping) {
  31766. // trailing \\
  31767. re += "\\\\";
  31768. } // only need to apply the nodot start if the re starts with
  31769. // something that could conceivably capture a dot
  31770. var addPatternStart = false;
  31771. switch (re.charAt(0)) {
  31772. case ".":
  31773. case "[":
  31774. case "(":
  31775. addPatternStart = true;
  31776. } // if the re is not "" at this point, then we need to make sure
  31777. // it doesn't match against an empty path part.
  31778. // Otherwise a/* will match a/, which it should not.
  31779. if (re !== "" && hasMagic) re = "(?=.)" + re;
  31780. if (addPatternStart) re = patternStart + re; // parsing just a piece of a larger pattern.
  31781. if (isSub === SUBPARSE) {
  31782. return [re, hasMagic];
  31783. } // skip the regexp for non-magical patterns
  31784. // unescape anything in it, though, so that it'll be
  31785. // an exact match against a file etc.
  31786. if (!hasMagic) {
  31787. return globUnescape(pattern);
  31788. }
  31789. var flags = options.nocase ? "i" : "",
  31790. regExp = new RegExp("^" + re + "$", flags);
  31791. regExp._glob = pattern;
  31792. regExp._src = re;
  31793. return regExp;
  31794. }
  31795. minimatch.makeRe = function (pattern, options) {
  31796. return new Minimatch(pattern, options || {}).makeRe();
  31797. };
  31798. Minimatch.prototype.makeRe = makeRe;
  31799. function makeRe() {
  31800. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  31801. // pattern strings, or "**".
  31802. //
  31803. // It's better to use .match(). This function shouldn't
  31804. // be used, really, but it's pretty convenient sometimes,
  31805. // when you just want to work with a regex.
  31806. var set = this.set;
  31807. if (!set.length) return this.regexp = false;
  31808. var options = this.options;
  31809. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot,
  31810. flags = options.nocase ? "i" : "";
  31811. var re = set.map(function (pattern) {
  31812. return pattern.map(function (p) {
  31813. return p === GLOBSTAR ? twoStar : typeof p === "string" ? regExpEscape(p) : p._src;
  31814. }).join("\\\/");
  31815. }).join("|"); // must match entire pattern
  31816. // ending in a * or ** will make it less strict.
  31817. re = "^(?:" + re + ")$"; // can match anything, as long as it's not this.
  31818. if (this.negate) re = "^(?!" + re + ").*$";
  31819. try {
  31820. return this.regexp = new RegExp(re, flags);
  31821. } catch (ex) {
  31822. return this.regexp = false;
  31823. }
  31824. }
  31825. minimatch.match = function (list, pattern, options) {
  31826. var mm = new Minimatch(pattern, options);
  31827. list = list.filter(function (f) {
  31828. return mm.match(f);
  31829. });
  31830. if (options.nonull && !list.length) {
  31831. list.push(pattern);
  31832. }
  31833. return list;
  31834. };
  31835. Minimatch.prototype.match = match;
  31836. function match(f, partial) {
  31837. // console.error("match", f, this.pattern)
  31838. // short-circuit in the case of busted things.
  31839. // comments, etc.
  31840. if (this.comment) return false;
  31841. if (this.empty) return f === "";
  31842. if (f === "/" && partial) return true;
  31843. var options = this.options; // windows: need to use /, not \
  31844. // On other platforms, \ is a valid (albeit bad) filename char.
  31845. if (platform === "win32") {
  31846. f = f.split("\\").join("/");
  31847. } // treat the test path as a set of pathparts.
  31848. f = f.split(slashSplit);
  31849. if (options.debug) {
  31850. console.error(this.pattern, "split", f);
  31851. } // just ONE of the pattern sets in this.set needs to match
  31852. // in order for it to be valid. If negating, then just one
  31853. // match means that we have failed.
  31854. // Either way, return on the first hit.
  31855. var set = this.set; // console.error(this.pattern, "set", set)
  31856. for (var i = 0, l = set.length; i < l; i++) {
  31857. var pattern = set[i];
  31858. var hit = this.matchOne(f, pattern, partial);
  31859. if (hit) {
  31860. if (options.flipNegate) return true;
  31861. return !this.negate;
  31862. }
  31863. } // didn't get any hits. this is success if it's a negative
  31864. // pattern, failure otherwise.
  31865. if (options.flipNegate) return false;
  31866. return this.negate;
  31867. } // set partial to true to test if, for example,
  31868. // "/a/b" matches the start of "/*/b/*/d"
  31869. // Partial means, if you run out of file before you run
  31870. // out of pattern, then that's fine, as long as all
  31871. // the parts match.
  31872. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  31873. var options = this.options;
  31874. if (options.debug) {
  31875. console.error("matchOne", {
  31876. "this": this,
  31877. file: file,
  31878. pattern: pattern
  31879. });
  31880. }
  31881. if (options.matchBase && pattern.length === 1) {
  31882. file = path.basename(file.join("/")).split("/");
  31883. }
  31884. if (options.debug) {
  31885. console.error("matchOne", file.length, pattern.length);
  31886. }
  31887. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  31888. if (options.debug) {
  31889. console.error("matchOne loop");
  31890. }
  31891. var p = pattern[pi],
  31892. f = file[fi];
  31893. if (options.debug) {
  31894. console.error(pattern, p, f);
  31895. } // should be impossible.
  31896. // some invalid regexp stuff in the set.
  31897. if (p === false) return false;
  31898. if (p === GLOBSTAR) {
  31899. if (options.debug) console.error('GLOBSTAR', [pattern, p, f]); // "**"
  31900. // a/**/b/**/c would match the following:
  31901. // a/b/x/y/z/c
  31902. // a/x/y/z/b/c
  31903. // a/b/x/b/x/c
  31904. // a/b/c
  31905. // To do this, take the rest of the pattern after
  31906. // the **, and see if it would match the file remainder.
  31907. // If so, return success.
  31908. // If not, the ** "swallows" a segment, and try again.
  31909. // This is recursively awful.
  31910. //
  31911. // a/**/b/**/c matching a/b/x/y/z/c
  31912. // - a matches a
  31913. // - doublestar
  31914. // - matchOne(b/x/y/z/c, b/**/c)
  31915. // - b matches b
  31916. // - doublestar
  31917. // - matchOne(x/y/z/c, c) -> no
  31918. // - matchOne(y/z/c, c) -> no
  31919. // - matchOne(z/c, c) -> no
  31920. // - matchOne(c, c) yes, hit
  31921. var fr = fi,
  31922. pr = pi + 1;
  31923. if (pr === pl) {
  31924. if (options.debug) console.error('** at the end'); // a ** at the end will just swallow the rest.
  31925. // We have found a match.
  31926. // however, it will not swallow /.x, unless
  31927. // options.dot is set.
  31928. // . and .. are *never* matched by **, for explosively
  31929. // exponential reasons.
  31930. for (; fi < fl; fi++) {
  31931. if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".") return false;
  31932. }
  31933. return true;
  31934. } // ok, let's see if we can swallow whatever we can.
  31935. WHILE: while (fr < fl) {
  31936. var swallowee = file[fr];
  31937. if (options.debug) {
  31938. console.error('\nglobstar while', file, fr, pattern, pr, swallowee);
  31939. } // XXX remove this slice. Just pass the start index.
  31940. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  31941. if (options.debug) console.error('globstar found match!', fr, fl, swallowee); // found a match.
  31942. return true;
  31943. } else {
  31944. // can't swallow "." or ".." ever.
  31945. // can only swallow ".foo" when explicitly asked.
  31946. if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
  31947. if (options.debug) console.error("dot detected!", file, fr, pattern, pr);
  31948. break WHILE;
  31949. } // ** swallows a segment, and continue.
  31950. if (options.debug) console.error('globstar swallow a segment, and continue');
  31951. fr++;
  31952. }
  31953. } // no match was found.
  31954. // However, in partial mode, we can't say this is necessarily over.
  31955. // If there's more *pattern* left, then
  31956. if (partial) {
  31957. // ran out of file
  31958. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  31959. if (fr === fl) return true;
  31960. }
  31961. return false;
  31962. } // something other than **
  31963. // non-magic patterns just have to match exactly
  31964. // patterns with magic have been turned into regexps.
  31965. var hit;
  31966. if (typeof p === "string") {
  31967. if (options.nocase) {
  31968. hit = f.toLowerCase() === p.toLowerCase();
  31969. } else {
  31970. hit = f === p;
  31971. }
  31972. if (options.debug) {
  31973. console.error("string match", p, f, hit);
  31974. }
  31975. } else {
  31976. hit = f.match(p);
  31977. if (options.debug) {
  31978. console.error("pattern match", p, f, hit);
  31979. }
  31980. }
  31981. if (!hit) return false;
  31982. } // Note: ending in / means that we'll get a final ""
  31983. // at the end of the pattern. This can only match a
  31984. // corresponding "" at the end of the file.
  31985. // If the file ends in /, then it can only match a
  31986. // a pattern that ends in /, unless the pattern just
  31987. // doesn't have any more for it. But, a/b/ should *not*
  31988. // match "a/b/*", even though "" matches against the
  31989. // [^/]*? pattern, except in partial mode, where it might
  31990. // simply not be reached yet.
  31991. // However, a/b/ should still satisfy a/*
  31992. // now either we fell off the end of the pattern, or we're done.
  31993. if (fi === fl && pi === pl) {
  31994. // ran out of pattern and filename at the same time.
  31995. // an exact hit!
  31996. return true;
  31997. } else if (fi === fl) {
  31998. // ran out of file, but still had pattern left.
  31999. // this is ok if we're doing the match as part of
  32000. // a glob fs traversal.
  32001. return partial;
  32002. } else if (pi === pl) {
  32003. // ran out of pattern, still have file left.
  32004. // this is only acceptable if we're on the very last
  32005. // empty segment of a file with a trailing slash.
  32006. // a/* should match a/b/
  32007. var emptyFileEnd = fi === fl - 1 && file[fi] === "";
  32008. return emptyFileEnd;
  32009. } // should be unreachable.
  32010. throw new Error("wtf?");
  32011. }; // replace stuff like \* with *
  32012. function globUnescape(s) {
  32013. return s.replace(/\\(.)/g, "$1");
  32014. }
  32015. function regExpEscape(s) {
  32016. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  32017. }
  32018. });
  32019. var ini = createCommonjsModule(function (module, exports) {
  32020. "use strict"; // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
  32021. var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function (thisArg, _arguments, P, generator) {
  32022. return new (P || (P = Promise))(function (resolve, reject) {
  32023. function fulfilled(value) {
  32024. try {
  32025. step(generator.next(value));
  32026. } catch (e) {
  32027. reject(e);
  32028. }
  32029. }
  32030. function rejected(value) {
  32031. try {
  32032. step(generator["throw"](value));
  32033. } catch (e) {
  32034. reject(e);
  32035. }
  32036. }
  32037. function step(result) {
  32038. result.done ? resolve(result.value) : new P(function (resolve) {
  32039. resolve(result.value);
  32040. }).then(fulfilled, rejected);
  32041. }
  32042. step((generator = generator.apply(thisArg, _arguments || [])).next());
  32043. });
  32044. };
  32045. var __generator = commonjsGlobal && commonjsGlobal.__generator || function (thisArg, body) {
  32046. var _ = {
  32047. label: 0,
  32048. sent: function sent() {
  32049. if (t[0] & 1) throw t[1];
  32050. return t[1];
  32051. },
  32052. trys: [],
  32053. ops: []
  32054. },
  32055. f,
  32056. y,
  32057. t,
  32058. g;
  32059. return g = {
  32060. next: verb(0),
  32061. "throw": verb(1),
  32062. "return": verb(2)
  32063. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  32064. return this;
  32065. }), g;
  32066. function verb(n) {
  32067. return function (v) {
  32068. return step([n, v]);
  32069. };
  32070. }
  32071. function step(op) {
  32072. if (f) throw new TypeError("Generator is already executing.");
  32073. while (_) {
  32074. try {
  32075. 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;
  32076. if (y = 0, t) op = [op[0] & 2, t.value];
  32077. switch (op[0]) {
  32078. case 0:
  32079. case 1:
  32080. t = op;
  32081. break;
  32082. case 4:
  32083. _.label++;
  32084. return {
  32085. value: op[1],
  32086. done: false
  32087. };
  32088. case 5:
  32089. _.label++;
  32090. y = op[1];
  32091. op = [0];
  32092. continue;
  32093. case 7:
  32094. op = _.ops.pop();
  32095. _.trys.pop();
  32096. continue;
  32097. default:
  32098. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  32099. _ = 0;
  32100. continue;
  32101. }
  32102. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  32103. _.label = op[1];
  32104. break;
  32105. }
  32106. if (op[0] === 6 && _.label < t[1]) {
  32107. _.label = t[1];
  32108. t = op;
  32109. break;
  32110. }
  32111. if (t && _.label < t[2]) {
  32112. _.label = t[2];
  32113. _.ops.push(op);
  32114. break;
  32115. }
  32116. if (t[2]) _.ops.pop();
  32117. _.trys.pop();
  32118. continue;
  32119. }
  32120. op = body.call(thisArg, _);
  32121. } catch (e) {
  32122. op = [6, e];
  32123. y = 0;
  32124. } finally {
  32125. f = t = 0;
  32126. }
  32127. }
  32128. if (op[0] & 5) throw op[1];
  32129. return {
  32130. value: op[0] ? op[1] : void 0,
  32131. done: true
  32132. };
  32133. }
  32134. };
  32135. var __importStar = commonjsGlobal && commonjsGlobal.__importStar || function (mod) {
  32136. if (mod && mod.__esModule) return mod;
  32137. var result = {};
  32138. if (mod != null) for (var k in mod) {
  32139. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  32140. }
  32141. result["default"] = mod;
  32142. return result;
  32143. };
  32144. Object.defineProperty(exports, "__esModule", {
  32145. value: true
  32146. });
  32147. var fs$$2 = __importStar(fs);
  32148. /**
  32149. * define the possible values:
  32150. * section: [section]
  32151. * param: key=value
  32152. * comment: ;this is a comment
  32153. */
  32154. var regex = {
  32155. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  32156. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  32157. comment: /^\s*[#;].*$/
  32158. };
  32159. /**
  32160. * Parses an .ini file
  32161. * @param file The location of the .ini file
  32162. */
  32163. function parse(file) {
  32164. return __awaiter(this, void 0, void 0, function () {
  32165. return __generator(this, function (_a) {
  32166. return [2
  32167. /*return*/
  32168. , new Promise(function (resolve, reject) {
  32169. fs$$2.readFile(file, 'utf8', function (err, data) {
  32170. if (err) {
  32171. reject(err);
  32172. return;
  32173. }
  32174. resolve(parseString(data));
  32175. });
  32176. })];
  32177. });
  32178. });
  32179. }
  32180. exports.parse = parse;
  32181. function parseSync(file) {
  32182. return parseString(fs$$2.readFileSync(file, 'utf8'));
  32183. }
  32184. exports.parseSync = parseSync;
  32185. function parseString(data) {
  32186. var sectionBody = {};
  32187. var sectionName = null;
  32188. var value = [[sectionName, sectionBody]];
  32189. var lines = data.split(/\r\n|\r|\n/);
  32190. lines.forEach(function (line) {
  32191. var match;
  32192. if (regex.comment.test(line)) {
  32193. return;
  32194. }
  32195. if (regex.param.test(line)) {
  32196. match = line.match(regex.param);
  32197. sectionBody[match[1]] = match[2];
  32198. } else if (regex.section.test(line)) {
  32199. match = line.match(regex.section);
  32200. sectionName = match[1];
  32201. sectionBody = {};
  32202. value.push([sectionName, sectionBody]);
  32203. }
  32204. });
  32205. return value;
  32206. }
  32207. exports.parseString = parseString;
  32208. });
  32209. unwrapExports(ini);
  32210. var name$17 = "editorconfig";
  32211. var version$3 = "0.15.2";
  32212. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  32213. var keywords = ["editorconfig", "core"];
  32214. var main$1 = "src/index.js";
  32215. var contributors = ["Hong Xu (topbug.net)", "Jed Mao (https://github.com/jedmao/)", "Trey Hunner (http://treyhunner.com)"];
  32216. var directories = {
  32217. "bin": "./bin",
  32218. "lib": "./lib"
  32219. };
  32220. var scripts$1 = {
  32221. "clean": "rimraf dist",
  32222. "prebuild": "npm run clean",
  32223. "build": "tsc",
  32224. "pretest": "npm run lint && npm run build && npm run copy && cmake .",
  32225. "test": "ctest .",
  32226. "pretest:ci": "npm run pretest",
  32227. "test:ci": "ctest -VV --output-on-failure .",
  32228. "lint": "npm run eclint && npm run tslint",
  32229. "eclint": "eclint check --indent_size ignore \"src/**\"",
  32230. "tslint": "tslint --project tsconfig.json --exclude package.json",
  32231. "copy": "cpy .npmignore LICENSE README.md CHANGELOG.md dist && cpy bin/* dist/bin && cpy src/lib/fnmatch*.* dist/src/lib",
  32232. "prepub": "npm run lint && npm run build && npm run copy",
  32233. "pub": "npm publish ./dist"
  32234. };
  32235. var repository$1 = {
  32236. "type": "git",
  32237. "url": "git://github.com/editorconfig/editorconfig-core-js.git"
  32238. };
  32239. var bugs = "https://github.com/editorconfig/editorconfig-core-js/issues";
  32240. var author$1 = "EditorConfig Team";
  32241. var license$1 = "MIT";
  32242. var dependencies$1 = {
  32243. "@types/node": "^10.11.7",
  32244. "@types/semver": "^5.5.0",
  32245. "commander": "^2.19.0",
  32246. "lru-cache": "^4.1.3",
  32247. "semver": "^5.6.0",
  32248. "sigmund": "^1.0.1"
  32249. };
  32250. var devDependencies$1 = {
  32251. "@types/mocha": "^5.2.5",
  32252. "cpy-cli": "^2.0.0",
  32253. "eclint": "^2.8.0",
  32254. "mocha": "^5.2.0",
  32255. "rimraf": "^2.6.2",
  32256. "should": "^13.2.3",
  32257. "tslint": "^5.11.0",
  32258. "typescript": "^3.1.3"
  32259. };
  32260. var _package$2 = {
  32261. name: name$17,
  32262. version: version$3,
  32263. description: description$1,
  32264. keywords: keywords,
  32265. main: main$1,
  32266. contributors: contributors,
  32267. directories: directories,
  32268. scripts: scripts$1,
  32269. repository: repository$1,
  32270. bugs: bugs,
  32271. author: author$1,
  32272. license: license$1,
  32273. dependencies: dependencies$1,
  32274. devDependencies: devDependencies$1
  32275. };
  32276. var _package$3 = Object.freeze({
  32277. name: name$17,
  32278. version: version$3,
  32279. description: description$1,
  32280. keywords: keywords,
  32281. main: main$1,
  32282. contributors: contributors,
  32283. directories: directories,
  32284. scripts: scripts$1,
  32285. repository: repository$1,
  32286. bugs: bugs,
  32287. author: author$1,
  32288. license: license$1,
  32289. dependencies: dependencies$1,
  32290. devDependencies: devDependencies$1,
  32291. default: _package$2
  32292. });
  32293. var require$$4$6 = ( _package$3 && _package$2 ) || _package$3;
  32294. var src$2 = createCommonjsModule(function (module, exports) {
  32295. "use strict";
  32296. var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function (thisArg, _arguments, P, generator) {
  32297. return new (P || (P = Promise))(function (resolve, reject) {
  32298. function fulfilled(value) {
  32299. try {
  32300. step(generator.next(value));
  32301. } catch (e) {
  32302. reject(e);
  32303. }
  32304. }
  32305. function rejected(value) {
  32306. try {
  32307. step(generator["throw"](value));
  32308. } catch (e) {
  32309. reject(e);
  32310. }
  32311. }
  32312. function step(result) {
  32313. result.done ? resolve(result.value) : new P(function (resolve) {
  32314. resolve(result.value);
  32315. }).then(fulfilled, rejected);
  32316. }
  32317. step((generator = generator.apply(thisArg, _arguments || [])).next());
  32318. });
  32319. };
  32320. var __generator = commonjsGlobal && commonjsGlobal.__generator || function (thisArg, body) {
  32321. var _ = {
  32322. label: 0,
  32323. sent: function sent() {
  32324. if (t[0] & 1) throw t[1];
  32325. return t[1];
  32326. },
  32327. trys: [],
  32328. ops: []
  32329. },
  32330. f,
  32331. y,
  32332. t,
  32333. g;
  32334. return g = {
  32335. next: verb(0),
  32336. "throw": verb(1),
  32337. "return": verb(2)
  32338. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  32339. return this;
  32340. }), g;
  32341. function verb(n) {
  32342. return function (v) {
  32343. return step([n, v]);
  32344. };
  32345. }
  32346. function step(op) {
  32347. if (f) throw new TypeError("Generator is already executing.");
  32348. while (_) {
  32349. try {
  32350. 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;
  32351. if (y = 0, t) op = [op[0] & 2, t.value];
  32352. switch (op[0]) {
  32353. case 0:
  32354. case 1:
  32355. t = op;
  32356. break;
  32357. case 4:
  32358. _.label++;
  32359. return {
  32360. value: op[1],
  32361. done: false
  32362. };
  32363. case 5:
  32364. _.label++;
  32365. y = op[1];
  32366. op = [0];
  32367. continue;
  32368. case 7:
  32369. op = _.ops.pop();
  32370. _.trys.pop();
  32371. continue;
  32372. default:
  32373. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  32374. _ = 0;
  32375. continue;
  32376. }
  32377. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  32378. _.label = op[1];
  32379. break;
  32380. }
  32381. if (op[0] === 6 && _.label < t[1]) {
  32382. _.label = t[1];
  32383. t = op;
  32384. break;
  32385. }
  32386. if (t && _.label < t[2]) {
  32387. _.label = t[2];
  32388. _.ops.push(op);
  32389. break;
  32390. }
  32391. if (t[2]) _.ops.pop();
  32392. _.trys.pop();
  32393. continue;
  32394. }
  32395. op = body.call(thisArg, _);
  32396. } catch (e) {
  32397. op = [6, e];
  32398. y = 0;
  32399. } finally {
  32400. f = t = 0;
  32401. }
  32402. }
  32403. if (op[0] & 5) throw op[1];
  32404. return {
  32405. value: op[0] ? op[1] : void 0,
  32406. done: true
  32407. };
  32408. }
  32409. };
  32410. var __importStar = commonjsGlobal && commonjsGlobal.__importStar || function (mod) {
  32411. if (mod && mod.__esModule) return mod;
  32412. var result = {};
  32413. if (mod != null) for (var k in mod) {
  32414. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  32415. }
  32416. result["default"] = mod;
  32417. return result;
  32418. };
  32419. var __importDefault = commonjsGlobal && commonjsGlobal.__importDefault || function (mod) {
  32420. return mod && mod.__esModule ? mod : {
  32421. "default": mod
  32422. };
  32423. };
  32424. Object.defineProperty(exports, "__esModule", {
  32425. value: true
  32426. });
  32427. var fs$$2 = __importStar(fs);
  32428. var path$$2 = __importStar(path);
  32429. var semver = __importStar(semver$3);
  32430. var fnmatch_1 = __importDefault(fnmatch);
  32431. exports.parseString = ini.parseString;
  32432. var package_json_1 = __importDefault(require$$4$6);
  32433. var knownProps = {
  32434. end_of_line: true,
  32435. indent_style: true,
  32436. indent_size: true,
  32437. insert_final_newline: true,
  32438. trim_trailing_whitespace: true,
  32439. charset: true
  32440. };
  32441. function fnmatch$$1(filepath, glob) {
  32442. var matchOptions = {
  32443. matchBase: true,
  32444. dot: true,
  32445. noext: true
  32446. };
  32447. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  32448. return fnmatch_1.default(filepath, glob, matchOptions);
  32449. }
  32450. function getConfigFileNames(filepath, options) {
  32451. var paths = [];
  32452. do {
  32453. filepath = path$$2.dirname(filepath);
  32454. paths.push(path$$2.join(filepath, options.config));
  32455. } while (filepath !== options.root);
  32456. return paths;
  32457. }
  32458. function processMatches(matches, version) {
  32459. // Set indent_size to 'tab' if indent_size is unspecified and
  32460. // indent_style is set to 'tab'.
  32461. if ('indent_style' in matches && matches.indent_style === 'tab' && !('indent_size' in matches) && semver.gte(version, '0.10.0')) {
  32462. matches.indent_size = 'tab';
  32463. } // Set tab_width to indent_size if indent_size is specified and
  32464. // tab_width is unspecified
  32465. if ('indent_size' in matches && !('tab_width' in matches) && matches.indent_size !== 'tab') {
  32466. matches.tab_width = matches.indent_size;
  32467. } // Set indent_size to tab_width if indent_size is 'tab'
  32468. if ('indent_size' in matches && 'tab_width' in matches && matches.indent_size === 'tab') {
  32469. matches.indent_size = matches.tab_width;
  32470. }
  32471. return matches;
  32472. }
  32473. function processOptions(options, filepath) {
  32474. if (options === void 0) {
  32475. options = {};
  32476. }
  32477. return {
  32478. config: options.config || '.editorconfig',
  32479. version: options.version || package_json_1.default.version,
  32480. root: path$$2.resolve(options.root || path$$2.parse(filepath).root)
  32481. };
  32482. }
  32483. function buildFullGlob(pathPrefix, glob) {
  32484. switch (glob.indexOf('/')) {
  32485. case -1:
  32486. glob = '**/' + glob;
  32487. break;
  32488. case 0:
  32489. glob = glob.substring(1);
  32490. break;
  32491. default:
  32492. break;
  32493. }
  32494. return path$$2.join(pathPrefix, glob);
  32495. }
  32496. function extendProps(props, options) {
  32497. if (props === void 0) {
  32498. props = {};
  32499. }
  32500. if (options === void 0) {
  32501. options = {};
  32502. }
  32503. for (var key in options) {
  32504. if (options.hasOwnProperty(key)) {
  32505. var value = options[key];
  32506. var key2 = key.toLowerCase();
  32507. var value2 = value;
  32508. if (knownProps[key2]) {
  32509. value2 = value.toLowerCase();
  32510. }
  32511. try {
  32512. value2 = JSON.parse(value);
  32513. } catch (e) {}
  32514. if (typeof value === 'undefined' || value === null) {
  32515. // null and undefined are values specific to JSON (no special meaning
  32516. // in editorconfig) & should just be returned as regular strings.
  32517. value2 = String(value);
  32518. }
  32519. props[key2] = value2;
  32520. }
  32521. }
  32522. return props;
  32523. }
  32524. function parseFromConfigs(configs, filepath, options) {
  32525. return processMatches(configs.reverse().reduce(function (matches, file) {
  32526. var pathPrefix = path$$2.dirname(file.name);
  32527. file.contents.forEach(function (section) {
  32528. var glob = section[0];
  32529. var options2 = section[1];
  32530. if (!glob) {
  32531. return;
  32532. }
  32533. var fullGlob = buildFullGlob(pathPrefix, glob);
  32534. if (!fnmatch$$1(filepath, fullGlob)) {
  32535. return;
  32536. }
  32537. matches = extendProps(matches, options2);
  32538. });
  32539. return matches;
  32540. }, {}), options.version);
  32541. }
  32542. function getConfigsForFiles(files) {
  32543. var configs = [];
  32544. for (var i in files) {
  32545. if (files.hasOwnProperty(i)) {
  32546. var file = files[i];
  32547. var contents = ini.parseString(file.contents);
  32548. configs.push({
  32549. name: file.name,
  32550. contents: contents
  32551. });
  32552. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  32553. break;
  32554. }
  32555. }
  32556. }
  32557. return configs;
  32558. }
  32559. function readConfigFiles(filepaths) {
  32560. return __awaiter(this, void 0, void 0, function () {
  32561. return __generator(this, function (_a) {
  32562. return [2
  32563. /*return*/
  32564. , Promise.all(filepaths.map(function (name) {
  32565. return new Promise(function (resolve) {
  32566. fs$$2.readFile(name, 'utf8', function (err, data) {
  32567. resolve({
  32568. name: name,
  32569. contents: err ? '' : data
  32570. });
  32571. });
  32572. });
  32573. }))];
  32574. });
  32575. });
  32576. }
  32577. function readConfigFilesSync(filepaths) {
  32578. var files = [];
  32579. var file;
  32580. filepaths.forEach(function (filepath) {
  32581. try {
  32582. file = fs$$2.readFileSync(filepath, 'utf8');
  32583. } catch (e) {
  32584. file = '';
  32585. }
  32586. files.push({
  32587. name: filepath,
  32588. contents: file
  32589. });
  32590. });
  32591. return files;
  32592. }
  32593. function opts(filepath, options) {
  32594. if (options === void 0) {
  32595. options = {};
  32596. }
  32597. var resolvedFilePath = path$$2.resolve(filepath);
  32598. return [resolvedFilePath, processOptions(options, resolvedFilePath)];
  32599. }
  32600. function parseFromFiles(filepath, files, options) {
  32601. if (options === void 0) {
  32602. options = {};
  32603. }
  32604. return __awaiter(this, void 0, void 0, function () {
  32605. var _a, resolvedFilePath, processedOptions;
  32606. return __generator(this, function (_b) {
  32607. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  32608. return [2
  32609. /*return*/
  32610. , files.then(getConfigsForFiles).then(function (configs) {
  32611. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  32612. })];
  32613. });
  32614. });
  32615. }
  32616. exports.parseFromFiles = parseFromFiles;
  32617. function parseFromFilesSync(filepath, files, options) {
  32618. if (options === void 0) {
  32619. options = {};
  32620. }
  32621. var _a = opts(filepath, options),
  32622. resolvedFilePath = _a[0],
  32623. processedOptions = _a[1];
  32624. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  32625. }
  32626. exports.parseFromFilesSync = parseFromFilesSync;
  32627. function parse(_filepath, _options) {
  32628. if (_options === void 0) {
  32629. _options = {};
  32630. }
  32631. return __awaiter(this, void 0, void 0, function () {
  32632. var _a, resolvedFilePath, processedOptions, filepaths;
  32633. return __generator(this, function (_b) {
  32634. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  32635. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  32636. return [2
  32637. /*return*/
  32638. , readConfigFiles(filepaths).then(getConfigsForFiles).then(function (configs) {
  32639. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  32640. })];
  32641. });
  32642. });
  32643. }
  32644. exports.parse = parse;
  32645. function parseSync(_filepath, _options) {
  32646. if (_options === void 0) {
  32647. _options = {};
  32648. }
  32649. var _a = opts(_filepath, _options),
  32650. resolvedFilePath = _a[0],
  32651. processedOptions = _a[1];
  32652. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  32653. var files = readConfigFilesSync(filepaths);
  32654. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  32655. }
  32656. exports.parseSync = parseSync;
  32657. });
  32658. unwrapExports(src$2);
  32659. var editorconfigToPrettier = editorConfigToPrettier;
  32660. function removeUnset(editorConfig) {
  32661. var result = {};
  32662. var keys = Object.keys(editorConfig);
  32663. for (var i = 0; i < keys.length; i++) {
  32664. var key = keys[i];
  32665. if (editorConfig[key] === "unset") {
  32666. continue;
  32667. }
  32668. result[key] = editorConfig[key];
  32669. }
  32670. return result;
  32671. }
  32672. function editorConfigToPrettier(editorConfig) {
  32673. if (!editorConfig) {
  32674. return null;
  32675. }
  32676. editorConfig = removeUnset(editorConfig);
  32677. if (Object.keys(editorConfig).length === 0) {
  32678. return null;
  32679. }
  32680. var result = {};
  32681. if (editorConfig.indent_style) {
  32682. result.useTabs = editorConfig.indent_style === "tab";
  32683. }
  32684. if (editorConfig.indent_size === "tab") {
  32685. result.useTabs = true;
  32686. }
  32687. if (result.useTabs && editorConfig.tab_width) {
  32688. result.tabWidth = editorConfig.tab_width;
  32689. } else if (editorConfig.indent_style === "space" && editorConfig.indent_size && editorConfig.indent_size !== "tab") {
  32690. result.tabWidth = editorConfig.indent_size;
  32691. } else if (editorConfig.tab_width !== undefined) {
  32692. result.tabWidth = editorConfig.tab_width;
  32693. }
  32694. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  32695. result.printWidth = editorConfig.max_line_length;
  32696. }
  32697. if (editorConfig.quote_type === "single") {
  32698. result.singleQuote = true;
  32699. } else if (editorConfig.quote_type === "double") {
  32700. result.singleQuote = false;
  32701. }
  32702. if (["cr", "crlf", "lf"].indexOf(editorConfig.end_of_line) !== -1) {
  32703. result.endOfLine = editorConfig.end_of_line;
  32704. }
  32705. return result;
  32706. }
  32707. function markerExists(files, markers) {
  32708. return markers.some(function (marker) {
  32709. return files.some(function (file) {
  32710. return file === marker;
  32711. });
  32712. });
  32713. }
  32714. function traverseFolder(directory, levels, markers) {
  32715. var files = fs.readdirSync(directory);
  32716. if (levels === 0) {
  32717. return null;
  32718. } else if (markerExists(files, markers)) {
  32719. return directory;
  32720. } else {
  32721. return traverseFolder(path.resolve(directory, '..'), levels - 1, markers);
  32722. }
  32723. }
  32724. var findProjectRoot = function findRoot(dir, opts) {
  32725. if (!dir) throw new Error("Directory not defined");
  32726. opts = opts || {};
  32727. var levels = opts.maxDepth || findRoot.MAX_DEPTH;
  32728. var markers = opts.markers || findRoot.MARKERS;
  32729. return traverseFolder(dir, levels, markers);
  32730. };
  32731. var MAX_DEPTH = 9;
  32732. var MARKERS = ['.git', '.hg'];
  32733. findProjectRoot.MAX_DEPTH = MAX_DEPTH;
  32734. findProjectRoot.MARKERS = MARKERS;
  32735. var resolveConfigEditorconfig = createCommonjsModule(function (module) {
  32736. "use strict";
  32737. var maybeParse = function maybeParse(filePath, config, parse) {
  32738. var root = findProjectRoot(path.dirname(path.resolve(filePath)));
  32739. return filePath && parse(filePath, {
  32740. root
  32741. });
  32742. };
  32743. var editorconfigAsyncNoCache = function editorconfigAsyncNoCache(filePath, config) {
  32744. return Promise.resolve(maybeParse(filePath, config, src$2.parse)).then(editorconfigToPrettier);
  32745. };
  32746. var editorconfigAsyncWithCache = mem(editorconfigAsyncNoCache);
  32747. var editorconfigSyncNoCache = function editorconfigSyncNoCache(filePath, config) {
  32748. return editorconfigToPrettier(maybeParse(filePath, config, src$2.parseSync));
  32749. };
  32750. var editorconfigSyncWithCache = mem(editorconfigSyncNoCache);
  32751. function getLoadFunction(opts) {
  32752. if (!opts.editorconfig) {
  32753. return function () {
  32754. return null;
  32755. };
  32756. }
  32757. if (opts.sync) {
  32758. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  32759. }
  32760. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  32761. }
  32762. function clearCache() {
  32763. mem.clear(editorconfigSyncWithCache);
  32764. mem.clear(editorconfigAsyncWithCache);
  32765. }
  32766. module.exports = {
  32767. getLoadFunction,
  32768. clearCache
  32769. };
  32770. });
  32771. var ParserEND = 0x110000;
  32772. var ParserError =
  32773. /*#__PURE__*/
  32774. function (_Error) {
  32775. _inherits(ParserError, _Error);
  32776. /* istanbul ignore next */
  32777. function ParserError(msg, filename, linenumber) {
  32778. var _this;
  32779. _classCallCheck(this, ParserError);
  32780. _this = _possibleConstructorReturn(this, _getPrototypeOf(ParserError).call(this, '[ParserError] ' + msg, filename, linenumber));
  32781. _this.code = 'ParserError';
  32782. if (Error.captureStackTrace) Error.captureStackTrace(_assertThisInitialized(_assertThisInitialized(_this)), ParserError);
  32783. return _this;
  32784. }
  32785. return ParserError;
  32786. }(_wrapNativeSuper(Error));
  32787. var State = function State(parser) {
  32788. _classCallCheck(this, State);
  32789. this.parser = parser;
  32790. this.buf = '';
  32791. this.returned = null;
  32792. this.result = null;
  32793. this.resultTable = null;
  32794. this.resultArr = null;
  32795. };
  32796. var Parser =
  32797. /*#__PURE__*/
  32798. function () {
  32799. function Parser() {
  32800. _classCallCheck(this, Parser);
  32801. this.pos = 0;
  32802. this.col = 0;
  32803. this.line = 0;
  32804. this.obj = {};
  32805. this.ctx = this.obj;
  32806. this.stack = [];
  32807. this._buf = '';
  32808. this.char = null;
  32809. this.ii = 0;
  32810. this.state = new State(this.parseStart);
  32811. }
  32812. _createClass(Parser, [{
  32813. key: "parse",
  32814. value: function parse(str) {
  32815. /* istanbul ignore next */
  32816. if (str.length === 0 || str.length == null) return;
  32817. this._buf = String(str);
  32818. this.ii = -1;
  32819. this.char = -1;
  32820. var getNext;
  32821. while (getNext === false || this.nextChar()) {
  32822. getNext = this.runOne();
  32823. }
  32824. this._buf = null;
  32825. }
  32826. }, {
  32827. key: "nextChar",
  32828. value: function nextChar() {
  32829. if (this.char === 0x0A) {
  32830. ++this.line;
  32831. this.col = -1;
  32832. }
  32833. ++this.ii;
  32834. this.char = this._buf.codePointAt(this.ii);
  32835. ++this.pos;
  32836. ++this.col;
  32837. return this.haveBuffer();
  32838. }
  32839. }, {
  32840. key: "haveBuffer",
  32841. value: function haveBuffer() {
  32842. return this.ii < this._buf.length;
  32843. }
  32844. }, {
  32845. key: "runOne",
  32846. value: function runOne() {
  32847. return this.state.parser.call(this, this.state.returned);
  32848. }
  32849. }, {
  32850. key: "finish",
  32851. value: function finish() {
  32852. this.char = ParserEND;
  32853. var last;
  32854. do {
  32855. last = this.state.parser;
  32856. this.runOne();
  32857. } while (this.state.parser !== last);
  32858. this.ctx = null;
  32859. this.state = null;
  32860. this._buf = null;
  32861. return this.obj;
  32862. }
  32863. }, {
  32864. key: "next",
  32865. value: function next(fn) {
  32866. /* istanbul ignore next */
  32867. if (typeof fn !== 'function') throw new ParserError('Tried to set state to non-existent state: ' + JSON.stringify(fn));
  32868. this.state.parser = fn;
  32869. }
  32870. }, {
  32871. key: "goto",
  32872. value: function goto(fn) {
  32873. this.next(fn);
  32874. return this.runOne();
  32875. }
  32876. }, {
  32877. key: "call",
  32878. value: function call(fn, returnWith) {
  32879. if (returnWith) this.next(returnWith);
  32880. this.stack.push(this.state);
  32881. this.state = new State(fn);
  32882. }
  32883. }, {
  32884. key: "callNow",
  32885. value: function callNow(fn, returnWith) {
  32886. this.call(fn, returnWith);
  32887. return this.runOne();
  32888. }
  32889. }, {
  32890. key: "return",
  32891. value: function _return(value) {
  32892. /* istanbul ignore next */
  32893. if (!this.stack.length) throw this.error(new ParserError('Stack underflow'));
  32894. if (value === undefined) value = this.state.buf;
  32895. this.state = this.stack.pop();
  32896. this.state.returned = value;
  32897. }
  32898. }, {
  32899. key: "returnNow",
  32900. value: function returnNow(value) {
  32901. this.return(value);
  32902. return this.runOne();
  32903. }
  32904. }, {
  32905. key: "consume",
  32906. value: function consume() {
  32907. /* istanbul ignore next */
  32908. if (this.char === ParserEND) throw this.error(new ParserError('Unexpected end-of-buffer'));
  32909. this.state.buf += this._buf[this.ii];
  32910. }
  32911. }, {
  32912. key: "error",
  32913. value: function error(err) {
  32914. err.line = this.line;
  32915. err.col = this.col;
  32916. err.pos = this.pos;
  32917. return err;
  32918. }
  32919. /* istanbul ignore next */
  32920. }, {
  32921. key: "parseStart",
  32922. value: function parseStart() {
  32923. throw new ParserError('Must declare a parseStart method');
  32924. }
  32925. }]);
  32926. return Parser;
  32927. }();
  32928. Parser.END = ParserEND;
  32929. Parser.Error = ParserError;
  32930. var parser$2 = Parser;
  32931. var createDatetime = createCommonjsModule(function (module) {
  32932. 'use strict';
  32933. module.exports = function (value) {
  32934. var date = new Date(value);
  32935. /* istanbul ignore if */
  32936. if (isNaN(date)) {
  32937. throw new TypeError('Invalid Datetime');
  32938. } else {
  32939. return date;
  32940. }
  32941. };
  32942. });
  32943. var formatNum = createCommonjsModule(function (module) {
  32944. 'use strict';
  32945. module.exports = function (d, num) {
  32946. num = String(num);
  32947. while (num.length < d) {
  32948. num = '0' + num;
  32949. }
  32950. return num;
  32951. };
  32952. });
  32953. var createDatetimeFloat = createCommonjsModule(function (module) {
  32954. 'use strict';
  32955. var FloatingDateTime =
  32956. /*#__PURE__*/
  32957. function (_Date) {
  32958. _inherits(FloatingDateTime, _Date);
  32959. function FloatingDateTime(value) {
  32960. var _this;
  32961. _classCallCheck(this, FloatingDateTime);
  32962. _this = _possibleConstructorReturn(this, _getPrototypeOf(FloatingDateTime).call(this, value + 'Z'));
  32963. _this.isFloating = true;
  32964. return _this;
  32965. }
  32966. _createClass(FloatingDateTime, [{
  32967. key: "toISOString",
  32968. value: function toISOString() {
  32969. var date = `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  32970. var time = `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  32971. return `${date}T${time}`;
  32972. }
  32973. }]);
  32974. return FloatingDateTime;
  32975. }(_wrapNativeSuper(Date));
  32976. module.exports = function (value) {
  32977. var date = new FloatingDateTime(value);
  32978. /* istanbul ignore if */
  32979. if (isNaN(date)) {
  32980. throw new TypeError('Invalid Datetime');
  32981. } else {
  32982. return date;
  32983. }
  32984. };
  32985. });
  32986. var createDate = createCommonjsModule(function (module) {
  32987. 'use strict';
  32988. var DateTime = commonjsGlobal.Date;
  32989. var Date =
  32990. /*#__PURE__*/
  32991. function (_DateTime) {
  32992. _inherits(Date, _DateTime);
  32993. function Date(value) {
  32994. var _this;
  32995. _classCallCheck(this, Date);
  32996. _this = _possibleConstructorReturn(this, _getPrototypeOf(Date).call(this, value));
  32997. _this.isDate = true;
  32998. return _this;
  32999. }
  33000. _createClass(Date, [{
  33001. key: "toISOString",
  33002. value: function toISOString() {
  33003. return `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  33004. }
  33005. }]);
  33006. return Date;
  33007. }(DateTime);
  33008. module.exports = function (value) {
  33009. var date = new Date(value);
  33010. /* istanbul ignore if */
  33011. if (isNaN(date)) {
  33012. throw new TypeError('Invalid Datetime');
  33013. } else {
  33014. return date;
  33015. }
  33016. };
  33017. });
  33018. var createTime = createCommonjsModule(function (module) {
  33019. 'use strict';
  33020. var Time =
  33021. /*#__PURE__*/
  33022. function (_Date) {
  33023. _inherits(Time, _Date);
  33024. function Time(value) {
  33025. var _this;
  33026. _classCallCheck(this, Time);
  33027. _this = _possibleConstructorReturn(this, _getPrototypeOf(Time).call(this, `0000-01-01T${value}Z`));
  33028. _this.isTime = true;
  33029. return _this;
  33030. }
  33031. _createClass(Time, [{
  33032. key: "toISOString",
  33033. value: function toISOString() {
  33034. return `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  33035. }
  33036. }]);
  33037. return Time;
  33038. }(_wrapNativeSuper(Date));
  33039. module.exports = function (value) {
  33040. var date = new Time(value);
  33041. /* istanbul ignore if */
  33042. if (isNaN(date)) {
  33043. throw new TypeError('Invalid Datetime');
  33044. } else {
  33045. return date;
  33046. }
  33047. };
  33048. });
  33049. var tomlParser = createCommonjsModule(function (module) {
  33050. 'use strict';
  33051. /* eslint-disable no-new-wrappers, no-eval, camelcase, operator-linebreak */
  33052. module.exports = makeParserClass(parser$2);
  33053. module.exports.makeParserClass = makeParserClass;
  33054. var TomlError =
  33055. /*#__PURE__*/
  33056. function (_Error) {
  33057. _inherits(TomlError, _Error);
  33058. function TomlError(msg) {
  33059. var _this;
  33060. _classCallCheck(this, TomlError);
  33061. _this = _possibleConstructorReturn(this, _getPrototypeOf(TomlError).call(this, msg));
  33062. /* istanbul ignore next */
  33063. if (Error.captureStackTrace) Error.captureStackTrace(_assertThisInitialized(_assertThisInitialized(_this)), TomlError);
  33064. _this.fromTOML = true;
  33065. _this.wrapped = null;
  33066. return _this;
  33067. }
  33068. return TomlError;
  33069. }(_wrapNativeSuper(Error));
  33070. TomlError.wrap = function (err) {
  33071. var terr = new TomlError(err.message);
  33072. terr.code = err.code;
  33073. terr.wrapped = err;
  33074. return terr;
  33075. };
  33076. module.exports.TomlError = TomlError;
  33077. var CTRL_I = 0x09;
  33078. var CTRL_J = 0x0A;
  33079. var CTRL_M = 0x0D;
  33080. var CTRL_CHAR_BOUNDARY = 0x1F; // the last non-character in the latin1 region of unicode, except DEL
  33081. var CHAR_SP = 0x20;
  33082. var CHAR_QUOT = 0x22;
  33083. var CHAR_NUM = 0x23;
  33084. var CHAR_APOS = 0x27;
  33085. var CHAR_PLUS = 0x2B;
  33086. var CHAR_COMMA = 0x2C;
  33087. var CHAR_HYPHEN = 0x2D;
  33088. var CHAR_PERIOD = 0x2E;
  33089. var CHAR_0 = 0x30;
  33090. var CHAR_1 = 0x31;
  33091. var CHAR_7 = 0x37;
  33092. var CHAR_9 = 0x39;
  33093. var CHAR_COLON = 0x3A;
  33094. var CHAR_EQUALS = 0x3D;
  33095. var CHAR_A = 0x41;
  33096. var CHAR_E = 0x45;
  33097. var CHAR_F = 0x46;
  33098. var CHAR_T = 0x54;
  33099. var CHAR_U = 0x55;
  33100. var CHAR_Z = 0x5A;
  33101. var CHAR_LOWBAR = 0x5F;
  33102. var CHAR_a = 0x61;
  33103. var CHAR_b = 0x62;
  33104. var CHAR_e = 0x65;
  33105. var CHAR_f = 0x66;
  33106. var CHAR_i = 0x69;
  33107. var CHAR_l = 0x6C;
  33108. var CHAR_n = 0x6E;
  33109. var CHAR_o = 0x6F;
  33110. var CHAR_r = 0x72;
  33111. var CHAR_s = 0x73;
  33112. var CHAR_t = 0x74;
  33113. var CHAR_u = 0x75;
  33114. var CHAR_x = 0x78;
  33115. var CHAR_z = 0x7A;
  33116. var CHAR_LCUB = 0x7B;
  33117. var CHAR_RCUB = 0x7D;
  33118. var CHAR_LSQB = 0x5B;
  33119. var CHAR_BSOL = 0x5C;
  33120. var CHAR_RSQB = 0x5D;
  33121. var CHAR_DEL = 0x7F;
  33122. var SURROGATE_FIRST = 0xD800;
  33123. var SURROGATE_LAST = 0xDFFF;
  33124. var escapes = {
  33125. [CHAR_b]: '\x08',
  33126. [CHAR_t]: '\x09',
  33127. [CHAR_n]: '\x0a',
  33128. [CHAR_f]: '\x0c',
  33129. [CHAR_r]: '\x0d',
  33130. [CHAR_QUOT]: '\x22',
  33131. [CHAR_BSOL]: '\x5c'
  33132. };
  33133. function isDigit(cp) {
  33134. return cp >= CHAR_0 && cp <= CHAR_9;
  33135. }
  33136. function isHexit(cp) {
  33137. return cp >= CHAR_A && cp <= CHAR_F || cp >= CHAR_a && cp <= CHAR_f || cp >= CHAR_0 && cp <= CHAR_9;
  33138. }
  33139. function isBit(cp) {
  33140. return cp === CHAR_1 || cp === CHAR_0;
  33141. }
  33142. function isOctit(cp) {
  33143. return cp >= CHAR_0 && cp <= CHAR_7;
  33144. }
  33145. function isAlphaNumQuoteHyphen(cp) {
  33146. 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;
  33147. }
  33148. function isAlphaNumHyphen(cp) {
  33149. 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;
  33150. }
  33151. var _type = Symbol('type');
  33152. var _declared = Symbol('declared');
  33153. var INLINE_TABLE = Symbol('inline-table');
  33154. function InlineTable() {
  33155. return Object.defineProperties({}, {
  33156. [_type]: {
  33157. value: INLINE_TABLE
  33158. }
  33159. });
  33160. }
  33161. function isInlineTable(obj) {
  33162. if (obj === null || typeof obj !== 'object') return false;
  33163. return obj[_type] === INLINE_TABLE;
  33164. }
  33165. var TABLE = Symbol('table');
  33166. function Table() {
  33167. return Object.defineProperties({}, {
  33168. [_type]: {
  33169. value: TABLE
  33170. },
  33171. [_declared]: {
  33172. value: false,
  33173. writable: true
  33174. }
  33175. });
  33176. }
  33177. function isTable(obj) {
  33178. if (obj === null || typeof obj !== 'object') return false;
  33179. return obj[_type] === TABLE;
  33180. }
  33181. var _contentType = Symbol('content-type');
  33182. var INLINE_LIST = Symbol('inline-list');
  33183. function InlineList(type) {
  33184. return Object.defineProperties([], {
  33185. [_type]: {
  33186. value: INLINE_LIST
  33187. },
  33188. [_contentType]: {
  33189. value: type
  33190. }
  33191. });
  33192. }
  33193. function isInlineList(obj) {
  33194. if (obj === null || typeof obj !== 'object') return false;
  33195. return obj[_type] === INLINE_LIST;
  33196. }
  33197. var LIST = Symbol('list');
  33198. function List() {
  33199. return Object.defineProperties([], {
  33200. [_type]: {
  33201. value: LIST
  33202. }
  33203. });
  33204. }
  33205. function isList(obj) {
  33206. if (obj === null || typeof obj !== 'object') return false;
  33207. return obj[_type] === LIST;
  33208. } // in an eval, to let bundlers not slurp in a util proxy
  33209. var utilInspect = eval(`require('util').inspect`);
  33210. /* istanbul ignore next */
  33211. var _inspect = utilInspect && utilInspect.custom || 'inspect';
  33212. var BoxedBigInt =
  33213. /*#__PURE__*/
  33214. function () {
  33215. function BoxedBigInt(value) {
  33216. _classCallCheck(this, BoxedBigInt);
  33217. try {
  33218. this.value = commonjsGlobal.BigInt(value);
  33219. } catch (_) {
  33220. /* istanbul ignore next */
  33221. this.value = null;
  33222. }
  33223. Object.defineProperty(this, _type, {
  33224. value: INTEGER
  33225. });
  33226. }
  33227. _createClass(BoxedBigInt, [{
  33228. key: "isNaN",
  33229. value: function isNaN() {
  33230. return this.value === null;
  33231. }
  33232. /* istanbul ignore next */
  33233. }, {
  33234. key: "toString",
  33235. value: function toString() {
  33236. return String(this.value);
  33237. }
  33238. /* istanbul ignore next */
  33239. }, {
  33240. key: _inspect,
  33241. value: function value() {
  33242. return `[BigInt: ${this.toString()}]}`;
  33243. }
  33244. }, {
  33245. key: "valueOf",
  33246. value: function valueOf() {
  33247. return this.value;
  33248. }
  33249. }]);
  33250. return BoxedBigInt;
  33251. }();
  33252. var INTEGER = Symbol('integer');
  33253. function Integer(_value) {
  33254. var num = Number(_value); // -0 is a float thing, not an int thing
  33255. if (Object.is(num, -0)) num = 0;
  33256. /* istanbul ignore else */
  33257. if (commonjsGlobal.BigInt && !Number.isSafeInteger(num)) {
  33258. return new BoxedBigInt(_value);
  33259. } else {
  33260. /* istanbul ignore next */
  33261. return Object.defineProperties(new Number(num), {
  33262. isNaN: {
  33263. value: function value() {
  33264. return isNaN(this);
  33265. }
  33266. },
  33267. [_type]: {
  33268. value: INTEGER
  33269. },
  33270. [_inspect]: {
  33271. value: function value() {
  33272. return `[Integer: ${_value}]`;
  33273. }
  33274. }
  33275. });
  33276. }
  33277. }
  33278. function isInteger(obj) {
  33279. if (obj === null || typeof obj !== 'object') return false;
  33280. return obj[_type] === INTEGER;
  33281. }
  33282. var FLOAT = Symbol('float');
  33283. function Float(_value2) {
  33284. /* istanbul ignore next */
  33285. return Object.defineProperties(new Number(_value2), {
  33286. [_type]: {
  33287. value: FLOAT
  33288. },
  33289. [_inspect]: {
  33290. value: function value() {
  33291. return `[Float: ${_value2}]`;
  33292. }
  33293. }
  33294. });
  33295. }
  33296. function isFloat(obj) {
  33297. if (obj === null || typeof obj !== 'object') return false;
  33298. return obj[_type] === FLOAT;
  33299. }
  33300. function tomlType(value) {
  33301. var type = typeof value;
  33302. if (type === 'object') {
  33303. /* istanbul ignore if */
  33304. if (value === null) return 'null';
  33305. if (value instanceof Date) return 'datetime';
  33306. /* istanbul ignore else */
  33307. if (_type in value) {
  33308. switch (value[_type]) {
  33309. case INLINE_TABLE:
  33310. return 'inline-table';
  33311. case INLINE_LIST:
  33312. return 'inline-list';
  33313. /* istanbul ignore next */
  33314. case TABLE:
  33315. return 'table';
  33316. /* istanbul ignore next */
  33317. case LIST:
  33318. return 'list';
  33319. case FLOAT:
  33320. return 'float';
  33321. case INTEGER:
  33322. return 'integer';
  33323. }
  33324. }
  33325. }
  33326. return type;
  33327. }
  33328. function makeParserClass(Parser) {
  33329. var TOMLParser =
  33330. /*#__PURE__*/
  33331. function (_Parser) {
  33332. _inherits(TOMLParser, _Parser);
  33333. function TOMLParser() {
  33334. var _this2;
  33335. _classCallCheck(this, TOMLParser);
  33336. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(TOMLParser).call(this));
  33337. _this2.ctx = _this2.obj = Table();
  33338. return _this2;
  33339. }
  33340. /* MATCH HELPER */
  33341. _createClass(TOMLParser, [{
  33342. key: "atEndOfWord",
  33343. value: function atEndOfWord() {
  33344. return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine();
  33345. }
  33346. }, {
  33347. key: "atEndOfLine",
  33348. value: function atEndOfLine() {
  33349. return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M;
  33350. }
  33351. }, {
  33352. key: "parseStart",
  33353. value: function parseStart() {
  33354. if (this.char === Parser.END) {
  33355. return null;
  33356. } else if (this.char === CHAR_LSQB) {
  33357. return this.call(this.parseTableOrList);
  33358. } else if (this.char === CHAR_NUM) {
  33359. return this.call(this.parseComment);
  33360. } else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  33361. return null;
  33362. } else if (isAlphaNumQuoteHyphen(this.char)) {
  33363. return this.callNow(this.parseAssignStatement);
  33364. } else {
  33365. throw this.error(new TomlError(`Unknown character "${this.char}"`));
  33366. }
  33367. } // HELPER, this strips any whitespace and comments to the end of the line
  33368. // then RETURNS. Last state in a production.
  33369. }, {
  33370. key: "parseWhitespaceToEOL",
  33371. value: function parseWhitespaceToEOL() {
  33372. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  33373. return null;
  33374. } else if (this.char === CHAR_NUM) {
  33375. return this.goto(this.parseComment);
  33376. } else if (this.char === Parser.END || this.char === CTRL_J) {
  33377. return this.return();
  33378. } else {
  33379. throw this.error(new TomlError('Unexpected character, expected only whitespace or comments till end of line'));
  33380. }
  33381. }
  33382. /* ASSIGNMENT: key = value */
  33383. }, {
  33384. key: "parseAssignStatement",
  33385. value: function parseAssignStatement() {
  33386. return this.callNow(this.parseAssign, this.recordAssignStatement);
  33387. }
  33388. }, {
  33389. key: "recordAssignStatement",
  33390. value: function recordAssignStatement(kv) {
  33391. var target = this.ctx;
  33392. var finalKey = kv.key.pop();
  33393. var _iteratorNormalCompletion = true;
  33394. var _didIteratorError = false;
  33395. var _iteratorError = undefined;
  33396. try {
  33397. for (var _iterator = kv.key[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  33398. var kw = _step.value;
  33399. if (kw in target && (!isTable(target[kw]) || target[kw][_declared])) {
  33400. throw this.error(new TomlError("Can't redefine existing key"));
  33401. }
  33402. target = target[kw] = target[kw] || Table();
  33403. }
  33404. } catch (err) {
  33405. _didIteratorError = true;
  33406. _iteratorError = err;
  33407. } finally {
  33408. try {
  33409. if (!_iteratorNormalCompletion && _iterator.return != null) {
  33410. _iterator.return();
  33411. }
  33412. } finally {
  33413. if (_didIteratorError) {
  33414. throw _iteratorError;
  33415. }
  33416. }
  33417. }
  33418. if (finalKey in target) {
  33419. throw this.error(new TomlError("Can't redefine existing key"));
  33420. } // unbox our numbers
  33421. if (isInteger(kv.value) || isFloat(kv.value)) {
  33422. target[finalKey] = kv.value.valueOf();
  33423. } else {
  33424. target[finalKey] = kv.value;
  33425. }
  33426. return this.goto(this.parseWhitespaceToEOL);
  33427. }
  33428. /* ASSSIGNMENT expression, key = value possibly inside an inline table */
  33429. }, {
  33430. key: "parseAssign",
  33431. value: function parseAssign() {
  33432. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  33433. }
  33434. }, {
  33435. key: "recordAssignKeyword",
  33436. value: function recordAssignKeyword(key) {
  33437. if (this.state.resultTable) {
  33438. this.state.resultTable.push(key);
  33439. } else {
  33440. this.state.resultTable = [key];
  33441. }
  33442. return this.goto(this.parseAssignKeywordPreDot);
  33443. }
  33444. }, {
  33445. key: "parseAssignKeywordPreDot",
  33446. value: function parseAssignKeywordPreDot() {
  33447. if (this.char === CHAR_PERIOD) {
  33448. return this.next(this.parseAssignKeywordPostDot);
  33449. } else if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  33450. return this.goto(this.parseAssignEqual);
  33451. }
  33452. }
  33453. }, {
  33454. key: "parseAssignKeywordPostDot",
  33455. value: function parseAssignKeywordPostDot() {
  33456. if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  33457. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  33458. }
  33459. }
  33460. }, {
  33461. key: "parseAssignEqual",
  33462. value: function parseAssignEqual() {
  33463. if (this.char === CHAR_EQUALS) {
  33464. return this.next(this.parseAssignPreValue);
  33465. } else {
  33466. throw this.error(new TomlError('Invalid character, expected "="'));
  33467. }
  33468. }
  33469. }, {
  33470. key: "parseAssignPreValue",
  33471. value: function parseAssignPreValue() {
  33472. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33473. return null;
  33474. } else {
  33475. return this.callNow(this.parseValue, this.recordAssignValue);
  33476. }
  33477. }
  33478. }, {
  33479. key: "recordAssignValue",
  33480. value: function recordAssignValue(value) {
  33481. return this.returnNow({
  33482. key: this.state.resultTable,
  33483. value: value
  33484. });
  33485. }
  33486. /* COMMENTS: #...eol */
  33487. }, {
  33488. key: "parseComment",
  33489. value: function parseComment() {
  33490. do {
  33491. if (this.char === Parser.END || this.char === CTRL_J) {
  33492. return this.return();
  33493. }
  33494. } while (this.nextChar());
  33495. }
  33496. /* TABLES AND LISTS, [foo] and [[foo]] */
  33497. }, {
  33498. key: "parseTableOrList",
  33499. value: function parseTableOrList() {
  33500. if (this.char === CHAR_LSQB) {
  33501. this.next(this.parseList);
  33502. } else {
  33503. return this.goto(this.parseTable);
  33504. }
  33505. }
  33506. /* TABLE [foo.bar.baz] */
  33507. }, {
  33508. key: "parseTable",
  33509. value: function parseTable() {
  33510. this.ctx = this.obj;
  33511. return this.goto(this.parseTableNext);
  33512. }
  33513. }, {
  33514. key: "parseTableNext",
  33515. value: function parseTableNext() {
  33516. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33517. return null;
  33518. } else {
  33519. return this.callNow(this.parseKeyword, this.parseTableMore);
  33520. }
  33521. }
  33522. }, {
  33523. key: "parseTableMore",
  33524. value: function parseTableMore(keyword) {
  33525. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33526. return null;
  33527. } else if (this.char === CHAR_RSQB) {
  33528. if (keyword in this.ctx && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) {
  33529. throw this.error(new TomlError("Can't redefine existing key"));
  33530. } else {
  33531. this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table();
  33532. this.ctx[_declared] = true;
  33533. }
  33534. return this.next(this.parseWhitespaceToEOL);
  33535. } else if (this.char === CHAR_PERIOD) {
  33536. if (!(keyword in this.ctx)) {
  33537. this.ctx = this.ctx[keyword] = Table();
  33538. } else if (isTable(this.ctx[keyword])) {
  33539. this.ctx = this.ctx[keyword];
  33540. } else if (isList(this.ctx[keyword])) {
  33541. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  33542. } else {
  33543. throw this.error(new TomlError("Can't redefine existing key"));
  33544. }
  33545. return this.next(this.parseTableNext);
  33546. } else {
  33547. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  33548. }
  33549. }
  33550. /* LIST [[a.b.c]] */
  33551. }, {
  33552. key: "parseList",
  33553. value: function parseList() {
  33554. this.ctx = this.obj;
  33555. return this.goto(this.parseListNext);
  33556. }
  33557. }, {
  33558. key: "parseListNext",
  33559. value: function parseListNext() {
  33560. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33561. return null;
  33562. } else {
  33563. return this.callNow(this.parseKeyword, this.parseListMore);
  33564. }
  33565. }
  33566. }, {
  33567. key: "parseListMore",
  33568. value: function parseListMore(keyword) {
  33569. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33570. return null;
  33571. } else if (this.char === CHAR_RSQB) {
  33572. if (!(keyword in this.ctx)) {
  33573. this.ctx[keyword] = List();
  33574. }
  33575. if (isInlineList(this.ctx[keyword])) {
  33576. throw this.error(new TomlError("Can't extend an inline array"));
  33577. } else if (isList(this.ctx[keyword])) {
  33578. var next = Table();
  33579. this.ctx[keyword].push(next);
  33580. this.ctx = next;
  33581. } else {
  33582. throw this.error(new TomlError("Can't redefine an existing key"));
  33583. }
  33584. return this.next(this.parseListEnd);
  33585. } else if (this.char === CHAR_PERIOD) {
  33586. if (!(keyword in this.ctx)) {
  33587. this.ctx = this.ctx[keyword] = Table();
  33588. } else if (isInlineList(this.ctx[keyword])) {
  33589. throw this.error(new TomlError("Can't extend an inline array"));
  33590. } else if (isInlineTable(this.ctx[keyword])) {
  33591. throw this.error(new TomlError("Can't extend an inline table"));
  33592. } else if (isList(this.ctx[keyword])) {
  33593. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  33594. } else if (isTable(this.ctx[keyword])) {
  33595. this.ctx = this.ctx[keyword];
  33596. } else {
  33597. throw this.error(new TomlError("Can't redefine an existing key"));
  33598. }
  33599. return this.next(this.parseListNext);
  33600. } else {
  33601. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  33602. }
  33603. }
  33604. }, {
  33605. key: "parseListEnd",
  33606. value: function parseListEnd(keyword) {
  33607. if (this.char === CHAR_RSQB) {
  33608. return this.next(this.parseWhitespaceToEOL);
  33609. } else {
  33610. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  33611. }
  33612. }
  33613. /* VALUE string, number, boolean, inline list, inline object */
  33614. }, {
  33615. key: "parseValue",
  33616. value: function parseValue() {
  33617. if (this.char === Parser.END) {
  33618. throw this.error(new TomlError('Key without value'));
  33619. } else if (this.char === CHAR_QUOT) {
  33620. return this.next(this.parseDoubleString);
  33621. }
  33622. if (this.char === CHAR_APOS) {
  33623. return this.next(this.parseSingleString);
  33624. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  33625. return this.goto(this.parseNumberSign);
  33626. } else if (this.char === CHAR_i) {
  33627. return this.next(this.parseInf);
  33628. } else if (this.char === CHAR_n) {
  33629. return this.next(this.parseNan);
  33630. } else if (isDigit(this.char)) {
  33631. return this.goto(this.parseNumberOrDateTime);
  33632. } else if (this.char === CHAR_t || this.char === CHAR_f) {
  33633. return this.goto(this.parseBoolean);
  33634. } else if (this.char === CHAR_LSQB) {
  33635. return this.call(this.parseInlineList, this.recordValue);
  33636. } else if (this.char === CHAR_LCUB) {
  33637. return this.call(this.parseInlineTable, this.recordValue);
  33638. } else {
  33639. throw this.error(new TomlError('Unexpected character, expecting string, number, datetime, boolean, inline array or inline table'));
  33640. }
  33641. }
  33642. }, {
  33643. key: "recordValue",
  33644. value: function recordValue(value) {
  33645. return this.returnNow(value);
  33646. }
  33647. }, {
  33648. key: "parseInf",
  33649. value: function parseInf() {
  33650. if (this.char === CHAR_n) {
  33651. return this.next(this.parseInf2);
  33652. } else {
  33653. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  33654. }
  33655. }
  33656. }, {
  33657. key: "parseInf2",
  33658. value: function parseInf2() {
  33659. if (this.char === CHAR_f) {
  33660. if (this.state.buf === '-') {
  33661. return this.return(-Infinity);
  33662. } else {
  33663. return this.return(Infinity);
  33664. }
  33665. } else {
  33666. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  33667. }
  33668. }
  33669. }, {
  33670. key: "parseNan",
  33671. value: function parseNan() {
  33672. if (this.char === CHAR_a) {
  33673. return this.next(this.parseNan2);
  33674. } else {
  33675. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  33676. }
  33677. }
  33678. }, {
  33679. key: "parseNan2",
  33680. value: function parseNan2() {
  33681. if (this.char === CHAR_n) {
  33682. return this.return(NaN);
  33683. } else {
  33684. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  33685. }
  33686. }
  33687. /* KEYS, barewords or basic, literal, or dotted */
  33688. }, {
  33689. key: "parseKeyword",
  33690. value: function parseKeyword() {
  33691. if (this.char === CHAR_QUOT) {
  33692. return this.next(this.parseBasicString);
  33693. } else if (this.char === CHAR_APOS) {
  33694. return this.next(this.parseLiteralString);
  33695. } else {
  33696. return this.goto(this.parseBareKey);
  33697. }
  33698. }
  33699. /* KEYS: barewords */
  33700. }, {
  33701. key: "parseBareKey",
  33702. value: function parseBareKey() {
  33703. do {
  33704. if (this.char === Parser.END) {
  33705. throw this.error(new TomlError('Key ended without value'));
  33706. } else if (isAlphaNumHyphen(this.char)) {
  33707. this.consume();
  33708. } else if (this.state.buf.length === 0) {
  33709. throw this.error(new TomlError('Empty bare keys are not allowed'));
  33710. } else {
  33711. return this.returnNow();
  33712. }
  33713. } while (this.nextChar());
  33714. }
  33715. /* STRINGS, single quoted (literal) */
  33716. }, {
  33717. key: "parseSingleString",
  33718. value: function parseSingleString() {
  33719. if (this.char === CHAR_APOS) {
  33720. return this.next(this.parseLiteralMultiStringMaybe);
  33721. } else {
  33722. return this.goto(this.parseLiteralString);
  33723. }
  33724. }
  33725. }, {
  33726. key: "parseLiteralString",
  33727. value: function parseLiteralString() {
  33728. do {
  33729. if (this.char === CHAR_APOS) {
  33730. return this.return();
  33731. } else if (this.atEndOfLine()) {
  33732. throw this.error(new TomlError('Unterminated string'));
  33733. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  33734. throw this.errorControlCharInString();
  33735. } else {
  33736. this.consume();
  33737. }
  33738. } while (this.nextChar());
  33739. }
  33740. }, {
  33741. key: "parseLiteralMultiStringMaybe",
  33742. value: function parseLiteralMultiStringMaybe() {
  33743. if (this.char === CHAR_APOS) {
  33744. return this.next(this.parseLiteralMultiString);
  33745. } else {
  33746. return this.returnNow();
  33747. }
  33748. }
  33749. }, {
  33750. key: "parseLiteralMultiString",
  33751. value: function parseLiteralMultiString() {
  33752. if (this.char === CTRL_M) {
  33753. return null;
  33754. } else if (this.char === CTRL_J) {
  33755. return this.next(this.parseLiteralMultiStringContent);
  33756. } else {
  33757. return this.goto(this.parseLiteralMultiStringContent);
  33758. }
  33759. }
  33760. }, {
  33761. key: "parseLiteralMultiStringContent",
  33762. value: function parseLiteralMultiStringContent() {
  33763. do {
  33764. if (this.char === CHAR_APOS) {
  33765. return this.next(this.parseLiteralMultiEnd);
  33766. } else if (this.char === Parser.END) {
  33767. throw this.error(new TomlError('Unterminated multi-line string'));
  33768. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  33769. throw this.errorControlCharInString();
  33770. } else {
  33771. this.consume();
  33772. }
  33773. } while (this.nextChar());
  33774. }
  33775. }, {
  33776. key: "parseLiteralMultiEnd",
  33777. value: function parseLiteralMultiEnd() {
  33778. if (this.char === CHAR_APOS) {
  33779. return this.next(this.parseLiteralMultiEnd2);
  33780. } else {
  33781. this.state.buf += "'";
  33782. return this.goto(this.parseLiteralMultiStringContent);
  33783. }
  33784. }
  33785. }, {
  33786. key: "parseLiteralMultiEnd2",
  33787. value: function parseLiteralMultiEnd2() {
  33788. if (this.char === CHAR_APOS) {
  33789. return this.return();
  33790. } else {
  33791. this.state.buf += "''";
  33792. return this.goto(this.parseLiteralMultiStringContent);
  33793. }
  33794. }
  33795. /* STRINGS double quoted */
  33796. }, {
  33797. key: "parseDoubleString",
  33798. value: function parseDoubleString() {
  33799. if (this.char === CHAR_QUOT) {
  33800. return this.next(this.parseMultiStringMaybe);
  33801. } else {
  33802. return this.goto(this.parseBasicString);
  33803. }
  33804. }
  33805. }, {
  33806. key: "parseBasicString",
  33807. value: function parseBasicString() {
  33808. do {
  33809. if (this.char === CHAR_BSOL) {
  33810. return this.call(this.parseEscape, this.recordEscapeReplacement);
  33811. } else if (this.char === CHAR_QUOT) {
  33812. return this.return();
  33813. } else if (this.atEndOfLine()) {
  33814. throw this.error(new TomlError('Unterminated string'));
  33815. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  33816. throw this.errorControlCharInString();
  33817. } else {
  33818. this.consume();
  33819. }
  33820. } while (this.nextChar());
  33821. }
  33822. }, {
  33823. key: "recordEscapeReplacement",
  33824. value: function recordEscapeReplacement(replacement) {
  33825. this.state.buf += replacement;
  33826. return this.goto(this.parseBasicString);
  33827. }
  33828. }, {
  33829. key: "parseMultiStringMaybe",
  33830. value: function parseMultiStringMaybe() {
  33831. if (this.char === CHAR_QUOT) {
  33832. return this.next(this.parseMultiString);
  33833. } else {
  33834. return this.returnNow();
  33835. }
  33836. }
  33837. }, {
  33838. key: "parseMultiString",
  33839. value: function parseMultiString() {
  33840. if (this.char === CTRL_M) {
  33841. return null;
  33842. } else if (this.char === CTRL_J) {
  33843. return this.next(this.parseMultiStringContent);
  33844. } else {
  33845. return this.goto(this.parseMultiStringContent);
  33846. }
  33847. }
  33848. }, {
  33849. key: "parseMultiStringContent",
  33850. value: function parseMultiStringContent() {
  33851. do {
  33852. if (this.char === CHAR_BSOL) {
  33853. return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement);
  33854. } else if (this.char === CHAR_QUOT) {
  33855. return this.next(this.parseMultiEnd);
  33856. } else if (this.char === Parser.END) {
  33857. throw this.error(new TomlError('Unterminated multi-line string'));
  33858. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  33859. throw this.errorControlCharInString();
  33860. } else {
  33861. this.consume();
  33862. }
  33863. } while (this.nextChar());
  33864. }
  33865. }, {
  33866. key: "errorControlCharInString",
  33867. value: function errorControlCharInString() {
  33868. var displayCode = '\\u00';
  33869. if (this.char < 16) {
  33870. displayCode += '0';
  33871. }
  33872. displayCode += this.char.toString(16);
  33873. return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`));
  33874. }
  33875. }, {
  33876. key: "recordMultiEscapeReplacement",
  33877. value: function recordMultiEscapeReplacement(replacement) {
  33878. this.state.buf += replacement;
  33879. return this.goto(this.parseMultiStringContent);
  33880. }
  33881. }, {
  33882. key: "parseMultiEnd",
  33883. value: function parseMultiEnd() {
  33884. if (this.char === CHAR_QUOT) {
  33885. return this.next(this.parseMultiEnd2);
  33886. } else {
  33887. this.state.buf += '"';
  33888. return this.goto(this.parseMultiStringContent);
  33889. }
  33890. }
  33891. }, {
  33892. key: "parseMultiEnd2",
  33893. value: function parseMultiEnd2() {
  33894. if (this.char === CHAR_QUOT) {
  33895. return this.return();
  33896. } else {
  33897. this.state.buf += '""';
  33898. return this.goto(this.parseMultiStringContent);
  33899. }
  33900. }
  33901. }, {
  33902. key: "parseMultiEscape",
  33903. value: function parseMultiEscape() {
  33904. if (this.char === CTRL_M || this.char === CTRL_J) {
  33905. return this.next(this.parseMultiTrim);
  33906. } else if (this.char === CHAR_SP || this.char === CTRL_I) {
  33907. return this.next(this.parsePreMultiTrim);
  33908. } else {
  33909. return this.goto(this.parseEscape);
  33910. }
  33911. }
  33912. }, {
  33913. key: "parsePreMultiTrim",
  33914. value: function parsePreMultiTrim() {
  33915. if (this.char === CHAR_SP || this.char === CTRL_I) {
  33916. return null;
  33917. } else if (this.char === CTRL_M || this.char === CTRL_J) {
  33918. return this.next(this.parseMultiTrim);
  33919. } else {
  33920. throw this.error(new TomlError("Can't escape whitespace"));
  33921. }
  33922. }
  33923. }, {
  33924. key: "parseMultiTrim",
  33925. value: function parseMultiTrim() {
  33926. // explicitly whitespace here, END should follow the same path as chars
  33927. if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  33928. return null;
  33929. } else {
  33930. return this.returnNow();
  33931. }
  33932. }
  33933. }, {
  33934. key: "parseEscape",
  33935. value: function parseEscape() {
  33936. if (this.char in escapes) {
  33937. return this.return(escapes[this.char]);
  33938. } else if (this.char === CHAR_u) {
  33939. return this.call(this.parseSmallUnicode, this.parseUnicodeReturn);
  33940. } else if (this.char === CHAR_U) {
  33941. return this.call(this.parseLargeUnicode, this.parseUnicodeReturn);
  33942. } else {
  33943. throw this.error(new TomlError('Unknown escape character: ' + this.char));
  33944. }
  33945. }
  33946. }, {
  33947. key: "parseUnicodeReturn",
  33948. value: function parseUnicodeReturn(char) {
  33949. try {
  33950. var codePoint = parseInt(char, 16);
  33951. if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) {
  33952. throw this.error(new TomlError('Invalid unicode, character in range 0xD800 - 0xDFFF is reserved'));
  33953. }
  33954. return this.returnNow(String.fromCodePoint(codePoint));
  33955. } catch (ex) {
  33956. throw this.error(TomlError.wrap(ex));
  33957. }
  33958. }
  33959. }, {
  33960. key: "parseSmallUnicode",
  33961. value: function parseSmallUnicode() {
  33962. if (!isHexit(this.char)) {
  33963. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  33964. } else {
  33965. this.consume();
  33966. if (this.state.buf.length >= 4) return this.return();
  33967. }
  33968. }
  33969. }, {
  33970. key: "parseLargeUnicode",
  33971. value: function parseLargeUnicode() {
  33972. if (!isHexit(this.char)) {
  33973. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  33974. } else {
  33975. this.consume();
  33976. if (this.state.buf.length >= 8) return this.return();
  33977. }
  33978. }
  33979. /* NUMBERS */
  33980. }, {
  33981. key: "parseNumberSign",
  33982. value: function parseNumberSign() {
  33983. this.consume();
  33984. return this.next(this.parseMaybeSignedInfOrNan);
  33985. }
  33986. }, {
  33987. key: "parseMaybeSignedInfOrNan",
  33988. value: function parseMaybeSignedInfOrNan() {
  33989. if (this.char === CHAR_i) {
  33990. return this.next(this.parseInf);
  33991. } else if (this.char === CHAR_n) {
  33992. return this.next(this.parseNan);
  33993. } else {
  33994. return this.callNow(this.parseNoUnder, this.parseNumberInteger);
  33995. }
  33996. }
  33997. }, {
  33998. key: "parseNumberInteger",
  33999. value: function parseNumberInteger() {
  34000. if (isDigit(this.char)) {
  34001. this.consume();
  34002. } else if (this.char === CHAR_LOWBAR) {
  34003. return this.call(this.parseNoUnder);
  34004. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  34005. this.consume();
  34006. return this.next(this.parseNumberExponentSign);
  34007. } else if (this.char === CHAR_PERIOD) {
  34008. this.consume();
  34009. return this.call(this.parseNoUnder, this.parseNumberFloat);
  34010. } else {
  34011. var result = Integer(this.state.buf);
  34012. /* istanbul ignore if */
  34013. if (result.isNaN()) {
  34014. throw this.error(new TomlError('Invalid number'));
  34015. } else {
  34016. return this.returnNow(result);
  34017. }
  34018. }
  34019. }
  34020. }, {
  34021. key: "parseNoUnder",
  34022. value: function parseNoUnder() {
  34023. if (this.char === CHAR_LOWBAR) {
  34024. throw this.error(new TomlError('Unexpected character, expected digit, exponent marker(e) or whitespace'));
  34025. } else if (this.atEndOfWord() || this.char === CHAR_E || this.char === CHAR_e) {
  34026. throw this.error(new TomlError('Incomplete number'));
  34027. }
  34028. return this.returnNow();
  34029. }
  34030. }, {
  34031. key: "parseNumberFloat",
  34032. value: function parseNumberFloat() {
  34033. if (this.char === CHAR_LOWBAR) {
  34034. return this.call(this.parseNoUnder, this.parseNumberFloat);
  34035. } else if (isDigit(this.char)) {
  34036. this.consume();
  34037. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  34038. this.consume();
  34039. return this.next(this.parseNumberExponentSign);
  34040. } else {
  34041. return this.returnNow(Float(this.state.buf));
  34042. }
  34043. }
  34044. }, {
  34045. key: "parseNumberExponentSign",
  34046. value: function parseNumberExponentSign() {
  34047. if (isDigit(this.char)) {
  34048. return this.goto(this.parseNumberExponent);
  34049. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  34050. this.consume();
  34051. this.call(this.parseNoUnder, this.parseNumberExponent);
  34052. } else {
  34053. throw this.error(new TomlError('Unexpected character, expected -, + or digit'));
  34054. }
  34055. }
  34056. }, {
  34057. key: "parseNumberExponent",
  34058. value: function parseNumberExponent() {
  34059. if (isDigit(this.char)) {
  34060. this.consume();
  34061. } else if (this.char === CHAR_LOWBAR) {
  34062. return this.call(this.parseNoUnder);
  34063. } else {
  34064. return this.returnNow(Float(this.state.buf));
  34065. }
  34066. }
  34067. /* NUMBERS or DATETIMES */
  34068. }, {
  34069. key: "parseNumberOrDateTime",
  34070. value: function parseNumberOrDateTime() {
  34071. if (this.char === CHAR_0) {
  34072. this.consume();
  34073. return this.next(this.parseNumberBaseOrDateTime);
  34074. } else {
  34075. return this.goto(this.parseNumberOrDateTimeOnly);
  34076. }
  34077. }
  34078. }, {
  34079. key: "parseNumberOrDateTimeOnly",
  34080. value: function parseNumberOrDateTimeOnly() {
  34081. // note, if two zeros are in a row then it MUST be a date
  34082. if (this.char === CHAR_LOWBAR) {
  34083. return this.call(this.parseNoUnder, this.parseNumberInteger);
  34084. } else if (isDigit(this.char)) {
  34085. this.consume();
  34086. if (this.state.buf.length > 4) this.next(this.parseNumberInteger);
  34087. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  34088. this.consume();
  34089. return this.next(this.parseNumberExponentSign);
  34090. } else if (this.char === CHAR_PERIOD) {
  34091. this.consume();
  34092. return this.call(this.parseNoUnder, this.parseNumberFloat);
  34093. } else if (this.char === CHAR_HYPHEN) {
  34094. return this.goto(this.parseDateTime);
  34095. } else if (this.char === CHAR_COLON) {
  34096. return this.goto(this.parseOnlyTimeHour);
  34097. } else {
  34098. return this.returnNow(Integer(this.state.buf));
  34099. }
  34100. }
  34101. }, {
  34102. key: "parseDateTimeOnly",
  34103. value: function parseDateTimeOnly() {
  34104. if (this.state.buf.length < 4) {
  34105. if (isDigit(this.char)) {
  34106. return this.consume();
  34107. } else if (this.char === CHAR_COLON) {
  34108. return this.goto(this.parseOnlyTimeHour);
  34109. } else {
  34110. throw this.error(new TomlError('Expected digit while parsing year part of a date'));
  34111. }
  34112. } else {
  34113. if (this.char === CHAR_HYPHEN) {
  34114. return this.goto(this.parseDateTime);
  34115. } else {
  34116. throw this.error(new TomlError('Expected hyphen (-) while parsing year part of date'));
  34117. }
  34118. }
  34119. }
  34120. }, {
  34121. key: "parseNumberBaseOrDateTime",
  34122. value: function parseNumberBaseOrDateTime() {
  34123. if (this.char === CHAR_b) {
  34124. this.consume();
  34125. return this.call(this.parseNoUnder, this.parseIntegerBin);
  34126. } else if (this.char === CHAR_o) {
  34127. this.consume();
  34128. return this.call(this.parseNoUnder, this.parseIntegerOct);
  34129. } else if (this.char === CHAR_x) {
  34130. this.consume();
  34131. return this.call(this.parseNoUnder, this.parseIntegerHex);
  34132. } else if (this.char === CHAR_PERIOD) {
  34133. return this.goto(this.parseNumberInteger);
  34134. } else if (isDigit(this.char)) {
  34135. return this.goto(this.parseDateTimeOnly);
  34136. } else {
  34137. return this.returnNow(Integer(this.state.buf));
  34138. }
  34139. }
  34140. }, {
  34141. key: "parseIntegerHex",
  34142. value: function parseIntegerHex() {
  34143. if (isHexit(this.char)) {
  34144. this.consume();
  34145. } else if (this.char === CHAR_LOWBAR) {
  34146. return this.call(this.parseNoUnder);
  34147. } else {
  34148. var result = Integer(this.state.buf);
  34149. /* istanbul ignore if */
  34150. if (result.isNaN()) {
  34151. throw this.error(new TomlError('Invalid number'));
  34152. } else {
  34153. return this.returnNow(result);
  34154. }
  34155. }
  34156. }
  34157. }, {
  34158. key: "parseIntegerOct",
  34159. value: function parseIntegerOct() {
  34160. if (isOctit(this.char)) {
  34161. this.consume();
  34162. } else if (this.char === CHAR_LOWBAR) {
  34163. return this.call(this.parseNoUnder);
  34164. } else {
  34165. var result = Integer(this.state.buf);
  34166. /* istanbul ignore if */
  34167. if (result.isNaN()) {
  34168. throw this.error(new TomlError('Invalid number'));
  34169. } else {
  34170. return this.returnNow(result);
  34171. }
  34172. }
  34173. }
  34174. }, {
  34175. key: "parseIntegerBin",
  34176. value: function parseIntegerBin() {
  34177. if (isBit(this.char)) {
  34178. this.consume();
  34179. } else if (this.char === CHAR_LOWBAR) {
  34180. return this.call(this.parseNoUnder);
  34181. } else {
  34182. var result = Integer(this.state.buf);
  34183. /* istanbul ignore if */
  34184. if (result.isNaN()) {
  34185. throw this.error(new TomlError('Invalid number'));
  34186. } else {
  34187. return this.returnNow(result);
  34188. }
  34189. }
  34190. }
  34191. /* DATETIME */
  34192. }, {
  34193. key: "parseDateTime",
  34194. value: function parseDateTime() {
  34195. // we enter here having just consumed the year and about to consume the hyphen
  34196. if (this.state.buf.length < 4) {
  34197. throw this.error(new TomlError('Years less than 1000 must be zero padded to four characters'));
  34198. }
  34199. this.state.result = this.state.buf;
  34200. this.state.buf = '';
  34201. return this.next(this.parseDateMonth);
  34202. }
  34203. }, {
  34204. key: "parseDateMonth",
  34205. value: function parseDateMonth() {
  34206. if (this.char === CHAR_HYPHEN) {
  34207. if (this.state.buf.length < 2) {
  34208. throw this.error(new TomlError('Months less than 10 must be zero padded to two characters'));
  34209. }
  34210. this.state.result += '-' + this.state.buf;
  34211. this.state.buf = '';
  34212. return this.next(this.parseDateDay);
  34213. } else if (isDigit(this.char)) {
  34214. this.consume();
  34215. } else {
  34216. throw this.error(new TomlError('Incomplete datetime'));
  34217. }
  34218. }
  34219. }, {
  34220. key: "parseDateDay",
  34221. value: function parseDateDay() {
  34222. if (this.char === CHAR_T || this.char === CHAR_SP) {
  34223. if (this.state.buf.length < 2) {
  34224. throw this.error(new TomlError('Days less than 10 must be zero padded to two characters'));
  34225. }
  34226. this.state.result += '-' + this.state.buf;
  34227. this.state.buf = '';
  34228. return this.next(this.parseStartTimeHour);
  34229. } else if (this.atEndOfWord()) {
  34230. return this.return(createDate(this.state.result + '-' + this.state.buf));
  34231. } else if (isDigit(this.char)) {
  34232. this.consume();
  34233. } else {
  34234. throw this.error(new TomlError('Incomplete datetime'));
  34235. }
  34236. }
  34237. }, {
  34238. key: "parseStartTimeHour",
  34239. value: function parseStartTimeHour() {
  34240. if (this.atEndOfWord()) {
  34241. return this.returnNow(createDate(this.state.result));
  34242. } else {
  34243. return this.goto(this.parseTimeHour);
  34244. }
  34245. }
  34246. }, {
  34247. key: "parseTimeHour",
  34248. value: function parseTimeHour() {
  34249. if (this.char === CHAR_COLON) {
  34250. if (this.state.buf.length < 2) {
  34251. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  34252. }
  34253. this.state.result += 'T' + this.state.buf;
  34254. this.state.buf = '';
  34255. return this.next(this.parseTimeMin);
  34256. } else if (isDigit(this.char)) {
  34257. this.consume();
  34258. } else {
  34259. throw this.error(new TomlError('Incomplete datetime'));
  34260. }
  34261. }
  34262. }, {
  34263. key: "parseTimeMin",
  34264. value: function parseTimeMin() {
  34265. if (this.state.buf.length < 2 && isDigit(this.char)) {
  34266. this.consume();
  34267. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  34268. this.state.result += ':' + this.state.buf;
  34269. this.state.buf = '';
  34270. return this.next(this.parseTimeSec);
  34271. } else {
  34272. throw this.error(new TomlError('Incomplete datetime'));
  34273. }
  34274. }
  34275. }, {
  34276. key: "parseTimeSec",
  34277. value: function parseTimeSec() {
  34278. if (isDigit(this.char)) {
  34279. this.consume();
  34280. if (this.state.buf.length === 2) {
  34281. this.state.result += ':' + this.state.buf;
  34282. this.state.buf = '';
  34283. return this.next(this.parseTimeZoneOrFraction);
  34284. }
  34285. } else {
  34286. throw this.error(new TomlError('Incomplete datetime'));
  34287. }
  34288. }
  34289. }, {
  34290. key: "parseOnlyTimeHour",
  34291. value: function parseOnlyTimeHour() {
  34292. /* istanbul ignore else */
  34293. if (this.char === CHAR_COLON) {
  34294. if (this.state.buf.length < 2) {
  34295. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  34296. }
  34297. this.state.result = this.state.buf;
  34298. this.state.buf = '';
  34299. return this.next(this.parseOnlyTimeMin);
  34300. } else {
  34301. throw this.error(new TomlError('Incomplete time'));
  34302. }
  34303. }
  34304. }, {
  34305. key: "parseOnlyTimeMin",
  34306. value: function parseOnlyTimeMin() {
  34307. if (this.state.buf.length < 2 && isDigit(this.char)) {
  34308. this.consume();
  34309. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  34310. this.state.result += ':' + this.state.buf;
  34311. this.state.buf = '';
  34312. return this.next(this.parseOnlyTimeSec);
  34313. } else {
  34314. throw this.error(new TomlError('Incomplete time'));
  34315. }
  34316. }
  34317. }, {
  34318. key: "parseOnlyTimeSec",
  34319. value: function parseOnlyTimeSec() {
  34320. if (isDigit(this.char)) {
  34321. this.consume();
  34322. if (this.state.buf.length === 2) {
  34323. return this.next(this.parseOnlyTimeFractionMaybe);
  34324. }
  34325. } else {
  34326. throw this.error(new TomlError('Incomplete time'));
  34327. }
  34328. }
  34329. }, {
  34330. key: "parseOnlyTimeFractionMaybe",
  34331. value: function parseOnlyTimeFractionMaybe() {
  34332. this.state.result += ':' + this.state.buf;
  34333. if (this.char === CHAR_PERIOD) {
  34334. this.state.buf = '';
  34335. this.next(this.parseOnlyTimeFraction);
  34336. } else {
  34337. return this.return(createTime(this.state.result));
  34338. }
  34339. }
  34340. }, {
  34341. key: "parseOnlyTimeFraction",
  34342. value: function parseOnlyTimeFraction() {
  34343. if (isDigit(this.char)) {
  34344. this.consume();
  34345. } else if (this.atEndOfWord()) {
  34346. if (this.state.buf.length === 0) throw this.error(new TomlError('Expected digit in milliseconds'));
  34347. return this.returnNow(createTime(this.state.result + '.' + this.state.buf));
  34348. } else {
  34349. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  34350. }
  34351. }
  34352. }, {
  34353. key: "parseTimeZoneOrFraction",
  34354. value: function parseTimeZoneOrFraction() {
  34355. if (this.char === CHAR_PERIOD) {
  34356. this.consume();
  34357. this.next(this.parseDateTimeFraction);
  34358. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  34359. this.consume();
  34360. this.next(this.parseTimeZoneHour);
  34361. } else if (this.char === CHAR_Z) {
  34362. this.consume();
  34363. return this.return(createDatetime(this.state.result + this.state.buf));
  34364. } else if (this.atEndOfWord()) {
  34365. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  34366. } else {
  34367. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  34368. }
  34369. }
  34370. }, {
  34371. key: "parseDateTimeFraction",
  34372. value: function parseDateTimeFraction() {
  34373. if (isDigit(this.char)) {
  34374. this.consume();
  34375. } else if (this.state.buf.length === 1) {
  34376. throw this.error(new TomlError('Expected digit in milliseconds'));
  34377. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  34378. this.consume();
  34379. this.next(this.parseTimeZoneHour);
  34380. } else if (this.char === CHAR_Z) {
  34381. this.consume();
  34382. return this.return(createDatetime(this.state.result + this.state.buf));
  34383. } else if (this.atEndOfWord()) {
  34384. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  34385. } else {
  34386. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  34387. }
  34388. }
  34389. }, {
  34390. key: "parseTimeZoneHour",
  34391. value: function parseTimeZoneHour() {
  34392. if (isDigit(this.char)) {
  34393. this.consume(); // FIXME: No more regexps
  34394. if (/\d\d$/.test(this.state.buf)) return this.next(this.parseTimeZoneSep);
  34395. } else {
  34396. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  34397. }
  34398. }
  34399. }, {
  34400. key: "parseTimeZoneSep",
  34401. value: function parseTimeZoneSep() {
  34402. if (this.char === CHAR_COLON) {
  34403. this.consume();
  34404. this.next(this.parseTimeZoneMin);
  34405. } else {
  34406. throw this.error(new TomlError('Unexpected character in datetime, expected colon'));
  34407. }
  34408. }
  34409. }, {
  34410. key: "parseTimeZoneMin",
  34411. value: function parseTimeZoneMin() {
  34412. if (isDigit(this.char)) {
  34413. this.consume();
  34414. if (/\d\d$/.test(this.state.buf)) return this.return(createDatetime(this.state.result + this.state.buf));
  34415. } else {
  34416. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  34417. }
  34418. }
  34419. /* BOOLEAN */
  34420. }, {
  34421. key: "parseBoolean",
  34422. value: function parseBoolean() {
  34423. /* istanbul ignore else */
  34424. if (this.char === CHAR_t) {
  34425. this.consume();
  34426. return this.next(this.parseTrue_r);
  34427. } else if (this.char === CHAR_f) {
  34428. this.consume();
  34429. return this.next(this.parseFalse_a);
  34430. }
  34431. }
  34432. }, {
  34433. key: "parseTrue_r",
  34434. value: function parseTrue_r() {
  34435. if (this.char === CHAR_r) {
  34436. this.consume();
  34437. return this.next(this.parseTrue_u);
  34438. } else {
  34439. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34440. }
  34441. }
  34442. }, {
  34443. key: "parseTrue_u",
  34444. value: function parseTrue_u() {
  34445. if (this.char === CHAR_u) {
  34446. this.consume();
  34447. return this.next(this.parseTrue_e);
  34448. } else {
  34449. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34450. }
  34451. }
  34452. }, {
  34453. key: "parseTrue_e",
  34454. value: function parseTrue_e() {
  34455. if (this.char === CHAR_e) {
  34456. return this.return(true);
  34457. } else {
  34458. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34459. }
  34460. }
  34461. }, {
  34462. key: "parseFalse_a",
  34463. value: function parseFalse_a() {
  34464. if (this.char === CHAR_a) {
  34465. this.consume();
  34466. return this.next(this.parseFalse_l);
  34467. } else {
  34468. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34469. }
  34470. }
  34471. }, {
  34472. key: "parseFalse_l",
  34473. value: function parseFalse_l() {
  34474. if (this.char === CHAR_l) {
  34475. this.consume();
  34476. return this.next(this.parseFalse_s);
  34477. } else {
  34478. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34479. }
  34480. }
  34481. }, {
  34482. key: "parseFalse_s",
  34483. value: function parseFalse_s() {
  34484. if (this.char === CHAR_s) {
  34485. this.consume();
  34486. return this.next(this.parseFalse_e);
  34487. } else {
  34488. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34489. }
  34490. }
  34491. }, {
  34492. key: "parseFalse_e",
  34493. value: function parseFalse_e() {
  34494. if (this.char === CHAR_e) {
  34495. return this.return(false);
  34496. } else {
  34497. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  34498. }
  34499. }
  34500. /* INLINE LISTS */
  34501. }, {
  34502. key: "parseInlineList",
  34503. value: function parseInlineList() {
  34504. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  34505. return null;
  34506. } else if (this.char === Parser.END) {
  34507. throw this.error(new TomlError('Unterminated inline array'));
  34508. } else if (this.char === CHAR_NUM) {
  34509. return this.call(this.parseComment);
  34510. } else if (this.char === CHAR_RSQB) {
  34511. return this.return(this.state.resultArr || InlineList());
  34512. } else {
  34513. return this.callNow(this.parseValue, this.recordInlineListValue);
  34514. }
  34515. }
  34516. }, {
  34517. key: "recordInlineListValue",
  34518. value: function recordInlineListValue(value) {
  34519. if (this.state.resultArr) {
  34520. var listType = this.state.resultArr[_contentType];
  34521. var valueType = tomlType(value);
  34522. if (listType !== valueType) {
  34523. throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`));
  34524. }
  34525. } else {
  34526. this.state.resultArr = InlineList(tomlType(value));
  34527. }
  34528. if (isFloat(value) || isInteger(value)) {
  34529. // unbox now that we've verified they're ok
  34530. this.state.resultArr.push(value.valueOf());
  34531. } else {
  34532. this.state.resultArr.push(value);
  34533. }
  34534. return this.goto(this.parseInlineListNext);
  34535. }
  34536. }, {
  34537. key: "parseInlineListNext",
  34538. value: function parseInlineListNext() {
  34539. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  34540. return null;
  34541. } else if (this.char === CHAR_NUM) {
  34542. return this.call(this.parseComment);
  34543. } else if (this.char === CHAR_COMMA) {
  34544. return this.next(this.parseInlineList);
  34545. } else if (this.char === CHAR_RSQB) {
  34546. return this.goto(this.parseInlineList);
  34547. } else {
  34548. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  34549. }
  34550. }
  34551. /* INLINE TABLE */
  34552. }, {
  34553. key: "parseInlineTable",
  34554. value: function parseInlineTable() {
  34555. if (this.char === CHAR_SP || this.char === CTRL_I) {
  34556. return null;
  34557. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  34558. throw this.error(new TomlError('Unterminated inline array'));
  34559. } else if (this.char === CHAR_RCUB) {
  34560. return this.return(this.state.resultTable || InlineTable());
  34561. } else {
  34562. if (!this.state.resultTable) this.state.resultTable = InlineTable();
  34563. return this.callNow(this.parseAssign, this.recordInlineTableValue);
  34564. }
  34565. }
  34566. }, {
  34567. key: "recordInlineTableValue",
  34568. value: function recordInlineTableValue(kv) {
  34569. var target = this.state.resultTable;
  34570. var finalKey = kv.key.pop();
  34571. var _iteratorNormalCompletion2 = true;
  34572. var _didIteratorError2 = false;
  34573. var _iteratorError2 = undefined;
  34574. try {
  34575. for (var _iterator2 = kv.key[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  34576. var kw = _step2.value;
  34577. if (kw in target && (!isTable(target[kw]) || target[kw][_declared])) {
  34578. throw this.error(new TomlError("Can't redefine existing key"));
  34579. }
  34580. target = target[kw] = target[kw] || Table();
  34581. }
  34582. } catch (err) {
  34583. _didIteratorError2 = true;
  34584. _iteratorError2 = err;
  34585. } finally {
  34586. try {
  34587. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  34588. _iterator2.return();
  34589. }
  34590. } finally {
  34591. if (_didIteratorError2) {
  34592. throw _iteratorError2;
  34593. }
  34594. }
  34595. }
  34596. if (finalKey in target) {
  34597. throw this.error(new TomlError("Can't redefine existing key"));
  34598. }
  34599. if (isInteger(kv.value) || isFloat(kv.value)) {
  34600. target[finalKey] = kv.value.valueOf();
  34601. } else {
  34602. target[finalKey] = kv.value;
  34603. }
  34604. return this.goto(this.parseInlineTableNext);
  34605. }
  34606. }, {
  34607. key: "parseInlineTableNext",
  34608. value: function parseInlineTableNext() {
  34609. if (this.char === CHAR_SP || this.char === CTRL_I) {
  34610. return null;
  34611. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  34612. throw this.error(new TomlError('Unterminated inline array'));
  34613. } else if (this.char === CHAR_COMMA) {
  34614. return this.next(this.parseInlineTable);
  34615. } else if (this.char === CHAR_RCUB) {
  34616. return this.goto(this.parseInlineTable);
  34617. } else {
  34618. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  34619. }
  34620. }
  34621. }]);
  34622. return TOMLParser;
  34623. }(Parser);
  34624. return TOMLParser;
  34625. }
  34626. });
  34627. var parsePrettyError = prettyError;
  34628. function prettyError(err, buf) {
  34629. /* istanbul ignore if */
  34630. if (err.pos == null || err.line == null) return err;
  34631. var msg = err.message;
  34632. msg += ` at row ${err.line + 1}, col ${err.col + 1}, pos ${err.pos}:\n`;
  34633. /* istanbul ignore else */
  34634. if (buf && buf.split) {
  34635. var lines = buf.split(/\n/);
  34636. var lineNumWidth = String(Math.min(lines.length, err.line + 3)).length;
  34637. var linePadding = ' ';
  34638. while (linePadding.length < lineNumWidth) {
  34639. linePadding += ' ';
  34640. }
  34641. for (var ii = Math.max(0, err.line - 1); ii < Math.min(lines.length, err.line + 2); ++ii) {
  34642. var lineNum = String(ii + 1);
  34643. if (lineNum.length < lineNumWidth) lineNum = ' ' + lineNum;
  34644. if (err.line === ii) {
  34645. msg += lineNum + '> ' + lines[ii] + '\n';
  34646. msg += linePadding + ' ';
  34647. for (var hh = 0; hh < err.col; ++hh) {
  34648. msg += ' ';
  34649. }
  34650. msg += '^\n';
  34651. } else {
  34652. msg += lineNum + ': ' + lines[ii] + '\n';
  34653. }
  34654. }
  34655. }
  34656. err.message = msg + '\n';
  34657. return err;
  34658. }
  34659. var parseString_1 = parseString;
  34660. function parseString(str) {
  34661. if (commonjsGlobal.Buffer && commonjsGlobal.Buffer.isBuffer(str)) {
  34662. str = str.toString('utf8');
  34663. }
  34664. var parser = new tomlParser();
  34665. try {
  34666. parser.parse(str);
  34667. return parser.finish();
  34668. } catch (ex) {
  34669. throw parsePrettyError(ex, str);
  34670. }
  34671. }
  34672. var loadToml = function loadToml(filePath, content) {
  34673. try {
  34674. return parseString_1(content);
  34675. } catch (error) {
  34676. error.message = `TOML Error in ${filePath}:\n${error.message}`;
  34677. throw error;
  34678. }
  34679. };
  34680. var resolveConfig_1 = createCommonjsModule(function (module) {
  34681. "use strict";
  34682. var getExplorerMemoized = mem(function (opts) {
  34683. var explorer = thirdParty$1.cosmiconfig("prettier", {
  34684. cache: opts.cache,
  34685. transform: function transform(result) {
  34686. if (result && result.config) {
  34687. if (typeof result.config !== "object") {
  34688. throw new Error(`Config is only allowed to be an object, ` + `but received ${typeof result.config} in "${result.filepath}"`);
  34689. }
  34690. delete result.config.$schema;
  34691. }
  34692. return result;
  34693. },
  34694. searchPlaces: ["package.json", ".prettierrc", ".prettierrc.json", ".prettierrc.yaml", ".prettierrc.yml", ".prettierrc.js", "prettier.config.js", ".prettierrc.toml"],
  34695. loaders: {
  34696. ".toml": loadToml
  34697. }
  34698. });
  34699. var _load = opts.sync ? explorer.loadSync : explorer.load;
  34700. var search = opts.sync ? explorer.searchSync : explorer.search;
  34701. return {
  34702. // cosmiconfig v4 interface
  34703. load: function load(searchPath, configPath) {
  34704. return configPath ? _load(configPath) : search(searchPath);
  34705. }
  34706. };
  34707. });
  34708. /** @param {{ cache: boolean, sync: boolean }} opts */
  34709. function getLoadFunction(opts) {
  34710. // Normalize opts before passing to a memoized function
  34711. opts = Object.assign({
  34712. sync: false,
  34713. cache: false
  34714. }, opts);
  34715. return getExplorerMemoized(opts).load;
  34716. }
  34717. function _resolveConfig(filePath, opts, sync) {
  34718. opts = Object.assign({
  34719. useCache: true
  34720. }, opts);
  34721. var loadOpts = {
  34722. cache: !!opts.useCache,
  34723. sync: !!sync,
  34724. editorconfig: !!opts.editorconfig
  34725. };
  34726. var load = getLoadFunction(loadOpts);
  34727. var loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  34728. var arr = [load, loadEditorConfig].map(function (l) {
  34729. return l(filePath, opts.config);
  34730. });
  34731. var unwrapAndMerge = function unwrapAndMerge(arr) {
  34732. var result = arr[0];
  34733. var editorConfigured = arr[1];
  34734. var merged = Object.assign({}, editorConfigured, mergeOverrides(Object.assign({}, result), filePath));
  34735. ["plugins", "pluginSearchDirs"].forEach(function (optionName) {
  34736. if (Array.isArray(merged[optionName])) {
  34737. merged[optionName] = merged[optionName].map(function (value) {
  34738. return typeof value === "string" && value.startsWith(".") // relative path
  34739. ? path.resolve(path.dirname(result.filepath), value) : value;
  34740. });
  34741. }
  34742. });
  34743. if (!result && !editorConfigured) {
  34744. return null;
  34745. }
  34746. return merged;
  34747. };
  34748. if (loadOpts.sync) {
  34749. return unwrapAndMerge(arr);
  34750. }
  34751. return Promise.all(arr).then(unwrapAndMerge);
  34752. }
  34753. var resolveConfig = function resolveConfig(filePath, opts) {
  34754. return _resolveConfig(filePath, opts, false);
  34755. };
  34756. resolveConfig.sync = function (filePath, opts) {
  34757. return _resolveConfig(filePath, opts, true);
  34758. };
  34759. function clearCache() {
  34760. mem.clear(getExplorerMemoized);
  34761. resolveConfigEditorconfig.clearCache();
  34762. }
  34763. function resolveConfigFile(filePath) {
  34764. var load = getLoadFunction({
  34765. sync: false
  34766. });
  34767. return load(filePath).then(function (result) {
  34768. return result ? result.filepath : null;
  34769. });
  34770. }
  34771. resolveConfigFile.sync = function (filePath) {
  34772. var load = getLoadFunction({
  34773. sync: true
  34774. });
  34775. var result = load(filePath);
  34776. return result ? result.filepath : null;
  34777. };
  34778. function mergeOverrides(configResult, filePath) {
  34779. var options = Object.assign({}, configResult.config);
  34780. if (filePath && options.overrides) {
  34781. var relativeFilePath = path.relative(path.dirname(configResult.filepath), filePath);
  34782. var _iteratorNormalCompletion = true;
  34783. var _didIteratorError = false;
  34784. var _iteratorError = undefined;
  34785. try {
  34786. for (var _iterator = options.overrides[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  34787. var override = _step.value;
  34788. if (pathMatchesGlobs(relativeFilePath, override.files, override.excludeFiles)) {
  34789. Object.assign(options, override.options);
  34790. }
  34791. }
  34792. } catch (err) {
  34793. _didIteratorError = true;
  34794. _iteratorError = err;
  34795. } finally {
  34796. try {
  34797. if (!_iteratorNormalCompletion && _iterator.return != null) {
  34798. _iterator.return();
  34799. }
  34800. } finally {
  34801. if (_didIteratorError) {
  34802. throw _iteratorError;
  34803. }
  34804. }
  34805. }
  34806. }
  34807. delete options.overrides;
  34808. return options;
  34809. } // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  34810. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  34811. var patternList = [].concat(patterns);
  34812. var excludedPatternList = [].concat(excludedPatterns || []);
  34813. var opts = {
  34814. matchBase: true
  34815. };
  34816. return patternList.some(function (pattern) {
  34817. return minimatch_1(filePath, pattern, opts);
  34818. }) && !excludedPatternList.some(function (excludedPattern) {
  34819. return minimatch_1(filePath, excludedPattern, opts);
  34820. });
  34821. }
  34822. module.exports = {
  34823. resolveConfig,
  34824. resolveConfigFile,
  34825. clearCache
  34826. };
  34827. });
  34828. var version = require$$0.version;
  34829. var getSupportInfo = support.getSupportInfo; // Luckily `opts` is always the 2nd argument
  34830. function _withPlugins(fn) {
  34831. return function () {
  34832. var args = Array.from(arguments);
  34833. var opts = args[1] || {};
  34834. args[1] = Object.assign({}, opts, {
  34835. plugins: loadPlugins_1(opts.plugins, opts.pluginSearchDirs)
  34836. });
  34837. return fn.apply(null, args);
  34838. };
  34839. }
  34840. function withPlugins(fn) {
  34841. var resultingFn = _withPlugins(fn);
  34842. if (fn.sync) {
  34843. resultingFn.sync = _withPlugins(fn.sync);
  34844. }
  34845. return resultingFn;
  34846. }
  34847. var formatWithCursor = withPlugins(core.formatWithCursor);
  34848. var src = {
  34849. formatWithCursor,
  34850. format(text, opts) {
  34851. return formatWithCursor(text, opts).formatted;
  34852. },
  34853. check: function check(text, opts) {
  34854. var formatted = formatWithCursor(text, opts).formatted;
  34855. return formatted === text;
  34856. },
  34857. doc,
  34858. resolveConfig: resolveConfig_1.resolveConfig,
  34859. resolveConfigFile: resolveConfig_1.resolveConfigFile,
  34860. clearConfigCache: resolveConfig_1.clearCache,
  34861. getFileInfo: withPlugins(getFileInfo_1),
  34862. getSupportInfo: withPlugins(getSupportInfo),
  34863. version,
  34864. util: utilShared,
  34865. /* istanbul ignore next */
  34866. __debug: {
  34867. parse: withPlugins(core.parse),
  34868. formatAST: withPlugins(core.formatAST),
  34869. formatDoc: withPlugins(core.formatDoc),
  34870. printToDoc: withPlugins(core.printToDoc),
  34871. printDocToString: withPlugins(core.printDocToString)
  34872. }
  34873. };
  34874. var prettier$2 = src;
  34875. var at;
  34876. var ch;
  34877. var escapee = {
  34878. '"': '"',
  34879. '\\': '\\',
  34880. '/': '/',
  34881. b: '\b',
  34882. f: '\f',
  34883. n: '\n',
  34884. r: '\r',
  34885. t: '\t'
  34886. };
  34887. var text;
  34888. var error = function error(m) {
  34889. // Call error when something is wrong.
  34890. throw {
  34891. name: 'SyntaxError',
  34892. message: m,
  34893. at: at,
  34894. text: text
  34895. };
  34896. };
  34897. var next = function next(c) {
  34898. // If a c parameter is provided, verify that it matches the current character.
  34899. if (c && c !== ch) {
  34900. error("Expected '" + c + "' instead of '" + ch + "'");
  34901. } // Get the next character. When there are no more characters,
  34902. // return the empty string.
  34903. ch = text.charAt(at);
  34904. at += 1;
  34905. return ch;
  34906. };
  34907. var number$2 = function number() {
  34908. // Parse a number value.
  34909. var number,
  34910. string = '';
  34911. if (ch === '-') {
  34912. string = '-';
  34913. next('-');
  34914. }
  34915. while (ch >= '0' && ch <= '9') {
  34916. string += ch;
  34917. next();
  34918. }
  34919. if (ch === '.') {
  34920. string += '.';
  34921. while (next() && ch >= '0' && ch <= '9') {
  34922. string += ch;
  34923. }
  34924. }
  34925. if (ch === 'e' || ch === 'E') {
  34926. string += ch;
  34927. next();
  34928. if (ch === '-' || ch === '+') {
  34929. string += ch;
  34930. next();
  34931. }
  34932. while (ch >= '0' && ch <= '9') {
  34933. string += ch;
  34934. next();
  34935. }
  34936. }
  34937. number = +string;
  34938. if (!isFinite(number)) {
  34939. error("Bad number");
  34940. } else {
  34941. return number;
  34942. }
  34943. };
  34944. var string$2 = function string() {
  34945. // Parse a string value.
  34946. var hex,
  34947. i,
  34948. string = '',
  34949. uffff; // When parsing for string values, we must look for " and \ characters.
  34950. if (ch === '"') {
  34951. while (next()) {
  34952. if (ch === '"') {
  34953. next();
  34954. return string;
  34955. } else if (ch === '\\') {
  34956. next();
  34957. if (ch === 'u') {
  34958. uffff = 0;
  34959. for (i = 0; i < 4; i += 1) {
  34960. hex = parseInt(next(), 16);
  34961. if (!isFinite(hex)) {
  34962. break;
  34963. }
  34964. uffff = uffff * 16 + hex;
  34965. }
  34966. string += String.fromCharCode(uffff);
  34967. } else if (typeof escapee[ch] === 'string') {
  34968. string += escapee[ch];
  34969. } else {
  34970. break;
  34971. }
  34972. } else {
  34973. string += ch;
  34974. }
  34975. }
  34976. }
  34977. error("Bad string");
  34978. };
  34979. var white = function white() {
  34980. // Skip whitespace.
  34981. while (ch && ch <= ' ') {
  34982. next();
  34983. }
  34984. };
  34985. var word$2 = function word() {
  34986. // true, false, or null.
  34987. switch (ch) {
  34988. case 't':
  34989. next('t');
  34990. next('r');
  34991. next('u');
  34992. next('e');
  34993. return true;
  34994. case 'f':
  34995. next('f');
  34996. next('a');
  34997. next('l');
  34998. next('s');
  34999. next('e');
  35000. return false;
  35001. case 'n':
  35002. next('n');
  35003. next('u');
  35004. next('l');
  35005. next('l');
  35006. return null;
  35007. }
  35008. error("Unexpected '" + ch + "'");
  35009. };
  35010. var value;
  35011. var array$4 = function array() {
  35012. // Parse an array value.
  35013. var array = [];
  35014. if (ch === '[') {
  35015. next('[');
  35016. white();
  35017. if (ch === ']') {
  35018. next(']');
  35019. return array; // empty array
  35020. }
  35021. while (ch) {
  35022. array.push(value());
  35023. white();
  35024. if (ch === ']') {
  35025. next(']');
  35026. return array;
  35027. }
  35028. next(',');
  35029. white();
  35030. }
  35031. }
  35032. error("Bad array");
  35033. };
  35034. var object$1 = function object() {
  35035. // Parse an object value.
  35036. var key,
  35037. object = {};
  35038. if (ch === '{') {
  35039. next('{');
  35040. white();
  35041. if (ch === '}') {
  35042. next('}');
  35043. return object; // empty object
  35044. }
  35045. while (ch) {
  35046. key = string$2();
  35047. white();
  35048. next(':');
  35049. if (Object.hasOwnProperty.call(object, key)) {
  35050. error('Duplicate key "' + key + '"');
  35051. }
  35052. object[key] = value();
  35053. white();
  35054. if (ch === '}') {
  35055. next('}');
  35056. return object;
  35057. }
  35058. next(',');
  35059. white();
  35060. }
  35061. }
  35062. error("Bad object");
  35063. };
  35064. value = function value() {
  35065. // Parse a JSON value. It could be an object, an array, a string, a number,
  35066. // or a word.
  35067. white();
  35068. switch (ch) {
  35069. case '{':
  35070. return object$1();
  35071. case '[':
  35072. return array$4();
  35073. case '"':
  35074. return string$2();
  35075. case '-':
  35076. return number$2();
  35077. default:
  35078. return ch >= '0' && ch <= '9' ? number$2() : word$2();
  35079. }
  35080. }; // Return the json_parse function. It will have access to all of the above
  35081. // functions and variables.
  35082. var parse$8 = function parse(source, reviver) {
  35083. var result;
  35084. text = source;
  35085. at = 0;
  35086. ch = ' ';
  35087. result = value();
  35088. white();
  35089. if (ch) {
  35090. error("Syntax error");
  35091. } // If there is a reviver function, we recursively walk the new structure,
  35092. // passing each name/value pair to the reviver function for possible
  35093. // transformation, starting with a temporary root object that holds the result
  35094. // in an empty key. If there is not a reviver function, we simply return the
  35095. // result.
  35096. return typeof reviver === 'function' ? function walk(holder, key) {
  35097. var k,
  35098. v,
  35099. value = holder[key];
  35100. if (value && typeof value === 'object') {
  35101. for (k in value) {
  35102. if (Object.prototype.hasOwnProperty.call(value, k)) {
  35103. v = walk(value, k);
  35104. if (v !== undefined) {
  35105. value[k] = v;
  35106. } else {
  35107. delete value[k];
  35108. }
  35109. }
  35110. }
  35111. }
  35112. return reviver.call(holder, key, value);
  35113. }({
  35114. '': result
  35115. }, '') : result;
  35116. };
  35117. var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  35118. var gap;
  35119. var indent$10;
  35120. var meta$1 = {
  35121. // table of character substitutions
  35122. '\b': '\\b',
  35123. '\t': '\\t',
  35124. '\n': '\\n',
  35125. '\f': '\\f',
  35126. '\r': '\\r',
  35127. '"': '\\"',
  35128. '\\': '\\\\'
  35129. };
  35130. var rep;
  35131. function quote(string) {
  35132. // If the string contains no control characters, no quote characters, and no
  35133. // backslash characters, then we can safely slap some quotes around it.
  35134. // Otherwise we must also replace the offending characters with safe escape
  35135. // sequences.
  35136. escapable.lastIndex = 0;
  35137. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  35138. var c = meta$1[a];
  35139. return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  35140. }) + '"' : '"' + string + '"';
  35141. }
  35142. function str(key, holder) {
  35143. // Produce a string from holder[key].
  35144. var i,
  35145. // The loop counter.
  35146. k,
  35147. // The member key.
  35148. v,
  35149. // The member value.
  35150. length,
  35151. mind = gap,
  35152. partial,
  35153. value = holder[key]; // If the value has a toJSON method, call it to obtain a replacement value.
  35154. if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
  35155. value = value.toJSON(key);
  35156. } // If we were called with a replacer function, then call the replacer to
  35157. // obtain a replacement value.
  35158. if (typeof rep === 'function') {
  35159. value = rep.call(holder, key, value);
  35160. } // What happens next depends on the value's type.
  35161. switch (typeof value) {
  35162. case 'string':
  35163. return quote(value);
  35164. case 'number':
  35165. // JSON numbers must be finite. Encode non-finite numbers as null.
  35166. return isFinite(value) ? String(value) : 'null';
  35167. case 'boolean':
  35168. case 'null':
  35169. // If the value is a boolean or null, convert it to a string. Note:
  35170. // typeof null does not produce 'null'. The case is included here in
  35171. // the remote chance that this gets fixed someday.
  35172. return String(value);
  35173. case 'object':
  35174. if (!value) return 'null';
  35175. gap += indent$10;
  35176. partial = []; // Array.isArray
  35177. if (Object.prototype.toString.apply(value) === '[object Array]') {
  35178. length = value.length;
  35179. for (i = 0; i < length; i += 1) {
  35180. partial[i] = str(i, value) || 'null';
  35181. } // Join all of the elements together, separated with commas, and
  35182. // wrap them in brackets.
  35183. v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
  35184. gap = mind;
  35185. return v;
  35186. } // If the replacer is an array, use it to select the members to be
  35187. // stringified.
  35188. if (rep && typeof rep === 'object') {
  35189. length = rep.length;
  35190. for (i = 0; i < length; i += 1) {
  35191. k = rep[i];
  35192. if (typeof k === 'string') {
  35193. v = str(k, value);
  35194. if (v) {
  35195. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  35196. }
  35197. }
  35198. }
  35199. } else {
  35200. // Otherwise, iterate through all of the keys in the object.
  35201. for (k in value) {
  35202. if (Object.prototype.hasOwnProperty.call(value, k)) {
  35203. v = str(k, value);
  35204. if (v) {
  35205. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  35206. }
  35207. }
  35208. }
  35209. } // Join all of the member texts together, separated with commas,
  35210. // and wrap them in braces.
  35211. v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
  35212. gap = mind;
  35213. return v;
  35214. }
  35215. }
  35216. var stringify$1 = function stringify(value, replacer, space) {
  35217. var i;
  35218. gap = '';
  35219. indent$10 = ''; // If the space parameter is a number, make an indent string containing that
  35220. // many spaces.
  35221. if (typeof space === 'number') {
  35222. for (i = 0; i < space; i += 1) {
  35223. indent$10 += ' ';
  35224. }
  35225. } // If the space parameter is a string, it will be used as the indent string.
  35226. else if (typeof space === 'string') {
  35227. indent$10 = space;
  35228. } // If there is a replacer, it must be a function or an array.
  35229. // Otherwise, throw an error.
  35230. rep = replacer;
  35231. if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  35232. throw new Error('JSON.stringify');
  35233. } // Make a fake root object containing our value under the key of ''.
  35234. // Return the result of stringifying the value.
  35235. return str('', {
  35236. '': value
  35237. });
  35238. };
  35239. var parse$7 = parse$8;
  35240. var stringify = stringify$1;
  35241. var jsonify = {
  35242. parse: parse$7,
  35243. stringify: stringify
  35244. };
  35245. var json$10 = typeof JSON !== 'undefined' ? JSON : jsonify;
  35246. var jsonStableStringify = function jsonStableStringify(obj, opts) {
  35247. if (!opts) opts = {};
  35248. if (typeof opts === 'function') opts = {
  35249. cmp: opts
  35250. };
  35251. var space = opts.space || '';
  35252. if (typeof space === 'number') space = Array(space + 1).join(' ');
  35253. var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
  35254. var replacer = opts.replacer || function (key, value) {
  35255. return value;
  35256. };
  35257. var cmp = opts.cmp && function (f) {
  35258. return function (node) {
  35259. return function (a, b) {
  35260. var aobj = {
  35261. key: a,
  35262. value: node[a]
  35263. };
  35264. var bobj = {
  35265. key: b,
  35266. value: node[b]
  35267. };
  35268. return f(aobj, bobj);
  35269. };
  35270. };
  35271. }(opts.cmp);
  35272. var seen = [];
  35273. return function stringify(parent, key, node, level) {
  35274. var indent = space ? '\n' + new Array(level + 1).join(space) : '';
  35275. var colonSeparator = space ? ': ' : ':';
  35276. if (node && node.toJSON && typeof node.toJSON === 'function') {
  35277. node = node.toJSON();
  35278. }
  35279. node = replacer.call(parent, key, node);
  35280. if (node === undefined) {
  35281. return;
  35282. }
  35283. if (typeof node !== 'object' || node === null) {
  35284. return json$10.stringify(node);
  35285. }
  35286. if (isArray$1(node)) {
  35287. var out = [];
  35288. for (var i = 0; i < node.length; i++) {
  35289. var item = stringify(node, i, node[i], level + 1) || json$10.stringify(null);
  35290. out.push(indent + space + item);
  35291. }
  35292. return '[' + out.join(',') + indent + ']';
  35293. } else {
  35294. if (seen.indexOf(node) !== -1) {
  35295. if (cycles) return json$10.stringify('__cycle__');
  35296. throw new TypeError('Converting circular structure to JSON');
  35297. } else seen.push(node);
  35298. var keys = objectKeys(node).sort(cmp && cmp(node));
  35299. var out = [];
  35300. for (var i = 0; i < keys.length; i++) {
  35301. var key = keys[i];
  35302. var value = stringify(node, key, node[key], level + 1);
  35303. if (!value) continue;
  35304. var keyValue = json$10.stringify(key) + colonSeparator + value;
  35305. out.push(indent + space + keyValue);
  35306. }
  35307. seen.splice(seen.indexOf(node), 1);
  35308. return '{' + out.join(',') + indent + '}';
  35309. }
  35310. }({
  35311. '': obj
  35312. }, '', obj, 0);
  35313. };
  35314. var isArray$1 = Array.isArray || function (x) {
  35315. return {}.toString.call(x) === '[object Array]';
  35316. };
  35317. var objectKeys = Object.keys || function (obj) {
  35318. var has = Object.prototype.hasOwnProperty || function () {
  35319. return true;
  35320. };
  35321. var keys = [];
  35322. for (var key in obj) {
  35323. if (has.call(obj, key)) keys.push(key);
  35324. }
  35325. return keys;
  35326. };
  35327. function preserveCamelCase(str) {
  35328. var isLastCharLower = false;
  35329. var isLastCharUpper = false;
  35330. var isLastLastCharUpper = false;
  35331. for (var i = 0; i < str.length; i++) {
  35332. var c = str[i];
  35333. if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
  35334. str = str.substr(0, i) + '-' + str.substr(i);
  35335. isLastCharLower = false;
  35336. isLastLastCharUpper = isLastCharUpper;
  35337. isLastCharUpper = true;
  35338. i++;
  35339. } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
  35340. str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
  35341. isLastLastCharUpper = isLastCharUpper;
  35342. isLastCharUpper = false;
  35343. isLastCharLower = true;
  35344. } else {
  35345. isLastCharLower = c.toLowerCase() === c;
  35346. isLastLastCharUpper = isLastCharUpper;
  35347. isLastCharUpper = c.toUpperCase() === c;
  35348. }
  35349. }
  35350. return str;
  35351. }
  35352. var camelcase = function camelcase(str) {
  35353. if (arguments.length > 1) {
  35354. str = Array.from(arguments).map(function (x) {
  35355. return x.trim();
  35356. }).filter(function (x) {
  35357. return x.length;
  35358. }).join('-');
  35359. } else {
  35360. str = str.trim();
  35361. }
  35362. if (str.length === 0) {
  35363. return '';
  35364. }
  35365. if (str.length === 1) {
  35366. return str.toLowerCase();
  35367. }
  35368. if (/^[a-z0-9]+$/.test(str)) {
  35369. return str;
  35370. }
  35371. var hasUpperCase = str !== str.toLowerCase();
  35372. if (hasUpperCase) {
  35373. str = preserveCamelCase(str);
  35374. }
  35375. return str.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
  35376. return p1.toUpperCase();
  35377. });
  35378. };
  35379. /*!
  35380. * dashify <https://github.com/jonschlinkert/dashify>
  35381. *
  35382. * Copyright (c) 2015 Jon Schlinkert.
  35383. * Licensed under the MIT license.
  35384. */
  35385. var dashify = function dashify(str) {
  35386. if (typeof str !== 'string') {
  35387. throw new TypeError('expected a string');
  35388. }
  35389. str = str.replace(/([a-z])([A-Z])/g, '$1-$2');
  35390. str = str.replace(/[ \t\W]/g, '-');
  35391. str = str.replace(/^-+|-+$/g, '');
  35392. return str.toLowerCase();
  35393. };
  35394. var minimist = function minimist(args, opts) {
  35395. if (!opts) opts = {};
  35396. var flags = {
  35397. bools: {},
  35398. strings: {},
  35399. unknownFn: null
  35400. };
  35401. if (typeof opts['unknown'] === 'function') {
  35402. flags.unknownFn = opts['unknown'];
  35403. }
  35404. if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
  35405. flags.allBools = true;
  35406. } else {
  35407. [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
  35408. flags.bools[key] = true;
  35409. });
  35410. }
  35411. var aliases = {};
  35412. Object.keys(opts.alias || {}).forEach(function (key) {
  35413. aliases[key] = [].concat(opts.alias[key]);
  35414. aliases[key].forEach(function (x) {
  35415. aliases[x] = [key].concat(aliases[key].filter(function (y) {
  35416. return x !== y;
  35417. }));
  35418. });
  35419. });
  35420. [].concat(opts.string).filter(Boolean).forEach(function (key) {
  35421. flags.strings[key] = true;
  35422. if (aliases[key]) {
  35423. flags.strings[aliases[key]] = true;
  35424. }
  35425. });
  35426. var defaults = opts['default'] || {};
  35427. var argv = {
  35428. _: []
  35429. };
  35430. Object.keys(flags.bools).forEach(function (key) {
  35431. setArg(key, defaults[key] === undefined ? false : defaults[key]);
  35432. });
  35433. var notFlags = [];
  35434. if (args.indexOf('--') !== -1) {
  35435. notFlags = args.slice(args.indexOf('--') + 1);
  35436. args = args.slice(0, args.indexOf('--'));
  35437. }
  35438. function argDefined(key, arg) {
  35439. return flags.allBools && /^--[^=]+$/.test(arg) || flags.strings[key] || flags.bools[key] || aliases[key];
  35440. }
  35441. function setArg(key, val, arg) {
  35442. if (arg && flags.unknownFn && !argDefined(key, arg)) {
  35443. if (flags.unknownFn(arg) === false) return;
  35444. }
  35445. var value = !flags.strings[key] && isNumber(val) ? Number(val) : val;
  35446. setKey(argv, key.split('.'), value);
  35447. (aliases[key] || []).forEach(function (x) {
  35448. setKey(argv, x.split('.'), value);
  35449. });
  35450. }
  35451. function setKey(obj, keys, value) {
  35452. var o = obj;
  35453. keys.slice(0, -1).forEach(function (key) {
  35454. if (o[key] === undefined) o[key] = {};
  35455. o = o[key];
  35456. });
  35457. var key = keys[keys.length - 1];
  35458. if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
  35459. o[key] = value;
  35460. } else if (Array.isArray(o[key])) {
  35461. o[key].push(value);
  35462. } else {
  35463. o[key] = [o[key], value];
  35464. }
  35465. }
  35466. function aliasIsBoolean(key) {
  35467. return aliases[key].some(function (x) {
  35468. return flags.bools[x];
  35469. });
  35470. }
  35471. for (var i = 0; i < args.length; i++) {
  35472. var arg = args[i];
  35473. if (/^--.+=/.test(arg)) {
  35474. // Using [\s\S] instead of . because js doesn't support the
  35475. // 'dotall' regex modifier. See:
  35476. // http://stackoverflow.com/a/1068308/13216
  35477. var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
  35478. var key = m[1];
  35479. var value = m[2];
  35480. if (flags.bools[key]) {
  35481. value = value !== 'false';
  35482. }
  35483. setArg(key, value, arg);
  35484. } else if (/^--no-.+/.test(arg)) {
  35485. var key = arg.match(/^--no-(.+)/)[1];
  35486. setArg(key, false, arg);
  35487. } else if (/^--.+/.test(arg)) {
  35488. var key = arg.match(/^--(.+)/)[1];
  35489. var next = args[i + 1];
  35490. if (next !== undefined && !/^-/.test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  35491. setArg(key, next, arg);
  35492. i++;
  35493. } else if (/^(true|false)$/.test(next)) {
  35494. setArg(key, next === 'true', arg);
  35495. i++;
  35496. } else {
  35497. setArg(key, flags.strings[key] ? '' : true, arg);
  35498. }
  35499. } else if (/^-[^-]+/.test(arg)) {
  35500. var letters = arg.slice(1, -1).split('');
  35501. var broken = false;
  35502. for (var j = 0; j < letters.length; j++) {
  35503. var next = arg.slice(j + 2);
  35504. if (next === '-') {
  35505. setArg(letters[j], next, arg);
  35506. continue;
  35507. }
  35508. if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
  35509. setArg(letters[j], next.split('=')[1], arg);
  35510. broken = true;
  35511. break;
  35512. }
  35513. if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
  35514. setArg(letters[j], next, arg);
  35515. broken = true;
  35516. break;
  35517. }
  35518. if (letters[j + 1] && letters[j + 1].match(/\W/)) {
  35519. setArg(letters[j], arg.slice(j + 2), arg);
  35520. broken = true;
  35521. break;
  35522. } else {
  35523. setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
  35524. }
  35525. }
  35526. var key = arg.slice(-1)[0];
  35527. if (!broken && key !== '-') {
  35528. if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !flags.bools[key] && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  35529. setArg(key, args[i + 1], arg);
  35530. i++;
  35531. } else if (args[i + 1] && /true|false/.test(args[i + 1])) {
  35532. setArg(key, args[i + 1] === 'true', arg);
  35533. i++;
  35534. } else {
  35535. setArg(key, flags.strings[key] ? '' : true, arg);
  35536. }
  35537. }
  35538. } else {
  35539. if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
  35540. argv._.push(flags.strings['_'] || !isNumber(arg) ? arg : Number(arg));
  35541. }
  35542. if (opts.stopEarly) {
  35543. argv._.push.apply(argv._, args.slice(i + 1));
  35544. break;
  35545. }
  35546. }
  35547. }
  35548. Object.keys(defaults).forEach(function (key) {
  35549. if (!hasKey(argv, key.split('.'))) {
  35550. setKey(argv, key.split('.'), defaults[key]);
  35551. (aliases[key] || []).forEach(function (x) {
  35552. setKey(argv, x.split('.'), defaults[key]);
  35553. });
  35554. }
  35555. });
  35556. if (opts['--']) {
  35557. argv['--'] = new Array();
  35558. notFlags.forEach(function (key) {
  35559. argv['--'].push(key);
  35560. });
  35561. } else {
  35562. notFlags.forEach(function (key) {
  35563. argv._.push(key);
  35564. });
  35565. }
  35566. return argv;
  35567. };
  35568. function hasKey(obj, keys) {
  35569. var o = obj;
  35570. keys.slice(0, -1).forEach(function (key) {
  35571. o = o[key] || {};
  35572. });
  35573. var key = keys[keys.length - 1];
  35574. return key in o;
  35575. }
  35576. function isNumber(x) {
  35577. if (typeof x === 'number') return true;
  35578. if (/^0x[0-9a-f]+$/i.test(x)) return true;
  35579. return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
  35580. }
  35581. var PLACEHOLDER = null;
  35582. /**
  35583. * unspecified boolean flag without default value is parsed as `undefined` instead of `false`
  35584. */
  35585. var minimist_1 = function minimist_1(args, options) {
  35586. var boolean = options.boolean || [];
  35587. var defaults = options.default || {};
  35588. var booleanWithoutDefault = boolean.filter(function (key) {
  35589. return !(key in defaults);
  35590. });
  35591. var newDefaults = Object.assign({}, defaults, booleanWithoutDefault.reduce(function (reduced, key) {
  35592. return Object.assign(reduced, {
  35593. [key]: PLACEHOLDER
  35594. });
  35595. }, {}));
  35596. var parsed = minimist(args, Object.assign({}, options, {
  35597. default: newDefaults
  35598. }));
  35599. return Object.keys(parsed).reduce(function (reduced, key) {
  35600. if (parsed[key] !== PLACEHOLDER) {
  35601. reduced[key] = parsed[key];
  35602. }
  35603. return reduced;
  35604. }, {});
  35605. };
  35606. var categoryOrder = [coreOptions$1.CATEGORY_OUTPUT, coreOptions$1.CATEGORY_FORMAT, coreOptions$1.CATEGORY_CONFIG, coreOptions$1.CATEGORY_EDITOR, coreOptions$1.CATEGORY_OTHER];
  35607. /**
  35608. * {
  35609. * [optionName]: {
  35610. * // The type of the option. For 'choice', see also `choices` below.
  35611. * // When passing a type other than the ones listed below, the option is
  35612. * // treated as taking any string as argument, and `--option <${type}>` will
  35613. * // be displayed in --help.
  35614. * type: "boolean" | "choice" | "int" | string;
  35615. *
  35616. * // Default value to be passed to the minimist option `default`.
  35617. * default?: any;
  35618. *
  35619. * // Alias name to be passed to the minimist option `alias`.
  35620. * alias?: string;
  35621. *
  35622. * // For grouping options by category in --help.
  35623. * category?: string;
  35624. *
  35625. * // Description to be displayed in --help. If omitted, the option won't be
  35626. * // shown at all in --help (but see also `oppositeDescription` below).
  35627. * description?: string;
  35628. *
  35629. * // Description for `--no-${name}` to be displayed in --help. If omitted,
  35630. * // `--no-${name}` won't be shown.
  35631. * oppositeDescription?: string;
  35632. *
  35633. * // Indicate if this option is simply passed to the API.
  35634. * // true: use camelified name as the API option name.
  35635. * // string: use this value as the API option name.
  35636. * forwardToApi?: boolean | string;
  35637. *
  35638. * // Indicate that a CLI flag should be an array when forwarded to the API.
  35639. * array?: boolean;
  35640. *
  35641. * // Specify available choices for validation. They will also be displayed
  35642. * // in --help as <a|b|c>.
  35643. * // Use an object instead of a string if a choice is deprecated and should
  35644. * // be treated as `redirect` instead, or if you'd like to add description for
  35645. * // the choice.
  35646. * choices?: Array<
  35647. * | string
  35648. * | { value: string, description?: string, deprecated?: boolean, redirect?: string }
  35649. * >;
  35650. *
  35651. * // If the option has a value that is an exception to the regular value
  35652. * // constraints, indicate that value here (or use a function for more
  35653. * // flexibility).
  35654. * exception?: ((value: any) => boolean);
  35655. *
  35656. * // Indicate that the option is deprecated. Use a string to add an extra
  35657. * // message to --help for the option, for example to suggest a replacement
  35658. * // option.
  35659. * deprecated?: true | string;
  35660. * }
  35661. * }
  35662. *
  35663. * Note: The options below are sorted alphabetically.
  35664. */
  35665. var options$21 = {
  35666. check: {
  35667. type: "boolean",
  35668. category: coreOptions$1.CATEGORY_OUTPUT,
  35669. alias: "c",
  35670. description: dedent_1`
  35671. Check if the given files are formatted, print a human-friendly summary
  35672. message and paths to unformatted files (see also --list-different).
  35673. `
  35674. },
  35675. color: {
  35676. // The supports-color package (a sub sub dependency) looks directly at
  35677. // `process.argv` for `--no-color` and such-like options. The reason it is
  35678. // listed here is to avoid "Ignored unknown option: --no-color" warnings.
  35679. // See https://github.com/chalk/supports-color/#info for more information.
  35680. type: "boolean",
  35681. default: true,
  35682. description: "Colorize error messages.",
  35683. oppositeDescription: "Do not colorize error messages."
  35684. },
  35685. config: {
  35686. type: "path",
  35687. category: coreOptions$1.CATEGORY_CONFIG,
  35688. description: "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
  35689. oppositeDescription: "Do not look for a configuration file.",
  35690. exception: function exception(value) {
  35691. return value === false;
  35692. }
  35693. },
  35694. "config-precedence": {
  35695. type: "choice",
  35696. category: coreOptions$1.CATEGORY_CONFIG,
  35697. default: "cli-override",
  35698. choices: [{
  35699. value: "cli-override",
  35700. description: "CLI options take precedence over config file"
  35701. }, {
  35702. value: "file-override",
  35703. description: "Config file take precedence over CLI options"
  35704. }, {
  35705. value: "prefer-file",
  35706. description: dedent_1`
  35707. If a config file is found will evaluate it and ignore other CLI options.
  35708. If no config file is found CLI options will evaluate as normal.
  35709. `
  35710. }],
  35711. description: "Define in which order config files and CLI options should be evaluated."
  35712. },
  35713. "debug-benchmark": {
  35714. // Run the formatting benchmarks. Requires 'benchmark' module to be installed.
  35715. type: "boolean"
  35716. },
  35717. "debug-check": {
  35718. // Run the formatting once again on the formatted output, throw if different.
  35719. type: "boolean"
  35720. },
  35721. "debug-print-doc": {
  35722. type: "boolean"
  35723. },
  35724. "debug-repeat": {
  35725. // Repeat the formatting a few times and measure the average duration.
  35726. type: "int",
  35727. default: 0
  35728. },
  35729. editorconfig: {
  35730. type: "boolean",
  35731. category: coreOptions$1.CATEGORY_CONFIG,
  35732. description: "Take .editorconfig into account when parsing configuration.",
  35733. oppositeDescription: "Don't take .editorconfig into account when parsing configuration.",
  35734. default: true
  35735. },
  35736. "find-config-path": {
  35737. type: "path",
  35738. category: coreOptions$1.CATEGORY_CONFIG,
  35739. description: "Find and print the path to a configuration file for the given input file."
  35740. },
  35741. "file-info": {
  35742. type: "path",
  35743. description: dedent_1`
  35744. Extract the following info (as JSON) for a given file path. Reported fields:
  35745. * ignored (boolean) - true if file path is filtered by --ignore-path
  35746. * inferredParser (string | null) - name of parser inferred from file path
  35747. `
  35748. },
  35749. help: {
  35750. type: "flag",
  35751. alias: "h",
  35752. description: dedent_1`
  35753. Show CLI usage, or details about the given flag.
  35754. Example: --help write
  35755. `,
  35756. exception: function exception(value) {
  35757. return value === "";
  35758. }
  35759. },
  35760. "ignore-path": {
  35761. type: "path",
  35762. category: coreOptions$1.CATEGORY_CONFIG,
  35763. default: ".prettierignore",
  35764. description: "Path to a file with patterns describing files to ignore."
  35765. },
  35766. "list-different": {
  35767. type: "boolean",
  35768. category: coreOptions$1.CATEGORY_OUTPUT,
  35769. alias: "l",
  35770. description: "Print the names of files that are different from Prettier's formatting (see also --check)."
  35771. },
  35772. loglevel: {
  35773. type: "choice",
  35774. description: "What level of logs to report.",
  35775. default: "log",
  35776. choices: ["silent", "error", "warn", "log", "debug"]
  35777. },
  35778. stdin: {
  35779. type: "boolean",
  35780. description: "Force reading input from stdin."
  35781. },
  35782. "support-info": {
  35783. type: "boolean",
  35784. description: "Print support information as JSON."
  35785. },
  35786. version: {
  35787. type: "boolean",
  35788. alias: "v",
  35789. description: "Print Prettier version."
  35790. },
  35791. "with-node-modules": {
  35792. type: "boolean",
  35793. category: coreOptions$1.CATEGORY_CONFIG,
  35794. description: "Process files inside 'node_modules' directory."
  35795. },
  35796. write: {
  35797. type: "boolean",
  35798. category: coreOptions$1.CATEGORY_OUTPUT,
  35799. description: "Edit files in-place. (Beware!)"
  35800. }
  35801. };
  35802. var usageSummary = dedent_1`
  35803. Usage: prettier [options] [file/glob ...]
  35804. By default, output is written to stdout.
  35805. Stdin is read if it is piped to Prettier and no files are given.
  35806. `;
  35807. var constant = {
  35808. categoryOrder,
  35809. options: options$21,
  35810. usageSummary
  35811. };
  35812. // which causes unwanted lines in the output. An additional check for isCI() helps.
  35813. // See https://github.com/prettier/prettier/issues/5801
  35814. var isTty = function isTTY() {
  35815. return process.stdout.isTTY && !thirdParty$1.isCI();
  35816. };
  35817. var OPTION_USAGE_THRESHOLD = 25;
  35818. var CHOICE_USAGE_MARGIN = 3;
  35819. var CHOICE_USAGE_INDENTATION = 2;
  35820. function getOptions(argv, detailedOptions) {
  35821. return detailedOptions.filter(function (option) {
  35822. return option.forwardToApi;
  35823. }).reduce(function (current, option) {
  35824. return Object.assign(current, {
  35825. [option.forwardToApi]: argv[option.name]
  35826. });
  35827. }, {});
  35828. }
  35829. function cliifyOptions(object, apiDetailedOptionMap) {
  35830. return Object.keys(object || {}).reduce(function (output, key) {
  35831. var apiOption = apiDetailedOptionMap[key];
  35832. var cliKey = apiOption ? apiOption.name : key;
  35833. output[dashify(cliKey)] = object[key];
  35834. return output;
  35835. }, {});
  35836. }
  35837. function diff(a, b) {
  35838. return lib.createTwoFilesPatch("", "", a, b, "", "", {
  35839. context: 2
  35840. });
  35841. }
  35842. function handleError(context, filename, error) {
  35843. if (error instanceof errors.UndefinedParserError) {
  35844. if (context.argv["write"] && isTty()) {
  35845. readline.clearLine(process.stdout, 0);
  35846. readline.cursorTo(process.stdout, 0, null);
  35847. }
  35848. if (!context.argv["check"] && !context.argv["list-different"]) {
  35849. process.exitCode = 2;
  35850. }
  35851. context.logger.error(error.message);
  35852. return;
  35853. }
  35854. if (context.argv["write"]) {
  35855. // Add newline to split errors from filename line.
  35856. process.stdout.write("\n");
  35857. }
  35858. var isParseError = Boolean(error && error.loc);
  35859. var isValidationError = /Validation Error/.test(error && error.message); // For parse errors and validation errors, we only want to show the error
  35860. // message formatted in a nice way. `String(error)` takes care of that. Other
  35861. // (unexpected) errors are passed as-is as a separate argument to
  35862. // `console.error`. That includes the stack trace (if any), and shows a nice
  35863. // `util.inspect` of throws things that aren't `Error` objects. (The Flow
  35864. // parser has mistakenly thrown arrays sometimes.)
  35865. if (isParseError) {
  35866. context.logger.error(`${filename}: ${String(error)}`);
  35867. } else if (isValidationError || error instanceof errors.ConfigError) {
  35868. context.logger.error(String(error)); // If validation fails for one file, it will fail for all of them.
  35869. process.exit(1);
  35870. } else if (error instanceof errors.DebugError) {
  35871. context.logger.error(`${filename}: ${error.message}`);
  35872. } else {
  35873. context.logger.error(filename + ": " + (error.stack || error));
  35874. } // Don't exit the process if one file failed
  35875. process.exitCode = 2;
  35876. }
  35877. function logResolvedConfigPathOrDie(context) {
  35878. var configFile = prettier$2.resolveConfigFile.sync(context.argv["find-config-path"]);
  35879. if (configFile) {
  35880. context.logger.log(path.relative(process.cwd(), configFile));
  35881. } else {
  35882. process.exit(1);
  35883. }
  35884. }
  35885. function logFileInfoOrDie(context) {
  35886. var options$$2 = {
  35887. ignorePath: context.argv["ignore-path"],
  35888. withNodeModules: context.argv["with-node-modules"],
  35889. plugins: context.argv["plugin"],
  35890. pluginSearchDirs: context.argv["plugin-search-dir"]
  35891. };
  35892. context.logger.log(prettier$2.format(jsonStableStringify(prettier$2.getFileInfo.sync(context.argv["file-info"], options$$2)), {
  35893. parser: "json"
  35894. }));
  35895. }
  35896. function writeOutput(context, result, options$$2) {
  35897. // Don't use `console.log` here since it adds an extra newline at the end.
  35898. process.stdout.write(context.argv["debug-check"] ? result.filepath : result.formatted);
  35899. if (options$$2 && options$$2.cursorOffset >= 0) {
  35900. process.stderr.write(result.cursorOffset + "\n");
  35901. }
  35902. }
  35903. function listDifferent(context, input, options$$2, filename) {
  35904. if (!context.argv["check"] && !context.argv["list-different"]) {
  35905. return;
  35906. }
  35907. try {
  35908. if (!options$$2.filepath && !options$$2.parser) {
  35909. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  35910. }
  35911. if (!prettier$2.check(input, options$$2)) {
  35912. if (!context.argv["write"]) {
  35913. context.logger.log(filename);
  35914. process.exitCode = 1;
  35915. }
  35916. }
  35917. } catch (error) {
  35918. context.logger.error(error.message);
  35919. }
  35920. return true;
  35921. }
  35922. function format$1(context, input, opt) {
  35923. if (!opt.parser && !opt.filepath) {
  35924. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  35925. }
  35926. if (context.argv["debug-print-doc"]) {
  35927. var doc = prettier$2.__debug.printToDoc(input, opt);
  35928. return {
  35929. formatted: prettier$2.__debug.formatDoc(doc)
  35930. };
  35931. }
  35932. if (context.argv["debug-check"]) {
  35933. var pp = prettier$2.format(input, opt);
  35934. var pppp = prettier$2.format(pp, opt);
  35935. if (pp !== pppp) {
  35936. throw new errors.DebugError("prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp));
  35937. } else {
  35938. var _stringify = function _stringify(obj) {
  35939. return JSON.stringify(obj, null, 2);
  35940. };
  35941. var ast = _stringify(prettier$2.__debug.parse(input, opt,
  35942. /* massage */
  35943. true).ast);
  35944. var past = _stringify(prettier$2.__debug.parse(pp, opt,
  35945. /* massage */
  35946. true).ast);
  35947. if (ast !== past) {
  35948. var MAX_AST_SIZE = 2097152; // 2MB
  35949. var astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
  35950. throw new errors.DebugError("ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp));
  35951. }
  35952. }
  35953. return {
  35954. formatted: pp,
  35955. filepath: opt.filepath || "(stdin)\n"
  35956. };
  35957. }
  35958. /* istanbul ignore if */
  35959. if (context.argv["debug-benchmark"]) {
  35960. var benchmark;
  35961. try {
  35962. benchmark = require("benchmark");
  35963. } catch (err) {
  35964. context.logger.debug("'--debug-benchmark' requires the 'benchmark' package to be installed.");
  35965. process.exit(2);
  35966. }
  35967. context.logger.debug("'--debug-benchmark' option found, measuring formatWithCursor with 'benchmark' module.");
  35968. var suite = new benchmark.Suite();
  35969. suite.add("format", function () {
  35970. prettier$2.formatWithCursor(input, opt);
  35971. }).on("cycle", function (event) {
  35972. var results = {
  35973. benchmark: String(event.target),
  35974. hz: event.target.hz,
  35975. ms: event.target.times.cycle * 1000
  35976. };
  35977. context.logger.debug("'--debug-benchmark' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
  35978. }).run({
  35979. async: false
  35980. });
  35981. } else if (context.argv["debug-repeat"] > 0) {
  35982. var repeat = context.argv["debug-repeat"];
  35983. context.logger.debug("'--debug-repeat' option found, running formatWithCursor " + repeat + " times."); // should be using `performance.now()`, but only `Date` is cross-platform enough
  35984. var now = Date.now ? function () {
  35985. return Date.now();
  35986. } : function () {
  35987. return +new Date();
  35988. };
  35989. var totalMs = 0;
  35990. for (var i = 0; i < repeat; ++i) {
  35991. var startMs = now();
  35992. prettier$2.formatWithCursor(input, opt);
  35993. totalMs += now() - startMs;
  35994. }
  35995. var averageMs = totalMs / repeat;
  35996. var results = {
  35997. repeat,
  35998. hz: 1000 / averageMs,
  35999. ms: averageMs
  36000. };
  36001. context.logger.debug("'--debug-repeat' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
  36002. }
  36003. return prettier$2.formatWithCursor(input, opt);
  36004. }
  36005. function getOptionsOrDie(context, filePath) {
  36006. try {
  36007. if (context.argv["config"] === false) {
  36008. context.logger.debug("'--no-config' option found, skip loading config file.");
  36009. return null;
  36010. }
  36011. context.logger.debug(context.argv["config"] ? `load config file from '${context.argv["config"]}'` : `resolve config from '${filePath}'`);
  36012. var options$$2 = prettier$2.resolveConfig.sync(filePath, {
  36013. editorconfig: context.argv["editorconfig"],
  36014. config: context.argv["config"]
  36015. });
  36016. context.logger.debug("loaded options `" + JSON.stringify(options$$2) + "`");
  36017. return options$$2;
  36018. } catch (error) {
  36019. context.logger.error("Invalid configuration file: " + error.message);
  36020. process.exit(2);
  36021. }
  36022. }
  36023. function getOptionsForFile(context, filepath) {
  36024. var options$$2 = getOptionsOrDie(context, filepath);
  36025. var hasPlugins = options$$2 && options$$2.plugins;
  36026. if (hasPlugins) {
  36027. pushContextPlugins(context, options$$2.plugins);
  36028. }
  36029. var appliedOptions = Object.assign({
  36030. filepath
  36031. }, applyConfigPrecedence(context, options$$2 && optionsNormalizer.normalizeApiOptions(options$$2, context.supportOptions, {
  36032. logger: context.logger
  36033. })));
  36034. context.logger.debug(`applied config-precedence (${context.argv["config-precedence"]}): ` + `${JSON.stringify(appliedOptions)}`);
  36035. if (hasPlugins) {
  36036. popContextPlugins(context);
  36037. }
  36038. return appliedOptions;
  36039. }
  36040. function parseArgsToOptions(context, overrideDefaults) {
  36041. var minimistOptions = createMinimistOptions(context.detailedOptions);
  36042. var apiDetailedOptionMap = createApiDetailedOptionMap(context.detailedOptions);
  36043. return getOptions(optionsNormalizer.normalizeCliOptions(minimist_1(context.args, Object.assign({
  36044. string: minimistOptions.string,
  36045. boolean: minimistOptions.boolean,
  36046. default: cliifyOptions(overrideDefaults, apiDetailedOptionMap)
  36047. })), context.detailedOptions, {
  36048. logger: false
  36049. }), context.detailedOptions);
  36050. }
  36051. function applyConfigPrecedence(context, options$$2) {
  36052. try {
  36053. switch (context.argv["config-precedence"]) {
  36054. case "cli-override":
  36055. return parseArgsToOptions(context, options$$2);
  36056. case "file-override":
  36057. return Object.assign({}, parseArgsToOptions(context), options$$2);
  36058. case "prefer-file":
  36059. return options$$2 || parseArgsToOptions(context);
  36060. }
  36061. } catch (error) {
  36062. context.logger.error(error.toString());
  36063. process.exit(2);
  36064. }
  36065. }
  36066. function formatStdin(context) {
  36067. var filepath = context.argv["stdin-filepath"] ? path.resolve(process.cwd(), context.argv["stdin-filepath"]) : process.cwd();
  36068. var ignorer = createIgnorerFromContextOrDie(context);
  36069. var relativeFilepath = path.relative(process.cwd(), filepath);
  36070. thirdParty$1.getStream(process.stdin).then(function (input) {
  36071. if (relativeFilepath && ignorer.filter([relativeFilepath]).length === 0) {
  36072. writeOutput(context, {
  36073. formatted: input
  36074. });
  36075. return;
  36076. }
  36077. var options$$2 = getOptionsForFile(context, filepath);
  36078. try {
  36079. if (listDifferent(context, input, options$$2, "(stdin)")) {
  36080. return;
  36081. }
  36082. writeOutput(context, format$1(context, input, options$$2), options$$2);
  36083. } catch (error) {
  36084. handleError(context, "stdin", error);
  36085. }
  36086. });
  36087. }
  36088. function createIgnorerFromContextOrDie(context) {
  36089. try {
  36090. return createIgnorer_1.sync(context.argv["ignore-path"], context.argv["with-node-modules"]);
  36091. } catch (e) {
  36092. context.logger.error(e.message);
  36093. process.exit(2);
  36094. }
  36095. }
  36096. function eachFilename(context, patterns, callback) {
  36097. // The '!./' globs are due to https://github.com/prettier/prettier/issues/2110
  36098. var ignoreNodeModules = context.argv["with-node-modules"] !== true;
  36099. if (ignoreNodeModules) {
  36100. patterns = patterns.concat(["!**/node_modules/**", "!./node_modules/**"]);
  36101. }
  36102. patterns = patterns.concat(["!**/.{git,svn,hg}/**", "!./.{git,svn,hg}/**"]);
  36103. try {
  36104. var filePaths = globby.sync(patterns, {
  36105. dot: true,
  36106. nodir: true
  36107. }).map(function (filePath) {
  36108. return path.relative(process.cwd(), filePath);
  36109. });
  36110. if (filePaths.length === 0) {
  36111. context.logger.error(`No matching files. Patterns tried: ${patterns.join(" ")}`);
  36112. process.exitCode = 2;
  36113. return;
  36114. }
  36115. filePaths.forEach(function (filePath) {
  36116. return callback(filePath, Object.assign(getOptionsForFile(context, filePath), {
  36117. filepath: filePath
  36118. }));
  36119. });
  36120. } catch (error) {
  36121. context.logger.error(`Unable to expand glob patterns: ${patterns.join(" ")}\n${error.message}`); // Don't exit the process if one pattern failed
  36122. process.exitCode = 2;
  36123. }
  36124. }
  36125. function formatFiles(context) {
  36126. // The ignorer will be used to filter file paths after the glob is checked,
  36127. // before any files are actually written
  36128. var ignorer = createIgnorerFromContextOrDie(context);
  36129. var numberOfUnformattedFilesFound = 0;
  36130. if (context.argv["check"]) {
  36131. context.logger.log("Checking formatting...");
  36132. }
  36133. eachFilename(context, context.filePatterns, function (filename, options$$2) {
  36134. var fileIgnored = ignorer.filter([filename]).length === 0;
  36135. if (fileIgnored && (context.argv["debug-check"] || context.argv["write"] || context.argv["check"] || context.argv["list-different"])) {
  36136. return;
  36137. }
  36138. if (isTty()) {
  36139. // Don't use `console.log` here since we need to replace this line.
  36140. context.logger.log(filename, {
  36141. newline: false
  36142. });
  36143. }
  36144. var input;
  36145. try {
  36146. input = fs.readFileSync(filename, "utf8");
  36147. } catch (error) {
  36148. // Add newline to split errors from filename line.
  36149. context.logger.log("");
  36150. context.logger.error(`Unable to read file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  36151. process.exitCode = 2;
  36152. return;
  36153. }
  36154. if (fileIgnored) {
  36155. writeOutput(context, {
  36156. formatted: input
  36157. }, options$$2);
  36158. return;
  36159. }
  36160. var start = Date.now();
  36161. var result;
  36162. var output;
  36163. try {
  36164. result = format$1(context, input, Object.assign({}, options$$2, {
  36165. filepath: filename
  36166. }));
  36167. output = result.formatted;
  36168. } catch (error) {
  36169. handleError(context, filename, error);
  36170. return;
  36171. }
  36172. var isDifferent = output !== input;
  36173. if (isTty()) {
  36174. // Remove previously printed filename to log it with duration.
  36175. readline.clearLine(process.stdout, 0);
  36176. readline.cursorTo(process.stdout, 0, null);
  36177. }
  36178. if (context.argv["write"]) {
  36179. // Don't write the file if it won't change in order not to invalidate
  36180. // mtime based caches.
  36181. if (isDifferent) {
  36182. if (!context.argv["check"] && !context.argv["list-different"]) {
  36183. context.logger.log(`${filename} ${Date.now() - start}ms`);
  36184. }
  36185. try {
  36186. fs.writeFileSync(filename, output, "utf8");
  36187. } catch (error) {
  36188. context.logger.error(`Unable to write file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  36189. process.exitCode = 2;
  36190. }
  36191. } else if (!context.argv["check"] && !context.argv["list-different"]) {
  36192. context.logger.log(`${chalk$2.grey(filename)} ${Date.now() - start}ms`);
  36193. }
  36194. } else if (context.argv["debug-check"]) {
  36195. if (result.filepath) {
  36196. context.logger.log(result.filepath);
  36197. } else {
  36198. process.exitCode = 2;
  36199. }
  36200. } else if (!context.argv["check"] && !context.argv["list-different"]) {
  36201. writeOutput(context, result, options$$2);
  36202. }
  36203. if ((context.argv["check"] || context.argv["list-different"]) && isDifferent) {
  36204. context.logger.log(filename);
  36205. numberOfUnformattedFilesFound += 1;
  36206. }
  36207. }); // Print check summary based on expected exit code
  36208. if (context.argv["check"]) {
  36209. 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?");
  36210. } // Ensure non-zero exitCode when using --check/list-different is not combined with --write
  36211. if ((context.argv["check"] || context.argv["list-different"]) && numberOfUnformattedFilesFound > 0 && !process.exitCode && !context.argv["write"]) {
  36212. process.exitCode = 1;
  36213. }
  36214. }
  36215. function getOptionsWithOpposites(options$$2) {
  36216. // Add --no-foo after --foo.
  36217. var optionsWithOpposites = options$$2.map(function (option) {
  36218. return [option.description ? option : null, option.oppositeDescription ? Object.assign({}, option, {
  36219. name: `no-${option.name}`,
  36220. type: "boolean",
  36221. description: option.oppositeDescription
  36222. }) : null];
  36223. });
  36224. return flattenArray(optionsWithOpposites).filter(Boolean);
  36225. }
  36226. function createUsage(context) {
  36227. var options$$2 = getOptionsWithOpposites(context.detailedOptions).filter( // remove unnecessary option (e.g. `semi`, `color`, etc.), which is only used for --help <flag>
  36228. function (option) {
  36229. return !(option.type === "boolean" && option.oppositeDescription && !option.name.startsWith("no-"));
  36230. });
  36231. var groupedOptions = groupBy(options$$2, function (option) {
  36232. return option.category;
  36233. });
  36234. var firstCategories = constant.categoryOrder.slice(0, -1);
  36235. var lastCategories = constant.categoryOrder.slice(-1);
  36236. var restCategories = Object.keys(groupedOptions).filter(function (category) {
  36237. return firstCategories.indexOf(category) === -1 && lastCategories.indexOf(category) === -1;
  36238. });
  36239. var allCategories = firstCategories.concat(restCategories, lastCategories);
  36240. var optionsUsage = allCategories.map(function (category) {
  36241. var categoryOptions = groupedOptions[category].map(function (option) {
  36242. return createOptionUsage(context, option, OPTION_USAGE_THRESHOLD);
  36243. }).join("\n");
  36244. return `${category} options:\n\n${indent$11(categoryOptions, 2)}`;
  36245. });
  36246. return [constant.usageSummary].concat(optionsUsage, [""]).join("\n\n");
  36247. }
  36248. function createOptionUsage(context, option, threshold) {
  36249. var header = createOptionUsageHeader(option);
  36250. var optionDefaultValue = getOptionDefaultValue(context, option.name);
  36251. return createOptionUsageRow(header, `${option.description}${optionDefaultValue === undefined ? "" : `\nDefaults to ${createDefaultValueDisplay(optionDefaultValue)}.`}`, threshold);
  36252. }
  36253. function createDefaultValueDisplay(value) {
  36254. return Array.isArray(value) ? `[${value.map(createDefaultValueDisplay).join(", ")}]` : value;
  36255. }
  36256. function createOptionUsageHeader(option) {
  36257. var name = `--${option.name}`;
  36258. var alias = option.alias ? `-${option.alias},` : null;
  36259. var type = createOptionUsageType(option);
  36260. return [alias, name, type].filter(Boolean).join(" ");
  36261. }
  36262. function createOptionUsageRow(header, content, threshold) {
  36263. var separator = header.length >= threshold ? `\n${" ".repeat(threshold)}` : " ".repeat(threshold - header.length);
  36264. var description = content.replace(/\n/g, `\n${" ".repeat(threshold)}`);
  36265. return `${header}${separator}${description}`;
  36266. }
  36267. function createOptionUsageType(option) {
  36268. switch (option.type) {
  36269. case "boolean":
  36270. return null;
  36271. case "choice":
  36272. return `<${option.choices.filter(function (choice) {
  36273. return choice.since !== null;
  36274. }).filter(function (choice) {
  36275. return !choice.deprecated;
  36276. }).map(function (choice) {
  36277. return choice.value;
  36278. }).join("|")}>`;
  36279. default:
  36280. return `<${option.type}>`;
  36281. }
  36282. }
  36283. function flattenArray(array) {
  36284. return [].concat.apply([], array);
  36285. }
  36286. function createChoiceUsages(choices, margin, indentation) {
  36287. var activeChoices = choices.filter(function (choice) {
  36288. return !choice.deprecated && choice.since !== null;
  36289. });
  36290. var threshold = activeChoices.map(function (choice) {
  36291. return choice.value.length;
  36292. }).reduce(function (current, length) {
  36293. return Math.max(current, length);
  36294. }, 0) + margin;
  36295. return activeChoices.map(function (choice) {
  36296. return indent$11(createOptionUsageRow(choice.value, choice.description, threshold), indentation);
  36297. });
  36298. }
  36299. function createDetailedUsage(context, flag) {
  36300. var option = getOptionsWithOpposites(context.detailedOptions).find(function (option) {
  36301. return option.name === flag || option.alias === flag;
  36302. });
  36303. var header = createOptionUsageHeader(option);
  36304. var description = `\n\n${indent$11(option.description, 2)}`;
  36305. var choices = option.type !== "choice" ? "" : `\n\nValid options:\n\n${createChoiceUsages(option.choices, CHOICE_USAGE_MARGIN, CHOICE_USAGE_INDENTATION).join("\n")}`;
  36306. var optionDefaultValue = getOptionDefaultValue(context, option.name);
  36307. var defaults = optionDefaultValue !== undefined ? `\n\nDefault: ${createDefaultValueDisplay(optionDefaultValue)}` : "";
  36308. var pluginDefaults = option.pluginDefaults && Object.keys(option.pluginDefaults).length ? `\nPlugin defaults:${Object.keys(option.pluginDefaults).map(function (key) {
  36309. return `\n* ${key}: ${createDefaultValueDisplay(option.pluginDefaults[key])}`;
  36310. })}` : "";
  36311. return `${header}${description}${choices}${defaults}${pluginDefaults}`;
  36312. }
  36313. function getOptionDefaultValue(context, optionName) {
  36314. // --no-option
  36315. if (!(optionName in context.detailedOptionMap)) {
  36316. return undefined;
  36317. }
  36318. var option = context.detailedOptionMap[optionName];
  36319. if (option.default !== undefined) {
  36320. return option.default;
  36321. }
  36322. var optionCamelName = camelcase(optionName);
  36323. if (optionCamelName in context.apiDefaultOptions) {
  36324. return context.apiDefaultOptions[optionCamelName];
  36325. }
  36326. return undefined;
  36327. }
  36328. function indent$11(str, spaces) {
  36329. return str.replace(/^/gm, " ".repeat(spaces));
  36330. }
  36331. function groupBy(array, getKey) {
  36332. return array.reduce(function (obj, item) {
  36333. var key = getKey(item);
  36334. var previousItems = key in obj ? obj[key] : [];
  36335. return Object.assign({}, obj, {
  36336. [key]: previousItems.concat(item)
  36337. });
  36338. }, Object.create(null));
  36339. }
  36340. function pick(object, keys) {
  36341. return !keys ? object : keys.reduce(function (reduced, key) {
  36342. return Object.assign(reduced, {
  36343. [key]: object[key]
  36344. });
  36345. }, {});
  36346. }
  36347. function createLogger(logLevel) {
  36348. return {
  36349. warn: createLogFunc("warn", "yellow"),
  36350. error: createLogFunc("error", "red"),
  36351. debug: createLogFunc("debug", "blue"),
  36352. log: createLogFunc("log")
  36353. };
  36354. function createLogFunc(loggerName, color) {
  36355. if (!shouldLog(loggerName)) {
  36356. return function () {};
  36357. }
  36358. var prefix = color ? `[${chalk$2[color](loggerName)}] ` : "";
  36359. return function (message, opts) {
  36360. opts = Object.assign({
  36361. newline: true
  36362. }, opts);
  36363. var stream = process[loggerName === "log" ? "stdout" : "stderr"];
  36364. stream.write(message.replace(/^/gm, prefix) + (opts.newline ? "\n" : ""));
  36365. };
  36366. }
  36367. function shouldLog(loggerName) {
  36368. switch (logLevel) {
  36369. case "silent":
  36370. return false;
  36371. default:
  36372. return true;
  36373. case "debug":
  36374. if (loggerName === "debug") {
  36375. return true;
  36376. }
  36377. // fall through
  36378. case "log":
  36379. if (loggerName === "log") {
  36380. return true;
  36381. }
  36382. // fall through
  36383. case "warn":
  36384. if (loggerName === "warn") {
  36385. return true;
  36386. }
  36387. // fall through
  36388. case "error":
  36389. return loggerName === "error";
  36390. }
  36391. }
  36392. }
  36393. function normalizeDetailedOption(name, option) {
  36394. return Object.assign({
  36395. category: coreOptions$1.CATEGORY_OTHER
  36396. }, option, {
  36397. choices: option.choices && option.choices.map(function (choice) {
  36398. var newChoice = Object.assign({
  36399. description: "",
  36400. deprecated: false
  36401. }, typeof choice === "object" ? choice : {
  36402. value: choice
  36403. });
  36404. if (newChoice.value === true) {
  36405. newChoice.value = ""; // backward compability for original boolean option
  36406. }
  36407. return newChoice;
  36408. })
  36409. });
  36410. }
  36411. function normalizeDetailedOptionMap(detailedOptionMap) {
  36412. return Object.keys(detailedOptionMap).sort().reduce(function (normalized, name) {
  36413. var option = detailedOptionMap[name];
  36414. return Object.assign(normalized, {
  36415. [name]: normalizeDetailedOption(name, option)
  36416. });
  36417. }, {});
  36418. }
  36419. function createMinimistOptions(detailedOptions) {
  36420. return {
  36421. // we use vnopts' AliasSchema to handle aliases for better error messages
  36422. alias: {},
  36423. boolean: detailedOptions.filter(function (option) {
  36424. return option.type === "boolean";
  36425. }).map(function (option) {
  36426. return [option.name].concat(option.alias || []);
  36427. }).reduce(function (a, b) {
  36428. return a.concat(b);
  36429. }),
  36430. string: detailedOptions.filter(function (option) {
  36431. return option.type !== "boolean";
  36432. }).map(function (option) {
  36433. return [option.name].concat(option.alias || []);
  36434. }).reduce(function (a, b) {
  36435. return a.concat(b);
  36436. }),
  36437. default: detailedOptions.filter(function (option) {
  36438. return !option.deprecated;
  36439. }).filter(function (option) {
  36440. return !option.forwardToApi || option.name === "plugin" || option.name === "plugin-search-dir";
  36441. }).filter(function (option) {
  36442. return option.default !== undefined;
  36443. }).reduce(function (current, option) {
  36444. return Object.assign({
  36445. [option.name]: option.default
  36446. }, current);
  36447. }, {})
  36448. };
  36449. }
  36450. function createApiDetailedOptionMap(detailedOptions) {
  36451. return detailedOptions.reduce(function (current, option) {
  36452. return option.forwardToApi && option.forwardToApi !== option.name ? Object.assign(current, {
  36453. [option.forwardToApi]: option
  36454. }) : current;
  36455. }, {});
  36456. }
  36457. function createDetailedOptionMap(supportOptions) {
  36458. return supportOptions.reduce(function (reduced, option) {
  36459. var newOption = Object.assign({}, option, {
  36460. name: option.cliName || dashify(option.name),
  36461. description: option.cliDescription || option.description,
  36462. category: option.cliCategory || coreOptions$1.CATEGORY_FORMAT,
  36463. forwardToApi: option.name
  36464. });
  36465. if (option.deprecated) {
  36466. delete newOption.forwardToApi;
  36467. delete newOption.description;
  36468. delete newOption.oppositeDescription;
  36469. newOption.deprecated = true;
  36470. }
  36471. return Object.assign(reduced, {
  36472. [newOption.name]: newOption
  36473. });
  36474. }, {});
  36475. } //-----------------------------context-util-start-------------------------------
  36476. /**
  36477. * @typedef {Object} Context
  36478. * @property logger
  36479. * @property args
  36480. * @property argv
  36481. * @property filePatterns
  36482. * @property supportOptions
  36483. * @property detailedOptions
  36484. * @property detailedOptionMap
  36485. * @property apiDefaultOptions
  36486. */
  36487. function createContext(args) {
  36488. var context = {
  36489. args
  36490. };
  36491. updateContextArgv(context);
  36492. normalizeContextArgv(context, ["loglevel", "plugin", "plugin-search-dir"]);
  36493. context.logger = createLogger(context.argv["loglevel"]);
  36494. updateContextArgv(context, context.argv["plugin"], context.argv["plugin-search-dir"]);
  36495. return context;
  36496. }
  36497. function initContext(context) {
  36498. // split into 2 step so that we could wrap this in a `try..catch` in cli/index.js
  36499. normalizeContextArgv(context);
  36500. }
  36501. function updateContextOptions(context, plugins, pluginSearchDirs) {
  36502. var supportOptions = prettier$2.getSupportInfo(null, {
  36503. showDeprecated: true,
  36504. showUnreleased: true,
  36505. showInternal: true,
  36506. plugins,
  36507. pluginSearchDirs
  36508. }).options;
  36509. var detailedOptionMap = normalizeDetailedOptionMap(Object.assign({}, createDetailedOptionMap(supportOptions), constant.options));
  36510. var detailedOptions = arrayify(detailedOptionMap, "name");
  36511. var apiDefaultOptions = supportOptions.filter(function (optionInfo) {
  36512. return !optionInfo.deprecated;
  36513. }).reduce(function (reduced, optionInfo) {
  36514. return Object.assign(reduced, {
  36515. [optionInfo.name]: optionInfo.default
  36516. });
  36517. }, Object.assign({}, options.hiddenDefaults));
  36518. context.supportOptions = supportOptions;
  36519. context.detailedOptions = detailedOptions;
  36520. context.detailedOptionMap = detailedOptionMap;
  36521. context.apiDefaultOptions = apiDefaultOptions;
  36522. }
  36523. function pushContextPlugins(context, plugins, pluginSearchDirs) {
  36524. context._supportOptions = context.supportOptions;
  36525. context._detailedOptions = context.detailedOptions;
  36526. context._detailedOptionMap = context.detailedOptionMap;
  36527. context._apiDefaultOptions = context.apiDefaultOptions;
  36528. updateContextOptions(context, plugins, pluginSearchDirs);
  36529. }
  36530. function popContextPlugins(context) {
  36531. context.supportOptions = context._supportOptions;
  36532. context.detailedOptions = context._detailedOptions;
  36533. context.detailedOptionMap = context._detailedOptionMap;
  36534. context.apiDefaultOptions = context._apiDefaultOptions;
  36535. }
  36536. function updateContextArgv(context, plugins, pluginSearchDirs) {
  36537. pushContextPlugins(context, plugins, pluginSearchDirs);
  36538. var minimistOptions = createMinimistOptions(context.detailedOptions);
  36539. var argv = minimist_1(context.args, minimistOptions);
  36540. context.argv = argv;
  36541. context.filePatterns = argv["_"];
  36542. }
  36543. function normalizeContextArgv(context, keys) {
  36544. var detailedOptions = !keys ? context.detailedOptions : context.detailedOptions.filter(function (option) {
  36545. return keys.indexOf(option.name) !== -1;
  36546. });
  36547. var argv = !keys ? context.argv : pick(context.argv, keys);
  36548. context.argv = optionsNormalizer.normalizeCliOptions(argv, detailedOptions, {
  36549. logger: context.logger
  36550. });
  36551. } //------------------------------context-util-end--------------------------------
  36552. var util$5 = {
  36553. createContext,
  36554. createDetailedOptionMap,
  36555. createDetailedUsage,
  36556. createUsage,
  36557. format: format$1,
  36558. formatFiles,
  36559. formatStdin,
  36560. initContext,
  36561. logResolvedConfigPathOrDie,
  36562. logFileInfoOrDie,
  36563. normalizeDetailedOptionMap
  36564. };
  36565. function run(args) {
  36566. var context = util$5.createContext(args);
  36567. try {
  36568. util$5.initContext(context);
  36569. context.logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
  36570. if (context.argv["check"] && context.argv["list-different"]) {
  36571. context.logger.error("Cannot use --check and --list-different together.");
  36572. process.exit(1);
  36573. }
  36574. if (context.argv["write"] && context.argv["debug-check"]) {
  36575. context.logger.error("Cannot use --write and --debug-check together.");
  36576. process.exit(1);
  36577. }
  36578. if (context.argv["find-config-path"] && context.filePatterns.length) {
  36579. context.logger.error("Cannot use --find-config-path with multiple files");
  36580. process.exit(1);
  36581. }
  36582. if (context.argv["file-info"] && context.filePatterns.length) {
  36583. context.logger.error("Cannot use --file-info with multiple files");
  36584. process.exit(1);
  36585. }
  36586. if (context.argv["version"]) {
  36587. context.logger.log(prettier$2.version);
  36588. process.exit(0);
  36589. }
  36590. if (context.argv["help"] !== undefined) {
  36591. context.logger.log(typeof context.argv["help"] === "string" && context.argv["help"] !== "" ? util$5.createDetailedUsage(context, context.argv["help"]) : util$5.createUsage(context));
  36592. process.exit(0);
  36593. }
  36594. if (context.argv["support-info"]) {
  36595. context.logger.log(prettier$2.format(jsonStableStringify(prettier$2.getSupportInfo()), {
  36596. parser: "json"
  36597. }));
  36598. process.exit(0);
  36599. }
  36600. var hasFilePatterns = context.filePatterns.length !== 0;
  36601. var useStdin = context.argv["stdin"] || !hasFilePatterns && !process.stdin.isTTY;
  36602. if (context.argv["find-config-path"]) {
  36603. util$5.logResolvedConfigPathOrDie(context);
  36604. } else if (context.argv["file-info"]) {
  36605. util$5.logFileInfoOrDie(context);
  36606. } else if (useStdin) {
  36607. util$5.formatStdin(context);
  36608. } else if (hasFilePatterns) {
  36609. util$5.formatFiles(context);
  36610. } else {
  36611. context.logger.log(util$5.createUsage(context));
  36612. process.exit(1);
  36613. }
  36614. } catch (error) {
  36615. context.logger.error(error.message);
  36616. process.exit(1);
  36617. }
  36618. }
  36619. var cli = {
  36620. run
  36621. };
  36622. cli.run(process.argv.slice(2));
  36623. var prettier = {};
  36624. module.exports = prettier;