third-party.js 285 KB

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