third-party.js 315 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712
  1. 'use strict';
  2. var require$$0$3 = require('os');
  3. var require$$0$1 = require('path');
  4. var require$$1$1 = require('module');
  5. var require$$1 = require('fs');
  6. var require$$0$2 = require('util');
  7. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  8. var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
  9. var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
  10. var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
  11. var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
  12. var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
  13. var dist$2 = {};
  14. var Explorer$1 = {};
  15. var ExplorerBase$1 = {};
  16. var loaders$1 = {};
  17. var resolveFrom$2 = {exports: {}};
  18. const path$1 = require$$0__default["default"];
  19. const Module = require$$1__default$1["default"];
  20. const fs$1 = require$$1__default["default"];
  21. const resolveFrom$1 = (fromDir, moduleId, silent) => {
  22. if (typeof fromDir !== 'string') {
  23. throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
  24. }
  25. if (typeof moduleId !== 'string') {
  26. throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
  27. }
  28. try {
  29. fromDir = fs$1.realpathSync(fromDir);
  30. } catch (err) {
  31. if (err.code === 'ENOENT') {
  32. fromDir = path$1.resolve(fromDir);
  33. } else if (silent) {
  34. return null;
  35. } else {
  36. throw err;
  37. }
  38. }
  39. const fromFile = path$1.join(fromDir, 'noop.js');
  40. const resolveFileName = () => Module._resolveFilename(moduleId, {
  41. id: fromFile,
  42. filename: fromFile,
  43. paths: Module._nodeModulePaths(fromDir)
  44. });
  45. if (silent) {
  46. try {
  47. return resolveFileName();
  48. } catch (err) {
  49. return null;
  50. }
  51. }
  52. return resolveFileName();
  53. };
  54. resolveFrom$2.exports = (fromDir, moduleId) => resolveFrom$1(fromDir, moduleId);
  55. resolveFrom$2.exports.silent = (fromDir, moduleId) => resolveFrom$1(fromDir, moduleId, true);
  56. var callsites$1 = {exports: {}};
  57. const callsites = () => {
  58. const _prepareStackTrace = Error.prepareStackTrace;
  59. Error.prepareStackTrace = (_, stack) => stack;
  60. const stack = new Error().stack.slice(1);
  61. Error.prepareStackTrace = _prepareStackTrace;
  62. return stack;
  63. };
  64. callsites$1.exports = callsites; // TODO: Remove this for the next major release
  65. callsites$1.exports.default = callsites;
  66. const path = require$$0__default["default"];
  67. const resolveFrom = resolveFrom$2.exports;
  68. var importFresh$1 = moduleId => {
  69. if (typeof moduleId !== 'string') {
  70. throw new TypeError('Expected a string');
  71. }
  72. const parentPath = __filename;
  73. const cwd = parentPath ? path.dirname(parentPath) : __dirname;
  74. const filePath = resolveFrom(cwd, moduleId);
  75. const oldModule = require.cache[filePath]; // Delete itself from module parent
  76. if (oldModule && oldModule.parent) {
  77. let i = oldModule.parent.children.length;
  78. while (i--) {
  79. if (oldModule.parent.children[i].id === filePath) {
  80. oldModule.parent.children.splice(i, 1);
  81. }
  82. }
  83. }
  84. delete require.cache[filePath]; // Delete module from cache
  85. const parent = require.cache[parentPath]; // If `filePath` and `parentPath` are the same, cache will already be deleted so we won't get a memory leak in next step
  86. return parent === undefined ? require(filePath) : parent.require(filePath); // In case cache doesn't have parent, fall back to normal require
  87. };
  88. var isArrayish$1 = function isArrayish(obj) {
  89. if (!obj) {
  90. return false;
  91. }
  92. return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && obj.splice instanceof Function;
  93. };
  94. var util = require$$0__default$1["default"];
  95. var isArrayish = isArrayish$1;
  96. var errorEx$1 = function errorEx(name, properties) {
  97. if (!name || name.constructor !== String) {
  98. properties = name || {};
  99. name = Error.name;
  100. }
  101. var errorExError = function ErrorEXError(message) {
  102. if (!this) {
  103. return new ErrorEXError(message);
  104. }
  105. message = message instanceof Error ? message.message : message || this.message;
  106. Error.call(this, message);
  107. Error.captureStackTrace(this, errorExError);
  108. this.name = name;
  109. Object.defineProperty(this, 'message', {
  110. configurable: true,
  111. enumerable: false,
  112. get: function () {
  113. var newMessage = message.split(/\r?\n/g);
  114. for (var key in properties) {
  115. if (!properties.hasOwnProperty(key)) {
  116. continue;
  117. }
  118. var modifier = properties[key];
  119. if ('message' in modifier) {
  120. newMessage = modifier.message(this[key], newMessage) || newMessage;
  121. if (!isArrayish(newMessage)) {
  122. newMessage = [newMessage];
  123. }
  124. }
  125. }
  126. return newMessage.join('\n');
  127. },
  128. set: function (v) {
  129. message = v;
  130. }
  131. });
  132. var overwrittenStack = null;
  133. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  134. var stackGetter = stackDescriptor.get;
  135. var stackValue = stackDescriptor.value;
  136. delete stackDescriptor.value;
  137. delete stackDescriptor.writable;
  138. stackDescriptor.set = function (newstack) {
  139. overwrittenStack = newstack;
  140. };
  141. stackDescriptor.get = function () {
  142. var stack = (overwrittenStack || (stackGetter ? stackGetter.call(this) : stackValue)).split(/\r?\n+/g); // starting in Node 7, the stack builder caches the message.
  143. // just replace it.
  144. if (!overwrittenStack) {
  145. stack[0] = this.name + ': ' + this.message;
  146. }
  147. var lineCount = 1;
  148. for (var key in properties) {
  149. if (!properties.hasOwnProperty(key)) {
  150. continue;
  151. }
  152. var modifier = properties[key];
  153. if ('line' in modifier) {
  154. var line = modifier.line(this[key]);
  155. if (line) {
  156. stack.splice(lineCount++, 0, ' ' + line);
  157. }
  158. }
  159. if ('stack' in modifier) {
  160. modifier.stack(this[key], stack);
  161. }
  162. }
  163. return stack.join('\n');
  164. };
  165. Object.defineProperty(this, 'stack', stackDescriptor);
  166. };
  167. if (Object.setPrototypeOf) {
  168. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  169. Object.setPrototypeOf(errorExError, Error);
  170. } else {
  171. util.inherits(errorExError, Error);
  172. }
  173. return errorExError;
  174. };
  175. errorEx$1.append = function (str, def) {
  176. return {
  177. message: function (v, message) {
  178. v = v || def;
  179. if (v) {
  180. message[0] += ' ' + str.replace('%s', v.toString());
  181. }
  182. return message;
  183. }
  184. };
  185. };
  186. errorEx$1.line = function (str, def) {
  187. return {
  188. line: function (v) {
  189. v = v || def;
  190. if (v) {
  191. return str.replace('%s', v.toString());
  192. }
  193. return null;
  194. }
  195. };
  196. };
  197. var errorEx_1 = errorEx$1;
  198. const hexify = char => {
  199. const h = char.charCodeAt(0).toString(16).toUpperCase();
  200. return '0x' + (h.length % 2 ? '0' : '') + h;
  201. };
  202. const parseError = (e, txt, context) => {
  203. if (!txt) {
  204. return {
  205. message: e.message + ' while parsing empty string',
  206. position: 0
  207. };
  208. }
  209. const badToken = e.message.match(/^Unexpected token (.) .*position\s+(\d+)/i);
  210. const errIdx = badToken ? +badToken[2] : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 : null;
  211. const msg = badToken ? e.message.replace(/^Unexpected token ./, `Unexpected token ${JSON.stringify(badToken[1])} (${hexify(badToken[1])})`) : e.message;
  212. if (errIdx !== null && errIdx !== undefined) {
  213. const start = errIdx <= context ? 0 : errIdx - context;
  214. const end = errIdx + context >= txt.length ? txt.length : errIdx + context;
  215. const slice = (start === 0 ? '' : '...') + txt.slice(start, end) + (end === txt.length ? '' : '...');
  216. const near = txt === slice ? '' : 'near ';
  217. return {
  218. message: msg + ` while parsing ${near}${JSON.stringify(slice)}`,
  219. position: errIdx
  220. };
  221. } else {
  222. return {
  223. message: msg + ` while parsing '${txt.slice(0, context * 2)}'`,
  224. position: 0
  225. };
  226. }
  227. };
  228. class JSONParseError extends SyntaxError {
  229. constructor(er, txt, context, caller) {
  230. context = context || 20;
  231. const metadata = parseError(er, txt, context);
  232. super(metadata.message);
  233. Object.assign(this, metadata);
  234. this.code = 'EJSONPARSE';
  235. this.systemError = er;
  236. Error.captureStackTrace(this, caller || this.constructor);
  237. }
  238. get name() {
  239. return this.constructor.name;
  240. }
  241. set name(n) {}
  242. get [Symbol.toStringTag]() {
  243. return this.constructor.name;
  244. }
  245. }
  246. const kIndent = Symbol.for('indent');
  247. const kNewline = Symbol.for('newline'); // only respect indentation if we got a line break, otherwise squash it
  248. // things other than objects and arrays aren't indented, so ignore those
  249. // Important: in both of these regexps, the $1 capture group is the newline
  250. // or undefined, and the $2 capture group is the indent, or undefined.
  251. const formatRE = /^\s*[{\[]((?:\r?\n)+)([\s\t]*)/;
  252. const emptyRE = /^(?:\{\}|\[\])((?:\r?\n)+)?$/;
  253. const parseJson$2 = (txt, reviver, context) => {
  254. const parseText = stripBOM(txt);
  255. context = context || 20;
  256. try {
  257. // get the indentation so that we can save it back nicely
  258. // if the file starts with {" then we have an indent of '', ie, none
  259. // otherwise, pick the indentation of the next line after the first \n
  260. // If the pattern doesn't match, then it means no indentation.
  261. // JSON.stringify ignores symbols, so this is reasonably safe.
  262. // if the string is '{}' or '[]', then use the default 2-space indent.
  263. const [, newline = '\n', indent = ' '] = parseText.match(emptyRE) || parseText.match(formatRE) || [, '', ''];
  264. const result = JSON.parse(parseText, reviver);
  265. if (result && typeof result === 'object') {
  266. result[kNewline] = newline;
  267. result[kIndent] = indent;
  268. }
  269. return result;
  270. } catch (e) {
  271. if (typeof txt !== 'string' && !Buffer.isBuffer(txt)) {
  272. const isEmptyArray = Array.isArray(txt) && txt.length === 0;
  273. throw Object.assign(new TypeError(`Cannot parse ${isEmptyArray ? 'an empty array' : String(txt)}`), {
  274. code: 'EJSONPARSE',
  275. systemError: e
  276. });
  277. }
  278. throw new JSONParseError(e, parseText, context, parseJson$2);
  279. }
  280. }; // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  281. // because the buffer-to-string conversion in `fs.readFileSync()`
  282. // translates it to FEFF, the UTF-16 BOM.
  283. const stripBOM = txt => String(txt).replace(/^\uFEFF/, '');
  284. var jsonParseEvenBetterErrors = parseJson$2;
  285. parseJson$2.JSONParseError = JSONParseError;
  286. parseJson$2.noExceptions = (txt, reviver) => {
  287. try {
  288. return JSON.parse(stripBOM(txt), reviver);
  289. } catch (e) {}
  290. };
  291. var dist$1 = {};
  292. (function (exports) {
  293. var LF = '\n';
  294. var CR = '\r';
  295. var LinesAndColumns = function () {
  296. function LinesAndColumns(string) {
  297. this.string = string;
  298. var offsets = [0];
  299. for (var offset = 0; offset < string.length;) {
  300. switch (string[offset]) {
  301. case LF:
  302. offset += LF.length;
  303. offsets.push(offset);
  304. break;
  305. case CR:
  306. offset += CR.length;
  307. if (string[offset] === LF) {
  308. offset += LF.length;
  309. }
  310. offsets.push(offset);
  311. break;
  312. default:
  313. offset++;
  314. break;
  315. }
  316. }
  317. this.offsets = offsets;
  318. }
  319. LinesAndColumns.prototype.locationForIndex = function (index) {
  320. if (index < 0 || index > this.string.length) {
  321. return null;
  322. }
  323. var line = 0;
  324. var offsets = this.offsets;
  325. while (offsets[line + 1] <= index) {
  326. line++;
  327. }
  328. var column = index - offsets[line];
  329. return {
  330. line: line,
  331. column: column
  332. };
  333. };
  334. LinesAndColumns.prototype.indexForLocation = function (location) {
  335. var line = location.line,
  336. column = location.column;
  337. if (line < 0 || line >= this.offsets.length) {
  338. return null;
  339. }
  340. if (column < 0 || column > this.lengthOfLine(line)) {
  341. return null;
  342. }
  343. return this.offsets[line] + column;
  344. };
  345. LinesAndColumns.prototype.lengthOfLine = function (line) {
  346. var offset = this.offsets[line];
  347. var nextOffset = line === this.offsets.length - 1 ? this.string.length : this.offsets[line + 1];
  348. return nextOffset - offset;
  349. };
  350. return LinesAndColumns;
  351. }();
  352. exports.__esModule = true;
  353. exports["default"] = LinesAndColumns;
  354. })(dist$1);
  355. var lib$2 = {};
  356. var lib$1 = {};
  357. var jsTokens = {};
  358. // License: MIT. (See LICENSE.)
  359. Object.defineProperty(jsTokens, "__esModule", {
  360. value: true
  361. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  362. // (run `npm run build`).
  363. jsTokens.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
  364. jsTokens.matchToToken = function (match) {
  365. var token = {
  366. type: "invalid",
  367. value: match[0],
  368. closed: undefined
  369. };
  370. 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";
  371. return token;
  372. };
  373. var lib = {};
  374. var identifier = {};
  375. Object.defineProperty(identifier, "__esModule", {
  376. value: true
  377. });
  378. identifier.isIdentifierStart = isIdentifierStart;
  379. identifier.isIdentifierChar = isIdentifierChar;
  380. identifier.isIdentifierName = isIdentifierName;
  381. let nonASCIIidentifierStartChars = "\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\u0560-\u0588\u05d0-\u05ea\u05ef-\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\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\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\u09fc\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\u0af9\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-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\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-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\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-\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-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ca\ua7d0\ua7d1\ua7d3\ua7d5-\ua7d9\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\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-\uab69\uab70-\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";
  382. let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0898-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  383. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  384. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  385. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  386. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 68, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 190, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1070, 4050, 582, 8634, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8936, 3, 2, 6, 2, 1, 2, 290, 46, 2, 18, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 482, 44, 11, 6, 17, 0, 322, 29, 19, 43, 1269, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4152, 8, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938];
  387. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 357, 0, 62, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  388. function isInAstralSet(code, set) {
  389. let pos = 0x10000;
  390. for (let i = 0, length = set.length; i < length; i += 2) {
  391. pos += set[i];
  392. if (pos > code) return false;
  393. pos += set[i + 1];
  394. if (pos >= code) return true;
  395. }
  396. return false;
  397. }
  398. function isIdentifierStart(code) {
  399. if (code < 65) return code === 36;
  400. if (code <= 90) return true;
  401. if (code < 97) return code === 95;
  402. if (code <= 122) return true;
  403. if (code <= 0xffff) {
  404. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  405. }
  406. return isInAstralSet(code, astralIdentifierStartCodes);
  407. }
  408. function isIdentifierChar(code) {
  409. if (code < 48) return code === 36;
  410. if (code < 58) return true;
  411. if (code < 65) return false;
  412. if (code <= 90) return true;
  413. if (code < 97) return code === 95;
  414. if (code <= 122) return true;
  415. if (code <= 0xffff) {
  416. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  417. }
  418. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  419. }
  420. function isIdentifierName(name) {
  421. let isFirst = true;
  422. for (let i = 0; i < name.length; i++) {
  423. let cp = name.charCodeAt(i);
  424. if ((cp & 0xfc00) === 0xd800 && i + 1 < name.length) {
  425. const trail = name.charCodeAt(++i);
  426. if ((trail & 0xfc00) === 0xdc00) {
  427. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  428. }
  429. }
  430. if (isFirst) {
  431. isFirst = false;
  432. if (!isIdentifierStart(cp)) {
  433. return false;
  434. }
  435. } else if (!isIdentifierChar(cp)) {
  436. return false;
  437. }
  438. }
  439. return !isFirst;
  440. }
  441. var keyword = {};
  442. Object.defineProperty(keyword, "__esModule", {
  443. value: true
  444. });
  445. keyword.isReservedWord = isReservedWord;
  446. keyword.isStrictReservedWord = isStrictReservedWord;
  447. keyword.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord;
  448. keyword.isStrictBindReservedWord = isStrictBindReservedWord;
  449. keyword.isKeyword = isKeyword;
  450. const reservedWords = {
  451. keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
  452. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  453. strictBind: ["eval", "arguments"]
  454. };
  455. const keywords = new Set(reservedWords.keyword);
  456. const reservedWordsStrictSet = new Set(reservedWords.strict);
  457. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  458. function isReservedWord(word, inModule) {
  459. return inModule && word === "await" || word === "enum";
  460. }
  461. function isStrictReservedWord(word, inModule) {
  462. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  463. }
  464. function isStrictBindOnlyReservedWord(word) {
  465. return reservedWordsStrictBindSet.has(word);
  466. }
  467. function isStrictBindReservedWord(word, inModule) {
  468. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  469. }
  470. function isKeyword(word) {
  471. return keywords.has(word);
  472. }
  473. (function (exports) {
  474. Object.defineProperty(exports, "__esModule", {
  475. value: true
  476. });
  477. Object.defineProperty(exports, "isIdentifierName", {
  478. enumerable: true,
  479. get: function () {
  480. return _identifier.isIdentifierName;
  481. }
  482. });
  483. Object.defineProperty(exports, "isIdentifierChar", {
  484. enumerable: true,
  485. get: function () {
  486. return _identifier.isIdentifierChar;
  487. }
  488. });
  489. Object.defineProperty(exports, "isIdentifierStart", {
  490. enumerable: true,
  491. get: function () {
  492. return _identifier.isIdentifierStart;
  493. }
  494. });
  495. Object.defineProperty(exports, "isReservedWord", {
  496. enumerable: true,
  497. get: function () {
  498. return _keyword.isReservedWord;
  499. }
  500. });
  501. Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
  502. enumerable: true,
  503. get: function () {
  504. return _keyword.isStrictBindOnlyReservedWord;
  505. }
  506. });
  507. Object.defineProperty(exports, "isStrictBindReservedWord", {
  508. enumerable: true,
  509. get: function () {
  510. return _keyword.isStrictBindReservedWord;
  511. }
  512. });
  513. Object.defineProperty(exports, "isStrictReservedWord", {
  514. enumerable: true,
  515. get: function () {
  516. return _keyword.isStrictReservedWord;
  517. }
  518. });
  519. Object.defineProperty(exports, "isKeyword", {
  520. enumerable: true,
  521. get: function () {
  522. return _keyword.isKeyword;
  523. }
  524. });
  525. var _identifier = identifier;
  526. var _keyword = keyword;
  527. })(lib);
  528. var chalk = {exports: {}};
  529. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  530. var escapeStringRegexp = function (str) {
  531. if (typeof str !== 'string') {
  532. throw new TypeError('Expected a string');
  533. }
  534. return str.replace(matchOperatorsRe, '\\$&');
  535. };
  536. var ansiStyles = {exports: {}};
  537. var conversions$2 = {exports: {}};
  538. var colorName = {
  539. "aliceblue": [240, 248, 255],
  540. "antiquewhite": [250, 235, 215],
  541. "aqua": [0, 255, 255],
  542. "aquamarine": [127, 255, 212],
  543. "azure": [240, 255, 255],
  544. "beige": [245, 245, 220],
  545. "bisque": [255, 228, 196],
  546. "black": [0, 0, 0],
  547. "blanchedalmond": [255, 235, 205],
  548. "blue": [0, 0, 255],
  549. "blueviolet": [138, 43, 226],
  550. "brown": [165, 42, 42],
  551. "burlywood": [222, 184, 135],
  552. "cadetblue": [95, 158, 160],
  553. "chartreuse": [127, 255, 0],
  554. "chocolate": [210, 105, 30],
  555. "coral": [255, 127, 80],
  556. "cornflowerblue": [100, 149, 237],
  557. "cornsilk": [255, 248, 220],
  558. "crimson": [220, 20, 60],
  559. "cyan": [0, 255, 255],
  560. "darkblue": [0, 0, 139],
  561. "darkcyan": [0, 139, 139],
  562. "darkgoldenrod": [184, 134, 11],
  563. "darkgray": [169, 169, 169],
  564. "darkgreen": [0, 100, 0],
  565. "darkgrey": [169, 169, 169],
  566. "darkkhaki": [189, 183, 107],
  567. "darkmagenta": [139, 0, 139],
  568. "darkolivegreen": [85, 107, 47],
  569. "darkorange": [255, 140, 0],
  570. "darkorchid": [153, 50, 204],
  571. "darkred": [139, 0, 0],
  572. "darksalmon": [233, 150, 122],
  573. "darkseagreen": [143, 188, 143],
  574. "darkslateblue": [72, 61, 139],
  575. "darkslategray": [47, 79, 79],
  576. "darkslategrey": [47, 79, 79],
  577. "darkturquoise": [0, 206, 209],
  578. "darkviolet": [148, 0, 211],
  579. "deeppink": [255, 20, 147],
  580. "deepskyblue": [0, 191, 255],
  581. "dimgray": [105, 105, 105],
  582. "dimgrey": [105, 105, 105],
  583. "dodgerblue": [30, 144, 255],
  584. "firebrick": [178, 34, 34],
  585. "floralwhite": [255, 250, 240],
  586. "forestgreen": [34, 139, 34],
  587. "fuchsia": [255, 0, 255],
  588. "gainsboro": [220, 220, 220],
  589. "ghostwhite": [248, 248, 255],
  590. "gold": [255, 215, 0],
  591. "goldenrod": [218, 165, 32],
  592. "gray": [128, 128, 128],
  593. "green": [0, 128, 0],
  594. "greenyellow": [173, 255, 47],
  595. "grey": [128, 128, 128],
  596. "honeydew": [240, 255, 240],
  597. "hotpink": [255, 105, 180],
  598. "indianred": [205, 92, 92],
  599. "indigo": [75, 0, 130],
  600. "ivory": [255, 255, 240],
  601. "khaki": [240, 230, 140],
  602. "lavender": [230, 230, 250],
  603. "lavenderblush": [255, 240, 245],
  604. "lawngreen": [124, 252, 0],
  605. "lemonchiffon": [255, 250, 205],
  606. "lightblue": [173, 216, 230],
  607. "lightcoral": [240, 128, 128],
  608. "lightcyan": [224, 255, 255],
  609. "lightgoldenrodyellow": [250, 250, 210],
  610. "lightgray": [211, 211, 211],
  611. "lightgreen": [144, 238, 144],
  612. "lightgrey": [211, 211, 211],
  613. "lightpink": [255, 182, 193],
  614. "lightsalmon": [255, 160, 122],
  615. "lightseagreen": [32, 178, 170],
  616. "lightskyblue": [135, 206, 250],
  617. "lightslategray": [119, 136, 153],
  618. "lightslategrey": [119, 136, 153],
  619. "lightsteelblue": [176, 196, 222],
  620. "lightyellow": [255, 255, 224],
  621. "lime": [0, 255, 0],
  622. "limegreen": [50, 205, 50],
  623. "linen": [250, 240, 230],
  624. "magenta": [255, 0, 255],
  625. "maroon": [128, 0, 0],
  626. "mediumaquamarine": [102, 205, 170],
  627. "mediumblue": [0, 0, 205],
  628. "mediumorchid": [186, 85, 211],
  629. "mediumpurple": [147, 112, 219],
  630. "mediumseagreen": [60, 179, 113],
  631. "mediumslateblue": [123, 104, 238],
  632. "mediumspringgreen": [0, 250, 154],
  633. "mediumturquoise": [72, 209, 204],
  634. "mediumvioletred": [199, 21, 133],
  635. "midnightblue": [25, 25, 112],
  636. "mintcream": [245, 255, 250],
  637. "mistyrose": [255, 228, 225],
  638. "moccasin": [255, 228, 181],
  639. "navajowhite": [255, 222, 173],
  640. "navy": [0, 0, 128],
  641. "oldlace": [253, 245, 230],
  642. "olive": [128, 128, 0],
  643. "olivedrab": [107, 142, 35],
  644. "orange": [255, 165, 0],
  645. "orangered": [255, 69, 0],
  646. "orchid": [218, 112, 214],
  647. "palegoldenrod": [238, 232, 170],
  648. "palegreen": [152, 251, 152],
  649. "paleturquoise": [175, 238, 238],
  650. "palevioletred": [219, 112, 147],
  651. "papayawhip": [255, 239, 213],
  652. "peachpuff": [255, 218, 185],
  653. "peru": [205, 133, 63],
  654. "pink": [255, 192, 203],
  655. "plum": [221, 160, 221],
  656. "powderblue": [176, 224, 230],
  657. "purple": [128, 0, 128],
  658. "rebeccapurple": [102, 51, 153],
  659. "red": [255, 0, 0],
  660. "rosybrown": [188, 143, 143],
  661. "royalblue": [65, 105, 225],
  662. "saddlebrown": [139, 69, 19],
  663. "salmon": [250, 128, 114],
  664. "sandybrown": [244, 164, 96],
  665. "seagreen": [46, 139, 87],
  666. "seashell": [255, 245, 238],
  667. "sienna": [160, 82, 45],
  668. "silver": [192, 192, 192],
  669. "skyblue": [135, 206, 235],
  670. "slateblue": [106, 90, 205],
  671. "slategray": [112, 128, 144],
  672. "slategrey": [112, 128, 144],
  673. "snow": [255, 250, 250],
  674. "springgreen": [0, 255, 127],
  675. "steelblue": [70, 130, 180],
  676. "tan": [210, 180, 140],
  677. "teal": [0, 128, 128],
  678. "thistle": [216, 191, 216],
  679. "tomato": [255, 99, 71],
  680. "turquoise": [64, 224, 208],
  681. "violet": [238, 130, 238],
  682. "wheat": [245, 222, 179],
  683. "white": [255, 255, 255],
  684. "whitesmoke": [245, 245, 245],
  685. "yellow": [255, 255, 0],
  686. "yellowgreen": [154, 205, 50]
  687. };
  688. /* MIT license */
  689. var cssKeywords = colorName; // NOTE: conversions should only return primitive values (i.e. arrays, or
  690. // values that give correct `typeof` results).
  691. // do not use box values types (i.e. Number(), String(), etc.)
  692. var reverseKeywords = {};
  693. for (var key in cssKeywords) {
  694. if (cssKeywords.hasOwnProperty(key)) {
  695. reverseKeywords[cssKeywords[key]] = key;
  696. }
  697. }
  698. var convert$1 = conversions$2.exports = {
  699. rgb: {
  700. channels: 3,
  701. labels: 'rgb'
  702. },
  703. hsl: {
  704. channels: 3,
  705. labels: 'hsl'
  706. },
  707. hsv: {
  708. channels: 3,
  709. labels: 'hsv'
  710. },
  711. hwb: {
  712. channels: 3,
  713. labels: 'hwb'
  714. },
  715. cmyk: {
  716. channels: 4,
  717. labels: 'cmyk'
  718. },
  719. xyz: {
  720. channels: 3,
  721. labels: 'xyz'
  722. },
  723. lab: {
  724. channels: 3,
  725. labels: 'lab'
  726. },
  727. lch: {
  728. channels: 3,
  729. labels: 'lch'
  730. },
  731. hex: {
  732. channels: 1,
  733. labels: ['hex']
  734. },
  735. keyword: {
  736. channels: 1,
  737. labels: ['keyword']
  738. },
  739. ansi16: {
  740. channels: 1,
  741. labels: ['ansi16']
  742. },
  743. ansi256: {
  744. channels: 1,
  745. labels: ['ansi256']
  746. },
  747. hcg: {
  748. channels: 3,
  749. labels: ['h', 'c', 'g']
  750. },
  751. apple: {
  752. channels: 3,
  753. labels: ['r16', 'g16', 'b16']
  754. },
  755. gray: {
  756. channels: 1,
  757. labels: ['gray']
  758. }
  759. }; // hide .channels and .labels properties
  760. for (var model in convert$1) {
  761. if (convert$1.hasOwnProperty(model)) {
  762. if (!('channels' in convert$1[model])) {
  763. throw new Error('missing channels property: ' + model);
  764. }
  765. if (!('labels' in convert$1[model])) {
  766. throw new Error('missing channel labels property: ' + model);
  767. }
  768. if (convert$1[model].labels.length !== convert$1[model].channels) {
  769. throw new Error('channel and label counts mismatch: ' + model);
  770. }
  771. var channels = convert$1[model].channels;
  772. var labels = convert$1[model].labels;
  773. delete convert$1[model].channels;
  774. delete convert$1[model].labels;
  775. Object.defineProperty(convert$1[model], 'channels', {
  776. value: channels
  777. });
  778. Object.defineProperty(convert$1[model], 'labels', {
  779. value: labels
  780. });
  781. }
  782. }
  783. convert$1.rgb.hsl = function (rgb) {
  784. var r = rgb[0] / 255;
  785. var g = rgb[1] / 255;
  786. var b = rgb[2] / 255;
  787. var min = Math.min(r, g, b);
  788. var max = Math.max(r, g, b);
  789. var delta = max - min;
  790. var h;
  791. var s;
  792. var l;
  793. if (max === min) {
  794. h = 0;
  795. } else if (r === max) {
  796. h = (g - b) / delta;
  797. } else if (g === max) {
  798. h = 2 + (b - r) / delta;
  799. } else if (b === max) {
  800. h = 4 + (r - g) / delta;
  801. }
  802. h = Math.min(h * 60, 360);
  803. if (h < 0) {
  804. h += 360;
  805. }
  806. l = (min + max) / 2;
  807. if (max === min) {
  808. s = 0;
  809. } else if (l <= 0.5) {
  810. s = delta / (max + min);
  811. } else {
  812. s = delta / (2 - max - min);
  813. }
  814. return [h, s * 100, l * 100];
  815. };
  816. convert$1.rgb.hsv = function (rgb) {
  817. var rdif;
  818. var gdif;
  819. var bdif;
  820. var h;
  821. var s;
  822. var r = rgb[0] / 255;
  823. var g = rgb[1] / 255;
  824. var b = rgb[2] / 255;
  825. var v = Math.max(r, g, b);
  826. var diff = v - Math.min(r, g, b);
  827. var diffc = function (c) {
  828. return (v - c) / 6 / diff + 1 / 2;
  829. };
  830. if (diff === 0) {
  831. h = s = 0;
  832. } else {
  833. s = diff / v;
  834. rdif = diffc(r);
  835. gdif = diffc(g);
  836. bdif = diffc(b);
  837. if (r === v) {
  838. h = bdif - gdif;
  839. } else if (g === v) {
  840. h = 1 / 3 + rdif - bdif;
  841. } else if (b === v) {
  842. h = 2 / 3 + gdif - rdif;
  843. }
  844. if (h < 0) {
  845. h += 1;
  846. } else if (h > 1) {
  847. h -= 1;
  848. }
  849. }
  850. return [h * 360, s * 100, v * 100];
  851. };
  852. convert$1.rgb.hwb = function (rgb) {
  853. var r = rgb[0];
  854. var g = rgb[1];
  855. var b = rgb[2];
  856. var h = convert$1.rgb.hsl(rgb)[0];
  857. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  858. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  859. return [h, w * 100, b * 100];
  860. };
  861. convert$1.rgb.cmyk = function (rgb) {
  862. var r = rgb[0] / 255;
  863. var g = rgb[1] / 255;
  864. var b = rgb[2] / 255;
  865. var c;
  866. var m;
  867. var y;
  868. var k;
  869. k = Math.min(1 - r, 1 - g, 1 - b);
  870. c = (1 - r - k) / (1 - k) || 0;
  871. m = (1 - g - k) / (1 - k) || 0;
  872. y = (1 - b - k) / (1 - k) || 0;
  873. return [c * 100, m * 100, y * 100, k * 100];
  874. };
  875. /**
  876. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  877. * */
  878. function comparativeDistance(x, y) {
  879. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  880. }
  881. convert$1.rgb.keyword = function (rgb) {
  882. var reversed = reverseKeywords[rgb];
  883. if (reversed) {
  884. return reversed;
  885. }
  886. var currentClosestDistance = Infinity;
  887. var currentClosestKeyword;
  888. for (var keyword in cssKeywords) {
  889. if (cssKeywords.hasOwnProperty(keyword)) {
  890. var value = cssKeywords[keyword]; // Compute comparative distance
  891. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  892. if (distance < currentClosestDistance) {
  893. currentClosestDistance = distance;
  894. currentClosestKeyword = keyword;
  895. }
  896. }
  897. }
  898. return currentClosestKeyword;
  899. };
  900. convert$1.keyword.rgb = function (keyword) {
  901. return cssKeywords[keyword];
  902. };
  903. convert$1.rgb.xyz = function (rgb) {
  904. var r = rgb[0] / 255;
  905. var g = rgb[1] / 255;
  906. var b = rgb[2] / 255; // assume sRGB
  907. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  908. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  909. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  910. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  911. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  912. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  913. return [x * 100, y * 100, z * 100];
  914. };
  915. convert$1.rgb.lab = function (rgb) {
  916. var xyz = convert$1.rgb.xyz(rgb);
  917. var x = xyz[0];
  918. var y = xyz[1];
  919. var z = xyz[2];
  920. var l;
  921. var a;
  922. var b;
  923. x /= 95.047;
  924. y /= 100;
  925. z /= 108.883;
  926. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  927. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  928. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  929. l = 116 * y - 16;
  930. a = 500 * (x - y);
  931. b = 200 * (y - z);
  932. return [l, a, b];
  933. };
  934. convert$1.hsl.rgb = function (hsl) {
  935. var h = hsl[0] / 360;
  936. var s = hsl[1] / 100;
  937. var l = hsl[2] / 100;
  938. var t1;
  939. var t2;
  940. var t3;
  941. var rgb;
  942. var val;
  943. if (s === 0) {
  944. val = l * 255;
  945. return [val, val, val];
  946. }
  947. if (l < 0.5) {
  948. t2 = l * (1 + s);
  949. } else {
  950. t2 = l + s - l * s;
  951. }
  952. t1 = 2 * l - t2;
  953. rgb = [0, 0, 0];
  954. for (var i = 0; i < 3; i++) {
  955. t3 = h + 1 / 3 * -(i - 1);
  956. if (t3 < 0) {
  957. t3++;
  958. }
  959. if (t3 > 1) {
  960. t3--;
  961. }
  962. if (6 * t3 < 1) {
  963. val = t1 + (t2 - t1) * 6 * t3;
  964. } else if (2 * t3 < 1) {
  965. val = t2;
  966. } else if (3 * t3 < 2) {
  967. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  968. } else {
  969. val = t1;
  970. }
  971. rgb[i] = val * 255;
  972. }
  973. return rgb;
  974. };
  975. convert$1.hsl.hsv = function (hsl) {
  976. var h = hsl[0];
  977. var s = hsl[1] / 100;
  978. var l = hsl[2] / 100;
  979. var smin = s;
  980. var lmin = Math.max(l, 0.01);
  981. var sv;
  982. var v;
  983. l *= 2;
  984. s *= l <= 1 ? l : 2 - l;
  985. smin *= lmin <= 1 ? lmin : 2 - lmin;
  986. v = (l + s) / 2;
  987. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  988. return [h, sv * 100, v * 100];
  989. };
  990. convert$1.hsv.rgb = function (hsv) {
  991. var h = hsv[0] / 60;
  992. var s = hsv[1] / 100;
  993. var v = hsv[2] / 100;
  994. var hi = Math.floor(h) % 6;
  995. var f = h - Math.floor(h);
  996. var p = 255 * v * (1 - s);
  997. var q = 255 * v * (1 - s * f);
  998. var t = 255 * v * (1 - s * (1 - f));
  999. v *= 255;
  1000. switch (hi) {
  1001. case 0:
  1002. return [v, t, p];
  1003. case 1:
  1004. return [q, v, p];
  1005. case 2:
  1006. return [p, v, t];
  1007. case 3:
  1008. return [p, q, v];
  1009. case 4:
  1010. return [t, p, v];
  1011. case 5:
  1012. return [v, p, q];
  1013. }
  1014. };
  1015. convert$1.hsv.hsl = function (hsv) {
  1016. var h = hsv[0];
  1017. var s = hsv[1] / 100;
  1018. var v = hsv[2] / 100;
  1019. var vmin = Math.max(v, 0.01);
  1020. var lmin;
  1021. var sl;
  1022. var l;
  1023. l = (2 - s) * v;
  1024. lmin = (2 - s) * vmin;
  1025. sl = s * vmin;
  1026. sl /= lmin <= 1 ? lmin : 2 - lmin;
  1027. sl = sl || 0;
  1028. l /= 2;
  1029. return [h, sl * 100, l * 100];
  1030. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  1031. convert$1.hwb.rgb = function (hwb) {
  1032. var h = hwb[0] / 360;
  1033. var wh = hwb[1] / 100;
  1034. var bl = hwb[2] / 100;
  1035. var ratio = wh + bl;
  1036. var i;
  1037. var v;
  1038. var f;
  1039. var n; // wh + bl cant be > 1
  1040. if (ratio > 1) {
  1041. wh /= ratio;
  1042. bl /= ratio;
  1043. }
  1044. i = Math.floor(6 * h);
  1045. v = 1 - bl;
  1046. f = 6 * h - i;
  1047. if ((i & 0x01) !== 0) {
  1048. f = 1 - f;
  1049. }
  1050. n = wh + f * (v - wh); // linear interpolation
  1051. var r;
  1052. var g;
  1053. var b;
  1054. switch (i) {
  1055. default:
  1056. case 6:
  1057. case 0:
  1058. r = v;
  1059. g = n;
  1060. b = wh;
  1061. break;
  1062. case 1:
  1063. r = n;
  1064. g = v;
  1065. b = wh;
  1066. break;
  1067. case 2:
  1068. r = wh;
  1069. g = v;
  1070. b = n;
  1071. break;
  1072. case 3:
  1073. r = wh;
  1074. g = n;
  1075. b = v;
  1076. break;
  1077. case 4:
  1078. r = n;
  1079. g = wh;
  1080. b = v;
  1081. break;
  1082. case 5:
  1083. r = v;
  1084. g = wh;
  1085. b = n;
  1086. break;
  1087. }
  1088. return [r * 255, g * 255, b * 255];
  1089. };
  1090. convert$1.cmyk.rgb = function (cmyk) {
  1091. var c = cmyk[0] / 100;
  1092. var m = cmyk[1] / 100;
  1093. var y = cmyk[2] / 100;
  1094. var k = cmyk[3] / 100;
  1095. var r;
  1096. var g;
  1097. var b;
  1098. r = 1 - Math.min(1, c * (1 - k) + k);
  1099. g = 1 - Math.min(1, m * (1 - k) + k);
  1100. b = 1 - Math.min(1, y * (1 - k) + k);
  1101. return [r * 255, g * 255, b * 255];
  1102. };
  1103. convert$1.xyz.rgb = function (xyz) {
  1104. var x = xyz[0] / 100;
  1105. var y = xyz[1] / 100;
  1106. var z = xyz[2] / 100;
  1107. var r;
  1108. var g;
  1109. var b;
  1110. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  1111. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  1112. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  1113. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  1114. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  1115. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  1116. r = Math.min(Math.max(0, r), 1);
  1117. g = Math.min(Math.max(0, g), 1);
  1118. b = Math.min(Math.max(0, b), 1);
  1119. return [r * 255, g * 255, b * 255];
  1120. };
  1121. convert$1.xyz.lab = function (xyz) {
  1122. var x = xyz[0];
  1123. var y = xyz[1];
  1124. var z = xyz[2];
  1125. var l;
  1126. var a;
  1127. var b;
  1128. x /= 95.047;
  1129. y /= 100;
  1130. z /= 108.883;
  1131. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  1132. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  1133. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  1134. l = 116 * y - 16;
  1135. a = 500 * (x - y);
  1136. b = 200 * (y - z);
  1137. return [l, a, b];
  1138. };
  1139. convert$1.lab.xyz = function (lab) {
  1140. var l = lab[0];
  1141. var a = lab[1];
  1142. var b = lab[2];
  1143. var x;
  1144. var y;
  1145. var z;
  1146. y = (l + 16) / 116;
  1147. x = a / 500 + y;
  1148. z = y - b / 200;
  1149. var y2 = Math.pow(y, 3);
  1150. var x2 = Math.pow(x, 3);
  1151. var z2 = Math.pow(z, 3);
  1152. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  1153. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  1154. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  1155. x *= 95.047;
  1156. y *= 100;
  1157. z *= 108.883;
  1158. return [x, y, z];
  1159. };
  1160. convert$1.lab.lch = function (lab) {
  1161. var l = lab[0];
  1162. var a = lab[1];
  1163. var b = lab[2];
  1164. var hr;
  1165. var h;
  1166. var c;
  1167. hr = Math.atan2(b, a);
  1168. h = hr * 360 / 2 / Math.PI;
  1169. if (h < 0) {
  1170. h += 360;
  1171. }
  1172. c = Math.sqrt(a * a + b * b);
  1173. return [l, c, h];
  1174. };
  1175. convert$1.lch.lab = function (lch) {
  1176. var l = lch[0];
  1177. var c = lch[1];
  1178. var h = lch[2];
  1179. var a;
  1180. var b;
  1181. var hr;
  1182. hr = h / 360 * 2 * Math.PI;
  1183. a = c * Math.cos(hr);
  1184. b = c * Math.sin(hr);
  1185. return [l, a, b];
  1186. };
  1187. convert$1.rgb.ansi16 = function (args) {
  1188. var r = args[0];
  1189. var g = args[1];
  1190. var b = args[2];
  1191. var value = 1 in arguments ? arguments[1] : convert$1.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  1192. value = Math.round(value / 50);
  1193. if (value === 0) {
  1194. return 30;
  1195. }
  1196. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  1197. if (value === 2) {
  1198. ansi += 60;
  1199. }
  1200. return ansi;
  1201. };
  1202. convert$1.hsv.ansi16 = function (args) {
  1203. // optimization here; we already know the value and don't need to get
  1204. // it converted for us.
  1205. return convert$1.rgb.ansi16(convert$1.hsv.rgb(args), args[2]);
  1206. };
  1207. convert$1.rgb.ansi256 = function (args) {
  1208. var r = args[0];
  1209. var g = args[1];
  1210. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  1211. // black and white. normal palette only has 4 greyscale shades.
  1212. if (r === g && g === b) {
  1213. if (r < 8) {
  1214. return 16;
  1215. }
  1216. if (r > 248) {
  1217. return 231;
  1218. }
  1219. return Math.round((r - 8) / 247 * 24) + 232;
  1220. }
  1221. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  1222. return ansi;
  1223. };
  1224. convert$1.ansi16.rgb = function (args) {
  1225. var color = args % 10; // handle greyscale
  1226. if (color === 0 || color === 7) {
  1227. if (args > 50) {
  1228. color += 3.5;
  1229. }
  1230. color = color / 10.5 * 255;
  1231. return [color, color, color];
  1232. }
  1233. var mult = (~~(args > 50) + 1) * 0.5;
  1234. var r = (color & 1) * mult * 255;
  1235. var g = (color >> 1 & 1) * mult * 255;
  1236. var b = (color >> 2 & 1) * mult * 255;
  1237. return [r, g, b];
  1238. };
  1239. convert$1.ansi256.rgb = function (args) {
  1240. // handle greyscale
  1241. if (args >= 232) {
  1242. var c = (args - 232) * 10 + 8;
  1243. return [c, c, c];
  1244. }
  1245. args -= 16;
  1246. var rem;
  1247. var r = Math.floor(args / 36) / 5 * 255;
  1248. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  1249. var b = rem % 6 / 5 * 255;
  1250. return [r, g, b];
  1251. };
  1252. convert$1.rgb.hex = function (args) {
  1253. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  1254. var string = integer.toString(16).toUpperCase();
  1255. return '000000'.substring(string.length) + string;
  1256. };
  1257. convert$1.hex.rgb = function (args) {
  1258. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  1259. if (!match) {
  1260. return [0, 0, 0];
  1261. }
  1262. var colorString = match[0];
  1263. if (match[0].length === 3) {
  1264. colorString = colorString.split('').map(function (char) {
  1265. return char + char;
  1266. }).join('');
  1267. }
  1268. var integer = parseInt(colorString, 16);
  1269. var r = integer >> 16 & 0xFF;
  1270. var g = integer >> 8 & 0xFF;
  1271. var b = integer & 0xFF;
  1272. return [r, g, b];
  1273. };
  1274. convert$1.rgb.hcg = function (rgb) {
  1275. var r = rgb[0] / 255;
  1276. var g = rgb[1] / 255;
  1277. var b = rgb[2] / 255;
  1278. var max = Math.max(Math.max(r, g), b);
  1279. var min = Math.min(Math.min(r, g), b);
  1280. var chroma = max - min;
  1281. var grayscale;
  1282. var hue;
  1283. if (chroma < 1) {
  1284. grayscale = min / (1 - chroma);
  1285. } else {
  1286. grayscale = 0;
  1287. }
  1288. if (chroma <= 0) {
  1289. hue = 0;
  1290. } else if (max === r) {
  1291. hue = (g - b) / chroma % 6;
  1292. } else if (max === g) {
  1293. hue = 2 + (b - r) / chroma;
  1294. } else {
  1295. hue = 4 + (r - g) / chroma + 4;
  1296. }
  1297. hue /= 6;
  1298. hue %= 1;
  1299. return [hue * 360, chroma * 100, grayscale * 100];
  1300. };
  1301. convert$1.hsl.hcg = function (hsl) {
  1302. var s = hsl[1] / 100;
  1303. var l = hsl[2] / 100;
  1304. var c = 1;
  1305. var f = 0;
  1306. if (l < 0.5) {
  1307. c = 2.0 * s * l;
  1308. } else {
  1309. c = 2.0 * s * (1.0 - l);
  1310. }
  1311. if (c < 1.0) {
  1312. f = (l - 0.5 * c) / (1.0 - c);
  1313. }
  1314. return [hsl[0], c * 100, f * 100];
  1315. };
  1316. convert$1.hsv.hcg = function (hsv) {
  1317. var s = hsv[1] / 100;
  1318. var v = hsv[2] / 100;
  1319. var c = s * v;
  1320. var f = 0;
  1321. if (c < 1.0) {
  1322. f = (v - c) / (1 - c);
  1323. }
  1324. return [hsv[0], c * 100, f * 100];
  1325. };
  1326. convert$1.hcg.rgb = function (hcg) {
  1327. var h = hcg[0] / 360;
  1328. var c = hcg[1] / 100;
  1329. var g = hcg[2] / 100;
  1330. if (c === 0.0) {
  1331. return [g * 255, g * 255, g * 255];
  1332. }
  1333. var pure = [0, 0, 0];
  1334. var hi = h % 1 * 6;
  1335. var v = hi % 1;
  1336. var w = 1 - v;
  1337. var mg = 0;
  1338. switch (Math.floor(hi)) {
  1339. case 0:
  1340. pure[0] = 1;
  1341. pure[1] = v;
  1342. pure[2] = 0;
  1343. break;
  1344. case 1:
  1345. pure[0] = w;
  1346. pure[1] = 1;
  1347. pure[2] = 0;
  1348. break;
  1349. case 2:
  1350. pure[0] = 0;
  1351. pure[1] = 1;
  1352. pure[2] = v;
  1353. break;
  1354. case 3:
  1355. pure[0] = 0;
  1356. pure[1] = w;
  1357. pure[2] = 1;
  1358. break;
  1359. case 4:
  1360. pure[0] = v;
  1361. pure[1] = 0;
  1362. pure[2] = 1;
  1363. break;
  1364. default:
  1365. pure[0] = 1;
  1366. pure[1] = 0;
  1367. pure[2] = w;
  1368. }
  1369. mg = (1.0 - c) * g;
  1370. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  1371. };
  1372. convert$1.hcg.hsv = function (hcg) {
  1373. var c = hcg[1] / 100;
  1374. var g = hcg[2] / 100;
  1375. var v = c + g * (1.0 - c);
  1376. var f = 0;
  1377. if (v > 0.0) {
  1378. f = c / v;
  1379. }
  1380. return [hcg[0], f * 100, v * 100];
  1381. };
  1382. convert$1.hcg.hsl = function (hcg) {
  1383. var c = hcg[1] / 100;
  1384. var g = hcg[2] / 100;
  1385. var l = g * (1.0 - c) + 0.5 * c;
  1386. var s = 0;
  1387. if (l > 0.0 && l < 0.5) {
  1388. s = c / (2 * l);
  1389. } else if (l >= 0.5 && l < 1.0) {
  1390. s = c / (2 * (1 - l));
  1391. }
  1392. return [hcg[0], s * 100, l * 100];
  1393. };
  1394. convert$1.hcg.hwb = function (hcg) {
  1395. var c = hcg[1] / 100;
  1396. var g = hcg[2] / 100;
  1397. var v = c + g * (1.0 - c);
  1398. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  1399. };
  1400. convert$1.hwb.hcg = function (hwb) {
  1401. var w = hwb[1] / 100;
  1402. var b = hwb[2] / 100;
  1403. var v = 1 - b;
  1404. var c = v - w;
  1405. var g = 0;
  1406. if (c < 1) {
  1407. g = (v - c) / (1 - c);
  1408. }
  1409. return [hwb[0], c * 100, g * 100];
  1410. };
  1411. convert$1.apple.rgb = function (apple) {
  1412. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  1413. };
  1414. convert$1.rgb.apple = function (rgb) {
  1415. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  1416. };
  1417. convert$1.gray.rgb = function (args) {
  1418. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  1419. };
  1420. convert$1.gray.hsl = convert$1.gray.hsv = function (args) {
  1421. return [0, 0, args[0]];
  1422. };
  1423. convert$1.gray.hwb = function (gray) {
  1424. return [0, 100, gray[0]];
  1425. };
  1426. convert$1.gray.cmyk = function (gray) {
  1427. return [0, 0, 0, gray[0]];
  1428. };
  1429. convert$1.gray.lab = function (gray) {
  1430. return [gray[0], 0, 0];
  1431. };
  1432. convert$1.gray.hex = function (gray) {
  1433. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  1434. var integer = (val << 16) + (val << 8) + val;
  1435. var string = integer.toString(16).toUpperCase();
  1436. return '000000'.substring(string.length) + string;
  1437. };
  1438. convert$1.rgb.gray = function (rgb) {
  1439. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  1440. return [val / 255 * 100];
  1441. };
  1442. var conversions$1 = conversions$2.exports;
  1443. /*
  1444. this function routes a model to all other models.
  1445. all functions that are routed have a property `.conversion` attached
  1446. to the returned synthetic function. This property is an array
  1447. of strings, each with the steps in between the 'from' and 'to'
  1448. color models (inclusive).
  1449. conversions that are not possible simply are not included.
  1450. */
  1451. function buildGraph() {
  1452. var graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  1453. var models = Object.keys(conversions$1);
  1454. for (var len = models.length, i = 0; i < len; i++) {
  1455. graph[models[i]] = {
  1456. // http://jsperf.com/1-vs-infinity
  1457. // micro-opt, but this is simple.
  1458. distance: -1,
  1459. parent: null
  1460. };
  1461. }
  1462. return graph;
  1463. } // https://en.wikipedia.org/wiki/Breadth-first_search
  1464. function deriveBFS(fromModel) {
  1465. var graph = buildGraph();
  1466. var queue = [fromModel]; // unshift -> queue -> pop
  1467. graph[fromModel].distance = 0;
  1468. while (queue.length) {
  1469. var current = queue.pop();
  1470. var adjacents = Object.keys(conversions$1[current]);
  1471. for (var len = adjacents.length, i = 0; i < len; i++) {
  1472. var adjacent = adjacents[i];
  1473. var node = graph[adjacent];
  1474. if (node.distance === -1) {
  1475. node.distance = graph[current].distance + 1;
  1476. node.parent = current;
  1477. queue.unshift(adjacent);
  1478. }
  1479. }
  1480. }
  1481. return graph;
  1482. }
  1483. function link(from, to) {
  1484. return function (args) {
  1485. return to(from(args));
  1486. };
  1487. }
  1488. function wrapConversion(toModel, graph) {
  1489. var path = [graph[toModel].parent, toModel];
  1490. var fn = conversions$1[graph[toModel].parent][toModel];
  1491. var cur = graph[toModel].parent;
  1492. while (graph[cur].parent) {
  1493. path.unshift(graph[cur].parent);
  1494. fn = link(conversions$1[graph[cur].parent][cur], fn);
  1495. cur = graph[cur].parent;
  1496. }
  1497. fn.conversion = path;
  1498. return fn;
  1499. }
  1500. var route$1 = function (fromModel) {
  1501. var graph = deriveBFS(fromModel);
  1502. var conversion = {};
  1503. var models = Object.keys(graph);
  1504. for (var len = models.length, i = 0; i < len; i++) {
  1505. var toModel = models[i];
  1506. var node = graph[toModel];
  1507. if (node.parent === null) {
  1508. // no possible conversion, or this node is the source model.
  1509. continue;
  1510. }
  1511. conversion[toModel] = wrapConversion(toModel, graph);
  1512. }
  1513. return conversion;
  1514. };
  1515. var conversions = conversions$2.exports;
  1516. var route = route$1;
  1517. var convert = {};
  1518. var models = Object.keys(conversions);
  1519. function wrapRaw(fn) {
  1520. var wrappedFn = function (args) {
  1521. if (args === undefined || args === null) {
  1522. return args;
  1523. }
  1524. if (arguments.length > 1) {
  1525. args = Array.prototype.slice.call(arguments);
  1526. }
  1527. return fn(args);
  1528. }; // preserve .conversion property if there is one
  1529. if ('conversion' in fn) {
  1530. wrappedFn.conversion = fn.conversion;
  1531. }
  1532. return wrappedFn;
  1533. }
  1534. function wrapRounded(fn) {
  1535. var wrappedFn = function (args) {
  1536. if (args === undefined || args === null) {
  1537. return args;
  1538. }
  1539. if (arguments.length > 1) {
  1540. args = Array.prototype.slice.call(arguments);
  1541. }
  1542. var result = fn(args); // we're assuming the result is an array here.
  1543. // see notice in conversions.js; don't use box types
  1544. // in conversion functions.
  1545. if (typeof result === 'object') {
  1546. for (var len = result.length, i = 0; i < len; i++) {
  1547. result[i] = Math.round(result[i]);
  1548. }
  1549. }
  1550. return result;
  1551. }; // preserve .conversion property if there is one
  1552. if ('conversion' in fn) {
  1553. wrappedFn.conversion = fn.conversion;
  1554. }
  1555. return wrappedFn;
  1556. }
  1557. models.forEach(function (fromModel) {
  1558. convert[fromModel] = {};
  1559. Object.defineProperty(convert[fromModel], 'channels', {
  1560. value: conversions[fromModel].channels
  1561. });
  1562. Object.defineProperty(convert[fromModel], 'labels', {
  1563. value: conversions[fromModel].labels
  1564. });
  1565. var routes = route(fromModel);
  1566. var routeModels = Object.keys(routes);
  1567. routeModels.forEach(function (toModel) {
  1568. var fn = routes[toModel];
  1569. convert[fromModel][toModel] = wrapRounded(fn);
  1570. convert[fromModel][toModel].raw = wrapRaw(fn);
  1571. });
  1572. });
  1573. var colorConvert = convert;
  1574. (function (module) {
  1575. const colorConvert$1 = colorConvert;
  1576. const wrapAnsi16 = (fn, offset) => function () {
  1577. const code = fn.apply(colorConvert$1, arguments);
  1578. return `\u001B[${code + offset}m`;
  1579. };
  1580. const wrapAnsi256 = (fn, offset) => function () {
  1581. const code = fn.apply(colorConvert$1, arguments);
  1582. return `\u001B[${38 + offset};5;${code}m`;
  1583. };
  1584. const wrapAnsi16m = (fn, offset) => function () {
  1585. const rgb = fn.apply(colorConvert$1, arguments);
  1586. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  1587. };
  1588. function assembleStyles() {
  1589. const codes = new Map();
  1590. const styles = {
  1591. modifier: {
  1592. reset: [0, 0],
  1593. // 21 isn't widely supported and 22 does the same thing
  1594. bold: [1, 22],
  1595. dim: [2, 22],
  1596. italic: [3, 23],
  1597. underline: [4, 24],
  1598. inverse: [7, 27],
  1599. hidden: [8, 28],
  1600. strikethrough: [9, 29]
  1601. },
  1602. color: {
  1603. black: [30, 39],
  1604. red: [31, 39],
  1605. green: [32, 39],
  1606. yellow: [33, 39],
  1607. blue: [34, 39],
  1608. magenta: [35, 39],
  1609. cyan: [36, 39],
  1610. white: [37, 39],
  1611. gray: [90, 39],
  1612. // Bright color
  1613. redBright: [91, 39],
  1614. greenBright: [92, 39],
  1615. yellowBright: [93, 39],
  1616. blueBright: [94, 39],
  1617. magentaBright: [95, 39],
  1618. cyanBright: [96, 39],
  1619. whiteBright: [97, 39]
  1620. },
  1621. bgColor: {
  1622. bgBlack: [40, 49],
  1623. bgRed: [41, 49],
  1624. bgGreen: [42, 49],
  1625. bgYellow: [43, 49],
  1626. bgBlue: [44, 49],
  1627. bgMagenta: [45, 49],
  1628. bgCyan: [46, 49],
  1629. bgWhite: [47, 49],
  1630. // Bright color
  1631. bgBlackBright: [100, 49],
  1632. bgRedBright: [101, 49],
  1633. bgGreenBright: [102, 49],
  1634. bgYellowBright: [103, 49],
  1635. bgBlueBright: [104, 49],
  1636. bgMagentaBright: [105, 49],
  1637. bgCyanBright: [106, 49],
  1638. bgWhiteBright: [107, 49]
  1639. }
  1640. }; // Fix humans
  1641. styles.color.grey = styles.color.gray;
  1642. for (const groupName of Object.keys(styles)) {
  1643. const group = styles[groupName];
  1644. for (const styleName of Object.keys(group)) {
  1645. const style = group[styleName];
  1646. styles[styleName] = {
  1647. open: `\u001B[${style[0]}m`,
  1648. close: `\u001B[${style[1]}m`
  1649. };
  1650. group[styleName] = styles[styleName];
  1651. codes.set(style[0], style[1]);
  1652. }
  1653. Object.defineProperty(styles, groupName, {
  1654. value: group,
  1655. enumerable: false
  1656. });
  1657. Object.defineProperty(styles, 'codes', {
  1658. value: codes,
  1659. enumerable: false
  1660. });
  1661. }
  1662. const ansi2ansi = n => n;
  1663. const rgb2rgb = (r, g, b) => [r, g, b];
  1664. styles.color.close = '\u001B[39m';
  1665. styles.bgColor.close = '\u001B[49m';
  1666. styles.color.ansi = {
  1667. ansi: wrapAnsi16(ansi2ansi, 0)
  1668. };
  1669. styles.color.ansi256 = {
  1670. ansi256: wrapAnsi256(ansi2ansi, 0)
  1671. };
  1672. styles.color.ansi16m = {
  1673. rgb: wrapAnsi16m(rgb2rgb, 0)
  1674. };
  1675. styles.bgColor.ansi = {
  1676. ansi: wrapAnsi16(ansi2ansi, 10)
  1677. };
  1678. styles.bgColor.ansi256 = {
  1679. ansi256: wrapAnsi256(ansi2ansi, 10)
  1680. };
  1681. styles.bgColor.ansi16m = {
  1682. rgb: wrapAnsi16m(rgb2rgb, 10)
  1683. };
  1684. for (let key of Object.keys(colorConvert$1)) {
  1685. if (typeof colorConvert$1[key] !== 'object') {
  1686. continue;
  1687. }
  1688. const suite = colorConvert$1[key];
  1689. if (key === 'ansi16') {
  1690. key = 'ansi';
  1691. }
  1692. if ('ansi16' in suite) {
  1693. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  1694. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  1695. }
  1696. if ('ansi256' in suite) {
  1697. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  1698. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  1699. }
  1700. if ('rgb' in suite) {
  1701. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  1702. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  1703. }
  1704. }
  1705. return styles;
  1706. } // Make the export immutable
  1707. Object.defineProperty(module, 'exports', {
  1708. enumerable: true,
  1709. get: assembleStyles
  1710. });
  1711. })(ansiStyles);
  1712. var hasFlag$1 = (flag, argv) => {
  1713. argv = argv || process.argv;
  1714. const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  1715. const pos = argv.indexOf(prefix + flag);
  1716. const terminatorPos = argv.indexOf('--');
  1717. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  1718. };
  1719. const os = require$$0__default$2["default"];
  1720. const hasFlag = hasFlag$1;
  1721. const env = process.env;
  1722. let forceColor;
  1723. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  1724. forceColor = false;
  1725. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  1726. forceColor = true;
  1727. }
  1728. if ('FORCE_COLOR' in env) {
  1729. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  1730. }
  1731. function translateLevel(level) {
  1732. if (level === 0) {
  1733. return false;
  1734. }
  1735. return {
  1736. level,
  1737. hasBasic: true,
  1738. has256: level >= 2,
  1739. has16m: level >= 3
  1740. };
  1741. }
  1742. function supportsColor(stream) {
  1743. if (forceColor === false) {
  1744. return 0;
  1745. }
  1746. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  1747. return 3;
  1748. }
  1749. if (hasFlag('color=256')) {
  1750. return 2;
  1751. }
  1752. if (stream && !stream.isTTY && forceColor !== true) {
  1753. return 0;
  1754. }
  1755. const min = forceColor ? 1 : 0;
  1756. if (process.platform === 'win32') {
  1757. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  1758. // libuv that enables 256 color output on Windows. Anything earlier and it
  1759. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  1760. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  1761. // release that supports 256 colors. Windows 10 build 14931 is the first release
  1762. // that supports 16m/TrueColor.
  1763. const osRelease = os.release().split('.');
  1764. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  1765. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  1766. }
  1767. return 1;
  1768. }
  1769. if ('CI' in env) {
  1770. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
  1771. return 1;
  1772. }
  1773. return min;
  1774. }
  1775. if ('TEAMCITY_VERSION' in env) {
  1776. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  1777. }
  1778. if (env.COLORTERM === 'truecolor') {
  1779. return 3;
  1780. }
  1781. if ('TERM_PROGRAM' in env) {
  1782. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  1783. switch (env.TERM_PROGRAM) {
  1784. case 'iTerm.app':
  1785. return version >= 3 ? 3 : 2;
  1786. case 'Apple_Terminal':
  1787. return 2;
  1788. // No default
  1789. }
  1790. }
  1791. if (/-256(color)?$/i.test(env.TERM)) {
  1792. return 2;
  1793. }
  1794. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  1795. return 1;
  1796. }
  1797. if ('COLORTERM' in env) {
  1798. return 1;
  1799. }
  1800. if (env.TERM === 'dumb') {
  1801. return min;
  1802. }
  1803. return min;
  1804. }
  1805. function getSupportLevel(stream) {
  1806. const level = supportsColor(stream);
  1807. return translateLevel(level);
  1808. }
  1809. var supportsColor_1 = {
  1810. supportsColor: getSupportLevel,
  1811. stdout: getSupportLevel(process.stdout),
  1812. stderr: getSupportLevel(process.stderr)
  1813. };
  1814. const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  1815. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  1816. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  1817. const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  1818. const ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  1819. function unescape(c) {
  1820. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  1821. return String.fromCharCode(parseInt(c.slice(1), 16));
  1822. }
  1823. return ESCAPES.get(c) || c;
  1824. }
  1825. function parseArguments(name, args) {
  1826. const results = [];
  1827. const chunks = args.trim().split(/\s*,\s*/g);
  1828. let matches;
  1829. for (const chunk of chunks) {
  1830. if (!isNaN(chunk)) {
  1831. results.push(Number(chunk));
  1832. } else if (matches = chunk.match(STRING_REGEX)) {
  1833. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
  1834. } else {
  1835. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  1836. }
  1837. }
  1838. return results;
  1839. }
  1840. function parseStyle(style) {
  1841. STYLE_REGEX.lastIndex = 0;
  1842. const results = [];
  1843. let matches;
  1844. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  1845. const name = matches[1];
  1846. if (matches[2]) {
  1847. const args = parseArguments(name, matches[2]);
  1848. results.push([name].concat(args));
  1849. } else {
  1850. results.push([name]);
  1851. }
  1852. }
  1853. return results;
  1854. }
  1855. function buildStyle(chalk, styles) {
  1856. const enabled = {};
  1857. for (const layer of styles) {
  1858. for (const style of layer.styles) {
  1859. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  1860. }
  1861. }
  1862. let current = chalk;
  1863. for (const styleName of Object.keys(enabled)) {
  1864. if (Array.isArray(enabled[styleName])) {
  1865. if (!(styleName in current)) {
  1866. throw new Error(`Unknown Chalk style: ${styleName}`);
  1867. }
  1868. if (enabled[styleName].length > 0) {
  1869. current = current[styleName].apply(current, enabled[styleName]);
  1870. } else {
  1871. current = current[styleName];
  1872. }
  1873. }
  1874. }
  1875. return current;
  1876. }
  1877. var templates = (chalk, tmp) => {
  1878. const styles = [];
  1879. const chunks = [];
  1880. let chunk = []; // eslint-disable-next-line max-params
  1881. tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
  1882. if (escapeChar) {
  1883. chunk.push(unescape(escapeChar));
  1884. } else if (style) {
  1885. const str = chunk.join('');
  1886. chunk = [];
  1887. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  1888. styles.push({
  1889. inverse,
  1890. styles: parseStyle(style)
  1891. });
  1892. } else if (close) {
  1893. if (styles.length === 0) {
  1894. throw new Error('Found extraneous } in Chalk template literal');
  1895. }
  1896. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  1897. chunk = [];
  1898. styles.pop();
  1899. } else {
  1900. chunk.push(chr);
  1901. }
  1902. });
  1903. chunks.push(chunk.join(''));
  1904. if (styles.length > 0) {
  1905. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  1906. throw new Error(errMsg);
  1907. }
  1908. return chunks.join('');
  1909. };
  1910. (function (module) {
  1911. const escapeStringRegexp$1 = escapeStringRegexp;
  1912. const ansiStyles$1 = ansiStyles.exports;
  1913. const stdoutColor = supportsColor_1.stdout;
  1914. const template = templates;
  1915. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  1916. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  1917. const skipModels = new Set(['gray']);
  1918. const styles = Object.create(null);
  1919. function applyOptions(obj, options) {
  1920. options = options || {}; // Detect level if not set manually
  1921. const scLevel = stdoutColor ? stdoutColor.level : 0;
  1922. obj.level = options.level === undefined ? scLevel : options.level;
  1923. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  1924. }
  1925. function Chalk(options) {
  1926. // We check for this.template here since calling `chalk.constructor()`
  1927. // by itself will have a `this` of a previously constructed chalk object
  1928. if (!this || !(this instanceof Chalk) || this.template) {
  1929. const chalk = {};
  1930. applyOptions(chalk, options);
  1931. chalk.template = function () {
  1932. const args = [].slice.call(arguments);
  1933. return chalkTag.apply(null, [chalk.template].concat(args));
  1934. };
  1935. Object.setPrototypeOf(chalk, Chalk.prototype);
  1936. Object.setPrototypeOf(chalk.template, chalk);
  1937. chalk.template.constructor = Chalk;
  1938. return chalk.template;
  1939. }
  1940. applyOptions(this, options);
  1941. } // Use bright blue on Windows as the normal blue color is illegible
  1942. if (isSimpleWindowsTerm) {
  1943. ansiStyles$1.blue.open = '\u001B[94m';
  1944. }
  1945. for (const key of Object.keys(ansiStyles$1)) {
  1946. ansiStyles$1[key].closeRe = new RegExp(escapeStringRegexp$1(ansiStyles$1[key].close), 'g');
  1947. styles[key] = {
  1948. get() {
  1949. const codes = ansiStyles$1[key];
  1950. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  1951. }
  1952. };
  1953. }
  1954. styles.visible = {
  1955. get() {
  1956. return build.call(this, this._styles || [], true, 'visible');
  1957. }
  1958. };
  1959. ansiStyles$1.color.closeRe = new RegExp(escapeStringRegexp$1(ansiStyles$1.color.close), 'g');
  1960. for (const model of Object.keys(ansiStyles$1.color.ansi)) {
  1961. if (skipModels.has(model)) {
  1962. continue;
  1963. }
  1964. styles[model] = {
  1965. get() {
  1966. const level = this.level;
  1967. return function () {
  1968. const open = ansiStyles$1.color[levelMapping[level]][model].apply(null, arguments);
  1969. const codes = {
  1970. open,
  1971. close: ansiStyles$1.color.close,
  1972. closeRe: ansiStyles$1.color.closeRe
  1973. };
  1974. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  1975. };
  1976. }
  1977. };
  1978. }
  1979. ansiStyles$1.bgColor.closeRe = new RegExp(escapeStringRegexp$1(ansiStyles$1.bgColor.close), 'g');
  1980. for (const model of Object.keys(ansiStyles$1.bgColor.ansi)) {
  1981. if (skipModels.has(model)) {
  1982. continue;
  1983. }
  1984. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  1985. styles[bgModel] = {
  1986. get() {
  1987. const level = this.level;
  1988. return function () {
  1989. const open = ansiStyles$1.bgColor[levelMapping[level]][model].apply(null, arguments);
  1990. const codes = {
  1991. open,
  1992. close: ansiStyles$1.bgColor.close,
  1993. closeRe: ansiStyles$1.bgColor.closeRe
  1994. };
  1995. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  1996. };
  1997. }
  1998. };
  1999. }
  2000. const proto = Object.defineProperties(() => {}, styles);
  2001. function build(_styles, _empty, key) {
  2002. const builder = function () {
  2003. return applyStyle.apply(builder, arguments);
  2004. };
  2005. builder._styles = _styles;
  2006. builder._empty = _empty;
  2007. const self = this;
  2008. Object.defineProperty(builder, 'level', {
  2009. enumerable: true,
  2010. get() {
  2011. return self.level;
  2012. },
  2013. set(level) {
  2014. self.level = level;
  2015. }
  2016. });
  2017. Object.defineProperty(builder, 'enabled', {
  2018. enumerable: true,
  2019. get() {
  2020. return self.enabled;
  2021. },
  2022. set(enabled) {
  2023. self.enabled = enabled;
  2024. }
  2025. }); // See below for fix regarding invisible grey/dim combination on Windows
  2026. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  2027. // no way to create a function with a different prototype
  2028. builder.__proto__ = proto; // eslint-disable-line no-proto
  2029. return builder;
  2030. }
  2031. function applyStyle() {
  2032. // Support varags, but simply cast to string in case there's only one arg
  2033. const args = arguments;
  2034. const argsLen = args.length;
  2035. let str = String(arguments[0]);
  2036. if (argsLen === 0) {
  2037. return '';
  2038. }
  2039. if (argsLen > 1) {
  2040. // Don't slice `arguments`, it prevents V8 optimizations
  2041. for (let a = 1; a < argsLen; a++) {
  2042. str += ' ' + args[a];
  2043. }
  2044. }
  2045. if (!this.enabled || this.level <= 0 || !str) {
  2046. return this._empty ? '' : str;
  2047. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  2048. // see https://github.com/chalk/chalk/issues/58
  2049. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  2050. const originalDim = ansiStyles$1.dim.open;
  2051. if (isSimpleWindowsTerm && this.hasGrey) {
  2052. ansiStyles$1.dim.open = '';
  2053. }
  2054. for (const code of this._styles.slice().reverse()) {
  2055. // Replace any instances already present with a re-opening code
  2056. // otherwise only the part of the string until said closing code
  2057. // will be colored, and the rest will simply be 'plain'.
  2058. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  2059. // after next line to fix a bleed issue on macOS
  2060. // https://github.com/chalk/chalk/pull/92
  2061. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  2062. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  2063. ansiStyles$1.dim.open = originalDim;
  2064. return str;
  2065. }
  2066. function chalkTag(chalk, strings) {
  2067. if (!Array.isArray(strings)) {
  2068. // If chalk() was called by itself or with a string,
  2069. // return the string itself as a string.
  2070. return [].slice.call(arguments, 1).join(' ');
  2071. }
  2072. const args = [].slice.call(arguments, 2);
  2073. const parts = [strings.raw[0]];
  2074. for (let i = 1; i < strings.length; i++) {
  2075. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  2076. parts.push(String(strings.raw[i]));
  2077. }
  2078. return template(chalk, parts.join(''));
  2079. }
  2080. Object.defineProperties(Chalk.prototype, styles);
  2081. module.exports = Chalk(); // eslint-disable-line new-cap
  2082. module.exports.supportsColor = stdoutColor;
  2083. module.exports.default = module.exports; // For TypeScript
  2084. })(chalk);
  2085. Object.defineProperty(lib$1, "__esModule", {
  2086. value: true
  2087. });
  2088. lib$1.default = highlight;
  2089. lib$1.getChalk = getChalk;
  2090. lib$1.shouldHighlight = shouldHighlight;
  2091. var _jsTokens = jsTokens;
  2092. var _helperValidatorIdentifier = lib;
  2093. var _chalk = chalk.exports;
  2094. const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]);
  2095. function getDefs$1(chalk) {
  2096. return {
  2097. keyword: chalk.cyan,
  2098. capitalized: chalk.yellow,
  2099. jsxIdentifier: chalk.yellow,
  2100. punctuator: chalk.yellow,
  2101. number: chalk.magenta,
  2102. string: chalk.green,
  2103. regex: chalk.magenta,
  2104. comment: chalk.grey,
  2105. invalid: chalk.white.bgRed.bold
  2106. };
  2107. }
  2108. const NEWLINE$1 = /\r\n|[\n\r\u2028\u2029]/;
  2109. const BRACKET = /^[()[\]{}]$/;
  2110. let tokenize;
  2111. {
  2112. const JSX_TAG = /^[a-z][\w-]*$/i;
  2113. const getTokenType = function (token, offset, text) {
  2114. if (token.type === "name") {
  2115. if ((0, _helperValidatorIdentifier.isKeyword)(token.value) || (0, _helperValidatorIdentifier.isStrictReservedWord)(token.value, true) || sometimesKeywords.has(token.value)) {
  2116. return "keyword";
  2117. }
  2118. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  2119. return "jsxIdentifier";
  2120. }
  2121. if (token.value[0] !== token.value[0].toLowerCase()) {
  2122. return "capitalized";
  2123. }
  2124. }
  2125. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  2126. return "bracket";
  2127. }
  2128. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  2129. return "punctuator";
  2130. }
  2131. return token.type;
  2132. };
  2133. tokenize = function* (text) {
  2134. let match;
  2135. while (match = _jsTokens.default.exec(text)) {
  2136. const token = _jsTokens.matchToToken(match);
  2137. yield {
  2138. type: getTokenType(token, match.index, text),
  2139. value: token.value
  2140. };
  2141. }
  2142. };
  2143. }
  2144. function highlightTokens(defs, text) {
  2145. let highlighted = "";
  2146. for (const {
  2147. type,
  2148. value
  2149. } of tokenize(text)) {
  2150. const colorize = defs[type];
  2151. if (colorize) {
  2152. highlighted += value.split(NEWLINE$1).map(str => colorize(str)).join("\n");
  2153. } else {
  2154. highlighted += value;
  2155. }
  2156. }
  2157. return highlighted;
  2158. }
  2159. function shouldHighlight(options) {
  2160. return !!_chalk.supportsColor || options.forceColor;
  2161. }
  2162. function getChalk(options) {
  2163. return options.forceColor ? new _chalk.constructor({
  2164. enabled: true,
  2165. level: 1
  2166. }) : _chalk;
  2167. }
  2168. function highlight(code, options = {}) {
  2169. if (shouldHighlight(options)) {
  2170. const chalk = getChalk(options);
  2171. const defs = getDefs$1(chalk);
  2172. return highlightTokens(defs, code);
  2173. } else {
  2174. return code;
  2175. }
  2176. }
  2177. Object.defineProperty(lib$2, "__esModule", {
  2178. value: true
  2179. });
  2180. lib$2.codeFrameColumns = codeFrameColumns$1;
  2181. lib$2.default = _default;
  2182. var _highlight = lib$1;
  2183. let deprecationWarningShown = false;
  2184. function getDefs(chalk) {
  2185. return {
  2186. gutter: chalk.grey,
  2187. marker: chalk.red.bold,
  2188. message: chalk.red.bold
  2189. };
  2190. }
  2191. const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  2192. function getMarkerLines(loc, source, opts) {
  2193. const startLoc = Object.assign({
  2194. column: 0,
  2195. line: -1
  2196. }, loc.start);
  2197. const endLoc = Object.assign({}, startLoc, loc.end);
  2198. const {
  2199. linesAbove = 2,
  2200. linesBelow = 3
  2201. } = opts || {};
  2202. const startLine = startLoc.line;
  2203. const startColumn = startLoc.column;
  2204. const endLine = endLoc.line;
  2205. const endColumn = endLoc.column;
  2206. let start = Math.max(startLine - (linesAbove + 1), 0);
  2207. let end = Math.min(source.length, endLine + linesBelow);
  2208. if (startLine === -1) {
  2209. start = 0;
  2210. }
  2211. if (endLine === -1) {
  2212. end = source.length;
  2213. }
  2214. const lineDiff = endLine - startLine;
  2215. const markerLines = {};
  2216. if (lineDiff) {
  2217. for (let i = 0; i <= lineDiff; i++) {
  2218. const lineNumber = i + startLine;
  2219. if (!startColumn) {
  2220. markerLines[lineNumber] = true;
  2221. } else if (i === 0) {
  2222. const sourceLength = source[lineNumber - 1].length;
  2223. markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
  2224. } else if (i === lineDiff) {
  2225. markerLines[lineNumber] = [0, endColumn];
  2226. } else {
  2227. const sourceLength = source[lineNumber - i].length;
  2228. markerLines[lineNumber] = [0, sourceLength];
  2229. }
  2230. }
  2231. } else {
  2232. if (startColumn === endColumn) {
  2233. if (startColumn) {
  2234. markerLines[startLine] = [startColumn, 0];
  2235. } else {
  2236. markerLines[startLine] = true;
  2237. }
  2238. } else {
  2239. markerLines[startLine] = [startColumn, endColumn - startColumn];
  2240. }
  2241. }
  2242. return {
  2243. start,
  2244. end,
  2245. markerLines
  2246. };
  2247. }
  2248. function codeFrameColumns$1(rawLines, loc, opts = {}) {
  2249. const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
  2250. const chalk = (0, _highlight.getChalk)(opts);
  2251. const defs = getDefs(chalk);
  2252. const maybeHighlight = (chalkFn, string) => {
  2253. return highlighted ? chalkFn(string) : string;
  2254. };
  2255. const lines = rawLines.split(NEWLINE);
  2256. const {
  2257. start,
  2258. end,
  2259. markerLines
  2260. } = getMarkerLines(loc, lines, opts);
  2261. const hasColumns = loc.start && typeof loc.start.column === "number";
  2262. const numberMaxWidth = String(end).length;
  2263. const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines;
  2264. let frame = highlightedLines.split(NEWLINE, end).slice(start, end).map((line, index) => {
  2265. const number = start + 1 + index;
  2266. const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  2267. const gutter = ` ${paddedNumber} |`;
  2268. const hasMarker = markerLines[number];
  2269. const lastMarkerLine = !markerLines[number + 1];
  2270. if (hasMarker) {
  2271. let markerLine = "";
  2272. if (Array.isArray(hasMarker)) {
  2273. const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  2274. const numberOfMarkers = hasMarker[1] || 1;
  2275. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), " ", markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  2276. if (lastMarkerLine && opts.message) {
  2277. markerLine += " " + maybeHighlight(defs.message, opts.message);
  2278. }
  2279. }
  2280. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
  2281. } else {
  2282. return ` ${maybeHighlight(defs.gutter, gutter)}${line.length > 0 ? ` ${line}` : ""}`;
  2283. }
  2284. }).join("\n");
  2285. if (opts.message && !hasColumns) {
  2286. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  2287. }
  2288. if (highlighted) {
  2289. return chalk.reset(frame);
  2290. } else {
  2291. return frame;
  2292. }
  2293. }
  2294. function _default(rawLines, lineNumber, colNumber, opts = {}) {
  2295. if (!deprecationWarningShown) {
  2296. deprecationWarningShown = true;
  2297. const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  2298. if (process.emitWarning) {
  2299. process.emitWarning(message, "DeprecationWarning");
  2300. } else {
  2301. const deprecationError = new Error(message);
  2302. deprecationError.name = "DeprecationWarning";
  2303. console.warn(new Error(message));
  2304. }
  2305. }
  2306. colNumber = Math.max(colNumber, 0);
  2307. const location = {
  2308. start: {
  2309. column: colNumber,
  2310. line: lineNumber
  2311. }
  2312. };
  2313. return codeFrameColumns$1(rawLines, location, opts);
  2314. }
  2315. const errorEx = errorEx_1;
  2316. const fallback = jsonParseEvenBetterErrors;
  2317. const {
  2318. default: LinesAndColumns
  2319. } = dist$1;
  2320. const {
  2321. codeFrameColumns
  2322. } = lib$2;
  2323. const JSONError = errorEx('JSONError', {
  2324. fileName: errorEx.append('in %s'),
  2325. codeFrame: errorEx.append('\n\n%s\n')
  2326. });
  2327. const parseJson$1 = (string, reviver, filename) => {
  2328. if (typeof reviver === 'string') {
  2329. filename = reviver;
  2330. reviver = null;
  2331. }
  2332. try {
  2333. try {
  2334. return JSON.parse(string, reviver);
  2335. } catch (error) {
  2336. fallback(string, reviver);
  2337. throw error;
  2338. }
  2339. } catch (error) {
  2340. error.message = error.message.replace(/\n/g, '');
  2341. const indexMatch = error.message.match(/in JSON at position (\d+) while parsing/);
  2342. const jsonError = new JSONError(error);
  2343. if (filename) {
  2344. jsonError.fileName = filename;
  2345. }
  2346. if (indexMatch && indexMatch.length > 0) {
  2347. const lines = new LinesAndColumns(string);
  2348. const index = Number(indexMatch[1]);
  2349. const location = lines.locationForIndex(index);
  2350. const codeFrame = codeFrameColumns(string, {
  2351. start: {
  2352. line: location.line + 1,
  2353. column: location.column + 1
  2354. }
  2355. }, {
  2356. highlightCode: true
  2357. });
  2358. jsonError.codeFrame = codeFrame;
  2359. }
  2360. throw jsonError;
  2361. }
  2362. };
  2363. parseJson$1.JSONError = JSONError;
  2364. var parseJson_1 = parseJson$1;
  2365. var dist = {};
  2366. var parseCst$1 = {};
  2367. var PlainValueEc8e588e = {};
  2368. const Char = {
  2369. ANCHOR: '&',
  2370. COMMENT: '#',
  2371. TAG: '!',
  2372. DIRECTIVES_END: '-',
  2373. DOCUMENT_END: '.'
  2374. };
  2375. const Type = {
  2376. ALIAS: 'ALIAS',
  2377. BLANK_LINE: 'BLANK_LINE',
  2378. BLOCK_FOLDED: 'BLOCK_FOLDED',
  2379. BLOCK_LITERAL: 'BLOCK_LITERAL',
  2380. COMMENT: 'COMMENT',
  2381. DIRECTIVE: 'DIRECTIVE',
  2382. DOCUMENT: 'DOCUMENT',
  2383. FLOW_MAP: 'FLOW_MAP',
  2384. FLOW_SEQ: 'FLOW_SEQ',
  2385. MAP: 'MAP',
  2386. MAP_KEY: 'MAP_KEY',
  2387. MAP_VALUE: 'MAP_VALUE',
  2388. PLAIN: 'PLAIN',
  2389. QUOTE_DOUBLE: 'QUOTE_DOUBLE',
  2390. QUOTE_SINGLE: 'QUOTE_SINGLE',
  2391. SEQ: 'SEQ',
  2392. SEQ_ITEM: 'SEQ_ITEM'
  2393. };
  2394. const defaultTagPrefix = 'tag:yaml.org,2002:';
  2395. const defaultTags = {
  2396. MAP: 'tag:yaml.org,2002:map',
  2397. SEQ: 'tag:yaml.org,2002:seq',
  2398. STR: 'tag:yaml.org,2002:str'
  2399. };
  2400. function findLineStarts(src) {
  2401. const ls = [0];
  2402. let offset = src.indexOf('\n');
  2403. while (offset !== -1) {
  2404. offset += 1;
  2405. ls.push(offset);
  2406. offset = src.indexOf('\n', offset);
  2407. }
  2408. return ls;
  2409. }
  2410. function getSrcInfo(cst) {
  2411. let lineStarts, src;
  2412. if (typeof cst === 'string') {
  2413. lineStarts = findLineStarts(cst);
  2414. src = cst;
  2415. } else {
  2416. if (Array.isArray(cst)) cst = cst[0];
  2417. if (cst && cst.context) {
  2418. if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src);
  2419. lineStarts = cst.lineStarts;
  2420. src = cst.context.src;
  2421. }
  2422. }
  2423. return {
  2424. lineStarts,
  2425. src
  2426. };
  2427. }
  2428. /**
  2429. * @typedef {Object} LinePos - One-indexed position in the source
  2430. * @property {number} line
  2431. * @property {number} col
  2432. */
  2433. /**
  2434. * Determine the line/col position matching a character offset.
  2435. *
  2436. * Accepts a source string or a CST document as the second parameter. With
  2437. * the latter, starting indices for lines are cached in the document as
  2438. * `lineStarts: number[]`.
  2439. *
  2440. * Returns a one-indexed `{ line, col }` location if found, or
  2441. * `undefined` otherwise.
  2442. *
  2443. * @param {number} offset
  2444. * @param {string|Document|Document[]} cst
  2445. * @returns {?LinePos}
  2446. */
  2447. function getLinePos(offset, cst) {
  2448. if (typeof offset !== 'number' || offset < 0) return null;
  2449. const {
  2450. lineStarts,
  2451. src
  2452. } = getSrcInfo(cst);
  2453. if (!lineStarts || !src || offset > src.length) return null;
  2454. for (let i = 0; i < lineStarts.length; ++i) {
  2455. const start = lineStarts[i];
  2456. if (offset < start) {
  2457. return {
  2458. line: i,
  2459. col: offset - lineStarts[i - 1] + 1
  2460. };
  2461. }
  2462. if (offset === start) return {
  2463. line: i + 1,
  2464. col: 1
  2465. };
  2466. }
  2467. const line = lineStarts.length;
  2468. return {
  2469. line,
  2470. col: offset - lineStarts[line - 1] + 1
  2471. };
  2472. }
  2473. /**
  2474. * Get a specified line from the source.
  2475. *
  2476. * Accepts a source string or a CST document as the second parameter. With
  2477. * the latter, starting indices for lines are cached in the document as
  2478. * `lineStarts: number[]`.
  2479. *
  2480. * Returns the line as a string if found, or `null` otherwise.
  2481. *
  2482. * @param {number} line One-indexed line number
  2483. * @param {string|Document|Document[]} cst
  2484. * @returns {?string}
  2485. */
  2486. function getLine(line, cst) {
  2487. const {
  2488. lineStarts,
  2489. src
  2490. } = getSrcInfo(cst);
  2491. if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null;
  2492. const start = lineStarts[line - 1];
  2493. let end = lineStarts[line]; // undefined for last line; that's ok for slice()
  2494. while (end && end > start && src[end - 1] === '\n') --end;
  2495. return src.slice(start, end);
  2496. }
  2497. /**
  2498. * Pretty-print the starting line from the source indicated by the range `pos`
  2499. *
  2500. * Trims output to `maxWidth` chars while keeping the starting column visible,
  2501. * using `…` at either end to indicate dropped characters.
  2502. *
  2503. * Returns a two-line string (or `null`) with `\n` as separator; the second line
  2504. * will hold appropriately indented `^` marks indicating the column range.
  2505. *
  2506. * @param {Object} pos
  2507. * @param {LinePos} pos.start
  2508. * @param {LinePos} [pos.end]
  2509. * @param {string|Document|Document[]*} cst
  2510. * @param {number} [maxWidth=80]
  2511. * @returns {?string}
  2512. */
  2513. function getPrettyContext({
  2514. start,
  2515. end
  2516. }, cst, maxWidth = 80) {
  2517. let src = getLine(start.line, cst);
  2518. if (!src) return null;
  2519. let {
  2520. col
  2521. } = start;
  2522. if (src.length > maxWidth) {
  2523. if (col <= maxWidth - 10) {
  2524. src = src.substr(0, maxWidth - 1) + '…';
  2525. } else {
  2526. const halfWidth = Math.round(maxWidth / 2);
  2527. if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…';
  2528. col -= src.length - maxWidth;
  2529. src = '…' + src.substr(1 - maxWidth);
  2530. }
  2531. }
  2532. let errLen = 1;
  2533. let errEnd = '';
  2534. if (end) {
  2535. if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
  2536. errLen = end.col - start.col;
  2537. } else {
  2538. errLen = Math.min(src.length + 1, maxWidth) - col;
  2539. errEnd = '…';
  2540. }
  2541. }
  2542. const offset = col > 1 ? ' '.repeat(col - 1) : '';
  2543. const err = '^'.repeat(errLen);
  2544. return `${src}\n${offset}${err}${errEnd}`;
  2545. }
  2546. class Range {
  2547. static copy(orig) {
  2548. return new Range(orig.start, orig.end);
  2549. }
  2550. constructor(start, end) {
  2551. this.start = start;
  2552. this.end = end || start;
  2553. }
  2554. isEmpty() {
  2555. return typeof this.start !== 'number' || !this.end || this.end <= this.start;
  2556. }
  2557. /**
  2558. * Set `origStart` and `origEnd` to point to the original source range for
  2559. * this node, which may differ due to dropped CR characters.
  2560. *
  2561. * @param {number[]} cr - Positions of dropped CR characters
  2562. * @param {number} offset - Starting index of `cr` from the last call
  2563. * @returns {number} - The next offset, matching the one found for `origStart`
  2564. */
  2565. setOrigRange(cr, offset) {
  2566. const {
  2567. start,
  2568. end
  2569. } = this;
  2570. if (cr.length === 0 || end <= cr[0]) {
  2571. this.origStart = start;
  2572. this.origEnd = end;
  2573. return offset;
  2574. }
  2575. let i = offset;
  2576. while (i < cr.length) {
  2577. if (cr[i] > start) break;else ++i;
  2578. }
  2579. this.origStart = start + i;
  2580. const nextOffset = i;
  2581. while (i < cr.length) {
  2582. // if end was at \n, it should now be at \r
  2583. if (cr[i] >= end) break;else ++i;
  2584. }
  2585. this.origEnd = end + i;
  2586. return nextOffset;
  2587. }
  2588. }
  2589. /** Root class of all nodes */
  2590. class Node$1 {
  2591. static addStringTerminator(src, offset, str) {
  2592. if (str[str.length - 1] === '\n') return str;
  2593. const next = Node$1.endOfWhiteSpace(src, offset);
  2594. return next >= src.length || src[next] === '\n' ? str + '\n' : str;
  2595. } // ^(---|...)
  2596. static atDocumentBoundary(src, offset, sep) {
  2597. const ch0 = src[offset];
  2598. if (!ch0) return true;
  2599. const prev = src[offset - 1];
  2600. if (prev && prev !== '\n') return false;
  2601. if (sep) {
  2602. if (ch0 !== sep) return false;
  2603. } else {
  2604. if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
  2605. }
  2606. const ch1 = src[offset + 1];
  2607. const ch2 = src[offset + 2];
  2608. if (ch1 !== ch0 || ch2 !== ch0) return false;
  2609. const ch3 = src[offset + 3];
  2610. return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
  2611. }
  2612. static endOfIdentifier(src, offset) {
  2613. let ch = src[offset];
  2614. const isVerbatim = ch === '<';
  2615. const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
  2616. while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1];
  2617. if (isVerbatim && ch === '>') offset += 1;
  2618. return offset;
  2619. }
  2620. static endOfIndent(src, offset) {
  2621. let ch = src[offset];
  2622. while (ch === ' ') ch = src[offset += 1];
  2623. return offset;
  2624. }
  2625. static endOfLine(src, offset) {
  2626. let ch = src[offset];
  2627. while (ch && ch !== '\n') ch = src[offset += 1];
  2628. return offset;
  2629. }
  2630. static endOfWhiteSpace(src, offset) {
  2631. let ch = src[offset];
  2632. while (ch === '\t' || ch === ' ') ch = src[offset += 1];
  2633. return offset;
  2634. }
  2635. static startOfLine(src, offset) {
  2636. let ch = src[offset - 1];
  2637. if (ch === '\n') return offset;
  2638. while (ch && ch !== '\n') ch = src[offset -= 1];
  2639. return offset + 1;
  2640. }
  2641. /**
  2642. * End of indentation, or null if the line's indent level is not more
  2643. * than `indent`
  2644. *
  2645. * @param {string} src
  2646. * @param {number} indent
  2647. * @param {number} lineStart
  2648. * @returns {?number}
  2649. */
  2650. static endOfBlockIndent(src, indent, lineStart) {
  2651. const inEnd = Node$1.endOfIndent(src, lineStart);
  2652. if (inEnd > lineStart + indent) {
  2653. return inEnd;
  2654. } else {
  2655. const wsEnd = Node$1.endOfWhiteSpace(src, inEnd);
  2656. const ch = src[wsEnd];
  2657. if (!ch || ch === '\n') return wsEnd;
  2658. }
  2659. return null;
  2660. }
  2661. static atBlank(src, offset, endAsBlank) {
  2662. const ch = src[offset];
  2663. return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
  2664. }
  2665. static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
  2666. if (!ch || indentDiff < 0) return false;
  2667. if (indentDiff > 0) return true;
  2668. return indicatorAsIndent && ch === '-';
  2669. } // should be at line or string end, or at next non-whitespace char
  2670. static normalizeOffset(src, offset) {
  2671. const ch = src[offset];
  2672. return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node$1.endOfWhiteSpace(src, offset);
  2673. } // fold single newline into space, multiple newlines to N - 1 newlines
  2674. // presumes src[offset] === '\n'
  2675. static foldNewline(src, offset, indent) {
  2676. let inCount = 0;
  2677. let error = false;
  2678. let fold = '';
  2679. let ch = src[offset + 1];
  2680. while (ch === ' ' || ch === '\t' || ch === '\n') {
  2681. switch (ch) {
  2682. case '\n':
  2683. inCount = 0;
  2684. offset += 1;
  2685. fold += '\n';
  2686. break;
  2687. case '\t':
  2688. if (inCount <= indent) error = true;
  2689. offset = Node$1.endOfWhiteSpace(src, offset + 2) - 1;
  2690. break;
  2691. case ' ':
  2692. inCount += 1;
  2693. offset += 1;
  2694. break;
  2695. }
  2696. ch = src[offset + 1];
  2697. }
  2698. if (!fold) fold = ' ';
  2699. if (ch && inCount <= indent) error = true;
  2700. return {
  2701. fold,
  2702. offset,
  2703. error
  2704. };
  2705. }
  2706. constructor(type, props, context) {
  2707. Object.defineProperty(this, 'context', {
  2708. value: context || null,
  2709. writable: true
  2710. });
  2711. this.error = null;
  2712. this.range = null;
  2713. this.valueRange = null;
  2714. this.props = props || [];
  2715. this.type = type;
  2716. this.value = null;
  2717. }
  2718. getPropValue(idx, key, skipKey) {
  2719. if (!this.context) return null;
  2720. const {
  2721. src
  2722. } = this.context;
  2723. const prop = this.props[idx];
  2724. return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
  2725. }
  2726. get anchor() {
  2727. for (let i = 0; i < this.props.length; ++i) {
  2728. const anchor = this.getPropValue(i, Char.ANCHOR, true);
  2729. if (anchor != null) return anchor;
  2730. }
  2731. return null;
  2732. }
  2733. get comment() {
  2734. const comments = [];
  2735. for (let i = 0; i < this.props.length; ++i) {
  2736. const comment = this.getPropValue(i, Char.COMMENT, true);
  2737. if (comment != null) comments.push(comment);
  2738. }
  2739. return comments.length > 0 ? comments.join('\n') : null;
  2740. }
  2741. commentHasRequiredWhitespace(start) {
  2742. const {
  2743. src
  2744. } = this.context;
  2745. if (this.header && start === this.header.end) return false;
  2746. if (!this.valueRange) return false;
  2747. const {
  2748. end
  2749. } = this.valueRange;
  2750. return start !== end || Node$1.atBlank(src, end - 1);
  2751. }
  2752. get hasComment() {
  2753. if (this.context) {
  2754. const {
  2755. src
  2756. } = this.context;
  2757. for (let i = 0; i < this.props.length; ++i) {
  2758. if (src[this.props[i].start] === Char.COMMENT) return true;
  2759. }
  2760. }
  2761. return false;
  2762. }
  2763. get hasProps() {
  2764. if (this.context) {
  2765. const {
  2766. src
  2767. } = this.context;
  2768. for (let i = 0; i < this.props.length; ++i) {
  2769. if (src[this.props[i].start] !== Char.COMMENT) return true;
  2770. }
  2771. }
  2772. return false;
  2773. }
  2774. get includesTrailingLines() {
  2775. return false;
  2776. }
  2777. get jsonLike() {
  2778. const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
  2779. return jsonLikeTypes.indexOf(this.type) !== -1;
  2780. }
  2781. get rangeAsLinePos() {
  2782. if (!this.range || !this.context) return undefined;
  2783. const start = getLinePos(this.range.start, this.context.root);
  2784. if (!start) return undefined;
  2785. const end = getLinePos(this.range.end, this.context.root);
  2786. return {
  2787. start,
  2788. end
  2789. };
  2790. }
  2791. get rawValue() {
  2792. if (!this.valueRange || !this.context) return null;
  2793. const {
  2794. start,
  2795. end
  2796. } = this.valueRange;
  2797. return this.context.src.slice(start, end);
  2798. }
  2799. get tag() {
  2800. for (let i = 0; i < this.props.length; ++i) {
  2801. const tag = this.getPropValue(i, Char.TAG, false);
  2802. if (tag != null) {
  2803. if (tag[1] === '<') {
  2804. return {
  2805. verbatim: tag.slice(2, -1)
  2806. };
  2807. } else {
  2808. // eslint-disable-next-line no-unused-vars
  2809. const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/);
  2810. return {
  2811. handle,
  2812. suffix
  2813. };
  2814. }
  2815. }
  2816. }
  2817. return null;
  2818. }
  2819. get valueRangeContainsNewline() {
  2820. if (!this.valueRange || !this.context) return false;
  2821. const {
  2822. start,
  2823. end
  2824. } = this.valueRange;
  2825. const {
  2826. src
  2827. } = this.context;
  2828. for (let i = start; i < end; ++i) {
  2829. if (src[i] === '\n') return true;
  2830. }
  2831. return false;
  2832. }
  2833. parseComment(start) {
  2834. const {
  2835. src
  2836. } = this.context;
  2837. if (src[start] === Char.COMMENT) {
  2838. const end = Node$1.endOfLine(src, start + 1);
  2839. const commentRange = new Range(start, end);
  2840. this.props.push(commentRange);
  2841. return end;
  2842. }
  2843. return start;
  2844. }
  2845. /**
  2846. * Populates the `origStart` and `origEnd` values of all ranges for this
  2847. * node. Extended by child classes to handle descendant nodes.
  2848. *
  2849. * @param {number[]} cr - Positions of dropped CR characters
  2850. * @param {number} offset - Starting index of `cr` from the last call
  2851. * @returns {number} - The next offset, matching the one found for `origStart`
  2852. */
  2853. setOrigRanges(cr, offset) {
  2854. if (this.range) offset = this.range.setOrigRange(cr, offset);
  2855. if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
  2856. this.props.forEach(prop => prop.setOrigRange(cr, offset));
  2857. return offset;
  2858. }
  2859. toString() {
  2860. const {
  2861. context: {
  2862. src
  2863. },
  2864. range,
  2865. value
  2866. } = this;
  2867. if (value != null) return value;
  2868. const str = src.slice(range.start, range.end);
  2869. return Node$1.addStringTerminator(src, range.end, str);
  2870. }
  2871. }
  2872. class YAMLError extends Error {
  2873. constructor(name, source, message) {
  2874. if (!message || !(source instanceof Node$1)) throw new Error(`Invalid arguments for new ${name}`);
  2875. super();
  2876. this.name = name;
  2877. this.message = message;
  2878. this.source = source;
  2879. }
  2880. makePretty() {
  2881. if (!this.source) return;
  2882. this.nodeType = this.source.type;
  2883. const cst = this.source.context && this.source.context.root;
  2884. if (typeof this.offset === 'number') {
  2885. this.range = new Range(this.offset, this.offset + 1);
  2886. const start = cst && getLinePos(this.offset, cst);
  2887. if (start) {
  2888. const end = {
  2889. line: start.line,
  2890. col: start.col + 1
  2891. };
  2892. this.linePos = {
  2893. start,
  2894. end
  2895. };
  2896. }
  2897. delete this.offset;
  2898. } else {
  2899. this.range = this.source.range;
  2900. this.linePos = this.source.rangeAsLinePos;
  2901. }
  2902. if (this.linePos) {
  2903. const {
  2904. line,
  2905. col
  2906. } = this.linePos.start;
  2907. this.message += ` at line ${line}, column ${col}`;
  2908. const ctx = cst && getPrettyContext(this.linePos, cst);
  2909. if (ctx) this.message += `:\n\n${ctx}\n`;
  2910. }
  2911. delete this.source;
  2912. }
  2913. }
  2914. class YAMLReferenceError extends YAMLError {
  2915. constructor(source, message) {
  2916. super('YAMLReferenceError', source, message);
  2917. }
  2918. }
  2919. class YAMLSemanticError extends YAMLError {
  2920. constructor(source, message) {
  2921. super('YAMLSemanticError', source, message);
  2922. }
  2923. }
  2924. class YAMLSyntaxError extends YAMLError {
  2925. constructor(source, message) {
  2926. super('YAMLSyntaxError', source, message);
  2927. }
  2928. }
  2929. class YAMLWarning extends YAMLError {
  2930. constructor(source, message) {
  2931. super('YAMLWarning', source, message);
  2932. }
  2933. }
  2934. function _defineProperty(obj, key, value) {
  2935. if (key in obj) {
  2936. Object.defineProperty(obj, key, {
  2937. value: value,
  2938. enumerable: true,
  2939. configurable: true,
  2940. writable: true
  2941. });
  2942. } else {
  2943. obj[key] = value;
  2944. }
  2945. return obj;
  2946. }
  2947. class PlainValue$6 extends Node$1 {
  2948. static endOfLine(src, start, inFlow) {
  2949. let ch = src[start];
  2950. let offset = start;
  2951. while (ch && ch !== '\n') {
  2952. if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break;
  2953. const next = src[offset + 1];
  2954. if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
  2955. if ((ch === ' ' || ch === '\t') && next === '#') break;
  2956. offset += 1;
  2957. ch = next;
  2958. }
  2959. return offset;
  2960. }
  2961. get strValue() {
  2962. if (!this.valueRange || !this.context) return null;
  2963. let {
  2964. start,
  2965. end
  2966. } = this.valueRange;
  2967. const {
  2968. src
  2969. } = this.context;
  2970. let ch = src[end - 1];
  2971. while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) ch = src[--end - 1];
  2972. let str = '';
  2973. for (let i = start; i < end; ++i) {
  2974. const ch = src[i];
  2975. if (ch === '\n') {
  2976. const {
  2977. fold,
  2978. offset
  2979. } = Node$1.foldNewline(src, i, -1);
  2980. str += fold;
  2981. i = offset;
  2982. } else if (ch === ' ' || ch === '\t') {
  2983. // trim trailing whitespace
  2984. const wsStart = i;
  2985. let next = src[i + 1];
  2986. while (i < end && (next === ' ' || next === '\t')) {
  2987. i += 1;
  2988. next = src[i + 1];
  2989. }
  2990. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  2991. } else {
  2992. str += ch;
  2993. }
  2994. }
  2995. const ch0 = src[start];
  2996. switch (ch0) {
  2997. case '\t':
  2998. {
  2999. const msg = 'Plain value cannot start with a tab character';
  3000. const errors = [new YAMLSemanticError(this, msg)];
  3001. return {
  3002. errors,
  3003. str
  3004. };
  3005. }
  3006. case '@':
  3007. case '`':
  3008. {
  3009. const msg = `Plain value cannot start with reserved character ${ch0}`;
  3010. const errors = [new YAMLSemanticError(this, msg)];
  3011. return {
  3012. errors,
  3013. str
  3014. };
  3015. }
  3016. default:
  3017. return str;
  3018. }
  3019. }
  3020. parseBlockValue(start) {
  3021. const {
  3022. indent,
  3023. inFlow,
  3024. src
  3025. } = this.context;
  3026. let offset = start;
  3027. let valueEnd = start;
  3028. for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
  3029. if (Node$1.atDocumentBoundary(src, offset + 1)) break;
  3030. const end = Node$1.endOfBlockIndent(src, indent, offset + 1);
  3031. if (end === null || src[end] === '#') break;
  3032. if (src[end] === '\n') {
  3033. offset = end;
  3034. } else {
  3035. valueEnd = PlainValue$6.endOfLine(src, end, inFlow);
  3036. offset = valueEnd;
  3037. }
  3038. }
  3039. if (this.valueRange.isEmpty()) this.valueRange.start = start;
  3040. this.valueRange.end = valueEnd;
  3041. return valueEnd;
  3042. }
  3043. /**
  3044. * Parses a plain value from the source
  3045. *
  3046. * Accepted forms are:
  3047. * ```
  3048. * #comment
  3049. *
  3050. * first line
  3051. *
  3052. * first line #comment
  3053. *
  3054. * first line
  3055. * block
  3056. * lines
  3057. *
  3058. * #comment
  3059. * block
  3060. * lines
  3061. * ```
  3062. * where block lines are empty or have an indent level greater than `indent`.
  3063. *
  3064. * @param {ParseContext} context
  3065. * @param {number} start - Index of first character
  3066. * @returns {number} - Index of the character after this scalar, may be `\n`
  3067. */
  3068. parse(context, start) {
  3069. this.context = context;
  3070. const {
  3071. inFlow,
  3072. src
  3073. } = context;
  3074. let offset = start;
  3075. const ch = src[offset];
  3076. if (ch && ch !== '#' && ch !== '\n') {
  3077. offset = PlainValue$6.endOfLine(src, start, inFlow);
  3078. }
  3079. this.valueRange = new Range(start, offset);
  3080. offset = Node$1.endOfWhiteSpace(src, offset);
  3081. offset = this.parseComment(offset);
  3082. if (!this.hasComment || this.valueRange.isEmpty()) {
  3083. offset = this.parseBlockValue(offset);
  3084. }
  3085. return offset;
  3086. }
  3087. }
  3088. PlainValueEc8e588e.Char = Char;
  3089. PlainValueEc8e588e.Node = Node$1;
  3090. PlainValueEc8e588e.PlainValue = PlainValue$6;
  3091. PlainValueEc8e588e.Range = Range;
  3092. PlainValueEc8e588e.Type = Type;
  3093. PlainValueEc8e588e.YAMLError = YAMLError;
  3094. PlainValueEc8e588e.YAMLReferenceError = YAMLReferenceError;
  3095. PlainValueEc8e588e.YAMLSemanticError = YAMLSemanticError;
  3096. PlainValueEc8e588e.YAMLSyntaxError = YAMLSyntaxError;
  3097. PlainValueEc8e588e.YAMLWarning = YAMLWarning;
  3098. PlainValueEc8e588e._defineProperty = _defineProperty;
  3099. PlainValueEc8e588e.defaultTagPrefix = defaultTagPrefix;
  3100. PlainValueEc8e588e.defaultTags = defaultTags;
  3101. var PlainValue$5 = PlainValueEc8e588e;
  3102. class BlankLine extends PlainValue$5.Node {
  3103. constructor() {
  3104. super(PlainValue$5.Type.BLANK_LINE);
  3105. }
  3106. /* istanbul ignore next */
  3107. get includesTrailingLines() {
  3108. // This is never called from anywhere, but if it were,
  3109. // this is the value it should return.
  3110. return true;
  3111. }
  3112. /**
  3113. * Parses a blank line from the source
  3114. *
  3115. * @param {ParseContext} context
  3116. * @param {number} start - Index of first \n character
  3117. * @returns {number} - Index of the character after this
  3118. */
  3119. parse(context, start) {
  3120. this.context = context;
  3121. this.range = new PlainValue$5.Range(start, start + 1);
  3122. return start + 1;
  3123. }
  3124. }
  3125. class CollectionItem extends PlainValue$5.Node {
  3126. constructor(type, props) {
  3127. super(type, props);
  3128. this.node = null;
  3129. }
  3130. get includesTrailingLines() {
  3131. return !!this.node && this.node.includesTrailingLines;
  3132. }
  3133. /**
  3134. * @param {ParseContext} context
  3135. * @param {number} start - Index of first character
  3136. * @returns {number} - Index of the character after this
  3137. */
  3138. parse(context, start) {
  3139. this.context = context;
  3140. const {
  3141. parseNode,
  3142. src
  3143. } = context;
  3144. let {
  3145. atLineStart,
  3146. lineStart
  3147. } = context;
  3148. if (!atLineStart && this.type === PlainValue$5.Type.SEQ_ITEM) this.error = new PlainValue$5.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
  3149. const indent = atLineStart ? start - lineStart : context.indent;
  3150. let offset = PlainValue$5.Node.endOfWhiteSpace(src, start + 1);
  3151. let ch = src[offset];
  3152. const inlineComment = ch === '#';
  3153. const comments = [];
  3154. let blankLine = null;
  3155. while (ch === '\n' || ch === '#') {
  3156. if (ch === '#') {
  3157. const end = PlainValue$5.Node.endOfLine(src, offset + 1);
  3158. comments.push(new PlainValue$5.Range(offset, end));
  3159. offset = end;
  3160. } else {
  3161. atLineStart = true;
  3162. lineStart = offset + 1;
  3163. const wsEnd = PlainValue$5.Node.endOfWhiteSpace(src, lineStart);
  3164. if (src[wsEnd] === '\n' && comments.length === 0) {
  3165. blankLine = new BlankLine();
  3166. lineStart = blankLine.parse({
  3167. src
  3168. }, lineStart);
  3169. }
  3170. offset = PlainValue$5.Node.endOfIndent(src, lineStart);
  3171. }
  3172. ch = src[offset];
  3173. }
  3174. if (PlainValue$5.Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== PlainValue$5.Type.SEQ_ITEM)) {
  3175. this.node = parseNode({
  3176. atLineStart,
  3177. inCollection: false,
  3178. indent,
  3179. lineStart,
  3180. parent: this
  3181. }, offset);
  3182. } else if (ch && lineStart > start + 1) {
  3183. offset = lineStart - 1;
  3184. }
  3185. if (this.node) {
  3186. if (blankLine) {
  3187. // Only blank lines preceding non-empty nodes are captured. Note that
  3188. // this means that collection item range start indices do not always
  3189. // increase monotonically. -- eemeli/yaml#126
  3190. const items = context.parent.items || context.parent.contents;
  3191. if (items) items.push(blankLine);
  3192. }
  3193. if (comments.length) Array.prototype.push.apply(this.props, comments);
  3194. offset = this.node.range.end;
  3195. } else {
  3196. if (inlineComment) {
  3197. const c = comments[0];
  3198. this.props.push(c);
  3199. offset = c.end;
  3200. } else {
  3201. offset = PlainValue$5.Node.endOfLine(src, start + 1);
  3202. }
  3203. }
  3204. const end = this.node ? this.node.valueRange.end : offset;
  3205. this.valueRange = new PlainValue$5.Range(start, end);
  3206. return offset;
  3207. }
  3208. setOrigRanges(cr, offset) {
  3209. offset = super.setOrigRanges(cr, offset);
  3210. return this.node ? this.node.setOrigRanges(cr, offset) : offset;
  3211. }
  3212. toString() {
  3213. const {
  3214. context: {
  3215. src
  3216. },
  3217. node,
  3218. range,
  3219. value
  3220. } = this;
  3221. if (value != null) return value;
  3222. const str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end);
  3223. return PlainValue$5.Node.addStringTerminator(src, range.end, str);
  3224. }
  3225. }
  3226. class Comment extends PlainValue$5.Node {
  3227. constructor() {
  3228. super(PlainValue$5.Type.COMMENT);
  3229. }
  3230. /**
  3231. * Parses a comment line from the source
  3232. *
  3233. * @param {ParseContext} context
  3234. * @param {number} start - Index of first character
  3235. * @returns {number} - Index of the character after this scalar
  3236. */
  3237. parse(context, start) {
  3238. this.context = context;
  3239. const offset = this.parseComment(start);
  3240. this.range = new PlainValue$5.Range(start, offset);
  3241. return offset;
  3242. }
  3243. }
  3244. function grabCollectionEndComments(node) {
  3245. let cnode = node;
  3246. while (cnode instanceof CollectionItem) cnode = cnode.node;
  3247. if (!(cnode instanceof Collection$1)) return null;
  3248. const len = cnode.items.length;
  3249. let ci = -1;
  3250. for (let i = len - 1; i >= 0; --i) {
  3251. const n = cnode.items[i];
  3252. if (n.type === PlainValue$5.Type.COMMENT) {
  3253. // Keep sufficiently indented comments with preceding node
  3254. const {
  3255. indent,
  3256. lineStart
  3257. } = n.context;
  3258. if (indent > 0 && n.range.start >= lineStart + indent) break;
  3259. ci = i;
  3260. } else if (n.type === PlainValue$5.Type.BLANK_LINE) ci = i;else break;
  3261. }
  3262. if (ci === -1) return null;
  3263. const ca = cnode.items.splice(ci, len - ci);
  3264. const prevEnd = ca[0].range.start;
  3265. while (true) {
  3266. cnode.range.end = prevEnd;
  3267. if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd;
  3268. if (cnode === node) break;
  3269. cnode = cnode.context.parent;
  3270. }
  3271. return ca;
  3272. }
  3273. class Collection$1 extends PlainValue$5.Node {
  3274. static nextContentHasIndent(src, offset, indent) {
  3275. const lineStart = PlainValue$5.Node.endOfLine(src, offset) + 1;
  3276. offset = PlainValue$5.Node.endOfWhiteSpace(src, lineStart);
  3277. const ch = src[offset];
  3278. if (!ch) return false;
  3279. if (offset >= lineStart + indent) return true;
  3280. if (ch !== '#' && ch !== '\n') return false;
  3281. return Collection$1.nextContentHasIndent(src, offset, indent);
  3282. }
  3283. constructor(firstItem) {
  3284. super(firstItem.type === PlainValue$5.Type.SEQ_ITEM ? PlainValue$5.Type.SEQ : PlainValue$5.Type.MAP);
  3285. for (let i = firstItem.props.length - 1; i >= 0; --i) {
  3286. if (firstItem.props[i].start < firstItem.context.lineStart) {
  3287. // props on previous line are assumed by the collection
  3288. this.props = firstItem.props.slice(0, i + 1);
  3289. firstItem.props = firstItem.props.slice(i + 1);
  3290. const itemRange = firstItem.props[0] || firstItem.valueRange;
  3291. firstItem.range.start = itemRange.start;
  3292. break;
  3293. }
  3294. }
  3295. this.items = [firstItem];
  3296. const ec = grabCollectionEndComments(firstItem);
  3297. if (ec) Array.prototype.push.apply(this.items, ec);
  3298. }
  3299. get includesTrailingLines() {
  3300. return this.items.length > 0;
  3301. }
  3302. /**
  3303. * @param {ParseContext} context
  3304. * @param {number} start - Index of first character
  3305. * @returns {number} - Index of the character after this
  3306. */
  3307. parse(context, start) {
  3308. this.context = context;
  3309. const {
  3310. parseNode,
  3311. src
  3312. } = context; // It's easier to recalculate lineStart here rather than tracking down the
  3313. // last context from which to read it -- eemeli/yaml#2
  3314. let lineStart = PlainValue$5.Node.startOfLine(src, start);
  3315. const firstItem = this.items[0]; // First-item context needs to be correct for later comment handling
  3316. // -- eemeli/yaml#17
  3317. firstItem.context.parent = this;
  3318. this.valueRange = PlainValue$5.Range.copy(firstItem.valueRange);
  3319. const indent = firstItem.range.start - firstItem.context.lineStart;
  3320. let offset = start;
  3321. offset = PlainValue$5.Node.normalizeOffset(src, offset);
  3322. let ch = src[offset];
  3323. let atLineStart = PlainValue$5.Node.endOfWhiteSpace(src, lineStart) === offset;
  3324. let prevIncludesTrailingLines = false;
  3325. while (ch) {
  3326. while (ch === '\n' || ch === '#') {
  3327. if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) {
  3328. const blankLine = new BlankLine();
  3329. offset = blankLine.parse({
  3330. src
  3331. }, offset);
  3332. this.valueRange.end = offset;
  3333. if (offset >= src.length) {
  3334. ch = null;
  3335. break;
  3336. }
  3337. this.items.push(blankLine);
  3338. offset -= 1; // blankLine.parse() consumes terminal newline
  3339. } else if (ch === '#') {
  3340. if (offset < lineStart + indent && !Collection$1.nextContentHasIndent(src, offset, indent)) {
  3341. return offset;
  3342. }
  3343. const comment = new Comment();
  3344. offset = comment.parse({
  3345. indent,
  3346. lineStart,
  3347. src
  3348. }, offset);
  3349. this.items.push(comment);
  3350. this.valueRange.end = offset;
  3351. if (offset >= src.length) {
  3352. ch = null;
  3353. break;
  3354. }
  3355. }
  3356. lineStart = offset + 1;
  3357. offset = PlainValue$5.Node.endOfIndent(src, lineStart);
  3358. if (PlainValue$5.Node.atBlank(src, offset)) {
  3359. const wsEnd = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  3360. const next = src[wsEnd];
  3361. if (!next || next === '\n' || next === '#') {
  3362. offset = wsEnd;
  3363. }
  3364. }
  3365. ch = src[offset];
  3366. atLineStart = true;
  3367. }
  3368. if (!ch) {
  3369. break;
  3370. }
  3371. if (offset !== lineStart + indent && (atLineStart || ch !== ':')) {
  3372. if (offset < lineStart + indent) {
  3373. if (lineStart > start) offset = lineStart;
  3374. break;
  3375. } else if (!this.error) {
  3376. const msg = 'All collection items must start at the same column';
  3377. this.error = new PlainValue$5.YAMLSyntaxError(this, msg);
  3378. }
  3379. }
  3380. if (firstItem.type === PlainValue$5.Type.SEQ_ITEM) {
  3381. if (ch !== '-') {
  3382. if (lineStart > start) offset = lineStart;
  3383. break;
  3384. }
  3385. } else if (ch === '-' && !this.error) {
  3386. // map key may start with -, as long as it's followed by a non-whitespace char
  3387. const next = src[offset + 1];
  3388. if (!next || next === '\n' || next === '\t' || next === ' ') {
  3389. const msg = 'A collection cannot be both a mapping and a sequence';
  3390. this.error = new PlainValue$5.YAMLSyntaxError(this, msg);
  3391. }
  3392. }
  3393. const node = parseNode({
  3394. atLineStart,
  3395. inCollection: true,
  3396. indent,
  3397. lineStart,
  3398. parent: this
  3399. }, offset);
  3400. if (!node) return offset; // at next document start
  3401. this.items.push(node);
  3402. this.valueRange.end = node.valueRange.end;
  3403. offset = PlainValue$5.Node.normalizeOffset(src, node.range.end);
  3404. ch = src[offset];
  3405. atLineStart = false;
  3406. prevIncludesTrailingLines = node.includesTrailingLines; // Need to reset lineStart and atLineStart here if preceding node's range
  3407. // has advanced to check the current line's indentation level
  3408. // -- eemeli/yaml#10 & eemeli/yaml#38
  3409. if (ch) {
  3410. let ls = offset - 1;
  3411. let prev = src[ls];
  3412. while (prev === ' ' || prev === '\t') prev = src[--ls];
  3413. if (prev === '\n') {
  3414. lineStart = ls + 1;
  3415. atLineStart = true;
  3416. }
  3417. }
  3418. const ec = grabCollectionEndComments(node);
  3419. if (ec) Array.prototype.push.apply(this.items, ec);
  3420. }
  3421. return offset;
  3422. }
  3423. setOrigRanges(cr, offset) {
  3424. offset = super.setOrigRanges(cr, offset);
  3425. this.items.forEach(node => {
  3426. offset = node.setOrigRanges(cr, offset);
  3427. });
  3428. return offset;
  3429. }
  3430. toString() {
  3431. const {
  3432. context: {
  3433. src
  3434. },
  3435. items,
  3436. range,
  3437. value
  3438. } = this;
  3439. if (value != null) return value;
  3440. let str = src.slice(range.start, items[0].range.start) + String(items[0]);
  3441. for (let i = 1; i < items.length; ++i) {
  3442. const item = items[i];
  3443. const {
  3444. atLineStart,
  3445. indent
  3446. } = item.context;
  3447. if (atLineStart) for (let i = 0; i < indent; ++i) str += ' ';
  3448. str += String(item);
  3449. }
  3450. return PlainValue$5.Node.addStringTerminator(src, range.end, str);
  3451. }
  3452. }
  3453. class Directive extends PlainValue$5.Node {
  3454. constructor() {
  3455. super(PlainValue$5.Type.DIRECTIVE);
  3456. this.name = null;
  3457. }
  3458. get parameters() {
  3459. const raw = this.rawValue;
  3460. return raw ? raw.trim().split(/[ \t]+/) : [];
  3461. }
  3462. parseName(start) {
  3463. const {
  3464. src
  3465. } = this.context;
  3466. let offset = start;
  3467. let ch = src[offset];
  3468. while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') ch = src[offset += 1];
  3469. this.name = src.slice(start, offset);
  3470. return offset;
  3471. }
  3472. parseParameters(start) {
  3473. const {
  3474. src
  3475. } = this.context;
  3476. let offset = start;
  3477. let ch = src[offset];
  3478. while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1];
  3479. this.valueRange = new PlainValue$5.Range(start, offset);
  3480. return offset;
  3481. }
  3482. parse(context, start) {
  3483. this.context = context;
  3484. let offset = this.parseName(start + 1);
  3485. offset = this.parseParameters(offset);
  3486. offset = this.parseComment(offset);
  3487. this.range = new PlainValue$5.Range(start, offset);
  3488. return offset;
  3489. }
  3490. }
  3491. class Document$3 extends PlainValue$5.Node {
  3492. static startCommentOrEndBlankLine(src, start) {
  3493. const offset = PlainValue$5.Node.endOfWhiteSpace(src, start);
  3494. const ch = src[offset];
  3495. return ch === '#' || ch === '\n' ? offset : start;
  3496. }
  3497. constructor() {
  3498. super(PlainValue$5.Type.DOCUMENT);
  3499. this.directives = null;
  3500. this.contents = null;
  3501. this.directivesEndMarker = null;
  3502. this.documentEndMarker = null;
  3503. }
  3504. parseDirectives(start) {
  3505. const {
  3506. src
  3507. } = this.context;
  3508. this.directives = [];
  3509. let atLineStart = true;
  3510. let hasDirectives = false;
  3511. let offset = start;
  3512. while (!PlainValue$5.Node.atDocumentBoundary(src, offset, PlainValue$5.Char.DIRECTIVES_END)) {
  3513. offset = Document$3.startCommentOrEndBlankLine(src, offset);
  3514. switch (src[offset]) {
  3515. case '\n':
  3516. if (atLineStart) {
  3517. const blankLine = new BlankLine();
  3518. offset = blankLine.parse({
  3519. src
  3520. }, offset);
  3521. if (offset < src.length) {
  3522. this.directives.push(blankLine);
  3523. }
  3524. } else {
  3525. offset += 1;
  3526. atLineStart = true;
  3527. }
  3528. break;
  3529. case '#':
  3530. {
  3531. const comment = new Comment();
  3532. offset = comment.parse({
  3533. src
  3534. }, offset);
  3535. this.directives.push(comment);
  3536. atLineStart = false;
  3537. }
  3538. break;
  3539. case '%':
  3540. {
  3541. const directive = new Directive();
  3542. offset = directive.parse({
  3543. parent: this,
  3544. src
  3545. }, offset);
  3546. this.directives.push(directive);
  3547. hasDirectives = true;
  3548. atLineStart = false;
  3549. }
  3550. break;
  3551. default:
  3552. if (hasDirectives) {
  3553. this.error = new PlainValue$5.YAMLSemanticError(this, 'Missing directives-end indicator line');
  3554. } else if (this.directives.length > 0) {
  3555. this.contents = this.directives;
  3556. this.directives = [];
  3557. }
  3558. return offset;
  3559. }
  3560. }
  3561. if (src[offset]) {
  3562. this.directivesEndMarker = new PlainValue$5.Range(offset, offset + 3);
  3563. return offset + 3;
  3564. }
  3565. if (hasDirectives) {
  3566. this.error = new PlainValue$5.YAMLSemanticError(this, 'Missing directives-end indicator line');
  3567. } else if (this.directives.length > 0) {
  3568. this.contents = this.directives;
  3569. this.directives = [];
  3570. }
  3571. return offset;
  3572. }
  3573. parseContents(start) {
  3574. const {
  3575. parseNode,
  3576. src
  3577. } = this.context;
  3578. if (!this.contents) this.contents = [];
  3579. let lineStart = start;
  3580. while (src[lineStart - 1] === '-') lineStart -= 1;
  3581. let offset = PlainValue$5.Node.endOfWhiteSpace(src, start);
  3582. let atLineStart = lineStart === start;
  3583. this.valueRange = new PlainValue$5.Range(offset);
  3584. while (!PlainValue$5.Node.atDocumentBoundary(src, offset, PlainValue$5.Char.DOCUMENT_END)) {
  3585. switch (src[offset]) {
  3586. case '\n':
  3587. if (atLineStart) {
  3588. const blankLine = new BlankLine();
  3589. offset = blankLine.parse({
  3590. src
  3591. }, offset);
  3592. if (offset < src.length) {
  3593. this.contents.push(blankLine);
  3594. }
  3595. } else {
  3596. offset += 1;
  3597. atLineStart = true;
  3598. }
  3599. lineStart = offset;
  3600. break;
  3601. case '#':
  3602. {
  3603. const comment = new Comment();
  3604. offset = comment.parse({
  3605. src
  3606. }, offset);
  3607. this.contents.push(comment);
  3608. atLineStart = false;
  3609. }
  3610. break;
  3611. default:
  3612. {
  3613. const iEnd = PlainValue$5.Node.endOfIndent(src, offset);
  3614. const context = {
  3615. atLineStart,
  3616. indent: -1,
  3617. inFlow: false,
  3618. inCollection: false,
  3619. lineStart,
  3620. parent: this
  3621. };
  3622. const node = parseNode(context, iEnd);
  3623. if (!node) return this.valueRange.end = iEnd; // at next document start
  3624. this.contents.push(node);
  3625. offset = node.range.end;
  3626. atLineStart = false;
  3627. const ec = grabCollectionEndComments(node);
  3628. if (ec) Array.prototype.push.apply(this.contents, ec);
  3629. }
  3630. }
  3631. offset = Document$3.startCommentOrEndBlankLine(src, offset);
  3632. }
  3633. this.valueRange.end = offset;
  3634. if (src[offset]) {
  3635. this.documentEndMarker = new PlainValue$5.Range(offset, offset + 3);
  3636. offset += 3;
  3637. if (src[offset]) {
  3638. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  3639. if (src[offset] === '#') {
  3640. const comment = new Comment();
  3641. offset = comment.parse({
  3642. src
  3643. }, offset);
  3644. this.contents.push(comment);
  3645. }
  3646. switch (src[offset]) {
  3647. case '\n':
  3648. offset += 1;
  3649. break;
  3650. case undefined:
  3651. break;
  3652. default:
  3653. this.error = new PlainValue$5.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
  3654. }
  3655. }
  3656. }
  3657. return offset;
  3658. }
  3659. /**
  3660. * @param {ParseContext} context
  3661. * @param {number} start - Index of first character
  3662. * @returns {number} - Index of the character after this
  3663. */
  3664. parse(context, start) {
  3665. context.root = this;
  3666. this.context = context;
  3667. const {
  3668. src
  3669. } = context;
  3670. let offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM
  3671. offset = this.parseDirectives(offset);
  3672. offset = this.parseContents(offset);
  3673. return offset;
  3674. }
  3675. setOrigRanges(cr, offset) {
  3676. offset = super.setOrigRanges(cr, offset);
  3677. this.directives.forEach(node => {
  3678. offset = node.setOrigRanges(cr, offset);
  3679. });
  3680. if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
  3681. this.contents.forEach(node => {
  3682. offset = node.setOrigRanges(cr, offset);
  3683. });
  3684. if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
  3685. return offset;
  3686. }
  3687. toString() {
  3688. const {
  3689. contents,
  3690. directives,
  3691. value
  3692. } = this;
  3693. if (value != null) return value;
  3694. let str = directives.join('');
  3695. if (contents.length > 0) {
  3696. if (directives.length > 0 || contents[0].type === PlainValue$5.Type.COMMENT) str += '---\n';
  3697. str += contents.join('');
  3698. }
  3699. if (str[str.length - 1] !== '\n') str += '\n';
  3700. return str;
  3701. }
  3702. }
  3703. class Alias$1 extends PlainValue$5.Node {
  3704. /**
  3705. * Parses an *alias from the source
  3706. *
  3707. * @param {ParseContext} context
  3708. * @param {number} start - Index of first character
  3709. * @returns {number} - Index of the character after this scalar
  3710. */
  3711. parse(context, start) {
  3712. this.context = context;
  3713. const {
  3714. src
  3715. } = context;
  3716. let offset = PlainValue$5.Node.endOfIdentifier(src, start + 1);
  3717. this.valueRange = new PlainValue$5.Range(start + 1, offset);
  3718. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  3719. offset = this.parseComment(offset);
  3720. return offset;
  3721. }
  3722. }
  3723. const Chomp = {
  3724. CLIP: 'CLIP',
  3725. KEEP: 'KEEP',
  3726. STRIP: 'STRIP'
  3727. };
  3728. class BlockValue extends PlainValue$5.Node {
  3729. constructor(type, props) {
  3730. super(type, props);
  3731. this.blockIndent = null;
  3732. this.chomping = Chomp.CLIP;
  3733. this.header = null;
  3734. }
  3735. get includesTrailingLines() {
  3736. return this.chomping === Chomp.KEEP;
  3737. }
  3738. get strValue() {
  3739. if (!this.valueRange || !this.context) return null;
  3740. let {
  3741. start,
  3742. end
  3743. } = this.valueRange;
  3744. const {
  3745. indent,
  3746. src
  3747. } = this.context;
  3748. if (this.valueRange.isEmpty()) return '';
  3749. let lastNewLine = null;
  3750. let ch = src[end - 1];
  3751. while (ch === '\n' || ch === '\t' || ch === ' ') {
  3752. end -= 1;
  3753. if (end <= start) {
  3754. if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
  3755. }
  3756. if (ch === '\n') lastNewLine = end;
  3757. ch = src[end - 1];
  3758. }
  3759. let keepStart = end + 1;
  3760. if (lastNewLine) {
  3761. if (this.chomping === Chomp.KEEP) {
  3762. keepStart = lastNewLine;
  3763. end = this.valueRange.end;
  3764. } else {
  3765. end = lastNewLine;
  3766. }
  3767. }
  3768. const bi = indent + this.blockIndent;
  3769. const folded = this.type === PlainValue$5.Type.BLOCK_FOLDED;
  3770. let atStart = true;
  3771. let str = '';
  3772. let sep = '';
  3773. let prevMoreIndented = false;
  3774. for (let i = start; i < end; ++i) {
  3775. for (let j = 0; j < bi; ++j) {
  3776. if (src[i] !== ' ') break;
  3777. i += 1;
  3778. }
  3779. const ch = src[i];
  3780. if (ch === '\n') {
  3781. if (sep === '\n') str += '\n';else sep = '\n';
  3782. } else {
  3783. const lineEnd = PlainValue$5.Node.endOfLine(src, i);
  3784. const line = src.slice(i, lineEnd);
  3785. i = lineEnd;
  3786. if (folded && (ch === ' ' || ch === '\t') && i < keepStart) {
  3787. if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
  3788. str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
  3789. sep = lineEnd < end && src[lineEnd] || '';
  3790. prevMoreIndented = true;
  3791. } else {
  3792. str += sep + line;
  3793. sep = folded && i < keepStart ? ' ' : '\n';
  3794. prevMoreIndented = false;
  3795. }
  3796. if (atStart && line !== '') atStart = false;
  3797. }
  3798. }
  3799. return this.chomping === Chomp.STRIP ? str : str + '\n';
  3800. }
  3801. parseBlockHeader(start) {
  3802. const {
  3803. src
  3804. } = this.context;
  3805. let offset = start + 1;
  3806. let bi = '';
  3807. while (true) {
  3808. const ch = src[offset];
  3809. switch (ch) {
  3810. case '-':
  3811. this.chomping = Chomp.STRIP;
  3812. break;
  3813. case '+':
  3814. this.chomping = Chomp.KEEP;
  3815. break;
  3816. case '0':
  3817. case '1':
  3818. case '2':
  3819. case '3':
  3820. case '4':
  3821. case '5':
  3822. case '6':
  3823. case '7':
  3824. case '8':
  3825. case '9':
  3826. bi += ch;
  3827. break;
  3828. default:
  3829. this.blockIndent = Number(bi) || null;
  3830. this.header = new PlainValue$5.Range(start, offset);
  3831. return offset;
  3832. }
  3833. offset += 1;
  3834. }
  3835. }
  3836. parseBlockValue(start) {
  3837. const {
  3838. indent,
  3839. src
  3840. } = this.context;
  3841. const explicit = !!this.blockIndent;
  3842. let offset = start;
  3843. let valueEnd = start;
  3844. let minBlockIndent = 1;
  3845. for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
  3846. offset += 1;
  3847. if (PlainValue$5.Node.atDocumentBoundary(src, offset)) break;
  3848. const end = PlainValue$5.Node.endOfBlockIndent(src, indent, offset); // should not include tab?
  3849. if (end === null) break;
  3850. const ch = src[end];
  3851. const lineIndent = end - (offset + indent);
  3852. if (!this.blockIndent) {
  3853. // no explicit block indent, none yet detected
  3854. if (src[end] !== '\n') {
  3855. // first line with non-whitespace content
  3856. if (lineIndent < minBlockIndent) {
  3857. const msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
  3858. this.error = new PlainValue$5.YAMLSemanticError(this, msg);
  3859. }
  3860. this.blockIndent = lineIndent;
  3861. } else if (lineIndent > minBlockIndent) {
  3862. // empty line with more whitespace
  3863. minBlockIndent = lineIndent;
  3864. }
  3865. } else if (ch && ch !== '\n' && lineIndent < this.blockIndent) {
  3866. if (src[end] === '#') break;
  3867. if (!this.error) {
  3868. const src = explicit ? 'explicit indentation indicator' : 'first line';
  3869. const msg = `Block scalars must not be less indented than their ${src}`;
  3870. this.error = new PlainValue$5.YAMLSemanticError(this, msg);
  3871. }
  3872. }
  3873. if (src[end] === '\n') {
  3874. offset = end;
  3875. } else {
  3876. offset = valueEnd = PlainValue$5.Node.endOfLine(src, end);
  3877. }
  3878. }
  3879. if (this.chomping !== Chomp.KEEP) {
  3880. offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
  3881. }
  3882. this.valueRange = new PlainValue$5.Range(start + 1, offset);
  3883. return offset;
  3884. }
  3885. /**
  3886. * Parses a block value from the source
  3887. *
  3888. * Accepted forms are:
  3889. * ```
  3890. * BS
  3891. * block
  3892. * lines
  3893. *
  3894. * BS #comment
  3895. * block
  3896. * lines
  3897. * ```
  3898. * where the block style BS matches the regexp `[|>][-+1-9]*` and block lines
  3899. * are empty or have an indent level greater than `indent`.
  3900. *
  3901. * @param {ParseContext} context
  3902. * @param {number} start - Index of first character
  3903. * @returns {number} - Index of the character after this block
  3904. */
  3905. parse(context, start) {
  3906. this.context = context;
  3907. const {
  3908. src
  3909. } = context;
  3910. let offset = this.parseBlockHeader(start);
  3911. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  3912. offset = this.parseComment(offset);
  3913. offset = this.parseBlockValue(offset);
  3914. return offset;
  3915. }
  3916. setOrigRanges(cr, offset) {
  3917. offset = super.setOrigRanges(cr, offset);
  3918. return this.header ? this.header.setOrigRange(cr, offset) : offset;
  3919. }
  3920. }
  3921. class FlowCollection extends PlainValue$5.Node {
  3922. constructor(type, props) {
  3923. super(type, props);
  3924. this.items = null;
  3925. }
  3926. prevNodeIsJsonLike(idx = this.items.length) {
  3927. const node = this.items[idx - 1];
  3928. return !!node && (node.jsonLike || node.type === PlainValue$5.Type.COMMENT && this.prevNodeIsJsonLike(idx - 1));
  3929. }
  3930. /**
  3931. * @param {ParseContext} context
  3932. * @param {number} start - Index of first character
  3933. * @returns {number} - Index of the character after this
  3934. */
  3935. parse(context, start) {
  3936. this.context = context;
  3937. const {
  3938. parseNode,
  3939. src
  3940. } = context;
  3941. let {
  3942. indent,
  3943. lineStart
  3944. } = context;
  3945. let char = src[start]; // { or [
  3946. this.items = [{
  3947. char,
  3948. offset: start
  3949. }];
  3950. let offset = PlainValue$5.Node.endOfWhiteSpace(src, start + 1);
  3951. char = src[offset];
  3952. while (char && char !== ']' && char !== '}') {
  3953. switch (char) {
  3954. case '\n':
  3955. {
  3956. lineStart = offset + 1;
  3957. const wsEnd = PlainValue$5.Node.endOfWhiteSpace(src, lineStart);
  3958. if (src[wsEnd] === '\n') {
  3959. const blankLine = new BlankLine();
  3960. lineStart = blankLine.parse({
  3961. src
  3962. }, lineStart);
  3963. this.items.push(blankLine);
  3964. }
  3965. offset = PlainValue$5.Node.endOfIndent(src, lineStart);
  3966. if (offset <= lineStart + indent) {
  3967. char = src[offset];
  3968. if (offset < lineStart + indent || char !== ']' && char !== '}') {
  3969. const msg = 'Insufficient indentation in flow collection';
  3970. this.error = new PlainValue$5.YAMLSemanticError(this, msg);
  3971. }
  3972. }
  3973. }
  3974. break;
  3975. case ',':
  3976. {
  3977. this.items.push({
  3978. char,
  3979. offset
  3980. });
  3981. offset += 1;
  3982. }
  3983. break;
  3984. case '#':
  3985. {
  3986. const comment = new Comment();
  3987. offset = comment.parse({
  3988. src
  3989. }, offset);
  3990. this.items.push(comment);
  3991. }
  3992. break;
  3993. case '?':
  3994. case ':':
  3995. {
  3996. const next = src[offset + 1];
  3997. if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace
  3998. char === ':' && this.prevNodeIsJsonLike()) {
  3999. this.items.push({
  4000. char,
  4001. offset
  4002. });
  4003. offset += 1;
  4004. break;
  4005. }
  4006. }
  4007. // fallthrough
  4008. default:
  4009. {
  4010. const node = parseNode({
  4011. atLineStart: false,
  4012. inCollection: false,
  4013. inFlow: true,
  4014. indent: -1,
  4015. lineStart,
  4016. parent: this
  4017. }, offset);
  4018. if (!node) {
  4019. // at next document start
  4020. this.valueRange = new PlainValue$5.Range(start, offset);
  4021. return offset;
  4022. }
  4023. this.items.push(node);
  4024. offset = PlainValue$5.Node.normalizeOffset(src, node.range.end);
  4025. }
  4026. }
  4027. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  4028. char = src[offset];
  4029. }
  4030. this.valueRange = new PlainValue$5.Range(start, offset + 1);
  4031. if (char) {
  4032. this.items.push({
  4033. char,
  4034. offset
  4035. });
  4036. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset + 1);
  4037. offset = this.parseComment(offset);
  4038. }
  4039. return offset;
  4040. }
  4041. setOrigRanges(cr, offset) {
  4042. offset = super.setOrigRanges(cr, offset);
  4043. this.items.forEach(node => {
  4044. if (node instanceof PlainValue$5.Node) {
  4045. offset = node.setOrigRanges(cr, offset);
  4046. } else if (cr.length === 0) {
  4047. node.origOffset = node.offset;
  4048. } else {
  4049. let i = offset;
  4050. while (i < cr.length) {
  4051. if (cr[i] > node.offset) break;else ++i;
  4052. }
  4053. node.origOffset = node.offset + i;
  4054. offset = i;
  4055. }
  4056. });
  4057. return offset;
  4058. }
  4059. toString() {
  4060. const {
  4061. context: {
  4062. src
  4063. },
  4064. items,
  4065. range,
  4066. value
  4067. } = this;
  4068. if (value != null) return value;
  4069. const nodes = items.filter(item => item instanceof PlainValue$5.Node);
  4070. let str = '';
  4071. let prevEnd = range.start;
  4072. nodes.forEach(node => {
  4073. const prefix = src.slice(prevEnd, node.range.start);
  4074. prevEnd = node.range.end;
  4075. str += prefix + String(node);
  4076. if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') {
  4077. // Comment range does not include the terminal newline, but its
  4078. // stringified value does. Without this fix, newlines at comment ends
  4079. // get duplicated.
  4080. prevEnd += 1;
  4081. }
  4082. });
  4083. str += src.slice(prevEnd, range.end);
  4084. return PlainValue$5.Node.addStringTerminator(src, range.end, str);
  4085. }
  4086. }
  4087. class QuoteDouble extends PlainValue$5.Node {
  4088. static endOfQuote(src, offset) {
  4089. let ch = src[offset];
  4090. while (ch && ch !== '"') {
  4091. offset += ch === '\\' ? 2 : 1;
  4092. ch = src[offset];
  4093. }
  4094. return offset + 1;
  4095. }
  4096. /**
  4097. * @returns {string | { str: string, errors: YAMLSyntaxError[] }}
  4098. */
  4099. get strValue() {
  4100. if (!this.valueRange || !this.context) return null;
  4101. const errors = [];
  4102. const {
  4103. start,
  4104. end
  4105. } = this.valueRange;
  4106. const {
  4107. indent,
  4108. src
  4109. } = this.context;
  4110. if (src[end - 1] !== '"') errors.push(new PlainValue$5.YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by
  4111. // escaped backslashes; also, this should be faster.
  4112. let str = '';
  4113. for (let i = start + 1; i < end - 1; ++i) {
  4114. const ch = src[i];
  4115. if (ch === '\n') {
  4116. if (PlainValue$5.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValue$5.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
  4117. const {
  4118. fold,
  4119. offset,
  4120. error
  4121. } = PlainValue$5.Node.foldNewline(src, i, indent);
  4122. str += fold;
  4123. i = offset;
  4124. if (error) errors.push(new PlainValue$5.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
  4125. } else if (ch === '\\') {
  4126. i += 1;
  4127. switch (src[i]) {
  4128. case '0':
  4129. str += '\0';
  4130. break;
  4131. // null character
  4132. case 'a':
  4133. str += '\x07';
  4134. break;
  4135. // bell character
  4136. case 'b':
  4137. str += '\b';
  4138. break;
  4139. // backspace
  4140. case 'e':
  4141. str += '\x1b';
  4142. break;
  4143. // escape character
  4144. case 'f':
  4145. str += '\f';
  4146. break;
  4147. // form feed
  4148. case 'n':
  4149. str += '\n';
  4150. break;
  4151. // line feed
  4152. case 'r':
  4153. str += '\r';
  4154. break;
  4155. // carriage return
  4156. case 't':
  4157. str += '\t';
  4158. break;
  4159. // horizontal tab
  4160. case 'v':
  4161. str += '\v';
  4162. break;
  4163. // vertical tab
  4164. case 'N':
  4165. str += '\u0085';
  4166. break;
  4167. // Unicode next line
  4168. case '_':
  4169. str += '\u00a0';
  4170. break;
  4171. // Unicode non-breaking space
  4172. case 'L':
  4173. str += '\u2028';
  4174. break;
  4175. // Unicode line separator
  4176. case 'P':
  4177. str += '\u2029';
  4178. break;
  4179. // Unicode paragraph separator
  4180. case ' ':
  4181. str += ' ';
  4182. break;
  4183. case '"':
  4184. str += '"';
  4185. break;
  4186. case '/':
  4187. str += '/';
  4188. break;
  4189. case '\\':
  4190. str += '\\';
  4191. break;
  4192. case '\t':
  4193. str += '\t';
  4194. break;
  4195. case 'x':
  4196. str += this.parseCharCode(i + 1, 2, errors);
  4197. i += 2;
  4198. break;
  4199. case 'u':
  4200. str += this.parseCharCode(i + 1, 4, errors);
  4201. i += 4;
  4202. break;
  4203. case 'U':
  4204. str += this.parseCharCode(i + 1, 8, errors);
  4205. i += 8;
  4206. break;
  4207. case '\n':
  4208. // skip escaped newlines, but still trim the following line
  4209. while (src[i + 1] === ' ' || src[i + 1] === '\t') i += 1;
  4210. break;
  4211. default:
  4212. errors.push(new PlainValue$5.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(i - 1, 2)}`));
  4213. str += '\\' + src[i];
  4214. }
  4215. } else if (ch === ' ' || ch === '\t') {
  4216. // trim trailing whitespace
  4217. const wsStart = i;
  4218. let next = src[i + 1];
  4219. while (next === ' ' || next === '\t') {
  4220. i += 1;
  4221. next = src[i + 1];
  4222. }
  4223. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  4224. } else {
  4225. str += ch;
  4226. }
  4227. }
  4228. return errors.length > 0 ? {
  4229. errors,
  4230. str
  4231. } : str;
  4232. }
  4233. parseCharCode(offset, length, errors) {
  4234. const {
  4235. src
  4236. } = this.context;
  4237. const cc = src.substr(offset, length);
  4238. const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
  4239. const code = ok ? parseInt(cc, 16) : NaN;
  4240. if (isNaN(code)) {
  4241. errors.push(new PlainValue$5.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(offset - 2, length + 2)}`));
  4242. return src.substr(offset - 2, length + 2);
  4243. }
  4244. return String.fromCodePoint(code);
  4245. }
  4246. /**
  4247. * Parses a "double quoted" value from the source
  4248. *
  4249. * @param {ParseContext} context
  4250. * @param {number} start - Index of first character
  4251. * @returns {number} - Index of the character after this scalar
  4252. */
  4253. parse(context, start) {
  4254. this.context = context;
  4255. const {
  4256. src
  4257. } = context;
  4258. let offset = QuoteDouble.endOfQuote(src, start + 1);
  4259. this.valueRange = new PlainValue$5.Range(start, offset);
  4260. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  4261. offset = this.parseComment(offset);
  4262. return offset;
  4263. }
  4264. }
  4265. class QuoteSingle extends PlainValue$5.Node {
  4266. static endOfQuote(src, offset) {
  4267. let ch = src[offset];
  4268. while (ch) {
  4269. if (ch === "'") {
  4270. if (src[offset + 1] !== "'") break;
  4271. ch = src[offset += 2];
  4272. } else {
  4273. ch = src[offset += 1];
  4274. }
  4275. }
  4276. return offset + 1;
  4277. }
  4278. /**
  4279. * @returns {string | { str: string, errors: YAMLSyntaxError[] }}
  4280. */
  4281. get strValue() {
  4282. if (!this.valueRange || !this.context) return null;
  4283. const errors = [];
  4284. const {
  4285. start,
  4286. end
  4287. } = this.valueRange;
  4288. const {
  4289. indent,
  4290. src
  4291. } = this.context;
  4292. if (src[end - 1] !== "'") errors.push(new PlainValue$5.YAMLSyntaxError(this, "Missing closing 'quote"));
  4293. let str = '';
  4294. for (let i = start + 1; i < end - 1; ++i) {
  4295. const ch = src[i];
  4296. if (ch === '\n') {
  4297. if (PlainValue$5.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValue$5.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
  4298. const {
  4299. fold,
  4300. offset,
  4301. error
  4302. } = PlainValue$5.Node.foldNewline(src, i, indent);
  4303. str += fold;
  4304. i = offset;
  4305. if (error) errors.push(new PlainValue$5.YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented'));
  4306. } else if (ch === "'") {
  4307. str += ch;
  4308. i += 1;
  4309. if (src[i] !== "'") errors.push(new PlainValue$5.YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.'));
  4310. } else if (ch === ' ' || ch === '\t') {
  4311. // trim trailing whitespace
  4312. const wsStart = i;
  4313. let next = src[i + 1];
  4314. while (next === ' ' || next === '\t') {
  4315. i += 1;
  4316. next = src[i + 1];
  4317. }
  4318. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  4319. } else {
  4320. str += ch;
  4321. }
  4322. }
  4323. return errors.length > 0 ? {
  4324. errors,
  4325. str
  4326. } : str;
  4327. }
  4328. /**
  4329. * Parses a 'single quoted' value from the source
  4330. *
  4331. * @param {ParseContext} context
  4332. * @param {number} start - Index of first character
  4333. * @returns {number} - Index of the character after this scalar
  4334. */
  4335. parse(context, start) {
  4336. this.context = context;
  4337. const {
  4338. src
  4339. } = context;
  4340. let offset = QuoteSingle.endOfQuote(src, start + 1);
  4341. this.valueRange = new PlainValue$5.Range(start, offset);
  4342. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  4343. offset = this.parseComment(offset);
  4344. return offset;
  4345. }
  4346. }
  4347. function createNewNode(type, props) {
  4348. switch (type) {
  4349. case PlainValue$5.Type.ALIAS:
  4350. return new Alias$1(type, props);
  4351. case PlainValue$5.Type.BLOCK_FOLDED:
  4352. case PlainValue$5.Type.BLOCK_LITERAL:
  4353. return new BlockValue(type, props);
  4354. case PlainValue$5.Type.FLOW_MAP:
  4355. case PlainValue$5.Type.FLOW_SEQ:
  4356. return new FlowCollection(type, props);
  4357. case PlainValue$5.Type.MAP_KEY:
  4358. case PlainValue$5.Type.MAP_VALUE:
  4359. case PlainValue$5.Type.SEQ_ITEM:
  4360. return new CollectionItem(type, props);
  4361. case PlainValue$5.Type.COMMENT:
  4362. case PlainValue$5.Type.PLAIN:
  4363. return new PlainValue$5.PlainValue(type, props);
  4364. case PlainValue$5.Type.QUOTE_DOUBLE:
  4365. return new QuoteDouble(type, props);
  4366. case PlainValue$5.Type.QUOTE_SINGLE:
  4367. return new QuoteSingle(type, props);
  4368. /* istanbul ignore next */
  4369. default:
  4370. return null;
  4371. // should never happen
  4372. }
  4373. }
  4374. /**
  4375. * @param {boolean} atLineStart - Node starts at beginning of line
  4376. * @param {boolean} inFlow - true if currently in a flow context
  4377. * @param {boolean} inCollection - true if currently in a collection context
  4378. * @param {number} indent - Current level of indentation
  4379. * @param {number} lineStart - Start of the current line
  4380. * @param {Node} parent - The parent of the node
  4381. * @param {string} src - Source of the YAML document
  4382. */
  4383. class ParseContext {
  4384. static parseType(src, offset, inFlow) {
  4385. switch (src[offset]) {
  4386. case '*':
  4387. return PlainValue$5.Type.ALIAS;
  4388. case '>':
  4389. return PlainValue$5.Type.BLOCK_FOLDED;
  4390. case '|':
  4391. return PlainValue$5.Type.BLOCK_LITERAL;
  4392. case '{':
  4393. return PlainValue$5.Type.FLOW_MAP;
  4394. case '[':
  4395. return PlainValue$5.Type.FLOW_SEQ;
  4396. case '?':
  4397. return !inFlow && PlainValue$5.Node.atBlank(src, offset + 1, true) ? PlainValue$5.Type.MAP_KEY : PlainValue$5.Type.PLAIN;
  4398. case ':':
  4399. return !inFlow && PlainValue$5.Node.atBlank(src, offset + 1, true) ? PlainValue$5.Type.MAP_VALUE : PlainValue$5.Type.PLAIN;
  4400. case '-':
  4401. return !inFlow && PlainValue$5.Node.atBlank(src, offset + 1, true) ? PlainValue$5.Type.SEQ_ITEM : PlainValue$5.Type.PLAIN;
  4402. case '"':
  4403. return PlainValue$5.Type.QUOTE_DOUBLE;
  4404. case "'":
  4405. return PlainValue$5.Type.QUOTE_SINGLE;
  4406. default:
  4407. return PlainValue$5.Type.PLAIN;
  4408. }
  4409. }
  4410. constructor(orig = {}, {
  4411. atLineStart,
  4412. inCollection,
  4413. inFlow,
  4414. indent,
  4415. lineStart,
  4416. parent
  4417. } = {}) {
  4418. PlainValue$5._defineProperty(this, "parseNode", (overlay, start) => {
  4419. if (PlainValue$5.Node.atDocumentBoundary(this.src, start)) return null;
  4420. const context = new ParseContext(this, overlay);
  4421. const {
  4422. props,
  4423. type,
  4424. valueStart
  4425. } = context.parseProps(start);
  4426. const node = createNewNode(type, props);
  4427. let offset = node.parse(context, valueStart);
  4428. node.range = new PlainValue$5.Range(start, offset);
  4429. /* istanbul ignore if */
  4430. if (offset <= start) {
  4431. // This should never happen, but if it does, let's make sure to at least
  4432. // step one character forward to avoid a busy loop.
  4433. node.error = new Error(`Node#parse consumed no characters`);
  4434. node.error.parseEnd = offset;
  4435. node.error.source = node;
  4436. node.range.end = start + 1;
  4437. }
  4438. if (context.nodeStartsCollection(node)) {
  4439. if (!node.error && !context.atLineStart && context.parent.type === PlainValue$5.Type.DOCUMENT) {
  4440. node.error = new PlainValue$5.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
  4441. }
  4442. const collection = new Collection$1(node);
  4443. offset = collection.parse(new ParseContext(context), offset);
  4444. collection.range = new PlainValue$5.Range(start, offset);
  4445. return collection;
  4446. }
  4447. return node;
  4448. });
  4449. this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
  4450. this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
  4451. this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
  4452. this.indent = indent != null ? indent : orig.indent;
  4453. this.lineStart = lineStart != null ? lineStart : orig.lineStart;
  4454. this.parent = parent != null ? parent : orig.parent || {};
  4455. this.root = orig.root;
  4456. this.src = orig.src;
  4457. }
  4458. nodeStartsCollection(node) {
  4459. const {
  4460. inCollection,
  4461. inFlow,
  4462. src
  4463. } = this;
  4464. if (inCollection || inFlow) return false;
  4465. if (node instanceof CollectionItem) return true; // check for implicit key
  4466. let offset = node.range.end;
  4467. if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
  4468. offset = PlainValue$5.Node.endOfWhiteSpace(src, offset);
  4469. return src[offset] === ':';
  4470. } // Anchor and tag are before type, which determines the node implementation
  4471. // class; hence this intermediate step.
  4472. parseProps(offset) {
  4473. const {
  4474. inFlow,
  4475. parent,
  4476. src
  4477. } = this;
  4478. const props = [];
  4479. let lineHasProps = false;
  4480. offset = this.atLineStart ? PlainValue$5.Node.endOfIndent(src, offset) : PlainValue$5.Node.endOfWhiteSpace(src, offset);
  4481. let ch = src[offset];
  4482. while (ch === PlainValue$5.Char.ANCHOR || ch === PlainValue$5.Char.COMMENT || ch === PlainValue$5.Char.TAG || ch === '\n') {
  4483. if (ch === '\n') {
  4484. let inEnd = offset;
  4485. let lineStart;
  4486. do {
  4487. lineStart = inEnd + 1;
  4488. inEnd = PlainValue$5.Node.endOfIndent(src, lineStart);
  4489. } while (src[inEnd] === '\n');
  4490. const indentDiff = inEnd - (lineStart + this.indent);
  4491. const noIndicatorAsIndent = parent.type === PlainValue$5.Type.SEQ_ITEM && parent.context.atLineStart;
  4492. if (src[inEnd] !== '#' && !PlainValue$5.Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
  4493. this.atLineStart = true;
  4494. this.lineStart = lineStart;
  4495. lineHasProps = false;
  4496. offset = inEnd;
  4497. } else if (ch === PlainValue$5.Char.COMMENT) {
  4498. const end = PlainValue$5.Node.endOfLine(src, offset + 1);
  4499. props.push(new PlainValue$5.Range(offset, end));
  4500. offset = end;
  4501. } else {
  4502. let end = PlainValue$5.Node.endOfIdentifier(src, offset + 1);
  4503. if (ch === PlainValue$5.Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
  4504. // Let's presume we're dealing with a YAML 1.0 domain tag here, rather
  4505. // than an empty but 'foo.bar' private-tagged node in a flow collection
  4506. // followed without whitespace by a plain string starting with a year
  4507. // or date divided by something.
  4508. end = PlainValue$5.Node.endOfIdentifier(src, end + 5);
  4509. }
  4510. props.push(new PlainValue$5.Range(offset, end));
  4511. lineHasProps = true;
  4512. offset = PlainValue$5.Node.endOfWhiteSpace(src, end);
  4513. }
  4514. ch = src[offset];
  4515. } // '- &a : b' has an anchor on an empty node
  4516. if (lineHasProps && ch === ':' && PlainValue$5.Node.atBlank(src, offset + 1, true)) offset -= 1;
  4517. const type = ParseContext.parseType(src, offset, inFlow);
  4518. return {
  4519. props,
  4520. type,
  4521. valueStart: offset
  4522. };
  4523. }
  4524. /**
  4525. * Parses a node from the source
  4526. * @param {ParseContext} overlay
  4527. * @param {number} start - Index of first non-whitespace character for the node
  4528. * @returns {?Node} - null if at a document boundary
  4529. */
  4530. } // Published as 'yaml/parse-cst'
  4531. function parse$1(src) {
  4532. const cr = [];
  4533. if (src.indexOf('\r') !== -1) {
  4534. src = src.replace(/\r\n?/g, (match, offset) => {
  4535. if (match.length > 1) cr.push(offset);
  4536. return '\n';
  4537. });
  4538. }
  4539. const documents = [];
  4540. let offset = 0;
  4541. do {
  4542. const doc = new Document$3();
  4543. const context = new ParseContext({
  4544. src
  4545. });
  4546. offset = doc.parse(context, offset);
  4547. documents.push(doc);
  4548. } while (offset < src.length);
  4549. documents.setOrigRanges = () => {
  4550. if (cr.length === 0) return false;
  4551. for (let i = 1; i < cr.length; ++i) cr[i] -= i;
  4552. let crOffset = 0;
  4553. for (let i = 0; i < documents.length; ++i) {
  4554. crOffset = documents[i].setOrigRanges(cr, crOffset);
  4555. }
  4556. cr.splice(0, cr.length);
  4557. return true;
  4558. };
  4559. documents.toString = () => documents.join('...\n');
  4560. return documents;
  4561. }
  4562. parseCst$1.parse = parse$1;
  4563. var Document9b4560a1 = {};
  4564. var resolveSeqD03cb037 = {};
  4565. var PlainValue$4 = PlainValueEc8e588e;
  4566. function addCommentBefore(str, indent, comment) {
  4567. if (!comment) return str;
  4568. const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`);
  4569. return `#${cc}\n${indent}${str}`;
  4570. }
  4571. function addComment(str, indent, comment) {
  4572. return !comment ? str : comment.indexOf('\n') === -1 ? `${str} #${comment}` : `${str}\n` + comment.replace(/^/gm, `${indent || ''}#`);
  4573. }
  4574. class Node {}
  4575. function toJSON(value, arg, ctx) {
  4576. if (Array.isArray(value)) return value.map((v, i) => toJSON(v, String(i), ctx));
  4577. if (value && typeof value.toJSON === 'function') {
  4578. const anchor = ctx && ctx.anchors && ctx.anchors.get(value);
  4579. if (anchor) ctx.onCreate = res => {
  4580. anchor.res = res;
  4581. delete ctx.onCreate;
  4582. };
  4583. const res = value.toJSON(arg, ctx);
  4584. if (anchor && ctx.onCreate) ctx.onCreate(res);
  4585. return res;
  4586. }
  4587. if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
  4588. return value;
  4589. }
  4590. class Scalar extends Node {
  4591. constructor(value) {
  4592. super();
  4593. this.value = value;
  4594. }
  4595. toJSON(arg, ctx) {
  4596. return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx);
  4597. }
  4598. toString() {
  4599. return String(this.value);
  4600. }
  4601. }
  4602. function collectionFromPath(schema, path, value) {
  4603. let v = value;
  4604. for (let i = path.length - 1; i >= 0; --i) {
  4605. const k = path[i];
  4606. if (Number.isInteger(k) && k >= 0) {
  4607. const a = [];
  4608. a[k] = v;
  4609. v = a;
  4610. } else {
  4611. const o = {};
  4612. Object.defineProperty(o, k, {
  4613. value: v,
  4614. writable: true,
  4615. enumerable: true,
  4616. configurable: true
  4617. });
  4618. v = o;
  4619. }
  4620. }
  4621. return schema.createNode(v, false);
  4622. } // null, undefined, or an empty non-string iterable (e.g. [])
  4623. const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
  4624. class Collection extends Node {
  4625. constructor(schema) {
  4626. super();
  4627. PlainValue$4._defineProperty(this, "items", []);
  4628. this.schema = schema;
  4629. }
  4630. addIn(path, value) {
  4631. if (isEmptyPath(path)) this.add(value);else {
  4632. const [key, ...rest] = path;
  4633. const node = this.get(key, true);
  4634. if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
  4635. }
  4636. }
  4637. deleteIn([key, ...rest]) {
  4638. if (rest.length === 0) return this.delete(key);
  4639. const node = this.get(key, true);
  4640. if (node instanceof Collection) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
  4641. }
  4642. getIn([key, ...rest], keepScalar) {
  4643. const node = this.get(key, true);
  4644. if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
  4645. }
  4646. hasAllNullValues() {
  4647. return this.items.every(node => {
  4648. if (!node || node.type !== 'PAIR') return false;
  4649. const n = node.value;
  4650. return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
  4651. });
  4652. }
  4653. hasIn([key, ...rest]) {
  4654. if (rest.length === 0) return this.has(key);
  4655. const node = this.get(key, true);
  4656. return node instanceof Collection ? node.hasIn(rest) : false;
  4657. }
  4658. setIn([key, ...rest], value) {
  4659. if (rest.length === 0) {
  4660. this.set(key, value);
  4661. } else {
  4662. const node = this.get(key, true);
  4663. if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
  4664. }
  4665. } // overridden in implementations
  4666. /* istanbul ignore next */
  4667. toJSON() {
  4668. return null;
  4669. }
  4670. toString(ctx, {
  4671. blockItem,
  4672. flowChars,
  4673. isMap,
  4674. itemIndent
  4675. }, onComment, onChompKeep) {
  4676. const {
  4677. indent,
  4678. indentStep,
  4679. stringify
  4680. } = ctx;
  4681. const inFlow = this.type === PlainValue$4.Type.FLOW_MAP || this.type === PlainValue$4.Type.FLOW_SEQ || ctx.inFlow;
  4682. if (inFlow) itemIndent += indentStep;
  4683. const allNullValues = isMap && this.hasAllNullValues();
  4684. ctx = Object.assign({}, ctx, {
  4685. allNullValues,
  4686. indent: itemIndent,
  4687. inFlow,
  4688. type: null
  4689. });
  4690. let chompKeep = false;
  4691. let hasItemWithNewLine = false;
  4692. const nodes = this.items.reduce((nodes, item, i) => {
  4693. let comment;
  4694. if (item) {
  4695. if (!chompKeep && item.spaceBefore) nodes.push({
  4696. type: 'comment',
  4697. str: ''
  4698. });
  4699. if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(line => {
  4700. nodes.push({
  4701. type: 'comment',
  4702. str: `#${line}`
  4703. });
  4704. });
  4705. if (item.comment) comment = item.comment;
  4706. if (inFlow && (!chompKeep && item.spaceBefore || item.commentBefore || item.comment || item.key && (item.key.commentBefore || item.key.comment) || item.value && (item.value.commentBefore || item.value.comment))) hasItemWithNewLine = true;
  4707. }
  4708. chompKeep = false;
  4709. let str = stringify(item, ctx, () => comment = null, () => chompKeep = true);
  4710. if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
  4711. if (inFlow && i < this.items.length - 1) str += ',';
  4712. str = addComment(str, itemIndent, comment);
  4713. if (chompKeep && (comment || inFlow)) chompKeep = false;
  4714. nodes.push({
  4715. type: 'item',
  4716. str
  4717. });
  4718. return nodes;
  4719. }, []);
  4720. let str;
  4721. if (nodes.length === 0) {
  4722. str = flowChars.start + flowChars.end;
  4723. } else if (inFlow) {
  4724. const {
  4725. start,
  4726. end
  4727. } = flowChars;
  4728. const strings = nodes.map(n => n.str);
  4729. if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) {
  4730. str = start;
  4731. for (const s of strings) {
  4732. str += s ? `\n${indentStep}${indent}${s}` : '\n';
  4733. }
  4734. str += `\n${indent}${end}`;
  4735. } else {
  4736. str = `${start} ${strings.join(' ')} ${end}`;
  4737. }
  4738. } else {
  4739. const strings = nodes.map(blockItem);
  4740. str = strings.shift();
  4741. for (const s of strings) str += s ? `\n${indent}${s}` : '\n';
  4742. }
  4743. if (this.comment) {
  4744. str += '\n' + this.comment.replace(/^/gm, `${indent}#`);
  4745. if (onComment) onComment();
  4746. } else if (chompKeep && onChompKeep) onChompKeep();
  4747. return str;
  4748. }
  4749. }
  4750. PlainValue$4._defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
  4751. function asItemIndex(key) {
  4752. let idx = key instanceof Scalar ? key.value : key;
  4753. if (idx && typeof idx === 'string') idx = Number(idx);
  4754. return Number.isInteger(idx) && idx >= 0 ? idx : null;
  4755. }
  4756. class YAMLSeq extends Collection {
  4757. add(value) {
  4758. this.items.push(value);
  4759. }
  4760. delete(key) {
  4761. const idx = asItemIndex(key);
  4762. if (typeof idx !== 'number') return false;
  4763. const del = this.items.splice(idx, 1);
  4764. return del.length > 0;
  4765. }
  4766. get(key, keepScalar) {
  4767. const idx = asItemIndex(key);
  4768. if (typeof idx !== 'number') return undefined;
  4769. const it = this.items[idx];
  4770. return !keepScalar && it instanceof Scalar ? it.value : it;
  4771. }
  4772. has(key) {
  4773. const idx = asItemIndex(key);
  4774. return typeof idx === 'number' && idx < this.items.length;
  4775. }
  4776. set(key, value) {
  4777. const idx = asItemIndex(key);
  4778. if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`);
  4779. this.items[idx] = value;
  4780. }
  4781. toJSON(_, ctx) {
  4782. const seq = [];
  4783. if (ctx && ctx.onCreate) ctx.onCreate(seq);
  4784. let i = 0;
  4785. for (const item of this.items) seq.push(toJSON(item, String(i++), ctx));
  4786. return seq;
  4787. }
  4788. toString(ctx, onComment, onChompKeep) {
  4789. if (!ctx) return JSON.stringify(this);
  4790. return super.toString(ctx, {
  4791. blockItem: n => n.type === 'comment' ? n.str : `- ${n.str}`,
  4792. flowChars: {
  4793. start: '[',
  4794. end: ']'
  4795. },
  4796. isMap: false,
  4797. itemIndent: (ctx.indent || '') + ' '
  4798. }, onComment, onChompKeep);
  4799. }
  4800. }
  4801. const stringifyKey = (key, jsKey, ctx) => {
  4802. if (jsKey === null) return '';
  4803. if (typeof jsKey !== 'object') return String(jsKey);
  4804. if (key instanceof Node && ctx && ctx.doc) return key.toString({
  4805. anchors: Object.create(null),
  4806. doc: ctx.doc,
  4807. indent: '',
  4808. indentStep: ctx.indentStep,
  4809. inFlow: true,
  4810. inStringifyKey: true,
  4811. stringify: ctx.stringify
  4812. });
  4813. return JSON.stringify(jsKey);
  4814. };
  4815. class Pair extends Node {
  4816. constructor(key, value = null) {
  4817. super();
  4818. this.key = key;
  4819. this.value = value;
  4820. this.type = Pair.Type.PAIR;
  4821. }
  4822. get commentBefore() {
  4823. return this.key instanceof Node ? this.key.commentBefore : undefined;
  4824. }
  4825. set commentBefore(cb) {
  4826. if (this.key == null) this.key = new Scalar(null);
  4827. if (this.key instanceof Node) this.key.commentBefore = cb;else {
  4828. const msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.';
  4829. throw new Error(msg);
  4830. }
  4831. }
  4832. addToJSMap(ctx, map) {
  4833. const key = toJSON(this.key, '', ctx);
  4834. if (map instanceof Map) {
  4835. const value = toJSON(this.value, key, ctx);
  4836. map.set(key, value);
  4837. } else if (map instanceof Set) {
  4838. map.add(key);
  4839. } else {
  4840. const stringKey = stringifyKey(this.key, key, ctx);
  4841. const value = toJSON(this.value, stringKey, ctx);
  4842. if (stringKey in map) Object.defineProperty(map, stringKey, {
  4843. value,
  4844. writable: true,
  4845. enumerable: true,
  4846. configurable: true
  4847. });else map[stringKey] = value;
  4848. }
  4849. return map;
  4850. }
  4851. toJSON(_, ctx) {
  4852. const pair = ctx && ctx.mapAsMap ? new Map() : {};
  4853. return this.addToJSMap(ctx, pair);
  4854. }
  4855. toString(ctx, onComment, onChompKeep) {
  4856. if (!ctx || !ctx.doc) return JSON.stringify(this);
  4857. const {
  4858. indent: indentSize,
  4859. indentSeq,
  4860. simpleKeys
  4861. } = ctx.doc.options;
  4862. let {
  4863. key,
  4864. value
  4865. } = this;
  4866. let keyComment = key instanceof Node && key.comment;
  4867. if (simpleKeys) {
  4868. if (keyComment) {
  4869. throw new Error('With simple keys, key nodes cannot have comments');
  4870. }
  4871. if (key instanceof Collection) {
  4872. const msg = 'With simple keys, collection cannot be used as a key value';
  4873. throw new Error(msg);
  4874. }
  4875. }
  4876. let explicitKey = !simpleKeys && (!key || keyComment || (key instanceof Node ? key instanceof Collection || key.type === PlainValue$4.Type.BLOCK_FOLDED || key.type === PlainValue$4.Type.BLOCK_LITERAL : typeof key === 'object'));
  4877. const {
  4878. doc,
  4879. indent,
  4880. indentStep,
  4881. stringify
  4882. } = ctx;
  4883. ctx = Object.assign({}, ctx, {
  4884. implicitKey: !explicitKey,
  4885. indent: indent + indentStep
  4886. });
  4887. let chompKeep = false;
  4888. let str = stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
  4889. str = addComment(str, ctx.indent, keyComment);
  4890. if (!explicitKey && str.length > 1024) {
  4891. if (simpleKeys) throw new Error('With simple keys, single line scalar must not span more than 1024 characters');
  4892. explicitKey = true;
  4893. }
  4894. if (ctx.allNullValues && !simpleKeys) {
  4895. if (this.comment) {
  4896. str = addComment(str, ctx.indent, this.comment);
  4897. if (onComment) onComment();
  4898. } else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
  4899. return ctx.inFlow && !explicitKey ? str : `? ${str}`;
  4900. }
  4901. str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`;
  4902. if (this.comment) {
  4903. // expected (but not strictly required) to be a single-line comment
  4904. str = addComment(str, ctx.indent, this.comment);
  4905. if (onComment) onComment();
  4906. }
  4907. let vcb = '';
  4908. let valueComment = null;
  4909. if (value instanceof Node) {
  4910. if (value.spaceBefore) vcb = '\n';
  4911. if (value.commentBefore) {
  4912. const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
  4913. vcb += `\n${cs}`;
  4914. }
  4915. valueComment = value.comment;
  4916. } else if (value && typeof value === 'object') {
  4917. value = doc.schema.createNode(value, true);
  4918. }
  4919. ctx.implicitKey = false;
  4920. if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1;
  4921. chompKeep = false;
  4922. if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== PlainValue$4.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
  4923. // If indentSeq === false, consider '- ' as part of indentation where possible
  4924. ctx.indent = ctx.indent.substr(2);
  4925. }
  4926. const valueStr = stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
  4927. let ws = ' ';
  4928. if (vcb || this.comment) {
  4929. ws = `${vcb}\n${ctx.indent}`;
  4930. } else if (!explicitKey && value instanceof Collection) {
  4931. const flow = valueStr[0] === '[' || valueStr[0] === '{';
  4932. if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
  4933. } else if (valueStr[0] === '\n') ws = '';
  4934. if (chompKeep && !valueComment && onChompKeep) onChompKeep();
  4935. return addComment(str + ws + valueStr, ctx.indent, valueComment);
  4936. }
  4937. }
  4938. PlainValue$4._defineProperty(Pair, "Type", {
  4939. PAIR: 'PAIR',
  4940. MERGE_PAIR: 'MERGE_PAIR'
  4941. });
  4942. const getAliasCount = (node, anchors) => {
  4943. if (node instanceof Alias) {
  4944. const anchor = anchors.get(node.source);
  4945. return anchor.count * anchor.aliasCount;
  4946. } else if (node instanceof Collection) {
  4947. let count = 0;
  4948. for (const item of node.items) {
  4949. const c = getAliasCount(item, anchors);
  4950. if (c > count) count = c;
  4951. }
  4952. return count;
  4953. } else if (node instanceof Pair) {
  4954. const kc = getAliasCount(node.key, anchors);
  4955. const vc = getAliasCount(node.value, anchors);
  4956. return Math.max(kc, vc);
  4957. }
  4958. return 1;
  4959. };
  4960. class Alias extends Node {
  4961. static stringify({
  4962. range,
  4963. source
  4964. }, {
  4965. anchors,
  4966. doc,
  4967. implicitKey,
  4968. inStringifyKey
  4969. }) {
  4970. let anchor = Object.keys(anchors).find(a => anchors[a] === source);
  4971. if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
  4972. if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
  4973. const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
  4974. throw new Error(`${msg} [${range}]`);
  4975. }
  4976. constructor(source) {
  4977. super();
  4978. this.source = source;
  4979. this.type = PlainValue$4.Type.ALIAS;
  4980. }
  4981. set tag(t) {
  4982. throw new Error('Alias nodes cannot have tags');
  4983. }
  4984. toJSON(arg, ctx) {
  4985. if (!ctx) return toJSON(this.source, arg, ctx);
  4986. const {
  4987. anchors,
  4988. maxAliasCount
  4989. } = ctx;
  4990. const anchor = anchors.get(this.source);
  4991. /* istanbul ignore if */
  4992. if (!anchor || anchor.res === undefined) {
  4993. const msg = 'This should not happen: Alias anchor was not resolved?';
  4994. if (this.cstNode) throw new PlainValue$4.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  4995. }
  4996. if (maxAliasCount >= 0) {
  4997. anchor.count += 1;
  4998. if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
  4999. if (anchor.count * anchor.aliasCount > maxAliasCount) {
  5000. const msg = 'Excessive alias count indicates a resource exhaustion attack';
  5001. if (this.cstNode) throw new PlainValue$4.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  5002. }
  5003. }
  5004. return anchor.res;
  5005. } // Only called when stringifying an alias mapping key while constructing
  5006. // Object output.
  5007. toString(ctx) {
  5008. return Alias.stringify(this, ctx);
  5009. }
  5010. }
  5011. PlainValue$4._defineProperty(Alias, "default", true);
  5012. function findPair(items, key) {
  5013. const k = key instanceof Scalar ? key.value : key;
  5014. for (const it of items) {
  5015. if (it instanceof Pair) {
  5016. if (it.key === key || it.key === k) return it;
  5017. if (it.key && it.key.value === k) return it;
  5018. }
  5019. }
  5020. return undefined;
  5021. }
  5022. class YAMLMap extends Collection {
  5023. add(pair, overwrite) {
  5024. if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value);
  5025. const prev = findPair(this.items, pair.key);
  5026. const sortEntries = this.schema && this.schema.sortMapEntries;
  5027. if (prev) {
  5028. if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
  5029. } else if (sortEntries) {
  5030. const i = this.items.findIndex(item => sortEntries(pair, item) < 0);
  5031. if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
  5032. } else {
  5033. this.items.push(pair);
  5034. }
  5035. }
  5036. delete(key) {
  5037. const it = findPair(this.items, key);
  5038. if (!it) return false;
  5039. const del = this.items.splice(this.items.indexOf(it), 1);
  5040. return del.length > 0;
  5041. }
  5042. get(key, keepScalar) {
  5043. const it = findPair(this.items, key);
  5044. const node = it && it.value;
  5045. return !keepScalar && node instanceof Scalar ? node.value : node;
  5046. }
  5047. has(key) {
  5048. return !!findPair(this.items, key);
  5049. }
  5050. set(key, value) {
  5051. this.add(new Pair(key, value), true);
  5052. }
  5053. /**
  5054. * @param {*} arg ignored
  5055. * @param {*} ctx Conversion context, originally set in Document#toJSON()
  5056. * @param {Class} Type If set, forces the returned collection type
  5057. * @returns {*} Instance of Type, Map, or Object
  5058. */
  5059. toJSON(_, ctx, Type) {
  5060. const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
  5061. if (ctx && ctx.onCreate) ctx.onCreate(map);
  5062. for (const item of this.items) item.addToJSMap(ctx, map);
  5063. return map;
  5064. }
  5065. toString(ctx, onComment, onChompKeep) {
  5066. if (!ctx) return JSON.stringify(this);
  5067. for (const item of this.items) {
  5068. if (!(item instanceof Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
  5069. }
  5070. return super.toString(ctx, {
  5071. blockItem: n => n.str,
  5072. flowChars: {
  5073. start: '{',
  5074. end: '}'
  5075. },
  5076. isMap: true,
  5077. itemIndent: ctx.indent || ''
  5078. }, onComment, onChompKeep);
  5079. }
  5080. }
  5081. const MERGE_KEY = '<<';
  5082. class Merge extends Pair {
  5083. constructor(pair) {
  5084. if (pair instanceof Pair) {
  5085. let seq = pair.value;
  5086. if (!(seq instanceof YAMLSeq)) {
  5087. seq = new YAMLSeq();
  5088. seq.items.push(pair.value);
  5089. seq.range = pair.value.range;
  5090. }
  5091. super(pair.key, seq);
  5092. this.range = pair.range;
  5093. } else {
  5094. super(new Scalar(MERGE_KEY), new YAMLSeq());
  5095. }
  5096. this.type = Pair.Type.MERGE_PAIR;
  5097. } // If the value associated with a merge key is a single mapping node, each of
  5098. // its key/value pairs is inserted into the current mapping, unless the key
  5099. // already exists in it. If the value associated with the merge key is a
  5100. // sequence, then this sequence is expected to contain mapping nodes and each
  5101. // of these nodes is merged in turn according to its order in the sequence.
  5102. // Keys in mapping nodes earlier in the sequence override keys specified in
  5103. // later mapping nodes. -- http://yaml.org/type/merge.html
  5104. addToJSMap(ctx, map) {
  5105. for (const {
  5106. source
  5107. } of this.value.items) {
  5108. if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
  5109. const srcMap = source.toJSON(null, ctx, Map);
  5110. for (const [key, value] of srcMap) {
  5111. if (map instanceof Map) {
  5112. if (!map.has(key)) map.set(key, value);
  5113. } else if (map instanceof Set) {
  5114. map.add(key);
  5115. } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
  5116. Object.defineProperty(map, key, {
  5117. value,
  5118. writable: true,
  5119. enumerable: true,
  5120. configurable: true
  5121. });
  5122. }
  5123. }
  5124. }
  5125. return map;
  5126. }
  5127. toString(ctx, onComment) {
  5128. const seq = this.value;
  5129. if (seq.items.length > 1) return super.toString(ctx, onComment);
  5130. this.value = seq.items[0];
  5131. const str = super.toString(ctx, onComment);
  5132. this.value = seq;
  5133. return str;
  5134. }
  5135. }
  5136. const binaryOptions = {
  5137. defaultType: PlainValue$4.Type.BLOCK_LITERAL,
  5138. lineWidth: 76
  5139. };
  5140. const boolOptions = {
  5141. trueStr: 'true',
  5142. falseStr: 'false'
  5143. };
  5144. const intOptions = {
  5145. asBigInt: false
  5146. };
  5147. const nullOptions = {
  5148. nullStr: 'null'
  5149. };
  5150. const strOptions = {
  5151. defaultType: PlainValue$4.Type.PLAIN,
  5152. doubleQuoted: {
  5153. jsonEncoding: false,
  5154. minMultiLineLength: 40
  5155. },
  5156. fold: {
  5157. lineWidth: 80,
  5158. minContentWidth: 20
  5159. }
  5160. };
  5161. function resolveScalar(str, tags, scalarFallback) {
  5162. for (const {
  5163. format,
  5164. test,
  5165. resolve
  5166. } of tags) {
  5167. if (test) {
  5168. const match = str.match(test);
  5169. if (match) {
  5170. let res = resolve.apply(null, match);
  5171. if (!(res instanceof Scalar)) res = new Scalar(res);
  5172. if (format) res.format = format;
  5173. return res;
  5174. }
  5175. }
  5176. }
  5177. if (scalarFallback) str = scalarFallback(str);
  5178. return new Scalar(str);
  5179. }
  5180. const FOLD_FLOW = 'flow';
  5181. const FOLD_BLOCK = 'block';
  5182. const FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line
  5183. // returns index of last newline in more-indented block
  5184. const consumeMoreIndentedLines = (text, i) => {
  5185. let ch = text[i + 1];
  5186. while (ch === ' ' || ch === '\t') {
  5187. do {
  5188. ch = text[i += 1];
  5189. } while (ch && ch !== '\n');
  5190. ch = text[i + 1];
  5191. }
  5192. return i;
  5193. };
  5194. /**
  5195. * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
  5196. * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
  5197. * terminated with `\n` and started with `indent`.
  5198. *
  5199. * @param {string} text
  5200. * @param {string} indent
  5201. * @param {string} [mode='flow'] `'block'` prevents more-indented lines
  5202. * from being folded; `'quoted'` allows for `\` escapes, including escaped
  5203. * newlines
  5204. * @param {Object} options
  5205. * @param {number} [options.indentAtStart] Accounts for leading contents on
  5206. * the first line, defaulting to `indent.length`
  5207. * @param {number} [options.lineWidth=80]
  5208. * @param {number} [options.minContentWidth=20] Allow highly indented lines to
  5209. * stretch the line width or indent content from the start
  5210. * @param {function} options.onFold Called once if the text is folded
  5211. * @param {function} options.onFold Called once if any line of text exceeds
  5212. * lineWidth characters
  5213. */
  5214. function foldFlowLines(text, indent, mode, {
  5215. indentAtStart,
  5216. lineWidth = 80,
  5217. minContentWidth = 20,
  5218. onFold,
  5219. onOverflow
  5220. }) {
  5221. if (!lineWidth || lineWidth < 0) return text;
  5222. const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
  5223. if (text.length <= endStep) return text;
  5224. const folds = [];
  5225. const escapedFolds = {};
  5226. let end = lineWidth - indent.length;
  5227. if (typeof indentAtStart === 'number') {
  5228. if (indentAtStart > lineWidth - Math.max(2, minContentWidth)) folds.push(0);else end = lineWidth - indentAtStart;
  5229. }
  5230. let split = undefined;
  5231. let prev = undefined;
  5232. let overflow = false;
  5233. let i = -1;
  5234. let escStart = -1;
  5235. let escEnd = -1;
  5236. if (mode === FOLD_BLOCK) {
  5237. i = consumeMoreIndentedLines(text, i);
  5238. if (i !== -1) end = i + endStep;
  5239. }
  5240. for (let ch; ch = text[i += 1];) {
  5241. if (mode === FOLD_QUOTED && ch === '\\') {
  5242. escStart = i;
  5243. switch (text[i + 1]) {
  5244. case 'x':
  5245. i += 3;
  5246. break;
  5247. case 'u':
  5248. i += 5;
  5249. break;
  5250. case 'U':
  5251. i += 9;
  5252. break;
  5253. default:
  5254. i += 1;
  5255. }
  5256. escEnd = i;
  5257. }
  5258. if (ch === '\n') {
  5259. if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i);
  5260. end = i + endStep;
  5261. split = undefined;
  5262. } else {
  5263. if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') {
  5264. // space surrounded by non-space can be replaced with newline + indent
  5265. const next = text[i + 1];
  5266. if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i;
  5267. }
  5268. if (i >= end) {
  5269. if (split) {
  5270. folds.push(split);
  5271. end = split + endStep;
  5272. split = undefined;
  5273. } else if (mode === FOLD_QUOTED) {
  5274. // white-space collected at end may stretch past lineWidth
  5275. while (prev === ' ' || prev === '\t') {
  5276. prev = ch;
  5277. ch = text[i += 1];
  5278. overflow = true;
  5279. } // Account for newline escape, but don't break preceding escape
  5280. const j = i > escEnd + 1 ? i - 2 : escStart - 1; // Bail out if lineWidth & minContentWidth are shorter than an escape string
  5281. if (escapedFolds[j]) return text;
  5282. folds.push(j);
  5283. escapedFolds[j] = true;
  5284. end = j + endStep;
  5285. split = undefined;
  5286. } else {
  5287. overflow = true;
  5288. }
  5289. }
  5290. }
  5291. prev = ch;
  5292. }
  5293. if (overflow && onOverflow) onOverflow();
  5294. if (folds.length === 0) return text;
  5295. if (onFold) onFold();
  5296. let res = text.slice(0, folds[0]);
  5297. for (let i = 0; i < folds.length; ++i) {
  5298. const fold = folds[i];
  5299. const end = folds[i + 1] || text.length;
  5300. if (fold === 0) res = `\n${indent}${text.slice(0, end)}`;else {
  5301. if (mode === FOLD_QUOTED && escapedFolds[fold]) res += `${text[fold]}\\`;
  5302. res += `\n${indent}${text.slice(fold + 1, end)}`;
  5303. }
  5304. }
  5305. return res;
  5306. }
  5307. const getFoldOptions = ({
  5308. indentAtStart
  5309. }) => indentAtStart ? Object.assign({
  5310. indentAtStart
  5311. }, strOptions.fold) : strOptions.fold; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will
  5312. // presume that's starting a new document.
  5313. const containsDocumentMarker = str => /^(%|---|\.\.\.)/m.test(str);
  5314. function lineLengthOverLimit(str, lineWidth, indentLength) {
  5315. if (!lineWidth || lineWidth < 0) return false;
  5316. const limit = lineWidth - indentLength;
  5317. const strLen = str.length;
  5318. if (strLen <= limit) return false;
  5319. for (let i = 0, start = 0; i < strLen; ++i) {
  5320. if (str[i] === '\n') {
  5321. if (i - start > limit) return true;
  5322. start = i + 1;
  5323. if (strLen - start <= limit) return false;
  5324. }
  5325. }
  5326. return true;
  5327. }
  5328. function doubleQuotedString(value, ctx) {
  5329. const {
  5330. implicitKey
  5331. } = ctx;
  5332. const {
  5333. jsonEncoding,
  5334. minMultiLineLength
  5335. } = strOptions.doubleQuoted;
  5336. const json = JSON.stringify(value);
  5337. if (jsonEncoding) return json;
  5338. const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
  5339. let str = '';
  5340. let start = 0;
  5341. for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
  5342. if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
  5343. // space before newline needs to be escaped to not be folded
  5344. str += json.slice(start, i) + '\\ ';
  5345. i += 1;
  5346. start = i;
  5347. ch = '\\';
  5348. }
  5349. if (ch === '\\') switch (json[i + 1]) {
  5350. case 'u':
  5351. {
  5352. str += json.slice(start, i);
  5353. const code = json.substr(i + 2, 4);
  5354. switch (code) {
  5355. case '0000':
  5356. str += '\\0';
  5357. break;
  5358. case '0007':
  5359. str += '\\a';
  5360. break;
  5361. case '000b':
  5362. str += '\\v';
  5363. break;
  5364. case '001b':
  5365. str += '\\e';
  5366. break;
  5367. case '0085':
  5368. str += '\\N';
  5369. break;
  5370. case '00a0':
  5371. str += '\\_';
  5372. break;
  5373. case '2028':
  5374. str += '\\L';
  5375. break;
  5376. case '2029':
  5377. str += '\\P';
  5378. break;
  5379. default:
  5380. if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6);
  5381. }
  5382. i += 5;
  5383. start = i + 1;
  5384. }
  5385. break;
  5386. case 'n':
  5387. if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
  5388. i += 1;
  5389. } else {
  5390. // folding will eat first newline
  5391. str += json.slice(start, i) + '\n\n';
  5392. while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
  5393. str += '\n';
  5394. i += 2;
  5395. }
  5396. str += indent; // space after newline needs to be escaped to not be folded
  5397. if (json[i + 2] === ' ') str += '\\';
  5398. i += 1;
  5399. start = i + 1;
  5400. }
  5401. break;
  5402. default:
  5403. i += 1;
  5404. }
  5405. }
  5406. str = start ? str + json.slice(start) : json;
  5407. return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
  5408. }
  5409. function singleQuotedString(value, ctx) {
  5410. if (ctx.implicitKey) {
  5411. if (/\n/.test(value)) return doubleQuotedString(value, ctx);
  5412. } else {
  5413. // single quoted string can't have leading or trailing whitespace around newline
  5414. if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
  5415. }
  5416. const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
  5417. const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
  5418. return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
  5419. }
  5420. function blockString({
  5421. comment,
  5422. type,
  5423. value
  5424. }, ctx, onComment, onChompKeep) {
  5425. // 1. Block can't end in whitespace unless the last line is non-empty.
  5426. // 2. Strings consisting of only whitespace are best rendered explicitly.
  5427. if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
  5428. return doubleQuotedString(value, ctx);
  5429. }
  5430. const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
  5431. const indentSize = indent ? '2' : '1'; // root is at -1
  5432. const literal = type === PlainValue$4.Type.BLOCK_FOLDED ? false : type === PlainValue$4.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth, indent.length);
  5433. let header = literal ? '|' : '>';
  5434. if (!value) return header + '\n';
  5435. let wsStart = '';
  5436. let wsEnd = '';
  5437. value = value.replace(/[\n\t ]*$/, ws => {
  5438. const n = ws.indexOf('\n');
  5439. if (n === -1) {
  5440. header += '-'; // strip
  5441. } else if (value === ws || n !== ws.length - 1) {
  5442. header += '+'; // keep
  5443. if (onChompKeep) onChompKeep();
  5444. }
  5445. wsEnd = ws.replace(/\n$/, '');
  5446. return '';
  5447. }).replace(/^[\n ]*/, ws => {
  5448. if (ws.indexOf(' ') !== -1) header += indentSize;
  5449. const m = ws.match(/ +$/);
  5450. if (m) {
  5451. wsStart = ws.slice(0, -m[0].length);
  5452. return m[0];
  5453. } else {
  5454. wsStart = ws;
  5455. return '';
  5456. }
  5457. });
  5458. if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, `$&${indent}`);
  5459. if (wsStart) wsStart = wsStart.replace(/\n+/g, `$&${indent}`);
  5460. if (comment) {
  5461. header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
  5462. if (onComment) onComment();
  5463. }
  5464. if (!value) return `${header}${indentSize}\n${indent}${wsEnd}`;
  5465. if (literal) {
  5466. value = value.replace(/\n+/g, `$&${indent}`);
  5467. return `${header}\n${indent}${wsStart}${value}${wsEnd}`;
  5468. }
  5469. value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
  5470. // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
  5471. .replace(/\n+/g, `$&${indent}`);
  5472. const body = foldFlowLines(`${wsStart}${value}${wsEnd}`, indent, FOLD_BLOCK, strOptions.fold);
  5473. return `${header}\n${indent}${body}`;
  5474. }
  5475. function plainString(item, ctx, onComment, onChompKeep) {
  5476. const {
  5477. comment,
  5478. type,
  5479. value
  5480. } = item;
  5481. const {
  5482. actualString,
  5483. implicitKey,
  5484. indent,
  5485. inFlow
  5486. } = ctx;
  5487. if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {
  5488. return doubleQuotedString(value, ctx);
  5489. }
  5490. if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
  5491. // not allowed:
  5492. // - empty string, '-' or '?'
  5493. // - start with an indicator character (except [?:-]) or /[?-] /
  5494. // - '\n ', ': ' or ' \n' anywhere
  5495. // - '#' not preceded by a non-space char
  5496. // - end with ' ' or ':'
  5497. return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
  5498. }
  5499. if (!implicitKey && !inFlow && type !== PlainValue$4.Type.PLAIN && value.indexOf('\n') !== -1) {
  5500. // Where allowed & type not set explicitly, prefer block style for multiline strings
  5501. return blockString(item, ctx, onComment, onChompKeep);
  5502. }
  5503. if (indent === '' && containsDocumentMarker(value)) {
  5504. ctx.forceBlockIndent = true;
  5505. return blockString(item, ctx, onComment, onChompKeep);
  5506. }
  5507. const str = value.replace(/\n+/g, `$&\n${indent}`); // Verify that output will be parsed as a string, as e.g. plain numbers and
  5508. // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
  5509. // and others in v1.1.
  5510. if (actualString) {
  5511. const {
  5512. tags
  5513. } = ctx.doc.schema;
  5514. const resolved = resolveScalar(str, tags, tags.scalarFallback).value;
  5515. if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
  5516. }
  5517. const body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
  5518. if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
  5519. if (onComment) onComment();
  5520. return addCommentBefore(body, indent, comment);
  5521. }
  5522. return body;
  5523. }
  5524. function stringifyString(item, ctx, onComment, onChompKeep) {
  5525. const {
  5526. defaultType
  5527. } = strOptions;
  5528. const {
  5529. implicitKey,
  5530. inFlow
  5531. } = ctx;
  5532. let {
  5533. type,
  5534. value
  5535. } = item;
  5536. if (typeof value !== 'string') {
  5537. value = String(value);
  5538. item = Object.assign({}, item, {
  5539. value
  5540. });
  5541. }
  5542. const _stringify = _type => {
  5543. switch (_type) {
  5544. case PlainValue$4.Type.BLOCK_FOLDED:
  5545. case PlainValue$4.Type.BLOCK_LITERAL:
  5546. return blockString(item, ctx, onComment, onChompKeep);
  5547. case PlainValue$4.Type.QUOTE_DOUBLE:
  5548. return doubleQuotedString(value, ctx);
  5549. case PlainValue$4.Type.QUOTE_SINGLE:
  5550. return singleQuotedString(value, ctx);
  5551. case PlainValue$4.Type.PLAIN:
  5552. return plainString(item, ctx, onComment, onChompKeep);
  5553. default:
  5554. return null;
  5555. }
  5556. };
  5557. if (type !== PlainValue$4.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
  5558. // force double quotes on control characters
  5559. type = PlainValue$4.Type.QUOTE_DOUBLE;
  5560. } else if ((implicitKey || inFlow) && (type === PlainValue$4.Type.BLOCK_FOLDED || type === PlainValue$4.Type.BLOCK_LITERAL)) {
  5561. // should not happen; blocks are not valid inside flow containers
  5562. type = PlainValue$4.Type.QUOTE_DOUBLE;
  5563. }
  5564. let res = _stringify(type);
  5565. if (res === null) {
  5566. res = _stringify(defaultType);
  5567. if (res === null) throw new Error(`Unsupported default string type ${defaultType}`);
  5568. }
  5569. return res;
  5570. }
  5571. function stringifyNumber({
  5572. format,
  5573. minFractionDigits,
  5574. tag,
  5575. value
  5576. }) {
  5577. if (typeof value === 'bigint') return String(value);
  5578. if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
  5579. let n = JSON.stringify(value);
  5580. if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
  5581. let i = n.indexOf('.');
  5582. if (i < 0) {
  5583. i = n.length;
  5584. n += '.';
  5585. }
  5586. let d = minFractionDigits - (n.length - i - 1);
  5587. while (d-- > 0) n += '0';
  5588. }
  5589. return n;
  5590. }
  5591. function checkFlowCollectionEnd(errors, cst) {
  5592. let char, name;
  5593. switch (cst.type) {
  5594. case PlainValue$4.Type.FLOW_MAP:
  5595. char = '}';
  5596. name = 'flow map';
  5597. break;
  5598. case PlainValue$4.Type.FLOW_SEQ:
  5599. char = ']';
  5600. name = 'flow sequence';
  5601. break;
  5602. default:
  5603. errors.push(new PlainValue$4.YAMLSemanticError(cst, 'Not a flow collection!?'));
  5604. return;
  5605. }
  5606. let lastItem;
  5607. for (let i = cst.items.length - 1; i >= 0; --i) {
  5608. const item = cst.items[i];
  5609. if (!item || item.type !== PlainValue$4.Type.COMMENT) {
  5610. lastItem = item;
  5611. break;
  5612. }
  5613. }
  5614. if (lastItem && lastItem.char !== char) {
  5615. const msg = `Expected ${name} to end with ${char}`;
  5616. let err;
  5617. if (typeof lastItem.offset === 'number') {
  5618. err = new PlainValue$4.YAMLSemanticError(cst, msg);
  5619. err.offset = lastItem.offset + 1;
  5620. } else {
  5621. err = new PlainValue$4.YAMLSemanticError(lastItem, msg);
  5622. if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
  5623. }
  5624. errors.push(err);
  5625. }
  5626. }
  5627. function checkFlowCommentSpace(errors, comment) {
  5628. const prev = comment.context.src[comment.range.start - 1];
  5629. if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
  5630. const msg = 'Comments must be separated from other tokens by white space characters';
  5631. errors.push(new PlainValue$4.YAMLSemanticError(comment, msg));
  5632. }
  5633. }
  5634. function getLongKeyError(source, key) {
  5635. const sk = String(key);
  5636. const k = sk.substr(0, 8) + '...' + sk.substr(-8);
  5637. return new PlainValue$4.YAMLSemanticError(source, `The "${k}" key is too long`);
  5638. }
  5639. function resolveComments(collection, comments) {
  5640. for (const {
  5641. afterKey,
  5642. before,
  5643. comment
  5644. } of comments) {
  5645. let item = collection.items[before];
  5646. if (!item) {
  5647. if (comment !== undefined) {
  5648. if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
  5649. }
  5650. } else {
  5651. if (afterKey && item.value) item = item.value;
  5652. if (comment === undefined) {
  5653. if (afterKey || !item.commentBefore) item.spaceBefore = true;
  5654. } else {
  5655. if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
  5656. }
  5657. }
  5658. }
  5659. } // on error, will return { str: string, errors: Error[] }
  5660. function resolveString(doc, node) {
  5661. const res = node.strValue;
  5662. if (!res) return '';
  5663. if (typeof res === 'string') return res;
  5664. res.errors.forEach(error => {
  5665. if (!error.source) error.source = node;
  5666. doc.errors.push(error);
  5667. });
  5668. return res.str;
  5669. }
  5670. function resolveTagHandle(doc, node) {
  5671. const {
  5672. handle,
  5673. suffix
  5674. } = node.tag;
  5675. let prefix = doc.tagPrefixes.find(p => p.handle === handle);
  5676. if (!prefix) {
  5677. const dtp = doc.getDefaults().tagPrefixes;
  5678. if (dtp) prefix = dtp.find(p => p.handle === handle);
  5679. if (!prefix) throw new PlainValue$4.YAMLSemanticError(node, `The ${handle} tag handle is non-default and was not declared.`);
  5680. }
  5681. if (!suffix) throw new PlainValue$4.YAMLSemanticError(node, `The ${handle} tag has no suffix.`);
  5682. if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
  5683. if (suffix[0] === '^') {
  5684. doc.warnings.push(new PlainValue$4.YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
  5685. return suffix;
  5686. }
  5687. if (/[:/]/.test(suffix)) {
  5688. // word/foo -> tag:word.yaml.org,2002:foo
  5689. const vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
  5690. return vocab ? `tag:${vocab[1]}.yaml.org,2002:${vocab[2]}` : `tag:${suffix}`;
  5691. }
  5692. }
  5693. return prefix.prefix + decodeURIComponent(suffix);
  5694. }
  5695. function resolveTagName(doc, node) {
  5696. const {
  5697. tag,
  5698. type
  5699. } = node;
  5700. let nonSpecific = false;
  5701. if (tag) {
  5702. const {
  5703. handle,
  5704. suffix,
  5705. verbatim
  5706. } = tag;
  5707. if (verbatim) {
  5708. if (verbatim !== '!' && verbatim !== '!!') return verbatim;
  5709. const msg = `Verbatim tags aren't resolved, so ${verbatim} is invalid.`;
  5710. doc.errors.push(new PlainValue$4.YAMLSemanticError(node, msg));
  5711. } else if (handle === '!' && !suffix) {
  5712. nonSpecific = true;
  5713. } else {
  5714. try {
  5715. return resolveTagHandle(doc, node);
  5716. } catch (error) {
  5717. doc.errors.push(error);
  5718. }
  5719. }
  5720. }
  5721. switch (type) {
  5722. case PlainValue$4.Type.BLOCK_FOLDED:
  5723. case PlainValue$4.Type.BLOCK_LITERAL:
  5724. case PlainValue$4.Type.QUOTE_DOUBLE:
  5725. case PlainValue$4.Type.QUOTE_SINGLE:
  5726. return PlainValue$4.defaultTags.STR;
  5727. case PlainValue$4.Type.FLOW_MAP:
  5728. case PlainValue$4.Type.MAP:
  5729. return PlainValue$4.defaultTags.MAP;
  5730. case PlainValue$4.Type.FLOW_SEQ:
  5731. case PlainValue$4.Type.SEQ:
  5732. return PlainValue$4.defaultTags.SEQ;
  5733. case PlainValue$4.Type.PLAIN:
  5734. return nonSpecific ? PlainValue$4.defaultTags.STR : null;
  5735. default:
  5736. return null;
  5737. }
  5738. }
  5739. function resolveByTagName(doc, node, tagName) {
  5740. const {
  5741. tags
  5742. } = doc.schema;
  5743. const matchWithTest = [];
  5744. for (const tag of tags) {
  5745. if (tag.tag === tagName) {
  5746. if (tag.test) matchWithTest.push(tag);else {
  5747. const res = tag.resolve(doc, node);
  5748. return res instanceof Collection ? res : new Scalar(res);
  5749. }
  5750. }
  5751. }
  5752. const str = resolveString(doc, node);
  5753. if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
  5754. return null;
  5755. }
  5756. function getFallbackTagName({
  5757. type
  5758. }) {
  5759. switch (type) {
  5760. case PlainValue$4.Type.FLOW_MAP:
  5761. case PlainValue$4.Type.MAP:
  5762. return PlainValue$4.defaultTags.MAP;
  5763. case PlainValue$4.Type.FLOW_SEQ:
  5764. case PlainValue$4.Type.SEQ:
  5765. return PlainValue$4.defaultTags.SEQ;
  5766. default:
  5767. return PlainValue$4.defaultTags.STR;
  5768. }
  5769. }
  5770. function resolveTag(doc, node, tagName) {
  5771. try {
  5772. const res = resolveByTagName(doc, node, tagName);
  5773. if (res) {
  5774. if (tagName && node.tag) res.tag = tagName;
  5775. return res;
  5776. }
  5777. } catch (error) {
  5778. /* istanbul ignore if */
  5779. if (!error.source) error.source = node;
  5780. doc.errors.push(error);
  5781. return null;
  5782. }
  5783. try {
  5784. const fallback = getFallbackTagName(node);
  5785. if (!fallback) throw new Error(`The tag ${tagName} is unavailable`);
  5786. const msg = `The tag ${tagName} is unavailable, falling back to ${fallback}`;
  5787. doc.warnings.push(new PlainValue$4.YAMLWarning(node, msg));
  5788. const res = resolveByTagName(doc, node, fallback);
  5789. res.tag = tagName;
  5790. return res;
  5791. } catch (error) {
  5792. const refError = new PlainValue$4.YAMLReferenceError(node, error.message);
  5793. refError.stack = error.stack;
  5794. doc.errors.push(refError);
  5795. return null;
  5796. }
  5797. }
  5798. const isCollectionItem = node => {
  5799. if (!node) return false;
  5800. const {
  5801. type
  5802. } = node;
  5803. return type === PlainValue$4.Type.MAP_KEY || type === PlainValue$4.Type.MAP_VALUE || type === PlainValue$4.Type.SEQ_ITEM;
  5804. };
  5805. function resolveNodeProps(errors, node) {
  5806. const comments = {
  5807. before: [],
  5808. after: []
  5809. };
  5810. let hasAnchor = false;
  5811. let hasTag = false;
  5812. const props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
  5813. for (const {
  5814. start,
  5815. end
  5816. } of props) {
  5817. switch (node.context.src[start]) {
  5818. case PlainValue$4.Char.COMMENT:
  5819. {
  5820. if (!node.commentHasRequiredWhitespace(start)) {
  5821. const msg = 'Comments must be separated from other tokens by white space characters';
  5822. errors.push(new PlainValue$4.YAMLSemanticError(node, msg));
  5823. }
  5824. const {
  5825. header,
  5826. valueRange
  5827. } = node;
  5828. const cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
  5829. cc.push(node.context.src.slice(start + 1, end));
  5830. break;
  5831. }
  5832. // Actual anchor & tag resolution is handled by schema, here we just complain
  5833. case PlainValue$4.Char.ANCHOR:
  5834. if (hasAnchor) {
  5835. const msg = 'A node can have at most one anchor';
  5836. errors.push(new PlainValue$4.YAMLSemanticError(node, msg));
  5837. }
  5838. hasAnchor = true;
  5839. break;
  5840. case PlainValue$4.Char.TAG:
  5841. if (hasTag) {
  5842. const msg = 'A node can have at most one tag';
  5843. errors.push(new PlainValue$4.YAMLSemanticError(node, msg));
  5844. }
  5845. hasTag = true;
  5846. break;
  5847. }
  5848. }
  5849. return {
  5850. comments,
  5851. hasAnchor,
  5852. hasTag
  5853. };
  5854. }
  5855. function resolveNodeValue(doc, node) {
  5856. const {
  5857. anchors,
  5858. errors,
  5859. schema
  5860. } = doc;
  5861. if (node.type === PlainValue$4.Type.ALIAS) {
  5862. const name = node.rawValue;
  5863. const src = anchors.getNode(name);
  5864. if (!src) {
  5865. const msg = `Aliased anchor not found: ${name}`;
  5866. errors.push(new PlainValue$4.YAMLReferenceError(node, msg));
  5867. return null;
  5868. } // Lazy resolution for circular references
  5869. const res = new Alias(src);
  5870. anchors._cstAliases.push(res);
  5871. return res;
  5872. }
  5873. const tagName = resolveTagName(doc, node);
  5874. if (tagName) return resolveTag(doc, node, tagName);
  5875. if (node.type !== PlainValue$4.Type.PLAIN) {
  5876. const msg = `Failed to resolve ${node.type} node here`;
  5877. errors.push(new PlainValue$4.YAMLSyntaxError(node, msg));
  5878. return null;
  5879. }
  5880. try {
  5881. const str = resolveString(doc, node);
  5882. return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
  5883. } catch (error) {
  5884. if (!error.source) error.source = node;
  5885. errors.push(error);
  5886. return null;
  5887. }
  5888. } // sets node.resolved on success
  5889. function resolveNode(doc, node) {
  5890. if (!node) return null;
  5891. if (node.error) doc.errors.push(node.error);
  5892. const {
  5893. comments,
  5894. hasAnchor,
  5895. hasTag
  5896. } = resolveNodeProps(doc.errors, node);
  5897. if (hasAnchor) {
  5898. const {
  5899. anchors
  5900. } = doc;
  5901. const name = node.anchor;
  5902. const prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
  5903. // name have already been resolved, so it may safely be renamed.
  5904. if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
  5905. // anchors need to be available during resolution to allow for
  5906. // circular references.
  5907. anchors.map[name] = node;
  5908. }
  5909. if (node.type === PlainValue$4.Type.ALIAS && (hasAnchor || hasTag)) {
  5910. const msg = 'An alias node must not specify any properties';
  5911. doc.errors.push(new PlainValue$4.YAMLSemanticError(node, msg));
  5912. }
  5913. const res = resolveNodeValue(doc, node);
  5914. if (res) {
  5915. res.range = [node.range.start, node.range.end];
  5916. if (doc.options.keepCstNodes) res.cstNode = node;
  5917. if (doc.options.keepNodeTypes) res.type = node.type;
  5918. const cb = comments.before.join('\n');
  5919. if (cb) {
  5920. res.commentBefore = res.commentBefore ? `${res.commentBefore}\n${cb}` : cb;
  5921. }
  5922. const ca = comments.after.join('\n');
  5923. if (ca) res.comment = res.comment ? `${res.comment}\n${ca}` : ca;
  5924. }
  5925. return node.resolved = res;
  5926. }
  5927. function resolveMap(doc, cst) {
  5928. if (cst.type !== PlainValue$4.Type.MAP && cst.type !== PlainValue$4.Type.FLOW_MAP) {
  5929. const msg = `A ${cst.type} node cannot be resolved as a mapping`;
  5930. doc.errors.push(new PlainValue$4.YAMLSyntaxError(cst, msg));
  5931. return null;
  5932. }
  5933. const {
  5934. comments,
  5935. items
  5936. } = cst.type === PlainValue$4.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
  5937. const map = new YAMLMap();
  5938. map.items = items;
  5939. resolveComments(map, comments);
  5940. let hasCollectionKey = false;
  5941. for (let i = 0; i < items.length; ++i) {
  5942. const {
  5943. key: iKey
  5944. } = items[i];
  5945. if (iKey instanceof Collection) hasCollectionKey = true;
  5946. if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
  5947. items[i] = new Merge(items[i]);
  5948. const sources = items[i].value.items;
  5949. let error = null;
  5950. sources.some(node => {
  5951. if (node instanceof Alias) {
  5952. // During parsing, alias sources are CST nodes; to account for
  5953. // circular references their resolved values can't be used here.
  5954. const {
  5955. type
  5956. } = node.source;
  5957. if (type === PlainValue$4.Type.MAP || type === PlainValue$4.Type.FLOW_MAP) return false;
  5958. return error = 'Merge nodes aliases can only point to maps';
  5959. }
  5960. return error = 'Merge nodes can only have Alias nodes as values';
  5961. });
  5962. if (error) doc.errors.push(new PlainValue$4.YAMLSemanticError(cst, error));
  5963. } else {
  5964. for (let j = i + 1; j < items.length; ++j) {
  5965. const {
  5966. key: jKey
  5967. } = items[j];
  5968. if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
  5969. const msg = `Map keys must be unique; "${iKey}" is repeated`;
  5970. doc.errors.push(new PlainValue$4.YAMLSemanticError(cst, msg));
  5971. break;
  5972. }
  5973. }
  5974. }
  5975. }
  5976. if (hasCollectionKey && !doc.options.mapAsMap) {
  5977. const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
  5978. doc.warnings.push(new PlainValue$4.YAMLWarning(cst, warn));
  5979. }
  5980. cst.resolved = map;
  5981. return map;
  5982. }
  5983. const valueHasPairComment = ({
  5984. context: {
  5985. lineStart,
  5986. node,
  5987. src
  5988. },
  5989. props
  5990. }) => {
  5991. if (props.length === 0) return false;
  5992. const {
  5993. start
  5994. } = props[0];
  5995. if (node && start > node.valueRange.start) return false;
  5996. if (src[start] !== PlainValue$4.Char.COMMENT) return false;
  5997. for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
  5998. return true;
  5999. };
  6000. function resolvePairComment(item, pair) {
  6001. if (!valueHasPairComment(item)) return;
  6002. const comment = item.getPropValue(0, PlainValue$4.Char.COMMENT, true);
  6003. let found = false;
  6004. const cb = pair.value.commentBefore;
  6005. if (cb && cb.startsWith(comment)) {
  6006. pair.value.commentBefore = cb.substr(comment.length + 1);
  6007. found = true;
  6008. } else {
  6009. const cc = pair.value.comment;
  6010. if (!item.node && cc && cc.startsWith(comment)) {
  6011. pair.value.comment = cc.substr(comment.length + 1);
  6012. found = true;
  6013. }
  6014. }
  6015. if (found) pair.comment = comment;
  6016. }
  6017. function resolveBlockMapItems(doc, cst) {
  6018. const comments = [];
  6019. const items = [];
  6020. let key = undefined;
  6021. let keyStart = null;
  6022. for (let i = 0; i < cst.items.length; ++i) {
  6023. const item = cst.items[i];
  6024. switch (item.type) {
  6025. case PlainValue$4.Type.BLANK_LINE:
  6026. comments.push({
  6027. afterKey: !!key,
  6028. before: items.length
  6029. });
  6030. break;
  6031. case PlainValue$4.Type.COMMENT:
  6032. comments.push({
  6033. afterKey: !!key,
  6034. before: items.length,
  6035. comment: item.comment
  6036. });
  6037. break;
  6038. case PlainValue$4.Type.MAP_KEY:
  6039. if (key !== undefined) items.push(new Pair(key));
  6040. if (item.error) doc.errors.push(item.error);
  6041. key = resolveNode(doc, item.node);
  6042. keyStart = null;
  6043. break;
  6044. case PlainValue$4.Type.MAP_VALUE:
  6045. {
  6046. if (key === undefined) key = null;
  6047. if (item.error) doc.errors.push(item.error);
  6048. if (!item.context.atLineStart && item.node && item.node.type === PlainValue$4.Type.MAP && !item.node.context.atLineStart) {
  6049. const msg = 'Nested mappings are not allowed in compact mappings';
  6050. doc.errors.push(new PlainValue$4.YAMLSemanticError(item.node, msg));
  6051. }
  6052. let valueNode = item.node;
  6053. if (!valueNode && item.props.length > 0) {
  6054. // Comments on an empty mapping value need to be preserved, so we
  6055. // need to construct a minimal empty node here to use instead of the
  6056. // missing `item.node`. -- eemeli/yaml#19
  6057. valueNode = new PlainValue$4.PlainValue(PlainValue$4.Type.PLAIN, []);
  6058. valueNode.context = {
  6059. parent: item,
  6060. src: item.context.src
  6061. };
  6062. const pos = item.range.start + 1;
  6063. valueNode.range = {
  6064. start: pos,
  6065. end: pos
  6066. };
  6067. valueNode.valueRange = {
  6068. start: pos,
  6069. end: pos
  6070. };
  6071. if (typeof item.range.origStart === 'number') {
  6072. const origPos = item.range.origStart + 1;
  6073. valueNode.range.origStart = valueNode.range.origEnd = origPos;
  6074. valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
  6075. }
  6076. }
  6077. const pair = new Pair(key, resolveNode(doc, valueNode));
  6078. resolvePairComment(item, pair);
  6079. items.push(pair);
  6080. if (key && typeof keyStart === 'number') {
  6081. if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
  6082. }
  6083. key = undefined;
  6084. keyStart = null;
  6085. }
  6086. break;
  6087. default:
  6088. if (key !== undefined) items.push(new Pair(key));
  6089. key = resolveNode(doc, item);
  6090. keyStart = item.range.start;
  6091. if (item.error) doc.errors.push(item.error);
  6092. next: for (let j = i + 1;; ++j) {
  6093. const nextItem = cst.items[j];
  6094. switch (nextItem && nextItem.type) {
  6095. case PlainValue$4.Type.BLANK_LINE:
  6096. case PlainValue$4.Type.COMMENT:
  6097. continue next;
  6098. case PlainValue$4.Type.MAP_VALUE:
  6099. break next;
  6100. default:
  6101. {
  6102. const msg = 'Implicit map keys need to be followed by map values';
  6103. doc.errors.push(new PlainValue$4.YAMLSemanticError(item, msg));
  6104. break next;
  6105. }
  6106. }
  6107. }
  6108. if (item.valueRangeContainsNewline) {
  6109. const msg = 'Implicit map keys need to be on a single line';
  6110. doc.errors.push(new PlainValue$4.YAMLSemanticError(item, msg));
  6111. }
  6112. }
  6113. }
  6114. if (key !== undefined) items.push(new Pair(key));
  6115. return {
  6116. comments,
  6117. items
  6118. };
  6119. }
  6120. function resolveFlowMapItems(doc, cst) {
  6121. const comments = [];
  6122. const items = [];
  6123. let key = undefined;
  6124. let explicitKey = false;
  6125. let next = '{';
  6126. for (let i = 0; i < cst.items.length; ++i) {
  6127. const item = cst.items[i];
  6128. if (typeof item.char === 'string') {
  6129. const {
  6130. char,
  6131. offset
  6132. } = item;
  6133. if (char === '?' && key === undefined && !explicitKey) {
  6134. explicitKey = true;
  6135. next = ':';
  6136. continue;
  6137. }
  6138. if (char === ':') {
  6139. if (key === undefined) key = null;
  6140. if (next === ':') {
  6141. next = ',';
  6142. continue;
  6143. }
  6144. } else {
  6145. if (explicitKey) {
  6146. if (key === undefined && char !== ',') key = null;
  6147. explicitKey = false;
  6148. }
  6149. if (key !== undefined) {
  6150. items.push(new Pair(key));
  6151. key = undefined;
  6152. if (char === ',') {
  6153. next = ':';
  6154. continue;
  6155. }
  6156. }
  6157. }
  6158. if (char === '}') {
  6159. if (i === cst.items.length - 1) continue;
  6160. } else if (char === next) {
  6161. next = ':';
  6162. continue;
  6163. }
  6164. const msg = `Flow map contains an unexpected ${char}`;
  6165. const err = new PlainValue$4.YAMLSyntaxError(cst, msg);
  6166. err.offset = offset;
  6167. doc.errors.push(err);
  6168. } else if (item.type === PlainValue$4.Type.BLANK_LINE) {
  6169. comments.push({
  6170. afterKey: !!key,
  6171. before: items.length
  6172. });
  6173. } else if (item.type === PlainValue$4.Type.COMMENT) {
  6174. checkFlowCommentSpace(doc.errors, item);
  6175. comments.push({
  6176. afterKey: !!key,
  6177. before: items.length,
  6178. comment: item.comment
  6179. });
  6180. } else if (key === undefined) {
  6181. if (next === ',') doc.errors.push(new PlainValue$4.YAMLSemanticError(item, 'Separator , missing in flow map'));
  6182. key = resolveNode(doc, item);
  6183. } else {
  6184. if (next !== ',') doc.errors.push(new PlainValue$4.YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
  6185. items.push(new Pair(key, resolveNode(doc, item)));
  6186. key = undefined;
  6187. explicitKey = false;
  6188. }
  6189. }
  6190. checkFlowCollectionEnd(doc.errors, cst);
  6191. if (key !== undefined) items.push(new Pair(key));
  6192. return {
  6193. comments,
  6194. items
  6195. };
  6196. }
  6197. function resolveSeq$3(doc, cst) {
  6198. if (cst.type !== PlainValue$4.Type.SEQ && cst.type !== PlainValue$4.Type.FLOW_SEQ) {
  6199. const msg = `A ${cst.type} node cannot be resolved as a sequence`;
  6200. doc.errors.push(new PlainValue$4.YAMLSyntaxError(cst, msg));
  6201. return null;
  6202. }
  6203. const {
  6204. comments,
  6205. items
  6206. } = cst.type === PlainValue$4.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
  6207. const seq = new YAMLSeq();
  6208. seq.items = items;
  6209. resolveComments(seq, comments);
  6210. if (!doc.options.mapAsMap && items.some(it => it instanceof Pair && it.key instanceof Collection)) {
  6211. const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
  6212. doc.warnings.push(new PlainValue$4.YAMLWarning(cst, warn));
  6213. }
  6214. cst.resolved = seq;
  6215. return seq;
  6216. }
  6217. function resolveBlockSeqItems(doc, cst) {
  6218. const comments = [];
  6219. const items = [];
  6220. for (let i = 0; i < cst.items.length; ++i) {
  6221. const item = cst.items[i];
  6222. switch (item.type) {
  6223. case PlainValue$4.Type.BLANK_LINE:
  6224. comments.push({
  6225. before: items.length
  6226. });
  6227. break;
  6228. case PlainValue$4.Type.COMMENT:
  6229. comments.push({
  6230. comment: item.comment,
  6231. before: items.length
  6232. });
  6233. break;
  6234. case PlainValue$4.Type.SEQ_ITEM:
  6235. if (item.error) doc.errors.push(item.error);
  6236. items.push(resolveNode(doc, item.node));
  6237. if (item.hasProps) {
  6238. const msg = 'Sequence items cannot have tags or anchors before the - indicator';
  6239. doc.errors.push(new PlainValue$4.YAMLSemanticError(item, msg));
  6240. }
  6241. break;
  6242. default:
  6243. if (item.error) doc.errors.push(item.error);
  6244. doc.errors.push(new PlainValue$4.YAMLSyntaxError(item, `Unexpected ${item.type} node in sequence`));
  6245. }
  6246. }
  6247. return {
  6248. comments,
  6249. items
  6250. };
  6251. }
  6252. function resolveFlowSeqItems(doc, cst) {
  6253. const comments = [];
  6254. const items = [];
  6255. let explicitKey = false;
  6256. let key = undefined;
  6257. let keyStart = null;
  6258. let next = '[';
  6259. let prevItem = null;
  6260. for (let i = 0; i < cst.items.length; ++i) {
  6261. const item = cst.items[i];
  6262. if (typeof item.char === 'string') {
  6263. const {
  6264. char,
  6265. offset
  6266. } = item;
  6267. if (char !== ':' && (explicitKey || key !== undefined)) {
  6268. if (explicitKey && key === undefined) key = next ? items.pop() : null;
  6269. items.push(new Pair(key));
  6270. explicitKey = false;
  6271. key = undefined;
  6272. keyStart = null;
  6273. }
  6274. if (char === next) {
  6275. next = null;
  6276. } else if (!next && char === '?') {
  6277. explicitKey = true;
  6278. } else if (next !== '[' && char === ':' && key === undefined) {
  6279. if (next === ',') {
  6280. key = items.pop();
  6281. if (key instanceof Pair) {
  6282. const msg = 'Chaining flow sequence pairs is invalid';
  6283. const err = new PlainValue$4.YAMLSemanticError(cst, msg);
  6284. err.offset = offset;
  6285. doc.errors.push(err);
  6286. }
  6287. if (!explicitKey && typeof keyStart === 'number') {
  6288. const keyEnd = item.range ? item.range.start : item.offset;
  6289. if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
  6290. const {
  6291. src
  6292. } = prevItem.context;
  6293. for (let i = keyStart; i < keyEnd; ++i) if (src[i] === '\n') {
  6294. const msg = 'Implicit keys of flow sequence pairs need to be on a single line';
  6295. doc.errors.push(new PlainValue$4.YAMLSemanticError(prevItem, msg));
  6296. break;
  6297. }
  6298. }
  6299. } else {
  6300. key = null;
  6301. }
  6302. keyStart = null;
  6303. explicitKey = false;
  6304. next = null;
  6305. } else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
  6306. const msg = `Flow sequence contains an unexpected ${char}`;
  6307. const err = new PlainValue$4.YAMLSyntaxError(cst, msg);
  6308. err.offset = offset;
  6309. doc.errors.push(err);
  6310. }
  6311. } else if (item.type === PlainValue$4.Type.BLANK_LINE) {
  6312. comments.push({
  6313. before: items.length
  6314. });
  6315. } else if (item.type === PlainValue$4.Type.COMMENT) {
  6316. checkFlowCommentSpace(doc.errors, item);
  6317. comments.push({
  6318. comment: item.comment,
  6319. before: items.length
  6320. });
  6321. } else {
  6322. if (next) {
  6323. const msg = `Expected a ${next} in flow sequence`;
  6324. doc.errors.push(new PlainValue$4.YAMLSemanticError(item, msg));
  6325. }
  6326. const value = resolveNode(doc, item);
  6327. if (key === undefined) {
  6328. items.push(value);
  6329. prevItem = item;
  6330. } else {
  6331. items.push(new Pair(key, value));
  6332. key = undefined;
  6333. }
  6334. keyStart = item.range.start;
  6335. next = ',';
  6336. }
  6337. }
  6338. checkFlowCollectionEnd(doc.errors, cst);
  6339. if (key !== undefined) items.push(new Pair(key));
  6340. return {
  6341. comments,
  6342. items
  6343. };
  6344. }
  6345. resolveSeqD03cb037.Alias = Alias;
  6346. resolveSeqD03cb037.Collection = Collection;
  6347. resolveSeqD03cb037.Merge = Merge;
  6348. resolveSeqD03cb037.Node = Node;
  6349. resolveSeqD03cb037.Pair = Pair;
  6350. resolveSeqD03cb037.Scalar = Scalar;
  6351. resolveSeqD03cb037.YAMLMap = YAMLMap;
  6352. resolveSeqD03cb037.YAMLSeq = YAMLSeq;
  6353. resolveSeqD03cb037.addComment = addComment;
  6354. resolveSeqD03cb037.binaryOptions = binaryOptions;
  6355. resolveSeqD03cb037.boolOptions = boolOptions;
  6356. resolveSeqD03cb037.findPair = findPair;
  6357. resolveSeqD03cb037.intOptions = intOptions;
  6358. resolveSeqD03cb037.isEmptyPath = isEmptyPath;
  6359. resolveSeqD03cb037.nullOptions = nullOptions;
  6360. resolveSeqD03cb037.resolveMap = resolveMap;
  6361. resolveSeqD03cb037.resolveNode = resolveNode;
  6362. resolveSeqD03cb037.resolveSeq = resolveSeq$3;
  6363. resolveSeqD03cb037.resolveString = resolveString;
  6364. resolveSeqD03cb037.strOptions = strOptions;
  6365. resolveSeqD03cb037.stringifyNumber = stringifyNumber;
  6366. resolveSeqD03cb037.stringifyString = stringifyString;
  6367. resolveSeqD03cb037.toJSON = toJSON;
  6368. var check = function (it) {
  6369. return it && it.Math == Math && it;
  6370. };
  6371. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  6372. var global$m =
  6373. // eslint-disable-next-line es/no-global-this -- safe
  6374. check(typeof globalThis == 'object' && globalThis) ||
  6375. check(typeof window == 'object' && window) ||
  6376. // eslint-disable-next-line no-restricted-globals -- safe
  6377. check(typeof self == 'object' && self) ||
  6378. check(typeof global$m == 'object' && global$m) ||
  6379. // eslint-disable-next-line no-new-func -- fallback
  6380. (function () { return this; })() || Function('return this')();
  6381. var objectGetOwnPropertyDescriptor = {};
  6382. var fails$7 = function (exec) {
  6383. try {
  6384. return !!exec();
  6385. } catch (error) {
  6386. return true;
  6387. }
  6388. };
  6389. var fails$6 = fails$7;
  6390. // Detect IE8's incomplete defineProperty implementation
  6391. var descriptors = !fails$6(function () {
  6392. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  6393. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  6394. });
  6395. var call$4 = Function.prototype.call;
  6396. var functionCall = call$4.bind ? call$4.bind(call$4) : function () {
  6397. return call$4.apply(call$4, arguments);
  6398. };
  6399. var objectPropertyIsEnumerable = {};
  6400. var $propertyIsEnumerable = {}.propertyIsEnumerable;
  6401. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  6402. var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
  6403. // Nashorn ~ JDK8 bug
  6404. var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
  6405. // `Object.prototype.propertyIsEnumerable` method implementation
  6406. // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
  6407. objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  6408. var descriptor = getOwnPropertyDescriptor$1(this, V);
  6409. return !!descriptor && descriptor.enumerable;
  6410. } : $propertyIsEnumerable;
  6411. var createPropertyDescriptor$2 = function (bitmap, value) {
  6412. return {
  6413. enumerable: !(bitmap & 1),
  6414. configurable: !(bitmap & 2),
  6415. writable: !(bitmap & 4),
  6416. value: value
  6417. };
  6418. };
  6419. var FunctionPrototype$1 = Function.prototype;
  6420. var bind = FunctionPrototype$1.bind;
  6421. var call$3 = FunctionPrototype$1.call;
  6422. var callBind = bind && bind.bind(call$3);
  6423. var functionUncurryThis = bind ? function (fn) {
  6424. return fn && callBind(call$3, fn);
  6425. } : function (fn) {
  6426. return fn && function () {
  6427. return call$3.apply(fn, arguments);
  6428. };
  6429. };
  6430. var uncurryThis$a = functionUncurryThis;
  6431. var toString$3 = uncurryThis$a({}.toString);
  6432. var stringSlice = uncurryThis$a(''.slice);
  6433. var classofRaw$1 = function (it) {
  6434. return stringSlice(toString$3(it), 8, -1);
  6435. };
  6436. var global$l = global$m;
  6437. var uncurryThis$9 = functionUncurryThis;
  6438. var fails$5 = fails$7;
  6439. var classof$2 = classofRaw$1;
  6440. var Object$4 = global$l.Object;
  6441. var split = uncurryThis$9(''.split);
  6442. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  6443. var indexedObject = fails$5(function () {
  6444. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  6445. // eslint-disable-next-line no-prototype-builtins -- safe
  6446. return !Object$4('z').propertyIsEnumerable(0);
  6447. }) ? function (it) {
  6448. return classof$2(it) == 'String' ? split(it, '') : Object$4(it);
  6449. } : Object$4;
  6450. var global$k = global$m;
  6451. var TypeError$7 = global$k.TypeError;
  6452. // `RequireObjectCoercible` abstract operation
  6453. // https://tc39.es/ecma262/#sec-requireobjectcoercible
  6454. var requireObjectCoercible$2 = function (it) {
  6455. if (it == undefined) throw TypeError$7("Can't call method on " + it);
  6456. return it;
  6457. };
  6458. // toObject with fallback for non-array-like ES3 strings
  6459. var IndexedObject = indexedObject;
  6460. var requireObjectCoercible$1 = requireObjectCoercible$2;
  6461. var toIndexedObject$3 = function (it) {
  6462. return IndexedObject(requireObjectCoercible$1(it));
  6463. };
  6464. // `IsCallable` abstract operation
  6465. // https://tc39.es/ecma262/#sec-iscallable
  6466. var isCallable$a = function (argument) {
  6467. return typeof argument == 'function';
  6468. };
  6469. var isCallable$9 = isCallable$a;
  6470. var isObject$5 = function (it) {
  6471. return typeof it == 'object' ? it !== null : isCallable$9(it);
  6472. };
  6473. var global$j = global$m;
  6474. var isCallable$8 = isCallable$a;
  6475. var aFunction = function (argument) {
  6476. return isCallable$8(argument) ? argument : undefined;
  6477. };
  6478. var getBuiltIn$3 = function (namespace, method) {
  6479. return arguments.length < 2 ? aFunction(global$j[namespace]) : global$j[namespace] && global$j[namespace][method];
  6480. };
  6481. var uncurryThis$8 = functionUncurryThis;
  6482. var objectIsPrototypeOf = uncurryThis$8({}.isPrototypeOf);
  6483. var getBuiltIn$2 = getBuiltIn$3;
  6484. var engineUserAgent = getBuiltIn$2('navigator', 'userAgent') || '';
  6485. var global$i = global$m;
  6486. var userAgent$2 = engineUserAgent;
  6487. var process$1 = global$i.process;
  6488. var Deno = global$i.Deno;
  6489. var versions = process$1 && process$1.versions || Deno && Deno.version;
  6490. var v8 = versions && versions.v8;
  6491. var match, version;
  6492. if (v8) {
  6493. match = v8.split('.');
  6494. // in old Chrome, versions of V8 isn't V8 = Chrome / 10
  6495. // but their correct versions are not interesting for us
  6496. version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]);
  6497. }
  6498. // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0`
  6499. // so check `userAgent` even if `.v8` exists, but 0
  6500. if (!version && userAgent$2) {
  6501. match = userAgent$2.match(/Edge\/(\d+)/);
  6502. if (!match || match[1] >= 74) {
  6503. match = userAgent$2.match(/Chrome\/(\d+)/);
  6504. if (match) version = +match[1];
  6505. }
  6506. }
  6507. var engineV8Version = version;
  6508. /* eslint-disable es/no-symbol -- required for testing */
  6509. var V8_VERSION = engineV8Version;
  6510. var fails$4 = fails$7;
  6511. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  6512. var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$4(function () {
  6513. var symbol = Symbol();
  6514. // Chrome 38 Symbol has incorrect toString conversion
  6515. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  6516. return !String(symbol) || !(Object(symbol) instanceof Symbol) ||
  6517. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  6518. !Symbol.sham && V8_VERSION && V8_VERSION < 41;
  6519. });
  6520. /* eslint-disable es/no-symbol -- required for testing */
  6521. var NATIVE_SYMBOL$1 = nativeSymbol;
  6522. var useSymbolAsUid = NATIVE_SYMBOL$1
  6523. && !Symbol.sham
  6524. && typeof Symbol.iterator == 'symbol';
  6525. var global$h = global$m;
  6526. var getBuiltIn$1 = getBuiltIn$3;
  6527. var isCallable$7 = isCallable$a;
  6528. var isPrototypeOf = objectIsPrototypeOf;
  6529. var USE_SYMBOL_AS_UID$1 = useSymbolAsUid;
  6530. var Object$3 = global$h.Object;
  6531. var isSymbol$2 = USE_SYMBOL_AS_UID$1 ? function (it) {
  6532. return typeof it == 'symbol';
  6533. } : function (it) {
  6534. var $Symbol = getBuiltIn$1('Symbol');
  6535. return isCallable$7($Symbol) && isPrototypeOf($Symbol.prototype, Object$3(it));
  6536. };
  6537. var global$g = global$m;
  6538. var String$3 = global$g.String;
  6539. var tryToString$1 = function (argument) {
  6540. try {
  6541. return String$3(argument);
  6542. } catch (error) {
  6543. return 'Object';
  6544. }
  6545. };
  6546. var global$f = global$m;
  6547. var isCallable$6 = isCallable$a;
  6548. var tryToString = tryToString$1;
  6549. var TypeError$6 = global$f.TypeError;
  6550. // `Assert: IsCallable(argument) is true`
  6551. var aCallable$2 = function (argument) {
  6552. if (isCallable$6(argument)) return argument;
  6553. throw TypeError$6(tryToString(argument) + ' is not a function');
  6554. };
  6555. var aCallable$1 = aCallable$2;
  6556. // `GetMethod` abstract operation
  6557. // https://tc39.es/ecma262/#sec-getmethod
  6558. var getMethod$1 = function (V, P) {
  6559. var func = V[P];
  6560. return func == null ? undefined : aCallable$1(func);
  6561. };
  6562. var global$e = global$m;
  6563. var call$2 = functionCall;
  6564. var isCallable$5 = isCallable$a;
  6565. var isObject$4 = isObject$5;
  6566. var TypeError$5 = global$e.TypeError;
  6567. // `OrdinaryToPrimitive` abstract operation
  6568. // https://tc39.es/ecma262/#sec-ordinarytoprimitive
  6569. var ordinaryToPrimitive$1 = function (input, pref) {
  6570. var fn, val;
  6571. if (pref === 'string' && isCallable$5(fn = input.toString) && !isObject$4(val = call$2(fn, input))) return val;
  6572. if (isCallable$5(fn = input.valueOf) && !isObject$4(val = call$2(fn, input))) return val;
  6573. if (pref !== 'string' && isCallable$5(fn = input.toString) && !isObject$4(val = call$2(fn, input))) return val;
  6574. throw TypeError$5("Can't convert object to primitive value");
  6575. };
  6576. var shared$3 = {exports: {}};
  6577. var global$d = global$m;
  6578. // eslint-disable-next-line es/no-object-defineproperty -- safe
  6579. var defineProperty = Object.defineProperty;
  6580. var setGlobal$3 = function (key, value) {
  6581. try {
  6582. defineProperty(global$d, key, { value: value, configurable: true, writable: true });
  6583. } catch (error) {
  6584. global$d[key] = value;
  6585. } return value;
  6586. };
  6587. var global$c = global$m;
  6588. var setGlobal$2 = setGlobal$3;
  6589. var SHARED = '__core-js_shared__';
  6590. var store$3 = global$c[SHARED] || setGlobal$2(SHARED, {});
  6591. var sharedStore = store$3;
  6592. var store$2 = sharedStore;
  6593. (shared$3.exports = function (key, value) {
  6594. return store$2[key] || (store$2[key] = value !== undefined ? value : {});
  6595. })('versions', []).push({
  6596. version: '3.19.1',
  6597. mode: 'global',
  6598. copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
  6599. });
  6600. var global$b = global$m;
  6601. var requireObjectCoercible = requireObjectCoercible$2;
  6602. var Object$2 = global$b.Object;
  6603. // `ToObject` abstract operation
  6604. // https://tc39.es/ecma262/#sec-toobject
  6605. var toObject$2 = function (argument) {
  6606. return Object$2(requireObjectCoercible(argument));
  6607. };
  6608. var uncurryThis$7 = functionUncurryThis;
  6609. var toObject$1 = toObject$2;
  6610. var hasOwnProperty = uncurryThis$7({}.hasOwnProperty);
  6611. // `HasOwnProperty` abstract operation
  6612. // https://tc39.es/ecma262/#sec-hasownproperty
  6613. var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
  6614. return hasOwnProperty(toObject$1(it), key);
  6615. };
  6616. var uncurryThis$6 = functionUncurryThis;
  6617. var id = 0;
  6618. var postfix = Math.random();
  6619. var toString$2 = uncurryThis$6(1.0.toString);
  6620. var uid$2 = function (key) {
  6621. return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$2(++id + postfix, 36);
  6622. };
  6623. var global$a = global$m;
  6624. var shared$2 = shared$3.exports;
  6625. var hasOwn$6 = hasOwnProperty_1;
  6626. var uid$1 = uid$2;
  6627. var NATIVE_SYMBOL = nativeSymbol;
  6628. var USE_SYMBOL_AS_UID = useSymbolAsUid;
  6629. var WellKnownSymbolsStore = shared$2('wks');
  6630. var Symbol$1 = global$a.Symbol;
  6631. var symbolFor = Symbol$1 && Symbol$1['for'];
  6632. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1;
  6633. var wellKnownSymbol$3 = function (name) {
  6634. if (!hasOwn$6(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) {
  6635. var description = 'Symbol.' + name;
  6636. if (NATIVE_SYMBOL && hasOwn$6(Symbol$1, name)) {
  6637. WellKnownSymbolsStore[name] = Symbol$1[name];
  6638. } else if (USE_SYMBOL_AS_UID && symbolFor) {
  6639. WellKnownSymbolsStore[name] = symbolFor(description);
  6640. } else {
  6641. WellKnownSymbolsStore[name] = createWellKnownSymbol(description);
  6642. }
  6643. } return WellKnownSymbolsStore[name];
  6644. };
  6645. var global$9 = global$m;
  6646. var call$1 = functionCall;
  6647. var isObject$3 = isObject$5;
  6648. var isSymbol$1 = isSymbol$2;
  6649. var getMethod = getMethod$1;
  6650. var ordinaryToPrimitive = ordinaryToPrimitive$1;
  6651. var wellKnownSymbol$2 = wellKnownSymbol$3;
  6652. var TypeError$4 = global$9.TypeError;
  6653. var TO_PRIMITIVE = wellKnownSymbol$2('toPrimitive');
  6654. // `ToPrimitive` abstract operation
  6655. // https://tc39.es/ecma262/#sec-toprimitive
  6656. var toPrimitive$1 = function (input, pref) {
  6657. if (!isObject$3(input) || isSymbol$1(input)) return input;
  6658. var exoticToPrim = getMethod(input, TO_PRIMITIVE);
  6659. var result;
  6660. if (exoticToPrim) {
  6661. if (pref === undefined) pref = 'default';
  6662. result = call$1(exoticToPrim, input, pref);
  6663. if (!isObject$3(result) || isSymbol$1(result)) return result;
  6664. throw TypeError$4("Can't convert object to primitive value");
  6665. }
  6666. if (pref === undefined) pref = 'number';
  6667. return ordinaryToPrimitive(input, pref);
  6668. };
  6669. var toPrimitive = toPrimitive$1;
  6670. var isSymbol = isSymbol$2;
  6671. // `ToPropertyKey` abstract operation
  6672. // https://tc39.es/ecma262/#sec-topropertykey
  6673. var toPropertyKey$2 = function (argument) {
  6674. var key = toPrimitive(argument, 'string');
  6675. return isSymbol(key) ? key : key + '';
  6676. };
  6677. var global$8 = global$m;
  6678. var isObject$2 = isObject$5;
  6679. var document = global$8.document;
  6680. // typeof document.createElement is 'object' in old IE
  6681. var EXISTS$1 = isObject$2(document) && isObject$2(document.createElement);
  6682. var documentCreateElement = function (it) {
  6683. return EXISTS$1 ? document.createElement(it) : {};
  6684. };
  6685. var DESCRIPTORS$4 = descriptors;
  6686. var fails$3 = fails$7;
  6687. var createElement = documentCreateElement;
  6688. // Thank's IE8 for his funny defineProperty
  6689. var ie8DomDefine = !DESCRIPTORS$4 && !fails$3(function () {
  6690. // eslint-disable-next-line es/no-object-defineproperty -- requied for testing
  6691. return Object.defineProperty(createElement('div'), 'a', {
  6692. get: function () { return 7; }
  6693. }).a != 7;
  6694. });
  6695. var DESCRIPTORS$3 = descriptors;
  6696. var call = functionCall;
  6697. var propertyIsEnumerableModule = objectPropertyIsEnumerable;
  6698. var createPropertyDescriptor$1 = createPropertyDescriptor$2;
  6699. var toIndexedObject$2 = toIndexedObject$3;
  6700. var toPropertyKey$1 = toPropertyKey$2;
  6701. var hasOwn$5 = hasOwnProperty_1;
  6702. var IE8_DOM_DEFINE$1 = ie8DomDefine;
  6703. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  6704. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  6705. // `Object.getOwnPropertyDescriptor` method
  6706. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  6707. objectGetOwnPropertyDescriptor.f = DESCRIPTORS$3 ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  6708. O = toIndexedObject$2(O);
  6709. P = toPropertyKey$1(P);
  6710. if (IE8_DOM_DEFINE$1) try {
  6711. return $getOwnPropertyDescriptor(O, P);
  6712. } catch (error) { /* empty */ }
  6713. if (hasOwn$5(O, P)) return createPropertyDescriptor$1(!call(propertyIsEnumerableModule.f, O, P), O[P]);
  6714. };
  6715. var objectDefineProperty = {};
  6716. var global$7 = global$m;
  6717. var isObject$1 = isObject$5;
  6718. var String$2 = global$7.String;
  6719. var TypeError$3 = global$7.TypeError;
  6720. // `Assert: Type(argument) is Object`
  6721. var anObject$2 = function (argument) {
  6722. if (isObject$1(argument)) return argument;
  6723. throw TypeError$3(String$2(argument) + ' is not an object');
  6724. };
  6725. var global$6 = global$m;
  6726. var DESCRIPTORS$2 = descriptors;
  6727. var IE8_DOM_DEFINE = ie8DomDefine;
  6728. var anObject$1 = anObject$2;
  6729. var toPropertyKey = toPropertyKey$2;
  6730. var TypeError$2 = global$6.TypeError;
  6731. // eslint-disable-next-line es/no-object-defineproperty -- safe
  6732. var $defineProperty = Object.defineProperty;
  6733. // `Object.defineProperty` method
  6734. // https://tc39.es/ecma262/#sec-object.defineproperty
  6735. objectDefineProperty.f = DESCRIPTORS$2 ? $defineProperty : function defineProperty(O, P, Attributes) {
  6736. anObject$1(O);
  6737. P = toPropertyKey(P);
  6738. anObject$1(Attributes);
  6739. if (IE8_DOM_DEFINE) try {
  6740. return $defineProperty(O, P, Attributes);
  6741. } catch (error) { /* empty */ }
  6742. if ('get' in Attributes || 'set' in Attributes) throw TypeError$2('Accessors not supported');
  6743. if ('value' in Attributes) O[P] = Attributes.value;
  6744. return O;
  6745. };
  6746. var DESCRIPTORS$1 = descriptors;
  6747. var definePropertyModule$1 = objectDefineProperty;
  6748. var createPropertyDescriptor = createPropertyDescriptor$2;
  6749. var createNonEnumerableProperty$3 = DESCRIPTORS$1 ? function (object, key, value) {
  6750. return definePropertyModule$1.f(object, key, createPropertyDescriptor(1, value));
  6751. } : function (object, key, value) {
  6752. object[key] = value;
  6753. return object;
  6754. };
  6755. var redefine$1 = {exports: {}};
  6756. var uncurryThis$5 = functionUncurryThis;
  6757. var isCallable$4 = isCallable$a;
  6758. var store$1 = sharedStore;
  6759. var functionToString = uncurryThis$5(Function.toString);
  6760. // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
  6761. if (!isCallable$4(store$1.inspectSource)) {
  6762. store$1.inspectSource = function (it) {
  6763. return functionToString(it);
  6764. };
  6765. }
  6766. var inspectSource$2 = store$1.inspectSource;
  6767. var global$5 = global$m;
  6768. var isCallable$3 = isCallable$a;
  6769. var inspectSource$1 = inspectSource$2;
  6770. var WeakMap$1 = global$5.WeakMap;
  6771. var nativeWeakMap = isCallable$3(WeakMap$1) && /native code/.test(inspectSource$1(WeakMap$1));
  6772. var shared$1 = shared$3.exports;
  6773. var uid = uid$2;
  6774. var keys = shared$1('keys');
  6775. var sharedKey$1 = function (key) {
  6776. return keys[key] || (keys[key] = uid(key));
  6777. };
  6778. var hiddenKeys$3 = {};
  6779. var NATIVE_WEAK_MAP = nativeWeakMap;
  6780. var global$4 = global$m;
  6781. var uncurryThis$4 = functionUncurryThis;
  6782. var isObject = isObject$5;
  6783. var createNonEnumerableProperty$2 = createNonEnumerableProperty$3;
  6784. var hasOwn$4 = hasOwnProperty_1;
  6785. var shared = sharedStore;
  6786. var sharedKey = sharedKey$1;
  6787. var hiddenKeys$2 = hiddenKeys$3;
  6788. var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
  6789. var TypeError$1 = global$4.TypeError;
  6790. var WeakMap = global$4.WeakMap;
  6791. var set$1, get, has;
  6792. var enforce = function (it) {
  6793. return has(it) ? get(it) : set$1(it, {});
  6794. };
  6795. var getterFor = function (TYPE) {
  6796. return function (it) {
  6797. var state;
  6798. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  6799. throw TypeError$1('Incompatible receiver, ' + TYPE + ' required');
  6800. } return state;
  6801. };
  6802. };
  6803. if (NATIVE_WEAK_MAP || shared.state) {
  6804. var store = shared.state || (shared.state = new WeakMap());
  6805. var wmget = uncurryThis$4(store.get);
  6806. var wmhas = uncurryThis$4(store.has);
  6807. var wmset = uncurryThis$4(store.set);
  6808. set$1 = function (it, metadata) {
  6809. if (wmhas(store, it)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
  6810. metadata.facade = it;
  6811. wmset(store, it, metadata);
  6812. return metadata;
  6813. };
  6814. get = function (it) {
  6815. return wmget(store, it) || {};
  6816. };
  6817. has = function (it) {
  6818. return wmhas(store, it);
  6819. };
  6820. } else {
  6821. var STATE = sharedKey('state');
  6822. hiddenKeys$2[STATE] = true;
  6823. set$1 = function (it, metadata) {
  6824. if (hasOwn$4(it, STATE)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
  6825. metadata.facade = it;
  6826. createNonEnumerableProperty$2(it, STATE, metadata);
  6827. return metadata;
  6828. };
  6829. get = function (it) {
  6830. return hasOwn$4(it, STATE) ? it[STATE] : {};
  6831. };
  6832. has = function (it) {
  6833. return hasOwn$4(it, STATE);
  6834. };
  6835. }
  6836. var internalState = {
  6837. set: set$1,
  6838. get: get,
  6839. has: has,
  6840. enforce: enforce,
  6841. getterFor: getterFor
  6842. };
  6843. var DESCRIPTORS = descriptors;
  6844. var hasOwn$3 = hasOwnProperty_1;
  6845. var FunctionPrototype = Function.prototype;
  6846. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  6847. var getDescriptor = DESCRIPTORS && Object.getOwnPropertyDescriptor;
  6848. var EXISTS = hasOwn$3(FunctionPrototype, 'name');
  6849. // additional protection from minified / mangled / dropped function names
  6850. var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something';
  6851. var CONFIGURABLE = EXISTS && (!DESCRIPTORS || (DESCRIPTORS && getDescriptor(FunctionPrototype, 'name').configurable));
  6852. var functionName = {
  6853. EXISTS: EXISTS,
  6854. PROPER: PROPER,
  6855. CONFIGURABLE: CONFIGURABLE
  6856. };
  6857. var global$3 = global$m;
  6858. var isCallable$2 = isCallable$a;
  6859. var hasOwn$2 = hasOwnProperty_1;
  6860. var createNonEnumerableProperty$1 = createNonEnumerableProperty$3;
  6861. var setGlobal$1 = setGlobal$3;
  6862. var inspectSource = inspectSource$2;
  6863. var InternalStateModule = internalState;
  6864. var CONFIGURABLE_FUNCTION_NAME = functionName.CONFIGURABLE;
  6865. var getInternalState = InternalStateModule.get;
  6866. var enforceInternalState = InternalStateModule.enforce;
  6867. var TEMPLATE = String(String).split('String');
  6868. (redefine$1.exports = function (O, key, value, options) {
  6869. var unsafe = options ? !!options.unsafe : false;
  6870. var simple = options ? !!options.enumerable : false;
  6871. var noTargetGet = options ? !!options.noTargetGet : false;
  6872. var name = options && options.name !== undefined ? options.name : key;
  6873. var state;
  6874. if (isCallable$2(value)) {
  6875. if (String(name).slice(0, 7) === 'Symbol(') {
  6876. name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']';
  6877. }
  6878. if (!hasOwn$2(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) {
  6879. createNonEnumerableProperty$1(value, 'name', name);
  6880. }
  6881. state = enforceInternalState(value);
  6882. if (!state.source) {
  6883. state.source = TEMPLATE.join(typeof name == 'string' ? name : '');
  6884. }
  6885. }
  6886. if (O === global$3) {
  6887. if (simple) O[key] = value;
  6888. else setGlobal$1(key, value);
  6889. return;
  6890. } else if (!unsafe) {
  6891. delete O[key];
  6892. } else if (!noTargetGet && O[key]) {
  6893. simple = true;
  6894. }
  6895. if (simple) O[key] = value;
  6896. else createNonEnumerableProperty$1(O, key, value);
  6897. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  6898. })(Function.prototype, 'toString', function toString() {
  6899. return isCallable$2(this) && getInternalState(this).source || inspectSource(this);
  6900. });
  6901. var objectGetOwnPropertyNames = {};
  6902. var ceil = Math.ceil;
  6903. var floor$1 = Math.floor;
  6904. // `ToIntegerOrInfinity` abstract operation
  6905. // https://tc39.es/ecma262/#sec-tointegerorinfinity
  6906. var toIntegerOrInfinity$2 = function (argument) {
  6907. var number = +argument;
  6908. // eslint-disable-next-line no-self-compare -- safe
  6909. return number !== number || number === 0 ? 0 : (number > 0 ? floor$1 : ceil)(number);
  6910. };
  6911. var toIntegerOrInfinity$1 = toIntegerOrInfinity$2;
  6912. var max = Math.max;
  6913. var min$1 = Math.min;
  6914. // Helper for a popular repeating case of the spec:
  6915. // Let integer be ? ToInteger(index).
  6916. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  6917. var toAbsoluteIndex$1 = function (index, length) {
  6918. var integer = toIntegerOrInfinity$1(index);
  6919. return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
  6920. };
  6921. var toIntegerOrInfinity = toIntegerOrInfinity$2;
  6922. var min = Math.min;
  6923. // `ToLength` abstract operation
  6924. // https://tc39.es/ecma262/#sec-tolength
  6925. var toLength$1 = function (argument) {
  6926. return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  6927. };
  6928. var toLength = toLength$1;
  6929. // `LengthOfArrayLike` abstract operation
  6930. // https://tc39.es/ecma262/#sec-lengthofarraylike
  6931. var lengthOfArrayLike$2 = function (obj) {
  6932. return toLength(obj.length);
  6933. };
  6934. var toIndexedObject$1 = toIndexedObject$3;
  6935. var toAbsoluteIndex = toAbsoluteIndex$1;
  6936. var lengthOfArrayLike$1 = lengthOfArrayLike$2;
  6937. // `Array.prototype.{ indexOf, includes }` methods implementation
  6938. var createMethod = function (IS_INCLUDES) {
  6939. return function ($this, el, fromIndex) {
  6940. var O = toIndexedObject$1($this);
  6941. var length = lengthOfArrayLike$1(O);
  6942. var index = toAbsoluteIndex(fromIndex, length);
  6943. var value;
  6944. // Array#includes uses SameValueZero equality algorithm
  6945. // eslint-disable-next-line no-self-compare -- NaN check
  6946. if (IS_INCLUDES && el != el) while (length > index) {
  6947. value = O[index++];
  6948. // eslint-disable-next-line no-self-compare -- NaN check
  6949. if (value != value) return true;
  6950. // Array#indexOf ignores holes, Array#includes - not
  6951. } else for (;length > index; index++) {
  6952. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  6953. } return !IS_INCLUDES && -1;
  6954. };
  6955. };
  6956. var arrayIncludes = {
  6957. // `Array.prototype.includes` method
  6958. // https://tc39.es/ecma262/#sec-array.prototype.includes
  6959. includes: createMethod(true),
  6960. // `Array.prototype.indexOf` method
  6961. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  6962. indexOf: createMethod(false)
  6963. };
  6964. var uncurryThis$3 = functionUncurryThis;
  6965. var hasOwn$1 = hasOwnProperty_1;
  6966. var toIndexedObject = toIndexedObject$3;
  6967. var indexOf = arrayIncludes.indexOf;
  6968. var hiddenKeys$1 = hiddenKeys$3;
  6969. var push$1 = uncurryThis$3([].push);
  6970. var objectKeysInternal = function (object, names) {
  6971. var O = toIndexedObject(object);
  6972. var i = 0;
  6973. var result = [];
  6974. var key;
  6975. for (key in O) !hasOwn$1(hiddenKeys$1, key) && hasOwn$1(O, key) && push$1(result, key);
  6976. // Don't enum bug & hidden keys
  6977. while (names.length > i) if (hasOwn$1(O, key = names[i++])) {
  6978. ~indexOf(result, key) || push$1(result, key);
  6979. }
  6980. return result;
  6981. };
  6982. // IE8- don't enum bug keys
  6983. var enumBugKeys$1 = [
  6984. 'constructor',
  6985. 'hasOwnProperty',
  6986. 'isPrototypeOf',
  6987. 'propertyIsEnumerable',
  6988. 'toLocaleString',
  6989. 'toString',
  6990. 'valueOf'
  6991. ];
  6992. var internalObjectKeys = objectKeysInternal;
  6993. var enumBugKeys = enumBugKeys$1;
  6994. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  6995. // `Object.getOwnPropertyNames` method
  6996. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  6997. // eslint-disable-next-line es/no-object-getownpropertynames -- safe
  6998. objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  6999. return internalObjectKeys(O, hiddenKeys);
  7000. };
  7001. var objectGetOwnPropertySymbols = {};
  7002. // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
  7003. objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols;
  7004. var getBuiltIn = getBuiltIn$3;
  7005. var uncurryThis$2 = functionUncurryThis;
  7006. var getOwnPropertyNamesModule = objectGetOwnPropertyNames;
  7007. var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols;
  7008. var anObject = anObject$2;
  7009. var concat = uncurryThis$2([].concat);
  7010. // all object keys, includes non-enumerable and symbols
  7011. var ownKeys$1 = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  7012. var keys = getOwnPropertyNamesModule.f(anObject(it));
  7013. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  7014. return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys;
  7015. };
  7016. var hasOwn = hasOwnProperty_1;
  7017. var ownKeys = ownKeys$1;
  7018. var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor;
  7019. var definePropertyModule = objectDefineProperty;
  7020. var copyConstructorProperties$1 = function (target, source) {
  7021. var keys = ownKeys(source);
  7022. var defineProperty = definePropertyModule.f;
  7023. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  7024. for (var i = 0; i < keys.length; i++) {
  7025. var key = keys[i];
  7026. if (!hasOwn(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  7027. }
  7028. };
  7029. var fails$2 = fails$7;
  7030. var isCallable$1 = isCallable$a;
  7031. var replacement = /#|\.prototype\./;
  7032. var isForced$1 = function (feature, detection) {
  7033. var value = data[normalize(feature)];
  7034. return value == POLYFILL ? true
  7035. : value == NATIVE ? false
  7036. : isCallable$1(detection) ? fails$2(detection)
  7037. : !!detection;
  7038. };
  7039. var normalize = isForced$1.normalize = function (string) {
  7040. return String(string).replace(replacement, '.').toLowerCase();
  7041. };
  7042. var data = isForced$1.data = {};
  7043. var NATIVE = isForced$1.NATIVE = 'N';
  7044. var POLYFILL = isForced$1.POLYFILL = 'P';
  7045. var isForced_1 = isForced$1;
  7046. var global$2 = global$m;
  7047. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  7048. var createNonEnumerableProperty = createNonEnumerableProperty$3;
  7049. var redefine = redefine$1.exports;
  7050. var setGlobal = setGlobal$3;
  7051. var copyConstructorProperties = copyConstructorProperties$1;
  7052. var isForced = isForced_1;
  7053. /*
  7054. options.target - name of the target object
  7055. options.global - target is the global object
  7056. options.stat - export as static methods of target
  7057. options.proto - export as prototype methods of target
  7058. options.real - real prototype method for the `pure` version
  7059. options.forced - export even if the native feature is available
  7060. options.bind - bind methods to the target, required for the `pure` version
  7061. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  7062. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  7063. options.sham - add a flag to not completely full polyfills
  7064. options.enumerable - export as enumerable property
  7065. options.noTargetGet - prevent calling a getter on target
  7066. options.name - the .name of the function if it does not match the key
  7067. */
  7068. var _export = function (options, source) {
  7069. var TARGET = options.target;
  7070. var GLOBAL = options.global;
  7071. var STATIC = options.stat;
  7072. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  7073. if (GLOBAL) {
  7074. target = global$2;
  7075. } else if (STATIC) {
  7076. target = global$2[TARGET] || setGlobal(TARGET, {});
  7077. } else {
  7078. target = (global$2[TARGET] || {}).prototype;
  7079. }
  7080. if (target) for (key in source) {
  7081. sourceProperty = source[key];
  7082. if (options.noTargetGet) {
  7083. descriptor = getOwnPropertyDescriptor(target, key);
  7084. targetProperty = descriptor && descriptor.value;
  7085. } else targetProperty = target[key];
  7086. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  7087. // contained in target
  7088. if (!FORCED && targetProperty !== undefined) {
  7089. if (typeof sourceProperty == typeof targetProperty) continue;
  7090. copyConstructorProperties(sourceProperty, targetProperty);
  7091. }
  7092. // add a flag to not completely full polyfills
  7093. if (options.sham || (targetProperty && targetProperty.sham)) {
  7094. createNonEnumerableProperty(sourceProperty, 'sham', true);
  7095. }
  7096. // extend global
  7097. redefine(target, key, sourceProperty, options);
  7098. }
  7099. };
  7100. var wellKnownSymbol$1 = wellKnownSymbol$3;
  7101. var TO_STRING_TAG$1 = wellKnownSymbol$1('toStringTag');
  7102. var test$1 = {};
  7103. test$1[TO_STRING_TAG$1] = 'z';
  7104. var toStringTagSupport = String(test$1) === '[object z]';
  7105. var global$1 = global$m;
  7106. var TO_STRING_TAG_SUPPORT = toStringTagSupport;
  7107. var isCallable = isCallable$a;
  7108. var classofRaw = classofRaw$1;
  7109. var wellKnownSymbol = wellKnownSymbol$3;
  7110. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  7111. var Object$1 = global$1.Object;
  7112. // ES3 wrong here
  7113. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments';
  7114. // fallback for IE11 Script Access Denied error
  7115. var tryGet = function (it, key) {
  7116. try {
  7117. return it[key];
  7118. } catch (error) { /* empty */ }
  7119. };
  7120. // getting tag from ES6+ `Object.prototype.toString`
  7121. var classof$1 = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) {
  7122. var O, tag, result;
  7123. return it === undefined ? 'Undefined' : it === null ? 'Null'
  7124. // @@toStringTag case
  7125. : typeof (tag = tryGet(O = Object$1(it), TO_STRING_TAG)) == 'string' ? tag
  7126. // builtinTag case
  7127. : CORRECT_ARGUMENTS ? classofRaw(O)
  7128. // ES3 arguments fallback
  7129. : (result = classofRaw(O)) == 'Object' && isCallable(O.callee) ? 'Arguments' : result;
  7130. };
  7131. var global = global$m;
  7132. var classof = classof$1;
  7133. var String$1 = global.String;
  7134. var toString$1 = function (argument) {
  7135. if (classof(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string');
  7136. return String$1(argument);
  7137. };
  7138. var uncurryThis$1 = functionUncurryThis;
  7139. var arraySlice$1 = uncurryThis$1([].slice);
  7140. var arraySlice = arraySlice$1;
  7141. var floor = Math.floor;
  7142. var mergeSort = function (array, comparefn) {
  7143. var length = array.length;
  7144. var middle = floor(length / 2);
  7145. return length < 8 ? insertionSort(array, comparefn) : merge(
  7146. array,
  7147. mergeSort(arraySlice(array, 0, middle), comparefn),
  7148. mergeSort(arraySlice(array, middle), comparefn),
  7149. comparefn
  7150. );
  7151. };
  7152. var insertionSort = function (array, comparefn) {
  7153. var length = array.length;
  7154. var i = 1;
  7155. var element, j;
  7156. while (i < length) {
  7157. j = i;
  7158. element = array[i];
  7159. while (j && comparefn(array[j - 1], element) > 0) {
  7160. array[j] = array[--j];
  7161. }
  7162. if (j !== i++) array[j] = element;
  7163. } return array;
  7164. };
  7165. var merge = function (array, left, right, comparefn) {
  7166. var llength = left.length;
  7167. var rlength = right.length;
  7168. var lindex = 0;
  7169. var rindex = 0;
  7170. while (lindex < llength || rindex < rlength) {
  7171. array[lindex + rindex] = (lindex < llength && rindex < rlength)
  7172. ? comparefn(left[lindex], right[rindex]) <= 0 ? left[lindex++] : right[rindex++]
  7173. : lindex < llength ? left[lindex++] : right[rindex++];
  7174. } return array;
  7175. };
  7176. var arraySort = mergeSort;
  7177. var fails$1 = fails$7;
  7178. var arrayMethodIsStrict$1 = function (METHOD_NAME, argument) {
  7179. var method = [][METHOD_NAME];
  7180. return !!method && fails$1(function () {
  7181. // eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing
  7182. method.call(null, argument || function () { throw 1; }, 1);
  7183. });
  7184. };
  7185. var userAgent$1 = engineUserAgent;
  7186. var firefox = userAgent$1.match(/firefox\/(\d+)/i);
  7187. var engineFfVersion = !!firefox && +firefox[1];
  7188. var UA = engineUserAgent;
  7189. var engineIsIeOrEdge = /MSIE|Trident/.test(UA);
  7190. var userAgent = engineUserAgent;
  7191. var webkit = userAgent.match(/AppleWebKit\/(\d+)\./);
  7192. var engineWebkitVersion = !!webkit && +webkit[1];
  7193. var $ = _export;
  7194. var uncurryThis = functionUncurryThis;
  7195. var aCallable = aCallable$2;
  7196. var toObject = toObject$2;
  7197. var lengthOfArrayLike = lengthOfArrayLike$2;
  7198. var toString = toString$1;
  7199. var fails = fails$7;
  7200. var internalSort = arraySort;
  7201. var arrayMethodIsStrict = arrayMethodIsStrict$1;
  7202. var FF = engineFfVersion;
  7203. var IE_OR_EDGE = engineIsIeOrEdge;
  7204. var V8 = engineV8Version;
  7205. var WEBKIT = engineWebkitVersion;
  7206. var test = [];
  7207. var un$Sort = uncurryThis(test.sort);
  7208. var push = uncurryThis(test.push);
  7209. // IE8-
  7210. var FAILS_ON_UNDEFINED = fails(function () {
  7211. test.sort(undefined);
  7212. });
  7213. // V8 bug
  7214. var FAILS_ON_NULL = fails(function () {
  7215. test.sort(null);
  7216. });
  7217. // Old WebKit
  7218. var STRICT_METHOD = arrayMethodIsStrict('sort');
  7219. var STABLE_SORT = !fails(function () {
  7220. // feature detection can be too slow, so check engines versions
  7221. if (V8) return V8 < 70;
  7222. if (FF && FF > 3) return;
  7223. if (IE_OR_EDGE) return true;
  7224. if (WEBKIT) return WEBKIT < 603;
  7225. var result = '';
  7226. var code, chr, value, index;
  7227. // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
  7228. for (code = 65; code < 76; code++) {
  7229. chr = String.fromCharCode(code);
  7230. switch (code) {
  7231. case 66: case 69: case 70: case 72: value = 3; break;
  7232. case 68: case 71: value = 4; break;
  7233. default: value = 2;
  7234. }
  7235. for (index = 0; index < 47; index++) {
  7236. test.push({ k: chr + index, v: value });
  7237. }
  7238. }
  7239. test.sort(function (a, b) { return b.v - a.v; });
  7240. for (index = 0; index < test.length; index++) {
  7241. chr = test[index].k.charAt(0);
  7242. if (result.charAt(result.length - 1) !== chr) result += chr;
  7243. }
  7244. return result !== 'DGBEFHACIJK';
  7245. });
  7246. var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
  7247. var getSortCompare = function (comparefn) {
  7248. return function (x, y) {
  7249. if (y === undefined) return -1;
  7250. if (x === undefined) return 1;
  7251. if (comparefn !== undefined) return +comparefn(x, y) || 0;
  7252. return toString(x) > toString(y) ? 1 : -1;
  7253. };
  7254. };
  7255. // `Array.prototype.sort` method
  7256. // https://tc39.es/ecma262/#sec-array.prototype.sort
  7257. $({ target: 'Array', proto: true, forced: FORCED }, {
  7258. sort: function sort(comparefn) {
  7259. if (comparefn !== undefined) aCallable(comparefn);
  7260. var array = toObject(this);
  7261. if (STABLE_SORT) return comparefn === undefined ? un$Sort(array) : un$Sort(array, comparefn);
  7262. var items = [];
  7263. var arrayLength = lengthOfArrayLike(array);
  7264. var itemsLength, index;
  7265. for (index = 0; index < arrayLength; index++) {
  7266. if (index in array) push(items, array[index]);
  7267. }
  7268. internalSort(items, getSortCompare(comparefn));
  7269. itemsLength = items.length;
  7270. index = 0;
  7271. while (index < itemsLength) array[index] = items[index++];
  7272. while (index < arrayLength) delete array[index++];
  7273. return array;
  7274. }
  7275. });
  7276. var Schema88e323a7 = {};
  7277. var warnings1000a372 = {};
  7278. var PlainValue$3 = PlainValueEc8e588e;
  7279. var resolveSeq$2 = resolveSeqD03cb037;
  7280. /* global atob, btoa, Buffer */
  7281. const binary = {
  7282. identify: value => value instanceof Uint8Array,
  7283. // Buffer inherits from Uint8Array
  7284. default: false,
  7285. tag: 'tag:yaml.org,2002:binary',
  7286. /**
  7287. * Returns a Buffer in node and an Uint8Array in browsers
  7288. *
  7289. * To use the resulting buffer as an image, you'll want to do something like:
  7290. *
  7291. * const blob = new Blob([buffer], { type: 'image/jpeg' })
  7292. * document.querySelector('#photo').src = URL.createObjectURL(blob)
  7293. */
  7294. resolve: (doc, node) => {
  7295. const src = resolveSeq$2.resolveString(doc, node);
  7296. if (typeof Buffer === 'function') {
  7297. return Buffer.from(src, 'base64');
  7298. } else if (typeof atob === 'function') {
  7299. // On IE 11, atob() can't handle newlines
  7300. const str = atob(src.replace(/[\n\r]/g, ''));
  7301. const buffer = new Uint8Array(str.length);
  7302. for (let i = 0; i < str.length; ++i) buffer[i] = str.charCodeAt(i);
  7303. return buffer;
  7304. } else {
  7305. const msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
  7306. doc.errors.push(new PlainValue$3.YAMLReferenceError(node, msg));
  7307. return null;
  7308. }
  7309. },
  7310. options: resolveSeq$2.binaryOptions,
  7311. stringify: ({
  7312. comment,
  7313. type,
  7314. value
  7315. }, ctx, onComment, onChompKeep) => {
  7316. let src;
  7317. if (typeof Buffer === 'function') {
  7318. src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
  7319. } else if (typeof btoa === 'function') {
  7320. let s = '';
  7321. for (let i = 0; i < value.length; ++i) s += String.fromCharCode(value[i]);
  7322. src = btoa(s);
  7323. } else {
  7324. throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
  7325. }
  7326. if (!type) type = resolveSeq$2.binaryOptions.defaultType;
  7327. if (type === PlainValue$3.Type.QUOTE_DOUBLE) {
  7328. value = src;
  7329. } else {
  7330. const {
  7331. lineWidth
  7332. } = resolveSeq$2.binaryOptions;
  7333. const n = Math.ceil(src.length / lineWidth);
  7334. const lines = new Array(n);
  7335. for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
  7336. lines[i] = src.substr(o, lineWidth);
  7337. }
  7338. value = lines.join(type === PlainValue$3.Type.BLOCK_LITERAL ? '\n' : ' ');
  7339. }
  7340. return resolveSeq$2.stringifyString({
  7341. comment,
  7342. type,
  7343. value
  7344. }, ctx, onComment, onChompKeep);
  7345. }
  7346. };
  7347. function parsePairs(doc, cst) {
  7348. const seq = resolveSeq$2.resolveSeq(doc, cst);
  7349. for (let i = 0; i < seq.items.length; ++i) {
  7350. let item = seq.items[i];
  7351. if (item instanceof resolveSeq$2.Pair) continue;else if (item instanceof resolveSeq$2.YAMLMap) {
  7352. if (item.items.length > 1) {
  7353. const msg = 'Each pair must have its own sequence indicator';
  7354. throw new PlainValue$3.YAMLSemanticError(cst, msg);
  7355. }
  7356. const pair = item.items[0] || new resolveSeq$2.Pair();
  7357. if (item.commentBefore) pair.commentBefore = pair.commentBefore ? `${item.commentBefore}\n${pair.commentBefore}` : item.commentBefore;
  7358. if (item.comment) pair.comment = pair.comment ? `${item.comment}\n${pair.comment}` : item.comment;
  7359. item = pair;
  7360. }
  7361. seq.items[i] = item instanceof resolveSeq$2.Pair ? item : new resolveSeq$2.Pair(item);
  7362. }
  7363. return seq;
  7364. }
  7365. function createPairs(schema, iterable, ctx) {
  7366. const pairs = new resolveSeq$2.YAMLSeq(schema);
  7367. pairs.tag = 'tag:yaml.org,2002:pairs';
  7368. for (const it of iterable) {
  7369. let key, value;
  7370. if (Array.isArray(it)) {
  7371. if (it.length === 2) {
  7372. key = it[0];
  7373. value = it[1];
  7374. } else throw new TypeError(`Expected [key, value] tuple: ${it}`);
  7375. } else if (it && it instanceof Object) {
  7376. const keys = Object.keys(it);
  7377. if (keys.length === 1) {
  7378. key = keys[0];
  7379. value = it[key];
  7380. } else throw new TypeError(`Expected { key: value } tuple: ${it}`);
  7381. } else {
  7382. key = it;
  7383. }
  7384. const pair = schema.createPair(key, value, ctx);
  7385. pairs.items.push(pair);
  7386. }
  7387. return pairs;
  7388. }
  7389. const pairs = {
  7390. default: false,
  7391. tag: 'tag:yaml.org,2002:pairs',
  7392. resolve: parsePairs,
  7393. createNode: createPairs
  7394. };
  7395. class YAMLOMap extends resolveSeq$2.YAMLSeq {
  7396. constructor() {
  7397. super();
  7398. PlainValue$3._defineProperty(this, "add", resolveSeq$2.YAMLMap.prototype.add.bind(this));
  7399. PlainValue$3._defineProperty(this, "delete", resolveSeq$2.YAMLMap.prototype.delete.bind(this));
  7400. PlainValue$3._defineProperty(this, "get", resolveSeq$2.YAMLMap.prototype.get.bind(this));
  7401. PlainValue$3._defineProperty(this, "has", resolveSeq$2.YAMLMap.prototype.has.bind(this));
  7402. PlainValue$3._defineProperty(this, "set", resolveSeq$2.YAMLMap.prototype.set.bind(this));
  7403. this.tag = YAMLOMap.tag;
  7404. }
  7405. toJSON(_, ctx) {
  7406. const map = new Map();
  7407. if (ctx && ctx.onCreate) ctx.onCreate(map);
  7408. for (const pair of this.items) {
  7409. let key, value;
  7410. if (pair instanceof resolveSeq$2.Pair) {
  7411. key = resolveSeq$2.toJSON(pair.key, '', ctx);
  7412. value = resolveSeq$2.toJSON(pair.value, key, ctx);
  7413. } else {
  7414. key = resolveSeq$2.toJSON(pair, '', ctx);
  7415. }
  7416. if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
  7417. map.set(key, value);
  7418. }
  7419. return map;
  7420. }
  7421. }
  7422. PlainValue$3._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
  7423. function parseOMap(doc, cst) {
  7424. const pairs = parsePairs(doc, cst);
  7425. const seenKeys = [];
  7426. for (const {
  7427. key
  7428. } of pairs.items) {
  7429. if (key instanceof resolveSeq$2.Scalar) {
  7430. if (seenKeys.includes(key.value)) {
  7431. const msg = 'Ordered maps must not include duplicate keys';
  7432. throw new PlainValue$3.YAMLSemanticError(cst, msg);
  7433. } else {
  7434. seenKeys.push(key.value);
  7435. }
  7436. }
  7437. }
  7438. return Object.assign(new YAMLOMap(), pairs);
  7439. }
  7440. function createOMap(schema, iterable, ctx) {
  7441. const pairs = createPairs(schema, iterable, ctx);
  7442. const omap = new YAMLOMap();
  7443. omap.items = pairs.items;
  7444. return omap;
  7445. }
  7446. const omap = {
  7447. identify: value => value instanceof Map,
  7448. nodeClass: YAMLOMap,
  7449. default: false,
  7450. tag: 'tag:yaml.org,2002:omap',
  7451. resolve: parseOMap,
  7452. createNode: createOMap
  7453. };
  7454. class YAMLSet extends resolveSeq$2.YAMLMap {
  7455. constructor() {
  7456. super();
  7457. this.tag = YAMLSet.tag;
  7458. }
  7459. add(key) {
  7460. const pair = key instanceof resolveSeq$2.Pair ? key : new resolveSeq$2.Pair(key);
  7461. const prev = resolveSeq$2.findPair(this.items, pair.key);
  7462. if (!prev) this.items.push(pair);
  7463. }
  7464. get(key, keepPair) {
  7465. const pair = resolveSeq$2.findPair(this.items, key);
  7466. return !keepPair && pair instanceof resolveSeq$2.Pair ? pair.key instanceof resolveSeq$2.Scalar ? pair.key.value : pair.key : pair;
  7467. }
  7468. set(key, value) {
  7469. if (typeof value !== 'boolean') throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
  7470. const prev = resolveSeq$2.findPair(this.items, key);
  7471. if (prev && !value) {
  7472. this.items.splice(this.items.indexOf(prev), 1);
  7473. } else if (!prev && value) {
  7474. this.items.push(new resolveSeq$2.Pair(key));
  7475. }
  7476. }
  7477. toJSON(_, ctx) {
  7478. return super.toJSON(_, ctx, Set);
  7479. }
  7480. toString(ctx, onComment, onChompKeep) {
  7481. if (!ctx) return JSON.stringify(this);
  7482. if (this.hasAllNullValues()) return super.toString(ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values');
  7483. }
  7484. }
  7485. PlainValue$3._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
  7486. function parseSet(doc, cst) {
  7487. const map = resolveSeq$2.resolveMap(doc, cst);
  7488. if (!map.hasAllNullValues()) throw new PlainValue$3.YAMLSemanticError(cst, 'Set items must all have null values');
  7489. return Object.assign(new YAMLSet(), map);
  7490. }
  7491. function createSet(schema, iterable, ctx) {
  7492. const set = new YAMLSet();
  7493. for (const value of iterable) set.items.push(schema.createPair(value, null, ctx));
  7494. return set;
  7495. }
  7496. const set = {
  7497. identify: value => value instanceof Set,
  7498. nodeClass: YAMLSet,
  7499. default: false,
  7500. tag: 'tag:yaml.org,2002:set',
  7501. resolve: parseSet,
  7502. createNode: createSet
  7503. };
  7504. const parseSexagesimal = (sign, parts) => {
  7505. const n = parts.split(':').reduce((n, p) => n * 60 + Number(p), 0);
  7506. return sign === '-' ? -n : n;
  7507. }; // hhhh:mm:ss.sss
  7508. const stringifySexagesimal = ({
  7509. value
  7510. }) => {
  7511. if (isNaN(value) || !isFinite(value)) return resolveSeq$2.stringifyNumber(value);
  7512. let sign = '';
  7513. if (value < 0) {
  7514. sign = '-';
  7515. value = Math.abs(value);
  7516. }
  7517. const parts = [value % 60]; // seconds, including ms
  7518. if (value < 60) {
  7519. parts.unshift(0); // at least one : is required
  7520. } else {
  7521. value = Math.round((value - parts[0]) / 60);
  7522. parts.unshift(value % 60); // minutes
  7523. if (value >= 60) {
  7524. value = Math.round((value - parts[0]) / 60);
  7525. parts.unshift(value); // hours
  7526. }
  7527. }
  7528. return sign + parts.map(n => n < 10 ? '0' + String(n) : String(n)).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
  7529. ;
  7530. };
  7531. const intTime = {
  7532. identify: value => typeof value === 'number',
  7533. default: true,
  7534. tag: 'tag:yaml.org,2002:int',
  7535. format: 'TIME',
  7536. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
  7537. resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
  7538. stringify: stringifySexagesimal
  7539. };
  7540. const floatTime = {
  7541. identify: value => typeof value === 'number',
  7542. default: true,
  7543. tag: 'tag:yaml.org,2002:float',
  7544. format: 'TIME',
  7545. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
  7546. resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
  7547. stringify: stringifySexagesimal
  7548. };
  7549. const timestamp = {
  7550. identify: value => value instanceof Date,
  7551. default: true,
  7552. tag: 'tag:yaml.org,2002:timestamp',
  7553. // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
  7554. // may be omitted altogether, resulting in a date format. In such a case, the time part is
  7555. // assumed to be 00:00:00Z (start of day, UTC).
  7556. test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
  7557. '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace
  7558. '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
  7559. '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
  7560. ')?' + ')$'),
  7561. resolve: (str, year, month, day, hour, minute, second, millisec, tz) => {
  7562. if (millisec) millisec = (millisec + '00').substr(1, 3);
  7563. let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
  7564. if (tz && tz !== 'Z') {
  7565. let d = parseSexagesimal(tz[0], tz.slice(1));
  7566. if (Math.abs(d) < 30) d *= 60;
  7567. date -= 60000 * d;
  7568. }
  7569. return new Date(date);
  7570. },
  7571. stringify: ({
  7572. value
  7573. }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
  7574. };
  7575. /* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
  7576. function shouldWarn(deprecation) {
  7577. const env = typeof process !== 'undefined' && process.env || {};
  7578. if (deprecation) {
  7579. if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS;
  7580. return !env.YAML_SILENCE_DEPRECATION_WARNINGS;
  7581. }
  7582. if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS;
  7583. return !env.YAML_SILENCE_WARNINGS;
  7584. }
  7585. function warn(warning, type) {
  7586. if (shouldWarn(false)) {
  7587. const emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to
  7588. // https://github.com/facebook/jest/issues/2549
  7589. if (emit) emit(warning, type);else {
  7590. // eslint-disable-next-line no-console
  7591. console.warn(type ? `${type}: ${warning}` : warning);
  7592. }
  7593. }
  7594. }
  7595. function warnFileDeprecation(filename) {
  7596. if (shouldWarn(true)) {
  7597. const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
  7598. warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, 'DeprecationWarning');
  7599. }
  7600. }
  7601. const warned = {};
  7602. function warnOptionDeprecation(name, alternative) {
  7603. if (!warned[name] && shouldWarn(true)) {
  7604. warned[name] = true;
  7605. let msg = `The option '${name}' will be removed in a future release`;
  7606. msg += alternative ? `, use '${alternative}' instead.` : '.';
  7607. warn(msg, 'DeprecationWarning');
  7608. }
  7609. }
  7610. warnings1000a372.binary = binary;
  7611. warnings1000a372.floatTime = floatTime;
  7612. warnings1000a372.intTime = intTime;
  7613. warnings1000a372.omap = omap;
  7614. warnings1000a372.pairs = pairs;
  7615. warnings1000a372.set = set;
  7616. warnings1000a372.timestamp = timestamp;
  7617. warnings1000a372.warn = warn;
  7618. warnings1000a372.warnFileDeprecation = warnFileDeprecation;
  7619. warnings1000a372.warnOptionDeprecation = warnOptionDeprecation;
  7620. var PlainValue$2 = PlainValueEc8e588e;
  7621. var resolveSeq$1 = resolveSeqD03cb037;
  7622. var warnings$1 = warnings1000a372;
  7623. function createMap(schema, obj, ctx) {
  7624. const map = new resolveSeq$1.YAMLMap(schema);
  7625. if (obj instanceof Map) {
  7626. for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
  7627. } else if (obj && typeof obj === 'object') {
  7628. for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
  7629. }
  7630. if (typeof schema.sortMapEntries === 'function') {
  7631. map.items.sort(schema.sortMapEntries);
  7632. }
  7633. return map;
  7634. }
  7635. const map = {
  7636. createNode: createMap,
  7637. default: true,
  7638. nodeClass: resolveSeq$1.YAMLMap,
  7639. tag: 'tag:yaml.org,2002:map',
  7640. resolve: resolveSeq$1.resolveMap
  7641. };
  7642. function createSeq(schema, obj, ctx) {
  7643. const seq = new resolveSeq$1.YAMLSeq(schema);
  7644. if (obj && obj[Symbol.iterator]) {
  7645. for (const it of obj) {
  7646. const v = schema.createNode(it, ctx.wrapScalars, null, ctx);
  7647. seq.items.push(v);
  7648. }
  7649. }
  7650. return seq;
  7651. }
  7652. const seq = {
  7653. createNode: createSeq,
  7654. default: true,
  7655. nodeClass: resolveSeq$1.YAMLSeq,
  7656. tag: 'tag:yaml.org,2002:seq',
  7657. resolve: resolveSeq$1.resolveSeq
  7658. };
  7659. const string = {
  7660. identify: value => typeof value === 'string',
  7661. default: true,
  7662. tag: 'tag:yaml.org,2002:str',
  7663. resolve: resolveSeq$1.resolveString,
  7664. stringify(item, ctx, onComment, onChompKeep) {
  7665. ctx = Object.assign({
  7666. actualString: true
  7667. }, ctx);
  7668. return resolveSeq$1.stringifyString(item, ctx, onComment, onChompKeep);
  7669. },
  7670. options: resolveSeq$1.strOptions
  7671. };
  7672. const failsafe = [map, seq, string];
  7673. /* global BigInt */
  7674. const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value);
  7675. const intResolve$1 = (src, part, radix) => resolveSeq$1.intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
  7676. function intStringify$1(node, radix, prefix) {
  7677. const {
  7678. value
  7679. } = node;
  7680. if (intIdentify$2(value) && value >= 0) return prefix + value.toString(radix);
  7681. return resolveSeq$1.stringifyNumber(node);
  7682. }
  7683. const nullObj = {
  7684. identify: value => value == null,
  7685. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq$1.Scalar(null) : null,
  7686. default: true,
  7687. tag: 'tag:yaml.org,2002:null',
  7688. test: /^(?:~|[Nn]ull|NULL)?$/,
  7689. resolve: () => null,
  7690. options: resolveSeq$1.nullOptions,
  7691. stringify: () => resolveSeq$1.nullOptions.nullStr
  7692. };
  7693. const boolObj = {
  7694. identify: value => typeof value === 'boolean',
  7695. default: true,
  7696. tag: 'tag:yaml.org,2002:bool',
  7697. test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
  7698. resolve: str => str[0] === 't' || str[0] === 'T',
  7699. options: resolveSeq$1.boolOptions,
  7700. stringify: ({
  7701. value
  7702. }) => value ? resolveSeq$1.boolOptions.trueStr : resolveSeq$1.boolOptions.falseStr
  7703. };
  7704. const octObj = {
  7705. identify: value => intIdentify$2(value) && value >= 0,
  7706. default: true,
  7707. tag: 'tag:yaml.org,2002:int',
  7708. format: 'OCT',
  7709. test: /^0o([0-7]+)$/,
  7710. resolve: (str, oct) => intResolve$1(str, oct, 8),
  7711. options: resolveSeq$1.intOptions,
  7712. stringify: node => intStringify$1(node, 8, '0o')
  7713. };
  7714. const intObj = {
  7715. identify: intIdentify$2,
  7716. default: true,
  7717. tag: 'tag:yaml.org,2002:int',
  7718. test: /^[-+]?[0-9]+$/,
  7719. resolve: str => intResolve$1(str, str, 10),
  7720. options: resolveSeq$1.intOptions,
  7721. stringify: resolveSeq$1.stringifyNumber
  7722. };
  7723. const hexObj = {
  7724. identify: value => intIdentify$2(value) && value >= 0,
  7725. default: true,
  7726. tag: 'tag:yaml.org,2002:int',
  7727. format: 'HEX',
  7728. test: /^0x([0-9a-fA-F]+)$/,
  7729. resolve: (str, hex) => intResolve$1(str, hex, 16),
  7730. options: resolveSeq$1.intOptions,
  7731. stringify: node => intStringify$1(node, 16, '0x')
  7732. };
  7733. const nanObj = {
  7734. identify: value => typeof value === 'number',
  7735. default: true,
  7736. tag: 'tag:yaml.org,2002:float',
  7737. test: /^(?:[-+]?\.inf|(\.nan))$/i,
  7738. resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
  7739. stringify: resolveSeq$1.stringifyNumber
  7740. };
  7741. const expObj = {
  7742. identify: value => typeof value === 'number',
  7743. default: true,
  7744. tag: 'tag:yaml.org,2002:float',
  7745. format: 'EXP',
  7746. test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
  7747. resolve: str => parseFloat(str),
  7748. stringify: ({
  7749. value
  7750. }) => Number(value).toExponential()
  7751. };
  7752. const floatObj = {
  7753. identify: value => typeof value === 'number',
  7754. default: true,
  7755. tag: 'tag:yaml.org,2002:float',
  7756. test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
  7757. resolve(str, frac1, frac2) {
  7758. const frac = frac1 || frac2;
  7759. const node = new resolveSeq$1.Scalar(parseFloat(str));
  7760. if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
  7761. return node;
  7762. },
  7763. stringify: resolveSeq$1.stringifyNumber
  7764. };
  7765. const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
  7766. /* global BigInt */
  7767. const intIdentify$1 = value => typeof value === 'bigint' || Number.isInteger(value);
  7768. const stringifyJSON = ({
  7769. value
  7770. }) => JSON.stringify(value);
  7771. const json = [map, seq, {
  7772. identify: value => typeof value === 'string',
  7773. default: true,
  7774. tag: 'tag:yaml.org,2002:str',
  7775. resolve: resolveSeq$1.resolveString,
  7776. stringify: stringifyJSON
  7777. }, {
  7778. identify: value => value == null,
  7779. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq$1.Scalar(null) : null,
  7780. default: true,
  7781. tag: 'tag:yaml.org,2002:null',
  7782. test: /^null$/,
  7783. resolve: () => null,
  7784. stringify: stringifyJSON
  7785. }, {
  7786. identify: value => typeof value === 'boolean',
  7787. default: true,
  7788. tag: 'tag:yaml.org,2002:bool',
  7789. test: /^true|false$/,
  7790. resolve: str => str === 'true',
  7791. stringify: stringifyJSON
  7792. }, {
  7793. identify: intIdentify$1,
  7794. default: true,
  7795. tag: 'tag:yaml.org,2002:int',
  7796. test: /^-?(?:0|[1-9][0-9]*)$/,
  7797. resolve: str => resolveSeq$1.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
  7798. stringify: ({
  7799. value
  7800. }) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
  7801. }, {
  7802. identify: value => typeof value === 'number',
  7803. default: true,
  7804. tag: 'tag:yaml.org,2002:float',
  7805. test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
  7806. resolve: str => parseFloat(str),
  7807. stringify: stringifyJSON
  7808. }];
  7809. json.scalarFallback = str => {
  7810. throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`);
  7811. };
  7812. /* global BigInt */
  7813. const boolStringify = ({
  7814. value
  7815. }) => value ? resolveSeq$1.boolOptions.trueStr : resolveSeq$1.boolOptions.falseStr;
  7816. const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
  7817. function intResolve(sign, src, radix) {
  7818. let str = src.replace(/_/g, '');
  7819. if (resolveSeq$1.intOptions.asBigInt) {
  7820. switch (radix) {
  7821. case 2:
  7822. str = `0b${str}`;
  7823. break;
  7824. case 8:
  7825. str = `0o${str}`;
  7826. break;
  7827. case 16:
  7828. str = `0x${str}`;
  7829. break;
  7830. }
  7831. const n = BigInt(str);
  7832. return sign === '-' ? BigInt(-1) * n : n;
  7833. }
  7834. const n = parseInt(str, radix);
  7835. return sign === '-' ? -1 * n : n;
  7836. }
  7837. function intStringify(node, radix, prefix) {
  7838. const {
  7839. value
  7840. } = node;
  7841. if (intIdentify(value)) {
  7842. const str = value.toString(radix);
  7843. return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
  7844. }
  7845. return resolveSeq$1.stringifyNumber(node);
  7846. }
  7847. const yaml11 = failsafe.concat([{
  7848. identify: value => value == null,
  7849. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq$1.Scalar(null) : null,
  7850. default: true,
  7851. tag: 'tag:yaml.org,2002:null',
  7852. test: /^(?:~|[Nn]ull|NULL)?$/,
  7853. resolve: () => null,
  7854. options: resolveSeq$1.nullOptions,
  7855. stringify: () => resolveSeq$1.nullOptions.nullStr
  7856. }, {
  7857. identify: value => typeof value === 'boolean',
  7858. default: true,
  7859. tag: 'tag:yaml.org,2002:bool',
  7860. test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
  7861. resolve: () => true,
  7862. options: resolveSeq$1.boolOptions,
  7863. stringify: boolStringify
  7864. }, {
  7865. identify: value => typeof value === 'boolean',
  7866. default: true,
  7867. tag: 'tag:yaml.org,2002:bool',
  7868. test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
  7869. resolve: () => false,
  7870. options: resolveSeq$1.boolOptions,
  7871. stringify: boolStringify
  7872. }, {
  7873. identify: intIdentify,
  7874. default: true,
  7875. tag: 'tag:yaml.org,2002:int',
  7876. format: 'BIN',
  7877. test: /^([-+]?)0b([0-1_]+)$/,
  7878. resolve: (str, sign, bin) => intResolve(sign, bin, 2),
  7879. stringify: node => intStringify(node, 2, '0b')
  7880. }, {
  7881. identify: intIdentify,
  7882. default: true,
  7883. tag: 'tag:yaml.org,2002:int',
  7884. format: 'OCT',
  7885. test: /^([-+]?)0([0-7_]+)$/,
  7886. resolve: (str, sign, oct) => intResolve(sign, oct, 8),
  7887. stringify: node => intStringify(node, 8, '0')
  7888. }, {
  7889. identify: intIdentify,
  7890. default: true,
  7891. tag: 'tag:yaml.org,2002:int',
  7892. test: /^([-+]?)([0-9][0-9_]*)$/,
  7893. resolve: (str, sign, abs) => intResolve(sign, abs, 10),
  7894. stringify: resolveSeq$1.stringifyNumber
  7895. }, {
  7896. identify: intIdentify,
  7897. default: true,
  7898. tag: 'tag:yaml.org,2002:int',
  7899. format: 'HEX',
  7900. test: /^([-+]?)0x([0-9a-fA-F_]+)$/,
  7901. resolve: (str, sign, hex) => intResolve(sign, hex, 16),
  7902. stringify: node => intStringify(node, 16, '0x')
  7903. }, {
  7904. identify: value => typeof value === 'number',
  7905. default: true,
  7906. tag: 'tag:yaml.org,2002:float',
  7907. test: /^(?:[-+]?\.inf|(\.nan))$/i,
  7908. resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
  7909. stringify: resolveSeq$1.stringifyNumber
  7910. }, {
  7911. identify: value => typeof value === 'number',
  7912. default: true,
  7913. tag: 'tag:yaml.org,2002:float',
  7914. format: 'EXP',
  7915. test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
  7916. resolve: str => parseFloat(str.replace(/_/g, '')),
  7917. stringify: ({
  7918. value
  7919. }) => Number(value).toExponential()
  7920. }, {
  7921. identify: value => typeof value === 'number',
  7922. default: true,
  7923. tag: 'tag:yaml.org,2002:float',
  7924. test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
  7925. resolve(str, frac) {
  7926. const node = new resolveSeq$1.Scalar(parseFloat(str.replace(/_/g, '')));
  7927. if (frac) {
  7928. const f = frac.replace(/_/g, '');
  7929. if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
  7930. }
  7931. return node;
  7932. },
  7933. stringify: resolveSeq$1.stringifyNumber
  7934. }], warnings$1.binary, warnings$1.omap, warnings$1.pairs, warnings$1.set, warnings$1.intTime, warnings$1.floatTime, warnings$1.timestamp);
  7935. const schemas = {
  7936. core,
  7937. failsafe,
  7938. json,
  7939. yaml11
  7940. };
  7941. const tags = {
  7942. binary: warnings$1.binary,
  7943. bool: boolObj,
  7944. float: floatObj,
  7945. floatExp: expObj,
  7946. floatNaN: nanObj,
  7947. floatTime: warnings$1.floatTime,
  7948. int: intObj,
  7949. intHex: hexObj,
  7950. intOct: octObj,
  7951. intTime: warnings$1.intTime,
  7952. map,
  7953. null: nullObj,
  7954. omap: warnings$1.omap,
  7955. pairs: warnings$1.pairs,
  7956. seq,
  7957. set: warnings$1.set,
  7958. timestamp: warnings$1.timestamp
  7959. };
  7960. function findTagObject(value, tagName, tags) {
  7961. if (tagName) {
  7962. const match = tags.filter(t => t.tag === tagName);
  7963. const tagObj = match.find(t => !t.format) || match[0];
  7964. if (!tagObj) throw new Error(`Tag ${tagName} not found`);
  7965. return tagObj;
  7966. } // TODO: deprecate/remove class check
  7967. return tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
  7968. }
  7969. function createNode$1(value, tagName, ctx) {
  7970. if (value instanceof resolveSeq$1.Node) return value;
  7971. const {
  7972. defaultPrefix,
  7973. onTagObj,
  7974. prevObjects,
  7975. schema,
  7976. wrapScalars
  7977. } = ctx;
  7978. if (tagName && tagName.startsWith('!!')) tagName = defaultPrefix + tagName.slice(2);
  7979. let tagObj = findTagObject(value, tagName, schema.tags);
  7980. if (!tagObj) {
  7981. if (typeof value.toJSON === 'function') value = value.toJSON();
  7982. if (!value || typeof value !== 'object') return wrapScalars ? new resolveSeq$1.Scalar(value) : value;
  7983. tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map;
  7984. }
  7985. if (onTagObj) {
  7986. onTagObj(tagObj);
  7987. delete ctx.onTagObj;
  7988. } // Detect duplicate references to the same object & use Alias nodes for all
  7989. // after first. The `obj` wrapper allows for circular references to resolve.
  7990. const obj = {
  7991. value: undefined,
  7992. node: undefined
  7993. };
  7994. if (value && typeof value === 'object' && prevObjects) {
  7995. const prev = prevObjects.get(value);
  7996. if (prev) {
  7997. const alias = new resolveSeq$1.Alias(prev); // leaves source dirty; must be cleaned by caller
  7998. ctx.aliasNodes.push(alias); // defined along with prevObjects
  7999. return alias;
  8000. }
  8001. obj.value = value;
  8002. prevObjects.set(value, obj);
  8003. }
  8004. obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new resolveSeq$1.Scalar(value) : value;
  8005. if (tagName && obj.node instanceof resolveSeq$1.Node) obj.node.tag = tagName;
  8006. return obj.node;
  8007. }
  8008. function getSchemaTags(schemas, knownTags, customTags, schemaId) {
  8009. let tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
  8010. if (!tags) {
  8011. const keys = Object.keys(schemas).map(key => JSON.stringify(key)).join(', ');
  8012. throw new Error(`Unknown schema "${schemaId}"; use one of ${keys}`);
  8013. }
  8014. if (Array.isArray(customTags)) {
  8015. for (const tag of customTags) tags = tags.concat(tag);
  8016. } else if (typeof customTags === 'function') {
  8017. tags = customTags(tags.slice());
  8018. }
  8019. for (let i = 0; i < tags.length; ++i) {
  8020. const tag = tags[i];
  8021. if (typeof tag === 'string') {
  8022. const tagObj = knownTags[tag];
  8023. if (!tagObj) {
  8024. const keys = Object.keys(knownTags).map(key => JSON.stringify(key)).join(', ');
  8025. throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
  8026. }
  8027. tags[i] = tagObj;
  8028. }
  8029. }
  8030. return tags;
  8031. }
  8032. const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
  8033. class Schema$2 {
  8034. // TODO: remove in v2
  8035. // TODO: remove in v2
  8036. constructor({
  8037. customTags,
  8038. merge,
  8039. schema,
  8040. sortMapEntries,
  8041. tags: deprecatedCustomTags
  8042. }) {
  8043. this.merge = !!merge;
  8044. this.name = schema;
  8045. this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
  8046. if (!customTags && deprecatedCustomTags) warnings$1.warnOptionDeprecation('tags', 'customTags');
  8047. this.tags = getSchemaTags(schemas, tags, customTags || deprecatedCustomTags, schema);
  8048. }
  8049. createNode(value, wrapScalars, tagName, ctx) {
  8050. const baseCtx = {
  8051. defaultPrefix: Schema$2.defaultPrefix,
  8052. schema: this,
  8053. wrapScalars
  8054. };
  8055. const createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx;
  8056. return createNode$1(value, tagName, createCtx);
  8057. }
  8058. createPair(key, value, ctx) {
  8059. if (!ctx) ctx = {
  8060. wrapScalars: true
  8061. };
  8062. const k = this.createNode(key, ctx.wrapScalars, null, ctx);
  8063. const v = this.createNode(value, ctx.wrapScalars, null, ctx);
  8064. return new resolveSeq$1.Pair(k, v);
  8065. }
  8066. }
  8067. PlainValue$2._defineProperty(Schema$2, "defaultPrefix", PlainValue$2.defaultTagPrefix);
  8068. PlainValue$2._defineProperty(Schema$2, "defaultTags", PlainValue$2.defaultTags);
  8069. Schema88e323a7.Schema = Schema$2;
  8070. var PlainValue$1 = PlainValueEc8e588e;
  8071. var resolveSeq = resolveSeqD03cb037;
  8072. var Schema$1 = Schema88e323a7;
  8073. const defaultOptions = {
  8074. anchorPrefix: 'a',
  8075. customTags: null,
  8076. indent: 2,
  8077. indentSeq: true,
  8078. keepCstNodes: false,
  8079. keepNodeTypes: true,
  8080. keepBlobsInJSON: true,
  8081. mapAsMap: false,
  8082. maxAliasCount: 100,
  8083. prettyErrors: false,
  8084. // TODO Set true in v2
  8085. simpleKeys: false,
  8086. version: '1.2'
  8087. };
  8088. const scalarOptions = {
  8089. get binary() {
  8090. return resolveSeq.binaryOptions;
  8091. },
  8092. set binary(opt) {
  8093. Object.assign(resolveSeq.binaryOptions, opt);
  8094. },
  8095. get bool() {
  8096. return resolveSeq.boolOptions;
  8097. },
  8098. set bool(opt) {
  8099. Object.assign(resolveSeq.boolOptions, opt);
  8100. },
  8101. get int() {
  8102. return resolveSeq.intOptions;
  8103. },
  8104. set int(opt) {
  8105. Object.assign(resolveSeq.intOptions, opt);
  8106. },
  8107. get null() {
  8108. return resolveSeq.nullOptions;
  8109. },
  8110. set null(opt) {
  8111. Object.assign(resolveSeq.nullOptions, opt);
  8112. },
  8113. get str() {
  8114. return resolveSeq.strOptions;
  8115. },
  8116. set str(opt) {
  8117. Object.assign(resolveSeq.strOptions, opt);
  8118. }
  8119. };
  8120. const documentOptions = {
  8121. '1.0': {
  8122. schema: 'yaml-1.1',
  8123. merge: true,
  8124. tagPrefixes: [{
  8125. handle: '!',
  8126. prefix: PlainValue$1.defaultTagPrefix
  8127. }, {
  8128. handle: '!!',
  8129. prefix: 'tag:private.yaml.org,2002:'
  8130. }]
  8131. },
  8132. 1.1: {
  8133. schema: 'yaml-1.1',
  8134. merge: true,
  8135. tagPrefixes: [{
  8136. handle: '!',
  8137. prefix: '!'
  8138. }, {
  8139. handle: '!!',
  8140. prefix: PlainValue$1.defaultTagPrefix
  8141. }]
  8142. },
  8143. 1.2: {
  8144. schema: 'core',
  8145. merge: false,
  8146. tagPrefixes: [{
  8147. handle: '!',
  8148. prefix: '!'
  8149. }, {
  8150. handle: '!!',
  8151. prefix: PlainValue$1.defaultTagPrefix
  8152. }]
  8153. }
  8154. };
  8155. function stringifyTag(doc, tag) {
  8156. if ((doc.version || doc.options.version) === '1.0') {
  8157. const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
  8158. if (priv) return '!' + priv[1];
  8159. const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
  8160. return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`;
  8161. }
  8162. let p = doc.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0);
  8163. if (!p) {
  8164. const dtp = doc.getDefaults().tagPrefixes;
  8165. p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0);
  8166. }
  8167. if (!p) return tag[0] === '!' ? tag : `!<${tag}>`;
  8168. const suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, ch => ({
  8169. '!': '%21',
  8170. ',': '%2C',
  8171. '[': '%5B',
  8172. ']': '%5D',
  8173. '{': '%7B',
  8174. '}': '%7D'
  8175. })[ch]);
  8176. return p.handle + suffix;
  8177. }
  8178. function getTagObject(tags, item) {
  8179. if (item instanceof resolveSeq.Alias) return resolveSeq.Alias;
  8180. if (item.tag) {
  8181. const match = tags.filter(t => t.tag === item.tag);
  8182. if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
  8183. }
  8184. let tagObj, obj;
  8185. if (item instanceof resolveSeq.Scalar) {
  8186. obj = item.value; // TODO: deprecate/remove class check
  8187. const match = tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
  8188. tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
  8189. } else {
  8190. obj = item;
  8191. tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
  8192. }
  8193. if (!tagObj) {
  8194. const name = obj && obj.constructor ? obj.constructor.name : typeof obj;
  8195. throw new Error(`Tag not resolved for ${name} value`);
  8196. }
  8197. return tagObj;
  8198. } // needs to be called before value stringifier to allow for circular anchor refs
  8199. function stringifyProps(node, tagObj, {
  8200. anchors,
  8201. doc
  8202. }) {
  8203. const props = [];
  8204. const anchor = doc.anchors.getName(node);
  8205. if (anchor) {
  8206. anchors[anchor] = node;
  8207. props.push(`&${anchor}`);
  8208. }
  8209. if (node.tag) {
  8210. props.push(stringifyTag(doc, node.tag));
  8211. } else if (!tagObj.default) {
  8212. props.push(stringifyTag(doc, tagObj.tag));
  8213. }
  8214. return props.join(' ');
  8215. }
  8216. function stringify$1(item, ctx, onComment, onChompKeep) {
  8217. const {
  8218. anchors,
  8219. schema
  8220. } = ctx.doc;
  8221. let tagObj;
  8222. if (!(item instanceof resolveSeq.Node)) {
  8223. const createCtx = {
  8224. aliasNodes: [],
  8225. onTagObj: o => tagObj = o,
  8226. prevObjects: new Map()
  8227. };
  8228. item = schema.createNode(item, true, null, createCtx);
  8229. for (const alias of createCtx.aliasNodes) {
  8230. alias.source = alias.source.node;
  8231. let name = anchors.getName(alias.source);
  8232. if (!name) {
  8233. name = anchors.newName();
  8234. anchors.map[name] = alias.source;
  8235. }
  8236. }
  8237. }
  8238. if (item instanceof resolveSeq.Pair) return item.toString(ctx, onComment, onChompKeep);
  8239. if (!tagObj) tagObj = getTagObject(schema.tags, item);
  8240. const props = stringifyProps(item, tagObj, ctx);
  8241. if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
  8242. const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof resolveSeq.Scalar ? resolveSeq.stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep);
  8243. if (!props) return str;
  8244. return item instanceof resolveSeq.Scalar || str[0] === '{' || str[0] === '[' ? `${props} ${str}` : `${props}\n${ctx.indent}${str}`;
  8245. }
  8246. class Anchors {
  8247. static validAnchorNode(node) {
  8248. return node instanceof resolveSeq.Scalar || node instanceof resolveSeq.YAMLSeq || node instanceof resolveSeq.YAMLMap;
  8249. }
  8250. constructor(prefix) {
  8251. PlainValue$1._defineProperty(this, "map", Object.create(null));
  8252. this.prefix = prefix;
  8253. }
  8254. createAlias(node, name) {
  8255. this.setAnchor(node, name);
  8256. return new resolveSeq.Alias(node);
  8257. }
  8258. createMergePair(...sources) {
  8259. const merge = new resolveSeq.Merge();
  8260. merge.value.items = sources.map(s => {
  8261. if (s instanceof resolveSeq.Alias) {
  8262. if (s.source instanceof resolveSeq.YAMLMap) return s;
  8263. } else if (s instanceof resolveSeq.YAMLMap) {
  8264. return this.createAlias(s);
  8265. }
  8266. throw new Error('Merge sources must be Map nodes or their Aliases');
  8267. });
  8268. return merge;
  8269. }
  8270. getName(node) {
  8271. const {
  8272. map
  8273. } = this;
  8274. return Object.keys(map).find(a => map[a] === node);
  8275. }
  8276. getNames() {
  8277. return Object.keys(this.map);
  8278. }
  8279. getNode(name) {
  8280. return this.map[name];
  8281. }
  8282. newName(prefix) {
  8283. if (!prefix) prefix = this.prefix;
  8284. const names = Object.keys(this.map);
  8285. for (let i = 1; true; ++i) {
  8286. const name = `${prefix}${i}`;
  8287. if (!names.includes(name)) return name;
  8288. }
  8289. } // During parsing, map & aliases contain CST nodes
  8290. resolveNodes() {
  8291. const {
  8292. map,
  8293. _cstAliases
  8294. } = this;
  8295. Object.keys(map).forEach(a => {
  8296. map[a] = map[a].resolved;
  8297. });
  8298. _cstAliases.forEach(a => {
  8299. a.source = a.source.resolved;
  8300. });
  8301. delete this._cstAliases;
  8302. }
  8303. setAnchor(node, name) {
  8304. if (node != null && !Anchors.validAnchorNode(node)) {
  8305. throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
  8306. }
  8307. if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
  8308. throw new Error('Anchor names must not contain whitespace or control characters');
  8309. }
  8310. const {
  8311. map
  8312. } = this;
  8313. const prev = node && Object.keys(map).find(a => map[a] === node);
  8314. if (prev) {
  8315. if (!name) {
  8316. return prev;
  8317. } else if (prev !== name) {
  8318. delete map[prev];
  8319. map[name] = node;
  8320. }
  8321. } else {
  8322. if (!name) {
  8323. if (!node) return null;
  8324. name = this.newName();
  8325. }
  8326. map[name] = node;
  8327. }
  8328. return name;
  8329. }
  8330. }
  8331. const visit = (node, tags) => {
  8332. if (node && typeof node === 'object') {
  8333. const {
  8334. tag
  8335. } = node;
  8336. if (node instanceof resolveSeq.Collection) {
  8337. if (tag) tags[tag] = true;
  8338. node.items.forEach(n => visit(n, tags));
  8339. } else if (node instanceof resolveSeq.Pair) {
  8340. visit(node.key, tags);
  8341. visit(node.value, tags);
  8342. } else if (node instanceof resolveSeq.Scalar) {
  8343. if (tag) tags[tag] = true;
  8344. }
  8345. }
  8346. return tags;
  8347. };
  8348. const listTagNames = node => Object.keys(visit(node, {}));
  8349. function parseContents(doc, contents) {
  8350. const comments = {
  8351. before: [],
  8352. after: []
  8353. };
  8354. let body = undefined;
  8355. let spaceBefore = false;
  8356. for (const node of contents) {
  8357. if (node.valueRange) {
  8358. if (body !== undefined) {
  8359. const msg = 'Document contains trailing content not separated by a ... or --- line';
  8360. doc.errors.push(new PlainValue$1.YAMLSyntaxError(node, msg));
  8361. break;
  8362. }
  8363. const res = resolveSeq.resolveNode(doc, node);
  8364. if (spaceBefore) {
  8365. res.spaceBefore = true;
  8366. spaceBefore = false;
  8367. }
  8368. body = res;
  8369. } else if (node.comment !== null) {
  8370. const cc = body === undefined ? comments.before : comments.after;
  8371. cc.push(node.comment);
  8372. } else if (node.type === PlainValue$1.Type.BLANK_LINE) {
  8373. spaceBefore = true;
  8374. if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
  8375. // space-separated comments at start are parsed as document comments
  8376. doc.commentBefore = comments.before.join('\n');
  8377. comments.before = [];
  8378. }
  8379. }
  8380. }
  8381. doc.contents = body || null;
  8382. if (!body) {
  8383. doc.comment = comments.before.concat(comments.after).join('\n') || null;
  8384. } else {
  8385. const cb = comments.before.join('\n');
  8386. if (cb) {
  8387. const cbNode = body instanceof resolveSeq.Collection && body.items[0] ? body.items[0] : body;
  8388. cbNode.commentBefore = cbNode.commentBefore ? `${cb}\n${cbNode.commentBefore}` : cb;
  8389. }
  8390. doc.comment = comments.after.join('\n') || null;
  8391. }
  8392. }
  8393. function resolveTagDirective({
  8394. tagPrefixes
  8395. }, directive) {
  8396. const [handle, prefix] = directive.parameters;
  8397. if (!handle || !prefix) {
  8398. const msg = 'Insufficient parameters given for %TAG directive';
  8399. throw new PlainValue$1.YAMLSemanticError(directive, msg);
  8400. }
  8401. if (tagPrefixes.some(p => p.handle === handle)) {
  8402. const msg = 'The %TAG directive must only be given at most once per handle in the same document.';
  8403. throw new PlainValue$1.YAMLSemanticError(directive, msg);
  8404. }
  8405. return {
  8406. handle,
  8407. prefix
  8408. };
  8409. }
  8410. function resolveYamlDirective(doc, directive) {
  8411. let [version] = directive.parameters;
  8412. if (directive.name === 'YAML:1.0') version = '1.0';
  8413. if (!version) {
  8414. const msg = 'Insufficient parameters given for %YAML directive';
  8415. throw new PlainValue$1.YAMLSemanticError(directive, msg);
  8416. }
  8417. if (!documentOptions[version]) {
  8418. const v0 = doc.version || doc.options.version;
  8419. const msg = `Document will be parsed as YAML ${v0} rather than YAML ${version}`;
  8420. doc.warnings.push(new PlainValue$1.YAMLWarning(directive, msg));
  8421. }
  8422. return version;
  8423. }
  8424. function parseDirectives(doc, directives, prevDoc) {
  8425. const directiveComments = [];
  8426. let hasDirectives = false;
  8427. for (const directive of directives) {
  8428. const {
  8429. comment,
  8430. name
  8431. } = directive;
  8432. switch (name) {
  8433. case 'TAG':
  8434. try {
  8435. doc.tagPrefixes.push(resolveTagDirective(doc, directive));
  8436. } catch (error) {
  8437. doc.errors.push(error);
  8438. }
  8439. hasDirectives = true;
  8440. break;
  8441. case 'YAML':
  8442. case 'YAML:1.0':
  8443. if (doc.version) {
  8444. const msg = 'The %YAML directive must only be given at most once per document.';
  8445. doc.errors.push(new PlainValue$1.YAMLSemanticError(directive, msg));
  8446. }
  8447. try {
  8448. doc.version = resolveYamlDirective(doc, directive);
  8449. } catch (error) {
  8450. doc.errors.push(error);
  8451. }
  8452. hasDirectives = true;
  8453. break;
  8454. default:
  8455. if (name) {
  8456. const msg = `YAML only supports %TAG and %YAML directives, and not %${name}`;
  8457. doc.warnings.push(new PlainValue$1.YAMLWarning(directive, msg));
  8458. }
  8459. }
  8460. if (comment) directiveComments.push(comment);
  8461. }
  8462. if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) {
  8463. const copyTagPrefix = ({
  8464. handle,
  8465. prefix
  8466. }) => ({
  8467. handle,
  8468. prefix
  8469. });
  8470. doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
  8471. doc.version = prevDoc.version;
  8472. }
  8473. doc.commentBefore = directiveComments.join('\n') || null;
  8474. }
  8475. function assertCollection(contents) {
  8476. if (contents instanceof resolveSeq.Collection) return true;
  8477. throw new Error('Expected a YAML collection as document contents');
  8478. }
  8479. class Document$2 {
  8480. constructor(options) {
  8481. this.anchors = new Anchors(options.anchorPrefix);
  8482. this.commentBefore = null;
  8483. this.comment = null;
  8484. this.contents = null;
  8485. this.directivesEndMarker = null;
  8486. this.errors = [];
  8487. this.options = options;
  8488. this.schema = null;
  8489. this.tagPrefixes = [];
  8490. this.version = null;
  8491. this.warnings = [];
  8492. }
  8493. add(value) {
  8494. assertCollection(this.contents);
  8495. return this.contents.add(value);
  8496. }
  8497. addIn(path, value) {
  8498. assertCollection(this.contents);
  8499. this.contents.addIn(path, value);
  8500. }
  8501. delete(key) {
  8502. assertCollection(this.contents);
  8503. return this.contents.delete(key);
  8504. }
  8505. deleteIn(path) {
  8506. if (resolveSeq.isEmptyPath(path)) {
  8507. if (this.contents == null) return false;
  8508. this.contents = null;
  8509. return true;
  8510. }
  8511. assertCollection(this.contents);
  8512. return this.contents.deleteIn(path);
  8513. }
  8514. getDefaults() {
  8515. return Document$2.defaults[this.version] || Document$2.defaults[this.options.version] || {};
  8516. }
  8517. get(key, keepScalar) {
  8518. return this.contents instanceof resolveSeq.Collection ? this.contents.get(key, keepScalar) : undefined;
  8519. }
  8520. getIn(path, keepScalar) {
  8521. if (resolveSeq.isEmptyPath(path)) return !keepScalar && this.contents instanceof resolveSeq.Scalar ? this.contents.value : this.contents;
  8522. return this.contents instanceof resolveSeq.Collection ? this.contents.getIn(path, keepScalar) : undefined;
  8523. }
  8524. has(key) {
  8525. return this.contents instanceof resolveSeq.Collection ? this.contents.has(key) : false;
  8526. }
  8527. hasIn(path) {
  8528. if (resolveSeq.isEmptyPath(path)) return this.contents !== undefined;
  8529. return this.contents instanceof resolveSeq.Collection ? this.contents.hasIn(path) : false;
  8530. }
  8531. set(key, value) {
  8532. assertCollection(this.contents);
  8533. this.contents.set(key, value);
  8534. }
  8535. setIn(path, value) {
  8536. if (resolveSeq.isEmptyPath(path)) this.contents = value;else {
  8537. assertCollection(this.contents);
  8538. this.contents.setIn(path, value);
  8539. }
  8540. }
  8541. setSchema(id, customTags) {
  8542. if (!id && !customTags && this.schema) return;
  8543. if (typeof id === 'number') id = id.toFixed(1);
  8544. if (id === '1.0' || id === '1.1' || id === '1.2') {
  8545. if (this.version) this.version = id;else this.options.version = id;
  8546. delete this.options.schema;
  8547. } else if (id && typeof id === 'string') {
  8548. this.options.schema = id;
  8549. }
  8550. if (Array.isArray(customTags)) this.options.customTags = customTags;
  8551. const opt = Object.assign({}, this.getDefaults(), this.options);
  8552. this.schema = new Schema$1.Schema(opt);
  8553. }
  8554. parse(node, prevDoc) {
  8555. if (this.options.keepCstNodes) this.cstNode = node;
  8556. if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
  8557. const {
  8558. directives = [],
  8559. contents = [],
  8560. directivesEndMarker,
  8561. error,
  8562. valueRange
  8563. } = node;
  8564. if (error) {
  8565. if (!error.source) error.source = this;
  8566. this.errors.push(error);
  8567. }
  8568. parseDirectives(this, directives, prevDoc);
  8569. if (directivesEndMarker) this.directivesEndMarker = true;
  8570. this.range = valueRange ? [valueRange.start, valueRange.end] : null;
  8571. this.setSchema();
  8572. this.anchors._cstAliases = [];
  8573. parseContents(this, contents);
  8574. this.anchors.resolveNodes();
  8575. if (this.options.prettyErrors) {
  8576. for (const error of this.errors) if (error instanceof PlainValue$1.YAMLError) error.makePretty();
  8577. for (const warn of this.warnings) if (warn instanceof PlainValue$1.YAMLError) warn.makePretty();
  8578. }
  8579. return this;
  8580. }
  8581. listNonDefaultTags() {
  8582. return listTagNames(this.contents).filter(t => t.indexOf(Schema$1.Schema.defaultPrefix) !== 0);
  8583. }
  8584. setTagPrefix(handle, prefix) {
  8585. if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
  8586. if (prefix) {
  8587. const prev = this.tagPrefixes.find(p => p.handle === handle);
  8588. if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
  8589. handle,
  8590. prefix
  8591. });
  8592. } else {
  8593. this.tagPrefixes = this.tagPrefixes.filter(p => p.handle !== handle);
  8594. }
  8595. }
  8596. toJSON(arg, onAnchor) {
  8597. const {
  8598. keepBlobsInJSON,
  8599. mapAsMap,
  8600. maxAliasCount
  8601. } = this.options;
  8602. const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof resolveSeq.Scalar));
  8603. const ctx = {
  8604. doc: this,
  8605. indentStep: ' ',
  8606. keep,
  8607. mapAsMap: keep && !!mapAsMap,
  8608. maxAliasCount,
  8609. stringify: stringify$1 // Requiring directly in Pair would create circular dependencies
  8610. };
  8611. const anchorNames = Object.keys(this.anchors.map);
  8612. if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(name => [this.anchors.map[name], {
  8613. alias: [],
  8614. aliasCount: 0,
  8615. count: 1
  8616. }]));
  8617. const res = resolveSeq.toJSON(this.contents, arg, ctx);
  8618. if (typeof onAnchor === 'function' && ctx.anchors) for (const {
  8619. count,
  8620. res
  8621. } of ctx.anchors.values()) onAnchor(res, count);
  8622. return res;
  8623. }
  8624. toString() {
  8625. if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
  8626. const indentSize = this.options.indent;
  8627. if (!Number.isInteger(indentSize) || indentSize <= 0) {
  8628. const s = JSON.stringify(indentSize);
  8629. throw new Error(`"indent" option must be a positive integer, not ${s}`);
  8630. }
  8631. this.setSchema();
  8632. const lines = [];
  8633. let hasDirectives = false;
  8634. if (this.version) {
  8635. let vd = '%YAML 1.2';
  8636. if (this.schema.name === 'yaml-1.1') {
  8637. if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
  8638. }
  8639. lines.push(vd);
  8640. hasDirectives = true;
  8641. }
  8642. const tagNames = this.listNonDefaultTags();
  8643. this.tagPrefixes.forEach(({
  8644. handle,
  8645. prefix
  8646. }) => {
  8647. if (tagNames.some(t => t.indexOf(prefix) === 0)) {
  8648. lines.push(`%TAG ${handle} ${prefix}`);
  8649. hasDirectives = true;
  8650. }
  8651. });
  8652. if (hasDirectives || this.directivesEndMarker) lines.push('---');
  8653. if (this.commentBefore) {
  8654. if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
  8655. lines.unshift(this.commentBefore.replace(/^/gm, '#'));
  8656. }
  8657. const ctx = {
  8658. anchors: Object.create(null),
  8659. doc: this,
  8660. indent: '',
  8661. indentStep: ' '.repeat(indentSize),
  8662. stringify: stringify$1 // Requiring directly in nodes would create circular dependencies
  8663. };
  8664. let chompKeep = false;
  8665. let contentComment = null;
  8666. if (this.contents) {
  8667. if (this.contents instanceof resolveSeq.Node) {
  8668. if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
  8669. if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
  8670. ctx.forceBlockIndent = !!this.comment;
  8671. contentComment = this.contents.comment;
  8672. }
  8673. const onChompKeep = contentComment ? null : () => chompKeep = true;
  8674. const body = stringify$1(this.contents, ctx, () => contentComment = null, onChompKeep);
  8675. lines.push(resolveSeq.addComment(body, '', contentComment));
  8676. } else if (this.contents !== undefined) {
  8677. lines.push(stringify$1(this.contents, ctx));
  8678. }
  8679. if (this.comment) {
  8680. if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
  8681. lines.push(this.comment.replace(/^/gm, '#'));
  8682. }
  8683. return lines.join('\n') + '\n';
  8684. }
  8685. }
  8686. PlainValue$1._defineProperty(Document$2, "defaults", documentOptions);
  8687. Document9b4560a1.Document = Document$2;
  8688. Document9b4560a1.defaultOptions = defaultOptions;
  8689. Document9b4560a1.scalarOptions = scalarOptions;
  8690. var parseCst = parseCst$1;
  8691. var Document$1 = Document9b4560a1;
  8692. var Schema = Schema88e323a7;
  8693. var PlainValue = PlainValueEc8e588e;
  8694. var warnings = warnings1000a372;
  8695. function createNode(value, wrapScalars = true, tag) {
  8696. if (tag === undefined && typeof wrapScalars === 'string') {
  8697. tag = wrapScalars;
  8698. wrapScalars = true;
  8699. }
  8700. const options = Object.assign({}, Document$1.Document.defaults[Document$1.defaultOptions.version], Document$1.defaultOptions);
  8701. const schema = new Schema.Schema(options);
  8702. return schema.createNode(value, wrapScalars, tag);
  8703. }
  8704. class Document extends Document$1.Document {
  8705. constructor(options) {
  8706. super(Object.assign({}, Document$1.defaultOptions, options));
  8707. }
  8708. }
  8709. function parseAllDocuments(src, options) {
  8710. const stream = [];
  8711. let prev;
  8712. for (const cstDoc of parseCst.parse(src)) {
  8713. const doc = new Document(options);
  8714. doc.parse(cstDoc, prev);
  8715. stream.push(doc);
  8716. prev = doc;
  8717. }
  8718. return stream;
  8719. }
  8720. function parseDocument(src, options) {
  8721. const cst = parseCst.parse(src);
  8722. const doc = new Document(options).parse(cst[0]);
  8723. if (cst.length > 1) {
  8724. const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
  8725. doc.errors.unshift(new PlainValue.YAMLSemanticError(cst[1], errMsg));
  8726. }
  8727. return doc;
  8728. }
  8729. function parse(src, options) {
  8730. const doc = parseDocument(src, options);
  8731. doc.warnings.forEach(warning => warnings.warn(warning));
  8732. if (doc.errors.length > 0) throw doc.errors[0];
  8733. return doc.toJSON();
  8734. }
  8735. function stringify(value, options) {
  8736. const doc = new Document(options);
  8737. doc.contents = value;
  8738. return String(doc);
  8739. }
  8740. const YAML = {
  8741. createNode,
  8742. defaultOptions: Document$1.defaultOptions,
  8743. Document,
  8744. parse,
  8745. parseAllDocuments,
  8746. parseCST: parseCst.parse,
  8747. parseDocument,
  8748. scalarOptions: Document$1.scalarOptions,
  8749. stringify
  8750. };
  8751. dist.YAML = YAML;
  8752. var yaml$1 = dist.YAML;
  8753. Object.defineProperty(loaders$1, "__esModule", {
  8754. value: true
  8755. });
  8756. loaders$1.loaders = void 0;
  8757. /* eslint-disable @typescript-eslint/no-require-imports */
  8758. let importFresh;
  8759. const loadJs = function loadJs(filepath) {
  8760. if (importFresh === undefined) {
  8761. importFresh = importFresh$1;
  8762. }
  8763. const result = importFresh(filepath);
  8764. return result;
  8765. };
  8766. let parseJson;
  8767. const loadJson = function loadJson(filepath, content) {
  8768. if (parseJson === undefined) {
  8769. parseJson = parseJson_1;
  8770. }
  8771. try {
  8772. const result = parseJson(content);
  8773. return result;
  8774. } catch (error) {
  8775. error.message = `JSON Error in ${filepath}:\n${error.message}`;
  8776. throw error;
  8777. }
  8778. };
  8779. let yaml;
  8780. const loadYaml = function loadYaml(filepath, content) {
  8781. if (yaml === undefined) {
  8782. yaml = yaml$1;
  8783. }
  8784. try {
  8785. const result = yaml.parse(content, {
  8786. prettyErrors: true
  8787. });
  8788. return result;
  8789. } catch (error) {
  8790. error.message = `YAML Error in ${filepath}:\n${error.message}`;
  8791. throw error;
  8792. }
  8793. };
  8794. const loaders = {
  8795. loadJs,
  8796. loadJson,
  8797. loadYaml
  8798. };
  8799. loaders$1.loaders = loaders;
  8800. var getPropertyByPath$1 = {};
  8801. Object.defineProperty(getPropertyByPath$1, "__esModule", {
  8802. value: true
  8803. });
  8804. getPropertyByPath$1.getPropertyByPath = getPropertyByPath; // Resolves property names or property paths defined with period-delimited
  8805. // strings or arrays of strings. Property names that are found on the source
  8806. // object are used directly (even if they include a period).
  8807. // Nested property names that include periods, within a path, are only
  8808. // understood in array paths.
  8809. function getPropertyByPath(source, path) {
  8810. if (typeof path === 'string' && Object.prototype.hasOwnProperty.call(source, path)) {
  8811. return source[path];
  8812. }
  8813. const parsedPath = typeof path === 'string' ? path.split('.') : path; // eslint-disable-next-line @typescript-eslint/no-explicit-any
  8814. return parsedPath.reduce((previous, key) => {
  8815. if (previous === undefined) {
  8816. return previous;
  8817. }
  8818. return previous[key];
  8819. }, source);
  8820. }
  8821. Object.defineProperty(ExplorerBase$1, "__esModule", {
  8822. value: true
  8823. });
  8824. ExplorerBase$1.getExtensionDescription = getExtensionDescription;
  8825. ExplorerBase$1.ExplorerBase = void 0;
  8826. var _path$3 = _interopRequireDefault$5(require$$0__default["default"]);
  8827. var _loaders$1 = loaders$1;
  8828. var _getPropertyByPath = getPropertyByPath$1;
  8829. function _interopRequireDefault$5(obj) {
  8830. return obj && obj.__esModule ? obj : {
  8831. default: obj
  8832. };
  8833. }
  8834. class ExplorerBase {
  8835. constructor(options) {
  8836. if (options.cache === true) {
  8837. this.loadCache = new Map();
  8838. this.searchCache = new Map();
  8839. }
  8840. this.config = options;
  8841. this.validateConfig();
  8842. }
  8843. clearLoadCache() {
  8844. if (this.loadCache) {
  8845. this.loadCache.clear();
  8846. }
  8847. }
  8848. clearSearchCache() {
  8849. if (this.searchCache) {
  8850. this.searchCache.clear();
  8851. }
  8852. }
  8853. clearCaches() {
  8854. this.clearLoadCache();
  8855. this.clearSearchCache();
  8856. }
  8857. validateConfig() {
  8858. const config = this.config;
  8859. config.searchPlaces.forEach(place => {
  8860. const loaderKey = _path$3.default.extname(place) || 'noExt';
  8861. const loader = config.loaders[loaderKey];
  8862. if (!loader) {
  8863. throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
  8864. }
  8865. if (typeof loader !== 'function') {
  8866. throw new Error(`loader for ${getExtensionDescription(place)} is not a function (type provided: "${typeof loader}"), so searchPlaces item "${place}" is invalid`);
  8867. }
  8868. });
  8869. }
  8870. shouldSearchStopWithResult(result) {
  8871. if (result === null) return false;
  8872. if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
  8873. return true;
  8874. }
  8875. nextDirectoryToSearch(currentDir, currentResult) {
  8876. if (this.shouldSearchStopWithResult(currentResult)) {
  8877. return null;
  8878. }
  8879. const nextDir = nextDirUp(currentDir);
  8880. if (nextDir === currentDir || currentDir === this.config.stopDir) {
  8881. return null;
  8882. }
  8883. return nextDir;
  8884. }
  8885. loadPackageProp(filepath, content) {
  8886. const parsedContent = _loaders$1.loaders.loadJson(filepath, content);
  8887. const packagePropValue = (0, _getPropertyByPath.getPropertyByPath)(parsedContent, this.config.packageProp);
  8888. return packagePropValue || null;
  8889. }
  8890. getLoaderEntryForFile(filepath) {
  8891. if (_path$3.default.basename(filepath) === 'package.json') {
  8892. const loader = this.loadPackageProp.bind(this);
  8893. return loader;
  8894. }
  8895. const loaderKey = _path$3.default.extname(filepath) || 'noExt';
  8896. const loader = this.config.loaders[loaderKey];
  8897. if (!loader) {
  8898. throw new Error(`No loader specified for ${getExtensionDescription(filepath)}`);
  8899. }
  8900. return loader;
  8901. }
  8902. loadedContentToCosmiconfigResult(filepath, loadedContent) {
  8903. if (loadedContent === null) {
  8904. return null;
  8905. }
  8906. if (loadedContent === undefined) {
  8907. return {
  8908. filepath,
  8909. config: undefined,
  8910. isEmpty: true
  8911. };
  8912. }
  8913. return {
  8914. config: loadedContent,
  8915. filepath
  8916. };
  8917. }
  8918. validateFilePath(filepath) {
  8919. if (!filepath) {
  8920. throw new Error('load must pass a non-empty string');
  8921. }
  8922. }
  8923. }
  8924. ExplorerBase$1.ExplorerBase = ExplorerBase;
  8925. function nextDirUp(dir) {
  8926. return _path$3.default.dirname(dir);
  8927. }
  8928. function getExtensionDescription(filepath) {
  8929. const ext = _path$3.default.extname(filepath);
  8930. return ext ? `extension "${ext}"` : 'files without extensions';
  8931. }
  8932. var readFile$1 = {};
  8933. Object.defineProperty(readFile$1, "__esModule", {
  8934. value: true
  8935. });
  8936. readFile$1.readFile = readFile;
  8937. readFile$1.readFileSync = readFileSync;
  8938. var _fs = _interopRequireDefault$4(require$$1__default["default"]);
  8939. function _interopRequireDefault$4(obj) {
  8940. return obj && obj.__esModule ? obj : {
  8941. default: obj
  8942. };
  8943. }
  8944. async function fsReadFileAsync(pathname, encoding) {
  8945. return new Promise((resolve, reject) => {
  8946. _fs.default.readFile(pathname, encoding, (error, contents) => {
  8947. if (error) {
  8948. reject(error);
  8949. return;
  8950. }
  8951. resolve(contents);
  8952. });
  8953. });
  8954. }
  8955. async function readFile(filepath, options = {}) {
  8956. const throwNotFound = options.throwNotFound === true;
  8957. try {
  8958. const content = await fsReadFileAsync(filepath, 'utf8');
  8959. return content;
  8960. } catch (error) {
  8961. if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
  8962. return null;
  8963. }
  8964. throw error;
  8965. }
  8966. }
  8967. function readFileSync(filepath, options = {}) {
  8968. const throwNotFound = options.throwNotFound === true;
  8969. try {
  8970. const content = _fs.default.readFileSync(filepath, 'utf8');
  8971. return content;
  8972. } catch (error) {
  8973. if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
  8974. return null;
  8975. }
  8976. throw error;
  8977. }
  8978. }
  8979. var cacheWrapper$1 = {};
  8980. Object.defineProperty(cacheWrapper$1, "__esModule", {
  8981. value: true
  8982. });
  8983. cacheWrapper$1.cacheWrapper = cacheWrapper;
  8984. cacheWrapper$1.cacheWrapperSync = cacheWrapperSync;
  8985. async function cacheWrapper(cache, key, fn) {
  8986. const cached = cache.get(key);
  8987. if (cached !== undefined) {
  8988. return cached;
  8989. }
  8990. const result = await fn();
  8991. cache.set(key, result);
  8992. return result;
  8993. }
  8994. function cacheWrapperSync(cache, key, fn) {
  8995. const cached = cache.get(key);
  8996. if (cached !== undefined) {
  8997. return cached;
  8998. }
  8999. const result = fn();
  9000. cache.set(key, result);
  9001. return result;
  9002. }
  9003. var getDirectory$1 = {};
  9004. var pathType = {};
  9005. const {
  9006. promisify
  9007. } = require$$0__default$1["default"];
  9008. const fs = require$$1__default["default"];
  9009. async function isType(fsStatType, statsMethodName, filePath) {
  9010. if (typeof filePath !== 'string') {
  9011. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  9012. }
  9013. try {
  9014. const stats = await promisify(fs[fsStatType])(filePath);
  9015. return stats[statsMethodName]();
  9016. } catch (error) {
  9017. if (error.code === 'ENOENT') {
  9018. return false;
  9019. }
  9020. throw error;
  9021. }
  9022. }
  9023. function isTypeSync(fsStatType, statsMethodName, filePath) {
  9024. if (typeof filePath !== 'string') {
  9025. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  9026. }
  9027. try {
  9028. return fs[fsStatType](filePath)[statsMethodName]();
  9029. } catch (error) {
  9030. if (error.code === 'ENOENT') {
  9031. return false;
  9032. }
  9033. throw error;
  9034. }
  9035. }
  9036. pathType.isFile = isType.bind(null, 'stat', 'isFile');
  9037. pathType.isDirectory = isType.bind(null, 'stat', 'isDirectory');
  9038. pathType.isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink');
  9039. pathType.isFileSync = isTypeSync.bind(null, 'statSync', 'isFile');
  9040. pathType.isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory');
  9041. pathType.isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink');
  9042. Object.defineProperty(getDirectory$1, "__esModule", {
  9043. value: true
  9044. });
  9045. getDirectory$1.getDirectory = getDirectory;
  9046. getDirectory$1.getDirectorySync = getDirectorySync;
  9047. var _path$2 = _interopRequireDefault$3(require$$0__default["default"]);
  9048. var _pathType = pathType;
  9049. function _interopRequireDefault$3(obj) {
  9050. return obj && obj.__esModule ? obj : {
  9051. default: obj
  9052. };
  9053. }
  9054. async function getDirectory(filepath) {
  9055. const filePathIsDirectory = await (0, _pathType.isDirectory)(filepath);
  9056. if (filePathIsDirectory === true) {
  9057. return filepath;
  9058. }
  9059. const directory = _path$2.default.dirname(filepath);
  9060. return directory;
  9061. }
  9062. function getDirectorySync(filepath) {
  9063. const filePathIsDirectory = (0, _pathType.isDirectorySync)(filepath);
  9064. if (filePathIsDirectory === true) {
  9065. return filepath;
  9066. }
  9067. const directory = _path$2.default.dirname(filepath);
  9068. return directory;
  9069. }
  9070. Object.defineProperty(Explorer$1, "__esModule", {
  9071. value: true
  9072. });
  9073. Explorer$1.Explorer = void 0;
  9074. var _path$1 = _interopRequireDefault$2(require$$0__default["default"]);
  9075. var _ExplorerBase$1 = ExplorerBase$1;
  9076. var _readFile$1 = readFile$1;
  9077. var _cacheWrapper$1 = cacheWrapper$1;
  9078. var _getDirectory$1 = getDirectory$1;
  9079. function _interopRequireDefault$2(obj) {
  9080. return obj && obj.__esModule ? obj : {
  9081. default: obj
  9082. };
  9083. }
  9084. class Explorer extends _ExplorerBase$1.ExplorerBase {
  9085. constructor(options) {
  9086. super(options);
  9087. }
  9088. async search(searchFrom = process.cwd()) {
  9089. const startDirectory = await (0, _getDirectory$1.getDirectory)(searchFrom);
  9090. const result = await this.searchFromDirectory(startDirectory);
  9091. return result;
  9092. }
  9093. async searchFromDirectory(dir) {
  9094. const absoluteDir = _path$1.default.resolve(process.cwd(), dir);
  9095. const run = async () => {
  9096. const result = await this.searchDirectory(absoluteDir);
  9097. const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
  9098. if (nextDir) {
  9099. return this.searchFromDirectory(nextDir);
  9100. }
  9101. const transformResult = await this.config.transform(result);
  9102. return transformResult;
  9103. };
  9104. if (this.searchCache) {
  9105. return (0, _cacheWrapper$1.cacheWrapper)(this.searchCache, absoluteDir, run);
  9106. }
  9107. return run();
  9108. }
  9109. async searchDirectory(dir) {
  9110. for await (const place of this.config.searchPlaces) {
  9111. const placeResult = await this.loadSearchPlace(dir, place);
  9112. if (this.shouldSearchStopWithResult(placeResult) === true) {
  9113. return placeResult;
  9114. }
  9115. } // config not found
  9116. return null;
  9117. }
  9118. async loadSearchPlace(dir, place) {
  9119. const filepath = _path$1.default.join(dir, place);
  9120. const fileContents = await (0, _readFile$1.readFile)(filepath);
  9121. const result = await this.createCosmiconfigResult(filepath, fileContents);
  9122. return result;
  9123. }
  9124. async loadFileContent(filepath, content) {
  9125. if (content === null) {
  9126. return null;
  9127. }
  9128. if (content.trim() === '') {
  9129. return undefined;
  9130. }
  9131. const loader = this.getLoaderEntryForFile(filepath);
  9132. const loaderResult = await loader(filepath, content);
  9133. return loaderResult;
  9134. }
  9135. async createCosmiconfigResult(filepath, content) {
  9136. const fileContent = await this.loadFileContent(filepath, content);
  9137. const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
  9138. return result;
  9139. }
  9140. async load(filepath) {
  9141. this.validateFilePath(filepath);
  9142. const absoluteFilePath = _path$1.default.resolve(process.cwd(), filepath);
  9143. const runLoad = async () => {
  9144. const fileContents = await (0, _readFile$1.readFile)(absoluteFilePath, {
  9145. throwNotFound: true
  9146. });
  9147. const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents);
  9148. const transformResult = await this.config.transform(result);
  9149. return transformResult;
  9150. };
  9151. if (this.loadCache) {
  9152. return (0, _cacheWrapper$1.cacheWrapper)(this.loadCache, absoluteFilePath, runLoad);
  9153. }
  9154. return runLoad();
  9155. }
  9156. }
  9157. Explorer$1.Explorer = Explorer;
  9158. var ExplorerSync$1 = {};
  9159. Object.defineProperty(ExplorerSync$1, "__esModule", {
  9160. value: true
  9161. });
  9162. ExplorerSync$1.ExplorerSync = void 0;
  9163. var _path = _interopRequireDefault$1(require$$0__default["default"]);
  9164. var _ExplorerBase = ExplorerBase$1;
  9165. var _readFile = readFile$1;
  9166. var _cacheWrapper = cacheWrapper$1;
  9167. var _getDirectory = getDirectory$1;
  9168. function _interopRequireDefault$1(obj) {
  9169. return obj && obj.__esModule ? obj : {
  9170. default: obj
  9171. };
  9172. }
  9173. class ExplorerSync extends _ExplorerBase.ExplorerBase {
  9174. constructor(options) {
  9175. super(options);
  9176. }
  9177. searchSync(searchFrom = process.cwd()) {
  9178. const startDirectory = (0, _getDirectory.getDirectorySync)(searchFrom);
  9179. const result = this.searchFromDirectorySync(startDirectory);
  9180. return result;
  9181. }
  9182. searchFromDirectorySync(dir) {
  9183. const absoluteDir = _path.default.resolve(process.cwd(), dir);
  9184. const run = () => {
  9185. const result = this.searchDirectorySync(absoluteDir);
  9186. const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
  9187. if (nextDir) {
  9188. return this.searchFromDirectorySync(nextDir);
  9189. }
  9190. const transformResult = this.config.transform(result);
  9191. return transformResult;
  9192. };
  9193. if (this.searchCache) {
  9194. return (0, _cacheWrapper.cacheWrapperSync)(this.searchCache, absoluteDir, run);
  9195. }
  9196. return run();
  9197. }
  9198. searchDirectorySync(dir) {
  9199. for (const place of this.config.searchPlaces) {
  9200. const placeResult = this.loadSearchPlaceSync(dir, place);
  9201. if (this.shouldSearchStopWithResult(placeResult) === true) {
  9202. return placeResult;
  9203. }
  9204. } // config not found
  9205. return null;
  9206. }
  9207. loadSearchPlaceSync(dir, place) {
  9208. const filepath = _path.default.join(dir, place);
  9209. const content = (0, _readFile.readFileSync)(filepath);
  9210. const result = this.createCosmiconfigResultSync(filepath, content);
  9211. return result;
  9212. }
  9213. loadFileContentSync(filepath, content) {
  9214. if (content === null) {
  9215. return null;
  9216. }
  9217. if (content.trim() === '') {
  9218. return undefined;
  9219. }
  9220. const loader = this.getLoaderEntryForFile(filepath);
  9221. const loaderResult = loader(filepath, content);
  9222. return loaderResult;
  9223. }
  9224. createCosmiconfigResultSync(filepath, content) {
  9225. const fileContent = this.loadFileContentSync(filepath, content);
  9226. const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
  9227. return result;
  9228. }
  9229. loadSync(filepath) {
  9230. this.validateFilePath(filepath);
  9231. const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
  9232. const runLoadSync = () => {
  9233. const content = (0, _readFile.readFileSync)(absoluteFilePath, {
  9234. throwNotFound: true
  9235. });
  9236. const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content);
  9237. const transformResult = this.config.transform(cosmiconfigResult);
  9238. return transformResult;
  9239. };
  9240. if (this.loadCache) {
  9241. return (0, _cacheWrapper.cacheWrapperSync)(this.loadCache, absoluteFilePath, runLoadSync);
  9242. }
  9243. return runLoadSync();
  9244. }
  9245. }
  9246. ExplorerSync$1.ExplorerSync = ExplorerSync;
  9247. var types = {};
  9248. Object.defineProperty(types, "__esModule", {
  9249. value: true
  9250. });
  9251. Object.defineProperty(dist$2, "__esModule", {
  9252. value: true
  9253. });
  9254. dist$2.cosmiconfig = cosmiconfig;
  9255. dist$2.cosmiconfigSync = cosmiconfigSync;
  9256. dist$2.defaultLoaders = void 0;
  9257. var _os = _interopRequireDefault(require$$0__default$2["default"]);
  9258. var _Explorer = Explorer$1;
  9259. var _ExplorerSync = ExplorerSync$1;
  9260. var _loaders = loaders$1;
  9261. function _interopRequireDefault(obj) {
  9262. return obj && obj.__esModule ? obj : {
  9263. default: obj
  9264. };
  9265. }
  9266. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  9267. // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  9268. function cosmiconfig(moduleName, options = {}) {
  9269. const normalizedOptions = normalizeOptions(moduleName, options);
  9270. const explorer = new _Explorer.Explorer(normalizedOptions);
  9271. return {
  9272. search: explorer.search.bind(explorer),
  9273. load: explorer.load.bind(explorer),
  9274. clearLoadCache: explorer.clearLoadCache.bind(explorer),
  9275. clearSearchCache: explorer.clearSearchCache.bind(explorer),
  9276. clearCaches: explorer.clearCaches.bind(explorer)
  9277. };
  9278. } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  9279. function cosmiconfigSync(moduleName, options = {}) {
  9280. const normalizedOptions = normalizeOptions(moduleName, options);
  9281. const explorerSync = new _ExplorerSync.ExplorerSync(normalizedOptions);
  9282. return {
  9283. search: explorerSync.searchSync.bind(explorerSync),
  9284. load: explorerSync.loadSync.bind(explorerSync),
  9285. clearLoadCache: explorerSync.clearLoadCache.bind(explorerSync),
  9286. clearSearchCache: explorerSync.clearSearchCache.bind(explorerSync),
  9287. clearCaches: explorerSync.clearCaches.bind(explorerSync)
  9288. };
  9289. } // do not allow mutation of default loaders. Make sure it is set inside options
  9290. const defaultLoaders = Object.freeze({
  9291. '.cjs': _loaders.loaders.loadJs,
  9292. '.js': _loaders.loaders.loadJs,
  9293. '.json': _loaders.loaders.loadJson,
  9294. '.yaml': _loaders.loaders.loadYaml,
  9295. '.yml': _loaders.loaders.loadYaml,
  9296. noExt: _loaders.loaders.loadYaml
  9297. });
  9298. dist$2.defaultLoaders = defaultLoaders;
  9299. const identity = function identity(x) {
  9300. return x;
  9301. };
  9302. function normalizeOptions(moduleName, options) {
  9303. const defaults = {
  9304. packageProp: moduleName,
  9305. searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `.${moduleName}rc.cjs`, `${moduleName}.config.js`, `${moduleName}.config.cjs`],
  9306. ignoreEmptySearchPlaces: true,
  9307. stopDir: _os.default.homedir(),
  9308. cache: true,
  9309. transform: identity,
  9310. loaders: defaultLoaders
  9311. };
  9312. const normalizedOptions = Object.assign(Object.assign(Object.assign({}, defaults), options), {}, {
  9313. loaders: Object.assign(Object.assign({}, defaults.loaders), options.loaders)
  9314. });
  9315. return normalizedOptions;
  9316. }
  9317. var findParentDir = {exports: {}};
  9318. (function (module, exports) {
  9319. var path = require$$0__default["default"],
  9320. fs = require$$1__default["default"],
  9321. exists = fs.exists || path.exists,
  9322. existsSync = fs.existsSync || path.existsSync;
  9323. function splitPath(path) {
  9324. var parts = path.split(/(\/|\\)/);
  9325. if (!parts.length) return parts; // when path starts with a slash, the first part is empty string
  9326. return !parts[0].length ? parts.slice(1) : parts;
  9327. }
  9328. exports = module.exports = function (currentFullPath, clue, cb) {
  9329. function testDir(parts) {
  9330. if (parts.length === 0) return cb(null, null);
  9331. var p = parts.join('');
  9332. exists(path.join(p, clue), function (itdoes) {
  9333. if (itdoes) return cb(null, p);
  9334. testDir(parts.slice(0, -1));
  9335. });
  9336. }
  9337. testDir(splitPath(currentFullPath));
  9338. };
  9339. exports.sync = function (currentFullPath, clue) {
  9340. function testDir(parts) {
  9341. if (parts.length === 0) return null;
  9342. var p = parts.join('');
  9343. var itdoes = existsSync(path.join(p, clue));
  9344. return itdoes ? p : testDir(parts.slice(0, -1));
  9345. }
  9346. return testDir(splitPath(currentFullPath));
  9347. };
  9348. })(findParentDir, findParentDir.exports);
  9349. var getStdin = {exports: {}};
  9350. const {
  9351. stdin
  9352. } = process;
  9353. getStdin.exports = async () => {
  9354. let result = '';
  9355. if (stdin.isTTY) {
  9356. return result;
  9357. }
  9358. stdin.setEncoding('utf8');
  9359. for await (const chunk of stdin) {
  9360. result += chunk;
  9361. }
  9362. return result;
  9363. };
  9364. getStdin.exports.buffer = async () => {
  9365. const result = [];
  9366. let length = 0;
  9367. if (stdin.isTTY) {
  9368. return Buffer.concat([]);
  9369. }
  9370. for await (const chunk of stdin) {
  9371. result.push(chunk);
  9372. length += chunk.length;
  9373. }
  9374. return Buffer.concat(result, length);
  9375. };
  9376. var ciInfo = {};
  9377. var require$$0 = [
  9378. {
  9379. name: "AppVeyor",
  9380. constant: "APPVEYOR",
  9381. env: "APPVEYOR",
  9382. pr: "APPVEYOR_PULL_REQUEST_NUMBER"
  9383. },
  9384. {
  9385. name: "Azure Pipelines",
  9386. constant: "AZURE_PIPELINES",
  9387. env: "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
  9388. pr: "SYSTEM_PULLREQUEST_PULLREQUESTID"
  9389. },
  9390. {
  9391. name: "Appcircle",
  9392. constant: "APPCIRCLE",
  9393. env: "AC_APPCIRCLE"
  9394. },
  9395. {
  9396. name: "Bamboo",
  9397. constant: "BAMBOO",
  9398. env: "bamboo_planKey"
  9399. },
  9400. {
  9401. name: "Bitbucket Pipelines",
  9402. constant: "BITBUCKET",
  9403. env: "BITBUCKET_COMMIT",
  9404. pr: "BITBUCKET_PR_ID"
  9405. },
  9406. {
  9407. name: "Bitrise",
  9408. constant: "BITRISE",
  9409. env: "BITRISE_IO",
  9410. pr: "BITRISE_PULL_REQUEST"
  9411. },
  9412. {
  9413. name: "Buddy",
  9414. constant: "BUDDY",
  9415. env: "BUDDY_WORKSPACE_ID",
  9416. pr: "BUDDY_EXECUTION_PULL_REQUEST_ID"
  9417. },
  9418. {
  9419. name: "Buildkite",
  9420. constant: "BUILDKITE",
  9421. env: "BUILDKITE",
  9422. pr: {
  9423. env: "BUILDKITE_PULL_REQUEST",
  9424. ne: "false"
  9425. }
  9426. },
  9427. {
  9428. name: "CircleCI",
  9429. constant: "CIRCLE",
  9430. env: "CIRCLECI",
  9431. pr: "CIRCLE_PULL_REQUEST"
  9432. },
  9433. {
  9434. name: "Cirrus CI",
  9435. constant: "CIRRUS",
  9436. env: "CIRRUS_CI",
  9437. pr: "CIRRUS_PR"
  9438. },
  9439. {
  9440. name: "AWS CodeBuild",
  9441. constant: "CODEBUILD",
  9442. env: "CODEBUILD_BUILD_ARN"
  9443. },
  9444. {
  9445. name: "Codefresh",
  9446. constant: "CODEFRESH",
  9447. env: "CF_BUILD_ID",
  9448. pr: {
  9449. any: [
  9450. "CF_PULL_REQUEST_NUMBER",
  9451. "CF_PULL_REQUEST_ID"
  9452. ]
  9453. }
  9454. },
  9455. {
  9456. name: "Codeship",
  9457. constant: "CODESHIP",
  9458. env: {
  9459. CI_NAME: "codeship"
  9460. }
  9461. },
  9462. {
  9463. name: "Drone",
  9464. constant: "DRONE",
  9465. env: "DRONE",
  9466. pr: {
  9467. DRONE_BUILD_EVENT: "pull_request"
  9468. }
  9469. },
  9470. {
  9471. name: "dsari",
  9472. constant: "DSARI",
  9473. env: "DSARI"
  9474. },
  9475. {
  9476. name: "GitHub Actions",
  9477. constant: "GITHUB_ACTIONS",
  9478. env: "GITHUB_ACTIONS",
  9479. pr: {
  9480. GITHUB_EVENT_NAME: "pull_request"
  9481. }
  9482. },
  9483. {
  9484. name: "GitLab CI",
  9485. constant: "GITLAB",
  9486. env: "GITLAB_CI",
  9487. pr: "CI_MERGE_REQUEST_ID"
  9488. },
  9489. {
  9490. name: "GoCD",
  9491. constant: "GOCD",
  9492. env: "GO_PIPELINE_LABEL"
  9493. },
  9494. {
  9495. name: "LayerCI",
  9496. constant: "LAYERCI",
  9497. env: "LAYERCI",
  9498. pr: "LAYERCI_PULL_REQUEST"
  9499. },
  9500. {
  9501. name: "Hudson",
  9502. constant: "HUDSON",
  9503. env: "HUDSON_URL"
  9504. },
  9505. {
  9506. name: "Jenkins",
  9507. constant: "JENKINS",
  9508. env: [
  9509. "JENKINS_URL",
  9510. "BUILD_ID"
  9511. ],
  9512. pr: {
  9513. any: [
  9514. "ghprbPullId",
  9515. "CHANGE_ID"
  9516. ]
  9517. }
  9518. },
  9519. {
  9520. name: "Magnum CI",
  9521. constant: "MAGNUM",
  9522. env: "MAGNUM"
  9523. },
  9524. {
  9525. name: "Netlify CI",
  9526. constant: "NETLIFY",
  9527. env: "NETLIFY",
  9528. pr: {
  9529. env: "PULL_REQUEST",
  9530. ne: "false"
  9531. }
  9532. },
  9533. {
  9534. name: "Nevercode",
  9535. constant: "NEVERCODE",
  9536. env: "NEVERCODE",
  9537. pr: {
  9538. env: "NEVERCODE_PULL_REQUEST",
  9539. ne: "false"
  9540. }
  9541. },
  9542. {
  9543. name: "Render",
  9544. constant: "RENDER",
  9545. env: "RENDER",
  9546. pr: {
  9547. IS_PULL_REQUEST: "true"
  9548. }
  9549. },
  9550. {
  9551. name: "Sail CI",
  9552. constant: "SAIL",
  9553. env: "SAILCI",
  9554. pr: "SAIL_PULL_REQUEST_NUMBER"
  9555. },
  9556. {
  9557. name: "Semaphore",
  9558. constant: "SEMAPHORE",
  9559. env: "SEMAPHORE",
  9560. pr: "PULL_REQUEST_NUMBER"
  9561. },
  9562. {
  9563. name: "Screwdriver",
  9564. constant: "SCREWDRIVER",
  9565. env: "SCREWDRIVER",
  9566. pr: {
  9567. env: "SD_PULL_REQUEST",
  9568. ne: "false"
  9569. }
  9570. },
  9571. {
  9572. name: "Shippable",
  9573. constant: "SHIPPABLE",
  9574. env: "SHIPPABLE",
  9575. pr: {
  9576. IS_PULL_REQUEST: "true"
  9577. }
  9578. },
  9579. {
  9580. name: "Solano CI",
  9581. constant: "SOLANO",
  9582. env: "TDDIUM",
  9583. pr: "TDDIUM_PR_ID"
  9584. },
  9585. {
  9586. name: "Strider CD",
  9587. constant: "STRIDER",
  9588. env: "STRIDER"
  9589. },
  9590. {
  9591. name: "TaskCluster",
  9592. constant: "TASKCLUSTER",
  9593. env: [
  9594. "TASK_ID",
  9595. "RUN_ID"
  9596. ]
  9597. },
  9598. {
  9599. name: "TeamCity",
  9600. constant: "TEAMCITY",
  9601. env: "TEAMCITY_VERSION"
  9602. },
  9603. {
  9604. name: "Travis CI",
  9605. constant: "TRAVIS",
  9606. env: "TRAVIS",
  9607. pr: {
  9608. env: "TRAVIS_PULL_REQUEST",
  9609. ne: "false"
  9610. }
  9611. },
  9612. {
  9613. name: "Vercel",
  9614. constant: "VERCEL",
  9615. env: "NOW_BUILDER"
  9616. },
  9617. {
  9618. name: "Visual Studio App Center",
  9619. constant: "APPCENTER",
  9620. env: "APPCENTER_BUILD_ID"
  9621. }
  9622. ];
  9623. (function (exports) {
  9624. const vendors = require$$0;
  9625. const env = process.env; // Used for testing only
  9626. Object.defineProperty(exports, '_vendors', {
  9627. value: vendors.map(function (v) {
  9628. return v.constant;
  9629. })
  9630. });
  9631. exports.name = null;
  9632. exports.isPR = null;
  9633. vendors.forEach(function (vendor) {
  9634. const envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env];
  9635. const isCI = envs.every(function (obj) {
  9636. return checkEnv(obj);
  9637. });
  9638. exports[vendor.constant] = isCI;
  9639. if (isCI) {
  9640. exports.name = vendor.name;
  9641. switch (typeof vendor.pr) {
  9642. case 'string':
  9643. // "pr": "CIRRUS_PR"
  9644. exports.isPR = !!env[vendor.pr];
  9645. break;
  9646. case 'object':
  9647. if ('env' in vendor.pr) {
  9648. // "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
  9649. exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne;
  9650. } else if ('any' in vendor.pr) {
  9651. // "pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
  9652. exports.isPR = vendor.pr.any.some(function (key) {
  9653. return !!env[key];
  9654. });
  9655. } else {
  9656. // "pr": { "DRONE_BUILD_EVENT": "pull_request" }
  9657. exports.isPR = checkEnv(vendor.pr);
  9658. }
  9659. break;
  9660. default:
  9661. // PR detection not supported for this vendor
  9662. exports.isPR = null;
  9663. }
  9664. }
  9665. });
  9666. exports.isCI = !!(env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
  9667. env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
  9668. env.BUILD_NUMBER || // Jenkins, TeamCity
  9669. env.RUN_ID || // TaskCluster, dsari
  9670. exports.name || false);
  9671. function checkEnv(obj) {
  9672. if (typeof obj === 'string') return !!env[obj];
  9673. return Object.keys(obj).every(function (k) {
  9674. return env[k] === obj[k];
  9675. });
  9676. }
  9677. })(ciInfo);
  9678. var thirdParty = {
  9679. cosmiconfig: dist$2.cosmiconfig,
  9680. cosmiconfigSync: dist$2.cosmiconfigSync,
  9681. findParentDir: findParentDir.exports.sync,
  9682. getStdin: getStdin.exports,
  9683. isCI: () => ciInfo.isCI
  9684. };
  9685. module.exports = thirdParty;