third-party.js 283 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476
  1. 'use strict';
  2. var os = require('os');
  3. var path = require('path');
  4. var Module = require('module');
  5. var fs = require('fs');
  6. var util = require('util');
  7. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  8. var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
  9. var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
  10. var Module__default = /*#__PURE__*/_interopDefaultLegacy(Module);
  11. var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
  12. var util__default = /*#__PURE__*/_interopDefaultLegacy(util);
  13. function createCommonjsModule(fn, basedir, module) {
  14. return module = {
  15. path: basedir,
  16. exports: {},
  17. require: function (path, base) {
  18. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  19. }
  20. }, fn(module, module.exports), module.exports;
  21. }
  22. function commonjsRequire () {
  23. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  24. }
  25. const resolveFrom = (fromDir, moduleId, silent) => {
  26. if (typeof fromDir !== 'string') {
  27. throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
  28. }
  29. if (typeof moduleId !== 'string') {
  30. throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
  31. }
  32. try {
  33. fromDir = fs__default['default'].realpathSync(fromDir);
  34. } catch (err) {
  35. if (err.code === 'ENOENT') {
  36. fromDir = path__default['default'].resolve(fromDir);
  37. } else if (silent) {
  38. return null;
  39. } else {
  40. throw err;
  41. }
  42. }
  43. const fromFile = path__default['default'].join(fromDir, 'noop.js');
  44. const resolveFileName = () => Module__default['default']._resolveFilename(moduleId, {
  45. id: fromFile,
  46. filename: fromFile,
  47. paths: Module__default['default']._nodeModulePaths(fromDir)
  48. });
  49. if (silent) {
  50. try {
  51. return resolveFileName();
  52. } catch (err) {
  53. return null;
  54. }
  55. }
  56. return resolveFileName();
  57. };
  58. var resolveFrom_1 = (fromDir, moduleId) => resolveFrom(fromDir, moduleId);
  59. var silent = (fromDir, moduleId) => resolveFrom(fromDir, moduleId, true);
  60. resolveFrom_1.silent = silent;
  61. var importFresh = moduleId => {
  62. if (typeof moduleId !== 'string') {
  63. throw new TypeError('Expected a string');
  64. }
  65. const parentPath = __filename;
  66. const filePath = resolveFrom_1(path__default['default'].dirname(parentPath), moduleId);
  67. const oldModule = eval('require').cache[filePath]; // Delete itself from module parent
  68. if (oldModule && oldModule.parent) {
  69. let i = oldModule.parent.children.length;
  70. while (i--) {
  71. if (oldModule.parent.children[i].id === filePath) {
  72. oldModule.parent.children.splice(i, 1);
  73. }
  74. }
  75. }
  76. delete eval('require').cache[filePath]; // Delete module from cache
  77. const parent = eval('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
  78. return parent === undefined ? eval('require')(filePath) : parent.require(filePath); // In case cache doesn't have parent, fall back to normal require
  79. };
  80. var isArrayish = function isArrayish(obj) {
  81. if (!obj) {
  82. return false;
  83. }
  84. return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && obj.splice instanceof Function;
  85. };
  86. var errorEx = function errorEx(name, properties) {
  87. if (!name || name.constructor !== String) {
  88. properties = name || {};
  89. name = Error.name;
  90. }
  91. var errorExError = function ErrorEXError(message) {
  92. if (!this) {
  93. return new ErrorEXError(message);
  94. }
  95. message = message instanceof Error ? message.message : message || this.message;
  96. Error.call(this, message);
  97. Error.captureStackTrace(this, errorExError);
  98. this.name = name;
  99. Object.defineProperty(this, 'message', {
  100. configurable: true,
  101. enumerable: false,
  102. get: function () {
  103. var newMessage = message.split(/\r?\n/g);
  104. for (var key in properties) {
  105. if (!properties.hasOwnProperty(key)) {
  106. continue;
  107. }
  108. var modifier = properties[key];
  109. if ('message' in modifier) {
  110. newMessage = modifier.message(this[key], newMessage) || newMessage;
  111. if (!isArrayish(newMessage)) {
  112. newMessage = [newMessage];
  113. }
  114. }
  115. }
  116. return newMessage.join('\n');
  117. },
  118. set: function (v) {
  119. message = v;
  120. }
  121. });
  122. var overwrittenStack = null;
  123. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  124. var stackGetter = stackDescriptor.get;
  125. var stackValue = stackDescriptor.value;
  126. delete stackDescriptor.value;
  127. delete stackDescriptor.writable;
  128. stackDescriptor.set = function (newstack) {
  129. overwrittenStack = newstack;
  130. };
  131. stackDescriptor.get = function () {
  132. var stack = (overwrittenStack || (stackGetter ? stackGetter.call(this) : stackValue)).split(/\r?\n+/g); // starting in Node 7, the stack builder caches the message.
  133. // just replace it.
  134. if (!overwrittenStack) {
  135. stack[0] = this.name + ': ' + this.message;
  136. }
  137. var lineCount = 1;
  138. for (var key in properties) {
  139. if (!properties.hasOwnProperty(key)) {
  140. continue;
  141. }
  142. var modifier = properties[key];
  143. if ('line' in modifier) {
  144. var line = modifier.line(this[key]);
  145. if (line) {
  146. stack.splice(lineCount++, 0, ' ' + line);
  147. }
  148. }
  149. if ('stack' in modifier) {
  150. modifier.stack(this[key], stack);
  151. }
  152. }
  153. return stack.join('\n');
  154. };
  155. Object.defineProperty(this, 'stack', stackDescriptor);
  156. };
  157. if (Object.setPrototypeOf) {
  158. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  159. Object.setPrototypeOf(errorExError, Error);
  160. } else {
  161. util__default['default'].inherits(errorExError, Error);
  162. }
  163. return errorExError;
  164. };
  165. errorEx.append = function (str, def) {
  166. return {
  167. message: function (v, message) {
  168. v = v || def;
  169. if (v) {
  170. message[0] += ' ' + str.replace('%s', v.toString());
  171. }
  172. return message;
  173. }
  174. };
  175. };
  176. errorEx.line = function (str, def) {
  177. return {
  178. line: function (v) {
  179. v = v || def;
  180. if (v) {
  181. return str.replace('%s', v.toString());
  182. }
  183. return null;
  184. }
  185. };
  186. };
  187. var errorEx_1 = errorEx;
  188. var jsonParseBetterErrors = parseJson;
  189. function parseJson(txt, reviver, context) {
  190. context = context || 20;
  191. try {
  192. return JSON.parse(txt, reviver);
  193. } catch (e) {
  194. if (typeof txt !== 'string') {
  195. const isEmptyArray = Array.isArray(txt) && txt.length === 0;
  196. const errorMessage = 'Cannot parse ' + (isEmptyArray ? 'an empty array' : String(txt));
  197. throw new TypeError(errorMessage);
  198. }
  199. const syntaxErr = e.message.match(/^Unexpected token.*position\s+(\d+)/i);
  200. const errIdx = syntaxErr ? +syntaxErr[1] : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 : null;
  201. if (errIdx != null) {
  202. const start = errIdx <= context ? 0 : errIdx - context;
  203. const end = errIdx + context >= txt.length ? txt.length : errIdx + context;
  204. e.message += ` while parsing near '${start === 0 ? '' : '...'}${txt.slice(start, end)}${end === txt.length ? '' : '...'}'`;
  205. } else {
  206. e.message += ` while parsing '${txt.slice(0, context * 2)}'`;
  207. }
  208. throw e;
  209. }
  210. }
  211. var dist = createCommonjsModule(function (module, exports) {
  212. var LF = '\n';
  213. var CR = '\r';
  214. var LinesAndColumns = function () {
  215. function LinesAndColumns(string) {
  216. this.string = string;
  217. var offsets = [0];
  218. for (var offset = 0; offset < string.length;) {
  219. switch (string[offset]) {
  220. case LF:
  221. offset += LF.length;
  222. offsets.push(offset);
  223. break;
  224. case CR:
  225. offset += CR.length;
  226. if (string[offset] === LF) {
  227. offset += LF.length;
  228. }
  229. offsets.push(offset);
  230. break;
  231. default:
  232. offset++;
  233. break;
  234. }
  235. }
  236. this.offsets = offsets;
  237. }
  238. LinesAndColumns.prototype.locationForIndex = function (index) {
  239. if (index < 0 || index > this.string.length) {
  240. return null;
  241. }
  242. var line = 0;
  243. var offsets = this.offsets;
  244. while (offsets[line + 1] <= index) {
  245. line++;
  246. }
  247. var column = index - offsets[line];
  248. return {
  249. line: line,
  250. column: column
  251. };
  252. };
  253. LinesAndColumns.prototype.indexForLocation = function (location) {
  254. var line = location.line,
  255. column = location.column;
  256. if (line < 0 || line >= this.offsets.length) {
  257. return null;
  258. }
  259. if (column < 0 || column > this.lengthOfLine(line)) {
  260. return null;
  261. }
  262. return this.offsets[line] + column;
  263. };
  264. LinesAndColumns.prototype.lengthOfLine = function (line) {
  265. var offset = this.offsets[line];
  266. var nextOffset = line === this.offsets.length - 1 ? this.string.length : this.offsets[line + 1];
  267. return nextOffset - offset;
  268. };
  269. return LinesAndColumns;
  270. }();
  271. exports.__esModule = true;
  272. exports["default"] = LinesAndColumns;
  273. });
  274. var jsTokens = createCommonjsModule(function (module, exports) {
  275. // Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
  276. // License: MIT. (See LICENSE.)
  277. Object.defineProperty(exports, "__esModule", {
  278. value: true
  279. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  280. // (run `npm run build`).
  281. exports.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
  282. exports.matchToToken = function (match) {
  283. var token = {
  284. type: "invalid",
  285. value: match[0],
  286. closed: undefined
  287. };
  288. 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";
  289. return token;
  290. };
  291. });
  292. var identifier = createCommonjsModule(function (module, exports) {
  293. Object.defineProperty(exports, "__esModule", {
  294. value: true
  295. });
  296. exports.isIdentifierStart = isIdentifierStart;
  297. exports.isIdentifierChar = isIdentifierChar;
  298. exports.isIdentifierName = isIdentifierName;
  299. 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\u08a0-\u08b4\u08b6-\u08c7\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\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\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-\u170c\u170e-\u1711\u1720-\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-\u1b4b\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-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\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";
  300. 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\u08d3-\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\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-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\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-\u1df9\u1dfb-\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";
  301. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  302. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  303. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  304. 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, 157, 310, 10, 21, 11, 7, 153, 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, 107, 20, 28, 22, 13, 52, 76, 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, 230, 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, 35, 56, 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, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 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, 8952, 286, 50, 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, 2357, 44, 11, 6, 17, 0, 370, 43, 1301, 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, 42717, 35, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938];
  305. 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, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 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, 135, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 5319, 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, 419, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  306. function isInAstralSet(code, set) {
  307. let pos = 0x10000;
  308. for (let i = 0, length = set.length; i < length; i += 2) {
  309. pos += set[i];
  310. if (pos > code) return false;
  311. pos += set[i + 1];
  312. if (pos >= code) return true;
  313. }
  314. return false;
  315. }
  316. function isIdentifierStart(code) {
  317. if (code < 65) return code === 36;
  318. if (code <= 90) return true;
  319. if (code < 97) return code === 95;
  320. if (code <= 122) return true;
  321. if (code <= 0xffff) {
  322. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  323. }
  324. return isInAstralSet(code, astralIdentifierStartCodes);
  325. }
  326. function isIdentifierChar(code) {
  327. if (code < 48) return code === 36;
  328. if (code < 58) return true;
  329. if (code < 65) return false;
  330. if (code <= 90) return true;
  331. if (code < 97) return code === 95;
  332. if (code <= 122) return true;
  333. if (code <= 0xffff) {
  334. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  335. }
  336. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  337. }
  338. function isIdentifierName(name) {
  339. let isFirst = true;
  340. for (let _i = 0, _Array$from = Array.from(name); _i < _Array$from.length; _i++) {
  341. const char = _Array$from[_i];
  342. const cp = char.codePointAt(0);
  343. if (isFirst) {
  344. if (!isIdentifierStart(cp)) {
  345. return false;
  346. }
  347. isFirst = false;
  348. } else if (!isIdentifierChar(cp)) {
  349. return false;
  350. }
  351. }
  352. return !isFirst;
  353. }
  354. });
  355. var keyword = createCommonjsModule(function (module, exports) {
  356. Object.defineProperty(exports, "__esModule", {
  357. value: true
  358. });
  359. exports.isReservedWord = isReservedWord;
  360. exports.isStrictReservedWord = isStrictReservedWord;
  361. exports.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord;
  362. exports.isStrictBindReservedWord = isStrictBindReservedWord;
  363. exports.isKeyword = isKeyword;
  364. const reservedWords = {
  365. 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"],
  366. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  367. strictBind: ["eval", "arguments"]
  368. };
  369. const keywords = new Set(reservedWords.keyword);
  370. const reservedWordsStrictSet = new Set(reservedWords.strict);
  371. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  372. function isReservedWord(word, inModule) {
  373. return inModule && word === "await" || word === "enum";
  374. }
  375. function isStrictReservedWord(word, inModule) {
  376. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  377. }
  378. function isStrictBindOnlyReservedWord(word) {
  379. return reservedWordsStrictBindSet.has(word);
  380. }
  381. function isStrictBindReservedWord(word, inModule) {
  382. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  383. }
  384. function isKeyword(word) {
  385. return keywords.has(word);
  386. }
  387. });
  388. var lib = createCommonjsModule(function (module, exports) {
  389. Object.defineProperty(exports, "__esModule", {
  390. value: true
  391. });
  392. Object.defineProperty(exports, "isIdentifierName", {
  393. enumerable: true,
  394. get: function () {
  395. return identifier.isIdentifierName;
  396. }
  397. });
  398. Object.defineProperty(exports, "isIdentifierChar", {
  399. enumerable: true,
  400. get: function () {
  401. return identifier.isIdentifierChar;
  402. }
  403. });
  404. Object.defineProperty(exports, "isIdentifierStart", {
  405. enumerable: true,
  406. get: function () {
  407. return identifier.isIdentifierStart;
  408. }
  409. });
  410. Object.defineProperty(exports, "isReservedWord", {
  411. enumerable: true,
  412. get: function () {
  413. return keyword.isReservedWord;
  414. }
  415. });
  416. Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
  417. enumerable: true,
  418. get: function () {
  419. return keyword.isStrictBindOnlyReservedWord;
  420. }
  421. });
  422. Object.defineProperty(exports, "isStrictBindReservedWord", {
  423. enumerable: true,
  424. get: function () {
  425. return keyword.isStrictBindReservedWord;
  426. }
  427. });
  428. Object.defineProperty(exports, "isStrictReservedWord", {
  429. enumerable: true,
  430. get: function () {
  431. return keyword.isStrictReservedWord;
  432. }
  433. });
  434. Object.defineProperty(exports, "isKeyword", {
  435. enumerable: true,
  436. get: function () {
  437. return keyword.isKeyword;
  438. }
  439. });
  440. });
  441. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  442. var escapeStringRegexp = function (str) {
  443. if (typeof str !== 'string') {
  444. throw new TypeError('Expected a string');
  445. }
  446. return str.replace(matchOperatorsRe, '\\$&');
  447. };
  448. var colorName = {
  449. "aliceblue": [240, 248, 255],
  450. "antiquewhite": [250, 235, 215],
  451. "aqua": [0, 255, 255],
  452. "aquamarine": [127, 255, 212],
  453. "azure": [240, 255, 255],
  454. "beige": [245, 245, 220],
  455. "bisque": [255, 228, 196],
  456. "black": [0, 0, 0],
  457. "blanchedalmond": [255, 235, 205],
  458. "blue": [0, 0, 255],
  459. "blueviolet": [138, 43, 226],
  460. "brown": [165, 42, 42],
  461. "burlywood": [222, 184, 135],
  462. "cadetblue": [95, 158, 160],
  463. "chartreuse": [127, 255, 0],
  464. "chocolate": [210, 105, 30],
  465. "coral": [255, 127, 80],
  466. "cornflowerblue": [100, 149, 237],
  467. "cornsilk": [255, 248, 220],
  468. "crimson": [220, 20, 60],
  469. "cyan": [0, 255, 255],
  470. "darkblue": [0, 0, 139],
  471. "darkcyan": [0, 139, 139],
  472. "darkgoldenrod": [184, 134, 11],
  473. "darkgray": [169, 169, 169],
  474. "darkgreen": [0, 100, 0],
  475. "darkgrey": [169, 169, 169],
  476. "darkkhaki": [189, 183, 107],
  477. "darkmagenta": [139, 0, 139],
  478. "darkolivegreen": [85, 107, 47],
  479. "darkorange": [255, 140, 0],
  480. "darkorchid": [153, 50, 204],
  481. "darkred": [139, 0, 0],
  482. "darksalmon": [233, 150, 122],
  483. "darkseagreen": [143, 188, 143],
  484. "darkslateblue": [72, 61, 139],
  485. "darkslategray": [47, 79, 79],
  486. "darkslategrey": [47, 79, 79],
  487. "darkturquoise": [0, 206, 209],
  488. "darkviolet": [148, 0, 211],
  489. "deeppink": [255, 20, 147],
  490. "deepskyblue": [0, 191, 255],
  491. "dimgray": [105, 105, 105],
  492. "dimgrey": [105, 105, 105],
  493. "dodgerblue": [30, 144, 255],
  494. "firebrick": [178, 34, 34],
  495. "floralwhite": [255, 250, 240],
  496. "forestgreen": [34, 139, 34],
  497. "fuchsia": [255, 0, 255],
  498. "gainsboro": [220, 220, 220],
  499. "ghostwhite": [248, 248, 255],
  500. "gold": [255, 215, 0],
  501. "goldenrod": [218, 165, 32],
  502. "gray": [128, 128, 128],
  503. "green": [0, 128, 0],
  504. "greenyellow": [173, 255, 47],
  505. "grey": [128, 128, 128],
  506. "honeydew": [240, 255, 240],
  507. "hotpink": [255, 105, 180],
  508. "indianred": [205, 92, 92],
  509. "indigo": [75, 0, 130],
  510. "ivory": [255, 255, 240],
  511. "khaki": [240, 230, 140],
  512. "lavender": [230, 230, 250],
  513. "lavenderblush": [255, 240, 245],
  514. "lawngreen": [124, 252, 0],
  515. "lemonchiffon": [255, 250, 205],
  516. "lightblue": [173, 216, 230],
  517. "lightcoral": [240, 128, 128],
  518. "lightcyan": [224, 255, 255],
  519. "lightgoldenrodyellow": [250, 250, 210],
  520. "lightgray": [211, 211, 211],
  521. "lightgreen": [144, 238, 144],
  522. "lightgrey": [211, 211, 211],
  523. "lightpink": [255, 182, 193],
  524. "lightsalmon": [255, 160, 122],
  525. "lightseagreen": [32, 178, 170],
  526. "lightskyblue": [135, 206, 250],
  527. "lightslategray": [119, 136, 153],
  528. "lightslategrey": [119, 136, 153],
  529. "lightsteelblue": [176, 196, 222],
  530. "lightyellow": [255, 255, 224],
  531. "lime": [0, 255, 0],
  532. "limegreen": [50, 205, 50],
  533. "linen": [250, 240, 230],
  534. "magenta": [255, 0, 255],
  535. "maroon": [128, 0, 0],
  536. "mediumaquamarine": [102, 205, 170],
  537. "mediumblue": [0, 0, 205],
  538. "mediumorchid": [186, 85, 211],
  539. "mediumpurple": [147, 112, 219],
  540. "mediumseagreen": [60, 179, 113],
  541. "mediumslateblue": [123, 104, 238],
  542. "mediumspringgreen": [0, 250, 154],
  543. "mediumturquoise": [72, 209, 204],
  544. "mediumvioletred": [199, 21, 133],
  545. "midnightblue": [25, 25, 112],
  546. "mintcream": [245, 255, 250],
  547. "mistyrose": [255, 228, 225],
  548. "moccasin": [255, 228, 181],
  549. "navajowhite": [255, 222, 173],
  550. "navy": [0, 0, 128],
  551. "oldlace": [253, 245, 230],
  552. "olive": [128, 128, 0],
  553. "olivedrab": [107, 142, 35],
  554. "orange": [255, 165, 0],
  555. "orangered": [255, 69, 0],
  556. "orchid": [218, 112, 214],
  557. "palegoldenrod": [238, 232, 170],
  558. "palegreen": [152, 251, 152],
  559. "paleturquoise": [175, 238, 238],
  560. "palevioletred": [219, 112, 147],
  561. "papayawhip": [255, 239, 213],
  562. "peachpuff": [255, 218, 185],
  563. "peru": [205, 133, 63],
  564. "pink": [255, 192, 203],
  565. "plum": [221, 160, 221],
  566. "powderblue": [176, 224, 230],
  567. "purple": [128, 0, 128],
  568. "rebeccapurple": [102, 51, 153],
  569. "red": [255, 0, 0],
  570. "rosybrown": [188, 143, 143],
  571. "royalblue": [65, 105, 225],
  572. "saddlebrown": [139, 69, 19],
  573. "salmon": [250, 128, 114],
  574. "sandybrown": [244, 164, 96],
  575. "seagreen": [46, 139, 87],
  576. "seashell": [255, 245, 238],
  577. "sienna": [160, 82, 45],
  578. "silver": [192, 192, 192],
  579. "skyblue": [135, 206, 235],
  580. "slateblue": [106, 90, 205],
  581. "slategray": [112, 128, 144],
  582. "slategrey": [112, 128, 144],
  583. "snow": [255, 250, 250],
  584. "springgreen": [0, 255, 127],
  585. "steelblue": [70, 130, 180],
  586. "tan": [210, 180, 140],
  587. "teal": [0, 128, 128],
  588. "thistle": [216, 191, 216],
  589. "tomato": [255, 99, 71],
  590. "turquoise": [64, 224, 208],
  591. "violet": [238, 130, 238],
  592. "wheat": [245, 222, 179],
  593. "white": [255, 255, 255],
  594. "whitesmoke": [245, 245, 245],
  595. "yellow": [255, 255, 0],
  596. "yellowgreen": [154, 205, 50]
  597. };
  598. var conversions = createCommonjsModule(function (module) {
  599. /* MIT license */
  600. // NOTE: conversions should only return primitive values (i.e. arrays, or
  601. // values that give correct `typeof` results).
  602. // do not use box values types (i.e. Number(), String(), etc.)
  603. var reverseKeywords = {};
  604. for (var key in colorName) {
  605. if (colorName.hasOwnProperty(key)) {
  606. reverseKeywords[colorName[key]] = key;
  607. }
  608. }
  609. var convert = module.exports = {
  610. rgb: {
  611. channels: 3,
  612. labels: 'rgb'
  613. },
  614. hsl: {
  615. channels: 3,
  616. labels: 'hsl'
  617. },
  618. hsv: {
  619. channels: 3,
  620. labels: 'hsv'
  621. },
  622. hwb: {
  623. channels: 3,
  624. labels: 'hwb'
  625. },
  626. cmyk: {
  627. channels: 4,
  628. labels: 'cmyk'
  629. },
  630. xyz: {
  631. channels: 3,
  632. labels: 'xyz'
  633. },
  634. lab: {
  635. channels: 3,
  636. labels: 'lab'
  637. },
  638. lch: {
  639. channels: 3,
  640. labels: 'lch'
  641. },
  642. hex: {
  643. channels: 1,
  644. labels: ['hex']
  645. },
  646. keyword: {
  647. channels: 1,
  648. labels: ['keyword']
  649. },
  650. ansi16: {
  651. channels: 1,
  652. labels: ['ansi16']
  653. },
  654. ansi256: {
  655. channels: 1,
  656. labels: ['ansi256']
  657. },
  658. hcg: {
  659. channels: 3,
  660. labels: ['h', 'c', 'g']
  661. },
  662. apple: {
  663. channels: 3,
  664. labels: ['r16', 'g16', 'b16']
  665. },
  666. gray: {
  667. channels: 1,
  668. labels: ['gray']
  669. }
  670. }; // hide .channels and .labels properties
  671. for (var model in convert) {
  672. if (convert.hasOwnProperty(model)) {
  673. if (!('channels' in convert[model])) {
  674. throw new Error('missing channels property: ' + model);
  675. }
  676. if (!('labels' in convert[model])) {
  677. throw new Error('missing channel labels property: ' + model);
  678. }
  679. if (convert[model].labels.length !== convert[model].channels) {
  680. throw new Error('channel and label counts mismatch: ' + model);
  681. }
  682. var channels = convert[model].channels;
  683. var labels = convert[model].labels;
  684. delete convert[model].channels;
  685. delete convert[model].labels;
  686. Object.defineProperty(convert[model], 'channels', {
  687. value: channels
  688. });
  689. Object.defineProperty(convert[model], 'labels', {
  690. value: labels
  691. });
  692. }
  693. }
  694. convert.rgb.hsl = function (rgb) {
  695. var r = rgb[0] / 255;
  696. var g = rgb[1] / 255;
  697. var b = rgb[2] / 255;
  698. var min = Math.min(r, g, b);
  699. var max = Math.max(r, g, b);
  700. var delta = max - min;
  701. var h;
  702. var s;
  703. var l;
  704. if (max === min) {
  705. h = 0;
  706. } else if (r === max) {
  707. h = (g - b) / delta;
  708. } else if (g === max) {
  709. h = 2 + (b - r) / delta;
  710. } else if (b === max) {
  711. h = 4 + (r - g) / delta;
  712. }
  713. h = Math.min(h * 60, 360);
  714. if (h < 0) {
  715. h += 360;
  716. }
  717. l = (min + max) / 2;
  718. if (max === min) {
  719. s = 0;
  720. } else if (l <= 0.5) {
  721. s = delta / (max + min);
  722. } else {
  723. s = delta / (2 - max - min);
  724. }
  725. return [h, s * 100, l * 100];
  726. };
  727. convert.rgb.hsv = function (rgb) {
  728. var rdif;
  729. var gdif;
  730. var bdif;
  731. var h;
  732. var s;
  733. var r = rgb[0] / 255;
  734. var g = rgb[1] / 255;
  735. var b = rgb[2] / 255;
  736. var v = Math.max(r, g, b);
  737. var diff = v - Math.min(r, g, b);
  738. var diffc = function (c) {
  739. return (v - c) / 6 / diff + 1 / 2;
  740. };
  741. if (diff === 0) {
  742. h = s = 0;
  743. } else {
  744. s = diff / v;
  745. rdif = diffc(r);
  746. gdif = diffc(g);
  747. bdif = diffc(b);
  748. if (r === v) {
  749. h = bdif - gdif;
  750. } else if (g === v) {
  751. h = 1 / 3 + rdif - bdif;
  752. } else if (b === v) {
  753. h = 2 / 3 + gdif - rdif;
  754. }
  755. if (h < 0) {
  756. h += 1;
  757. } else if (h > 1) {
  758. h -= 1;
  759. }
  760. }
  761. return [h * 360, s * 100, v * 100];
  762. };
  763. convert.rgb.hwb = function (rgb) {
  764. var r = rgb[0];
  765. var g = rgb[1];
  766. var b = rgb[2];
  767. var h = convert.rgb.hsl(rgb)[0];
  768. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  769. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  770. return [h, w * 100, b * 100];
  771. };
  772. convert.rgb.cmyk = function (rgb) {
  773. var r = rgb[0] / 255;
  774. var g = rgb[1] / 255;
  775. var b = rgb[2] / 255;
  776. var c;
  777. var m;
  778. var y;
  779. var k;
  780. k = Math.min(1 - r, 1 - g, 1 - b);
  781. c = (1 - r - k) / (1 - k) || 0;
  782. m = (1 - g - k) / (1 - k) || 0;
  783. y = (1 - b - k) / (1 - k) || 0;
  784. return [c * 100, m * 100, y * 100, k * 100];
  785. };
  786. /**
  787. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  788. * */
  789. function comparativeDistance(x, y) {
  790. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  791. }
  792. convert.rgb.keyword = function (rgb) {
  793. var reversed = reverseKeywords[rgb];
  794. if (reversed) {
  795. return reversed;
  796. }
  797. var currentClosestDistance = Infinity;
  798. var currentClosestKeyword;
  799. for (var keyword in colorName) {
  800. if (colorName.hasOwnProperty(keyword)) {
  801. var value = colorName[keyword]; // Compute comparative distance
  802. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  803. if (distance < currentClosestDistance) {
  804. currentClosestDistance = distance;
  805. currentClosestKeyword = keyword;
  806. }
  807. }
  808. }
  809. return currentClosestKeyword;
  810. };
  811. convert.keyword.rgb = function (keyword) {
  812. return colorName[keyword];
  813. };
  814. convert.rgb.xyz = function (rgb) {
  815. var r = rgb[0] / 255;
  816. var g = rgb[1] / 255;
  817. var b = rgb[2] / 255; // assume sRGB
  818. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  819. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  820. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  821. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  822. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  823. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  824. return [x * 100, y * 100, z * 100];
  825. };
  826. convert.rgb.lab = function (rgb) {
  827. var xyz = convert.rgb.xyz(rgb);
  828. var x = xyz[0];
  829. var y = xyz[1];
  830. var z = xyz[2];
  831. var l;
  832. var a;
  833. var b;
  834. x /= 95.047;
  835. y /= 100;
  836. z /= 108.883;
  837. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  838. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  839. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  840. l = 116 * y - 16;
  841. a = 500 * (x - y);
  842. b = 200 * (y - z);
  843. return [l, a, b];
  844. };
  845. convert.hsl.rgb = function (hsl) {
  846. var h = hsl[0] / 360;
  847. var s = hsl[1] / 100;
  848. var l = hsl[2] / 100;
  849. var t1;
  850. var t2;
  851. var t3;
  852. var rgb;
  853. var val;
  854. if (s === 0) {
  855. val = l * 255;
  856. return [val, val, val];
  857. }
  858. if (l < 0.5) {
  859. t2 = l * (1 + s);
  860. } else {
  861. t2 = l + s - l * s;
  862. }
  863. t1 = 2 * l - t2;
  864. rgb = [0, 0, 0];
  865. for (var i = 0; i < 3; i++) {
  866. t3 = h + 1 / 3 * -(i - 1);
  867. if (t3 < 0) {
  868. t3++;
  869. }
  870. if (t3 > 1) {
  871. t3--;
  872. }
  873. if (6 * t3 < 1) {
  874. val = t1 + (t2 - t1) * 6 * t3;
  875. } else if (2 * t3 < 1) {
  876. val = t2;
  877. } else if (3 * t3 < 2) {
  878. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  879. } else {
  880. val = t1;
  881. }
  882. rgb[i] = val * 255;
  883. }
  884. return rgb;
  885. };
  886. convert.hsl.hsv = function (hsl) {
  887. var h = hsl[0];
  888. var s = hsl[1] / 100;
  889. var l = hsl[2] / 100;
  890. var smin = s;
  891. var lmin = Math.max(l, 0.01);
  892. var sv;
  893. var v;
  894. l *= 2;
  895. s *= l <= 1 ? l : 2 - l;
  896. smin *= lmin <= 1 ? lmin : 2 - lmin;
  897. v = (l + s) / 2;
  898. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  899. return [h, sv * 100, v * 100];
  900. };
  901. convert.hsv.rgb = function (hsv) {
  902. var h = hsv[0] / 60;
  903. var s = hsv[1] / 100;
  904. var v = hsv[2] / 100;
  905. var hi = Math.floor(h) % 6;
  906. var f = h - Math.floor(h);
  907. var p = 255 * v * (1 - s);
  908. var q = 255 * v * (1 - s * f);
  909. var t = 255 * v * (1 - s * (1 - f));
  910. v *= 255;
  911. switch (hi) {
  912. case 0:
  913. return [v, t, p];
  914. case 1:
  915. return [q, v, p];
  916. case 2:
  917. return [p, v, t];
  918. case 3:
  919. return [p, q, v];
  920. case 4:
  921. return [t, p, v];
  922. case 5:
  923. return [v, p, q];
  924. }
  925. };
  926. convert.hsv.hsl = function (hsv) {
  927. var h = hsv[0];
  928. var s = hsv[1] / 100;
  929. var v = hsv[2] / 100;
  930. var vmin = Math.max(v, 0.01);
  931. var lmin;
  932. var sl;
  933. var l;
  934. l = (2 - s) * v;
  935. lmin = (2 - s) * vmin;
  936. sl = s * vmin;
  937. sl /= lmin <= 1 ? lmin : 2 - lmin;
  938. sl = sl || 0;
  939. l /= 2;
  940. return [h, sl * 100, l * 100];
  941. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  942. convert.hwb.rgb = function (hwb) {
  943. var h = hwb[0] / 360;
  944. var wh = hwb[1] / 100;
  945. var bl = hwb[2] / 100;
  946. var ratio = wh + bl;
  947. var i;
  948. var v;
  949. var f;
  950. var n; // wh + bl cant be > 1
  951. if (ratio > 1) {
  952. wh /= ratio;
  953. bl /= ratio;
  954. }
  955. i = Math.floor(6 * h);
  956. v = 1 - bl;
  957. f = 6 * h - i;
  958. if ((i & 0x01) !== 0) {
  959. f = 1 - f;
  960. }
  961. n = wh + f * (v - wh); // linear interpolation
  962. var r;
  963. var g;
  964. var b;
  965. switch (i) {
  966. default:
  967. case 6:
  968. case 0:
  969. r = v;
  970. g = n;
  971. b = wh;
  972. break;
  973. case 1:
  974. r = n;
  975. g = v;
  976. b = wh;
  977. break;
  978. case 2:
  979. r = wh;
  980. g = v;
  981. b = n;
  982. break;
  983. case 3:
  984. r = wh;
  985. g = n;
  986. b = v;
  987. break;
  988. case 4:
  989. r = n;
  990. g = wh;
  991. b = v;
  992. break;
  993. case 5:
  994. r = v;
  995. g = wh;
  996. b = n;
  997. break;
  998. }
  999. return [r * 255, g * 255, b * 255];
  1000. };
  1001. convert.cmyk.rgb = function (cmyk) {
  1002. var c = cmyk[0] / 100;
  1003. var m = cmyk[1] / 100;
  1004. var y = cmyk[2] / 100;
  1005. var k = cmyk[3] / 100;
  1006. var r;
  1007. var g;
  1008. var b;
  1009. r = 1 - Math.min(1, c * (1 - k) + k);
  1010. g = 1 - Math.min(1, m * (1 - k) + k);
  1011. b = 1 - Math.min(1, y * (1 - k) + k);
  1012. return [r * 255, g * 255, b * 255];
  1013. };
  1014. convert.xyz.rgb = function (xyz) {
  1015. var x = xyz[0] / 100;
  1016. var y = xyz[1] / 100;
  1017. var z = xyz[2] / 100;
  1018. var r;
  1019. var g;
  1020. var b;
  1021. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  1022. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  1023. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  1024. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  1025. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  1026. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  1027. r = Math.min(Math.max(0, r), 1);
  1028. g = Math.min(Math.max(0, g), 1);
  1029. b = Math.min(Math.max(0, b), 1);
  1030. return [r * 255, g * 255, b * 255];
  1031. };
  1032. convert.xyz.lab = function (xyz) {
  1033. var x = xyz[0];
  1034. var y = xyz[1];
  1035. var z = xyz[2];
  1036. var l;
  1037. var a;
  1038. var b;
  1039. x /= 95.047;
  1040. y /= 100;
  1041. z /= 108.883;
  1042. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  1043. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  1044. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  1045. l = 116 * y - 16;
  1046. a = 500 * (x - y);
  1047. b = 200 * (y - z);
  1048. return [l, a, b];
  1049. };
  1050. convert.lab.xyz = function (lab) {
  1051. var l = lab[0];
  1052. var a = lab[1];
  1053. var b = lab[2];
  1054. var x;
  1055. var y;
  1056. var z;
  1057. y = (l + 16) / 116;
  1058. x = a / 500 + y;
  1059. z = y - b / 200;
  1060. var y2 = Math.pow(y, 3);
  1061. var x2 = Math.pow(x, 3);
  1062. var z2 = Math.pow(z, 3);
  1063. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  1064. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  1065. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  1066. x *= 95.047;
  1067. y *= 100;
  1068. z *= 108.883;
  1069. return [x, y, z];
  1070. };
  1071. convert.lab.lch = function (lab) {
  1072. var l = lab[0];
  1073. var a = lab[1];
  1074. var b = lab[2];
  1075. var hr;
  1076. var h;
  1077. var c;
  1078. hr = Math.atan2(b, a);
  1079. h = hr * 360 / 2 / Math.PI;
  1080. if (h < 0) {
  1081. h += 360;
  1082. }
  1083. c = Math.sqrt(a * a + b * b);
  1084. return [l, c, h];
  1085. };
  1086. convert.lch.lab = function (lch) {
  1087. var l = lch[0];
  1088. var c = lch[1];
  1089. var h = lch[2];
  1090. var a;
  1091. var b;
  1092. var hr;
  1093. hr = h / 360 * 2 * Math.PI;
  1094. a = c * Math.cos(hr);
  1095. b = c * Math.sin(hr);
  1096. return [l, a, b];
  1097. };
  1098. convert.rgb.ansi16 = function (args) {
  1099. var r = args[0];
  1100. var g = args[1];
  1101. var b = args[2];
  1102. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  1103. value = Math.round(value / 50);
  1104. if (value === 0) {
  1105. return 30;
  1106. }
  1107. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  1108. if (value === 2) {
  1109. ansi += 60;
  1110. }
  1111. return ansi;
  1112. };
  1113. convert.hsv.ansi16 = function (args) {
  1114. // optimization here; we already know the value and don't need to get
  1115. // it converted for us.
  1116. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  1117. };
  1118. convert.rgb.ansi256 = function (args) {
  1119. var r = args[0];
  1120. var g = args[1];
  1121. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  1122. // black and white. normal palette only has 4 greyscale shades.
  1123. if (r === g && g === b) {
  1124. if (r < 8) {
  1125. return 16;
  1126. }
  1127. if (r > 248) {
  1128. return 231;
  1129. }
  1130. return Math.round((r - 8) / 247 * 24) + 232;
  1131. }
  1132. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  1133. return ansi;
  1134. };
  1135. convert.ansi16.rgb = function (args) {
  1136. var color = args % 10; // handle greyscale
  1137. if (color === 0 || color === 7) {
  1138. if (args > 50) {
  1139. color += 3.5;
  1140. }
  1141. color = color / 10.5 * 255;
  1142. return [color, color, color];
  1143. }
  1144. var mult = (~~(args > 50) + 1) * 0.5;
  1145. var r = (color & 1) * mult * 255;
  1146. var g = (color >> 1 & 1) * mult * 255;
  1147. var b = (color >> 2 & 1) * mult * 255;
  1148. return [r, g, b];
  1149. };
  1150. convert.ansi256.rgb = function (args) {
  1151. // handle greyscale
  1152. if (args >= 232) {
  1153. var c = (args - 232) * 10 + 8;
  1154. return [c, c, c];
  1155. }
  1156. args -= 16;
  1157. var rem;
  1158. var r = Math.floor(args / 36) / 5 * 255;
  1159. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  1160. var b = rem % 6 / 5 * 255;
  1161. return [r, g, b];
  1162. };
  1163. convert.rgb.hex = function (args) {
  1164. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  1165. var string = integer.toString(16).toUpperCase();
  1166. return '000000'.substring(string.length) + string;
  1167. };
  1168. convert.hex.rgb = function (args) {
  1169. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  1170. if (!match) {
  1171. return [0, 0, 0];
  1172. }
  1173. var colorString = match[0];
  1174. if (match[0].length === 3) {
  1175. colorString = colorString.split('').map(function (char) {
  1176. return char + char;
  1177. }).join('');
  1178. }
  1179. var integer = parseInt(colorString, 16);
  1180. var r = integer >> 16 & 0xFF;
  1181. var g = integer >> 8 & 0xFF;
  1182. var b = integer & 0xFF;
  1183. return [r, g, b];
  1184. };
  1185. convert.rgb.hcg = function (rgb) {
  1186. var r = rgb[0] / 255;
  1187. var g = rgb[1] / 255;
  1188. var b = rgb[2] / 255;
  1189. var max = Math.max(Math.max(r, g), b);
  1190. var min = Math.min(Math.min(r, g), b);
  1191. var chroma = max - min;
  1192. var grayscale;
  1193. var hue;
  1194. if (chroma < 1) {
  1195. grayscale = min / (1 - chroma);
  1196. } else {
  1197. grayscale = 0;
  1198. }
  1199. if (chroma <= 0) {
  1200. hue = 0;
  1201. } else if (max === r) {
  1202. hue = (g - b) / chroma % 6;
  1203. } else if (max === g) {
  1204. hue = 2 + (b - r) / chroma;
  1205. } else {
  1206. hue = 4 + (r - g) / chroma + 4;
  1207. }
  1208. hue /= 6;
  1209. hue %= 1;
  1210. return [hue * 360, chroma * 100, grayscale * 100];
  1211. };
  1212. convert.hsl.hcg = function (hsl) {
  1213. var s = hsl[1] / 100;
  1214. var l = hsl[2] / 100;
  1215. var c = 1;
  1216. var f = 0;
  1217. if (l < 0.5) {
  1218. c = 2.0 * s * l;
  1219. } else {
  1220. c = 2.0 * s * (1.0 - l);
  1221. }
  1222. if (c < 1.0) {
  1223. f = (l - 0.5 * c) / (1.0 - c);
  1224. }
  1225. return [hsl[0], c * 100, f * 100];
  1226. };
  1227. convert.hsv.hcg = function (hsv) {
  1228. var s = hsv[1] / 100;
  1229. var v = hsv[2] / 100;
  1230. var c = s * v;
  1231. var f = 0;
  1232. if (c < 1.0) {
  1233. f = (v - c) / (1 - c);
  1234. }
  1235. return [hsv[0], c * 100, f * 100];
  1236. };
  1237. convert.hcg.rgb = function (hcg) {
  1238. var h = hcg[0] / 360;
  1239. var c = hcg[1] / 100;
  1240. var g = hcg[2] / 100;
  1241. if (c === 0.0) {
  1242. return [g * 255, g * 255, g * 255];
  1243. }
  1244. var pure = [0, 0, 0];
  1245. var hi = h % 1 * 6;
  1246. var v = hi % 1;
  1247. var w = 1 - v;
  1248. var mg = 0;
  1249. switch (Math.floor(hi)) {
  1250. case 0:
  1251. pure[0] = 1;
  1252. pure[1] = v;
  1253. pure[2] = 0;
  1254. break;
  1255. case 1:
  1256. pure[0] = w;
  1257. pure[1] = 1;
  1258. pure[2] = 0;
  1259. break;
  1260. case 2:
  1261. pure[0] = 0;
  1262. pure[1] = 1;
  1263. pure[2] = v;
  1264. break;
  1265. case 3:
  1266. pure[0] = 0;
  1267. pure[1] = w;
  1268. pure[2] = 1;
  1269. break;
  1270. case 4:
  1271. pure[0] = v;
  1272. pure[1] = 0;
  1273. pure[2] = 1;
  1274. break;
  1275. default:
  1276. pure[0] = 1;
  1277. pure[1] = 0;
  1278. pure[2] = w;
  1279. }
  1280. mg = (1.0 - c) * g;
  1281. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  1282. };
  1283. convert.hcg.hsv = function (hcg) {
  1284. var c = hcg[1] / 100;
  1285. var g = hcg[2] / 100;
  1286. var v = c + g * (1.0 - c);
  1287. var f = 0;
  1288. if (v > 0.0) {
  1289. f = c / v;
  1290. }
  1291. return [hcg[0], f * 100, v * 100];
  1292. };
  1293. convert.hcg.hsl = function (hcg) {
  1294. var c = hcg[1] / 100;
  1295. var g = hcg[2] / 100;
  1296. var l = g * (1.0 - c) + 0.5 * c;
  1297. var s = 0;
  1298. if (l > 0.0 && l < 0.5) {
  1299. s = c / (2 * l);
  1300. } else if (l >= 0.5 && l < 1.0) {
  1301. s = c / (2 * (1 - l));
  1302. }
  1303. return [hcg[0], s * 100, l * 100];
  1304. };
  1305. convert.hcg.hwb = function (hcg) {
  1306. var c = hcg[1] / 100;
  1307. var g = hcg[2] / 100;
  1308. var v = c + g * (1.0 - c);
  1309. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  1310. };
  1311. convert.hwb.hcg = function (hwb) {
  1312. var w = hwb[1] / 100;
  1313. var b = hwb[2] / 100;
  1314. var v = 1 - b;
  1315. var c = v - w;
  1316. var g = 0;
  1317. if (c < 1) {
  1318. g = (v - c) / (1 - c);
  1319. }
  1320. return [hwb[0], c * 100, g * 100];
  1321. };
  1322. convert.apple.rgb = function (apple) {
  1323. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  1324. };
  1325. convert.rgb.apple = function (rgb) {
  1326. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  1327. };
  1328. convert.gray.rgb = function (args) {
  1329. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  1330. };
  1331. convert.gray.hsl = convert.gray.hsv = function (args) {
  1332. return [0, 0, args[0]];
  1333. };
  1334. convert.gray.hwb = function (gray) {
  1335. return [0, 100, gray[0]];
  1336. };
  1337. convert.gray.cmyk = function (gray) {
  1338. return [0, 0, 0, gray[0]];
  1339. };
  1340. convert.gray.lab = function (gray) {
  1341. return [gray[0], 0, 0];
  1342. };
  1343. convert.gray.hex = function (gray) {
  1344. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  1345. var integer = (val << 16) + (val << 8) + val;
  1346. var string = integer.toString(16).toUpperCase();
  1347. return '000000'.substring(string.length) + string;
  1348. };
  1349. convert.rgb.gray = function (rgb) {
  1350. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  1351. return [val / 255 * 100];
  1352. };
  1353. });
  1354. /*
  1355. this function routes a model to all other models.
  1356. all functions that are routed have a property `.conversion` attached
  1357. to the returned synthetic function. This property is an array
  1358. of strings, each with the steps in between the 'from' and 'to'
  1359. color models (inclusive).
  1360. conversions that are not possible simply are not included.
  1361. */
  1362. function buildGraph() {
  1363. var graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  1364. var models = Object.keys(conversions);
  1365. for (var len = models.length, i = 0; i < len; i++) {
  1366. graph[models[i]] = {
  1367. // http://jsperf.com/1-vs-infinity
  1368. // micro-opt, but this is simple.
  1369. distance: -1,
  1370. parent: null
  1371. };
  1372. }
  1373. return graph;
  1374. } // https://en.wikipedia.org/wiki/Breadth-first_search
  1375. function deriveBFS(fromModel) {
  1376. var graph = buildGraph();
  1377. var queue = [fromModel]; // unshift -> queue -> pop
  1378. graph[fromModel].distance = 0;
  1379. while (queue.length) {
  1380. var current = queue.pop();
  1381. var adjacents = Object.keys(conversions[current]);
  1382. for (var len = adjacents.length, i = 0; i < len; i++) {
  1383. var adjacent = adjacents[i];
  1384. var node = graph[adjacent];
  1385. if (node.distance === -1) {
  1386. node.distance = graph[current].distance + 1;
  1387. node.parent = current;
  1388. queue.unshift(adjacent);
  1389. }
  1390. }
  1391. }
  1392. return graph;
  1393. }
  1394. function link(from, to) {
  1395. return function (args) {
  1396. return to(from(args));
  1397. };
  1398. }
  1399. function wrapConversion(toModel, graph) {
  1400. var path = [graph[toModel].parent, toModel];
  1401. var fn = conversions[graph[toModel].parent][toModel];
  1402. var cur = graph[toModel].parent;
  1403. while (graph[cur].parent) {
  1404. path.unshift(graph[cur].parent);
  1405. fn = link(conversions[graph[cur].parent][cur], fn);
  1406. cur = graph[cur].parent;
  1407. }
  1408. fn.conversion = path;
  1409. return fn;
  1410. }
  1411. var route = function (fromModel) {
  1412. var graph = deriveBFS(fromModel);
  1413. var conversion = {};
  1414. var models = Object.keys(graph);
  1415. for (var len = models.length, i = 0; i < len; i++) {
  1416. var toModel = models[i];
  1417. var node = graph[toModel];
  1418. if (node.parent === null) {
  1419. // no possible conversion, or this node is the source model.
  1420. continue;
  1421. }
  1422. conversion[toModel] = wrapConversion(toModel, graph);
  1423. }
  1424. return conversion;
  1425. };
  1426. var convert = {};
  1427. var models = Object.keys(conversions);
  1428. function wrapRaw(fn) {
  1429. var wrappedFn = function (args) {
  1430. if (args === undefined || args === null) {
  1431. return args;
  1432. }
  1433. if (arguments.length > 1) {
  1434. args = Array.prototype.slice.call(arguments);
  1435. }
  1436. return fn(args);
  1437. }; // preserve .conversion property if there is one
  1438. if ('conversion' in fn) {
  1439. wrappedFn.conversion = fn.conversion;
  1440. }
  1441. return wrappedFn;
  1442. }
  1443. function wrapRounded(fn) {
  1444. var wrappedFn = function (args) {
  1445. if (args === undefined || args === null) {
  1446. return args;
  1447. }
  1448. if (arguments.length > 1) {
  1449. args = Array.prototype.slice.call(arguments);
  1450. }
  1451. var result = fn(args); // we're assuming the result is an array here.
  1452. // see notice in conversions.js; don't use box types
  1453. // in conversion functions.
  1454. if (typeof result === 'object') {
  1455. for (var len = result.length, i = 0; i < len; i++) {
  1456. result[i] = Math.round(result[i]);
  1457. }
  1458. }
  1459. return result;
  1460. }; // preserve .conversion property if there is one
  1461. if ('conversion' in fn) {
  1462. wrappedFn.conversion = fn.conversion;
  1463. }
  1464. return wrappedFn;
  1465. }
  1466. models.forEach(function (fromModel) {
  1467. convert[fromModel] = {};
  1468. Object.defineProperty(convert[fromModel], 'channels', {
  1469. value: conversions[fromModel].channels
  1470. });
  1471. Object.defineProperty(convert[fromModel], 'labels', {
  1472. value: conversions[fromModel].labels
  1473. });
  1474. var routes = route(fromModel);
  1475. var routeModels = Object.keys(routes);
  1476. routeModels.forEach(function (toModel) {
  1477. var fn = routes[toModel];
  1478. convert[fromModel][toModel] = wrapRounded(fn);
  1479. convert[fromModel][toModel].raw = wrapRaw(fn);
  1480. });
  1481. });
  1482. var colorConvert = convert;
  1483. var ansiStyles = createCommonjsModule(function (module) {
  1484. const wrapAnsi16 = (fn, offset) => function () {
  1485. const code = fn.apply(colorConvert, arguments);
  1486. return `\u001B[${code + offset}m`;
  1487. };
  1488. const wrapAnsi256 = (fn, offset) => function () {
  1489. const code = fn.apply(colorConvert, arguments);
  1490. return `\u001B[${38 + offset};5;${code}m`;
  1491. };
  1492. const wrapAnsi16m = (fn, offset) => function () {
  1493. const rgb = fn.apply(colorConvert, arguments);
  1494. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  1495. };
  1496. function assembleStyles() {
  1497. const codes = new Map();
  1498. const styles = {
  1499. modifier: {
  1500. reset: [0, 0],
  1501. // 21 isn't widely supported and 22 does the same thing
  1502. bold: [1, 22],
  1503. dim: [2, 22],
  1504. italic: [3, 23],
  1505. underline: [4, 24],
  1506. inverse: [7, 27],
  1507. hidden: [8, 28],
  1508. strikethrough: [9, 29]
  1509. },
  1510. color: {
  1511. black: [30, 39],
  1512. red: [31, 39],
  1513. green: [32, 39],
  1514. yellow: [33, 39],
  1515. blue: [34, 39],
  1516. magenta: [35, 39],
  1517. cyan: [36, 39],
  1518. white: [37, 39],
  1519. gray: [90, 39],
  1520. // Bright color
  1521. redBright: [91, 39],
  1522. greenBright: [92, 39],
  1523. yellowBright: [93, 39],
  1524. blueBright: [94, 39],
  1525. magentaBright: [95, 39],
  1526. cyanBright: [96, 39],
  1527. whiteBright: [97, 39]
  1528. },
  1529. bgColor: {
  1530. bgBlack: [40, 49],
  1531. bgRed: [41, 49],
  1532. bgGreen: [42, 49],
  1533. bgYellow: [43, 49],
  1534. bgBlue: [44, 49],
  1535. bgMagenta: [45, 49],
  1536. bgCyan: [46, 49],
  1537. bgWhite: [47, 49],
  1538. // Bright color
  1539. bgBlackBright: [100, 49],
  1540. bgRedBright: [101, 49],
  1541. bgGreenBright: [102, 49],
  1542. bgYellowBright: [103, 49],
  1543. bgBlueBright: [104, 49],
  1544. bgMagentaBright: [105, 49],
  1545. bgCyanBright: [106, 49],
  1546. bgWhiteBright: [107, 49]
  1547. }
  1548. }; // Fix humans
  1549. styles.color.grey = styles.color.gray;
  1550. for (const groupName of Object.keys(styles)) {
  1551. const group = styles[groupName];
  1552. for (const styleName of Object.keys(group)) {
  1553. const style = group[styleName];
  1554. styles[styleName] = {
  1555. open: `\u001B[${style[0]}m`,
  1556. close: `\u001B[${style[1]}m`
  1557. };
  1558. group[styleName] = styles[styleName];
  1559. codes.set(style[0], style[1]);
  1560. }
  1561. Object.defineProperty(styles, groupName, {
  1562. value: group,
  1563. enumerable: false
  1564. });
  1565. Object.defineProperty(styles, 'codes', {
  1566. value: codes,
  1567. enumerable: false
  1568. });
  1569. }
  1570. const ansi2ansi = n => n;
  1571. const rgb2rgb = (r, g, b) => [r, g, b];
  1572. styles.color.close = '\u001B[39m';
  1573. styles.bgColor.close = '\u001B[49m';
  1574. styles.color.ansi = {
  1575. ansi: wrapAnsi16(ansi2ansi, 0)
  1576. };
  1577. styles.color.ansi256 = {
  1578. ansi256: wrapAnsi256(ansi2ansi, 0)
  1579. };
  1580. styles.color.ansi16m = {
  1581. rgb: wrapAnsi16m(rgb2rgb, 0)
  1582. };
  1583. styles.bgColor.ansi = {
  1584. ansi: wrapAnsi16(ansi2ansi, 10)
  1585. };
  1586. styles.bgColor.ansi256 = {
  1587. ansi256: wrapAnsi256(ansi2ansi, 10)
  1588. };
  1589. styles.bgColor.ansi16m = {
  1590. rgb: wrapAnsi16m(rgb2rgb, 10)
  1591. };
  1592. for (let key of Object.keys(colorConvert)) {
  1593. if (typeof colorConvert[key] !== 'object') {
  1594. continue;
  1595. }
  1596. const suite = colorConvert[key];
  1597. if (key === 'ansi16') {
  1598. key = 'ansi';
  1599. }
  1600. if ('ansi16' in suite) {
  1601. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  1602. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  1603. }
  1604. if ('ansi256' in suite) {
  1605. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  1606. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  1607. }
  1608. if ('rgb' in suite) {
  1609. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  1610. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  1611. }
  1612. }
  1613. return styles;
  1614. } // Make the export immutable
  1615. Object.defineProperty(module, 'exports', {
  1616. enumerable: true,
  1617. get: assembleStyles
  1618. });
  1619. });
  1620. var hasFlag = (flag, argv) => {
  1621. argv = argv || process.argv;
  1622. const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  1623. const pos = argv.indexOf(prefix + flag);
  1624. const terminatorPos = argv.indexOf('--');
  1625. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  1626. };
  1627. const env = process.env;
  1628. let forceColor;
  1629. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  1630. forceColor = false;
  1631. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  1632. forceColor = true;
  1633. }
  1634. if ('FORCE_COLOR' in env) {
  1635. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  1636. }
  1637. function translateLevel(level) {
  1638. if (level === 0) {
  1639. return false;
  1640. }
  1641. return {
  1642. level,
  1643. hasBasic: true,
  1644. has256: level >= 2,
  1645. has16m: level >= 3
  1646. };
  1647. }
  1648. function supportsColor(stream) {
  1649. if (forceColor === false) {
  1650. return 0;
  1651. }
  1652. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  1653. return 3;
  1654. }
  1655. if (hasFlag('color=256')) {
  1656. return 2;
  1657. }
  1658. if (stream && !stream.isTTY && forceColor !== true) {
  1659. return 0;
  1660. }
  1661. const min = forceColor ? 1 : 0;
  1662. if (process.platform === 'win32') {
  1663. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  1664. // libuv that enables 256 color output on Windows. Anything earlier and it
  1665. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  1666. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  1667. // release that supports 256 colors. Windows 10 build 14931 is the first release
  1668. // that supports 16m/TrueColor.
  1669. const osRelease = os__default['default'].release().split('.');
  1670. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  1671. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  1672. }
  1673. return 1;
  1674. }
  1675. if ('CI' in env) {
  1676. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
  1677. return 1;
  1678. }
  1679. return min;
  1680. }
  1681. if ('TEAMCITY_VERSION' in env) {
  1682. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  1683. }
  1684. if (env.COLORTERM === 'truecolor') {
  1685. return 3;
  1686. }
  1687. if ('TERM_PROGRAM' in env) {
  1688. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  1689. switch (env.TERM_PROGRAM) {
  1690. case 'iTerm.app':
  1691. return version >= 3 ? 3 : 2;
  1692. case 'Apple_Terminal':
  1693. return 2;
  1694. // No default
  1695. }
  1696. }
  1697. if (/-256(color)?$/i.test(env.TERM)) {
  1698. return 2;
  1699. }
  1700. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  1701. return 1;
  1702. }
  1703. if ('COLORTERM' in env) {
  1704. return 1;
  1705. }
  1706. if (env.TERM === 'dumb') {
  1707. return min;
  1708. }
  1709. return min;
  1710. }
  1711. function getSupportLevel(stream) {
  1712. const level = supportsColor(stream);
  1713. return translateLevel(level);
  1714. }
  1715. var supportsColor_1 = {
  1716. supportsColor: getSupportLevel,
  1717. stdout: getSupportLevel(process.stdout),
  1718. stderr: getSupportLevel(process.stderr)
  1719. };
  1720. const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  1721. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  1722. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  1723. const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  1724. const ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  1725. function unescape(c) {
  1726. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  1727. return String.fromCharCode(parseInt(c.slice(1), 16));
  1728. }
  1729. return ESCAPES.get(c) || c;
  1730. }
  1731. function parseArguments(name, args) {
  1732. const results = [];
  1733. const chunks = args.trim().split(/\s*,\s*/g);
  1734. let matches;
  1735. for (const chunk of chunks) {
  1736. if (!isNaN(chunk)) {
  1737. results.push(Number(chunk));
  1738. } else if (matches = chunk.match(STRING_REGEX)) {
  1739. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
  1740. } else {
  1741. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  1742. }
  1743. }
  1744. return results;
  1745. }
  1746. function parseStyle(style) {
  1747. STYLE_REGEX.lastIndex = 0;
  1748. const results = [];
  1749. let matches;
  1750. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  1751. const name = matches[1];
  1752. if (matches[2]) {
  1753. const args = parseArguments(name, matches[2]);
  1754. results.push([name].concat(args));
  1755. } else {
  1756. results.push([name]);
  1757. }
  1758. }
  1759. return results;
  1760. }
  1761. function buildStyle(chalk, styles) {
  1762. const enabled = {};
  1763. for (const layer of styles) {
  1764. for (const style of layer.styles) {
  1765. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  1766. }
  1767. }
  1768. let current = chalk;
  1769. for (const styleName of Object.keys(enabled)) {
  1770. if (Array.isArray(enabled[styleName])) {
  1771. if (!(styleName in current)) {
  1772. throw new Error(`Unknown Chalk style: ${styleName}`);
  1773. }
  1774. if (enabled[styleName].length > 0) {
  1775. current = current[styleName].apply(current, enabled[styleName]);
  1776. } else {
  1777. current = current[styleName];
  1778. }
  1779. }
  1780. }
  1781. return current;
  1782. }
  1783. var templates = (chalk, tmp) => {
  1784. const styles = [];
  1785. const chunks = [];
  1786. let chunk = []; // eslint-disable-next-line max-params
  1787. tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
  1788. if (escapeChar) {
  1789. chunk.push(unescape(escapeChar));
  1790. } else if (style) {
  1791. const str = chunk.join('');
  1792. chunk = [];
  1793. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  1794. styles.push({
  1795. inverse,
  1796. styles: parseStyle(style)
  1797. });
  1798. } else if (close) {
  1799. if (styles.length === 0) {
  1800. throw new Error('Found extraneous } in Chalk template literal');
  1801. }
  1802. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  1803. chunk = [];
  1804. styles.pop();
  1805. } else {
  1806. chunk.push(chr);
  1807. }
  1808. });
  1809. chunks.push(chunk.join(''));
  1810. if (styles.length > 0) {
  1811. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  1812. throw new Error(errMsg);
  1813. }
  1814. return chunks.join('');
  1815. };
  1816. var chalk = createCommonjsModule(function (module) {
  1817. const stdoutColor = supportsColor_1.stdout;
  1818. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  1819. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  1820. const skipModels = new Set(['gray']);
  1821. const styles = Object.create(null);
  1822. function applyOptions(obj, options) {
  1823. options = options || {}; // Detect level if not set manually
  1824. const scLevel = stdoutColor ? stdoutColor.level : 0;
  1825. obj.level = options.level === undefined ? scLevel : options.level;
  1826. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  1827. }
  1828. function Chalk(options) {
  1829. // We check for this.template here since calling `chalk.constructor()`
  1830. // by itself will have a `this` of a previously constructed chalk object
  1831. if (!this || !(this instanceof Chalk) || this.template) {
  1832. const chalk = {};
  1833. applyOptions(chalk, options);
  1834. chalk.template = function () {
  1835. const args = [].slice.call(arguments);
  1836. return chalkTag.apply(null, [chalk.template].concat(args));
  1837. };
  1838. Object.setPrototypeOf(chalk, Chalk.prototype);
  1839. Object.setPrototypeOf(chalk.template, chalk);
  1840. chalk.template.constructor = Chalk;
  1841. return chalk.template;
  1842. }
  1843. applyOptions(this, options);
  1844. } // Use bright blue on Windows as the normal blue color is illegible
  1845. if (isSimpleWindowsTerm) {
  1846. ansiStyles.blue.open = '\u001B[94m';
  1847. }
  1848. for (const key of Object.keys(ansiStyles)) {
  1849. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  1850. styles[key] = {
  1851. get() {
  1852. const codes = ansiStyles[key];
  1853. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  1854. }
  1855. };
  1856. }
  1857. styles.visible = {
  1858. get() {
  1859. return build.call(this, this._styles || [], true, 'visible');
  1860. }
  1861. };
  1862. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  1863. for (const model of Object.keys(ansiStyles.color.ansi)) {
  1864. if (skipModels.has(model)) {
  1865. continue;
  1866. }
  1867. styles[model] = {
  1868. get() {
  1869. const level = this.level;
  1870. return function () {
  1871. const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  1872. const codes = {
  1873. open,
  1874. close: ansiStyles.color.close,
  1875. closeRe: ansiStyles.color.closeRe
  1876. };
  1877. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  1878. };
  1879. }
  1880. };
  1881. }
  1882. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  1883. for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
  1884. if (skipModels.has(model)) {
  1885. continue;
  1886. }
  1887. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  1888. styles[bgModel] = {
  1889. get() {
  1890. const level = this.level;
  1891. return function () {
  1892. const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  1893. const codes = {
  1894. open,
  1895. close: ansiStyles.bgColor.close,
  1896. closeRe: ansiStyles.bgColor.closeRe
  1897. };
  1898. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  1899. };
  1900. }
  1901. };
  1902. }
  1903. const proto = Object.defineProperties(() => {}, styles);
  1904. function build(_styles, _empty, key) {
  1905. const builder = function () {
  1906. return applyStyle.apply(builder, arguments);
  1907. };
  1908. builder._styles = _styles;
  1909. builder._empty = _empty;
  1910. const self = this;
  1911. Object.defineProperty(builder, 'level', {
  1912. enumerable: true,
  1913. get() {
  1914. return self.level;
  1915. },
  1916. set(level) {
  1917. self.level = level;
  1918. }
  1919. });
  1920. Object.defineProperty(builder, 'enabled', {
  1921. enumerable: true,
  1922. get() {
  1923. return self.enabled;
  1924. },
  1925. set(enabled) {
  1926. self.enabled = enabled;
  1927. }
  1928. }); // See below for fix regarding invisible grey/dim combination on Windows
  1929. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  1930. // no way to create a function with a different prototype
  1931. builder.__proto__ = proto; // eslint-disable-line no-proto
  1932. return builder;
  1933. }
  1934. function applyStyle() {
  1935. // Support varags, but simply cast to string in case there's only one arg
  1936. const args = arguments;
  1937. const argsLen = args.length;
  1938. let str = String(arguments[0]);
  1939. if (argsLen === 0) {
  1940. return '';
  1941. }
  1942. if (argsLen > 1) {
  1943. // Don't slice `arguments`, it prevents V8 optimizations
  1944. for (let a = 1; a < argsLen; a++) {
  1945. str += ' ' + args[a];
  1946. }
  1947. }
  1948. if (!this.enabled || this.level <= 0 || !str) {
  1949. return this._empty ? '' : str;
  1950. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  1951. // see https://github.com/chalk/chalk/issues/58
  1952. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  1953. const originalDim = ansiStyles.dim.open;
  1954. if (isSimpleWindowsTerm && this.hasGrey) {
  1955. ansiStyles.dim.open = '';
  1956. }
  1957. for (const code of this._styles.slice().reverse()) {
  1958. // Replace any instances already present with a re-opening code
  1959. // otherwise only the part of the string until said closing code
  1960. // will be colored, and the rest will simply be 'plain'.
  1961. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  1962. // after next line to fix a bleed issue on macOS
  1963. // https://github.com/chalk/chalk/pull/92
  1964. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  1965. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  1966. ansiStyles.dim.open = originalDim;
  1967. return str;
  1968. }
  1969. function chalkTag(chalk, strings) {
  1970. if (!Array.isArray(strings)) {
  1971. // If chalk() was called by itself or with a string,
  1972. // return the string itself as a string.
  1973. return [].slice.call(arguments, 1).join(' ');
  1974. }
  1975. const args = [].slice.call(arguments, 2);
  1976. const parts = [strings.raw[0]];
  1977. for (let i = 1; i < strings.length; i++) {
  1978. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  1979. parts.push(String(strings.raw[i]));
  1980. }
  1981. return templates(chalk, parts.join(''));
  1982. }
  1983. Object.defineProperties(Chalk.prototype, styles);
  1984. module.exports = Chalk(); // eslint-disable-line new-cap
  1985. module.exports.supportsColor = stdoutColor;
  1986. module.exports.default = module.exports; // For TypeScript
  1987. });
  1988. var lib$1 = createCommonjsModule(function (module, exports) {
  1989. Object.defineProperty(exports, "__esModule", {
  1990. value: true
  1991. });
  1992. exports.shouldHighlight = shouldHighlight;
  1993. exports.getChalk = getChalk;
  1994. exports.default = highlight;
  1995. var _jsTokens = _interopRequireWildcard(jsTokens);
  1996. var _chalk = _interopRequireDefault(chalk);
  1997. function _interopRequireDefault(obj) {
  1998. return obj && obj.__esModule ? obj : {
  1999. default: obj
  2000. };
  2001. }
  2002. function _getRequireWildcardCache() {
  2003. if (typeof WeakMap !== "function") return null;
  2004. var cache = new WeakMap();
  2005. _getRequireWildcardCache = function () {
  2006. return cache;
  2007. };
  2008. return cache;
  2009. }
  2010. function _interopRequireWildcard(obj) {
  2011. if (obj && obj.__esModule) {
  2012. return obj;
  2013. }
  2014. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  2015. return {
  2016. default: obj
  2017. };
  2018. }
  2019. var cache = _getRequireWildcardCache();
  2020. if (cache && cache.has(obj)) {
  2021. return cache.get(obj);
  2022. }
  2023. var newObj = {};
  2024. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  2025. for (var key in obj) {
  2026. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  2027. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  2028. if (desc && (desc.get || desc.set)) {
  2029. Object.defineProperty(newObj, key, desc);
  2030. } else {
  2031. newObj[key] = obj[key];
  2032. }
  2033. }
  2034. }
  2035. newObj.default = obj;
  2036. if (cache) {
  2037. cache.set(obj, newObj);
  2038. }
  2039. return newObj;
  2040. }
  2041. function getDefs(chalk) {
  2042. return {
  2043. keyword: chalk.cyan,
  2044. capitalized: chalk.yellow,
  2045. jsx_tag: chalk.yellow,
  2046. punctuator: chalk.yellow,
  2047. number: chalk.magenta,
  2048. string: chalk.green,
  2049. regex: chalk.magenta,
  2050. comment: chalk.grey,
  2051. invalid: chalk.white.bgRed.bold
  2052. };
  2053. }
  2054. const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  2055. const JSX_TAG = /^[a-z][\w-]*$/i;
  2056. const BRACKET = /^[()[\]{}]$/;
  2057. function getTokenType(match) {
  2058. const [offset, text] = match.slice(-2);
  2059. const token = (0, _jsTokens.matchToToken)(match);
  2060. if (token.type === "name") {
  2061. if ((0, lib.isKeyword)(token.value) || (0, lib.isReservedWord)(token.value)) {
  2062. return "keyword";
  2063. }
  2064. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  2065. return "jsx_tag";
  2066. }
  2067. if (token.value[0] !== token.value[0].toLowerCase()) {
  2068. return "capitalized";
  2069. }
  2070. }
  2071. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  2072. return "bracket";
  2073. }
  2074. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  2075. return "punctuator";
  2076. }
  2077. return token.type;
  2078. }
  2079. function highlightTokens(defs, text) {
  2080. return text.replace(_jsTokens.default, function (...args) {
  2081. const type = getTokenType(args);
  2082. const colorize = defs[type];
  2083. if (colorize) {
  2084. return args[0].split(NEWLINE).map(str => colorize(str)).join("\n");
  2085. } else {
  2086. return args[0];
  2087. }
  2088. });
  2089. }
  2090. function shouldHighlight(options) {
  2091. return _chalk.default.supportsColor || options.forceColor;
  2092. }
  2093. function getChalk(options) {
  2094. let chalk = _chalk.default;
  2095. if (options.forceColor) {
  2096. chalk = new _chalk.default.constructor({
  2097. enabled: true,
  2098. level: 1
  2099. });
  2100. }
  2101. return chalk;
  2102. }
  2103. function highlight(code, options = {}) {
  2104. if (shouldHighlight(options)) {
  2105. const chalk = getChalk(options);
  2106. const defs = getDefs(chalk);
  2107. return highlightTokens(defs, code);
  2108. } else {
  2109. return code;
  2110. }
  2111. }
  2112. });
  2113. var lib$2 = createCommonjsModule(function (module, exports) {
  2114. Object.defineProperty(exports, "__esModule", {
  2115. value: true
  2116. });
  2117. exports.codeFrameColumns = codeFrameColumns;
  2118. exports.default = _default;
  2119. var _highlight = _interopRequireWildcard(lib$1);
  2120. function _getRequireWildcardCache() {
  2121. if (typeof WeakMap !== "function") return null;
  2122. var cache = new WeakMap();
  2123. _getRequireWildcardCache = function () {
  2124. return cache;
  2125. };
  2126. return cache;
  2127. }
  2128. function _interopRequireWildcard(obj) {
  2129. if (obj && obj.__esModule) {
  2130. return obj;
  2131. }
  2132. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  2133. return {
  2134. default: obj
  2135. };
  2136. }
  2137. var cache = _getRequireWildcardCache();
  2138. if (cache && cache.has(obj)) {
  2139. return cache.get(obj);
  2140. }
  2141. var newObj = {};
  2142. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  2143. for (var key in obj) {
  2144. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  2145. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  2146. if (desc && (desc.get || desc.set)) {
  2147. Object.defineProperty(newObj, key, desc);
  2148. } else {
  2149. newObj[key] = obj[key];
  2150. }
  2151. }
  2152. }
  2153. newObj.default = obj;
  2154. if (cache) {
  2155. cache.set(obj, newObj);
  2156. }
  2157. return newObj;
  2158. }
  2159. let deprecationWarningShown = false;
  2160. function getDefs(chalk) {
  2161. return {
  2162. gutter: chalk.grey,
  2163. marker: chalk.red.bold,
  2164. message: chalk.red.bold
  2165. };
  2166. }
  2167. const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  2168. function getMarkerLines(loc, source, opts) {
  2169. const startLoc = Object.assign({
  2170. column: 0,
  2171. line: -1
  2172. }, loc.start);
  2173. const endLoc = Object.assign({}, startLoc, loc.end);
  2174. const {
  2175. linesAbove = 2,
  2176. linesBelow = 3
  2177. } = opts || {};
  2178. const startLine = startLoc.line;
  2179. const startColumn = startLoc.column;
  2180. const endLine = endLoc.line;
  2181. const endColumn = endLoc.column;
  2182. let start = Math.max(startLine - (linesAbove + 1), 0);
  2183. let end = Math.min(source.length, endLine + linesBelow);
  2184. if (startLine === -1) {
  2185. start = 0;
  2186. }
  2187. if (endLine === -1) {
  2188. end = source.length;
  2189. }
  2190. const lineDiff = endLine - startLine;
  2191. const markerLines = {};
  2192. if (lineDiff) {
  2193. for (let i = 0; i <= lineDiff; i++) {
  2194. const lineNumber = i + startLine;
  2195. if (!startColumn) {
  2196. markerLines[lineNumber] = true;
  2197. } else if (i === 0) {
  2198. const sourceLength = source[lineNumber - 1].length;
  2199. markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
  2200. } else if (i === lineDiff) {
  2201. markerLines[lineNumber] = [0, endColumn];
  2202. } else {
  2203. const sourceLength = source[lineNumber - i].length;
  2204. markerLines[lineNumber] = [0, sourceLength];
  2205. }
  2206. }
  2207. } else {
  2208. if (startColumn === endColumn) {
  2209. if (startColumn) {
  2210. markerLines[startLine] = [startColumn, 0];
  2211. } else {
  2212. markerLines[startLine] = true;
  2213. }
  2214. } else {
  2215. markerLines[startLine] = [startColumn, endColumn - startColumn];
  2216. }
  2217. }
  2218. return {
  2219. start,
  2220. end,
  2221. markerLines
  2222. };
  2223. }
  2224. function codeFrameColumns(rawLines, loc, opts = {}) {
  2225. const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
  2226. const chalk = (0, _highlight.getChalk)(opts);
  2227. const defs = getDefs(chalk);
  2228. const maybeHighlight = (chalkFn, string) => {
  2229. return highlighted ? chalkFn(string) : string;
  2230. };
  2231. const lines = rawLines.split(NEWLINE);
  2232. const {
  2233. start,
  2234. end,
  2235. markerLines
  2236. } = getMarkerLines(loc, lines, opts);
  2237. const hasColumns = loc.start && typeof loc.start.column === "number";
  2238. const numberMaxWidth = String(end).length;
  2239. const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines;
  2240. let frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
  2241. const number = start + 1 + index;
  2242. const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  2243. const gutter = ` ${paddedNumber} | `;
  2244. const hasMarker = markerLines[number];
  2245. const lastMarkerLine = !markerLines[number + 1];
  2246. if (hasMarker) {
  2247. let markerLine = "";
  2248. if (Array.isArray(hasMarker)) {
  2249. const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  2250. const numberOfMarkers = hasMarker[1] || 1;
  2251. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  2252. if (lastMarkerLine && opts.message) {
  2253. markerLine += " " + maybeHighlight(defs.message, opts.message);
  2254. }
  2255. }
  2256. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  2257. } else {
  2258. return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
  2259. }
  2260. }).join("\n");
  2261. if (opts.message && !hasColumns) {
  2262. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  2263. }
  2264. if (highlighted) {
  2265. return chalk.reset(frame);
  2266. } else {
  2267. return frame;
  2268. }
  2269. }
  2270. function _default(rawLines, lineNumber, colNumber, opts = {}) {
  2271. if (!deprecationWarningShown) {
  2272. deprecationWarningShown = true;
  2273. const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  2274. if (process.emitWarning) {
  2275. process.emitWarning(message, "DeprecationWarning");
  2276. } else {
  2277. const deprecationError = new Error(message);
  2278. deprecationError.name = "DeprecationWarning";
  2279. console.warn(new Error(message));
  2280. }
  2281. }
  2282. colNumber = Math.max(colNumber, 0);
  2283. const location = {
  2284. start: {
  2285. column: colNumber,
  2286. line: lineNumber
  2287. }
  2288. };
  2289. return codeFrameColumns(rawLines, location, opts);
  2290. }
  2291. });
  2292. const {
  2293. default: LinesAndColumns
  2294. } = dist;
  2295. const {
  2296. codeFrameColumns
  2297. } = lib$2;
  2298. const JSONError = errorEx_1('JSONError', {
  2299. fileName: errorEx_1.append('in %s'),
  2300. codeFrame: errorEx_1.append('\n\n%s\n')
  2301. });
  2302. var parseJson$1 = (string, reviver, filename) => {
  2303. if (typeof reviver === 'string') {
  2304. filename = reviver;
  2305. reviver = null;
  2306. }
  2307. try {
  2308. try {
  2309. return JSON.parse(string, reviver);
  2310. } catch (error) {
  2311. jsonParseBetterErrors(string, reviver);
  2312. throw error;
  2313. }
  2314. } catch (error) {
  2315. error.message = error.message.replace(/\n/g, '');
  2316. const indexMatch = error.message.match(/in JSON at position (\d+) while parsing near/);
  2317. const jsonError = new JSONError(error);
  2318. if (filename) {
  2319. jsonError.fileName = filename;
  2320. }
  2321. if (indexMatch && indexMatch.length > 0) {
  2322. const lines = new LinesAndColumns(string);
  2323. const index = Number(indexMatch[1]);
  2324. const location = lines.locationForIndex(index);
  2325. const codeFrame = codeFrameColumns(string, {
  2326. start: {
  2327. line: location.line + 1,
  2328. column: location.column + 1
  2329. }
  2330. }, {
  2331. highlightCode: true
  2332. });
  2333. jsonError.codeFrame = codeFrame;
  2334. }
  2335. throw jsonError;
  2336. }
  2337. };
  2338. const Char = {
  2339. ANCHOR: '&',
  2340. COMMENT: '#',
  2341. TAG: '!',
  2342. DIRECTIVES_END: '-',
  2343. DOCUMENT_END: '.'
  2344. };
  2345. const Type = {
  2346. ALIAS: 'ALIAS',
  2347. BLANK_LINE: 'BLANK_LINE',
  2348. BLOCK_FOLDED: 'BLOCK_FOLDED',
  2349. BLOCK_LITERAL: 'BLOCK_LITERAL',
  2350. COMMENT: 'COMMENT',
  2351. DIRECTIVE: 'DIRECTIVE',
  2352. DOCUMENT: 'DOCUMENT',
  2353. FLOW_MAP: 'FLOW_MAP',
  2354. FLOW_SEQ: 'FLOW_SEQ',
  2355. MAP: 'MAP',
  2356. MAP_KEY: 'MAP_KEY',
  2357. MAP_VALUE: 'MAP_VALUE',
  2358. PLAIN: 'PLAIN',
  2359. QUOTE_DOUBLE: 'QUOTE_DOUBLE',
  2360. QUOTE_SINGLE: 'QUOTE_SINGLE',
  2361. SEQ: 'SEQ',
  2362. SEQ_ITEM: 'SEQ_ITEM'
  2363. };
  2364. const defaultTagPrefix = 'tag:yaml.org,2002:';
  2365. const defaultTags = {
  2366. MAP: 'tag:yaml.org,2002:map',
  2367. SEQ: 'tag:yaml.org,2002:seq',
  2368. STR: 'tag:yaml.org,2002:str'
  2369. };
  2370. function findLineStarts(src) {
  2371. const ls = [0];
  2372. let offset = src.indexOf('\n');
  2373. while (offset !== -1) {
  2374. offset += 1;
  2375. ls.push(offset);
  2376. offset = src.indexOf('\n', offset);
  2377. }
  2378. return ls;
  2379. }
  2380. function getSrcInfo(cst) {
  2381. let lineStarts, src;
  2382. if (typeof cst === 'string') {
  2383. lineStarts = findLineStarts(cst);
  2384. src = cst;
  2385. } else {
  2386. if (Array.isArray(cst)) cst = cst[0];
  2387. if (cst && cst.context) {
  2388. if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src);
  2389. lineStarts = cst.lineStarts;
  2390. src = cst.context.src;
  2391. }
  2392. }
  2393. return {
  2394. lineStarts,
  2395. src
  2396. };
  2397. }
  2398. /**
  2399. * @typedef {Object} LinePos - One-indexed position in the source
  2400. * @property {number} line
  2401. * @property {number} col
  2402. */
  2403. /**
  2404. * Determine the line/col position matching a character offset.
  2405. *
  2406. * Accepts a source string or a CST document as the second parameter. With
  2407. * the latter, starting indices for lines are cached in the document as
  2408. * `lineStarts: number[]`.
  2409. *
  2410. * Returns a one-indexed `{ line, col }` location if found, or
  2411. * `undefined` otherwise.
  2412. *
  2413. * @param {number} offset
  2414. * @param {string|Document|Document[]} cst
  2415. * @returns {?LinePos}
  2416. */
  2417. function getLinePos(offset, cst) {
  2418. if (typeof offset !== 'number' || offset < 0) return null;
  2419. const {
  2420. lineStarts,
  2421. src
  2422. } = getSrcInfo(cst);
  2423. if (!lineStarts || !src || offset > src.length) return null;
  2424. for (let i = 0; i < lineStarts.length; ++i) {
  2425. const start = lineStarts[i];
  2426. if (offset < start) {
  2427. return {
  2428. line: i,
  2429. col: offset - lineStarts[i - 1] + 1
  2430. };
  2431. }
  2432. if (offset === start) return {
  2433. line: i + 1,
  2434. col: 1
  2435. };
  2436. }
  2437. const line = lineStarts.length;
  2438. return {
  2439. line,
  2440. col: offset - lineStarts[line - 1] + 1
  2441. };
  2442. }
  2443. /**
  2444. * Get a specified line from the source.
  2445. *
  2446. * Accepts a source string or a CST document as the second parameter. With
  2447. * the latter, starting indices for lines are cached in the document as
  2448. * `lineStarts: number[]`.
  2449. *
  2450. * Returns the line as a string if found, or `null` otherwise.
  2451. *
  2452. * @param {number} line One-indexed line number
  2453. * @param {string|Document|Document[]} cst
  2454. * @returns {?string}
  2455. */
  2456. function getLine(line, cst) {
  2457. const {
  2458. lineStarts,
  2459. src
  2460. } = getSrcInfo(cst);
  2461. if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null;
  2462. const start = lineStarts[line - 1];
  2463. let end = lineStarts[line]; // undefined for last line; that's ok for slice()
  2464. while (end && end > start && src[end - 1] === '\n') --end;
  2465. return src.slice(start, end);
  2466. }
  2467. /**
  2468. * Pretty-print the starting line from the source indicated by the range `pos`
  2469. *
  2470. * Trims output to `maxWidth` chars while keeping the starting column visible,
  2471. * using `…` at either end to indicate dropped characters.
  2472. *
  2473. * Returns a two-line string (or `null`) with `\n` as separator; the second line
  2474. * will hold appropriately indented `^` marks indicating the column range.
  2475. *
  2476. * @param {Object} pos
  2477. * @param {LinePos} pos.start
  2478. * @param {LinePos} [pos.end]
  2479. * @param {string|Document|Document[]*} cst
  2480. * @param {number} [maxWidth=80]
  2481. * @returns {?string}
  2482. */
  2483. function getPrettyContext({
  2484. start,
  2485. end
  2486. }, cst, maxWidth = 80) {
  2487. let src = getLine(start.line, cst);
  2488. if (!src) return null;
  2489. let {
  2490. col
  2491. } = start;
  2492. if (src.length > maxWidth) {
  2493. if (col <= maxWidth - 10) {
  2494. src = src.substr(0, maxWidth - 1) + '…';
  2495. } else {
  2496. const halfWidth = Math.round(maxWidth / 2);
  2497. if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…';
  2498. col -= src.length - maxWidth;
  2499. src = '…' + src.substr(1 - maxWidth);
  2500. }
  2501. }
  2502. let errLen = 1;
  2503. let errEnd = '';
  2504. if (end) {
  2505. if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
  2506. errLen = end.col - start.col;
  2507. } else {
  2508. errLen = Math.min(src.length + 1, maxWidth) - col;
  2509. errEnd = '…';
  2510. }
  2511. }
  2512. const offset = col > 1 ? ' '.repeat(col - 1) : '';
  2513. const err = '^'.repeat(errLen);
  2514. return `${src}\n${offset}${err}${errEnd}`;
  2515. }
  2516. class Range {
  2517. static copy(orig) {
  2518. return new Range(orig.start, orig.end);
  2519. }
  2520. constructor(start, end) {
  2521. this.start = start;
  2522. this.end = end || start;
  2523. }
  2524. isEmpty() {
  2525. return typeof this.start !== 'number' || !this.end || this.end <= this.start;
  2526. }
  2527. /**
  2528. * Set `origStart` and `origEnd` to point to the original source range for
  2529. * this node, which may differ due to dropped CR characters.
  2530. *
  2531. * @param {number[]} cr - Positions of dropped CR characters
  2532. * @param {number} offset - Starting index of `cr` from the last call
  2533. * @returns {number} - The next offset, matching the one found for `origStart`
  2534. */
  2535. setOrigRange(cr, offset) {
  2536. const {
  2537. start,
  2538. end
  2539. } = this;
  2540. if (cr.length === 0 || end <= cr[0]) {
  2541. this.origStart = start;
  2542. this.origEnd = end;
  2543. return offset;
  2544. }
  2545. let i = offset;
  2546. while (i < cr.length) {
  2547. if (cr[i] > start) break;else ++i;
  2548. }
  2549. this.origStart = start + i;
  2550. const nextOffset = i;
  2551. while (i < cr.length) {
  2552. // if end was at \n, it should now be at \r
  2553. if (cr[i] >= end) break;else ++i;
  2554. }
  2555. this.origEnd = end + i;
  2556. return nextOffset;
  2557. }
  2558. }
  2559. /** Root class of all nodes */
  2560. class Node {
  2561. static addStringTerminator(src, offset, str) {
  2562. if (str[str.length - 1] === '\n') return str;
  2563. const next = Node.endOfWhiteSpace(src, offset);
  2564. return next >= src.length || src[next] === '\n' ? str + '\n' : str;
  2565. } // ^(---|...)
  2566. static atDocumentBoundary(src, offset, sep) {
  2567. const ch0 = src[offset];
  2568. if (!ch0) return true;
  2569. const prev = src[offset - 1];
  2570. if (prev && prev !== '\n') return false;
  2571. if (sep) {
  2572. if (ch0 !== sep) return false;
  2573. } else {
  2574. if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
  2575. }
  2576. const ch1 = src[offset + 1];
  2577. const ch2 = src[offset + 2];
  2578. if (ch1 !== ch0 || ch2 !== ch0) return false;
  2579. const ch3 = src[offset + 3];
  2580. return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
  2581. }
  2582. static endOfIdentifier(src, offset) {
  2583. let ch = src[offset];
  2584. const isVerbatim = ch === '<';
  2585. const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
  2586. while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1];
  2587. if (isVerbatim && ch === '>') offset += 1;
  2588. return offset;
  2589. }
  2590. static endOfIndent(src, offset) {
  2591. let ch = src[offset];
  2592. while (ch === ' ') ch = src[offset += 1];
  2593. return offset;
  2594. }
  2595. static endOfLine(src, offset) {
  2596. let ch = src[offset];
  2597. while (ch && ch !== '\n') ch = src[offset += 1];
  2598. return offset;
  2599. }
  2600. static endOfWhiteSpace(src, offset) {
  2601. let ch = src[offset];
  2602. while (ch === '\t' || ch === ' ') ch = src[offset += 1];
  2603. return offset;
  2604. }
  2605. static startOfLine(src, offset) {
  2606. let ch = src[offset - 1];
  2607. if (ch === '\n') return offset;
  2608. while (ch && ch !== '\n') ch = src[offset -= 1];
  2609. return offset + 1;
  2610. }
  2611. /**
  2612. * End of indentation, or null if the line's indent level is not more
  2613. * than `indent`
  2614. *
  2615. * @param {string} src
  2616. * @param {number} indent
  2617. * @param {number} lineStart
  2618. * @returns {?number}
  2619. */
  2620. static endOfBlockIndent(src, indent, lineStart) {
  2621. const inEnd = Node.endOfIndent(src, lineStart);
  2622. if (inEnd > lineStart + indent) {
  2623. return inEnd;
  2624. } else {
  2625. const wsEnd = Node.endOfWhiteSpace(src, inEnd);
  2626. const ch = src[wsEnd];
  2627. if (!ch || ch === '\n') return wsEnd;
  2628. }
  2629. return null;
  2630. }
  2631. static atBlank(src, offset, endAsBlank) {
  2632. const ch = src[offset];
  2633. return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
  2634. }
  2635. static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
  2636. if (!ch || indentDiff < 0) return false;
  2637. if (indentDiff > 0) return true;
  2638. return indicatorAsIndent && ch === '-';
  2639. } // should be at line or string end, or at next non-whitespace char
  2640. static normalizeOffset(src, offset) {
  2641. const ch = src[offset];
  2642. return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset);
  2643. } // fold single newline into space, multiple newlines to N - 1 newlines
  2644. // presumes src[offset] === '\n'
  2645. static foldNewline(src, offset, indent) {
  2646. let inCount = 0;
  2647. let error = false;
  2648. let fold = '';
  2649. let ch = src[offset + 1];
  2650. while (ch === ' ' || ch === '\t' || ch === '\n') {
  2651. switch (ch) {
  2652. case '\n':
  2653. inCount = 0;
  2654. offset += 1;
  2655. fold += '\n';
  2656. break;
  2657. case '\t':
  2658. if (inCount <= indent) error = true;
  2659. offset = Node.endOfWhiteSpace(src, offset + 2) - 1;
  2660. break;
  2661. case ' ':
  2662. inCount += 1;
  2663. offset += 1;
  2664. break;
  2665. }
  2666. ch = src[offset + 1];
  2667. }
  2668. if (!fold) fold = ' ';
  2669. if (ch && inCount <= indent) error = true;
  2670. return {
  2671. fold,
  2672. offset,
  2673. error
  2674. };
  2675. }
  2676. constructor(type, props, context) {
  2677. Object.defineProperty(this, 'context', {
  2678. value: context || null,
  2679. writable: true
  2680. });
  2681. this.error = null;
  2682. this.range = null;
  2683. this.valueRange = null;
  2684. this.props = props || [];
  2685. this.type = type;
  2686. this.value = null;
  2687. }
  2688. getPropValue(idx, key, skipKey) {
  2689. if (!this.context) return null;
  2690. const {
  2691. src
  2692. } = this.context;
  2693. const prop = this.props[idx];
  2694. return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
  2695. }
  2696. get anchor() {
  2697. for (let i = 0; i < this.props.length; ++i) {
  2698. const anchor = this.getPropValue(i, Char.ANCHOR, true);
  2699. if (anchor != null) return anchor;
  2700. }
  2701. return null;
  2702. }
  2703. get comment() {
  2704. const comments = [];
  2705. for (let i = 0; i < this.props.length; ++i) {
  2706. const comment = this.getPropValue(i, Char.COMMENT, true);
  2707. if (comment != null) comments.push(comment);
  2708. }
  2709. return comments.length > 0 ? comments.join('\n') : null;
  2710. }
  2711. commentHasRequiredWhitespace(start) {
  2712. const {
  2713. src
  2714. } = this.context;
  2715. if (this.header && start === this.header.end) return false;
  2716. if (!this.valueRange) return false;
  2717. const {
  2718. end
  2719. } = this.valueRange;
  2720. return start !== end || Node.atBlank(src, end - 1);
  2721. }
  2722. get hasComment() {
  2723. if (this.context) {
  2724. const {
  2725. src
  2726. } = this.context;
  2727. for (let i = 0; i < this.props.length; ++i) {
  2728. if (src[this.props[i].start] === Char.COMMENT) return true;
  2729. }
  2730. }
  2731. return false;
  2732. }
  2733. get hasProps() {
  2734. if (this.context) {
  2735. const {
  2736. src
  2737. } = this.context;
  2738. for (let i = 0; i < this.props.length; ++i) {
  2739. if (src[this.props[i].start] !== Char.COMMENT) return true;
  2740. }
  2741. }
  2742. return false;
  2743. }
  2744. get includesTrailingLines() {
  2745. return false;
  2746. }
  2747. get jsonLike() {
  2748. const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
  2749. return jsonLikeTypes.indexOf(this.type) !== -1;
  2750. }
  2751. get rangeAsLinePos() {
  2752. if (!this.range || !this.context) return undefined;
  2753. const start = getLinePos(this.range.start, this.context.root);
  2754. if (!start) return undefined;
  2755. const end = getLinePos(this.range.end, this.context.root);
  2756. return {
  2757. start,
  2758. end
  2759. };
  2760. }
  2761. get rawValue() {
  2762. if (!this.valueRange || !this.context) return null;
  2763. const {
  2764. start,
  2765. end
  2766. } = this.valueRange;
  2767. return this.context.src.slice(start, end);
  2768. }
  2769. get tag() {
  2770. for (let i = 0; i < this.props.length; ++i) {
  2771. const tag = this.getPropValue(i, Char.TAG, false);
  2772. if (tag != null) {
  2773. if (tag[1] === '<') {
  2774. return {
  2775. verbatim: tag.slice(2, -1)
  2776. };
  2777. } else {
  2778. // eslint-disable-next-line no-unused-vars
  2779. const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/);
  2780. return {
  2781. handle,
  2782. suffix
  2783. };
  2784. }
  2785. }
  2786. }
  2787. return null;
  2788. }
  2789. get valueRangeContainsNewline() {
  2790. if (!this.valueRange || !this.context) return false;
  2791. const {
  2792. start,
  2793. end
  2794. } = this.valueRange;
  2795. const {
  2796. src
  2797. } = this.context;
  2798. for (let i = start; i < end; ++i) {
  2799. if (src[i] === '\n') return true;
  2800. }
  2801. return false;
  2802. }
  2803. parseComment(start) {
  2804. const {
  2805. src
  2806. } = this.context;
  2807. if (src[start] === Char.COMMENT) {
  2808. const end = Node.endOfLine(src, start + 1);
  2809. const commentRange = new Range(start, end);
  2810. this.props.push(commentRange);
  2811. return end;
  2812. }
  2813. return start;
  2814. }
  2815. /**
  2816. * Populates the `origStart` and `origEnd` values of all ranges for this
  2817. * node. Extended by child classes to handle descendant nodes.
  2818. *
  2819. * @param {number[]} cr - Positions of dropped CR characters
  2820. * @param {number} offset - Starting index of `cr` from the last call
  2821. * @returns {number} - The next offset, matching the one found for `origStart`
  2822. */
  2823. setOrigRanges(cr, offset) {
  2824. if (this.range) offset = this.range.setOrigRange(cr, offset);
  2825. if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
  2826. this.props.forEach(prop => prop.setOrigRange(cr, offset));
  2827. return offset;
  2828. }
  2829. toString() {
  2830. const {
  2831. context: {
  2832. src
  2833. },
  2834. range,
  2835. value
  2836. } = this;
  2837. if (value != null) return value;
  2838. const str = src.slice(range.start, range.end);
  2839. return Node.addStringTerminator(src, range.end, str);
  2840. }
  2841. }
  2842. class YAMLError extends Error {
  2843. constructor(name, source, message) {
  2844. if (!message || !(source instanceof Node)) throw new Error(`Invalid arguments for new ${name}`);
  2845. super();
  2846. this.name = name;
  2847. this.message = message;
  2848. this.source = source;
  2849. }
  2850. makePretty() {
  2851. if (!this.source) return;
  2852. this.nodeType = this.source.type;
  2853. const cst = this.source.context && this.source.context.root;
  2854. if (typeof this.offset === 'number') {
  2855. this.range = new Range(this.offset, this.offset + 1);
  2856. const start = cst && getLinePos(this.offset, cst);
  2857. if (start) {
  2858. const end = {
  2859. line: start.line,
  2860. col: start.col + 1
  2861. };
  2862. this.linePos = {
  2863. start,
  2864. end
  2865. };
  2866. }
  2867. delete this.offset;
  2868. } else {
  2869. this.range = this.source.range;
  2870. this.linePos = this.source.rangeAsLinePos;
  2871. }
  2872. if (this.linePos) {
  2873. const {
  2874. line,
  2875. col
  2876. } = this.linePos.start;
  2877. this.message += ` at line ${line}, column ${col}`;
  2878. const ctx = cst && getPrettyContext(this.linePos, cst);
  2879. if (ctx) this.message += `:\n\n${ctx}\n`;
  2880. }
  2881. delete this.source;
  2882. }
  2883. }
  2884. class YAMLReferenceError extends YAMLError {
  2885. constructor(source, message) {
  2886. super('YAMLReferenceError', source, message);
  2887. }
  2888. }
  2889. class YAMLSemanticError extends YAMLError {
  2890. constructor(source, message) {
  2891. super('YAMLSemanticError', source, message);
  2892. }
  2893. }
  2894. class YAMLSyntaxError extends YAMLError {
  2895. constructor(source, message) {
  2896. super('YAMLSyntaxError', source, message);
  2897. }
  2898. }
  2899. class YAMLWarning extends YAMLError {
  2900. constructor(source, message) {
  2901. super('YAMLWarning', source, message);
  2902. }
  2903. }
  2904. function _defineProperty(obj, key, value) {
  2905. if (key in obj) {
  2906. Object.defineProperty(obj, key, {
  2907. value: value,
  2908. enumerable: true,
  2909. configurable: true,
  2910. writable: true
  2911. });
  2912. } else {
  2913. obj[key] = value;
  2914. }
  2915. return obj;
  2916. }
  2917. class PlainValue extends Node {
  2918. static endOfLine(src, start, inFlow) {
  2919. let ch = src[start];
  2920. let offset = start;
  2921. while (ch && ch !== '\n') {
  2922. if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break;
  2923. const next = src[offset + 1];
  2924. if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
  2925. if ((ch === ' ' || ch === '\t') && next === '#') break;
  2926. offset += 1;
  2927. ch = next;
  2928. }
  2929. return offset;
  2930. }
  2931. get strValue() {
  2932. if (!this.valueRange || !this.context) return null;
  2933. let {
  2934. start,
  2935. end
  2936. } = this.valueRange;
  2937. const {
  2938. src
  2939. } = this.context;
  2940. let ch = src[end - 1];
  2941. while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) ch = src[--end - 1];
  2942. let str = '';
  2943. for (let i = start; i < end; ++i) {
  2944. const ch = src[i];
  2945. if (ch === '\n') {
  2946. const {
  2947. fold,
  2948. offset
  2949. } = Node.foldNewline(src, i, -1);
  2950. str += fold;
  2951. i = offset;
  2952. } else if (ch === ' ' || ch === '\t') {
  2953. // trim trailing whitespace
  2954. const wsStart = i;
  2955. let next = src[i + 1];
  2956. while (i < end && (next === ' ' || next === '\t')) {
  2957. i += 1;
  2958. next = src[i + 1];
  2959. }
  2960. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  2961. } else {
  2962. str += ch;
  2963. }
  2964. }
  2965. const ch0 = src[start];
  2966. switch (ch0) {
  2967. case '\t':
  2968. {
  2969. const msg = 'Plain value cannot start with a tab character';
  2970. const errors = [new YAMLSemanticError(this, msg)];
  2971. return {
  2972. errors,
  2973. str
  2974. };
  2975. }
  2976. case '@':
  2977. case '`':
  2978. {
  2979. const msg = `Plain value cannot start with reserved character ${ch0}`;
  2980. const errors = [new YAMLSemanticError(this, msg)];
  2981. return {
  2982. errors,
  2983. str
  2984. };
  2985. }
  2986. default:
  2987. return str;
  2988. }
  2989. }
  2990. parseBlockValue(start) {
  2991. const {
  2992. indent,
  2993. inFlow,
  2994. src
  2995. } = this.context;
  2996. let offset = start;
  2997. let valueEnd = start;
  2998. for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
  2999. if (Node.atDocumentBoundary(src, offset + 1)) break;
  3000. const end = Node.endOfBlockIndent(src, indent, offset + 1);
  3001. if (end === null || src[end] === '#') break;
  3002. if (src[end] === '\n') {
  3003. offset = end;
  3004. } else {
  3005. valueEnd = PlainValue.endOfLine(src, end, inFlow);
  3006. offset = valueEnd;
  3007. }
  3008. }
  3009. if (this.valueRange.isEmpty()) this.valueRange.start = start;
  3010. this.valueRange.end = valueEnd;
  3011. return valueEnd;
  3012. }
  3013. /**
  3014. * Parses a plain value from the source
  3015. *
  3016. * Accepted forms are:
  3017. * ```
  3018. * #comment
  3019. *
  3020. * first line
  3021. *
  3022. * first line #comment
  3023. *
  3024. * first line
  3025. * block
  3026. * lines
  3027. *
  3028. * #comment
  3029. * block
  3030. * lines
  3031. * ```
  3032. * where block lines are empty or have an indent level greater than `indent`.
  3033. *
  3034. * @param {ParseContext} context
  3035. * @param {number} start - Index of first character
  3036. * @returns {number} - Index of the character after this scalar, may be `\n`
  3037. */
  3038. parse(context, start) {
  3039. this.context = context;
  3040. const {
  3041. inFlow,
  3042. src
  3043. } = context;
  3044. let offset = start;
  3045. const ch = src[offset];
  3046. if (ch && ch !== '#' && ch !== '\n') {
  3047. offset = PlainValue.endOfLine(src, start, inFlow);
  3048. }
  3049. this.valueRange = new Range(start, offset);
  3050. offset = Node.endOfWhiteSpace(src, offset);
  3051. offset = this.parseComment(offset);
  3052. if (!this.hasComment || this.valueRange.isEmpty()) {
  3053. offset = this.parseBlockValue(offset);
  3054. }
  3055. return offset;
  3056. }
  3057. }
  3058. var Char_1 = Char;
  3059. var Node_1 = Node;
  3060. var PlainValue_1 = PlainValue;
  3061. var Range_1 = Range;
  3062. var Type_1 = Type;
  3063. var YAMLError_1 = YAMLError;
  3064. var YAMLReferenceError_1 = YAMLReferenceError;
  3065. var YAMLSemanticError_1 = YAMLSemanticError;
  3066. var YAMLSyntaxError_1 = YAMLSyntaxError;
  3067. var YAMLWarning_1 = YAMLWarning;
  3068. var _defineProperty_1 = _defineProperty;
  3069. var defaultTagPrefix_1 = defaultTagPrefix;
  3070. var defaultTags_1 = defaultTags;
  3071. var PlainValueEc8e588e = {
  3072. Char: Char_1,
  3073. Node: Node_1,
  3074. PlainValue: PlainValue_1,
  3075. Range: Range_1,
  3076. Type: Type_1,
  3077. YAMLError: YAMLError_1,
  3078. YAMLReferenceError: YAMLReferenceError_1,
  3079. YAMLSemanticError: YAMLSemanticError_1,
  3080. YAMLSyntaxError: YAMLSyntaxError_1,
  3081. YAMLWarning: YAMLWarning_1,
  3082. _defineProperty: _defineProperty_1,
  3083. defaultTagPrefix: defaultTagPrefix_1,
  3084. defaultTags: defaultTags_1
  3085. };
  3086. class BlankLine extends PlainValueEc8e588e.Node {
  3087. constructor() {
  3088. super(PlainValueEc8e588e.Type.BLANK_LINE);
  3089. }
  3090. /* istanbul ignore next */
  3091. get includesTrailingLines() {
  3092. // This is never called from anywhere, but if it were,
  3093. // this is the value it should return.
  3094. return true;
  3095. }
  3096. /**
  3097. * Parses a blank line from the source
  3098. *
  3099. * @param {ParseContext} context
  3100. * @param {number} start - Index of first \n character
  3101. * @returns {number} - Index of the character after this
  3102. */
  3103. parse(context, start) {
  3104. this.context = context;
  3105. this.range = new PlainValueEc8e588e.Range(start, start + 1);
  3106. return start + 1;
  3107. }
  3108. }
  3109. class CollectionItem extends PlainValueEc8e588e.Node {
  3110. constructor(type, props) {
  3111. super(type, props);
  3112. this.node = null;
  3113. }
  3114. get includesTrailingLines() {
  3115. return !!this.node && this.node.includesTrailingLines;
  3116. }
  3117. /**
  3118. * @param {ParseContext} context
  3119. * @param {number} start - Index of first character
  3120. * @returns {number} - Index of the character after this
  3121. */
  3122. parse(context, start) {
  3123. this.context = context;
  3124. const {
  3125. parseNode,
  3126. src
  3127. } = context;
  3128. let {
  3129. atLineStart,
  3130. lineStart
  3131. } = context;
  3132. if (!atLineStart && this.type === PlainValueEc8e588e.Type.SEQ_ITEM) this.error = new PlainValueEc8e588e.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
  3133. const indent = atLineStart ? start - lineStart : context.indent;
  3134. let offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start + 1);
  3135. let ch = src[offset];
  3136. const inlineComment = ch === '#';
  3137. const comments = [];
  3138. let blankLine = null;
  3139. while (ch === '\n' || ch === '#') {
  3140. if (ch === '#') {
  3141. const end = PlainValueEc8e588e.Node.endOfLine(src, offset + 1);
  3142. comments.push(new PlainValueEc8e588e.Range(offset, end));
  3143. offset = end;
  3144. } else {
  3145. atLineStart = true;
  3146. lineStart = offset + 1;
  3147. const wsEnd = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart);
  3148. if (src[wsEnd] === '\n' && comments.length === 0) {
  3149. blankLine = new BlankLine();
  3150. lineStart = blankLine.parse({
  3151. src
  3152. }, lineStart);
  3153. }
  3154. offset = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  3155. }
  3156. ch = src[offset];
  3157. }
  3158. if (PlainValueEc8e588e.Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== PlainValueEc8e588e.Type.SEQ_ITEM)) {
  3159. this.node = parseNode({
  3160. atLineStart,
  3161. inCollection: false,
  3162. indent,
  3163. lineStart,
  3164. parent: this
  3165. }, offset);
  3166. } else if (ch && lineStart > start + 1) {
  3167. offset = lineStart - 1;
  3168. }
  3169. if (this.node) {
  3170. if (blankLine) {
  3171. // Only blank lines preceding non-empty nodes are captured. Note that
  3172. // this means that collection item range start indices do not always
  3173. // increase monotonically. -- eemeli/yaml#126
  3174. const items = context.parent.items || context.parent.contents;
  3175. if (items) items.push(blankLine);
  3176. }
  3177. if (comments.length) Array.prototype.push.apply(this.props, comments);
  3178. offset = this.node.range.end;
  3179. } else {
  3180. if (inlineComment) {
  3181. const c = comments[0];
  3182. this.props.push(c);
  3183. offset = c.end;
  3184. } else {
  3185. offset = PlainValueEc8e588e.Node.endOfLine(src, start + 1);
  3186. }
  3187. }
  3188. const end = this.node ? this.node.valueRange.end : offset;
  3189. this.valueRange = new PlainValueEc8e588e.Range(start, end);
  3190. return offset;
  3191. }
  3192. setOrigRanges(cr, offset) {
  3193. offset = super.setOrigRanges(cr, offset);
  3194. return this.node ? this.node.setOrigRanges(cr, offset) : offset;
  3195. }
  3196. toString() {
  3197. const {
  3198. context: {
  3199. src
  3200. },
  3201. node,
  3202. range,
  3203. value
  3204. } = this;
  3205. if (value != null) return value;
  3206. const str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end);
  3207. return PlainValueEc8e588e.Node.addStringTerminator(src, range.end, str);
  3208. }
  3209. }
  3210. class Comment extends PlainValueEc8e588e.Node {
  3211. constructor() {
  3212. super(PlainValueEc8e588e.Type.COMMENT);
  3213. }
  3214. /**
  3215. * Parses a comment line from the source
  3216. *
  3217. * @param {ParseContext} context
  3218. * @param {number} start - Index of first character
  3219. * @returns {number} - Index of the character after this scalar
  3220. */
  3221. parse(context, start) {
  3222. this.context = context;
  3223. const offset = this.parseComment(start);
  3224. this.range = new PlainValueEc8e588e.Range(start, offset);
  3225. return offset;
  3226. }
  3227. }
  3228. function grabCollectionEndComments(node) {
  3229. let cnode = node;
  3230. while (cnode instanceof CollectionItem) cnode = cnode.node;
  3231. if (!(cnode instanceof Collection)) return null;
  3232. const len = cnode.items.length;
  3233. let ci = -1;
  3234. for (let i = len - 1; i >= 0; --i) {
  3235. const n = cnode.items[i];
  3236. if (n.type === PlainValueEc8e588e.Type.COMMENT) {
  3237. // Keep sufficiently indented comments with preceding node
  3238. const {
  3239. indent,
  3240. lineStart
  3241. } = n.context;
  3242. if (indent > 0 && n.range.start >= lineStart + indent) break;
  3243. ci = i;
  3244. } else if (n.type === PlainValueEc8e588e.Type.BLANK_LINE) ci = i;else break;
  3245. }
  3246. if (ci === -1) return null;
  3247. const ca = cnode.items.splice(ci, len - ci);
  3248. const prevEnd = ca[0].range.start;
  3249. while (true) {
  3250. cnode.range.end = prevEnd;
  3251. if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd;
  3252. if (cnode === node) break;
  3253. cnode = cnode.context.parent;
  3254. }
  3255. return ca;
  3256. }
  3257. class Collection extends PlainValueEc8e588e.Node {
  3258. static nextContentHasIndent(src, offset, indent) {
  3259. const lineStart = PlainValueEc8e588e.Node.endOfLine(src, offset) + 1;
  3260. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart);
  3261. const ch = src[offset];
  3262. if (!ch) return false;
  3263. if (offset >= lineStart + indent) return true;
  3264. if (ch !== '#' && ch !== '\n') return false;
  3265. return Collection.nextContentHasIndent(src, offset, indent);
  3266. }
  3267. constructor(firstItem) {
  3268. super(firstItem.type === PlainValueEc8e588e.Type.SEQ_ITEM ? PlainValueEc8e588e.Type.SEQ : PlainValueEc8e588e.Type.MAP);
  3269. for (let i = firstItem.props.length - 1; i >= 0; --i) {
  3270. if (firstItem.props[i].start < firstItem.context.lineStart) {
  3271. // props on previous line are assumed by the collection
  3272. this.props = firstItem.props.slice(0, i + 1);
  3273. firstItem.props = firstItem.props.slice(i + 1);
  3274. const itemRange = firstItem.props[0] || firstItem.valueRange;
  3275. firstItem.range.start = itemRange.start;
  3276. break;
  3277. }
  3278. }
  3279. this.items = [firstItem];
  3280. const ec = grabCollectionEndComments(firstItem);
  3281. if (ec) Array.prototype.push.apply(this.items, ec);
  3282. }
  3283. get includesTrailingLines() {
  3284. return this.items.length > 0;
  3285. }
  3286. /**
  3287. * @param {ParseContext} context
  3288. * @param {number} start - Index of first character
  3289. * @returns {number} - Index of the character after this
  3290. */
  3291. parse(context, start) {
  3292. this.context = context;
  3293. const {
  3294. parseNode,
  3295. src
  3296. } = context; // It's easier to recalculate lineStart here rather than tracking down the
  3297. // last context from which to read it -- eemeli/yaml#2
  3298. let lineStart = PlainValueEc8e588e.Node.startOfLine(src, start);
  3299. const firstItem = this.items[0]; // First-item context needs to be correct for later comment handling
  3300. // -- eemeli/yaml#17
  3301. firstItem.context.parent = this;
  3302. this.valueRange = PlainValueEc8e588e.Range.copy(firstItem.valueRange);
  3303. const indent = firstItem.range.start - firstItem.context.lineStart;
  3304. let offset = start;
  3305. offset = PlainValueEc8e588e.Node.normalizeOffset(src, offset);
  3306. let ch = src[offset];
  3307. let atLineStart = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart) === offset;
  3308. let prevIncludesTrailingLines = false;
  3309. while (ch) {
  3310. while (ch === '\n' || ch === '#') {
  3311. if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) {
  3312. const blankLine = new BlankLine();
  3313. offset = blankLine.parse({
  3314. src
  3315. }, offset);
  3316. this.valueRange.end = offset;
  3317. if (offset >= src.length) {
  3318. ch = null;
  3319. break;
  3320. }
  3321. this.items.push(blankLine);
  3322. offset -= 1; // blankLine.parse() consumes terminal newline
  3323. } else if (ch === '#') {
  3324. if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) {
  3325. return offset;
  3326. }
  3327. const comment = new Comment();
  3328. offset = comment.parse({
  3329. indent,
  3330. lineStart,
  3331. src
  3332. }, offset);
  3333. this.items.push(comment);
  3334. this.valueRange.end = offset;
  3335. if (offset >= src.length) {
  3336. ch = null;
  3337. break;
  3338. }
  3339. }
  3340. lineStart = offset + 1;
  3341. offset = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  3342. if (PlainValueEc8e588e.Node.atBlank(src, offset)) {
  3343. const wsEnd = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3344. const next = src[wsEnd];
  3345. if (!next || next === '\n' || next === '#') {
  3346. offset = wsEnd;
  3347. }
  3348. }
  3349. ch = src[offset];
  3350. atLineStart = true;
  3351. }
  3352. if (!ch) {
  3353. break;
  3354. }
  3355. if (offset !== lineStart + indent && (atLineStart || ch !== ':')) {
  3356. if (offset < lineStart + indent) {
  3357. if (lineStart > start) offset = lineStart;
  3358. break;
  3359. } else if (!this.error) {
  3360. const msg = 'All collection items must start at the same column';
  3361. this.error = new PlainValueEc8e588e.YAMLSyntaxError(this, msg);
  3362. }
  3363. }
  3364. if (firstItem.type === PlainValueEc8e588e.Type.SEQ_ITEM) {
  3365. if (ch !== '-') {
  3366. if (lineStart > start) offset = lineStart;
  3367. break;
  3368. }
  3369. } else if (ch === '-' && !this.error) {
  3370. // map key may start with -, as long as it's followed by a non-whitespace char
  3371. const next = src[offset + 1];
  3372. if (!next || next === '\n' || next === '\t' || next === ' ') {
  3373. const msg = 'A collection cannot be both a mapping and a sequence';
  3374. this.error = new PlainValueEc8e588e.YAMLSyntaxError(this, msg);
  3375. }
  3376. }
  3377. const node = parseNode({
  3378. atLineStart,
  3379. inCollection: true,
  3380. indent,
  3381. lineStart,
  3382. parent: this
  3383. }, offset);
  3384. if (!node) return offset; // at next document start
  3385. this.items.push(node);
  3386. this.valueRange.end = node.valueRange.end;
  3387. offset = PlainValueEc8e588e.Node.normalizeOffset(src, node.range.end);
  3388. ch = src[offset];
  3389. atLineStart = false;
  3390. prevIncludesTrailingLines = node.includesTrailingLines; // Need to reset lineStart and atLineStart here if preceding node's range
  3391. // has advanced to check the current line's indentation level
  3392. // -- eemeli/yaml#10 & eemeli/yaml#38
  3393. if (ch) {
  3394. let ls = offset - 1;
  3395. let prev = src[ls];
  3396. while (prev === ' ' || prev === '\t') prev = src[--ls];
  3397. if (prev === '\n') {
  3398. lineStart = ls + 1;
  3399. atLineStart = true;
  3400. }
  3401. }
  3402. const ec = grabCollectionEndComments(node);
  3403. if (ec) Array.prototype.push.apply(this.items, ec);
  3404. }
  3405. return offset;
  3406. }
  3407. setOrigRanges(cr, offset) {
  3408. offset = super.setOrigRanges(cr, offset);
  3409. this.items.forEach(node => {
  3410. offset = node.setOrigRanges(cr, offset);
  3411. });
  3412. return offset;
  3413. }
  3414. toString() {
  3415. const {
  3416. context: {
  3417. src
  3418. },
  3419. items,
  3420. range,
  3421. value
  3422. } = this;
  3423. if (value != null) return value;
  3424. let str = src.slice(range.start, items[0].range.start) + String(items[0]);
  3425. for (let i = 1; i < items.length; ++i) {
  3426. const item = items[i];
  3427. const {
  3428. atLineStart,
  3429. indent
  3430. } = item.context;
  3431. if (atLineStart) for (let i = 0; i < indent; ++i) str += ' ';
  3432. str += String(item);
  3433. }
  3434. return PlainValueEc8e588e.Node.addStringTerminator(src, range.end, str);
  3435. }
  3436. }
  3437. class Directive extends PlainValueEc8e588e.Node {
  3438. constructor() {
  3439. super(PlainValueEc8e588e.Type.DIRECTIVE);
  3440. this.name = null;
  3441. }
  3442. get parameters() {
  3443. const raw = this.rawValue;
  3444. return raw ? raw.trim().split(/[ \t]+/) : [];
  3445. }
  3446. parseName(start) {
  3447. const {
  3448. src
  3449. } = this.context;
  3450. let offset = start;
  3451. let ch = src[offset];
  3452. while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') ch = src[offset += 1];
  3453. this.name = src.slice(start, offset);
  3454. return offset;
  3455. }
  3456. parseParameters(start) {
  3457. const {
  3458. src
  3459. } = this.context;
  3460. let offset = start;
  3461. let ch = src[offset];
  3462. while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1];
  3463. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  3464. return offset;
  3465. }
  3466. parse(context, start) {
  3467. this.context = context;
  3468. let offset = this.parseName(start + 1);
  3469. offset = this.parseParameters(offset);
  3470. offset = this.parseComment(offset);
  3471. this.range = new PlainValueEc8e588e.Range(start, offset);
  3472. return offset;
  3473. }
  3474. }
  3475. class Document extends PlainValueEc8e588e.Node {
  3476. static startCommentOrEndBlankLine(src, start) {
  3477. const offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start);
  3478. const ch = src[offset];
  3479. return ch === '#' || ch === '\n' ? offset : start;
  3480. }
  3481. constructor() {
  3482. super(PlainValueEc8e588e.Type.DOCUMENT);
  3483. this.directives = null;
  3484. this.contents = null;
  3485. this.directivesEndMarker = null;
  3486. this.documentEndMarker = null;
  3487. }
  3488. parseDirectives(start) {
  3489. const {
  3490. src
  3491. } = this.context;
  3492. this.directives = [];
  3493. let atLineStart = true;
  3494. let hasDirectives = false;
  3495. let offset = start;
  3496. while (!PlainValueEc8e588e.Node.atDocumentBoundary(src, offset, PlainValueEc8e588e.Char.DIRECTIVES_END)) {
  3497. offset = Document.startCommentOrEndBlankLine(src, offset);
  3498. switch (src[offset]) {
  3499. case '\n':
  3500. if (atLineStart) {
  3501. const blankLine = new BlankLine();
  3502. offset = blankLine.parse({
  3503. src
  3504. }, offset);
  3505. if (offset < src.length) {
  3506. this.directives.push(blankLine);
  3507. }
  3508. } else {
  3509. offset += 1;
  3510. atLineStart = true;
  3511. }
  3512. break;
  3513. case '#':
  3514. {
  3515. const comment = new Comment();
  3516. offset = comment.parse({
  3517. src
  3518. }, offset);
  3519. this.directives.push(comment);
  3520. atLineStart = false;
  3521. }
  3522. break;
  3523. case '%':
  3524. {
  3525. const directive = new Directive();
  3526. offset = directive.parse({
  3527. parent: this,
  3528. src
  3529. }, offset);
  3530. this.directives.push(directive);
  3531. hasDirectives = true;
  3532. atLineStart = false;
  3533. }
  3534. break;
  3535. default:
  3536. if (hasDirectives) {
  3537. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, 'Missing directives-end indicator line');
  3538. } else if (this.directives.length > 0) {
  3539. this.contents = this.directives;
  3540. this.directives = [];
  3541. }
  3542. return offset;
  3543. }
  3544. }
  3545. if (src[offset]) {
  3546. this.directivesEndMarker = new PlainValueEc8e588e.Range(offset, offset + 3);
  3547. return offset + 3;
  3548. }
  3549. if (hasDirectives) {
  3550. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, 'Missing directives-end indicator line');
  3551. } else if (this.directives.length > 0) {
  3552. this.contents = this.directives;
  3553. this.directives = [];
  3554. }
  3555. return offset;
  3556. }
  3557. parseContents(start) {
  3558. const {
  3559. parseNode,
  3560. src
  3561. } = this.context;
  3562. if (!this.contents) this.contents = [];
  3563. let lineStart = start;
  3564. while (src[lineStart - 1] === '-') lineStart -= 1;
  3565. let offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start);
  3566. let atLineStart = lineStart === start;
  3567. this.valueRange = new PlainValueEc8e588e.Range(offset);
  3568. while (!PlainValueEc8e588e.Node.atDocumentBoundary(src, offset, PlainValueEc8e588e.Char.DOCUMENT_END)) {
  3569. switch (src[offset]) {
  3570. case '\n':
  3571. if (atLineStart) {
  3572. const blankLine = new BlankLine();
  3573. offset = blankLine.parse({
  3574. src
  3575. }, offset);
  3576. if (offset < src.length) {
  3577. this.contents.push(blankLine);
  3578. }
  3579. } else {
  3580. offset += 1;
  3581. atLineStart = true;
  3582. }
  3583. lineStart = offset;
  3584. break;
  3585. case '#':
  3586. {
  3587. const comment = new Comment();
  3588. offset = comment.parse({
  3589. src
  3590. }, offset);
  3591. this.contents.push(comment);
  3592. atLineStart = false;
  3593. }
  3594. break;
  3595. default:
  3596. {
  3597. const iEnd = PlainValueEc8e588e.Node.endOfIndent(src, offset);
  3598. const context = {
  3599. atLineStart,
  3600. indent: -1,
  3601. inFlow: false,
  3602. inCollection: false,
  3603. lineStart,
  3604. parent: this
  3605. };
  3606. const node = parseNode(context, iEnd);
  3607. if (!node) return this.valueRange.end = iEnd; // at next document start
  3608. this.contents.push(node);
  3609. offset = node.range.end;
  3610. atLineStart = false;
  3611. const ec = grabCollectionEndComments(node);
  3612. if (ec) Array.prototype.push.apply(this.contents, ec);
  3613. }
  3614. }
  3615. offset = Document.startCommentOrEndBlankLine(src, offset);
  3616. }
  3617. this.valueRange.end = offset;
  3618. if (src[offset]) {
  3619. this.documentEndMarker = new PlainValueEc8e588e.Range(offset, offset + 3);
  3620. offset += 3;
  3621. if (src[offset]) {
  3622. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3623. if (src[offset] === '#') {
  3624. const comment = new Comment();
  3625. offset = comment.parse({
  3626. src
  3627. }, offset);
  3628. this.contents.push(comment);
  3629. }
  3630. switch (src[offset]) {
  3631. case '\n':
  3632. offset += 1;
  3633. break;
  3634. case undefined:
  3635. break;
  3636. default:
  3637. this.error = new PlainValueEc8e588e.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
  3638. }
  3639. }
  3640. }
  3641. return offset;
  3642. }
  3643. /**
  3644. * @param {ParseContext} context
  3645. * @param {number} start - Index of first character
  3646. * @returns {number} - Index of the character after this
  3647. */
  3648. parse(context, start) {
  3649. context.root = this;
  3650. this.context = context;
  3651. const {
  3652. src
  3653. } = context;
  3654. let offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM
  3655. offset = this.parseDirectives(offset);
  3656. offset = this.parseContents(offset);
  3657. return offset;
  3658. }
  3659. setOrigRanges(cr, offset) {
  3660. offset = super.setOrigRanges(cr, offset);
  3661. this.directives.forEach(node => {
  3662. offset = node.setOrigRanges(cr, offset);
  3663. });
  3664. if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
  3665. this.contents.forEach(node => {
  3666. offset = node.setOrigRanges(cr, offset);
  3667. });
  3668. if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
  3669. return offset;
  3670. }
  3671. toString() {
  3672. const {
  3673. contents,
  3674. directives,
  3675. value
  3676. } = this;
  3677. if (value != null) return value;
  3678. let str = directives.join('');
  3679. if (contents.length > 0) {
  3680. if (directives.length > 0 || contents[0].type === PlainValueEc8e588e.Type.COMMENT) str += '---\n';
  3681. str += contents.join('');
  3682. }
  3683. if (str[str.length - 1] !== '\n') str += '\n';
  3684. return str;
  3685. }
  3686. }
  3687. class Alias extends PlainValueEc8e588e.Node {
  3688. /**
  3689. * Parses an *alias from the source
  3690. *
  3691. * @param {ParseContext} context
  3692. * @param {number} start - Index of first character
  3693. * @returns {number} - Index of the character after this scalar
  3694. */
  3695. parse(context, start) {
  3696. this.context = context;
  3697. const {
  3698. src
  3699. } = context;
  3700. let offset = PlainValueEc8e588e.Node.endOfIdentifier(src, start + 1);
  3701. this.valueRange = new PlainValueEc8e588e.Range(start + 1, offset);
  3702. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3703. offset = this.parseComment(offset);
  3704. return offset;
  3705. }
  3706. }
  3707. const Chomp = {
  3708. CLIP: 'CLIP',
  3709. KEEP: 'KEEP',
  3710. STRIP: 'STRIP'
  3711. };
  3712. class BlockValue extends PlainValueEc8e588e.Node {
  3713. constructor(type, props) {
  3714. super(type, props);
  3715. this.blockIndent = null;
  3716. this.chomping = Chomp.CLIP;
  3717. this.header = null;
  3718. }
  3719. get includesTrailingLines() {
  3720. return this.chomping === Chomp.KEEP;
  3721. }
  3722. get strValue() {
  3723. if (!this.valueRange || !this.context) return null;
  3724. let {
  3725. start,
  3726. end
  3727. } = this.valueRange;
  3728. const {
  3729. indent,
  3730. src
  3731. } = this.context;
  3732. if (this.valueRange.isEmpty()) return '';
  3733. let lastNewLine = null;
  3734. let ch = src[end - 1];
  3735. while (ch === '\n' || ch === '\t' || ch === ' ') {
  3736. end -= 1;
  3737. if (end <= start) {
  3738. if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
  3739. }
  3740. if (ch === '\n') lastNewLine = end;
  3741. ch = src[end - 1];
  3742. }
  3743. let keepStart = end + 1;
  3744. if (lastNewLine) {
  3745. if (this.chomping === Chomp.KEEP) {
  3746. keepStart = lastNewLine;
  3747. end = this.valueRange.end;
  3748. } else {
  3749. end = lastNewLine;
  3750. }
  3751. }
  3752. const bi = indent + this.blockIndent;
  3753. const folded = this.type === PlainValueEc8e588e.Type.BLOCK_FOLDED;
  3754. let atStart = true;
  3755. let str = '';
  3756. let sep = '';
  3757. let prevMoreIndented = false;
  3758. for (let i = start; i < end; ++i) {
  3759. for (let j = 0; j < bi; ++j) {
  3760. if (src[i] !== ' ') break;
  3761. i += 1;
  3762. }
  3763. const ch = src[i];
  3764. if (ch === '\n') {
  3765. if (sep === '\n') str += '\n';else sep = '\n';
  3766. } else {
  3767. const lineEnd = PlainValueEc8e588e.Node.endOfLine(src, i);
  3768. const line = src.slice(i, lineEnd);
  3769. i = lineEnd;
  3770. if (folded && (ch === ' ' || ch === '\t') && i < keepStart) {
  3771. if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
  3772. str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
  3773. sep = lineEnd < end && src[lineEnd] || '';
  3774. prevMoreIndented = true;
  3775. } else {
  3776. str += sep + line;
  3777. sep = folded && i < keepStart ? ' ' : '\n';
  3778. prevMoreIndented = false;
  3779. }
  3780. if (atStart && line !== '') atStart = false;
  3781. }
  3782. }
  3783. return this.chomping === Chomp.STRIP ? str : str + '\n';
  3784. }
  3785. parseBlockHeader(start) {
  3786. const {
  3787. src
  3788. } = this.context;
  3789. let offset = start + 1;
  3790. let bi = '';
  3791. while (true) {
  3792. const ch = src[offset];
  3793. switch (ch) {
  3794. case '-':
  3795. this.chomping = Chomp.STRIP;
  3796. break;
  3797. case '+':
  3798. this.chomping = Chomp.KEEP;
  3799. break;
  3800. case '0':
  3801. case '1':
  3802. case '2':
  3803. case '3':
  3804. case '4':
  3805. case '5':
  3806. case '6':
  3807. case '7':
  3808. case '8':
  3809. case '9':
  3810. bi += ch;
  3811. break;
  3812. default:
  3813. this.blockIndent = Number(bi) || null;
  3814. this.header = new PlainValueEc8e588e.Range(start, offset);
  3815. return offset;
  3816. }
  3817. offset += 1;
  3818. }
  3819. }
  3820. parseBlockValue(start) {
  3821. const {
  3822. indent,
  3823. src
  3824. } = this.context;
  3825. const explicit = !!this.blockIndent;
  3826. let offset = start;
  3827. let valueEnd = start;
  3828. let minBlockIndent = 1;
  3829. for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
  3830. offset += 1;
  3831. if (PlainValueEc8e588e.Node.atDocumentBoundary(src, offset)) break;
  3832. const end = PlainValueEc8e588e.Node.endOfBlockIndent(src, indent, offset); // should not include tab?
  3833. if (end === null) break;
  3834. const ch = src[end];
  3835. const lineIndent = end - (offset + indent);
  3836. if (!this.blockIndent) {
  3837. // no explicit block indent, none yet detected
  3838. if (src[end] !== '\n') {
  3839. // first line with non-whitespace content
  3840. if (lineIndent < minBlockIndent) {
  3841. const msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
  3842. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, msg);
  3843. }
  3844. this.blockIndent = lineIndent;
  3845. } else if (lineIndent > minBlockIndent) {
  3846. // empty line with more whitespace
  3847. minBlockIndent = lineIndent;
  3848. }
  3849. } else if (ch && ch !== '\n' && lineIndent < this.blockIndent) {
  3850. if (src[end] === '#') break;
  3851. if (!this.error) {
  3852. const src = explicit ? 'explicit indentation indicator' : 'first line';
  3853. const msg = `Block scalars must not be less indented than their ${src}`;
  3854. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, msg);
  3855. }
  3856. }
  3857. if (src[end] === '\n') {
  3858. offset = end;
  3859. } else {
  3860. offset = valueEnd = PlainValueEc8e588e.Node.endOfLine(src, end);
  3861. }
  3862. }
  3863. if (this.chomping !== Chomp.KEEP) {
  3864. offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
  3865. }
  3866. this.valueRange = new PlainValueEc8e588e.Range(start + 1, offset);
  3867. return offset;
  3868. }
  3869. /**
  3870. * Parses a block value from the source
  3871. *
  3872. * Accepted forms are:
  3873. * ```
  3874. * BS
  3875. * block
  3876. * lines
  3877. *
  3878. * BS #comment
  3879. * block
  3880. * lines
  3881. * ```
  3882. * where the block style BS matches the regexp `[|>][-+1-9]*` and block lines
  3883. * are empty or have an indent level greater than `indent`.
  3884. *
  3885. * @param {ParseContext} context
  3886. * @param {number} start - Index of first character
  3887. * @returns {number} - Index of the character after this block
  3888. */
  3889. parse(context, start) {
  3890. this.context = context;
  3891. const {
  3892. src
  3893. } = context;
  3894. let offset = this.parseBlockHeader(start);
  3895. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3896. offset = this.parseComment(offset);
  3897. offset = this.parseBlockValue(offset);
  3898. return offset;
  3899. }
  3900. setOrigRanges(cr, offset) {
  3901. offset = super.setOrigRanges(cr, offset);
  3902. return this.header ? this.header.setOrigRange(cr, offset) : offset;
  3903. }
  3904. }
  3905. class FlowCollection extends PlainValueEc8e588e.Node {
  3906. constructor(type, props) {
  3907. super(type, props);
  3908. this.items = null;
  3909. }
  3910. prevNodeIsJsonLike(idx = this.items.length) {
  3911. const node = this.items[idx - 1];
  3912. return !!node && (node.jsonLike || node.type === PlainValueEc8e588e.Type.COMMENT && this.prevNodeIsJsonLike(idx - 1));
  3913. }
  3914. /**
  3915. * @param {ParseContext} context
  3916. * @param {number} start - Index of first character
  3917. * @returns {number} - Index of the character after this
  3918. */
  3919. parse(context, start) {
  3920. this.context = context;
  3921. const {
  3922. parseNode,
  3923. src
  3924. } = context;
  3925. let {
  3926. indent,
  3927. lineStart
  3928. } = context;
  3929. let char = src[start]; // { or [
  3930. this.items = [{
  3931. char,
  3932. offset: start
  3933. }];
  3934. let offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start + 1);
  3935. char = src[offset];
  3936. while (char && char !== ']' && char !== '}') {
  3937. switch (char) {
  3938. case '\n':
  3939. {
  3940. lineStart = offset + 1;
  3941. const wsEnd = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart);
  3942. if (src[wsEnd] === '\n') {
  3943. const blankLine = new BlankLine();
  3944. lineStart = blankLine.parse({
  3945. src
  3946. }, lineStart);
  3947. this.items.push(blankLine);
  3948. }
  3949. offset = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  3950. if (offset <= lineStart + indent) {
  3951. char = src[offset];
  3952. if (offset < lineStart + indent || char !== ']' && char !== '}') {
  3953. const msg = 'Insufficient indentation in flow collection';
  3954. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, msg);
  3955. }
  3956. }
  3957. }
  3958. break;
  3959. case ',':
  3960. {
  3961. this.items.push({
  3962. char,
  3963. offset
  3964. });
  3965. offset += 1;
  3966. }
  3967. break;
  3968. case '#':
  3969. {
  3970. const comment = new Comment();
  3971. offset = comment.parse({
  3972. src
  3973. }, offset);
  3974. this.items.push(comment);
  3975. }
  3976. break;
  3977. case '?':
  3978. case ':':
  3979. {
  3980. const next = src[offset + 1];
  3981. if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace
  3982. char === ':' && this.prevNodeIsJsonLike()) {
  3983. this.items.push({
  3984. char,
  3985. offset
  3986. });
  3987. offset += 1;
  3988. break;
  3989. }
  3990. }
  3991. // fallthrough
  3992. default:
  3993. {
  3994. const node = parseNode({
  3995. atLineStart: false,
  3996. inCollection: false,
  3997. inFlow: true,
  3998. indent: -1,
  3999. lineStart,
  4000. parent: this
  4001. }, offset);
  4002. if (!node) {
  4003. // at next document start
  4004. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  4005. return offset;
  4006. }
  4007. this.items.push(node);
  4008. offset = PlainValueEc8e588e.Node.normalizeOffset(src, node.range.end);
  4009. }
  4010. }
  4011. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4012. char = src[offset];
  4013. }
  4014. this.valueRange = new PlainValueEc8e588e.Range(start, offset + 1);
  4015. if (char) {
  4016. this.items.push({
  4017. char,
  4018. offset
  4019. });
  4020. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset + 1);
  4021. offset = this.parseComment(offset);
  4022. }
  4023. return offset;
  4024. }
  4025. setOrigRanges(cr, offset) {
  4026. offset = super.setOrigRanges(cr, offset);
  4027. this.items.forEach(node => {
  4028. if (node instanceof PlainValueEc8e588e.Node) {
  4029. offset = node.setOrigRanges(cr, offset);
  4030. } else if (cr.length === 0) {
  4031. node.origOffset = node.offset;
  4032. } else {
  4033. let i = offset;
  4034. while (i < cr.length) {
  4035. if (cr[i] > node.offset) break;else ++i;
  4036. }
  4037. node.origOffset = node.offset + i;
  4038. offset = i;
  4039. }
  4040. });
  4041. return offset;
  4042. }
  4043. toString() {
  4044. const {
  4045. context: {
  4046. src
  4047. },
  4048. items,
  4049. range,
  4050. value
  4051. } = this;
  4052. if (value != null) return value;
  4053. const nodes = items.filter(item => item instanceof PlainValueEc8e588e.Node);
  4054. let str = '';
  4055. let prevEnd = range.start;
  4056. nodes.forEach(node => {
  4057. const prefix = src.slice(prevEnd, node.range.start);
  4058. prevEnd = node.range.end;
  4059. str += prefix + String(node);
  4060. if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') {
  4061. // Comment range does not include the terminal newline, but its
  4062. // stringified value does. Without this fix, newlines at comment ends
  4063. // get duplicated.
  4064. prevEnd += 1;
  4065. }
  4066. });
  4067. str += src.slice(prevEnd, range.end);
  4068. return PlainValueEc8e588e.Node.addStringTerminator(src, range.end, str);
  4069. }
  4070. }
  4071. class QuoteDouble extends PlainValueEc8e588e.Node {
  4072. static endOfQuote(src, offset) {
  4073. let ch = src[offset];
  4074. while (ch && ch !== '"') {
  4075. offset += ch === '\\' ? 2 : 1;
  4076. ch = src[offset];
  4077. }
  4078. return offset + 1;
  4079. }
  4080. /**
  4081. * @returns {string | { str: string, errors: YAMLSyntaxError[] }}
  4082. */
  4083. get strValue() {
  4084. if (!this.valueRange || !this.context) return null;
  4085. const errors = [];
  4086. const {
  4087. start,
  4088. end
  4089. } = this.valueRange;
  4090. const {
  4091. indent,
  4092. src
  4093. } = this.context;
  4094. if (src[end - 1] !== '"') errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by
  4095. // escaped backslashes; also, this should be faster.
  4096. let str = '';
  4097. for (let i = start + 1; i < end - 1; ++i) {
  4098. const ch = src[i];
  4099. if (ch === '\n') {
  4100. if (PlainValueEc8e588e.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
  4101. const {
  4102. fold,
  4103. offset,
  4104. error
  4105. } = PlainValueEc8e588e.Node.foldNewline(src, i, indent);
  4106. str += fold;
  4107. i = offset;
  4108. if (error) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
  4109. } else if (ch === '\\') {
  4110. i += 1;
  4111. switch (src[i]) {
  4112. case '0':
  4113. str += '\0';
  4114. break;
  4115. // null character
  4116. case 'a':
  4117. str += '\x07';
  4118. break;
  4119. // bell character
  4120. case 'b':
  4121. str += '\b';
  4122. break;
  4123. // backspace
  4124. case 'e':
  4125. str += '\x1b';
  4126. break;
  4127. // escape character
  4128. case 'f':
  4129. str += '\f';
  4130. break;
  4131. // form feed
  4132. case 'n':
  4133. str += '\n';
  4134. break;
  4135. // line feed
  4136. case 'r':
  4137. str += '\r';
  4138. break;
  4139. // carriage return
  4140. case 't':
  4141. str += '\t';
  4142. break;
  4143. // horizontal tab
  4144. case 'v':
  4145. str += '\v';
  4146. break;
  4147. // vertical tab
  4148. case 'N':
  4149. str += '\u0085';
  4150. break;
  4151. // Unicode next line
  4152. case '_':
  4153. str += '\u00a0';
  4154. break;
  4155. // Unicode non-breaking space
  4156. case 'L':
  4157. str += '\u2028';
  4158. break;
  4159. // Unicode line separator
  4160. case 'P':
  4161. str += '\u2029';
  4162. break;
  4163. // Unicode paragraph separator
  4164. case ' ':
  4165. str += ' ';
  4166. break;
  4167. case '"':
  4168. str += '"';
  4169. break;
  4170. case '/':
  4171. str += '/';
  4172. break;
  4173. case '\\':
  4174. str += '\\';
  4175. break;
  4176. case '\t':
  4177. str += '\t';
  4178. break;
  4179. case 'x':
  4180. str += this.parseCharCode(i + 1, 2, errors);
  4181. i += 2;
  4182. break;
  4183. case 'u':
  4184. str += this.parseCharCode(i + 1, 4, errors);
  4185. i += 4;
  4186. break;
  4187. case 'U':
  4188. str += this.parseCharCode(i + 1, 8, errors);
  4189. i += 8;
  4190. break;
  4191. case '\n':
  4192. // skip escaped newlines, but still trim the following line
  4193. while (src[i + 1] === ' ' || src[i + 1] === '\t') i += 1;
  4194. break;
  4195. default:
  4196. errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(i - 1, 2)}`));
  4197. str += '\\' + src[i];
  4198. }
  4199. } else if (ch === ' ' || ch === '\t') {
  4200. // trim trailing whitespace
  4201. const wsStart = i;
  4202. let next = src[i + 1];
  4203. while (next === ' ' || next === '\t') {
  4204. i += 1;
  4205. next = src[i + 1];
  4206. }
  4207. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  4208. } else {
  4209. str += ch;
  4210. }
  4211. }
  4212. return errors.length > 0 ? {
  4213. errors,
  4214. str
  4215. } : str;
  4216. }
  4217. parseCharCode(offset, length, errors) {
  4218. const {
  4219. src
  4220. } = this.context;
  4221. const cc = src.substr(offset, length);
  4222. const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
  4223. const code = ok ? parseInt(cc, 16) : NaN;
  4224. if (isNaN(code)) {
  4225. errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(offset - 2, length + 2)}`));
  4226. return src.substr(offset - 2, length + 2);
  4227. }
  4228. return String.fromCodePoint(code);
  4229. }
  4230. /**
  4231. * Parses a "double quoted" value from the source
  4232. *
  4233. * @param {ParseContext} context
  4234. * @param {number} start - Index of first character
  4235. * @returns {number} - Index of the character after this scalar
  4236. */
  4237. parse(context, start) {
  4238. this.context = context;
  4239. const {
  4240. src
  4241. } = context;
  4242. let offset = QuoteDouble.endOfQuote(src, start + 1);
  4243. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  4244. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4245. offset = this.parseComment(offset);
  4246. return offset;
  4247. }
  4248. }
  4249. class QuoteSingle extends PlainValueEc8e588e.Node {
  4250. static endOfQuote(src, offset) {
  4251. let ch = src[offset];
  4252. while (ch) {
  4253. if (ch === "'") {
  4254. if (src[offset + 1] !== "'") break;
  4255. ch = src[offset += 2];
  4256. } else {
  4257. ch = src[offset += 1];
  4258. }
  4259. }
  4260. return offset + 1;
  4261. }
  4262. /**
  4263. * @returns {string | { str: string, errors: YAMLSyntaxError[] }}
  4264. */
  4265. get strValue() {
  4266. if (!this.valueRange || !this.context) return null;
  4267. const errors = [];
  4268. const {
  4269. start,
  4270. end
  4271. } = this.valueRange;
  4272. const {
  4273. indent,
  4274. src
  4275. } = this.context;
  4276. if (src[end - 1] !== "'") errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, "Missing closing 'quote"));
  4277. let str = '';
  4278. for (let i = start + 1; i < end - 1; ++i) {
  4279. const ch = src[i];
  4280. if (ch === '\n') {
  4281. if (PlainValueEc8e588e.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
  4282. const {
  4283. fold,
  4284. offset,
  4285. error
  4286. } = PlainValueEc8e588e.Node.foldNewline(src, i, indent);
  4287. str += fold;
  4288. i = offset;
  4289. if (error) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented'));
  4290. } else if (ch === "'") {
  4291. str += ch;
  4292. i += 1;
  4293. if (src[i] !== "'") errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.'));
  4294. } else if (ch === ' ' || ch === '\t') {
  4295. // trim trailing whitespace
  4296. const wsStart = i;
  4297. let next = src[i + 1];
  4298. while (next === ' ' || next === '\t') {
  4299. i += 1;
  4300. next = src[i + 1];
  4301. }
  4302. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  4303. } else {
  4304. str += ch;
  4305. }
  4306. }
  4307. return errors.length > 0 ? {
  4308. errors,
  4309. str
  4310. } : str;
  4311. }
  4312. /**
  4313. * Parses a 'single quoted' value from the source
  4314. *
  4315. * @param {ParseContext} context
  4316. * @param {number} start - Index of first character
  4317. * @returns {number} - Index of the character after this scalar
  4318. */
  4319. parse(context, start) {
  4320. this.context = context;
  4321. const {
  4322. src
  4323. } = context;
  4324. let offset = QuoteSingle.endOfQuote(src, start + 1);
  4325. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  4326. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4327. offset = this.parseComment(offset);
  4328. return offset;
  4329. }
  4330. }
  4331. function createNewNode(type, props) {
  4332. switch (type) {
  4333. case PlainValueEc8e588e.Type.ALIAS:
  4334. return new Alias(type, props);
  4335. case PlainValueEc8e588e.Type.BLOCK_FOLDED:
  4336. case PlainValueEc8e588e.Type.BLOCK_LITERAL:
  4337. return new BlockValue(type, props);
  4338. case PlainValueEc8e588e.Type.FLOW_MAP:
  4339. case PlainValueEc8e588e.Type.FLOW_SEQ:
  4340. return new FlowCollection(type, props);
  4341. case PlainValueEc8e588e.Type.MAP_KEY:
  4342. case PlainValueEc8e588e.Type.MAP_VALUE:
  4343. case PlainValueEc8e588e.Type.SEQ_ITEM:
  4344. return new CollectionItem(type, props);
  4345. case PlainValueEc8e588e.Type.COMMENT:
  4346. case PlainValueEc8e588e.Type.PLAIN:
  4347. return new PlainValueEc8e588e.PlainValue(type, props);
  4348. case PlainValueEc8e588e.Type.QUOTE_DOUBLE:
  4349. return new QuoteDouble(type, props);
  4350. case PlainValueEc8e588e.Type.QUOTE_SINGLE:
  4351. return new QuoteSingle(type, props);
  4352. /* istanbul ignore next */
  4353. default:
  4354. return null;
  4355. // should never happen
  4356. }
  4357. }
  4358. /**
  4359. * @param {boolean} atLineStart - Node starts at beginning of line
  4360. * @param {boolean} inFlow - true if currently in a flow context
  4361. * @param {boolean} inCollection - true if currently in a collection context
  4362. * @param {number} indent - Current level of indentation
  4363. * @param {number} lineStart - Start of the current line
  4364. * @param {Node} parent - The parent of the node
  4365. * @param {string} src - Source of the YAML document
  4366. */
  4367. class ParseContext {
  4368. static parseType(src, offset, inFlow) {
  4369. switch (src[offset]) {
  4370. case '*':
  4371. return PlainValueEc8e588e.Type.ALIAS;
  4372. case '>':
  4373. return PlainValueEc8e588e.Type.BLOCK_FOLDED;
  4374. case '|':
  4375. return PlainValueEc8e588e.Type.BLOCK_LITERAL;
  4376. case '{':
  4377. return PlainValueEc8e588e.Type.FLOW_MAP;
  4378. case '[':
  4379. return PlainValueEc8e588e.Type.FLOW_SEQ;
  4380. case '?':
  4381. return !inFlow && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true) ? PlainValueEc8e588e.Type.MAP_KEY : PlainValueEc8e588e.Type.PLAIN;
  4382. case ':':
  4383. return !inFlow && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true) ? PlainValueEc8e588e.Type.MAP_VALUE : PlainValueEc8e588e.Type.PLAIN;
  4384. case '-':
  4385. return !inFlow && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true) ? PlainValueEc8e588e.Type.SEQ_ITEM : PlainValueEc8e588e.Type.PLAIN;
  4386. case '"':
  4387. return PlainValueEc8e588e.Type.QUOTE_DOUBLE;
  4388. case "'":
  4389. return PlainValueEc8e588e.Type.QUOTE_SINGLE;
  4390. default:
  4391. return PlainValueEc8e588e.Type.PLAIN;
  4392. }
  4393. }
  4394. constructor(orig = {}, {
  4395. atLineStart,
  4396. inCollection,
  4397. inFlow,
  4398. indent,
  4399. lineStart,
  4400. parent
  4401. } = {}) {
  4402. PlainValueEc8e588e._defineProperty(this, "parseNode", (overlay, start) => {
  4403. if (PlainValueEc8e588e.Node.atDocumentBoundary(this.src, start)) return null;
  4404. const context = new ParseContext(this, overlay);
  4405. const {
  4406. props,
  4407. type,
  4408. valueStart
  4409. } = context.parseProps(start);
  4410. const node = createNewNode(type, props);
  4411. let offset = node.parse(context, valueStart);
  4412. node.range = new PlainValueEc8e588e.Range(start, offset);
  4413. /* istanbul ignore if */
  4414. if (offset <= start) {
  4415. // This should never happen, but if it does, let's make sure to at least
  4416. // step one character forward to avoid a busy loop.
  4417. node.error = new Error(`Node#parse consumed no characters`);
  4418. node.error.parseEnd = offset;
  4419. node.error.source = node;
  4420. node.range.end = start + 1;
  4421. }
  4422. if (context.nodeStartsCollection(node)) {
  4423. if (!node.error && !context.atLineStart && context.parent.type === PlainValueEc8e588e.Type.DOCUMENT) {
  4424. node.error = new PlainValueEc8e588e.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
  4425. }
  4426. const collection = new Collection(node);
  4427. offset = collection.parse(new ParseContext(context), offset);
  4428. collection.range = new PlainValueEc8e588e.Range(start, offset);
  4429. return collection;
  4430. }
  4431. return node;
  4432. });
  4433. this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
  4434. this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
  4435. this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
  4436. this.indent = indent != null ? indent : orig.indent;
  4437. this.lineStart = lineStart != null ? lineStart : orig.lineStart;
  4438. this.parent = parent != null ? parent : orig.parent || {};
  4439. this.root = orig.root;
  4440. this.src = orig.src;
  4441. }
  4442. nodeStartsCollection(node) {
  4443. const {
  4444. inCollection,
  4445. inFlow,
  4446. src
  4447. } = this;
  4448. if (inCollection || inFlow) return false;
  4449. if (node instanceof CollectionItem) return true; // check for implicit key
  4450. let offset = node.range.end;
  4451. if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
  4452. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4453. return src[offset] === ':';
  4454. } // Anchor and tag are before type, which determines the node implementation
  4455. // class; hence this intermediate step.
  4456. parseProps(offset) {
  4457. const {
  4458. inFlow,
  4459. parent,
  4460. src
  4461. } = this;
  4462. const props = [];
  4463. let lineHasProps = false;
  4464. offset = this.atLineStart ? PlainValueEc8e588e.Node.endOfIndent(src, offset) : PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4465. let ch = src[offset];
  4466. while (ch === PlainValueEc8e588e.Char.ANCHOR || ch === PlainValueEc8e588e.Char.COMMENT || ch === PlainValueEc8e588e.Char.TAG || ch === '\n') {
  4467. if (ch === '\n') {
  4468. const lineStart = offset + 1;
  4469. const inEnd = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  4470. const indentDiff = inEnd - (lineStart + this.indent);
  4471. const noIndicatorAsIndent = parent.type === PlainValueEc8e588e.Type.SEQ_ITEM && parent.context.atLineStart;
  4472. if (!PlainValueEc8e588e.Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
  4473. this.atLineStart = true;
  4474. this.lineStart = lineStart;
  4475. lineHasProps = false;
  4476. offset = inEnd;
  4477. } else if (ch === PlainValueEc8e588e.Char.COMMENT) {
  4478. const end = PlainValueEc8e588e.Node.endOfLine(src, offset + 1);
  4479. props.push(new PlainValueEc8e588e.Range(offset, end));
  4480. offset = end;
  4481. } else {
  4482. let end = PlainValueEc8e588e.Node.endOfIdentifier(src, offset + 1);
  4483. if (ch === PlainValueEc8e588e.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))) {
  4484. // Let's presume we're dealing with a YAML 1.0 domain tag here, rather
  4485. // than an empty but 'foo.bar' private-tagged node in a flow collection
  4486. // followed without whitespace by a plain string starting with a year
  4487. // or date divided by something.
  4488. end = PlainValueEc8e588e.Node.endOfIdentifier(src, end + 5);
  4489. }
  4490. props.push(new PlainValueEc8e588e.Range(offset, end));
  4491. lineHasProps = true;
  4492. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, end);
  4493. }
  4494. ch = src[offset];
  4495. } // '- &a : b' has an anchor on an empty node
  4496. if (lineHasProps && ch === ':' && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true)) offset -= 1;
  4497. const type = ParseContext.parseType(src, offset, inFlow);
  4498. return {
  4499. props,
  4500. type,
  4501. valueStart: offset
  4502. };
  4503. }
  4504. /**
  4505. * Parses a node from the source
  4506. * @param {ParseContext} overlay
  4507. * @param {number} start - Index of first non-whitespace character for the node
  4508. * @returns {?Node} - null if at a document boundary
  4509. */
  4510. } // Published as 'yaml/parse-cst'
  4511. function parse(src) {
  4512. const cr = [];
  4513. if (src.indexOf('\r') !== -1) {
  4514. src = src.replace(/\r\n?/g, (match, offset) => {
  4515. if (match.length > 1) cr.push(offset);
  4516. return '\n';
  4517. });
  4518. }
  4519. const documents = [];
  4520. let offset = 0;
  4521. do {
  4522. const doc = new Document();
  4523. const context = new ParseContext({
  4524. src
  4525. });
  4526. offset = doc.parse(context, offset);
  4527. documents.push(doc);
  4528. } while (offset < src.length);
  4529. documents.setOrigRanges = () => {
  4530. if (cr.length === 0) return false;
  4531. for (let i = 1; i < cr.length; ++i) cr[i] -= i;
  4532. let crOffset = 0;
  4533. for (let i = 0; i < documents.length; ++i) {
  4534. crOffset = documents[i].setOrigRanges(cr, crOffset);
  4535. }
  4536. cr.splice(0, cr.length);
  4537. return true;
  4538. };
  4539. documents.toString = () => documents.join('...\n');
  4540. return documents;
  4541. }
  4542. var parse_1 = parse;
  4543. var parseCst = {
  4544. parse: parse_1
  4545. };
  4546. function addCommentBefore(str, indent, comment) {
  4547. if (!comment) return str;
  4548. const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`);
  4549. return `#${cc}\n${indent}${str}`;
  4550. }
  4551. function addComment(str, indent, comment) {
  4552. return !comment ? str : comment.indexOf('\n') === -1 ? `${str} #${comment}` : `${str}\n` + comment.replace(/^/gm, `${indent || ''}#`);
  4553. }
  4554. class Node$1 {}
  4555. function toJSON(value, arg, ctx) {
  4556. if (Array.isArray(value)) return value.map((v, i) => toJSON(v, String(i), ctx));
  4557. if (value && typeof value.toJSON === 'function') {
  4558. const anchor = ctx && ctx.anchors && ctx.anchors.get(value);
  4559. if (anchor) ctx.onCreate = res => {
  4560. anchor.res = res;
  4561. delete ctx.onCreate;
  4562. };
  4563. const res = value.toJSON(arg, ctx);
  4564. if (anchor && ctx.onCreate) ctx.onCreate(res);
  4565. return res;
  4566. }
  4567. if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
  4568. return value;
  4569. }
  4570. class Scalar extends Node$1 {
  4571. constructor(value) {
  4572. super();
  4573. this.value = value;
  4574. }
  4575. toJSON(arg, ctx) {
  4576. return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx);
  4577. }
  4578. toString() {
  4579. return String(this.value);
  4580. }
  4581. }
  4582. function collectionFromPath(schema, path, value) {
  4583. let v = value;
  4584. for (let i = path.length - 1; i >= 0; --i) {
  4585. const k = path[i];
  4586. const o = Number.isInteger(k) && k >= 0 ? [] : {};
  4587. o[k] = v;
  4588. v = o;
  4589. }
  4590. return schema.createNode(v, false);
  4591. } // null, undefined, or an empty non-string iterable (e.g. [])
  4592. const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
  4593. class Collection$1 extends Node$1 {
  4594. constructor(schema) {
  4595. super();
  4596. PlainValueEc8e588e._defineProperty(this, "items", []);
  4597. this.schema = schema;
  4598. }
  4599. addIn(path, value) {
  4600. if (isEmptyPath(path)) this.add(value);else {
  4601. const [key, ...rest] = path;
  4602. const node = this.get(key, true);
  4603. if (node instanceof Collection$1) 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}`);
  4604. }
  4605. }
  4606. deleteIn([key, ...rest]) {
  4607. if (rest.length === 0) return this.delete(key);
  4608. const node = this.get(key, true);
  4609. if (node instanceof Collection$1) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
  4610. }
  4611. getIn([key, ...rest], keepScalar) {
  4612. const node = this.get(key, true);
  4613. if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection$1 ? node.getIn(rest, keepScalar) : undefined;
  4614. }
  4615. hasAllNullValues() {
  4616. return this.items.every(node => {
  4617. if (!node || node.type !== 'PAIR') return false;
  4618. const n = node.value;
  4619. return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
  4620. });
  4621. }
  4622. hasIn([key, ...rest]) {
  4623. if (rest.length === 0) return this.has(key);
  4624. const node = this.get(key, true);
  4625. return node instanceof Collection$1 ? node.hasIn(rest) : false;
  4626. }
  4627. setIn([key, ...rest], value) {
  4628. if (rest.length === 0) {
  4629. this.set(key, value);
  4630. } else {
  4631. const node = this.get(key, true);
  4632. if (node instanceof Collection$1) 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}`);
  4633. }
  4634. } // overridden in implementations
  4635. /* istanbul ignore next */
  4636. toJSON() {
  4637. return null;
  4638. }
  4639. toString(ctx, {
  4640. blockItem,
  4641. flowChars,
  4642. isMap,
  4643. itemIndent
  4644. }, onComment, onChompKeep) {
  4645. const {
  4646. indent,
  4647. indentStep,
  4648. stringify
  4649. } = ctx;
  4650. const inFlow = this.type === PlainValueEc8e588e.Type.FLOW_MAP || this.type === PlainValueEc8e588e.Type.FLOW_SEQ || ctx.inFlow;
  4651. if (inFlow) itemIndent += indentStep;
  4652. const allNullValues = isMap && this.hasAllNullValues();
  4653. ctx = Object.assign({}, ctx, {
  4654. allNullValues,
  4655. indent: itemIndent,
  4656. inFlow,
  4657. type: null
  4658. });
  4659. let chompKeep = false;
  4660. let hasItemWithNewLine = false;
  4661. const nodes = this.items.reduce((nodes, item, i) => {
  4662. let comment;
  4663. if (item) {
  4664. if (!chompKeep && item.spaceBefore) nodes.push({
  4665. type: 'comment',
  4666. str: ''
  4667. });
  4668. if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(line => {
  4669. nodes.push({
  4670. type: 'comment',
  4671. str: `#${line}`
  4672. });
  4673. });
  4674. if (item.comment) comment = item.comment;
  4675. 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;
  4676. }
  4677. chompKeep = false;
  4678. let str = stringify(item, ctx, () => comment = null, () => chompKeep = true);
  4679. if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
  4680. if (inFlow && i < this.items.length - 1) str += ',';
  4681. str = addComment(str, itemIndent, comment);
  4682. if (chompKeep && (comment || inFlow)) chompKeep = false;
  4683. nodes.push({
  4684. type: 'item',
  4685. str
  4686. });
  4687. return nodes;
  4688. }, []);
  4689. let str;
  4690. if (nodes.length === 0) {
  4691. str = flowChars.start + flowChars.end;
  4692. } else if (inFlow) {
  4693. const {
  4694. start,
  4695. end
  4696. } = flowChars;
  4697. const strings = nodes.map(n => n.str);
  4698. if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection$1.maxFlowStringSingleLineLength) {
  4699. str = start;
  4700. for (const s of strings) {
  4701. str += s ? `\n${indentStep}${indent}${s}` : '\n';
  4702. }
  4703. str += `\n${indent}${end}`;
  4704. } else {
  4705. str = `${start} ${strings.join(' ')} ${end}`;
  4706. }
  4707. } else {
  4708. const strings = nodes.map(blockItem);
  4709. str = strings.shift();
  4710. for (const s of strings) str += s ? `\n${indent}${s}` : '\n';
  4711. }
  4712. if (this.comment) {
  4713. str += '\n' + this.comment.replace(/^/gm, `${indent}#`);
  4714. if (onComment) onComment();
  4715. } else if (chompKeep && onChompKeep) onChompKeep();
  4716. return str;
  4717. }
  4718. }
  4719. PlainValueEc8e588e._defineProperty(Collection$1, "maxFlowStringSingleLineLength", 60);
  4720. function asItemIndex(key) {
  4721. let idx = key instanceof Scalar ? key.value : key;
  4722. if (idx && typeof idx === 'string') idx = Number(idx);
  4723. return Number.isInteger(idx) && idx >= 0 ? idx : null;
  4724. }
  4725. class YAMLSeq extends Collection$1 {
  4726. add(value) {
  4727. this.items.push(value);
  4728. }
  4729. delete(key) {
  4730. const idx = asItemIndex(key);
  4731. if (typeof idx !== 'number') return false;
  4732. const del = this.items.splice(idx, 1);
  4733. return del.length > 0;
  4734. }
  4735. get(key, keepScalar) {
  4736. const idx = asItemIndex(key);
  4737. if (typeof idx !== 'number') return undefined;
  4738. const it = this.items[idx];
  4739. return !keepScalar && it instanceof Scalar ? it.value : it;
  4740. }
  4741. has(key) {
  4742. const idx = asItemIndex(key);
  4743. return typeof idx === 'number' && idx < this.items.length;
  4744. }
  4745. set(key, value) {
  4746. const idx = asItemIndex(key);
  4747. if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`);
  4748. this.items[idx] = value;
  4749. }
  4750. toJSON(_, ctx) {
  4751. const seq = [];
  4752. if (ctx && ctx.onCreate) ctx.onCreate(seq);
  4753. let i = 0;
  4754. for (const item of this.items) seq.push(toJSON(item, String(i++), ctx));
  4755. return seq;
  4756. }
  4757. toString(ctx, onComment, onChompKeep) {
  4758. if (!ctx) return JSON.stringify(this);
  4759. return super.toString(ctx, {
  4760. blockItem: n => n.type === 'comment' ? n.str : `- ${n.str}`,
  4761. flowChars: {
  4762. start: '[',
  4763. end: ']'
  4764. },
  4765. isMap: false,
  4766. itemIndent: (ctx.indent || '') + ' '
  4767. }, onComment, onChompKeep);
  4768. }
  4769. }
  4770. const stringifyKey = (key, jsKey, ctx) => {
  4771. if (jsKey === null) return '';
  4772. if (typeof jsKey !== 'object') return String(jsKey);
  4773. if (key instanceof Node$1 && ctx && ctx.doc) return key.toString({
  4774. anchors: {},
  4775. doc: ctx.doc,
  4776. indent: '',
  4777. indentStep: ctx.indentStep,
  4778. inFlow: true,
  4779. inStringifyKey: true,
  4780. stringify: ctx.stringify
  4781. });
  4782. return JSON.stringify(jsKey);
  4783. };
  4784. class Pair extends Node$1 {
  4785. constructor(key, value = null) {
  4786. super();
  4787. this.key = key;
  4788. this.value = value;
  4789. this.type = Pair.Type.PAIR;
  4790. }
  4791. get commentBefore() {
  4792. return this.key instanceof Node$1 ? this.key.commentBefore : undefined;
  4793. }
  4794. set commentBefore(cb) {
  4795. if (this.key == null) this.key = new Scalar(null);
  4796. if (this.key instanceof Node$1) this.key.commentBefore = cb;else {
  4797. const msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.';
  4798. throw new Error(msg);
  4799. }
  4800. }
  4801. addToJSMap(ctx, map) {
  4802. const key = toJSON(this.key, '', ctx);
  4803. if (map instanceof Map) {
  4804. const value = toJSON(this.value, key, ctx);
  4805. map.set(key, value);
  4806. } else if (map instanceof Set) {
  4807. map.add(key);
  4808. } else {
  4809. const stringKey = stringifyKey(this.key, key, ctx);
  4810. map[stringKey] = toJSON(this.value, stringKey, ctx);
  4811. }
  4812. return map;
  4813. }
  4814. toJSON(_, ctx) {
  4815. const pair = ctx && ctx.mapAsMap ? new Map() : {};
  4816. return this.addToJSMap(ctx, pair);
  4817. }
  4818. toString(ctx, onComment, onChompKeep) {
  4819. if (!ctx || !ctx.doc) return JSON.stringify(this);
  4820. const {
  4821. indent: indentSize,
  4822. indentSeq,
  4823. simpleKeys
  4824. } = ctx.doc.options;
  4825. let {
  4826. key,
  4827. value
  4828. } = this;
  4829. let keyComment = key instanceof Node$1 && key.comment;
  4830. if (simpleKeys) {
  4831. if (keyComment) {
  4832. throw new Error('With simple keys, key nodes cannot have comments');
  4833. }
  4834. if (key instanceof Collection$1) {
  4835. const msg = 'With simple keys, collection cannot be used as a key value';
  4836. throw new Error(msg);
  4837. }
  4838. }
  4839. const explicitKey = !simpleKeys && (!key || keyComment || key instanceof Collection$1 || key.type === PlainValueEc8e588e.Type.BLOCK_FOLDED || key.type === PlainValueEc8e588e.Type.BLOCK_LITERAL);
  4840. const {
  4841. doc,
  4842. indent,
  4843. indentStep,
  4844. stringify
  4845. } = ctx;
  4846. ctx = Object.assign({}, ctx, {
  4847. implicitKey: !explicitKey,
  4848. indent: indent + indentStep
  4849. });
  4850. let chompKeep = false;
  4851. let str = stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
  4852. str = addComment(str, ctx.indent, keyComment);
  4853. if (ctx.allNullValues && !simpleKeys) {
  4854. if (this.comment) {
  4855. str = addComment(str, ctx.indent, this.comment);
  4856. if (onComment) onComment();
  4857. } else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
  4858. return ctx.inFlow ? str : `? ${str}`;
  4859. }
  4860. str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`;
  4861. if (this.comment) {
  4862. // expected (but not strictly required) to be a single-line comment
  4863. str = addComment(str, ctx.indent, this.comment);
  4864. if (onComment) onComment();
  4865. }
  4866. let vcb = '';
  4867. let valueComment = null;
  4868. if (value instanceof Node$1) {
  4869. if (value.spaceBefore) vcb = '\n';
  4870. if (value.commentBefore) {
  4871. const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
  4872. vcb += `\n${cs}`;
  4873. }
  4874. valueComment = value.comment;
  4875. } else if (value && typeof value === 'object') {
  4876. value = doc.schema.createNode(value, true);
  4877. }
  4878. ctx.implicitKey = false;
  4879. if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1;
  4880. chompKeep = false;
  4881. if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== PlainValueEc8e588e.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
  4882. // If indentSeq === false, consider '- ' as part of indentation where possible
  4883. ctx.indent = ctx.indent.substr(2);
  4884. }
  4885. const valueStr = stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
  4886. let ws = ' ';
  4887. if (vcb || this.comment) {
  4888. ws = `${vcb}\n${ctx.indent}`;
  4889. } else if (!explicitKey && value instanceof Collection$1) {
  4890. const flow = valueStr[0] === '[' || valueStr[0] === '{';
  4891. if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
  4892. }
  4893. if (chompKeep && !valueComment && onChompKeep) onChompKeep();
  4894. return addComment(str + ws + valueStr, ctx.indent, valueComment);
  4895. }
  4896. }
  4897. PlainValueEc8e588e._defineProperty(Pair, "Type", {
  4898. PAIR: 'PAIR',
  4899. MERGE_PAIR: 'MERGE_PAIR'
  4900. });
  4901. const getAliasCount = (node, anchors) => {
  4902. if (node instanceof Alias$1) {
  4903. const anchor = anchors.get(node.source);
  4904. return anchor.count * anchor.aliasCount;
  4905. } else if (node instanceof Collection$1) {
  4906. let count = 0;
  4907. for (const item of node.items) {
  4908. const c = getAliasCount(item, anchors);
  4909. if (c > count) count = c;
  4910. }
  4911. return count;
  4912. } else if (node instanceof Pair) {
  4913. const kc = getAliasCount(node.key, anchors);
  4914. const vc = getAliasCount(node.value, anchors);
  4915. return Math.max(kc, vc);
  4916. }
  4917. return 1;
  4918. };
  4919. class Alias$1 extends Node$1 {
  4920. static stringify({
  4921. range,
  4922. source
  4923. }, {
  4924. anchors,
  4925. doc,
  4926. implicitKey,
  4927. inStringifyKey
  4928. }) {
  4929. let anchor = Object.keys(anchors).find(a => anchors[a] === source);
  4930. if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
  4931. if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
  4932. const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
  4933. throw new Error(`${msg} [${range}]`);
  4934. }
  4935. constructor(source) {
  4936. super();
  4937. this.source = source;
  4938. this.type = PlainValueEc8e588e.Type.ALIAS;
  4939. }
  4940. set tag(t) {
  4941. throw new Error('Alias nodes cannot have tags');
  4942. }
  4943. toJSON(arg, ctx) {
  4944. if (!ctx) return toJSON(this.source, arg, ctx);
  4945. const {
  4946. anchors,
  4947. maxAliasCount
  4948. } = ctx;
  4949. const anchor = anchors.get(this.source);
  4950. /* istanbul ignore if */
  4951. if (!anchor || anchor.res === undefined) {
  4952. const msg = 'This should not happen: Alias anchor was not resolved?';
  4953. if (this.cstNode) throw new PlainValueEc8e588e.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  4954. }
  4955. if (maxAliasCount >= 0) {
  4956. anchor.count += 1;
  4957. if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
  4958. if (anchor.count * anchor.aliasCount > maxAliasCount) {
  4959. const msg = 'Excessive alias count indicates a resource exhaustion attack';
  4960. if (this.cstNode) throw new PlainValueEc8e588e.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  4961. }
  4962. }
  4963. return anchor.res;
  4964. } // Only called when stringifying an alias mapping key while constructing
  4965. // Object output.
  4966. toString(ctx) {
  4967. return Alias$1.stringify(this, ctx);
  4968. }
  4969. }
  4970. PlainValueEc8e588e._defineProperty(Alias$1, "default", true);
  4971. function findPair(items, key) {
  4972. const k = key instanceof Scalar ? key.value : key;
  4973. for (const it of items) {
  4974. if (it instanceof Pair) {
  4975. if (it.key === key || it.key === k) return it;
  4976. if (it.key && it.key.value === k) return it;
  4977. }
  4978. }
  4979. return undefined;
  4980. }
  4981. class YAMLMap extends Collection$1 {
  4982. add(pair, overwrite) {
  4983. if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value);
  4984. const prev = findPair(this.items, pair.key);
  4985. const sortEntries = this.schema && this.schema.sortMapEntries;
  4986. if (prev) {
  4987. if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
  4988. } else if (sortEntries) {
  4989. const i = this.items.findIndex(item => sortEntries(pair, item) < 0);
  4990. if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
  4991. } else {
  4992. this.items.push(pair);
  4993. }
  4994. }
  4995. delete(key) {
  4996. const it = findPair(this.items, key);
  4997. if (!it) return false;
  4998. const del = this.items.splice(this.items.indexOf(it), 1);
  4999. return del.length > 0;
  5000. }
  5001. get(key, keepScalar) {
  5002. const it = findPair(this.items, key);
  5003. const node = it && it.value;
  5004. return !keepScalar && node instanceof Scalar ? node.value : node;
  5005. }
  5006. has(key) {
  5007. return !!findPair(this.items, key);
  5008. }
  5009. set(key, value) {
  5010. this.add(new Pair(key, value), true);
  5011. }
  5012. /**
  5013. * @param {*} arg ignored
  5014. * @param {*} ctx Conversion context, originally set in Document#toJSON()
  5015. * @param {Class} Type If set, forces the returned collection type
  5016. * @returns {*} Instance of Type, Map, or Object
  5017. */
  5018. toJSON(_, ctx, Type) {
  5019. const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
  5020. if (ctx && ctx.onCreate) ctx.onCreate(map);
  5021. for (const item of this.items) item.addToJSMap(ctx, map);
  5022. return map;
  5023. }
  5024. toString(ctx, onComment, onChompKeep) {
  5025. if (!ctx) return JSON.stringify(this);
  5026. for (const item of this.items) {
  5027. if (!(item instanceof Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
  5028. }
  5029. return super.toString(ctx, {
  5030. blockItem: n => n.str,
  5031. flowChars: {
  5032. start: '{',
  5033. end: '}'
  5034. },
  5035. isMap: true,
  5036. itemIndent: ctx.indent || ''
  5037. }, onComment, onChompKeep);
  5038. }
  5039. }
  5040. const MERGE_KEY = '<<';
  5041. class Merge extends Pair {
  5042. constructor(pair) {
  5043. if (pair instanceof Pair) {
  5044. let seq = pair.value;
  5045. if (!(seq instanceof YAMLSeq)) {
  5046. seq = new YAMLSeq();
  5047. seq.items.push(pair.value);
  5048. seq.range = pair.value.range;
  5049. }
  5050. super(pair.key, seq);
  5051. this.range = pair.range;
  5052. } else {
  5053. super(new Scalar(MERGE_KEY), new YAMLSeq());
  5054. }
  5055. this.type = Pair.Type.MERGE_PAIR;
  5056. } // If the value associated with a merge key is a single mapping node, each of
  5057. // its key/value pairs is inserted into the current mapping, unless the key
  5058. // already exists in it. If the value associated with the merge key is a
  5059. // sequence, then this sequence is expected to contain mapping nodes and each
  5060. // of these nodes is merged in turn according to its order in the sequence.
  5061. // Keys in mapping nodes earlier in the sequence override keys specified in
  5062. // later mapping nodes. -- http://yaml.org/type/merge.html
  5063. addToJSMap(ctx, map) {
  5064. for (const {
  5065. source
  5066. } of this.value.items) {
  5067. if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
  5068. const srcMap = source.toJSON(null, ctx, Map);
  5069. for (const [key, value] of srcMap) {
  5070. if (map instanceof Map) {
  5071. if (!map.has(key)) map.set(key, value);
  5072. } else if (map instanceof Set) {
  5073. map.add(key);
  5074. } else {
  5075. if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value;
  5076. }
  5077. }
  5078. }
  5079. return map;
  5080. }
  5081. toString(ctx, onComment) {
  5082. const seq = this.value;
  5083. if (seq.items.length > 1) return super.toString(ctx, onComment);
  5084. this.value = seq.items[0];
  5085. const str = super.toString(ctx, onComment);
  5086. this.value = seq;
  5087. return str;
  5088. }
  5089. }
  5090. const binaryOptions = {
  5091. defaultType: PlainValueEc8e588e.Type.BLOCK_LITERAL,
  5092. lineWidth: 76
  5093. };
  5094. const boolOptions = {
  5095. trueStr: 'true',
  5096. falseStr: 'false'
  5097. };
  5098. const intOptions = {
  5099. asBigInt: false
  5100. };
  5101. const nullOptions = {
  5102. nullStr: 'null'
  5103. };
  5104. const strOptions = {
  5105. defaultType: PlainValueEc8e588e.Type.PLAIN,
  5106. doubleQuoted: {
  5107. jsonEncoding: false,
  5108. minMultiLineLength: 40
  5109. },
  5110. fold: {
  5111. lineWidth: 80,
  5112. minContentWidth: 20
  5113. }
  5114. };
  5115. function resolveScalar(str, tags, scalarFallback) {
  5116. for (const {
  5117. format,
  5118. test,
  5119. resolve
  5120. } of tags) {
  5121. if (test) {
  5122. const match = str.match(test);
  5123. if (match) {
  5124. let res = resolve.apply(null, match);
  5125. if (!(res instanceof Scalar)) res = new Scalar(res);
  5126. if (format) res.format = format;
  5127. return res;
  5128. }
  5129. }
  5130. }
  5131. if (scalarFallback) str = scalarFallback(str);
  5132. return new Scalar(str);
  5133. }
  5134. const FOLD_FLOW = 'flow';
  5135. const FOLD_BLOCK = 'block';
  5136. const FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line
  5137. // returns index of last newline in more-indented block
  5138. const consumeMoreIndentedLines = (text, i) => {
  5139. let ch = text[i + 1];
  5140. while (ch === ' ' || ch === '\t') {
  5141. do {
  5142. ch = text[i += 1];
  5143. } while (ch && ch !== '\n');
  5144. ch = text[i + 1];
  5145. }
  5146. return i;
  5147. };
  5148. /**
  5149. * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
  5150. * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
  5151. * terminated with `\n` and started with `indent`.
  5152. *
  5153. * @param {string} text
  5154. * @param {string} indent
  5155. * @param {string} [mode='flow'] `'block'` prevents more-indented lines
  5156. * from being folded; `'quoted'` allows for `\` escapes, including escaped
  5157. * newlines
  5158. * @param {Object} options
  5159. * @param {number} [options.indentAtStart] Accounts for leading contents on
  5160. * the first line, defaulting to `indent.length`
  5161. * @param {number} [options.lineWidth=80]
  5162. * @param {number} [options.minContentWidth=20] Allow highly indented lines to
  5163. * stretch the line width
  5164. * @param {function} options.onFold Called once if the text is folded
  5165. * @param {function} options.onFold Called once if any line of text exceeds
  5166. * lineWidth characters
  5167. */
  5168. function foldFlowLines(text, indent, mode, {
  5169. indentAtStart,
  5170. lineWidth = 80,
  5171. minContentWidth = 20,
  5172. onFold,
  5173. onOverflow
  5174. }) {
  5175. if (!lineWidth || lineWidth < 0) return text;
  5176. const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
  5177. if (text.length <= endStep) return text;
  5178. const folds = [];
  5179. const escapedFolds = {};
  5180. let end = lineWidth - (typeof indentAtStart === 'number' ? indentAtStart : indent.length);
  5181. let split = undefined;
  5182. let prev = undefined;
  5183. let overflow = false;
  5184. let i = -1;
  5185. if (mode === FOLD_BLOCK) {
  5186. i = consumeMoreIndentedLines(text, i);
  5187. if (i !== -1) end = i + endStep;
  5188. }
  5189. for (let ch; ch = text[i += 1];) {
  5190. if (mode === FOLD_QUOTED && ch === '\\') {
  5191. switch (text[i + 1]) {
  5192. case 'x':
  5193. i += 3;
  5194. break;
  5195. case 'u':
  5196. i += 5;
  5197. break;
  5198. case 'U':
  5199. i += 9;
  5200. break;
  5201. default:
  5202. i += 1;
  5203. }
  5204. }
  5205. if (ch === '\n') {
  5206. if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i);
  5207. end = i + endStep;
  5208. split = undefined;
  5209. } else {
  5210. if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') {
  5211. // space surrounded by non-space can be replaced with newline + indent
  5212. const next = text[i + 1];
  5213. if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i;
  5214. }
  5215. if (i >= end) {
  5216. if (split) {
  5217. folds.push(split);
  5218. end = split + endStep;
  5219. split = undefined;
  5220. } else if (mode === FOLD_QUOTED) {
  5221. // white-space collected at end may stretch past lineWidth
  5222. while (prev === ' ' || prev === '\t') {
  5223. prev = ch;
  5224. ch = text[i += 1];
  5225. overflow = true;
  5226. } // i - 2 accounts for not-dropped last char + newline-escaping \
  5227. folds.push(i - 2);
  5228. escapedFolds[i - 2] = true;
  5229. end = i - 2 + endStep;
  5230. split = undefined;
  5231. } else {
  5232. overflow = true;
  5233. }
  5234. }
  5235. }
  5236. prev = ch;
  5237. }
  5238. if (overflow && onOverflow) onOverflow();
  5239. if (folds.length === 0) return text;
  5240. if (onFold) onFold();
  5241. let res = text.slice(0, folds[0]);
  5242. for (let i = 0; i < folds.length; ++i) {
  5243. const fold = folds[i];
  5244. const end = folds[i + 1] || text.length;
  5245. if (mode === FOLD_QUOTED && escapedFolds[fold]) res += `${text[fold]}\\`;
  5246. res += `\n${indent}${text.slice(fold + 1, end)}`;
  5247. }
  5248. return res;
  5249. }
  5250. const getFoldOptions = ({
  5251. indentAtStart
  5252. }) => indentAtStart ? Object.assign({
  5253. indentAtStart
  5254. }, strOptions.fold) : strOptions.fold; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will
  5255. // presume that's starting a new document.
  5256. const containsDocumentMarker = str => /^(%|---|\.\.\.)/m.test(str);
  5257. function lineLengthOverLimit(str, limit) {
  5258. const strLen = str.length;
  5259. if (strLen <= limit) return false;
  5260. for (let i = 0, start = 0; i < strLen; ++i) {
  5261. if (str[i] === '\n') {
  5262. if (i - start > limit) return true;
  5263. start = i + 1;
  5264. if (strLen - start <= limit) return false;
  5265. }
  5266. }
  5267. return true;
  5268. }
  5269. function doubleQuotedString(value, ctx) {
  5270. const {
  5271. implicitKey
  5272. } = ctx;
  5273. const {
  5274. jsonEncoding,
  5275. minMultiLineLength
  5276. } = strOptions.doubleQuoted;
  5277. const json = JSON.stringify(value);
  5278. if (jsonEncoding) return json;
  5279. const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
  5280. let str = '';
  5281. let start = 0;
  5282. for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
  5283. if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
  5284. // space before newline needs to be escaped to not be folded
  5285. str += json.slice(start, i) + '\\ ';
  5286. i += 1;
  5287. start = i;
  5288. ch = '\\';
  5289. }
  5290. if (ch === '\\') switch (json[i + 1]) {
  5291. case 'u':
  5292. {
  5293. str += json.slice(start, i);
  5294. const code = json.substr(i + 2, 4);
  5295. switch (code) {
  5296. case '0000':
  5297. str += '\\0';
  5298. break;
  5299. case '0007':
  5300. str += '\\a';
  5301. break;
  5302. case '000b':
  5303. str += '\\v';
  5304. break;
  5305. case '001b':
  5306. str += '\\e';
  5307. break;
  5308. case '0085':
  5309. str += '\\N';
  5310. break;
  5311. case '00a0':
  5312. str += '\\_';
  5313. break;
  5314. case '2028':
  5315. str += '\\L';
  5316. break;
  5317. case '2029':
  5318. str += '\\P';
  5319. break;
  5320. default:
  5321. if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6);
  5322. }
  5323. i += 5;
  5324. start = i + 1;
  5325. }
  5326. break;
  5327. case 'n':
  5328. if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
  5329. i += 1;
  5330. } else {
  5331. // folding will eat first newline
  5332. str += json.slice(start, i) + '\n\n';
  5333. while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
  5334. str += '\n';
  5335. i += 2;
  5336. }
  5337. str += indent; // space after newline needs to be escaped to not be folded
  5338. if (json[i + 2] === ' ') str += '\\';
  5339. i += 1;
  5340. start = i + 1;
  5341. }
  5342. break;
  5343. default:
  5344. i += 1;
  5345. }
  5346. }
  5347. str = start ? str + json.slice(start) : json;
  5348. return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
  5349. }
  5350. function singleQuotedString(value, ctx) {
  5351. if (ctx.implicitKey) {
  5352. if (/\n/.test(value)) return doubleQuotedString(value, ctx);
  5353. } else {
  5354. // single quoted string can't have leading or trailing whitespace around newline
  5355. if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
  5356. }
  5357. const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
  5358. const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
  5359. return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
  5360. }
  5361. function blockString({
  5362. comment,
  5363. type,
  5364. value
  5365. }, ctx, onComment, onChompKeep) {
  5366. // 1. Block can't end in whitespace unless the last line is non-empty.
  5367. // 2. Strings consisting of only whitespace are best rendered explicitly.
  5368. if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
  5369. return doubleQuotedString(value, ctx);
  5370. }
  5371. const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
  5372. const indentSize = indent ? '2' : '1'; // root is at -1
  5373. const literal = type === PlainValueEc8e588e.Type.BLOCK_FOLDED ? false : type === PlainValueEc8e588e.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length);
  5374. let header = literal ? '|' : '>';
  5375. if (!value) return header + '\n';
  5376. let wsStart = '';
  5377. let wsEnd = '';
  5378. value = value.replace(/[\n\t ]*$/, ws => {
  5379. const n = ws.indexOf('\n');
  5380. if (n === -1) {
  5381. header += '-'; // strip
  5382. } else if (value === ws || n !== ws.length - 1) {
  5383. header += '+'; // keep
  5384. if (onChompKeep) onChompKeep();
  5385. }
  5386. wsEnd = ws.replace(/\n$/, '');
  5387. return '';
  5388. }).replace(/^[\n ]*/, ws => {
  5389. if (ws.indexOf(' ') !== -1) header += indentSize;
  5390. const m = ws.match(/ +$/);
  5391. if (m) {
  5392. wsStart = ws.slice(0, -m[0].length);
  5393. return m[0];
  5394. } else {
  5395. wsStart = ws;
  5396. return '';
  5397. }
  5398. });
  5399. if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, `$&${indent}`);
  5400. if (wsStart) wsStart = wsStart.replace(/\n+/g, `$&${indent}`);
  5401. if (comment) {
  5402. header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
  5403. if (onComment) onComment();
  5404. }
  5405. if (!value) return `${header}${indentSize}\n${indent}${wsEnd}`;
  5406. if (literal) {
  5407. value = value.replace(/\n+/g, `$&${indent}`);
  5408. return `${header}\n${indent}${wsStart}${value}${wsEnd}`;
  5409. }
  5410. value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
  5411. // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
  5412. .replace(/\n+/g, `$&${indent}`);
  5413. const body = foldFlowLines(`${wsStart}${value}${wsEnd}`, indent, FOLD_BLOCK, strOptions.fold);
  5414. return `${header}\n${indent}${body}`;
  5415. }
  5416. function plainString(item, ctx, onComment, onChompKeep) {
  5417. const {
  5418. comment,
  5419. type,
  5420. value
  5421. } = item;
  5422. const {
  5423. actualString,
  5424. implicitKey,
  5425. indent,
  5426. inFlow
  5427. } = ctx;
  5428. if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {
  5429. return doubleQuotedString(value, ctx);
  5430. }
  5431. if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
  5432. // not allowed:
  5433. // - empty string, '-' or '?'
  5434. // - start with an indicator character (except [?:-]) or /[?-] /
  5435. // - '\n ', ': ' or ' \n' anywhere
  5436. // - '#' not preceded by a non-space char
  5437. // - end with ' ' or ':'
  5438. return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
  5439. }
  5440. if (!implicitKey && !inFlow && type !== PlainValueEc8e588e.Type.PLAIN && value.indexOf('\n') !== -1) {
  5441. // Where allowed & type not set explicitly, prefer block style for multiline strings
  5442. return blockString(item, ctx, onComment, onChompKeep);
  5443. }
  5444. if (indent === '' && containsDocumentMarker(value)) {
  5445. ctx.forceBlockIndent = true;
  5446. return blockString(item, ctx, onComment, onChompKeep);
  5447. }
  5448. const str = value.replace(/\n+/g, `$&\n${indent}`); // Verify that output will be parsed as a string, as e.g. plain numbers and
  5449. // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
  5450. // and others in v1.1.
  5451. if (actualString) {
  5452. const {
  5453. tags
  5454. } = ctx.doc.schema;
  5455. const resolved = resolveScalar(str, tags, tags.scalarFallback).value;
  5456. if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
  5457. }
  5458. const body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
  5459. if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
  5460. if (onComment) onComment();
  5461. return addCommentBefore(body, indent, comment);
  5462. }
  5463. return body;
  5464. }
  5465. function stringifyString(item, ctx, onComment, onChompKeep) {
  5466. const {
  5467. defaultType
  5468. } = strOptions;
  5469. const {
  5470. implicitKey,
  5471. inFlow
  5472. } = ctx;
  5473. let {
  5474. type,
  5475. value
  5476. } = item;
  5477. if (typeof value !== 'string') {
  5478. value = String(value);
  5479. item = Object.assign({}, item, {
  5480. value
  5481. });
  5482. }
  5483. const _stringify = _type => {
  5484. switch (_type) {
  5485. case PlainValueEc8e588e.Type.BLOCK_FOLDED:
  5486. case PlainValueEc8e588e.Type.BLOCK_LITERAL:
  5487. return blockString(item, ctx, onComment, onChompKeep);
  5488. case PlainValueEc8e588e.Type.QUOTE_DOUBLE:
  5489. return doubleQuotedString(value, ctx);
  5490. case PlainValueEc8e588e.Type.QUOTE_SINGLE:
  5491. return singleQuotedString(value, ctx);
  5492. case PlainValueEc8e588e.Type.PLAIN:
  5493. return plainString(item, ctx, onComment, onChompKeep);
  5494. default:
  5495. return null;
  5496. }
  5497. };
  5498. if (type !== PlainValueEc8e588e.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
  5499. // force double quotes on control characters
  5500. type = PlainValueEc8e588e.Type.QUOTE_DOUBLE;
  5501. } else if ((implicitKey || inFlow) && (type === PlainValueEc8e588e.Type.BLOCK_FOLDED || type === PlainValueEc8e588e.Type.BLOCK_LITERAL)) {
  5502. // should not happen; blocks are not valid inside flow containers
  5503. type = PlainValueEc8e588e.Type.QUOTE_DOUBLE;
  5504. }
  5505. let res = _stringify(type);
  5506. if (res === null) {
  5507. res = _stringify(defaultType);
  5508. if (res === null) throw new Error(`Unsupported default string type ${defaultType}`);
  5509. }
  5510. return res;
  5511. }
  5512. function stringifyNumber({
  5513. format,
  5514. minFractionDigits,
  5515. tag,
  5516. value
  5517. }) {
  5518. if (typeof value === 'bigint') return String(value);
  5519. if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
  5520. let n = JSON.stringify(value);
  5521. if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
  5522. let i = n.indexOf('.');
  5523. if (i < 0) {
  5524. i = n.length;
  5525. n += '.';
  5526. }
  5527. let d = minFractionDigits - (n.length - i - 1);
  5528. while (d-- > 0) n += '0';
  5529. }
  5530. return n;
  5531. }
  5532. function checkFlowCollectionEnd(errors, cst) {
  5533. let char, name;
  5534. switch (cst.type) {
  5535. case PlainValueEc8e588e.Type.FLOW_MAP:
  5536. char = '}';
  5537. name = 'flow map';
  5538. break;
  5539. case PlainValueEc8e588e.Type.FLOW_SEQ:
  5540. char = ']';
  5541. name = 'flow sequence';
  5542. break;
  5543. default:
  5544. errors.push(new PlainValueEc8e588e.YAMLSemanticError(cst, 'Not a flow collection!?'));
  5545. return;
  5546. }
  5547. let lastItem;
  5548. for (let i = cst.items.length - 1; i >= 0; --i) {
  5549. const item = cst.items[i];
  5550. if (!item || item.type !== PlainValueEc8e588e.Type.COMMENT) {
  5551. lastItem = item;
  5552. break;
  5553. }
  5554. }
  5555. if (lastItem && lastItem.char !== char) {
  5556. const msg = `Expected ${name} to end with ${char}`;
  5557. let err;
  5558. if (typeof lastItem.offset === 'number') {
  5559. err = new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  5560. err.offset = lastItem.offset + 1;
  5561. } else {
  5562. err = new PlainValueEc8e588e.YAMLSemanticError(lastItem, msg);
  5563. if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
  5564. }
  5565. errors.push(err);
  5566. }
  5567. }
  5568. function checkFlowCommentSpace(errors, comment) {
  5569. const prev = comment.context.src[comment.range.start - 1];
  5570. if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
  5571. const msg = 'Comments must be separated from other tokens by white space characters';
  5572. errors.push(new PlainValueEc8e588e.YAMLSemanticError(comment, msg));
  5573. }
  5574. }
  5575. function getLongKeyError(source, key) {
  5576. const sk = String(key);
  5577. const k = sk.substr(0, 8) + '...' + sk.substr(-8);
  5578. return new PlainValueEc8e588e.YAMLSemanticError(source, `The "${k}" key is too long`);
  5579. }
  5580. function resolveComments(collection, comments) {
  5581. for (const {
  5582. afterKey,
  5583. before,
  5584. comment
  5585. } of comments) {
  5586. let item = collection.items[before];
  5587. if (!item) {
  5588. if (comment !== undefined) {
  5589. if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
  5590. }
  5591. } else {
  5592. if (afterKey && item.value) item = item.value;
  5593. if (comment === undefined) {
  5594. if (afterKey || !item.commentBefore) item.spaceBefore = true;
  5595. } else {
  5596. if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
  5597. }
  5598. }
  5599. }
  5600. } // on error, will return { str: string, errors: Error[] }
  5601. function resolveString(doc, node) {
  5602. const res = node.strValue;
  5603. if (!res) return '';
  5604. if (typeof res === 'string') return res;
  5605. res.errors.forEach(error => {
  5606. if (!error.source) error.source = node;
  5607. doc.errors.push(error);
  5608. });
  5609. return res.str;
  5610. }
  5611. function resolveTagHandle(doc, node) {
  5612. const {
  5613. handle,
  5614. suffix
  5615. } = node.tag;
  5616. let prefix = doc.tagPrefixes.find(p => p.handle === handle);
  5617. if (!prefix) {
  5618. const dtp = doc.getDefaults().tagPrefixes;
  5619. if (dtp) prefix = dtp.find(p => p.handle === handle);
  5620. if (!prefix) throw new PlainValueEc8e588e.YAMLSemanticError(node, `The ${handle} tag handle is non-default and was not declared.`);
  5621. }
  5622. if (!suffix) throw new PlainValueEc8e588e.YAMLSemanticError(node, `The ${handle} tag has no suffix.`);
  5623. if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
  5624. if (suffix[0] === '^') {
  5625. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
  5626. return suffix;
  5627. }
  5628. if (/[:/]/.test(suffix)) {
  5629. // word/foo -> tag:word.yaml.org,2002:foo
  5630. const vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
  5631. return vocab ? `tag:${vocab[1]}.yaml.org,2002:${vocab[2]}` : `tag:${suffix}`;
  5632. }
  5633. }
  5634. return prefix.prefix + decodeURIComponent(suffix);
  5635. }
  5636. function resolveTagName(doc, node) {
  5637. const {
  5638. tag,
  5639. type
  5640. } = node;
  5641. let nonSpecific = false;
  5642. if (tag) {
  5643. const {
  5644. handle,
  5645. suffix,
  5646. verbatim
  5647. } = tag;
  5648. if (verbatim) {
  5649. if (verbatim !== '!' && verbatim !== '!!') return verbatim;
  5650. const msg = `Verbatim tags aren't resolved, so ${verbatim} is invalid.`;
  5651. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5652. } else if (handle === '!' && !suffix) {
  5653. nonSpecific = true;
  5654. } else {
  5655. try {
  5656. return resolveTagHandle(doc, node);
  5657. } catch (error) {
  5658. doc.errors.push(error);
  5659. }
  5660. }
  5661. }
  5662. switch (type) {
  5663. case PlainValueEc8e588e.Type.BLOCK_FOLDED:
  5664. case PlainValueEc8e588e.Type.BLOCK_LITERAL:
  5665. case PlainValueEc8e588e.Type.QUOTE_DOUBLE:
  5666. case PlainValueEc8e588e.Type.QUOTE_SINGLE:
  5667. return PlainValueEc8e588e.defaultTags.STR;
  5668. case PlainValueEc8e588e.Type.FLOW_MAP:
  5669. case PlainValueEc8e588e.Type.MAP:
  5670. return PlainValueEc8e588e.defaultTags.MAP;
  5671. case PlainValueEc8e588e.Type.FLOW_SEQ:
  5672. case PlainValueEc8e588e.Type.SEQ:
  5673. return PlainValueEc8e588e.defaultTags.SEQ;
  5674. case PlainValueEc8e588e.Type.PLAIN:
  5675. return nonSpecific ? PlainValueEc8e588e.defaultTags.STR : null;
  5676. default:
  5677. return null;
  5678. }
  5679. }
  5680. function resolveByTagName(doc, node, tagName) {
  5681. const {
  5682. tags
  5683. } = doc.schema;
  5684. const matchWithTest = [];
  5685. for (const tag of tags) {
  5686. if (tag.tag === tagName) {
  5687. if (tag.test) matchWithTest.push(tag);else {
  5688. const res = tag.resolve(doc, node);
  5689. return res instanceof Collection$1 ? res : new Scalar(res);
  5690. }
  5691. }
  5692. }
  5693. const str = resolveString(doc, node);
  5694. if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
  5695. return null;
  5696. }
  5697. function getFallbackTagName({
  5698. type
  5699. }) {
  5700. switch (type) {
  5701. case PlainValueEc8e588e.Type.FLOW_MAP:
  5702. case PlainValueEc8e588e.Type.MAP:
  5703. return PlainValueEc8e588e.defaultTags.MAP;
  5704. case PlainValueEc8e588e.Type.FLOW_SEQ:
  5705. case PlainValueEc8e588e.Type.SEQ:
  5706. return PlainValueEc8e588e.defaultTags.SEQ;
  5707. default:
  5708. return PlainValueEc8e588e.defaultTags.STR;
  5709. }
  5710. }
  5711. function resolveTag(doc, node, tagName) {
  5712. try {
  5713. const res = resolveByTagName(doc, node, tagName);
  5714. if (res) {
  5715. if (tagName && node.tag) res.tag = tagName;
  5716. return res;
  5717. }
  5718. } catch (error) {
  5719. /* istanbul ignore if */
  5720. if (!error.source) error.source = node;
  5721. doc.errors.push(error);
  5722. return null;
  5723. }
  5724. try {
  5725. const fallback = getFallbackTagName(node);
  5726. if (!fallback) throw new Error(`The tag ${tagName} is unavailable`);
  5727. const msg = `The tag ${tagName} is unavailable, falling back to ${fallback}`;
  5728. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(node, msg));
  5729. const res = resolveByTagName(doc, node, fallback);
  5730. res.tag = tagName;
  5731. return res;
  5732. } catch (error) {
  5733. const refError = new PlainValueEc8e588e.YAMLReferenceError(node, error.message);
  5734. refError.stack = error.stack;
  5735. doc.errors.push(refError);
  5736. return null;
  5737. }
  5738. }
  5739. const isCollectionItem = node => {
  5740. if (!node) return false;
  5741. const {
  5742. type
  5743. } = node;
  5744. return type === PlainValueEc8e588e.Type.MAP_KEY || type === PlainValueEc8e588e.Type.MAP_VALUE || type === PlainValueEc8e588e.Type.SEQ_ITEM;
  5745. };
  5746. function resolveNodeProps(errors, node) {
  5747. const comments = {
  5748. before: [],
  5749. after: []
  5750. };
  5751. let hasAnchor = false;
  5752. let hasTag = false;
  5753. const props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
  5754. for (const {
  5755. start,
  5756. end
  5757. } of props) {
  5758. switch (node.context.src[start]) {
  5759. case PlainValueEc8e588e.Char.COMMENT:
  5760. {
  5761. if (!node.commentHasRequiredWhitespace(start)) {
  5762. const msg = 'Comments must be separated from other tokens by white space characters';
  5763. errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5764. }
  5765. const {
  5766. header,
  5767. valueRange
  5768. } = node;
  5769. const cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
  5770. cc.push(node.context.src.slice(start + 1, end));
  5771. break;
  5772. }
  5773. // Actual anchor & tag resolution is handled by schema, here we just complain
  5774. case PlainValueEc8e588e.Char.ANCHOR:
  5775. if (hasAnchor) {
  5776. const msg = 'A node can have at most one anchor';
  5777. errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5778. }
  5779. hasAnchor = true;
  5780. break;
  5781. case PlainValueEc8e588e.Char.TAG:
  5782. if (hasTag) {
  5783. const msg = 'A node can have at most one tag';
  5784. errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5785. }
  5786. hasTag = true;
  5787. break;
  5788. }
  5789. }
  5790. return {
  5791. comments,
  5792. hasAnchor,
  5793. hasTag
  5794. };
  5795. }
  5796. function resolveNodeValue(doc, node) {
  5797. const {
  5798. anchors,
  5799. errors,
  5800. schema
  5801. } = doc;
  5802. if (node.type === PlainValueEc8e588e.Type.ALIAS) {
  5803. const name = node.rawValue;
  5804. const src = anchors.getNode(name);
  5805. if (!src) {
  5806. const msg = `Aliased anchor not found: ${name}`;
  5807. errors.push(new PlainValueEc8e588e.YAMLReferenceError(node, msg));
  5808. return null;
  5809. } // Lazy resolution for circular references
  5810. const res = new Alias$1(src);
  5811. anchors._cstAliases.push(res);
  5812. return res;
  5813. }
  5814. const tagName = resolveTagName(doc, node);
  5815. if (tagName) return resolveTag(doc, node, tagName);
  5816. if (node.type !== PlainValueEc8e588e.Type.PLAIN) {
  5817. const msg = `Failed to resolve ${node.type} node here`;
  5818. errors.push(new PlainValueEc8e588e.YAMLSyntaxError(node, msg));
  5819. return null;
  5820. }
  5821. try {
  5822. const str = resolveString(doc, node);
  5823. return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
  5824. } catch (error) {
  5825. if (!error.source) error.source = node;
  5826. errors.push(error);
  5827. return null;
  5828. }
  5829. } // sets node.resolved on success
  5830. function resolveNode(doc, node) {
  5831. if (!node) return null;
  5832. if (node.error) doc.errors.push(node.error);
  5833. const {
  5834. comments,
  5835. hasAnchor,
  5836. hasTag
  5837. } = resolveNodeProps(doc.errors, node);
  5838. if (hasAnchor) {
  5839. const {
  5840. anchors
  5841. } = doc;
  5842. const name = node.anchor;
  5843. const prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
  5844. // name have already been resolved, so it may safely be renamed.
  5845. if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
  5846. // anchors need to be available during resolution to allow for
  5847. // circular references.
  5848. anchors.map[name] = node;
  5849. }
  5850. if (node.type === PlainValueEc8e588e.Type.ALIAS && (hasAnchor || hasTag)) {
  5851. const msg = 'An alias node must not specify any properties';
  5852. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5853. }
  5854. const res = resolveNodeValue(doc, node);
  5855. if (res) {
  5856. res.range = [node.range.start, node.range.end];
  5857. if (doc.options.keepCstNodes) res.cstNode = node;
  5858. if (doc.options.keepNodeTypes) res.type = node.type;
  5859. const cb = comments.before.join('\n');
  5860. if (cb) {
  5861. res.commentBefore = res.commentBefore ? `${res.commentBefore}\n${cb}` : cb;
  5862. }
  5863. const ca = comments.after.join('\n');
  5864. if (ca) res.comment = res.comment ? `${res.comment}\n${ca}` : ca;
  5865. }
  5866. return node.resolved = res;
  5867. }
  5868. function resolveMap(doc, cst) {
  5869. if (cst.type !== PlainValueEc8e588e.Type.MAP && cst.type !== PlainValueEc8e588e.Type.FLOW_MAP) {
  5870. const msg = `A ${cst.type} node cannot be resolved as a mapping`;
  5871. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(cst, msg));
  5872. return null;
  5873. }
  5874. const {
  5875. comments,
  5876. items
  5877. } = cst.type === PlainValueEc8e588e.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
  5878. const map = new YAMLMap();
  5879. map.items = items;
  5880. resolveComments(map, comments);
  5881. let hasCollectionKey = false;
  5882. for (let i = 0; i < items.length; ++i) {
  5883. const {
  5884. key: iKey
  5885. } = items[i];
  5886. if (iKey instanceof Collection$1) hasCollectionKey = true;
  5887. if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
  5888. items[i] = new Merge(items[i]);
  5889. const sources = items[i].value.items;
  5890. let error = null;
  5891. sources.some(node => {
  5892. if (node instanceof Alias$1) {
  5893. // During parsing, alias sources are CST nodes; to account for
  5894. // circular references their resolved values can't be used here.
  5895. const {
  5896. type
  5897. } = node.source;
  5898. if (type === PlainValueEc8e588e.Type.MAP || type === PlainValueEc8e588e.Type.FLOW_MAP) return false;
  5899. return error = 'Merge nodes aliases can only point to maps';
  5900. }
  5901. return error = 'Merge nodes can only have Alias nodes as values';
  5902. });
  5903. if (error) doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(cst, error));
  5904. } else {
  5905. for (let j = i + 1; j < items.length; ++j) {
  5906. const {
  5907. key: jKey
  5908. } = items[j];
  5909. if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
  5910. const msg = `Map keys must be unique; "${iKey}" is repeated`;
  5911. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(cst, msg));
  5912. break;
  5913. }
  5914. }
  5915. }
  5916. }
  5917. if (hasCollectionKey && !doc.options.mapAsMap) {
  5918. const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
  5919. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(cst, warn));
  5920. }
  5921. cst.resolved = map;
  5922. return map;
  5923. }
  5924. const valueHasPairComment = ({
  5925. context: {
  5926. lineStart,
  5927. node,
  5928. src
  5929. },
  5930. props
  5931. }) => {
  5932. if (props.length === 0) return false;
  5933. const {
  5934. start
  5935. } = props[0];
  5936. if (node && start > node.valueRange.start) return false;
  5937. if (src[start] !== PlainValueEc8e588e.Char.COMMENT) return false;
  5938. for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
  5939. return true;
  5940. };
  5941. function resolvePairComment(item, pair) {
  5942. if (!valueHasPairComment(item)) return;
  5943. const comment = item.getPropValue(0, PlainValueEc8e588e.Char.COMMENT, true);
  5944. let found = false;
  5945. const cb = pair.value.commentBefore;
  5946. if (cb && cb.startsWith(comment)) {
  5947. pair.value.commentBefore = cb.substr(comment.length + 1);
  5948. found = true;
  5949. } else {
  5950. const cc = pair.value.comment;
  5951. if (!item.node && cc && cc.startsWith(comment)) {
  5952. pair.value.comment = cc.substr(comment.length + 1);
  5953. found = true;
  5954. }
  5955. }
  5956. if (found) pair.comment = comment;
  5957. }
  5958. function resolveBlockMapItems(doc, cst) {
  5959. const comments = [];
  5960. const items = [];
  5961. let key = undefined;
  5962. let keyStart = null;
  5963. for (let i = 0; i < cst.items.length; ++i) {
  5964. const item = cst.items[i];
  5965. switch (item.type) {
  5966. case PlainValueEc8e588e.Type.BLANK_LINE:
  5967. comments.push({
  5968. afterKey: !!key,
  5969. before: items.length
  5970. });
  5971. break;
  5972. case PlainValueEc8e588e.Type.COMMENT:
  5973. comments.push({
  5974. afterKey: !!key,
  5975. before: items.length,
  5976. comment: item.comment
  5977. });
  5978. break;
  5979. case PlainValueEc8e588e.Type.MAP_KEY:
  5980. if (key !== undefined) items.push(new Pair(key));
  5981. if (item.error) doc.errors.push(item.error);
  5982. key = resolveNode(doc, item.node);
  5983. keyStart = null;
  5984. break;
  5985. case PlainValueEc8e588e.Type.MAP_VALUE:
  5986. {
  5987. if (key === undefined) key = null;
  5988. if (item.error) doc.errors.push(item.error);
  5989. if (!item.context.atLineStart && item.node && item.node.type === PlainValueEc8e588e.Type.MAP && !item.node.context.atLineStart) {
  5990. const msg = 'Nested mappings are not allowed in compact mappings';
  5991. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item.node, msg));
  5992. }
  5993. let valueNode = item.node;
  5994. if (!valueNode && item.props.length > 0) {
  5995. // Comments on an empty mapping value need to be preserved, so we
  5996. // need to construct a minimal empty node here to use instead of the
  5997. // missing `item.node`. -- eemeli/yaml#19
  5998. valueNode = new PlainValueEc8e588e.PlainValue(PlainValueEc8e588e.Type.PLAIN, []);
  5999. valueNode.context = {
  6000. parent: item,
  6001. src: item.context.src
  6002. };
  6003. const pos = item.range.start + 1;
  6004. valueNode.range = {
  6005. start: pos,
  6006. end: pos
  6007. };
  6008. valueNode.valueRange = {
  6009. start: pos,
  6010. end: pos
  6011. };
  6012. if (typeof item.range.origStart === 'number') {
  6013. const origPos = item.range.origStart + 1;
  6014. valueNode.range.origStart = valueNode.range.origEnd = origPos;
  6015. valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
  6016. }
  6017. }
  6018. const pair = new Pair(key, resolveNode(doc, valueNode));
  6019. resolvePairComment(item, pair);
  6020. items.push(pair);
  6021. if (key && typeof keyStart === 'number') {
  6022. if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
  6023. }
  6024. key = undefined;
  6025. keyStart = null;
  6026. }
  6027. break;
  6028. default:
  6029. if (key !== undefined) items.push(new Pair(key));
  6030. key = resolveNode(doc, item);
  6031. keyStart = item.range.start;
  6032. if (item.error) doc.errors.push(item.error);
  6033. next: for (let j = i + 1;; ++j) {
  6034. const nextItem = cst.items[j];
  6035. switch (nextItem && nextItem.type) {
  6036. case PlainValueEc8e588e.Type.BLANK_LINE:
  6037. case PlainValueEc8e588e.Type.COMMENT:
  6038. continue next;
  6039. case PlainValueEc8e588e.Type.MAP_VALUE:
  6040. break next;
  6041. default:
  6042. {
  6043. const msg = 'Implicit map keys need to be followed by map values';
  6044. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6045. break next;
  6046. }
  6047. }
  6048. }
  6049. if (item.valueRangeContainsNewline) {
  6050. const msg = 'Implicit map keys need to be on a single line';
  6051. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6052. }
  6053. }
  6054. }
  6055. if (key !== undefined) items.push(new Pair(key));
  6056. return {
  6057. comments,
  6058. items
  6059. };
  6060. }
  6061. function resolveFlowMapItems(doc, cst) {
  6062. const comments = [];
  6063. const items = [];
  6064. let key = undefined;
  6065. let explicitKey = false;
  6066. let next = '{';
  6067. for (let i = 0; i < cst.items.length; ++i) {
  6068. const item = cst.items[i];
  6069. if (typeof item.char === 'string') {
  6070. const {
  6071. char,
  6072. offset
  6073. } = item;
  6074. if (char === '?' && key === undefined && !explicitKey) {
  6075. explicitKey = true;
  6076. next = ':';
  6077. continue;
  6078. }
  6079. if (char === ':') {
  6080. if (key === undefined) key = null;
  6081. if (next === ':') {
  6082. next = ',';
  6083. continue;
  6084. }
  6085. } else {
  6086. if (explicitKey) {
  6087. if (key === undefined && char !== ',') key = null;
  6088. explicitKey = false;
  6089. }
  6090. if (key !== undefined) {
  6091. items.push(new Pair(key));
  6092. key = undefined;
  6093. if (char === ',') {
  6094. next = ':';
  6095. continue;
  6096. }
  6097. }
  6098. }
  6099. if (char === '}') {
  6100. if (i === cst.items.length - 1) continue;
  6101. } else if (char === next) {
  6102. next = ':';
  6103. continue;
  6104. }
  6105. const msg = `Flow map contains an unexpected ${char}`;
  6106. const err = new PlainValueEc8e588e.YAMLSyntaxError(cst, msg);
  6107. err.offset = offset;
  6108. doc.errors.push(err);
  6109. } else if (item.type === PlainValueEc8e588e.Type.BLANK_LINE) {
  6110. comments.push({
  6111. afterKey: !!key,
  6112. before: items.length
  6113. });
  6114. } else if (item.type === PlainValueEc8e588e.Type.COMMENT) {
  6115. checkFlowCommentSpace(doc.errors, item);
  6116. comments.push({
  6117. afterKey: !!key,
  6118. before: items.length,
  6119. comment: item.comment
  6120. });
  6121. } else if (key === undefined) {
  6122. if (next === ',') doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, 'Separator , missing in flow map'));
  6123. key = resolveNode(doc, item);
  6124. } else {
  6125. if (next !== ',') doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
  6126. items.push(new Pair(key, resolveNode(doc, item)));
  6127. key = undefined;
  6128. explicitKey = false;
  6129. }
  6130. }
  6131. checkFlowCollectionEnd(doc.errors, cst);
  6132. if (key !== undefined) items.push(new Pair(key));
  6133. return {
  6134. comments,
  6135. items
  6136. };
  6137. }
  6138. function resolveSeq(doc, cst) {
  6139. if (cst.type !== PlainValueEc8e588e.Type.SEQ && cst.type !== PlainValueEc8e588e.Type.FLOW_SEQ) {
  6140. const msg = `A ${cst.type} node cannot be resolved as a sequence`;
  6141. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(cst, msg));
  6142. return null;
  6143. }
  6144. const {
  6145. comments,
  6146. items
  6147. } = cst.type === PlainValueEc8e588e.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
  6148. const seq = new YAMLSeq();
  6149. seq.items = items;
  6150. resolveComments(seq, comments);
  6151. if (!doc.options.mapAsMap && items.some(it => it instanceof Pair && it.key instanceof Collection$1)) {
  6152. const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
  6153. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(cst, warn));
  6154. }
  6155. cst.resolved = seq;
  6156. return seq;
  6157. }
  6158. function resolveBlockSeqItems(doc, cst) {
  6159. const comments = [];
  6160. const items = [];
  6161. for (let i = 0; i < cst.items.length; ++i) {
  6162. const item = cst.items[i];
  6163. switch (item.type) {
  6164. case PlainValueEc8e588e.Type.BLANK_LINE:
  6165. comments.push({
  6166. before: items.length
  6167. });
  6168. break;
  6169. case PlainValueEc8e588e.Type.COMMENT:
  6170. comments.push({
  6171. comment: item.comment,
  6172. before: items.length
  6173. });
  6174. break;
  6175. case PlainValueEc8e588e.Type.SEQ_ITEM:
  6176. if (item.error) doc.errors.push(item.error);
  6177. items.push(resolveNode(doc, item.node));
  6178. if (item.hasProps) {
  6179. const msg = 'Sequence items cannot have tags or anchors before the - indicator';
  6180. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6181. }
  6182. break;
  6183. default:
  6184. if (item.error) doc.errors.push(item.error);
  6185. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(item, `Unexpected ${item.type} node in sequence`));
  6186. }
  6187. }
  6188. return {
  6189. comments,
  6190. items
  6191. };
  6192. }
  6193. function resolveFlowSeqItems(doc, cst) {
  6194. const comments = [];
  6195. const items = [];
  6196. let explicitKey = false;
  6197. let key = undefined;
  6198. let keyStart = null;
  6199. let next = '[';
  6200. let prevItem = null;
  6201. for (let i = 0; i < cst.items.length; ++i) {
  6202. const item = cst.items[i];
  6203. if (typeof item.char === 'string') {
  6204. const {
  6205. char,
  6206. offset
  6207. } = item;
  6208. if (char !== ':' && (explicitKey || key !== undefined)) {
  6209. if (explicitKey && key === undefined) key = next ? items.pop() : null;
  6210. items.push(new Pair(key));
  6211. explicitKey = false;
  6212. key = undefined;
  6213. keyStart = null;
  6214. }
  6215. if (char === next) {
  6216. next = null;
  6217. } else if (!next && char === '?') {
  6218. explicitKey = true;
  6219. } else if (next !== '[' && char === ':' && key === undefined) {
  6220. if (next === ',') {
  6221. key = items.pop();
  6222. if (key instanceof Pair) {
  6223. const msg = 'Chaining flow sequence pairs is invalid';
  6224. const err = new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  6225. err.offset = offset;
  6226. doc.errors.push(err);
  6227. }
  6228. if (!explicitKey && typeof keyStart === 'number') {
  6229. const keyEnd = item.range ? item.range.start : item.offset;
  6230. if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
  6231. const {
  6232. src
  6233. } = prevItem.context;
  6234. for (let i = keyStart; i < keyEnd; ++i) if (src[i] === '\n') {
  6235. const msg = 'Implicit keys of flow sequence pairs need to be on a single line';
  6236. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(prevItem, msg));
  6237. break;
  6238. }
  6239. }
  6240. } else {
  6241. key = null;
  6242. }
  6243. keyStart = null;
  6244. explicitKey = false;
  6245. next = null;
  6246. } else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
  6247. const msg = `Flow sequence contains an unexpected ${char}`;
  6248. const err = new PlainValueEc8e588e.YAMLSyntaxError(cst, msg);
  6249. err.offset = offset;
  6250. doc.errors.push(err);
  6251. }
  6252. } else if (item.type === PlainValueEc8e588e.Type.BLANK_LINE) {
  6253. comments.push({
  6254. before: items.length
  6255. });
  6256. } else if (item.type === PlainValueEc8e588e.Type.COMMENT) {
  6257. checkFlowCommentSpace(doc.errors, item);
  6258. comments.push({
  6259. comment: item.comment,
  6260. before: items.length
  6261. });
  6262. } else {
  6263. if (next) {
  6264. const msg = `Expected a ${next} in flow sequence`;
  6265. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6266. }
  6267. const value = resolveNode(doc, item);
  6268. if (key === undefined) {
  6269. items.push(value);
  6270. prevItem = item;
  6271. } else {
  6272. items.push(new Pair(key, value));
  6273. key = undefined;
  6274. }
  6275. keyStart = item.range.start;
  6276. next = ',';
  6277. }
  6278. }
  6279. checkFlowCollectionEnd(doc.errors, cst);
  6280. if (key !== undefined) items.push(new Pair(key));
  6281. return {
  6282. comments,
  6283. items
  6284. };
  6285. }
  6286. var Alias_1 = Alias$1;
  6287. var Collection_1 = Collection$1;
  6288. var Merge_1 = Merge;
  6289. var Node_1$1 = Node$1;
  6290. var Pair_1 = Pair;
  6291. var Scalar_1 = Scalar;
  6292. var YAMLMap_1 = YAMLMap;
  6293. var YAMLSeq_1 = YAMLSeq;
  6294. var addComment_1 = addComment;
  6295. var binaryOptions_1 = binaryOptions;
  6296. var boolOptions_1 = boolOptions;
  6297. var findPair_1 = findPair;
  6298. var intOptions_1 = intOptions;
  6299. var isEmptyPath_1 = isEmptyPath;
  6300. var nullOptions_1 = nullOptions;
  6301. var resolveMap_1 = resolveMap;
  6302. var resolveNode_1 = resolveNode;
  6303. var resolveSeq_1 = resolveSeq;
  6304. var resolveString_1 = resolveString;
  6305. var strOptions_1 = strOptions;
  6306. var stringifyNumber_1 = stringifyNumber;
  6307. var stringifyString_1 = stringifyString;
  6308. var toJSON_1 = toJSON;
  6309. var resolveSeq4a68b39b = {
  6310. Alias: Alias_1,
  6311. Collection: Collection_1,
  6312. Merge: Merge_1,
  6313. Node: Node_1$1,
  6314. Pair: Pair_1,
  6315. Scalar: Scalar_1,
  6316. YAMLMap: YAMLMap_1,
  6317. YAMLSeq: YAMLSeq_1,
  6318. addComment: addComment_1,
  6319. binaryOptions: binaryOptions_1,
  6320. boolOptions: boolOptions_1,
  6321. findPair: findPair_1,
  6322. intOptions: intOptions_1,
  6323. isEmptyPath: isEmptyPath_1,
  6324. nullOptions: nullOptions_1,
  6325. resolveMap: resolveMap_1,
  6326. resolveNode: resolveNode_1,
  6327. resolveSeq: resolveSeq_1,
  6328. resolveString: resolveString_1,
  6329. strOptions: strOptions_1,
  6330. stringifyNumber: stringifyNumber_1,
  6331. stringifyString: stringifyString_1,
  6332. toJSON: toJSON_1
  6333. };
  6334. /* global atob, btoa, Buffer */
  6335. const binary = {
  6336. identify: value => value instanceof Uint8Array,
  6337. // Buffer inherits from Uint8Array
  6338. default: false,
  6339. tag: 'tag:yaml.org,2002:binary',
  6340. /**
  6341. * Returns a Buffer in node and an Uint8Array in browsers
  6342. *
  6343. * To use the resulting buffer as an image, you'll want to do something like:
  6344. *
  6345. * const blob = new Blob([buffer], { type: 'image/jpeg' })
  6346. * document.querySelector('#photo').src = URL.createObjectURL(blob)
  6347. */
  6348. resolve: (doc, node) => {
  6349. const src = resolveSeq4a68b39b.resolveString(doc, node);
  6350. if (typeof Buffer === 'function') {
  6351. return Buffer.from(src, 'base64');
  6352. } else if (typeof atob === 'function') {
  6353. // On IE 11, atob() can't handle newlines
  6354. const str = atob(src.replace(/[\n\r]/g, ''));
  6355. const buffer = new Uint8Array(str.length);
  6356. for (let i = 0; i < str.length; ++i) buffer[i] = str.charCodeAt(i);
  6357. return buffer;
  6358. } else {
  6359. const msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
  6360. doc.errors.push(new PlainValueEc8e588e.YAMLReferenceError(node, msg));
  6361. return null;
  6362. }
  6363. },
  6364. options: resolveSeq4a68b39b.binaryOptions,
  6365. stringify: ({
  6366. comment,
  6367. type,
  6368. value
  6369. }, ctx, onComment, onChompKeep) => {
  6370. let src;
  6371. if (typeof Buffer === 'function') {
  6372. src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
  6373. } else if (typeof btoa === 'function') {
  6374. let s = '';
  6375. for (let i = 0; i < value.length; ++i) s += String.fromCharCode(value[i]);
  6376. src = btoa(s);
  6377. } else {
  6378. throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
  6379. }
  6380. if (!type) type = resolveSeq4a68b39b.binaryOptions.defaultType;
  6381. if (type === PlainValueEc8e588e.Type.QUOTE_DOUBLE) {
  6382. value = src;
  6383. } else {
  6384. const {
  6385. lineWidth
  6386. } = resolveSeq4a68b39b.binaryOptions;
  6387. const n = Math.ceil(src.length / lineWidth);
  6388. const lines = new Array(n);
  6389. for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
  6390. lines[i] = src.substr(o, lineWidth);
  6391. }
  6392. value = lines.join(type === PlainValueEc8e588e.Type.BLOCK_LITERAL ? '\n' : ' ');
  6393. }
  6394. return resolveSeq4a68b39b.stringifyString({
  6395. comment,
  6396. type,
  6397. value
  6398. }, ctx, onComment, onChompKeep);
  6399. }
  6400. };
  6401. function parsePairs(doc, cst) {
  6402. const seq = resolveSeq4a68b39b.resolveSeq(doc, cst);
  6403. for (let i = 0; i < seq.items.length; ++i) {
  6404. let item = seq.items[i];
  6405. if (item instanceof resolveSeq4a68b39b.Pair) continue;else if (item instanceof resolveSeq4a68b39b.YAMLMap) {
  6406. if (item.items.length > 1) {
  6407. const msg = 'Each pair must have its own sequence indicator';
  6408. throw new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  6409. }
  6410. const pair = item.items[0] || new resolveSeq4a68b39b.Pair();
  6411. if (item.commentBefore) pair.commentBefore = pair.commentBefore ? `${item.commentBefore}\n${pair.commentBefore}` : item.commentBefore;
  6412. if (item.comment) pair.comment = pair.comment ? `${item.comment}\n${pair.comment}` : item.comment;
  6413. item = pair;
  6414. }
  6415. seq.items[i] = item instanceof resolveSeq4a68b39b.Pair ? item : new resolveSeq4a68b39b.Pair(item);
  6416. }
  6417. return seq;
  6418. }
  6419. function createPairs(schema, iterable, ctx) {
  6420. const pairs = new resolveSeq4a68b39b.YAMLSeq(schema);
  6421. pairs.tag = 'tag:yaml.org,2002:pairs';
  6422. for (const it of iterable) {
  6423. let key, value;
  6424. if (Array.isArray(it)) {
  6425. if (it.length === 2) {
  6426. key = it[0];
  6427. value = it[1];
  6428. } else throw new TypeError(`Expected [key, value] tuple: ${it}`);
  6429. } else if (it && it instanceof Object) {
  6430. const keys = Object.keys(it);
  6431. if (keys.length === 1) {
  6432. key = keys[0];
  6433. value = it[key];
  6434. } else throw new TypeError(`Expected { key: value } tuple: ${it}`);
  6435. } else {
  6436. key = it;
  6437. }
  6438. const pair = schema.createPair(key, value, ctx);
  6439. pairs.items.push(pair);
  6440. }
  6441. return pairs;
  6442. }
  6443. const pairs = {
  6444. default: false,
  6445. tag: 'tag:yaml.org,2002:pairs',
  6446. resolve: parsePairs,
  6447. createNode: createPairs
  6448. };
  6449. class YAMLOMap extends resolveSeq4a68b39b.YAMLSeq {
  6450. constructor() {
  6451. super();
  6452. PlainValueEc8e588e._defineProperty(this, "add", resolveSeq4a68b39b.YAMLMap.prototype.add.bind(this));
  6453. PlainValueEc8e588e._defineProperty(this, "delete", resolveSeq4a68b39b.YAMLMap.prototype.delete.bind(this));
  6454. PlainValueEc8e588e._defineProperty(this, "get", resolveSeq4a68b39b.YAMLMap.prototype.get.bind(this));
  6455. PlainValueEc8e588e._defineProperty(this, "has", resolveSeq4a68b39b.YAMLMap.prototype.has.bind(this));
  6456. PlainValueEc8e588e._defineProperty(this, "set", resolveSeq4a68b39b.YAMLMap.prototype.set.bind(this));
  6457. this.tag = YAMLOMap.tag;
  6458. }
  6459. toJSON(_, ctx) {
  6460. const map = new Map();
  6461. if (ctx && ctx.onCreate) ctx.onCreate(map);
  6462. for (const pair of this.items) {
  6463. let key, value;
  6464. if (pair instanceof resolveSeq4a68b39b.Pair) {
  6465. key = resolveSeq4a68b39b.toJSON(pair.key, '', ctx);
  6466. value = resolveSeq4a68b39b.toJSON(pair.value, key, ctx);
  6467. } else {
  6468. key = resolveSeq4a68b39b.toJSON(pair, '', ctx);
  6469. }
  6470. if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
  6471. map.set(key, value);
  6472. }
  6473. return map;
  6474. }
  6475. }
  6476. PlainValueEc8e588e._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
  6477. function parseOMap(doc, cst) {
  6478. const pairs = parsePairs(doc, cst);
  6479. const seenKeys = [];
  6480. for (const {
  6481. key
  6482. } of pairs.items) {
  6483. if (key instanceof resolveSeq4a68b39b.Scalar) {
  6484. if (seenKeys.includes(key.value)) {
  6485. const msg = 'Ordered maps must not include duplicate keys';
  6486. throw new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  6487. } else {
  6488. seenKeys.push(key.value);
  6489. }
  6490. }
  6491. }
  6492. return Object.assign(new YAMLOMap(), pairs);
  6493. }
  6494. function createOMap(schema, iterable, ctx) {
  6495. const pairs = createPairs(schema, iterable, ctx);
  6496. const omap = new YAMLOMap();
  6497. omap.items = pairs.items;
  6498. return omap;
  6499. }
  6500. const omap = {
  6501. identify: value => value instanceof Map,
  6502. nodeClass: YAMLOMap,
  6503. default: false,
  6504. tag: 'tag:yaml.org,2002:omap',
  6505. resolve: parseOMap,
  6506. createNode: createOMap
  6507. };
  6508. class YAMLSet extends resolveSeq4a68b39b.YAMLMap {
  6509. constructor() {
  6510. super();
  6511. this.tag = YAMLSet.tag;
  6512. }
  6513. add(key) {
  6514. const pair = key instanceof resolveSeq4a68b39b.Pair ? key : new resolveSeq4a68b39b.Pair(key);
  6515. const prev = resolveSeq4a68b39b.findPair(this.items, pair.key);
  6516. if (!prev) this.items.push(pair);
  6517. }
  6518. get(key, keepPair) {
  6519. const pair = resolveSeq4a68b39b.findPair(this.items, key);
  6520. return !keepPair && pair instanceof resolveSeq4a68b39b.Pair ? pair.key instanceof resolveSeq4a68b39b.Scalar ? pair.key.value : pair.key : pair;
  6521. }
  6522. set(key, value) {
  6523. if (typeof value !== 'boolean') throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
  6524. const prev = resolveSeq4a68b39b.findPair(this.items, key);
  6525. if (prev && !value) {
  6526. this.items.splice(this.items.indexOf(prev), 1);
  6527. } else if (!prev && value) {
  6528. this.items.push(new resolveSeq4a68b39b.Pair(key));
  6529. }
  6530. }
  6531. toJSON(_, ctx) {
  6532. return super.toJSON(_, ctx, Set);
  6533. }
  6534. toString(ctx, onComment, onChompKeep) {
  6535. if (!ctx) return JSON.stringify(this);
  6536. if (this.hasAllNullValues()) return super.toString(ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values');
  6537. }
  6538. }
  6539. PlainValueEc8e588e._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
  6540. function parseSet(doc, cst) {
  6541. const map = resolveSeq4a68b39b.resolveMap(doc, cst);
  6542. if (!map.hasAllNullValues()) throw new PlainValueEc8e588e.YAMLSemanticError(cst, 'Set items must all have null values');
  6543. return Object.assign(new YAMLSet(), map);
  6544. }
  6545. function createSet(schema, iterable, ctx) {
  6546. const set = new YAMLSet();
  6547. for (const value of iterable) set.items.push(schema.createPair(value, null, ctx));
  6548. return set;
  6549. }
  6550. const set = {
  6551. identify: value => value instanceof Set,
  6552. nodeClass: YAMLSet,
  6553. default: false,
  6554. tag: 'tag:yaml.org,2002:set',
  6555. resolve: parseSet,
  6556. createNode: createSet
  6557. };
  6558. const parseSexagesimal = (sign, parts) => {
  6559. const n = parts.split(':').reduce((n, p) => n * 60 + Number(p), 0);
  6560. return sign === '-' ? -n : n;
  6561. }; // hhhh:mm:ss.sss
  6562. const stringifySexagesimal = ({
  6563. value
  6564. }) => {
  6565. if (isNaN(value) || !isFinite(value)) return resolveSeq4a68b39b.stringifyNumber(value);
  6566. let sign = '';
  6567. if (value < 0) {
  6568. sign = '-';
  6569. value = Math.abs(value);
  6570. }
  6571. const parts = [value % 60]; // seconds, including ms
  6572. if (value < 60) {
  6573. parts.unshift(0); // at least one : is required
  6574. } else {
  6575. value = Math.round((value - parts[0]) / 60);
  6576. parts.unshift(value % 60); // minutes
  6577. if (value >= 60) {
  6578. value = Math.round((value - parts[0]) / 60);
  6579. parts.unshift(value); // hours
  6580. }
  6581. }
  6582. return sign + parts.map(n => n < 10 ? '0' + String(n) : String(n)).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
  6583. ;
  6584. };
  6585. const intTime = {
  6586. identify: value => typeof value === 'number',
  6587. default: true,
  6588. tag: 'tag:yaml.org,2002:int',
  6589. format: 'TIME',
  6590. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
  6591. resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
  6592. stringify: stringifySexagesimal
  6593. };
  6594. const floatTime = {
  6595. identify: value => typeof value === 'number',
  6596. default: true,
  6597. tag: 'tag:yaml.org,2002:float',
  6598. format: 'TIME',
  6599. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
  6600. resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
  6601. stringify: stringifySexagesimal
  6602. };
  6603. const timestamp = {
  6604. identify: value => value instanceof Date,
  6605. default: true,
  6606. tag: 'tag:yaml.org,2002:timestamp',
  6607. // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
  6608. // may be omitted altogether, resulting in a date format. In such a case, the time part is
  6609. // assumed to be 00:00:00Z (start of day, UTC).
  6610. test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
  6611. '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace
  6612. '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
  6613. '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
  6614. ')?' + ')$'),
  6615. resolve: (str, year, month, day, hour, minute, second, millisec, tz) => {
  6616. if (millisec) millisec = (millisec + '00').substr(1, 3);
  6617. let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
  6618. if (tz && tz !== 'Z') {
  6619. let d = parseSexagesimal(tz[0], tz.slice(1));
  6620. if (Math.abs(d) < 30) d *= 60;
  6621. date -= 60000 * d;
  6622. }
  6623. return new Date(date);
  6624. },
  6625. stringify: ({
  6626. value
  6627. }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
  6628. };
  6629. /* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
  6630. function shouldWarn(deprecation) {
  6631. const env = typeof process !== 'undefined' && process.env || {};
  6632. if (deprecation) {
  6633. if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS;
  6634. return !env.YAML_SILENCE_DEPRECATION_WARNINGS;
  6635. }
  6636. if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS;
  6637. return !env.YAML_SILENCE_WARNINGS;
  6638. }
  6639. function warn(warning, type) {
  6640. if (shouldWarn(false)) {
  6641. const emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to
  6642. // https://github.com/facebook/jest/issues/2549
  6643. if (emit) emit(warning, type);else {
  6644. // eslint-disable-next-line no-console
  6645. console.warn(type ? `${type}: ${warning}` : warning);
  6646. }
  6647. }
  6648. }
  6649. function warnFileDeprecation(filename) {
  6650. if (shouldWarn(true)) {
  6651. const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
  6652. warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, 'DeprecationWarning');
  6653. }
  6654. }
  6655. const warned = {};
  6656. function warnOptionDeprecation(name, alternative) {
  6657. if (!warned[name] && shouldWarn(true)) {
  6658. warned[name] = true;
  6659. let msg = `The option '${name}' will be removed in a future release`;
  6660. msg += alternative ? `, use '${alternative}' instead.` : '.';
  6661. warn(msg, 'DeprecationWarning');
  6662. }
  6663. }
  6664. var binary_1 = binary;
  6665. var floatTime_1 = floatTime;
  6666. var intTime_1 = intTime;
  6667. var omap_1 = omap;
  6668. var pairs_1 = pairs;
  6669. var set_1 = set;
  6670. var timestamp_1 = timestamp;
  6671. var warn_1 = warn;
  6672. var warnFileDeprecation_1 = warnFileDeprecation;
  6673. var warnOptionDeprecation_1 = warnOptionDeprecation;
  6674. var warnings39684f17 = {
  6675. binary: binary_1,
  6676. floatTime: floatTime_1,
  6677. intTime: intTime_1,
  6678. omap: omap_1,
  6679. pairs: pairs_1,
  6680. set: set_1,
  6681. timestamp: timestamp_1,
  6682. warn: warn_1,
  6683. warnFileDeprecation: warnFileDeprecation_1,
  6684. warnOptionDeprecation: warnOptionDeprecation_1
  6685. };
  6686. function createMap(schema, obj, ctx) {
  6687. const map = new resolveSeq4a68b39b.YAMLMap(schema);
  6688. if (obj instanceof Map) {
  6689. for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
  6690. } else if (obj && typeof obj === 'object') {
  6691. for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
  6692. }
  6693. if (typeof schema.sortMapEntries === 'function') {
  6694. map.items.sort(schema.sortMapEntries);
  6695. }
  6696. return map;
  6697. }
  6698. const map = {
  6699. createNode: createMap,
  6700. default: true,
  6701. nodeClass: resolveSeq4a68b39b.YAMLMap,
  6702. tag: 'tag:yaml.org,2002:map',
  6703. resolve: resolveSeq4a68b39b.resolveMap
  6704. };
  6705. function createSeq(schema, obj, ctx) {
  6706. const seq = new resolveSeq4a68b39b.YAMLSeq(schema);
  6707. if (obj && obj[Symbol.iterator]) {
  6708. for (const it of obj) {
  6709. const v = schema.createNode(it, ctx.wrapScalars, null, ctx);
  6710. seq.items.push(v);
  6711. }
  6712. }
  6713. return seq;
  6714. }
  6715. const seq = {
  6716. createNode: createSeq,
  6717. default: true,
  6718. nodeClass: resolveSeq4a68b39b.YAMLSeq,
  6719. tag: 'tag:yaml.org,2002:seq',
  6720. resolve: resolveSeq4a68b39b.resolveSeq
  6721. };
  6722. const string = {
  6723. identify: value => typeof value === 'string',
  6724. default: true,
  6725. tag: 'tag:yaml.org,2002:str',
  6726. resolve: resolveSeq4a68b39b.resolveString,
  6727. stringify(item, ctx, onComment, onChompKeep) {
  6728. ctx = Object.assign({
  6729. actualString: true
  6730. }, ctx);
  6731. return resolveSeq4a68b39b.stringifyString(item, ctx, onComment, onChompKeep);
  6732. },
  6733. options: resolveSeq4a68b39b.strOptions
  6734. };
  6735. const failsafe = [map, seq, string];
  6736. /* global BigInt */
  6737. const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
  6738. const intResolve = (src, part, radix) => resolveSeq4a68b39b.intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
  6739. function intStringify(node, radix, prefix) {
  6740. const {
  6741. value
  6742. } = node;
  6743. if (intIdentify(value) && value >= 0) return prefix + value.toString(radix);
  6744. return resolveSeq4a68b39b.stringifyNumber(node);
  6745. }
  6746. const nullObj = {
  6747. identify: value => value == null,
  6748. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq4a68b39b.Scalar(null) : null,
  6749. default: true,
  6750. tag: 'tag:yaml.org,2002:null',
  6751. test: /^(?:~|[Nn]ull|NULL)?$/,
  6752. resolve: () => null,
  6753. options: resolveSeq4a68b39b.nullOptions,
  6754. stringify: () => resolveSeq4a68b39b.nullOptions.nullStr
  6755. };
  6756. const boolObj = {
  6757. identify: value => typeof value === 'boolean',
  6758. default: true,
  6759. tag: 'tag:yaml.org,2002:bool',
  6760. test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
  6761. resolve: str => str[0] === 't' || str[0] === 'T',
  6762. options: resolveSeq4a68b39b.boolOptions,
  6763. stringify: ({
  6764. value
  6765. }) => value ? resolveSeq4a68b39b.boolOptions.trueStr : resolveSeq4a68b39b.boolOptions.falseStr
  6766. };
  6767. const octObj = {
  6768. identify: value => intIdentify(value) && value >= 0,
  6769. default: true,
  6770. tag: 'tag:yaml.org,2002:int',
  6771. format: 'OCT',
  6772. test: /^0o([0-7]+)$/,
  6773. resolve: (str, oct) => intResolve(str, oct, 8),
  6774. options: resolveSeq4a68b39b.intOptions,
  6775. stringify: node => intStringify(node, 8, '0o')
  6776. };
  6777. const intObj = {
  6778. identify: intIdentify,
  6779. default: true,
  6780. tag: 'tag:yaml.org,2002:int',
  6781. test: /^[-+]?[0-9]+$/,
  6782. resolve: str => intResolve(str, str, 10),
  6783. options: resolveSeq4a68b39b.intOptions,
  6784. stringify: resolveSeq4a68b39b.stringifyNumber
  6785. };
  6786. const hexObj = {
  6787. identify: value => intIdentify(value) && value >= 0,
  6788. default: true,
  6789. tag: 'tag:yaml.org,2002:int',
  6790. format: 'HEX',
  6791. test: /^0x([0-9a-fA-F]+)$/,
  6792. resolve: (str, hex) => intResolve(str, hex, 16),
  6793. options: resolveSeq4a68b39b.intOptions,
  6794. stringify: node => intStringify(node, 16, '0x')
  6795. };
  6796. const nanObj = {
  6797. identify: value => typeof value === 'number',
  6798. default: true,
  6799. tag: 'tag:yaml.org,2002:float',
  6800. test: /^(?:[-+]?\.inf|(\.nan))$/i,
  6801. resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
  6802. stringify: resolveSeq4a68b39b.stringifyNumber
  6803. };
  6804. const expObj = {
  6805. identify: value => typeof value === 'number',
  6806. default: true,
  6807. tag: 'tag:yaml.org,2002:float',
  6808. format: 'EXP',
  6809. test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
  6810. resolve: str => parseFloat(str),
  6811. stringify: ({
  6812. value
  6813. }) => Number(value).toExponential()
  6814. };
  6815. const floatObj = {
  6816. identify: value => typeof value === 'number',
  6817. default: true,
  6818. tag: 'tag:yaml.org,2002:float',
  6819. test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
  6820. resolve(str, frac1, frac2) {
  6821. const frac = frac1 || frac2;
  6822. const node = new resolveSeq4a68b39b.Scalar(parseFloat(str));
  6823. if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
  6824. return node;
  6825. },
  6826. stringify: resolveSeq4a68b39b.stringifyNumber
  6827. };
  6828. const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
  6829. /* global BigInt */
  6830. const intIdentify$1 = value => typeof value === 'bigint' || Number.isInteger(value);
  6831. const stringifyJSON = ({
  6832. value
  6833. }) => JSON.stringify(value);
  6834. const json = [map, seq, {
  6835. identify: value => typeof value === 'string',
  6836. default: true,
  6837. tag: 'tag:yaml.org,2002:str',
  6838. resolve: resolveSeq4a68b39b.resolveString,
  6839. stringify: stringifyJSON
  6840. }, {
  6841. identify: value => value == null,
  6842. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq4a68b39b.Scalar(null) : null,
  6843. default: true,
  6844. tag: 'tag:yaml.org,2002:null',
  6845. test: /^null$/,
  6846. resolve: () => null,
  6847. stringify: stringifyJSON
  6848. }, {
  6849. identify: value => typeof value === 'boolean',
  6850. default: true,
  6851. tag: 'tag:yaml.org,2002:bool',
  6852. test: /^true|false$/,
  6853. resolve: str => str === 'true',
  6854. stringify: stringifyJSON
  6855. }, {
  6856. identify: intIdentify$1,
  6857. default: true,
  6858. tag: 'tag:yaml.org,2002:int',
  6859. test: /^-?(?:0|[1-9][0-9]*)$/,
  6860. resolve: str => resolveSeq4a68b39b.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
  6861. stringify: ({
  6862. value
  6863. }) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
  6864. }, {
  6865. identify: value => typeof value === 'number',
  6866. default: true,
  6867. tag: 'tag:yaml.org,2002:float',
  6868. test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
  6869. resolve: str => parseFloat(str),
  6870. stringify: stringifyJSON
  6871. }];
  6872. json.scalarFallback = str => {
  6873. throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`);
  6874. };
  6875. /* global BigInt */
  6876. const boolStringify = ({
  6877. value
  6878. }) => value ? resolveSeq4a68b39b.boolOptions.trueStr : resolveSeq4a68b39b.boolOptions.falseStr;
  6879. const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value);
  6880. function intResolve$1(sign, src, radix) {
  6881. let str = src.replace(/_/g, '');
  6882. if (resolveSeq4a68b39b.intOptions.asBigInt) {
  6883. switch (radix) {
  6884. case 2:
  6885. str = `0b${str}`;
  6886. break;
  6887. case 8:
  6888. str = `0o${str}`;
  6889. break;
  6890. case 16:
  6891. str = `0x${str}`;
  6892. break;
  6893. }
  6894. const n = BigInt(str);
  6895. return sign === '-' ? BigInt(-1) * n : n;
  6896. }
  6897. const n = parseInt(str, radix);
  6898. return sign === '-' ? -1 * n : n;
  6899. }
  6900. function intStringify$1(node, radix, prefix) {
  6901. const {
  6902. value
  6903. } = node;
  6904. if (intIdentify$2(value)) {
  6905. const str = value.toString(radix);
  6906. return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
  6907. }
  6908. return resolveSeq4a68b39b.stringifyNumber(node);
  6909. }
  6910. const yaml11 = failsafe.concat([{
  6911. identify: value => value == null,
  6912. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq4a68b39b.Scalar(null) : null,
  6913. default: true,
  6914. tag: 'tag:yaml.org,2002:null',
  6915. test: /^(?:~|[Nn]ull|NULL)?$/,
  6916. resolve: () => null,
  6917. options: resolveSeq4a68b39b.nullOptions,
  6918. stringify: () => resolveSeq4a68b39b.nullOptions.nullStr
  6919. }, {
  6920. identify: value => typeof value === 'boolean',
  6921. default: true,
  6922. tag: 'tag:yaml.org,2002:bool',
  6923. test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
  6924. resolve: () => true,
  6925. options: resolveSeq4a68b39b.boolOptions,
  6926. stringify: boolStringify
  6927. }, {
  6928. identify: value => typeof value === 'boolean',
  6929. default: true,
  6930. tag: 'tag:yaml.org,2002:bool',
  6931. test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
  6932. resolve: () => false,
  6933. options: resolveSeq4a68b39b.boolOptions,
  6934. stringify: boolStringify
  6935. }, {
  6936. identify: intIdentify$2,
  6937. default: true,
  6938. tag: 'tag:yaml.org,2002:int',
  6939. format: 'BIN',
  6940. test: /^([-+]?)0b([0-1_]+)$/,
  6941. resolve: (str, sign, bin) => intResolve$1(sign, bin, 2),
  6942. stringify: node => intStringify$1(node, 2, '0b')
  6943. }, {
  6944. identify: intIdentify$2,
  6945. default: true,
  6946. tag: 'tag:yaml.org,2002:int',
  6947. format: 'OCT',
  6948. test: /^([-+]?)0([0-7_]+)$/,
  6949. resolve: (str, sign, oct) => intResolve$1(sign, oct, 8),
  6950. stringify: node => intStringify$1(node, 8, '0')
  6951. }, {
  6952. identify: intIdentify$2,
  6953. default: true,
  6954. tag: 'tag:yaml.org,2002:int',
  6955. test: /^([-+]?)([0-9][0-9_]*)$/,
  6956. resolve: (str, sign, abs) => intResolve$1(sign, abs, 10),
  6957. stringify: resolveSeq4a68b39b.stringifyNumber
  6958. }, {
  6959. identify: intIdentify$2,
  6960. default: true,
  6961. tag: 'tag:yaml.org,2002:int',
  6962. format: 'HEX',
  6963. test: /^([-+]?)0x([0-9a-fA-F_]+)$/,
  6964. resolve: (str, sign, hex) => intResolve$1(sign, hex, 16),
  6965. stringify: node => intStringify$1(node, 16, '0x')
  6966. }, {
  6967. identify: value => typeof value === 'number',
  6968. default: true,
  6969. tag: 'tag:yaml.org,2002:float',
  6970. test: /^(?:[-+]?\.inf|(\.nan))$/i,
  6971. resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
  6972. stringify: resolveSeq4a68b39b.stringifyNumber
  6973. }, {
  6974. identify: value => typeof value === 'number',
  6975. default: true,
  6976. tag: 'tag:yaml.org,2002:float',
  6977. format: 'EXP',
  6978. test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
  6979. resolve: str => parseFloat(str.replace(/_/g, '')),
  6980. stringify: ({
  6981. value
  6982. }) => Number(value).toExponential()
  6983. }, {
  6984. identify: value => typeof value === 'number',
  6985. default: true,
  6986. tag: 'tag:yaml.org,2002:float',
  6987. test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
  6988. resolve(str, frac) {
  6989. const node = new resolveSeq4a68b39b.Scalar(parseFloat(str.replace(/_/g, '')));
  6990. if (frac) {
  6991. const f = frac.replace(/_/g, '');
  6992. if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
  6993. }
  6994. return node;
  6995. },
  6996. stringify: resolveSeq4a68b39b.stringifyNumber
  6997. }], warnings39684f17.binary, warnings39684f17.omap, warnings39684f17.pairs, warnings39684f17.set, warnings39684f17.intTime, warnings39684f17.floatTime, warnings39684f17.timestamp);
  6998. const schemas = {
  6999. core,
  7000. failsafe,
  7001. json,
  7002. yaml11
  7003. };
  7004. const tags = {
  7005. binary: warnings39684f17.binary,
  7006. bool: boolObj,
  7007. float: floatObj,
  7008. floatExp: expObj,
  7009. floatNaN: nanObj,
  7010. floatTime: warnings39684f17.floatTime,
  7011. int: intObj,
  7012. intHex: hexObj,
  7013. intOct: octObj,
  7014. intTime: warnings39684f17.intTime,
  7015. map,
  7016. null: nullObj,
  7017. omap: warnings39684f17.omap,
  7018. pairs: warnings39684f17.pairs,
  7019. seq,
  7020. set: warnings39684f17.set,
  7021. timestamp: warnings39684f17.timestamp
  7022. };
  7023. function findTagObject(value, tagName, tags) {
  7024. if (tagName) {
  7025. const match = tags.filter(t => t.tag === tagName);
  7026. const tagObj = match.find(t => !t.format) || match[0];
  7027. if (!tagObj) throw new Error(`Tag ${tagName} not found`);
  7028. return tagObj;
  7029. } // TODO: deprecate/remove class check
  7030. return tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
  7031. }
  7032. function createNode(value, tagName, ctx) {
  7033. if (value instanceof resolveSeq4a68b39b.Node) return value;
  7034. const {
  7035. defaultPrefix,
  7036. onTagObj,
  7037. prevObjects,
  7038. schema,
  7039. wrapScalars
  7040. } = ctx;
  7041. if (tagName && tagName.startsWith('!!')) tagName = defaultPrefix + tagName.slice(2);
  7042. let tagObj = findTagObject(value, tagName, schema.tags);
  7043. if (!tagObj) {
  7044. if (typeof value.toJSON === 'function') value = value.toJSON();
  7045. if (typeof value !== 'object') return wrapScalars ? new resolveSeq4a68b39b.Scalar(value) : value;
  7046. tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map;
  7047. }
  7048. if (onTagObj) {
  7049. onTagObj(tagObj);
  7050. delete ctx.onTagObj;
  7051. } // Detect duplicate references to the same object & use Alias nodes for all
  7052. // after first. The `obj` wrapper allows for circular references to resolve.
  7053. const obj = {};
  7054. if (value && typeof value === 'object' && prevObjects) {
  7055. const prev = prevObjects.get(value);
  7056. if (prev) {
  7057. const alias = new resolveSeq4a68b39b.Alias(prev); // leaves source dirty; must be cleaned by caller
  7058. ctx.aliasNodes.push(alias); // defined along with prevObjects
  7059. return alias;
  7060. }
  7061. obj.value = value;
  7062. prevObjects.set(value, obj);
  7063. }
  7064. obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new resolveSeq4a68b39b.Scalar(value) : value;
  7065. if (tagName && obj.node instanceof resolveSeq4a68b39b.Node) obj.node.tag = tagName;
  7066. return obj.node;
  7067. }
  7068. function getSchemaTags(schemas, knownTags, customTags, schemaId) {
  7069. let tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
  7070. if (!tags) {
  7071. const keys = Object.keys(schemas).map(key => JSON.stringify(key)).join(', ');
  7072. throw new Error(`Unknown schema "${schemaId}"; use one of ${keys}`);
  7073. }
  7074. if (Array.isArray(customTags)) {
  7075. for (const tag of customTags) tags = tags.concat(tag);
  7076. } else if (typeof customTags === 'function') {
  7077. tags = customTags(tags.slice());
  7078. }
  7079. for (let i = 0; i < tags.length; ++i) {
  7080. const tag = tags[i];
  7081. if (typeof tag === 'string') {
  7082. const tagObj = knownTags[tag];
  7083. if (!tagObj) {
  7084. const keys = Object.keys(knownTags).map(key => JSON.stringify(key)).join(', ');
  7085. throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
  7086. }
  7087. tags[i] = tagObj;
  7088. }
  7089. }
  7090. return tags;
  7091. }
  7092. const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
  7093. class Schema {
  7094. // TODO: remove in v2
  7095. // TODO: remove in v2
  7096. constructor({
  7097. customTags,
  7098. merge,
  7099. schema,
  7100. sortMapEntries,
  7101. tags: deprecatedCustomTags
  7102. }) {
  7103. this.merge = !!merge;
  7104. this.name = schema;
  7105. this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
  7106. if (!customTags && deprecatedCustomTags) warnings39684f17.warnOptionDeprecation('tags', 'customTags');
  7107. this.tags = getSchemaTags(schemas, tags, customTags || deprecatedCustomTags, schema);
  7108. }
  7109. createNode(value, wrapScalars, tagName, ctx) {
  7110. const baseCtx = {
  7111. defaultPrefix: Schema.defaultPrefix,
  7112. schema: this,
  7113. wrapScalars
  7114. };
  7115. const createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx;
  7116. return createNode(value, tagName, createCtx);
  7117. }
  7118. createPair(key, value, ctx) {
  7119. if (!ctx) ctx = {
  7120. wrapScalars: true
  7121. };
  7122. const k = this.createNode(key, ctx.wrapScalars, null, ctx);
  7123. const v = this.createNode(value, ctx.wrapScalars, null, ctx);
  7124. return new resolveSeq4a68b39b.Pair(k, v);
  7125. }
  7126. }
  7127. PlainValueEc8e588e._defineProperty(Schema, "defaultPrefix", PlainValueEc8e588e.defaultTagPrefix);
  7128. PlainValueEc8e588e._defineProperty(Schema, "defaultTags", PlainValueEc8e588e.defaultTags);
  7129. var Schema_1 = Schema;
  7130. var Schema42e9705c = {
  7131. Schema: Schema_1
  7132. };
  7133. const defaultOptions = {
  7134. anchorPrefix: 'a',
  7135. customTags: null,
  7136. indent: 2,
  7137. indentSeq: true,
  7138. keepCstNodes: false,
  7139. keepNodeTypes: true,
  7140. keepBlobsInJSON: true,
  7141. mapAsMap: false,
  7142. maxAliasCount: 100,
  7143. prettyErrors: false,
  7144. // TODO Set true in v2
  7145. simpleKeys: false,
  7146. version: '1.2'
  7147. };
  7148. const scalarOptions = {
  7149. get binary() {
  7150. return resolveSeq4a68b39b.binaryOptions;
  7151. },
  7152. set binary(opt) {
  7153. Object.assign(resolveSeq4a68b39b.binaryOptions, opt);
  7154. },
  7155. get bool() {
  7156. return resolveSeq4a68b39b.boolOptions;
  7157. },
  7158. set bool(opt) {
  7159. Object.assign(resolveSeq4a68b39b.boolOptions, opt);
  7160. },
  7161. get int() {
  7162. return resolveSeq4a68b39b.intOptions;
  7163. },
  7164. set int(opt) {
  7165. Object.assign(resolveSeq4a68b39b.intOptions, opt);
  7166. },
  7167. get null() {
  7168. return resolveSeq4a68b39b.nullOptions;
  7169. },
  7170. set null(opt) {
  7171. Object.assign(resolveSeq4a68b39b.nullOptions, opt);
  7172. },
  7173. get str() {
  7174. return resolveSeq4a68b39b.strOptions;
  7175. },
  7176. set str(opt) {
  7177. Object.assign(resolveSeq4a68b39b.strOptions, opt);
  7178. }
  7179. };
  7180. const documentOptions = {
  7181. '1.0': {
  7182. schema: 'yaml-1.1',
  7183. merge: true,
  7184. tagPrefixes: [{
  7185. handle: '!',
  7186. prefix: PlainValueEc8e588e.defaultTagPrefix
  7187. }, {
  7188. handle: '!!',
  7189. prefix: 'tag:private.yaml.org,2002:'
  7190. }]
  7191. },
  7192. '1.1': {
  7193. schema: 'yaml-1.1',
  7194. merge: true,
  7195. tagPrefixes: [{
  7196. handle: '!',
  7197. prefix: '!'
  7198. }, {
  7199. handle: '!!',
  7200. prefix: PlainValueEc8e588e.defaultTagPrefix
  7201. }]
  7202. },
  7203. '1.2': {
  7204. schema: 'core',
  7205. merge: false,
  7206. tagPrefixes: [{
  7207. handle: '!',
  7208. prefix: '!'
  7209. }, {
  7210. handle: '!!',
  7211. prefix: PlainValueEc8e588e.defaultTagPrefix
  7212. }]
  7213. }
  7214. };
  7215. function stringifyTag(doc, tag) {
  7216. if ((doc.version || doc.options.version) === '1.0') {
  7217. const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
  7218. if (priv) return '!' + priv[1];
  7219. const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
  7220. return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`;
  7221. }
  7222. let p = doc.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0);
  7223. if (!p) {
  7224. const dtp = doc.getDefaults().tagPrefixes;
  7225. p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0);
  7226. }
  7227. if (!p) return tag[0] === '!' ? tag : `!<${tag}>`;
  7228. const suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, ch => ({
  7229. '!': '%21',
  7230. ',': '%2C',
  7231. '[': '%5B',
  7232. ']': '%5D',
  7233. '{': '%7B',
  7234. '}': '%7D'
  7235. })[ch]);
  7236. return p.handle + suffix;
  7237. }
  7238. function getTagObject(tags, item) {
  7239. if (item instanceof resolveSeq4a68b39b.Alias) return resolveSeq4a68b39b.Alias;
  7240. if (item.tag) {
  7241. const match = tags.filter(t => t.tag === item.tag);
  7242. if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
  7243. }
  7244. let tagObj, obj;
  7245. if (item instanceof resolveSeq4a68b39b.Scalar) {
  7246. obj = item.value; // TODO: deprecate/remove class check
  7247. const match = tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
  7248. tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
  7249. } else {
  7250. obj = item;
  7251. tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
  7252. }
  7253. if (!tagObj) {
  7254. const name = obj && obj.constructor ? obj.constructor.name : typeof obj;
  7255. throw new Error(`Tag not resolved for ${name} value`);
  7256. }
  7257. return tagObj;
  7258. } // needs to be called before value stringifier to allow for circular anchor refs
  7259. function stringifyProps(node, tagObj, {
  7260. anchors,
  7261. doc
  7262. }) {
  7263. const props = [];
  7264. const anchor = doc.anchors.getName(node);
  7265. if (anchor) {
  7266. anchors[anchor] = node;
  7267. props.push(`&${anchor}`);
  7268. }
  7269. if (node.tag) {
  7270. props.push(stringifyTag(doc, node.tag));
  7271. } else if (!tagObj.default) {
  7272. props.push(stringifyTag(doc, tagObj.tag));
  7273. }
  7274. return props.join(' ');
  7275. }
  7276. function stringify(item, ctx, onComment, onChompKeep) {
  7277. const {
  7278. anchors,
  7279. schema
  7280. } = ctx.doc;
  7281. let tagObj;
  7282. if (!(item instanceof resolveSeq4a68b39b.Node)) {
  7283. const createCtx = {
  7284. aliasNodes: [],
  7285. onTagObj: o => tagObj = o,
  7286. prevObjects: new Map()
  7287. };
  7288. item = schema.createNode(item, true, null, createCtx);
  7289. for (const alias of createCtx.aliasNodes) {
  7290. alias.source = alias.source.node;
  7291. let name = anchors.getName(alias.source);
  7292. if (!name) {
  7293. name = anchors.newName();
  7294. anchors.map[name] = alias.source;
  7295. }
  7296. }
  7297. }
  7298. if (item instanceof resolveSeq4a68b39b.Pair) return item.toString(ctx, onComment, onChompKeep);
  7299. if (!tagObj) tagObj = getTagObject(schema.tags, item);
  7300. const props = stringifyProps(item, tagObj, ctx);
  7301. if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
  7302. const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof resolveSeq4a68b39b.Scalar ? resolveSeq4a68b39b.stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep);
  7303. if (!props) return str;
  7304. return item instanceof resolveSeq4a68b39b.Scalar || str[0] === '{' || str[0] === '[' ? `${props} ${str}` : `${props}\n${ctx.indent}${str}`;
  7305. }
  7306. class Anchors {
  7307. static validAnchorNode(node) {
  7308. return node instanceof resolveSeq4a68b39b.Scalar || node instanceof resolveSeq4a68b39b.YAMLSeq || node instanceof resolveSeq4a68b39b.YAMLMap;
  7309. }
  7310. constructor(prefix) {
  7311. PlainValueEc8e588e._defineProperty(this, "map", {});
  7312. this.prefix = prefix;
  7313. }
  7314. createAlias(node, name) {
  7315. this.setAnchor(node, name);
  7316. return new resolveSeq4a68b39b.Alias(node);
  7317. }
  7318. createMergePair(...sources) {
  7319. const merge = new resolveSeq4a68b39b.Merge();
  7320. merge.value.items = sources.map(s => {
  7321. if (s instanceof resolveSeq4a68b39b.Alias) {
  7322. if (s.source instanceof resolveSeq4a68b39b.YAMLMap) return s;
  7323. } else if (s instanceof resolveSeq4a68b39b.YAMLMap) {
  7324. return this.createAlias(s);
  7325. }
  7326. throw new Error('Merge sources must be Map nodes or their Aliases');
  7327. });
  7328. return merge;
  7329. }
  7330. getName(node) {
  7331. const {
  7332. map
  7333. } = this;
  7334. return Object.keys(map).find(a => map[a] === node);
  7335. }
  7336. getNames() {
  7337. return Object.keys(this.map);
  7338. }
  7339. getNode(name) {
  7340. return this.map[name];
  7341. }
  7342. newName(prefix) {
  7343. if (!prefix) prefix = this.prefix;
  7344. const names = Object.keys(this.map);
  7345. for (let i = 1; true; ++i) {
  7346. const name = `${prefix}${i}`;
  7347. if (!names.includes(name)) return name;
  7348. }
  7349. } // During parsing, map & aliases contain CST nodes
  7350. resolveNodes() {
  7351. const {
  7352. map,
  7353. _cstAliases
  7354. } = this;
  7355. Object.keys(map).forEach(a => {
  7356. map[a] = map[a].resolved;
  7357. });
  7358. _cstAliases.forEach(a => {
  7359. a.source = a.source.resolved;
  7360. });
  7361. delete this._cstAliases;
  7362. }
  7363. setAnchor(node, name) {
  7364. if (node != null && !Anchors.validAnchorNode(node)) {
  7365. throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
  7366. }
  7367. if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
  7368. throw new Error('Anchor names must not contain whitespace or control characters');
  7369. }
  7370. const {
  7371. map
  7372. } = this;
  7373. const prev = node && Object.keys(map).find(a => map[a] === node);
  7374. if (prev) {
  7375. if (!name) {
  7376. return prev;
  7377. } else if (prev !== name) {
  7378. delete map[prev];
  7379. map[name] = node;
  7380. }
  7381. } else {
  7382. if (!name) {
  7383. if (!node) return null;
  7384. name = this.newName();
  7385. }
  7386. map[name] = node;
  7387. }
  7388. return name;
  7389. }
  7390. }
  7391. const visit = (node, tags) => {
  7392. if (node && typeof node === 'object') {
  7393. const {
  7394. tag
  7395. } = node;
  7396. if (node instanceof resolveSeq4a68b39b.Collection) {
  7397. if (tag) tags[tag] = true;
  7398. node.items.forEach(n => visit(n, tags));
  7399. } else if (node instanceof resolveSeq4a68b39b.Pair) {
  7400. visit(node.key, tags);
  7401. visit(node.value, tags);
  7402. } else if (node instanceof resolveSeq4a68b39b.Scalar) {
  7403. if (tag) tags[tag] = true;
  7404. }
  7405. }
  7406. return tags;
  7407. };
  7408. const listTagNames = node => Object.keys(visit(node, {}));
  7409. function parseContents(doc, contents) {
  7410. const comments = {
  7411. before: [],
  7412. after: []
  7413. };
  7414. let body = undefined;
  7415. let spaceBefore = false;
  7416. for (const node of contents) {
  7417. if (node.valueRange) {
  7418. if (body !== undefined) {
  7419. const msg = 'Document contains trailing content not separated by a ... or --- line';
  7420. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(node, msg));
  7421. break;
  7422. }
  7423. const res = resolveSeq4a68b39b.resolveNode(doc, node);
  7424. if (spaceBefore) {
  7425. res.spaceBefore = true;
  7426. spaceBefore = false;
  7427. }
  7428. body = res;
  7429. } else if (node.comment !== null) {
  7430. const cc = body === undefined ? comments.before : comments.after;
  7431. cc.push(node.comment);
  7432. } else if (node.type === PlainValueEc8e588e.Type.BLANK_LINE) {
  7433. spaceBefore = true;
  7434. if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
  7435. // space-separated comments at start are parsed as document comments
  7436. doc.commentBefore = comments.before.join('\n');
  7437. comments.before = [];
  7438. }
  7439. }
  7440. }
  7441. doc.contents = body || null;
  7442. if (!body) {
  7443. doc.comment = comments.before.concat(comments.after).join('\n') || null;
  7444. } else {
  7445. const cb = comments.before.join('\n');
  7446. if (cb) {
  7447. const cbNode = body instanceof resolveSeq4a68b39b.Collection && body.items[0] ? body.items[0] : body;
  7448. cbNode.commentBefore = cbNode.commentBefore ? `${cb}\n${cbNode.commentBefore}` : cb;
  7449. }
  7450. doc.comment = comments.after.join('\n') || null;
  7451. }
  7452. }
  7453. function resolveTagDirective({
  7454. tagPrefixes
  7455. }, directive) {
  7456. const [handle, prefix] = directive.parameters;
  7457. if (!handle || !prefix) {
  7458. const msg = 'Insufficient parameters given for %TAG directive';
  7459. throw new PlainValueEc8e588e.YAMLSemanticError(directive, msg);
  7460. }
  7461. if (tagPrefixes.some(p => p.handle === handle)) {
  7462. const msg = 'The %TAG directive must only be given at most once per handle in the same document.';
  7463. throw new PlainValueEc8e588e.YAMLSemanticError(directive, msg);
  7464. }
  7465. return {
  7466. handle,
  7467. prefix
  7468. };
  7469. }
  7470. function resolveYamlDirective(doc, directive) {
  7471. let [version] = directive.parameters;
  7472. if (directive.name === 'YAML:1.0') version = '1.0';
  7473. if (!version) {
  7474. const msg = 'Insufficient parameters given for %YAML directive';
  7475. throw new PlainValueEc8e588e.YAMLSemanticError(directive, msg);
  7476. }
  7477. if (!documentOptions[version]) {
  7478. const v0 = doc.version || doc.options.version;
  7479. const msg = `Document will be parsed as YAML ${v0} rather than YAML ${version}`;
  7480. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(directive, msg));
  7481. }
  7482. return version;
  7483. }
  7484. function parseDirectives(doc, directives, prevDoc) {
  7485. const directiveComments = [];
  7486. let hasDirectives = false;
  7487. for (const directive of directives) {
  7488. const {
  7489. comment,
  7490. name
  7491. } = directive;
  7492. switch (name) {
  7493. case 'TAG':
  7494. try {
  7495. doc.tagPrefixes.push(resolveTagDirective(doc, directive));
  7496. } catch (error) {
  7497. doc.errors.push(error);
  7498. }
  7499. hasDirectives = true;
  7500. break;
  7501. case 'YAML':
  7502. case 'YAML:1.0':
  7503. if (doc.version) {
  7504. const msg = 'The %YAML directive must only be given at most once per document.';
  7505. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(directive, msg));
  7506. }
  7507. try {
  7508. doc.version = resolveYamlDirective(doc, directive);
  7509. } catch (error) {
  7510. doc.errors.push(error);
  7511. }
  7512. hasDirectives = true;
  7513. break;
  7514. default:
  7515. if (name) {
  7516. const msg = `YAML only supports %TAG and %YAML directives, and not %${name}`;
  7517. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(directive, msg));
  7518. }
  7519. }
  7520. if (comment) directiveComments.push(comment);
  7521. }
  7522. if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) {
  7523. const copyTagPrefix = ({
  7524. handle,
  7525. prefix
  7526. }) => ({
  7527. handle,
  7528. prefix
  7529. });
  7530. doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
  7531. doc.version = prevDoc.version;
  7532. }
  7533. doc.commentBefore = directiveComments.join('\n') || null;
  7534. }
  7535. function assertCollection(contents) {
  7536. if (contents instanceof resolveSeq4a68b39b.Collection) return true;
  7537. throw new Error('Expected a YAML collection as document contents');
  7538. }
  7539. class Document$1 {
  7540. constructor(options) {
  7541. this.anchors = new Anchors(options.anchorPrefix);
  7542. this.commentBefore = null;
  7543. this.comment = null;
  7544. this.contents = null;
  7545. this.directivesEndMarker = null;
  7546. this.errors = [];
  7547. this.options = options;
  7548. this.schema = null;
  7549. this.tagPrefixes = [];
  7550. this.version = null;
  7551. this.warnings = [];
  7552. }
  7553. add(value) {
  7554. assertCollection(this.contents);
  7555. return this.contents.add(value);
  7556. }
  7557. addIn(path, value) {
  7558. assertCollection(this.contents);
  7559. this.contents.addIn(path, value);
  7560. }
  7561. delete(key) {
  7562. assertCollection(this.contents);
  7563. return this.contents.delete(key);
  7564. }
  7565. deleteIn(path) {
  7566. if (resolveSeq4a68b39b.isEmptyPath(path)) {
  7567. if (this.contents == null) return false;
  7568. this.contents = null;
  7569. return true;
  7570. }
  7571. assertCollection(this.contents);
  7572. return this.contents.deleteIn(path);
  7573. }
  7574. getDefaults() {
  7575. return Document$1.defaults[this.version] || Document$1.defaults[this.options.version] || {};
  7576. }
  7577. get(key, keepScalar) {
  7578. return this.contents instanceof resolveSeq4a68b39b.Collection ? this.contents.get(key, keepScalar) : undefined;
  7579. }
  7580. getIn(path, keepScalar) {
  7581. if (resolveSeq4a68b39b.isEmptyPath(path)) return !keepScalar && this.contents instanceof resolveSeq4a68b39b.Scalar ? this.contents.value : this.contents;
  7582. return this.contents instanceof resolveSeq4a68b39b.Collection ? this.contents.getIn(path, keepScalar) : undefined;
  7583. }
  7584. has(key) {
  7585. return this.contents instanceof resolveSeq4a68b39b.Collection ? this.contents.has(key) : false;
  7586. }
  7587. hasIn(path) {
  7588. if (resolveSeq4a68b39b.isEmptyPath(path)) return this.contents !== undefined;
  7589. return this.contents instanceof resolveSeq4a68b39b.Collection ? this.contents.hasIn(path) : false;
  7590. }
  7591. set(key, value) {
  7592. assertCollection(this.contents);
  7593. this.contents.set(key, value);
  7594. }
  7595. setIn(path, value) {
  7596. if (resolveSeq4a68b39b.isEmptyPath(path)) this.contents = value;else {
  7597. assertCollection(this.contents);
  7598. this.contents.setIn(path, value);
  7599. }
  7600. }
  7601. setSchema(id, customTags) {
  7602. if (!id && !customTags && this.schema) return;
  7603. if (typeof id === 'number') id = id.toFixed(1);
  7604. if (id === '1.0' || id === '1.1' || id === '1.2') {
  7605. if (this.version) this.version = id;else this.options.version = id;
  7606. delete this.options.schema;
  7607. } else if (id && typeof id === 'string') {
  7608. this.options.schema = id;
  7609. }
  7610. if (Array.isArray(customTags)) this.options.customTags = customTags;
  7611. const opt = Object.assign({}, this.getDefaults(), this.options);
  7612. this.schema = new Schema42e9705c.Schema(opt);
  7613. }
  7614. parse(node, prevDoc) {
  7615. if (this.options.keepCstNodes) this.cstNode = node;
  7616. if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
  7617. const {
  7618. directives = [],
  7619. contents = [],
  7620. directivesEndMarker,
  7621. error,
  7622. valueRange
  7623. } = node;
  7624. if (error) {
  7625. if (!error.source) error.source = this;
  7626. this.errors.push(error);
  7627. }
  7628. parseDirectives(this, directives, prevDoc);
  7629. if (directivesEndMarker) this.directivesEndMarker = true;
  7630. this.range = valueRange ? [valueRange.start, valueRange.end] : null;
  7631. this.setSchema();
  7632. this.anchors._cstAliases = [];
  7633. parseContents(this, contents);
  7634. this.anchors.resolveNodes();
  7635. if (this.options.prettyErrors) {
  7636. for (const error of this.errors) if (error instanceof PlainValueEc8e588e.YAMLError) error.makePretty();
  7637. for (const warn of this.warnings) if (warn instanceof PlainValueEc8e588e.YAMLError) warn.makePretty();
  7638. }
  7639. return this;
  7640. }
  7641. listNonDefaultTags() {
  7642. return listTagNames(this.contents).filter(t => t.indexOf(Schema42e9705c.Schema.defaultPrefix) !== 0);
  7643. }
  7644. setTagPrefix(handle, prefix) {
  7645. if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
  7646. if (prefix) {
  7647. const prev = this.tagPrefixes.find(p => p.handle === handle);
  7648. if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
  7649. handle,
  7650. prefix
  7651. });
  7652. } else {
  7653. this.tagPrefixes = this.tagPrefixes.filter(p => p.handle !== handle);
  7654. }
  7655. }
  7656. toJSON(arg, onAnchor) {
  7657. const {
  7658. keepBlobsInJSON,
  7659. mapAsMap,
  7660. maxAliasCount
  7661. } = this.options;
  7662. const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof resolveSeq4a68b39b.Scalar));
  7663. const ctx = {
  7664. doc: this,
  7665. indentStep: ' ',
  7666. keep,
  7667. mapAsMap: keep && !!mapAsMap,
  7668. maxAliasCount,
  7669. stringify // Requiring directly in Pair would create circular dependencies
  7670. };
  7671. const anchorNames = Object.keys(this.anchors.map);
  7672. if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(name => [this.anchors.map[name], {
  7673. alias: [],
  7674. aliasCount: 0,
  7675. count: 1
  7676. }]));
  7677. const res = resolveSeq4a68b39b.toJSON(this.contents, arg, ctx);
  7678. if (typeof onAnchor === 'function' && ctx.anchors) for (const {
  7679. count,
  7680. res
  7681. } of ctx.anchors.values()) onAnchor(res, count);
  7682. return res;
  7683. }
  7684. toString() {
  7685. if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
  7686. const indentSize = this.options.indent;
  7687. if (!Number.isInteger(indentSize) || indentSize <= 0) {
  7688. const s = JSON.stringify(indentSize);
  7689. throw new Error(`"indent" option must be a positive integer, not ${s}`);
  7690. }
  7691. this.setSchema();
  7692. const lines = [];
  7693. let hasDirectives = false;
  7694. if (this.version) {
  7695. let vd = '%YAML 1.2';
  7696. if (this.schema.name === 'yaml-1.1') {
  7697. if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
  7698. }
  7699. lines.push(vd);
  7700. hasDirectives = true;
  7701. }
  7702. const tagNames = this.listNonDefaultTags();
  7703. this.tagPrefixes.forEach(({
  7704. handle,
  7705. prefix
  7706. }) => {
  7707. if (tagNames.some(t => t.indexOf(prefix) === 0)) {
  7708. lines.push(`%TAG ${handle} ${prefix}`);
  7709. hasDirectives = true;
  7710. }
  7711. });
  7712. if (hasDirectives || this.directivesEndMarker) lines.push('---');
  7713. if (this.commentBefore) {
  7714. if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
  7715. lines.unshift(this.commentBefore.replace(/^/gm, '#'));
  7716. }
  7717. const ctx = {
  7718. anchors: {},
  7719. doc: this,
  7720. indent: '',
  7721. indentStep: ' '.repeat(indentSize),
  7722. stringify // Requiring directly in nodes would create circular dependencies
  7723. };
  7724. let chompKeep = false;
  7725. let contentComment = null;
  7726. if (this.contents) {
  7727. if (this.contents instanceof resolveSeq4a68b39b.Node) {
  7728. if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
  7729. if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
  7730. ctx.forceBlockIndent = !!this.comment;
  7731. contentComment = this.contents.comment;
  7732. }
  7733. const onChompKeep = contentComment ? null : () => chompKeep = true;
  7734. const body = stringify(this.contents, ctx, () => contentComment = null, onChompKeep);
  7735. lines.push(resolveSeq4a68b39b.addComment(body, '', contentComment));
  7736. } else if (this.contents !== undefined) {
  7737. lines.push(stringify(this.contents, ctx));
  7738. }
  7739. if (this.comment) {
  7740. if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
  7741. lines.push(this.comment.replace(/^/gm, '#'));
  7742. }
  7743. return lines.join('\n') + '\n';
  7744. }
  7745. }
  7746. PlainValueEc8e588e._defineProperty(Document$1, "defaults", documentOptions);
  7747. var Document_1 = Document$1;
  7748. var defaultOptions_1 = defaultOptions;
  7749. var scalarOptions_1 = scalarOptions;
  7750. var Document2cf6b08c = {
  7751. Document: Document_1,
  7752. defaultOptions: defaultOptions_1,
  7753. scalarOptions: scalarOptions_1
  7754. };
  7755. function createNode$1(value, wrapScalars = true, tag) {
  7756. if (tag === undefined && typeof wrapScalars === 'string') {
  7757. tag = wrapScalars;
  7758. wrapScalars = true;
  7759. }
  7760. const options = Object.assign({}, Document2cf6b08c.Document.defaults[Document2cf6b08c.defaultOptions.version], Document2cf6b08c.defaultOptions);
  7761. const schema = new Schema42e9705c.Schema(options);
  7762. return schema.createNode(value, wrapScalars, tag);
  7763. }
  7764. class Document$2 extends Document2cf6b08c.Document {
  7765. constructor(options) {
  7766. super(Object.assign({}, Document2cf6b08c.defaultOptions, options));
  7767. }
  7768. }
  7769. function parseAllDocuments(src, options) {
  7770. const stream = [];
  7771. let prev;
  7772. for (const cstDoc of parseCst.parse(src)) {
  7773. const doc = new Document$2(options);
  7774. doc.parse(cstDoc, prev);
  7775. stream.push(doc);
  7776. prev = doc;
  7777. }
  7778. return stream;
  7779. }
  7780. function parseDocument(src, options) {
  7781. const cst = parseCst.parse(src);
  7782. const doc = new Document$2(options).parse(cst[0]);
  7783. if (cst.length > 1) {
  7784. const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
  7785. doc.errors.unshift(new PlainValueEc8e588e.YAMLSemanticError(cst[1], errMsg));
  7786. }
  7787. return doc;
  7788. }
  7789. function parse$1(src, options) {
  7790. const doc = parseDocument(src, options);
  7791. doc.warnings.forEach(warning => warnings39684f17.warn(warning));
  7792. if (doc.errors.length > 0) throw doc.errors[0];
  7793. return doc.toJSON();
  7794. }
  7795. function stringify$1(value, options) {
  7796. const doc = new Document$2(options);
  7797. doc.contents = value;
  7798. return String(doc);
  7799. }
  7800. const YAML = {
  7801. createNode: createNode$1,
  7802. defaultOptions: Document2cf6b08c.defaultOptions,
  7803. Document: Document$2,
  7804. parse: parse$1,
  7805. parseAllDocuments,
  7806. parseCST: parseCst.parse,
  7807. parseDocument,
  7808. scalarOptions: Document2cf6b08c.scalarOptions,
  7809. stringify: stringify$1
  7810. };
  7811. var YAML_1 = YAML;
  7812. var dist$1 = {
  7813. YAML: YAML_1
  7814. };
  7815. var yaml = dist$1.YAML;
  7816. var loaders_1 = createCommonjsModule(function (module, exports) {
  7817. Object.defineProperty(exports, "__esModule", {
  7818. value: true
  7819. });
  7820. exports.loaders = void 0;
  7821. /* eslint-disable @typescript-eslint/no-require-imports */
  7822. let importFresh$1;
  7823. const loadJs = function loadJs(filepath) {
  7824. if (importFresh$1 === undefined) {
  7825. importFresh$1 = importFresh;
  7826. }
  7827. const result = importFresh$1(filepath);
  7828. return result;
  7829. };
  7830. let parseJson;
  7831. const loadJson = function loadJson(filepath, content) {
  7832. if (parseJson === undefined) {
  7833. parseJson = parseJson$1;
  7834. }
  7835. try {
  7836. const result = parseJson(content);
  7837. return result;
  7838. } catch (error) {
  7839. error.message = `JSON Error in ${filepath}:\n${error.message}`;
  7840. throw error;
  7841. }
  7842. };
  7843. let yaml$1;
  7844. const loadYaml = function loadYaml(filepath, content) {
  7845. if (yaml$1 === undefined) {
  7846. yaml$1 = yaml;
  7847. }
  7848. try {
  7849. const result = yaml$1.parse(content, {
  7850. prettyErrors: true
  7851. });
  7852. return result;
  7853. } catch (error) {
  7854. error.message = `YAML Error in ${filepath}:\n${error.message}`;
  7855. throw error;
  7856. }
  7857. };
  7858. const loaders = {
  7859. loadJs,
  7860. loadJson,
  7861. loadYaml
  7862. };
  7863. exports.loaders = loaders;
  7864. });
  7865. var getPropertyByPath_1 = createCommonjsModule(function (module, exports) {
  7866. Object.defineProperty(exports, "__esModule", {
  7867. value: true
  7868. });
  7869. exports.getPropertyByPath = getPropertyByPath; // Resolves property names or property paths defined with period-delimited
  7870. // strings or arrays of strings. Property names that are found on the source
  7871. // object are used directly (even if they include a period).
  7872. // Nested property names that include periods, within a path, are only
  7873. // understood in array paths.
  7874. function getPropertyByPath(source, path) {
  7875. if (typeof path === 'string' && Object.prototype.hasOwnProperty.call(source, path)) {
  7876. return source[path];
  7877. }
  7878. const parsedPath = typeof path === 'string' ? path.split('.') : path; // eslint-disable-next-line @typescript-eslint/no-explicit-any
  7879. return parsedPath.reduce((previous, key) => {
  7880. if (previous === undefined) {
  7881. return previous;
  7882. }
  7883. return previous[key];
  7884. }, source);
  7885. }
  7886. });
  7887. var ExplorerBase_1 = createCommonjsModule(function (module, exports) {
  7888. Object.defineProperty(exports, "__esModule", {
  7889. value: true
  7890. });
  7891. exports.getExtensionDescription = getExtensionDescription;
  7892. exports.ExplorerBase = void 0;
  7893. var _path = _interopRequireDefault(path__default['default']);
  7894. function _interopRequireDefault(obj) {
  7895. return obj && obj.__esModule ? obj : {
  7896. default: obj
  7897. };
  7898. }
  7899. class ExplorerBase {
  7900. constructor(options) {
  7901. if (options.cache === true) {
  7902. this.loadCache = new Map();
  7903. this.searchCache = new Map();
  7904. }
  7905. this.config = options;
  7906. this.validateConfig();
  7907. }
  7908. clearLoadCache() {
  7909. if (this.loadCache) {
  7910. this.loadCache.clear();
  7911. }
  7912. }
  7913. clearSearchCache() {
  7914. if (this.searchCache) {
  7915. this.searchCache.clear();
  7916. }
  7917. }
  7918. clearCaches() {
  7919. this.clearLoadCache();
  7920. this.clearSearchCache();
  7921. }
  7922. validateConfig() {
  7923. const config = this.config;
  7924. config.searchPlaces.forEach(place => {
  7925. const loaderKey = _path.default.extname(place) || 'noExt';
  7926. const loader = config.loaders[loaderKey];
  7927. if (!loader) {
  7928. throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
  7929. }
  7930. if (typeof loader !== 'function') {
  7931. throw new Error(`loader for ${getExtensionDescription(place)} is not a function (type provided: "${typeof loader}"), so searchPlaces item "${place}" is invalid`);
  7932. }
  7933. });
  7934. }
  7935. shouldSearchStopWithResult(result) {
  7936. if (result === null) return false;
  7937. if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
  7938. return true;
  7939. }
  7940. nextDirectoryToSearch(currentDir, currentResult) {
  7941. if (this.shouldSearchStopWithResult(currentResult)) {
  7942. return null;
  7943. }
  7944. const nextDir = nextDirUp(currentDir);
  7945. if (nextDir === currentDir || currentDir === this.config.stopDir) {
  7946. return null;
  7947. }
  7948. return nextDir;
  7949. }
  7950. loadPackageProp(filepath, content) {
  7951. const parsedContent = loaders_1.loaders.loadJson(filepath, content);
  7952. const packagePropValue = (0, getPropertyByPath_1.getPropertyByPath)(parsedContent, this.config.packageProp);
  7953. return packagePropValue || null;
  7954. }
  7955. getLoaderEntryForFile(filepath) {
  7956. if (_path.default.basename(filepath) === 'package.json') {
  7957. const loader = this.loadPackageProp.bind(this);
  7958. return loader;
  7959. }
  7960. const loaderKey = _path.default.extname(filepath) || 'noExt';
  7961. const loader = this.config.loaders[loaderKey];
  7962. if (!loader) {
  7963. throw new Error(`No loader specified for ${getExtensionDescription(filepath)}`);
  7964. }
  7965. return loader;
  7966. }
  7967. loadedContentToCosmiconfigResult(filepath, loadedContent) {
  7968. if (loadedContent === null) {
  7969. return null;
  7970. }
  7971. if (loadedContent === undefined) {
  7972. return {
  7973. filepath,
  7974. config: undefined,
  7975. isEmpty: true
  7976. };
  7977. }
  7978. return {
  7979. config: loadedContent,
  7980. filepath
  7981. };
  7982. }
  7983. validateFilePath(filepath) {
  7984. if (!filepath) {
  7985. throw new Error('load must pass a non-empty string');
  7986. }
  7987. }
  7988. }
  7989. exports.ExplorerBase = ExplorerBase;
  7990. function nextDirUp(dir) {
  7991. return _path.default.dirname(dir);
  7992. }
  7993. function getExtensionDescription(filepath) {
  7994. const ext = _path.default.extname(filepath);
  7995. return ext ? `extension "${ext}"` : 'files without extensions';
  7996. }
  7997. });
  7998. var readFile_1 = createCommonjsModule(function (module, exports) {
  7999. Object.defineProperty(exports, "__esModule", {
  8000. value: true
  8001. });
  8002. exports.readFile = readFile;
  8003. exports.readFileSync = readFileSync;
  8004. var _fs = _interopRequireDefault(fs__default['default']);
  8005. function _interopRequireDefault(obj) {
  8006. return obj && obj.__esModule ? obj : {
  8007. default: obj
  8008. };
  8009. }
  8010. async function fsReadFileAsync(pathname, encoding) {
  8011. return new Promise((resolve, reject) => {
  8012. _fs.default.readFile(pathname, encoding, (error, contents) => {
  8013. if (error) {
  8014. reject(error);
  8015. return;
  8016. }
  8017. resolve(contents);
  8018. });
  8019. });
  8020. }
  8021. async function readFile(filepath, options = {}) {
  8022. const throwNotFound = options.throwNotFound === true;
  8023. try {
  8024. const content = await fsReadFileAsync(filepath, 'utf8');
  8025. return content;
  8026. } catch (error) {
  8027. if (throwNotFound === false && error.code === 'ENOENT') {
  8028. return null;
  8029. }
  8030. throw error;
  8031. }
  8032. }
  8033. function readFileSync(filepath, options = {}) {
  8034. const throwNotFound = options.throwNotFound === true;
  8035. try {
  8036. const content = _fs.default.readFileSync(filepath, 'utf8');
  8037. return content;
  8038. } catch (error) {
  8039. if (throwNotFound === false && error.code === 'ENOENT') {
  8040. return null;
  8041. }
  8042. throw error;
  8043. }
  8044. }
  8045. });
  8046. var cacheWrapper_1 = createCommonjsModule(function (module, exports) {
  8047. Object.defineProperty(exports, "__esModule", {
  8048. value: true
  8049. });
  8050. exports.cacheWrapper = cacheWrapper;
  8051. exports.cacheWrapperSync = cacheWrapperSync;
  8052. async function cacheWrapper(cache, key, fn) {
  8053. const cached = cache.get(key);
  8054. if (cached !== undefined) {
  8055. return cached;
  8056. }
  8057. const result = await fn();
  8058. cache.set(key, result);
  8059. return result;
  8060. }
  8061. function cacheWrapperSync(cache, key, fn) {
  8062. const cached = cache.get(key);
  8063. if (cached !== undefined) {
  8064. return cached;
  8065. }
  8066. const result = fn();
  8067. cache.set(key, result);
  8068. return result;
  8069. }
  8070. });
  8071. const {
  8072. promisify
  8073. } = util__default['default'];
  8074. async function isType(fsStatType, statsMethodName, filePath) {
  8075. if (typeof filePath !== 'string') {
  8076. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  8077. }
  8078. try {
  8079. const stats = await promisify(fs__default['default'][fsStatType])(filePath);
  8080. return stats[statsMethodName]();
  8081. } catch (error) {
  8082. if (error.code === 'ENOENT') {
  8083. return false;
  8084. }
  8085. throw error;
  8086. }
  8087. }
  8088. function isTypeSync(fsStatType, statsMethodName, filePath) {
  8089. if (typeof filePath !== 'string') {
  8090. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  8091. }
  8092. try {
  8093. return fs__default['default'][fsStatType](filePath)[statsMethodName]();
  8094. } catch (error) {
  8095. if (error.code === 'ENOENT') {
  8096. return false;
  8097. }
  8098. throw error;
  8099. }
  8100. }
  8101. var isFile = isType.bind(null, 'stat', 'isFile');
  8102. var isDirectory = isType.bind(null, 'stat', 'isDirectory');
  8103. var isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink');
  8104. var isFileSync = isTypeSync.bind(null, 'statSync', 'isFile');
  8105. var isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory');
  8106. var isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink');
  8107. var pathType = {
  8108. isFile: isFile,
  8109. isDirectory: isDirectory,
  8110. isSymlink: isSymlink,
  8111. isFileSync: isFileSync,
  8112. isDirectorySync: isDirectorySync,
  8113. isSymlinkSync: isSymlinkSync
  8114. };
  8115. var getDirectory_1 = createCommonjsModule(function (module, exports) {
  8116. Object.defineProperty(exports, "__esModule", {
  8117. value: true
  8118. });
  8119. exports.getDirectory = getDirectory;
  8120. exports.getDirectorySync = getDirectorySync;
  8121. var _path = _interopRequireDefault(path__default['default']);
  8122. function _interopRequireDefault(obj) {
  8123. return obj && obj.__esModule ? obj : {
  8124. default: obj
  8125. };
  8126. }
  8127. async function getDirectory(filepath) {
  8128. const filePathIsDirectory = await (0, pathType.isDirectory)(filepath);
  8129. if (filePathIsDirectory === true) {
  8130. return filepath;
  8131. }
  8132. const directory = _path.default.dirname(filepath);
  8133. return directory;
  8134. }
  8135. function getDirectorySync(filepath) {
  8136. const filePathIsDirectory = (0, pathType.isDirectorySync)(filepath);
  8137. if (filePathIsDirectory === true) {
  8138. return filepath;
  8139. }
  8140. const directory = _path.default.dirname(filepath);
  8141. return directory;
  8142. }
  8143. });
  8144. var Explorer_1 = createCommonjsModule(function (module, exports) {
  8145. Object.defineProperty(exports, "__esModule", {
  8146. value: true
  8147. });
  8148. exports.Explorer = void 0;
  8149. var _path = _interopRequireDefault(path__default['default']);
  8150. function _interopRequireDefault(obj) {
  8151. return obj && obj.__esModule ? obj : {
  8152. default: obj
  8153. };
  8154. }
  8155. class Explorer extends ExplorerBase_1.ExplorerBase {
  8156. constructor(options) {
  8157. super(options);
  8158. }
  8159. async search(searchFrom = process.cwd()) {
  8160. const startDirectory = await (0, getDirectory_1.getDirectory)(searchFrom);
  8161. const result = await this.searchFromDirectory(startDirectory);
  8162. return result;
  8163. }
  8164. async searchFromDirectory(dir) {
  8165. const absoluteDir = _path.default.resolve(process.cwd(), dir);
  8166. const run = async () => {
  8167. const result = await this.searchDirectory(absoluteDir);
  8168. const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
  8169. if (nextDir) {
  8170. return this.searchFromDirectory(nextDir);
  8171. }
  8172. const transformResult = await this.config.transform(result);
  8173. return transformResult;
  8174. };
  8175. if (this.searchCache) {
  8176. return (0, cacheWrapper_1.cacheWrapper)(this.searchCache, absoluteDir, run);
  8177. }
  8178. return run();
  8179. }
  8180. async searchDirectory(dir) {
  8181. for await (const place of this.config.searchPlaces) {
  8182. const placeResult = await this.loadSearchPlace(dir, place);
  8183. if (this.shouldSearchStopWithResult(placeResult) === true) {
  8184. return placeResult;
  8185. }
  8186. } // config not found
  8187. return null;
  8188. }
  8189. async loadSearchPlace(dir, place) {
  8190. const filepath = _path.default.join(dir, place);
  8191. const fileContents = await (0, readFile_1.readFile)(filepath);
  8192. const result = await this.createCosmiconfigResult(filepath, fileContents);
  8193. return result;
  8194. }
  8195. async loadFileContent(filepath, content) {
  8196. if (content === null) {
  8197. return null;
  8198. }
  8199. if (content.trim() === '') {
  8200. return undefined;
  8201. }
  8202. const loader = this.getLoaderEntryForFile(filepath);
  8203. const loaderResult = await loader(filepath, content);
  8204. return loaderResult;
  8205. }
  8206. async createCosmiconfigResult(filepath, content) {
  8207. const fileContent = await this.loadFileContent(filepath, content);
  8208. const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
  8209. return result;
  8210. }
  8211. async load(filepath) {
  8212. this.validateFilePath(filepath);
  8213. const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
  8214. const runLoad = async () => {
  8215. const fileContents = await (0, readFile_1.readFile)(absoluteFilePath, {
  8216. throwNotFound: true
  8217. });
  8218. const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents);
  8219. const transformResult = await this.config.transform(result);
  8220. return transformResult;
  8221. };
  8222. if (this.loadCache) {
  8223. return (0, cacheWrapper_1.cacheWrapper)(this.loadCache, absoluteFilePath, runLoad);
  8224. }
  8225. return runLoad();
  8226. }
  8227. }
  8228. exports.Explorer = Explorer;
  8229. });
  8230. var ExplorerSync_1 = createCommonjsModule(function (module, exports) {
  8231. Object.defineProperty(exports, "__esModule", {
  8232. value: true
  8233. });
  8234. exports.ExplorerSync = void 0;
  8235. var _path = _interopRequireDefault(path__default['default']);
  8236. function _interopRequireDefault(obj) {
  8237. return obj && obj.__esModule ? obj : {
  8238. default: obj
  8239. };
  8240. }
  8241. class ExplorerSync extends ExplorerBase_1.ExplorerBase {
  8242. constructor(options) {
  8243. super(options);
  8244. }
  8245. searchSync(searchFrom = process.cwd()) {
  8246. const startDirectory = (0, getDirectory_1.getDirectorySync)(searchFrom);
  8247. const result = this.searchFromDirectorySync(startDirectory);
  8248. return result;
  8249. }
  8250. searchFromDirectorySync(dir) {
  8251. const absoluteDir = _path.default.resolve(process.cwd(), dir);
  8252. const run = () => {
  8253. const result = this.searchDirectorySync(absoluteDir);
  8254. const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
  8255. if (nextDir) {
  8256. return this.searchFromDirectorySync(nextDir);
  8257. }
  8258. const transformResult = this.config.transform(result);
  8259. return transformResult;
  8260. };
  8261. if (this.searchCache) {
  8262. return (0, cacheWrapper_1.cacheWrapperSync)(this.searchCache, absoluteDir, run);
  8263. }
  8264. return run();
  8265. }
  8266. searchDirectorySync(dir) {
  8267. for (const place of this.config.searchPlaces) {
  8268. const placeResult = this.loadSearchPlaceSync(dir, place);
  8269. if (this.shouldSearchStopWithResult(placeResult) === true) {
  8270. return placeResult;
  8271. }
  8272. } // config not found
  8273. return null;
  8274. }
  8275. loadSearchPlaceSync(dir, place) {
  8276. const filepath = _path.default.join(dir, place);
  8277. const content = (0, readFile_1.readFileSync)(filepath);
  8278. const result = this.createCosmiconfigResultSync(filepath, content);
  8279. return result;
  8280. }
  8281. loadFileContentSync(filepath, content) {
  8282. if (content === null) {
  8283. return null;
  8284. }
  8285. if (content.trim() === '') {
  8286. return undefined;
  8287. }
  8288. const loader = this.getLoaderEntryForFile(filepath);
  8289. const loaderResult = loader(filepath, content);
  8290. return loaderResult;
  8291. }
  8292. createCosmiconfigResultSync(filepath, content) {
  8293. const fileContent = this.loadFileContentSync(filepath, content);
  8294. const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
  8295. return result;
  8296. }
  8297. loadSync(filepath) {
  8298. this.validateFilePath(filepath);
  8299. const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
  8300. const runLoadSync = () => {
  8301. const content = (0, readFile_1.readFileSync)(absoluteFilePath, {
  8302. throwNotFound: true
  8303. });
  8304. const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content);
  8305. const transformResult = this.config.transform(cosmiconfigResult);
  8306. return transformResult;
  8307. };
  8308. if (this.loadCache) {
  8309. return (0, cacheWrapper_1.cacheWrapperSync)(this.loadCache, absoluteFilePath, runLoadSync);
  8310. }
  8311. return runLoadSync();
  8312. }
  8313. }
  8314. exports.ExplorerSync = ExplorerSync;
  8315. });
  8316. var dist$2 = createCommonjsModule(function (module, exports) {
  8317. Object.defineProperty(exports, "__esModule", {
  8318. value: true
  8319. });
  8320. exports.cosmiconfig = cosmiconfig;
  8321. exports.cosmiconfigSync = cosmiconfigSync;
  8322. exports.defaultLoaders = void 0;
  8323. var _os = _interopRequireDefault(os__default['default']);
  8324. function _interopRequireDefault(obj) {
  8325. return obj && obj.__esModule ? obj : {
  8326. default: obj
  8327. };
  8328. }
  8329. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  8330. // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  8331. function cosmiconfig(moduleName, options = {}) {
  8332. const normalizedOptions = normalizeOptions(moduleName, options);
  8333. const explorer = new Explorer_1.Explorer(normalizedOptions);
  8334. return {
  8335. search: explorer.search.bind(explorer),
  8336. load: explorer.load.bind(explorer),
  8337. clearLoadCache: explorer.clearLoadCache.bind(explorer),
  8338. clearSearchCache: explorer.clearSearchCache.bind(explorer),
  8339. clearCaches: explorer.clearCaches.bind(explorer)
  8340. };
  8341. } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  8342. function cosmiconfigSync(moduleName, options = {}) {
  8343. const normalizedOptions = normalizeOptions(moduleName, options);
  8344. const explorerSync = new ExplorerSync_1.ExplorerSync(normalizedOptions);
  8345. return {
  8346. search: explorerSync.searchSync.bind(explorerSync),
  8347. load: explorerSync.loadSync.bind(explorerSync),
  8348. clearLoadCache: explorerSync.clearLoadCache.bind(explorerSync),
  8349. clearSearchCache: explorerSync.clearSearchCache.bind(explorerSync),
  8350. clearCaches: explorerSync.clearCaches.bind(explorerSync)
  8351. };
  8352. } // do not allow mutation of default loaders. Make sure it is set inside options
  8353. const defaultLoaders = Object.freeze({
  8354. '.cjs': loaders_1.loaders.loadJs,
  8355. '.js': loaders_1.loaders.loadJs,
  8356. '.json': loaders_1.loaders.loadJson,
  8357. '.yaml': loaders_1.loaders.loadYaml,
  8358. '.yml': loaders_1.loaders.loadYaml,
  8359. noExt: loaders_1.loaders.loadYaml
  8360. });
  8361. exports.defaultLoaders = defaultLoaders;
  8362. const identity = function identity(x) {
  8363. return x;
  8364. };
  8365. function normalizeOptions(moduleName, options) {
  8366. const defaults = {
  8367. packageProp: moduleName,
  8368. 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`],
  8369. ignoreEmptySearchPlaces: true,
  8370. stopDir: _os.default.homedir(),
  8371. cache: true,
  8372. transform: identity,
  8373. loaders: defaultLoaders
  8374. };
  8375. const normalizedOptions = Object.assign({}, defaults, options, {
  8376. loaders: Object.assign({}, defaults.loaders, options.loaders)
  8377. });
  8378. return normalizedOptions;
  8379. }
  8380. });
  8381. var findParentDir = createCommonjsModule(function (module, exports) {
  8382. var exists = fs__default['default'].exists || path__default['default'].exists,
  8383. existsSync = fs__default['default'].existsSync || path__default['default'].existsSync;
  8384. function splitPath(path) {
  8385. var parts = path.split(/(\/|\\)/);
  8386. if (!parts.length) return parts; // when path starts with a slash, the first part is empty string
  8387. return !parts[0].length ? parts.slice(1) : parts;
  8388. }
  8389. exports = module.exports = function (currentFullPath, clue, cb) {
  8390. function testDir(parts) {
  8391. if (parts.length === 0) return cb(null, null);
  8392. var p = parts.join('');
  8393. exists(path__default['default'].join(p, clue), function (itdoes) {
  8394. if (itdoes) return cb(null, p);
  8395. testDir(parts.slice(0, -1));
  8396. });
  8397. }
  8398. testDir(splitPath(currentFullPath));
  8399. };
  8400. exports.sync = function (currentFullPath, clue) {
  8401. function testDir(parts) {
  8402. if (parts.length === 0) return null;
  8403. var p = parts.join('');
  8404. var itdoes = existsSync(path__default['default'].join(p, clue));
  8405. return itdoes ? p : testDir(parts.slice(0, -1));
  8406. }
  8407. return testDir(splitPath(currentFullPath));
  8408. };
  8409. });
  8410. const {
  8411. stdin
  8412. } = process;
  8413. var getStdin = async () => {
  8414. let result = '';
  8415. if (stdin.isTTY) {
  8416. return result;
  8417. }
  8418. stdin.setEncoding('utf8');
  8419. for await (const chunk of stdin) {
  8420. result += chunk;
  8421. }
  8422. return result;
  8423. };
  8424. var buffer = async () => {
  8425. const result = [];
  8426. let length = 0;
  8427. if (stdin.isTTY) {
  8428. return Buffer.concat([]);
  8429. }
  8430. for await (const chunk of stdin) {
  8431. result.push(chunk);
  8432. length += chunk.length;
  8433. }
  8434. return Buffer.concat(result, length);
  8435. };
  8436. getStdin.buffer = buffer;
  8437. var vendors = [
  8438. {
  8439. name: "AppVeyor",
  8440. constant: "APPVEYOR",
  8441. env: "APPVEYOR",
  8442. pr: "APPVEYOR_PULL_REQUEST_NUMBER"
  8443. },
  8444. {
  8445. name: "Azure Pipelines",
  8446. constant: "AZURE_PIPELINES",
  8447. env: "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
  8448. pr: "SYSTEM_PULLREQUEST_PULLREQUESTID"
  8449. },
  8450. {
  8451. name: "Bamboo",
  8452. constant: "BAMBOO",
  8453. env: "bamboo_planKey"
  8454. },
  8455. {
  8456. name: "Bitbucket Pipelines",
  8457. constant: "BITBUCKET",
  8458. env: "BITBUCKET_COMMIT",
  8459. pr: "BITBUCKET_PR_ID"
  8460. },
  8461. {
  8462. name: "Bitrise",
  8463. constant: "BITRISE",
  8464. env: "BITRISE_IO",
  8465. pr: "BITRISE_PULL_REQUEST"
  8466. },
  8467. {
  8468. name: "Buddy",
  8469. constant: "BUDDY",
  8470. env: "BUDDY_WORKSPACE_ID",
  8471. pr: "BUDDY_EXECUTION_PULL_REQUEST_ID"
  8472. },
  8473. {
  8474. name: "Buildkite",
  8475. constant: "BUILDKITE",
  8476. env: "BUILDKITE",
  8477. pr: {
  8478. env: "BUILDKITE_PULL_REQUEST",
  8479. ne: "false"
  8480. }
  8481. },
  8482. {
  8483. name: "CircleCI",
  8484. constant: "CIRCLE",
  8485. env: "CIRCLECI",
  8486. pr: "CIRCLE_PULL_REQUEST"
  8487. },
  8488. {
  8489. name: "Cirrus CI",
  8490. constant: "CIRRUS",
  8491. env: "CIRRUS_CI",
  8492. pr: "CIRRUS_PR"
  8493. },
  8494. {
  8495. name: "AWS CodeBuild",
  8496. constant: "CODEBUILD",
  8497. env: "CODEBUILD_BUILD_ARN"
  8498. },
  8499. {
  8500. name: "Codeship",
  8501. constant: "CODESHIP",
  8502. env: {
  8503. CI_NAME: "codeship"
  8504. }
  8505. },
  8506. {
  8507. name: "Drone",
  8508. constant: "DRONE",
  8509. env: "DRONE",
  8510. pr: {
  8511. DRONE_BUILD_EVENT: "pull_request"
  8512. }
  8513. },
  8514. {
  8515. name: "dsari",
  8516. constant: "DSARI",
  8517. env: "DSARI"
  8518. },
  8519. {
  8520. name: "GitHub Actions",
  8521. constant: "GITHUB_ACTIONS",
  8522. env: "GITHUB_ACTIONS",
  8523. pr: {
  8524. GITHUB_EVENT_NAME: "pull_request"
  8525. }
  8526. },
  8527. {
  8528. name: "GitLab CI",
  8529. constant: "GITLAB",
  8530. env: "GITLAB_CI"
  8531. },
  8532. {
  8533. name: "GoCD",
  8534. constant: "GOCD",
  8535. env: "GO_PIPELINE_LABEL"
  8536. },
  8537. {
  8538. name: "Hudson",
  8539. constant: "HUDSON",
  8540. env: "HUDSON_URL"
  8541. },
  8542. {
  8543. name: "Jenkins",
  8544. constant: "JENKINS",
  8545. env: [
  8546. "JENKINS_URL",
  8547. "BUILD_ID"
  8548. ],
  8549. pr: {
  8550. any: [
  8551. "ghprbPullId",
  8552. "CHANGE_ID"
  8553. ]
  8554. }
  8555. },
  8556. {
  8557. name: "ZEIT Now",
  8558. constant: "ZEIT_NOW",
  8559. env: "NOW_BUILDER"
  8560. },
  8561. {
  8562. name: "Magnum CI",
  8563. constant: "MAGNUM",
  8564. env: "MAGNUM"
  8565. },
  8566. {
  8567. name: "Netlify CI",
  8568. constant: "NETLIFY",
  8569. env: "NETLIFY",
  8570. pr: {
  8571. env: "PULL_REQUEST",
  8572. ne: "false"
  8573. }
  8574. },
  8575. {
  8576. name: "Nevercode",
  8577. constant: "NEVERCODE",
  8578. env: "NEVERCODE",
  8579. pr: {
  8580. env: "NEVERCODE_PULL_REQUEST",
  8581. ne: "false"
  8582. }
  8583. },
  8584. {
  8585. name: "Render",
  8586. constant: "RENDER",
  8587. env: "RENDER",
  8588. pr: {
  8589. IS_PULL_REQUEST: "true"
  8590. }
  8591. },
  8592. {
  8593. name: "Sail CI",
  8594. constant: "SAIL",
  8595. env: "SAILCI",
  8596. pr: "SAIL_PULL_REQUEST_NUMBER"
  8597. },
  8598. {
  8599. name: "Semaphore",
  8600. constant: "SEMAPHORE",
  8601. env: "SEMAPHORE",
  8602. pr: "PULL_REQUEST_NUMBER"
  8603. },
  8604. {
  8605. name: "Shippable",
  8606. constant: "SHIPPABLE",
  8607. env: "SHIPPABLE",
  8608. pr: {
  8609. IS_PULL_REQUEST: "true"
  8610. }
  8611. },
  8612. {
  8613. name: "Solano CI",
  8614. constant: "SOLANO",
  8615. env: "TDDIUM",
  8616. pr: "TDDIUM_PR_ID"
  8617. },
  8618. {
  8619. name: "Strider CD",
  8620. constant: "STRIDER",
  8621. env: "STRIDER"
  8622. },
  8623. {
  8624. name: "TaskCluster",
  8625. constant: "TASKCLUSTER",
  8626. env: [
  8627. "TASK_ID",
  8628. "RUN_ID"
  8629. ]
  8630. },
  8631. {
  8632. name: "TeamCity",
  8633. constant: "TEAMCITY",
  8634. env: "TEAMCITY_VERSION"
  8635. },
  8636. {
  8637. name: "Travis CI",
  8638. constant: "TRAVIS",
  8639. env: "TRAVIS",
  8640. pr: {
  8641. env: "TRAVIS_PULL_REQUEST",
  8642. ne: "false"
  8643. }
  8644. }
  8645. ];
  8646. var ciInfo = createCommonjsModule(function (module, exports) {
  8647. var env = process.env; // Used for testing only
  8648. Object.defineProperty(exports, '_vendors', {
  8649. value: vendors.map(function (v) {
  8650. return v.constant;
  8651. })
  8652. });
  8653. exports.name = null;
  8654. exports.isPR = null;
  8655. vendors.forEach(function (vendor) {
  8656. var envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env];
  8657. var isCI = envs.every(function (obj) {
  8658. return checkEnv(obj);
  8659. });
  8660. exports[vendor.constant] = isCI;
  8661. if (isCI) {
  8662. exports.name = vendor.name;
  8663. switch (typeof vendor.pr) {
  8664. case 'string':
  8665. // "pr": "CIRRUS_PR"
  8666. exports.isPR = !!env[vendor.pr];
  8667. break;
  8668. case 'object':
  8669. if ('env' in vendor.pr) {
  8670. // "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
  8671. exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne;
  8672. } else if ('any' in vendor.pr) {
  8673. // "pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
  8674. exports.isPR = vendor.pr.any.some(function (key) {
  8675. return !!env[key];
  8676. });
  8677. } else {
  8678. // "pr": { "DRONE_BUILD_EVENT": "pull_request" }
  8679. exports.isPR = checkEnv(vendor.pr);
  8680. }
  8681. break;
  8682. default:
  8683. // PR detection not supported for this vendor
  8684. exports.isPR = null;
  8685. }
  8686. }
  8687. });
  8688. exports.isCI = !!(env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
  8689. env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
  8690. env.BUILD_NUMBER || // Jenkins, TeamCity
  8691. env.RUN_ID || // TaskCluster, dsari
  8692. exports.name || false);
  8693. function checkEnv(obj) {
  8694. if (typeof obj === 'string') return !!env[obj];
  8695. return Object.keys(obj).every(function (k) {
  8696. return env[k] === obj[k];
  8697. });
  8698. }
  8699. });
  8700. var thirdParty = {
  8701. cosmiconfig: dist$2.cosmiconfig,
  8702. cosmiconfigSync: dist$2.cosmiconfigSync,
  8703. findParentDir: findParentDir.sync,
  8704. getStdin: getStdin,
  8705. isCI: () => ciInfo.isCI
  8706. };
  8707. module.exports = thirdParty;