standalone.js 1.0 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = global || self, global.prettier = factory());
  5. }(this, (function () { 'use strict';
  6. var name = "prettier";
  7. var version = "1.19.1";
  8. var description = "Prettier is an opinionated code formatter";
  9. var bin = {
  10. prettier: "./bin/prettier.js"
  11. };
  12. var repository = "prettier/prettier";
  13. var homepage = "https://prettier.io";
  14. var author = "James Long";
  15. var license = "MIT";
  16. var main = "./index.js";
  17. var engines = {
  18. node: ">=8"
  19. };
  20. var dependencies = {
  21. "@angular/compiler": "8.2.13",
  22. "@babel/code-frame": "7.5.5",
  23. "@babel/parser": "7.7.3",
  24. "@glimmer/syntax": "0.41.0",
  25. "@iarna/toml": "2.2.3",
  26. "@typescript-eslint/typescript-estree": "2.6.1",
  27. "angular-estree-parser": "1.1.5",
  28. "angular-html-parser": "1.3.0",
  29. camelcase: "5.3.1",
  30. chalk: "2.4.2",
  31. "cjk-regex": "2.0.0",
  32. cosmiconfig: "5.2.1",
  33. dashify: "2.0.0",
  34. dedent: "0.7.0",
  35. diff: "4.0.1",
  36. editorconfig: "0.15.3",
  37. "editorconfig-to-prettier": "0.1.1",
  38. "escape-string-regexp": "1.0.5",
  39. esutils: "2.0.3",
  40. "find-parent-dir": "0.3.0",
  41. "find-project-root": "1.1.1",
  42. "flow-parser": "0.111.3",
  43. "get-stream": "4.1.0",
  44. globby: "6.1.0",
  45. graphql: "14.5.8",
  46. "html-element-attributes": "2.2.0",
  47. "html-styles": "1.0.0",
  48. "html-tag-names": "1.1.4",
  49. ignore: "4.0.6",
  50. "is-ci": "2.0.0",
  51. "jest-docblock": "24.9.0",
  52. "json-stable-stringify": "1.0.1",
  53. leven: "3.1.0",
  54. "lines-and-columns": "1.1.6",
  55. "linguist-languages": "7.6.0",
  56. "lodash.uniqby": "4.7.0",
  57. mem: "5.1.1",
  58. minimatch: "3.0.4",
  59. minimist: "1.2.0",
  60. "n-readlines": "1.0.0",
  61. "normalize-path": "3.0.0",
  62. "parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
  63. "postcss-less": "2.0.0",
  64. "postcss-media-query-parser": "0.2.3",
  65. "postcss-scss": "2.0.0",
  66. "postcss-selector-parser": "2.2.3",
  67. "postcss-values-parser": "1.5.0",
  68. "regexp-util": "1.2.2",
  69. "remark-math": "1.0.6",
  70. "remark-parse": "5.0.0",
  71. resolve: "1.12.0",
  72. semver: "6.3.0",
  73. "string-width": "4.1.0",
  74. typescript: "3.7.2",
  75. "unicode-regex": "3.0.0",
  76. unified: "8.4.1",
  77. vnopts: "1.0.2",
  78. "yaml-unist-parser": "1.1.1"
  79. };
  80. var devDependencies = {
  81. "@babel/core": "7.7.2",
  82. "@babel/preset-env": "7.7.1",
  83. "@rollup/plugin-alias": "2.2.0",
  84. "@rollup/plugin-replace": "2.2.1",
  85. "babel-loader": "8.0.6",
  86. benchmark: "2.1.4",
  87. "builtin-modules": "3.1.0",
  88. codecov: "3.6.1",
  89. "cross-env": "6.0.3",
  90. eslint: "6.6.0",
  91. "eslint-config-prettier": "6.5.0",
  92. "eslint-formatter-friendly": "7.0.0",
  93. "eslint-plugin-import": "2.18.2",
  94. "eslint-plugin-prettier": "3.1.1",
  95. "eslint-plugin-react": "7.16.0",
  96. execa: "3.2.0",
  97. jest: "23.3.0",
  98. "jest-junit": "9.0.0",
  99. "jest-snapshot-serializer-ansi": "1.0.0",
  100. "jest-snapshot-serializer-raw": "1.1.0",
  101. "jest-watch-typeahead": "0.4.0",
  102. mkdirp: "0.5.1",
  103. prettier: "1.19.0",
  104. prettylint: "1.0.0",
  105. rimraf: "3.0.0",
  106. rollup: "1.26.3",
  107. "rollup-plugin-babel": "4.3.3",
  108. "rollup-plugin-commonjs": "10.1.0",
  109. "rollup-plugin-json": "4.0.0",
  110. "rollup-plugin-node-globals": "1.4.0",
  111. "rollup-plugin-node-resolve": "5.2.0",
  112. "rollup-plugin-terser": "5.1.2",
  113. shelljs: "0.8.3",
  114. "snapshot-diff": "0.4.0",
  115. "strip-ansi": "5.2.0",
  116. "synchronous-promise": "2.0.10",
  117. tempy: "0.2.1",
  118. "terser-webpack-plugin": "2.2.1",
  119. webpack: "4.41.2"
  120. };
  121. var scripts = {
  122. prepublishOnly: "echo \"Error: must publish from dist/\" && exit 1",
  123. "prepare-release": "yarn && yarn build && yarn test:dist",
  124. test: "jest",
  125. "test:dist": "node ./scripts/test-dist.js",
  126. "test-integration": "jest tests_integration",
  127. "perf-repeat": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  128. "perf-repeat-inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  129. "perf-benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  130. "check-types": "tsc",
  131. lint: "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly",
  132. "lint-docs": "prettylint {.,docs,website,website/blog}/*.md",
  133. "lint-dist": "eslint --no-eslintrc --no-ignore --env=browser \"dist/!(bin-prettier|index|third-party).js\"",
  134. build: "node --max-old-space-size=3072 ./scripts/build/build.js",
  135. "build-docs": "node ./scripts/build-docs.js",
  136. "check-deps": "node ./scripts/check-deps.js",
  137. spellcheck: "npx -p cspell@4.0.31 cspell {bin,scripts,src}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md"
  138. };
  139. var _package = {
  140. name: name,
  141. version: version,
  142. description: description,
  143. bin: bin,
  144. repository: repository,
  145. homepage: homepage,
  146. author: author,
  147. license: license,
  148. main: main,
  149. engines: engines,
  150. dependencies: dependencies,
  151. devDependencies: devDependencies,
  152. scripts: scripts
  153. };
  154. var _package$1 = /*#__PURE__*/Object.freeze({
  155. __proto__: null,
  156. name: name,
  157. version: version,
  158. description: description,
  159. bin: bin,
  160. repository: repository,
  161. homepage: homepage,
  162. author: author,
  163. license: license,
  164. main: main,
  165. engines: engines,
  166. dependencies: dependencies,
  167. devDependencies: devDependencies,
  168. scripts: scripts,
  169. 'default': _package
  170. });
  171. function _typeof(obj) {
  172. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  173. _typeof = function (obj) {
  174. return typeof obj;
  175. };
  176. } else {
  177. _typeof = function (obj) {
  178. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  179. };
  180. }
  181. return _typeof(obj);
  182. }
  183. function _classCallCheck(instance, Constructor) {
  184. if (!(instance instanceof Constructor)) {
  185. throw new TypeError("Cannot call a class as a function");
  186. }
  187. }
  188. function _defineProperties(target, props) {
  189. for (var i = 0; i < props.length; i++) {
  190. var descriptor = props[i];
  191. descriptor.enumerable = descriptor.enumerable || false;
  192. descriptor.configurable = true;
  193. if ("value" in descriptor) descriptor.writable = true;
  194. Object.defineProperty(target, descriptor.key, descriptor);
  195. }
  196. }
  197. function _createClass(Constructor, protoProps, staticProps) {
  198. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  199. if (staticProps) _defineProperties(Constructor, staticProps);
  200. return Constructor;
  201. }
  202. function _defineProperty(obj, key, value) {
  203. if (key in obj) {
  204. Object.defineProperty(obj, key, {
  205. value: value,
  206. enumerable: true,
  207. configurable: true,
  208. writable: true
  209. });
  210. } else {
  211. obj[key] = value;
  212. }
  213. return obj;
  214. }
  215. function _inherits(subClass, superClass) {
  216. if (typeof superClass !== "function" && superClass !== null) {
  217. throw new TypeError("Super expression must either be null or a function");
  218. }
  219. subClass.prototype = Object.create(superClass && superClass.prototype, {
  220. constructor: {
  221. value: subClass,
  222. writable: true,
  223. configurable: true
  224. }
  225. });
  226. if (superClass) _setPrototypeOf(subClass, superClass);
  227. }
  228. function _getPrototypeOf(o) {
  229. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  230. return o.__proto__ || Object.getPrototypeOf(o);
  231. };
  232. return _getPrototypeOf(o);
  233. }
  234. function _setPrototypeOf(o, p) {
  235. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  236. o.__proto__ = p;
  237. return o;
  238. };
  239. return _setPrototypeOf(o, p);
  240. }
  241. function isNativeReflectConstruct() {
  242. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  243. if (Reflect.construct.sham) return false;
  244. if (typeof Proxy === "function") return true;
  245. try {
  246. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  247. return true;
  248. } catch (e) {
  249. return false;
  250. }
  251. }
  252. function _construct(Parent, args, Class) {
  253. if (isNativeReflectConstruct()) {
  254. _construct = Reflect.construct;
  255. } else {
  256. _construct = function _construct(Parent, args, Class) {
  257. var a = [null];
  258. a.push.apply(a, args);
  259. var Constructor = Function.bind.apply(Parent, a);
  260. var instance = new Constructor();
  261. if (Class) _setPrototypeOf(instance, Class.prototype);
  262. return instance;
  263. };
  264. }
  265. return _construct.apply(null, arguments);
  266. }
  267. function _isNativeFunction(fn) {
  268. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  269. }
  270. function _wrapNativeSuper(Class) {
  271. var _cache = typeof Map === "function" ? new Map() : undefined;
  272. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  273. if (Class === null || !_isNativeFunction(Class)) return Class;
  274. if (typeof Class !== "function") {
  275. throw new TypeError("Super expression must either be null or a function");
  276. }
  277. if (typeof _cache !== "undefined") {
  278. if (_cache.has(Class)) return _cache.get(Class);
  279. _cache.set(Class, Wrapper);
  280. }
  281. function Wrapper() {
  282. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  283. }
  284. Wrapper.prototype = Object.create(Class.prototype, {
  285. constructor: {
  286. value: Wrapper,
  287. enumerable: false,
  288. writable: true,
  289. configurable: true
  290. }
  291. });
  292. return _setPrototypeOf(Wrapper, Class);
  293. };
  294. return _wrapNativeSuper(Class);
  295. }
  296. function _assertThisInitialized(self) {
  297. if (self === void 0) {
  298. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  299. }
  300. return self;
  301. }
  302. function _possibleConstructorReturn(self, call) {
  303. if (call && (typeof call === "object" || typeof call === "function")) {
  304. return call;
  305. }
  306. return _assertThisInitialized(self);
  307. }
  308. function _superPropBase(object, property) {
  309. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  310. object = _getPrototypeOf(object);
  311. if (object === null) break;
  312. }
  313. return object;
  314. }
  315. function _get(target, property, receiver) {
  316. if (typeof Reflect !== "undefined" && Reflect.get) {
  317. _get = Reflect.get;
  318. } else {
  319. _get = function _get(target, property, receiver) {
  320. var base = _superPropBase(target, property);
  321. if (!base) return;
  322. var desc = Object.getOwnPropertyDescriptor(base, property);
  323. if (desc.get) {
  324. return desc.get.call(receiver);
  325. }
  326. return desc.value;
  327. };
  328. }
  329. return _get(target, property, receiver || target);
  330. }
  331. function _taggedTemplateLiteral(strings, raw) {
  332. if (!raw) {
  333. raw = strings.slice(0);
  334. }
  335. return Object.freeze(Object.defineProperties(strings, {
  336. raw: {
  337. value: Object.freeze(raw)
  338. }
  339. }));
  340. }
  341. function _slicedToArray(arr, i) {
  342. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  343. }
  344. function _toConsumableArray(arr) {
  345. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  346. }
  347. function _arrayWithoutHoles(arr) {
  348. if (Array.isArray(arr)) {
  349. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  350. return arr2;
  351. }
  352. }
  353. function _arrayWithHoles(arr) {
  354. if (Array.isArray(arr)) return arr;
  355. }
  356. function _iterableToArray(iter) {
  357. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  358. }
  359. function _iterableToArrayLimit(arr, i) {
  360. if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
  361. return;
  362. }
  363. var _arr = [];
  364. var _n = true;
  365. var _d = false;
  366. var _e = undefined;
  367. try {
  368. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  369. _arr.push(_s.value);
  370. if (i && _arr.length === i) break;
  371. }
  372. } catch (err) {
  373. _d = true;
  374. _e = err;
  375. } finally {
  376. try {
  377. if (!_n && _i["return"] != null) _i["return"]();
  378. } finally {
  379. if (_d) throw _e;
  380. }
  381. }
  382. return _arr;
  383. }
  384. function _nonIterableSpread() {
  385. throw new TypeError("Invalid attempt to spread non-iterable instance");
  386. }
  387. function _nonIterableRest() {
  388. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  389. }
  390. function Diff() {}
  391. Diff.prototype = {
  392. diff: function diff(oldString, newString) {
  393. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  394. var callback = options.callback;
  395. if (typeof options === 'function') {
  396. callback = options;
  397. options = {};
  398. }
  399. this.options = options;
  400. var self = this;
  401. function done(value) {
  402. if (callback) {
  403. setTimeout(function () {
  404. callback(undefined, value);
  405. }, 0);
  406. return true;
  407. } else {
  408. return value;
  409. }
  410. } // Allow subclasses to massage the input prior to running
  411. oldString = this.castInput(oldString);
  412. newString = this.castInput(newString);
  413. oldString = this.removeEmpty(this.tokenize(oldString));
  414. newString = this.removeEmpty(this.tokenize(newString));
  415. var newLen = newString.length,
  416. oldLen = oldString.length;
  417. var editLength = 1;
  418. var maxEditLength = newLen + oldLen;
  419. var bestPath = [{
  420. newPos: -1,
  421. components: []
  422. }]; // Seed editLength = 0, i.e. the content starts with the same values
  423. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  424. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  425. // Identity per the equality and tokenizer
  426. return done([{
  427. value: this.join(newString),
  428. count: newString.length
  429. }]);
  430. } // Main worker method. checks all permutations of a given edit length for acceptance.
  431. function execEditLength() {
  432. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  433. var basePath = void 0;
  434. var addPath = bestPath[diagonalPath - 1],
  435. removePath = bestPath[diagonalPath + 1],
  436. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  437. if (addPath) {
  438. // No one else is going to attempt to use this value, clear it
  439. bestPath[diagonalPath - 1] = undefined;
  440. }
  441. var canAdd = addPath && addPath.newPos + 1 < newLen,
  442. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  443. if (!canAdd && !canRemove) {
  444. // If this path is a terminal then prune
  445. bestPath[diagonalPath] = undefined;
  446. continue;
  447. } // Select the diagonal that we want to branch from. We select the prior
  448. // path whose position in the new string is the farthest from the origin
  449. // and does not pass the bounds of the diff graph
  450. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  451. basePath = clonePath(removePath);
  452. self.pushComponent(basePath.components, undefined, true);
  453. } else {
  454. basePath = addPath; // No need to clone, we've pulled it from the list
  455. basePath.newPos++;
  456. self.pushComponent(basePath.components, true, undefined);
  457. }
  458. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  459. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  460. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  461. } else {
  462. // Otherwise track this path as a potential candidate and continue.
  463. bestPath[diagonalPath] = basePath;
  464. }
  465. }
  466. editLength++;
  467. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  468. // sync and async mode which is never fun. Loops over execEditLength until a value
  469. // is produced.
  470. if (callback) {
  471. (function exec() {
  472. setTimeout(function () {
  473. // This should not happen, but we want to be safe.
  474. /* istanbul ignore next */
  475. if (editLength > maxEditLength) {
  476. return callback();
  477. }
  478. if (!execEditLength()) {
  479. exec();
  480. }
  481. }, 0);
  482. })();
  483. } else {
  484. while (editLength <= maxEditLength) {
  485. var ret = execEditLength();
  486. if (ret) {
  487. return ret;
  488. }
  489. }
  490. }
  491. },
  492. pushComponent: function pushComponent(components, added, removed) {
  493. var last = components[components.length - 1];
  494. if (last && last.added === added && last.removed === removed) {
  495. // We need to clone here as the component clone operation is just
  496. // as shallow array clone
  497. components[components.length - 1] = {
  498. count: last.count + 1,
  499. added: added,
  500. removed: removed
  501. };
  502. } else {
  503. components.push({
  504. count: 1,
  505. added: added,
  506. removed: removed
  507. });
  508. }
  509. },
  510. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  511. var newLen = newString.length,
  512. oldLen = oldString.length,
  513. newPos = basePath.newPos,
  514. oldPos = newPos - diagonalPath,
  515. commonCount = 0;
  516. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  517. newPos++;
  518. oldPos++;
  519. commonCount++;
  520. }
  521. if (commonCount) {
  522. basePath.components.push({
  523. count: commonCount
  524. });
  525. }
  526. basePath.newPos = newPos;
  527. return oldPos;
  528. },
  529. equals: function equals(left, right) {
  530. if (this.options.comparator) {
  531. return this.options.comparator(left, right);
  532. } else {
  533. return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
  534. }
  535. },
  536. removeEmpty: function removeEmpty(array) {
  537. var ret = [];
  538. for (var i = 0; i < array.length; i++) {
  539. if (array[i]) {
  540. ret.push(array[i]);
  541. }
  542. }
  543. return ret;
  544. },
  545. castInput: function castInput(value) {
  546. return value;
  547. },
  548. tokenize: function tokenize(value) {
  549. return value.split('');
  550. },
  551. join: function join(chars) {
  552. return chars.join('');
  553. }
  554. };
  555. function buildValues(diff, components, newString, oldString, useLongestToken) {
  556. var componentPos = 0,
  557. componentLen = components.length,
  558. newPos = 0,
  559. oldPos = 0;
  560. for (; componentPos < componentLen; componentPos++) {
  561. var component = components[componentPos];
  562. if (!component.removed) {
  563. if (!component.added && useLongestToken) {
  564. var value = newString.slice(newPos, newPos + component.count);
  565. value = value.map(function (value, i) {
  566. var oldValue = oldString[oldPos + i];
  567. return oldValue.length > value.length ? oldValue : value;
  568. });
  569. component.value = diff.join(value);
  570. } else {
  571. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  572. }
  573. newPos += component.count; // Common case
  574. if (!component.added) {
  575. oldPos += component.count;
  576. }
  577. } else {
  578. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  579. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  580. // The diffing algorithm is tied to add then remove output and this is the simplest
  581. // route to get the desired output with minimal overhead.
  582. if (componentPos && components[componentPos - 1].added) {
  583. var tmp = components[componentPos - 1];
  584. components[componentPos - 1] = components[componentPos];
  585. components[componentPos] = tmp;
  586. }
  587. }
  588. } // Special case handle for when one terminal is ignored (i.e. whitespace).
  589. // For this case we merge the terminal into the prior string and drop the change.
  590. // This is only available for string mode.
  591. var lastComponent = components[componentLen - 1];
  592. if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  593. components[componentLen - 2].value += lastComponent.value;
  594. components.pop();
  595. }
  596. return components;
  597. }
  598. function clonePath(path) {
  599. return {
  600. newPos: path.newPos,
  601. components: path.components.slice(0)
  602. };
  603. }
  604. var characterDiff = new Diff();
  605. function diffChars(oldStr, newStr, options) {
  606. return characterDiff.diff(oldStr, newStr, options);
  607. }
  608. function generateOptions(options, defaults) {
  609. if (typeof options === 'function') {
  610. defaults.callback = options;
  611. } else if (options) {
  612. for (var name in options) {
  613. /* istanbul ignore else */
  614. if (options.hasOwnProperty(name)) {
  615. defaults[name] = options[name];
  616. }
  617. }
  618. }
  619. return defaults;
  620. } //
  621. // Ranges and exceptions:
  622. // Latin-1 Supplement, 0080–00FF
  623. // - U+00D7 × Multiplication sign
  624. // - U+00F7 ÷ Division sign
  625. // Latin Extended-A, 0100–017F
  626. // Latin Extended-B, 0180–024F
  627. // IPA Extensions, 0250–02AF
  628. // Spacing Modifier Letters, 02B0–02FF
  629. // - U+02C7 ˇ &#711; Caron
  630. // - U+02D8 ˘ &#728; Breve
  631. // - U+02D9 ˙ &#729; Dot Above
  632. // - U+02DA ˚ &#730; Ring Above
  633. // - U+02DB ˛ &#731; Ogonek
  634. // - U+02DC ˜ &#732; Small Tilde
  635. // - U+02DD ˝ &#733; Double Acute Accent
  636. // Latin Extended Additional, 1E00–1EFF
  637. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  638. var reWhitespace = /\S/;
  639. var wordDiff = new Diff();
  640. wordDiff.equals = function (left, right) {
  641. if (this.options.ignoreCase) {
  642. left = left.toLowerCase();
  643. right = right.toLowerCase();
  644. }
  645. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  646. };
  647. wordDiff.tokenize = function (value) {
  648. var tokens = value.split(/(\s+|[()[\]{}'"]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
  649. for (var i = 0; i < tokens.length - 1; i++) {
  650. // If we have an empty string in the next field and we have only word chars before and after, merge
  651. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  652. tokens[i] += tokens[i + 2];
  653. tokens.splice(i + 1, 2);
  654. i--;
  655. }
  656. }
  657. return tokens;
  658. };
  659. function diffWords(oldStr, newStr, options) {
  660. options = generateOptions(options, {
  661. ignoreWhitespace: true
  662. });
  663. return wordDiff.diff(oldStr, newStr, options);
  664. }
  665. function diffWordsWithSpace(oldStr, newStr, options) {
  666. return wordDiff.diff(oldStr, newStr, options);
  667. }
  668. var lineDiff = new Diff();
  669. lineDiff.tokenize = function (value) {
  670. var retLines = [],
  671. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  672. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  673. linesAndNewlines.pop();
  674. } // Merge the content and line separators into single tokens
  675. for (var i = 0; i < linesAndNewlines.length; i++) {
  676. var line = linesAndNewlines[i];
  677. if (i % 2 && !this.options.newlineIsToken) {
  678. retLines[retLines.length - 1] += line;
  679. } else {
  680. if (this.options.ignoreWhitespace) {
  681. line = line.trim();
  682. }
  683. retLines.push(line);
  684. }
  685. }
  686. return retLines;
  687. };
  688. function diffLines(oldStr, newStr, callback) {
  689. return lineDiff.diff(oldStr, newStr, callback);
  690. }
  691. function diffTrimmedLines(oldStr, newStr, callback) {
  692. var options = generateOptions(callback, {
  693. ignoreWhitespace: true
  694. });
  695. return lineDiff.diff(oldStr, newStr, options);
  696. }
  697. var sentenceDiff = new Diff();
  698. sentenceDiff.tokenize = function (value) {
  699. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  700. };
  701. function diffSentences(oldStr, newStr, callback) {
  702. return sentenceDiff.diff(oldStr, newStr, callback);
  703. }
  704. var cssDiff = new Diff();
  705. cssDiff.tokenize = function (value) {
  706. return value.split(/([{}:;,]|\s+)/);
  707. };
  708. function diffCss(oldStr, newStr, callback) {
  709. return cssDiff.diff(oldStr, newStr, callback);
  710. }
  711. function _typeof$1(obj) {
  712. if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
  713. _typeof$1 = function _typeof$1(obj) {
  714. return _typeof(obj);
  715. };
  716. } else {
  717. _typeof$1 = function _typeof$1(obj) {
  718. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
  719. };
  720. }
  721. return _typeof$1(obj);
  722. }
  723. function _toConsumableArray$1(arr) {
  724. return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
  725. }
  726. function _arrayWithoutHoles$1(arr) {
  727. if (Array.isArray(arr)) {
  728. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  729. arr2[i] = arr[i];
  730. }
  731. return arr2;
  732. }
  733. }
  734. function _iterableToArray$1(iter) {
  735. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  736. }
  737. function _nonIterableSpread$1() {
  738. throw new TypeError("Invalid attempt to spread non-iterable instance");
  739. }
  740. var objectPrototypeToString = Object.prototype.toString;
  741. var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  742. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  743. jsonDiff.useLongestToken = true;
  744. jsonDiff.tokenize = lineDiff.tokenize;
  745. jsonDiff.castInput = function (value) {
  746. var _this$options = this.options,
  747. undefinedReplacement = _this$options.undefinedReplacement,
  748. _this$options$stringi = _this$options.stringifyReplacer,
  749. stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
  750. return typeof v === 'undefined' ? undefinedReplacement : v;
  751. } : _this$options$stringi;
  752. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
  753. };
  754. jsonDiff.equals = function (left, right) {
  755. return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
  756. };
  757. function diffJson(oldObj, newObj, options) {
  758. return jsonDiff.diff(oldObj, newObj, options);
  759. } // This function handles the presence of circular references by bailing out when encountering an
  760. // object that is already on the "stack" of items being processed. Accepts an optional replacer
  761. function canonicalize(obj, stack, replacementStack, replacer, key) {
  762. stack = stack || [];
  763. replacementStack = replacementStack || [];
  764. if (replacer) {
  765. obj = replacer(key, obj);
  766. }
  767. var i;
  768. for (i = 0; i < stack.length; i += 1) {
  769. if (stack[i] === obj) {
  770. return replacementStack[i];
  771. }
  772. }
  773. var canonicalizedObj;
  774. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  775. stack.push(obj);
  776. canonicalizedObj = new Array(obj.length);
  777. replacementStack.push(canonicalizedObj);
  778. for (i = 0; i < obj.length; i += 1) {
  779. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
  780. }
  781. stack.pop();
  782. replacementStack.pop();
  783. return canonicalizedObj;
  784. }
  785. if (obj && obj.toJSON) {
  786. obj = obj.toJSON();
  787. }
  788. if (_typeof$1(obj) === 'object' && obj !== null) {
  789. stack.push(obj);
  790. canonicalizedObj = {};
  791. replacementStack.push(canonicalizedObj);
  792. var sortedKeys = [],
  793. _key;
  794. for (_key in obj) {
  795. /* istanbul ignore else */
  796. if (obj.hasOwnProperty(_key)) {
  797. sortedKeys.push(_key);
  798. }
  799. }
  800. sortedKeys.sort();
  801. for (i = 0; i < sortedKeys.length; i += 1) {
  802. _key = sortedKeys[i];
  803. canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
  804. }
  805. stack.pop();
  806. replacementStack.pop();
  807. } else {
  808. canonicalizedObj = obj;
  809. }
  810. return canonicalizedObj;
  811. }
  812. var arrayDiff = new Diff();
  813. arrayDiff.tokenize = function (value) {
  814. return value.slice();
  815. };
  816. arrayDiff.join = arrayDiff.removeEmpty = function (value) {
  817. return value;
  818. };
  819. function diffArrays(oldArr, newArr, callback) {
  820. return arrayDiff.diff(oldArr, newArr, callback);
  821. }
  822. function parsePatch(uniDiff) {
  823. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  824. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  825. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  826. list = [],
  827. i = 0;
  828. function parseIndex() {
  829. var index = {};
  830. list.push(index); // Parse diff metadata
  831. while (i < diffstr.length) {
  832. var line = diffstr[i]; // File header found, end parsing diff metadata
  833. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  834. break;
  835. } // Diff index
  836. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  837. if (header) {
  838. index.index = header[1];
  839. }
  840. i++;
  841. } // Parse file headers if they are defined. Unified diff requires them, but
  842. // there's no technical issues to have an isolated hunk without file header
  843. parseFileHeader(index);
  844. parseFileHeader(index); // Parse hunks
  845. index.hunks = [];
  846. while (i < diffstr.length) {
  847. var _line = diffstr[i];
  848. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  849. break;
  850. } else if (/^@@/.test(_line)) {
  851. index.hunks.push(parseHunk());
  852. } else if (_line && options.strict) {
  853. // Ignore unexpected content unless in strict mode
  854. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  855. } else {
  856. i++;
  857. }
  858. }
  859. } // Parses the --- and +++ headers, if none are found, no lines
  860. // are consumed.
  861. function parseFileHeader(index) {
  862. var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
  863. if (fileHeader) {
  864. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  865. var data = fileHeader[2].split('\t', 2);
  866. var fileName = data[0].replace(/\\\\/g, '\\');
  867. if (/^".*"$/.test(fileName)) {
  868. fileName = fileName.substr(1, fileName.length - 2);
  869. }
  870. index[keyPrefix + 'FileName'] = fileName;
  871. index[keyPrefix + 'Header'] = (data[1] || '').trim();
  872. i++;
  873. }
  874. } // Parses a hunk
  875. // This assumes that we are at the start of a hunk.
  876. function parseHunk() {
  877. var chunkHeaderIndex = i,
  878. chunkHeaderLine = diffstr[i++],
  879. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  880. var hunk = {
  881. oldStart: +chunkHeader[1],
  882. oldLines: +chunkHeader[2] || 1,
  883. newStart: +chunkHeader[3],
  884. newLines: +chunkHeader[4] || 1,
  885. lines: [],
  886. linedelimiters: []
  887. };
  888. var addCount = 0,
  889. removeCount = 0;
  890. for (; i < diffstr.length; i++) {
  891. // Lines starting with '---' could be mistaken for the "remove line" operation
  892. // But they could be the header for the next file. Therefore prune such cases out.
  893. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  894. break;
  895. }
  896. var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
  897. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  898. hunk.lines.push(diffstr[i]);
  899. hunk.linedelimiters.push(delimiters[i] || '\n');
  900. if (operation === '+') {
  901. addCount++;
  902. } else if (operation === '-') {
  903. removeCount++;
  904. } else if (operation === ' ') {
  905. addCount++;
  906. removeCount++;
  907. }
  908. } else {
  909. break;
  910. }
  911. } // Handle the empty block count case
  912. if (!addCount && hunk.newLines === 1) {
  913. hunk.newLines = 0;
  914. }
  915. if (!removeCount && hunk.oldLines === 1) {
  916. hunk.oldLines = 0;
  917. } // Perform optional sanity checking
  918. if (options.strict) {
  919. if (addCount !== hunk.newLines) {
  920. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  921. }
  922. if (removeCount !== hunk.oldLines) {
  923. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  924. }
  925. }
  926. return hunk;
  927. }
  928. while (i < diffstr.length) {
  929. parseIndex();
  930. }
  931. return list;
  932. } // Iterator that traverses in the range of [min, max], stepping
  933. // by distance from a given start position. I.e. for [0, 4], with
  934. // start of 2, this will iterate 2, 3, 1, 4, 0.
  935. function distanceIterator(start, minLine, maxLine) {
  936. var wantForward = true,
  937. backwardExhausted = false,
  938. forwardExhausted = false,
  939. localOffset = 1;
  940. return function iterator() {
  941. if (wantForward && !forwardExhausted) {
  942. if (backwardExhausted) {
  943. localOffset++;
  944. } else {
  945. wantForward = false;
  946. } // Check if trying to fit beyond text length, and if not, check it fits
  947. // after offset location (or desired location on first iteration)
  948. if (start + localOffset <= maxLine) {
  949. return localOffset;
  950. }
  951. forwardExhausted = true;
  952. }
  953. if (!backwardExhausted) {
  954. if (!forwardExhausted) {
  955. wantForward = true;
  956. } // Check if trying to fit before text beginning, and if not, check it fits
  957. // before offset location
  958. if (minLine <= start - localOffset) {
  959. return -localOffset++;
  960. }
  961. backwardExhausted = true;
  962. return iterator();
  963. } // We tried to fit hunk before text beginning and beyond text length, then
  964. // hunk can't fit on the text. Return undefined
  965. };
  966. }
  967. function applyPatch(source, uniDiff) {
  968. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  969. if (typeof uniDiff === 'string') {
  970. uniDiff = parsePatch(uniDiff);
  971. }
  972. if (Array.isArray(uniDiff)) {
  973. if (uniDiff.length > 1) {
  974. throw new Error('applyPatch only works with a single input.');
  975. }
  976. uniDiff = uniDiff[0];
  977. } // Apply the diff to the input
  978. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  979. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  980. hunks = uniDiff.hunks,
  981. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
  982. return line === patchContent;
  983. },
  984. errorCount = 0,
  985. fuzzFactor = options.fuzzFactor || 0,
  986. minLine = 0,
  987. offset = 0,
  988. removeEOFNL,
  989. addEOFNL;
  990. /**
  991. * Checks if the hunk exactly fits on the provided location
  992. */
  993. function hunkFits(hunk, toPos) {
  994. for (var j = 0; j < hunk.lines.length; j++) {
  995. var line = hunk.lines[j],
  996. operation = line.length > 0 ? line[0] : ' ',
  997. content = line.length > 0 ? line.substr(1) : line;
  998. if (operation === ' ' || operation === '-') {
  999. // Context sanity check
  1000. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  1001. errorCount++;
  1002. if (errorCount > fuzzFactor) {
  1003. return false;
  1004. }
  1005. }
  1006. toPos++;
  1007. }
  1008. }
  1009. return true;
  1010. } // Search best fit offsets for each hunk based on the previous ones
  1011. for (var i = 0; i < hunks.length; i++) {
  1012. var hunk = hunks[i],
  1013. maxLine = lines.length - hunk.oldLines,
  1014. localOffset = 0,
  1015. toPos = offset + hunk.oldStart - 1;
  1016. var iterator = distanceIterator(toPos, minLine, maxLine);
  1017. for (; localOffset !== undefined; localOffset = iterator()) {
  1018. if (hunkFits(hunk, toPos + localOffset)) {
  1019. hunk.offset = offset += localOffset;
  1020. break;
  1021. }
  1022. }
  1023. if (localOffset === undefined) {
  1024. return false;
  1025. } // Set lower text limit to end of the current hunk, so next ones don't try
  1026. // to fit over already patched text
  1027. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  1028. } // Apply patch hunks
  1029. var diffOffset = 0;
  1030. for (var _i = 0; _i < hunks.length; _i++) {
  1031. var _hunk = hunks[_i],
  1032. _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
  1033. diffOffset += _hunk.newLines - _hunk.oldLines;
  1034. if (_toPos < 0) {
  1035. // Creating a new file
  1036. _toPos = 0;
  1037. }
  1038. for (var j = 0; j < _hunk.lines.length; j++) {
  1039. var line = _hunk.lines[j],
  1040. operation = line.length > 0 ? line[0] : ' ',
  1041. content = line.length > 0 ? line.substr(1) : line,
  1042. delimiter = _hunk.linedelimiters[j];
  1043. if (operation === ' ') {
  1044. _toPos++;
  1045. } else if (operation === '-') {
  1046. lines.splice(_toPos, 1);
  1047. delimiters.splice(_toPos, 1);
  1048. /* istanbul ignore else */
  1049. } else if (operation === '+') {
  1050. lines.splice(_toPos, 0, content);
  1051. delimiters.splice(_toPos, 0, delimiter);
  1052. _toPos++;
  1053. } else if (operation === '\\') {
  1054. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  1055. if (previousOperation === '+') {
  1056. removeEOFNL = true;
  1057. } else if (previousOperation === '-') {
  1058. addEOFNL = true;
  1059. }
  1060. }
  1061. }
  1062. } // Handle EOFNL insertion/removal
  1063. if (removeEOFNL) {
  1064. while (!lines[lines.length - 1]) {
  1065. lines.pop();
  1066. delimiters.pop();
  1067. }
  1068. } else if (addEOFNL) {
  1069. lines.push('');
  1070. delimiters.push('\n');
  1071. }
  1072. for (var _k = 0; _k < lines.length - 1; _k++) {
  1073. lines[_k] = lines[_k] + delimiters[_k];
  1074. }
  1075. return lines.join('');
  1076. } // Wrapper that supports multiple file patches via callbacks.
  1077. function applyPatches(uniDiff, options) {
  1078. if (typeof uniDiff === 'string') {
  1079. uniDiff = parsePatch(uniDiff);
  1080. }
  1081. var currentIndex = 0;
  1082. function processIndex() {
  1083. var index = uniDiff[currentIndex++];
  1084. if (!index) {
  1085. return options.complete();
  1086. }
  1087. options.loadFile(index, function (err, data) {
  1088. if (err) {
  1089. return options.complete(err);
  1090. }
  1091. var updatedContent = applyPatch(data, index, options);
  1092. options.patched(index, updatedContent, function (err) {
  1093. if (err) {
  1094. return options.complete(err);
  1095. }
  1096. processIndex();
  1097. });
  1098. });
  1099. }
  1100. processIndex();
  1101. }
  1102. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1103. if (!options) {
  1104. options = {};
  1105. }
  1106. if (typeof options.context === 'undefined') {
  1107. options.context = 4;
  1108. }
  1109. var diff = diffLines(oldStr, newStr, options);
  1110. diff.push({
  1111. value: '',
  1112. lines: []
  1113. }); // Append an empty value to make cleanup easier
  1114. function contextLines(lines) {
  1115. return lines.map(function (entry) {
  1116. return ' ' + entry;
  1117. });
  1118. }
  1119. var hunks = [];
  1120. var oldRangeStart = 0,
  1121. newRangeStart = 0,
  1122. curRange = [],
  1123. oldLine = 1,
  1124. newLine = 1;
  1125. var _loop = function _loop(i) {
  1126. var current = diff[i],
  1127. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  1128. current.lines = lines;
  1129. if (current.added || current.removed) {
  1130. var _curRange; // If we have previous context, start with that
  1131. if (!oldRangeStart) {
  1132. var prev = diff[i - 1];
  1133. oldRangeStart = oldLine;
  1134. newRangeStart = newLine;
  1135. if (prev) {
  1136. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  1137. oldRangeStart -= curRange.length;
  1138. newRangeStart -= curRange.length;
  1139. }
  1140. } // Output our changes
  1141. (_curRange = curRange).push.apply(_curRange, _toConsumableArray$1(lines.map(function (entry) {
  1142. return (current.added ? '+' : '-') + entry;
  1143. }))); // Track the updated file position
  1144. if (current.added) {
  1145. newLine += lines.length;
  1146. } else {
  1147. oldLine += lines.length;
  1148. }
  1149. } else {
  1150. // Identical context lines. Track line changes
  1151. if (oldRangeStart) {
  1152. // Close out any changes that have been output (or join overlapping)
  1153. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  1154. var _curRange2; // Overlapping
  1155. (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray$1(contextLines(lines)));
  1156. } else {
  1157. var _curRange3; // end the range and output
  1158. var contextSize = Math.min(lines.length, options.context);
  1159. (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray$1(contextLines(lines.slice(0, contextSize))));
  1160. var hunk = {
  1161. oldStart: oldRangeStart,
  1162. oldLines: oldLine - oldRangeStart + contextSize,
  1163. newStart: newRangeStart,
  1164. newLines: newLine - newRangeStart + contextSize,
  1165. lines: curRange
  1166. };
  1167. if (i >= diff.length - 2 && lines.length <= options.context) {
  1168. // EOF is inside this hunk
  1169. var oldEOFNewline = /\n$/.test(oldStr);
  1170. var newEOFNewline = /\n$/.test(newStr);
  1171. var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
  1172. if (!oldEOFNewline && noNlBeforeAdds) {
  1173. // special case: old has no eol and no trailing context; no-nl can end up before adds
  1174. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  1175. }
  1176. if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
  1177. curRange.push('\\ No newline at end of file');
  1178. }
  1179. }
  1180. hunks.push(hunk);
  1181. oldRangeStart = 0;
  1182. newRangeStart = 0;
  1183. curRange = [];
  1184. }
  1185. }
  1186. oldLine += lines.length;
  1187. newLine += lines.length;
  1188. }
  1189. };
  1190. for (var i = 0; i < diff.length; i++) {
  1191. _loop(i);
  1192. }
  1193. return {
  1194. oldFileName: oldFileName,
  1195. newFileName: newFileName,
  1196. oldHeader: oldHeader,
  1197. newHeader: newHeader,
  1198. hunks: hunks
  1199. };
  1200. }
  1201. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1202. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  1203. var ret = [];
  1204. if (oldFileName == newFileName) {
  1205. ret.push('Index: ' + oldFileName);
  1206. }
  1207. ret.push('===================================================================');
  1208. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  1209. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  1210. for (var i = 0; i < diff.hunks.length; i++) {
  1211. var hunk = diff.hunks[i];
  1212. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  1213. ret.push.apply(ret, hunk.lines);
  1214. }
  1215. return ret.join('\n') + '\n';
  1216. }
  1217. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  1218. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  1219. }
  1220. function arrayEqual(a, b) {
  1221. if (a.length !== b.length) {
  1222. return false;
  1223. }
  1224. return arrayStartsWith(a, b);
  1225. }
  1226. function arrayStartsWith(array, start) {
  1227. if (start.length > array.length) {
  1228. return false;
  1229. }
  1230. for (var i = 0; i < start.length; i++) {
  1231. if (start[i] !== array[i]) {
  1232. return false;
  1233. }
  1234. }
  1235. return true;
  1236. }
  1237. function calcLineCount(hunk) {
  1238. var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
  1239. oldLines = _calcOldNewLineCount.oldLines,
  1240. newLines = _calcOldNewLineCount.newLines;
  1241. if (oldLines !== undefined) {
  1242. hunk.oldLines = oldLines;
  1243. } else {
  1244. delete hunk.oldLines;
  1245. }
  1246. if (newLines !== undefined) {
  1247. hunk.newLines = newLines;
  1248. } else {
  1249. delete hunk.newLines;
  1250. }
  1251. }
  1252. function merge(mine, theirs, base) {
  1253. mine = loadPatch(mine, base);
  1254. theirs = loadPatch(theirs, base);
  1255. var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
  1256. // Leaving sanity checks on this to the API consumer that may know more about the
  1257. // meaning in their own context.
  1258. if (mine.index || theirs.index) {
  1259. ret.index = mine.index || theirs.index;
  1260. }
  1261. if (mine.newFileName || theirs.newFileName) {
  1262. if (!fileNameChanged(mine)) {
  1263. // No header or no change in ours, use theirs (and ours if theirs does not exist)
  1264. ret.oldFileName = theirs.oldFileName || mine.oldFileName;
  1265. ret.newFileName = theirs.newFileName || mine.newFileName;
  1266. ret.oldHeader = theirs.oldHeader || mine.oldHeader;
  1267. ret.newHeader = theirs.newHeader || mine.newHeader;
  1268. } else if (!fileNameChanged(theirs)) {
  1269. // No header or no change in theirs, use ours
  1270. ret.oldFileName = mine.oldFileName;
  1271. ret.newFileName = mine.newFileName;
  1272. ret.oldHeader = mine.oldHeader;
  1273. ret.newHeader = mine.newHeader;
  1274. } else {
  1275. // Both changed... figure it out
  1276. ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
  1277. ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
  1278. ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
  1279. ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
  1280. }
  1281. }
  1282. ret.hunks = [];
  1283. var mineIndex = 0,
  1284. theirsIndex = 0,
  1285. mineOffset = 0,
  1286. theirsOffset = 0;
  1287. while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
  1288. var mineCurrent = mine.hunks[mineIndex] || {
  1289. oldStart: Infinity
  1290. },
  1291. theirsCurrent = theirs.hunks[theirsIndex] || {
  1292. oldStart: Infinity
  1293. };
  1294. if (hunkBefore(mineCurrent, theirsCurrent)) {
  1295. // This patch does not overlap with any of the others, yay.
  1296. ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
  1297. mineIndex++;
  1298. theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
  1299. } else if (hunkBefore(theirsCurrent, mineCurrent)) {
  1300. // This patch does not overlap with any of the others, yay.
  1301. ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
  1302. theirsIndex++;
  1303. mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
  1304. } else {
  1305. // Overlap, merge as best we can
  1306. var mergedHunk = {
  1307. oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
  1308. oldLines: 0,
  1309. newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
  1310. newLines: 0,
  1311. lines: []
  1312. };
  1313. mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
  1314. theirsIndex++;
  1315. mineIndex++;
  1316. ret.hunks.push(mergedHunk);
  1317. }
  1318. }
  1319. return ret;
  1320. }
  1321. function loadPatch(param, base) {
  1322. if (typeof param === 'string') {
  1323. if (/^@@/m.test(param) || /^Index:/m.test(param)) {
  1324. return parsePatch(param)[0];
  1325. }
  1326. if (!base) {
  1327. throw new Error('Must provide a base reference or pass in a patch');
  1328. }
  1329. return structuredPatch(undefined, undefined, base, param);
  1330. }
  1331. return param;
  1332. }
  1333. function fileNameChanged(patch) {
  1334. return patch.newFileName && patch.newFileName !== patch.oldFileName;
  1335. }
  1336. function selectField(index, mine, theirs) {
  1337. if (mine === theirs) {
  1338. return mine;
  1339. } else {
  1340. index.conflict = true;
  1341. return {
  1342. mine: mine,
  1343. theirs: theirs
  1344. };
  1345. }
  1346. }
  1347. function hunkBefore(test, check) {
  1348. return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
  1349. }
  1350. function cloneHunk(hunk, offset) {
  1351. return {
  1352. oldStart: hunk.oldStart,
  1353. oldLines: hunk.oldLines,
  1354. newStart: hunk.newStart + offset,
  1355. newLines: hunk.newLines,
  1356. lines: hunk.lines
  1357. };
  1358. }
  1359. function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
  1360. // This will generally result in a conflicted hunk, but there are cases where the context
  1361. // is the only overlap where we can successfully merge the content here.
  1362. var mine = {
  1363. offset: mineOffset,
  1364. lines: mineLines,
  1365. index: 0
  1366. },
  1367. their = {
  1368. offset: theirOffset,
  1369. lines: theirLines,
  1370. index: 0
  1371. }; // Handle any leading content
  1372. insertLeading(hunk, mine, their);
  1373. insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
  1374. while (mine.index < mine.lines.length && their.index < their.lines.length) {
  1375. var mineCurrent = mine.lines[mine.index],
  1376. theirCurrent = their.lines[their.index];
  1377. if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
  1378. // Both modified ...
  1379. mutualChange(hunk, mine, their);
  1380. } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
  1381. var _hunk$lines; // Mine inserted
  1382. (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray$1(collectChange(mine)));
  1383. } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
  1384. var _hunk$lines2; // Theirs inserted
  1385. (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray$1(collectChange(their)));
  1386. } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
  1387. // Mine removed or edited
  1388. removal(hunk, mine, their);
  1389. } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
  1390. // Their removed or edited
  1391. removal(hunk, their, mine, true);
  1392. } else if (mineCurrent === theirCurrent) {
  1393. // Context identity
  1394. hunk.lines.push(mineCurrent);
  1395. mine.index++;
  1396. their.index++;
  1397. } else {
  1398. // Context mismatch
  1399. conflict(hunk, collectChange(mine), collectChange(their));
  1400. }
  1401. } // Now push anything that may be remaining
  1402. insertTrailing(hunk, mine);
  1403. insertTrailing(hunk, their);
  1404. calcLineCount(hunk);
  1405. }
  1406. function mutualChange(hunk, mine, their) {
  1407. var myChanges = collectChange(mine),
  1408. theirChanges = collectChange(their);
  1409. if (allRemoves(myChanges) && allRemoves(theirChanges)) {
  1410. // Special case for remove changes that are supersets of one another
  1411. if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
  1412. var _hunk$lines3;
  1413. (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray$1(myChanges));
  1414. return;
  1415. } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
  1416. var _hunk$lines4;
  1417. (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray$1(theirChanges));
  1418. return;
  1419. }
  1420. } else if (arrayEqual(myChanges, theirChanges)) {
  1421. var _hunk$lines5;
  1422. (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray$1(myChanges));
  1423. return;
  1424. }
  1425. conflict(hunk, myChanges, theirChanges);
  1426. }
  1427. function removal(hunk, mine, their, swap) {
  1428. var myChanges = collectChange(mine),
  1429. theirChanges = collectContext(their, myChanges);
  1430. if (theirChanges.merged) {
  1431. var _hunk$lines6;
  1432. (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray$1(theirChanges.merged));
  1433. } else {
  1434. conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
  1435. }
  1436. }
  1437. function conflict(hunk, mine, their) {
  1438. hunk.conflict = true;
  1439. hunk.lines.push({
  1440. conflict: true,
  1441. mine: mine,
  1442. theirs: their
  1443. });
  1444. }
  1445. function insertLeading(hunk, insert, their) {
  1446. while (insert.offset < their.offset && insert.index < insert.lines.length) {
  1447. var line = insert.lines[insert.index++];
  1448. hunk.lines.push(line);
  1449. insert.offset++;
  1450. }
  1451. }
  1452. function insertTrailing(hunk, insert) {
  1453. while (insert.index < insert.lines.length) {
  1454. var line = insert.lines[insert.index++];
  1455. hunk.lines.push(line);
  1456. }
  1457. }
  1458. function collectChange(state) {
  1459. var ret = [],
  1460. operation = state.lines[state.index][0];
  1461. while (state.index < state.lines.length) {
  1462. var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
  1463. if (operation === '-' && line[0] === '+') {
  1464. operation = '+';
  1465. }
  1466. if (operation === line[0]) {
  1467. ret.push(line);
  1468. state.index++;
  1469. } else {
  1470. break;
  1471. }
  1472. }
  1473. return ret;
  1474. }
  1475. function collectContext(state, matchChanges) {
  1476. var changes = [],
  1477. merged = [],
  1478. matchIndex = 0,
  1479. contextChanges = false,
  1480. conflicted = false;
  1481. while (matchIndex < matchChanges.length && state.index < state.lines.length) {
  1482. var change = state.lines[state.index],
  1483. match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
  1484. if (match[0] === '+') {
  1485. break;
  1486. }
  1487. contextChanges = contextChanges || change[0] !== ' ';
  1488. merged.push(match);
  1489. matchIndex++; // Consume any additions in the other block as a conflict to attempt
  1490. // to pull in the remaining context after this
  1491. if (change[0] === '+') {
  1492. conflicted = true;
  1493. while (change[0] === '+') {
  1494. changes.push(change);
  1495. change = state.lines[++state.index];
  1496. }
  1497. }
  1498. if (match.substr(1) === change.substr(1)) {
  1499. changes.push(change);
  1500. state.index++;
  1501. } else {
  1502. conflicted = true;
  1503. }
  1504. }
  1505. if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
  1506. conflicted = true;
  1507. }
  1508. if (conflicted) {
  1509. return changes;
  1510. }
  1511. while (matchIndex < matchChanges.length) {
  1512. merged.push(matchChanges[matchIndex++]);
  1513. }
  1514. return {
  1515. merged: merged,
  1516. changes: changes
  1517. };
  1518. }
  1519. function allRemoves(changes) {
  1520. return changes.reduce(function (prev, change) {
  1521. return prev && change[0] === '-';
  1522. }, true);
  1523. }
  1524. function skipRemoveSuperset(state, removeChanges, delta) {
  1525. for (var i = 0; i < delta; i++) {
  1526. var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
  1527. if (state.lines[state.index + i] !== ' ' + changeContent) {
  1528. return false;
  1529. }
  1530. }
  1531. state.index += delta;
  1532. return true;
  1533. }
  1534. function calcOldNewLineCount(lines) {
  1535. var oldLines = 0;
  1536. var newLines = 0;
  1537. lines.forEach(function (line) {
  1538. if (typeof line !== 'string') {
  1539. var myCount = calcOldNewLineCount(line.mine);
  1540. var theirCount = calcOldNewLineCount(line.theirs);
  1541. if (oldLines !== undefined) {
  1542. if (myCount.oldLines === theirCount.oldLines) {
  1543. oldLines += myCount.oldLines;
  1544. } else {
  1545. oldLines = undefined;
  1546. }
  1547. }
  1548. if (newLines !== undefined) {
  1549. if (myCount.newLines === theirCount.newLines) {
  1550. newLines += myCount.newLines;
  1551. } else {
  1552. newLines = undefined;
  1553. }
  1554. }
  1555. } else {
  1556. if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
  1557. newLines++;
  1558. }
  1559. if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
  1560. oldLines++;
  1561. }
  1562. }
  1563. });
  1564. return {
  1565. oldLines: oldLines,
  1566. newLines: newLines
  1567. };
  1568. } // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  1569. function convertChangesToDMP(changes) {
  1570. var ret = [],
  1571. change,
  1572. operation;
  1573. for (var i = 0; i < changes.length; i++) {
  1574. change = changes[i];
  1575. if (change.added) {
  1576. operation = 1;
  1577. } else if (change.removed) {
  1578. operation = -1;
  1579. } else {
  1580. operation = 0;
  1581. }
  1582. ret.push([operation, change.value]);
  1583. }
  1584. return ret;
  1585. }
  1586. function convertChangesToXML(changes) {
  1587. var ret = [];
  1588. for (var i = 0; i < changes.length; i++) {
  1589. var change = changes[i];
  1590. if (change.added) {
  1591. ret.push('<ins>');
  1592. } else if (change.removed) {
  1593. ret.push('<del>');
  1594. }
  1595. ret.push(escapeHTML(change.value));
  1596. if (change.added) {
  1597. ret.push('</ins>');
  1598. } else if (change.removed) {
  1599. ret.push('</del>');
  1600. }
  1601. }
  1602. return ret.join('');
  1603. }
  1604. function escapeHTML(s) {
  1605. var n = s;
  1606. n = n.replace(/&/g, '&amp;');
  1607. n = n.replace(/</g, '&lt;');
  1608. n = n.replace(/>/g, '&gt;');
  1609. n = n.replace(/"/g, '&quot;');
  1610. return n;
  1611. }
  1612. var index_es6 = /*#__PURE__*/Object.freeze({
  1613. __proto__: null,
  1614. Diff: Diff,
  1615. diffChars: diffChars,
  1616. diffWords: diffWords,
  1617. diffWordsWithSpace: diffWordsWithSpace,
  1618. diffLines: diffLines,
  1619. diffTrimmedLines: diffTrimmedLines,
  1620. diffSentences: diffSentences,
  1621. diffCss: diffCss,
  1622. diffJson: diffJson,
  1623. diffArrays: diffArrays,
  1624. structuredPatch: structuredPatch,
  1625. createTwoFilesPatch: createTwoFilesPatch,
  1626. createPatch: createPatch,
  1627. applyPatch: applyPatch,
  1628. applyPatches: applyPatches,
  1629. parsePatch: parsePatch,
  1630. merge: merge,
  1631. convertChangesToDMP: convertChangesToDMP,
  1632. convertChangesToXML: convertChangesToXML,
  1633. canonicalize: canonicalize
  1634. });
  1635. var _shim_fs = {};
  1636. var _shim_fs$1 = /*#__PURE__*/Object.freeze({
  1637. __proto__: null,
  1638. 'default': _shim_fs
  1639. });
  1640. /*!
  1641. * normalize-path <https://github.com/jonschlinkert/normalize-path>
  1642. *
  1643. * Copyright (c) 2014-2018, Jon Schlinkert.
  1644. * Released under the MIT License.
  1645. */
  1646. var normalizePath = function normalizePath(path, stripTrailing) {
  1647. if (typeof path !== 'string') {
  1648. throw new TypeError('expected path to be a string');
  1649. }
  1650. if (path === '\\' || path === '/') return '/';
  1651. var len = path.length;
  1652. if (len <= 1) return path; // ensure that win32 namespaces has two leading slashes, so that the path is
  1653. // handled properly by the win32 version of path.parse() after being normalized
  1654. // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
  1655. var prefix = '';
  1656. if (len > 4 && path[3] === '\\') {
  1657. var ch = path[2];
  1658. if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
  1659. path = path.slice(2);
  1660. prefix = '//';
  1661. }
  1662. }
  1663. var segs = path.split(/[/\\]+/);
  1664. if (stripTrailing !== false && segs[segs.length - 1] === '') {
  1665. segs.pop();
  1666. }
  1667. return prefix + segs.join('/');
  1668. };
  1669. var global$1 = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};
  1670. var lookup = [];
  1671. var revLookup = [];
  1672. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  1673. var inited = false;
  1674. function init() {
  1675. inited = true;
  1676. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  1677. for (var i = 0, len = code.length; i < len; ++i) {
  1678. lookup[i] = code[i];
  1679. revLookup[code.charCodeAt(i)] = i;
  1680. }
  1681. revLookup['-'.charCodeAt(0)] = 62;
  1682. revLookup['_'.charCodeAt(0)] = 63;
  1683. }
  1684. function toByteArray(b64) {
  1685. if (!inited) {
  1686. init();
  1687. }
  1688. var i, j, l, tmp, placeHolders, arr;
  1689. var len = b64.length;
  1690. if (len % 4 > 0) {
  1691. throw new Error('Invalid string. Length must be a multiple of 4');
  1692. } // the number of equal signs (place holders)
  1693. // if there are two placeholders, than the two characters before it
  1694. // represent one byte
  1695. // if there is only one, then the three characters before it represent 2 bytes
  1696. // this is just a cheap hack to not do indexOf twice
  1697. placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0; // base64 is 4/3 + up to two characters of the original data
  1698. arr = new Arr(len * 3 / 4 - placeHolders); // if there are placeholders, only get up to the last complete 4 chars
  1699. l = placeHolders > 0 ? len - 4 : len;
  1700. var L = 0;
  1701. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  1702. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  1703. arr[L++] = tmp >> 16 & 0xFF;
  1704. arr[L++] = tmp >> 8 & 0xFF;
  1705. arr[L++] = tmp & 0xFF;
  1706. }
  1707. if (placeHolders === 2) {
  1708. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  1709. arr[L++] = tmp & 0xFF;
  1710. } else if (placeHolders === 1) {
  1711. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  1712. arr[L++] = tmp >> 8 & 0xFF;
  1713. arr[L++] = tmp & 0xFF;
  1714. }
  1715. return arr;
  1716. }
  1717. function tripletToBase64(num) {
  1718. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  1719. }
  1720. function encodeChunk(uint8, start, end) {
  1721. var tmp;
  1722. var output = [];
  1723. for (var i = start; i < end; i += 3) {
  1724. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2];
  1725. output.push(tripletToBase64(tmp));
  1726. }
  1727. return output.join('');
  1728. }
  1729. function fromByteArray(uint8) {
  1730. if (!inited) {
  1731. init();
  1732. }
  1733. var tmp;
  1734. var len = uint8.length;
  1735. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  1736. var output = '';
  1737. var parts = [];
  1738. var maxChunkLength = 16383; // must be multiple of 3
  1739. // go through the array every three bytes, we'll deal with trailing stuff later
  1740. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  1741. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  1742. } // pad the end with zeros, but make sure to not forget the extra bytes
  1743. if (extraBytes === 1) {
  1744. tmp = uint8[len - 1];
  1745. output += lookup[tmp >> 2];
  1746. output += lookup[tmp << 4 & 0x3F];
  1747. output += '==';
  1748. } else if (extraBytes === 2) {
  1749. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  1750. output += lookup[tmp >> 10];
  1751. output += lookup[tmp >> 4 & 0x3F];
  1752. output += lookup[tmp << 2 & 0x3F];
  1753. output += '=';
  1754. }
  1755. parts.push(output);
  1756. return parts.join('');
  1757. }
  1758. function read(buffer, offset, isLE, mLen, nBytes) {
  1759. var e, m;
  1760. var eLen = nBytes * 8 - mLen - 1;
  1761. var eMax = (1 << eLen) - 1;
  1762. var eBias = eMax >> 1;
  1763. var nBits = -7;
  1764. var i = isLE ? nBytes - 1 : 0;
  1765. var d = isLE ? -1 : 1;
  1766. var s = buffer[offset + i];
  1767. i += d;
  1768. e = s & (1 << -nBits) - 1;
  1769. s >>= -nBits;
  1770. nBits += eLen;
  1771. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  1772. m = e & (1 << -nBits) - 1;
  1773. e >>= -nBits;
  1774. nBits += mLen;
  1775. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  1776. if (e === 0) {
  1777. e = 1 - eBias;
  1778. } else if (e === eMax) {
  1779. return m ? NaN : (s ? -1 : 1) * Infinity;
  1780. } else {
  1781. m = m + Math.pow(2, mLen);
  1782. e = e - eBias;
  1783. }
  1784. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  1785. }
  1786. function write(buffer, value, offset, isLE, mLen, nBytes) {
  1787. var e, m, c;
  1788. var eLen = nBytes * 8 - mLen - 1;
  1789. var eMax = (1 << eLen) - 1;
  1790. var eBias = eMax >> 1;
  1791. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  1792. var i = isLE ? 0 : nBytes - 1;
  1793. var d = isLE ? 1 : -1;
  1794. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  1795. value = Math.abs(value);
  1796. if (isNaN(value) || value === Infinity) {
  1797. m = isNaN(value) ? 1 : 0;
  1798. e = eMax;
  1799. } else {
  1800. e = Math.floor(Math.log(value) / Math.LN2);
  1801. if (value * (c = Math.pow(2, -e)) < 1) {
  1802. e--;
  1803. c *= 2;
  1804. }
  1805. if (e + eBias >= 1) {
  1806. value += rt / c;
  1807. } else {
  1808. value += rt * Math.pow(2, 1 - eBias);
  1809. }
  1810. if (value * c >= 2) {
  1811. e++;
  1812. c /= 2;
  1813. }
  1814. if (e + eBias >= eMax) {
  1815. m = 0;
  1816. e = eMax;
  1817. } else if (e + eBias >= 1) {
  1818. m = (value * c - 1) * Math.pow(2, mLen);
  1819. e = e + eBias;
  1820. } else {
  1821. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  1822. e = 0;
  1823. }
  1824. }
  1825. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  1826. e = e << mLen | m;
  1827. eLen += mLen;
  1828. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  1829. buffer[offset + i - d] |= s * 128;
  1830. }
  1831. var toString = {}.toString;
  1832. var isArray = Array.isArray || function (arr) {
  1833. return toString.call(arr) == '[object Array]';
  1834. };
  1835. var INSPECT_MAX_BYTES = 50;
  1836. /**
  1837. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  1838. * === true Use Uint8Array implementation (fastest)
  1839. * === false Use Object implementation (most compatible, even IE6)
  1840. *
  1841. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  1842. * Opera 11.6+, iOS 4.2+.
  1843. *
  1844. * Due to various browser bugs, sometimes the Object implementation will be used even
  1845. * when the browser supports typed arrays.
  1846. *
  1847. * Note:
  1848. *
  1849. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  1850. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  1851. *
  1852. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  1853. *
  1854. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  1855. * incorrect length in some situations.
  1856. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  1857. * get the Object implementation, which is slower but behaves correctly.
  1858. */
  1859. Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined ? global$1.TYPED_ARRAY_SUPPORT : true;
  1860. function kMaxLength() {
  1861. return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff;
  1862. }
  1863. function createBuffer(that, length) {
  1864. if (kMaxLength() < length) {
  1865. throw new RangeError('Invalid typed array length');
  1866. }
  1867. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1868. // Return an augmented `Uint8Array` instance, for best performance
  1869. that = new Uint8Array(length);
  1870. that.__proto__ = Buffer.prototype;
  1871. } else {
  1872. // Fallback: Return an object instance of the Buffer class
  1873. if (that === null) {
  1874. that = new Buffer(length);
  1875. }
  1876. that.length = length;
  1877. }
  1878. return that;
  1879. }
  1880. /**
  1881. * The Buffer constructor returns instances of `Uint8Array` that have their
  1882. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  1883. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  1884. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  1885. * returns a single octet.
  1886. *
  1887. * The `Uint8Array` prototype remains unmodified.
  1888. */
  1889. function Buffer(arg, encodingOrOffset, length) {
  1890. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  1891. return new Buffer(arg, encodingOrOffset, length);
  1892. } // Common case.
  1893. if (typeof arg === 'number') {
  1894. if (typeof encodingOrOffset === 'string') {
  1895. throw new Error('If encoding is specified then the first argument must be a string');
  1896. }
  1897. return allocUnsafe(this, arg);
  1898. }
  1899. return from(this, arg, encodingOrOffset, length);
  1900. }
  1901. Buffer.poolSize = 8192; // not used by this implementation
  1902. // TODO: Legacy, not needed anymore. Remove in next major version.
  1903. Buffer._augment = function (arr) {
  1904. arr.__proto__ = Buffer.prototype;
  1905. return arr;
  1906. };
  1907. function from(that, value, encodingOrOffset, length) {
  1908. if (typeof value === 'number') {
  1909. throw new TypeError('"value" argument must not be a number');
  1910. }
  1911. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  1912. return fromArrayBuffer(that, value, encodingOrOffset, length);
  1913. }
  1914. if (typeof value === 'string') {
  1915. return fromString(that, value, encodingOrOffset);
  1916. }
  1917. return fromObject(that, value);
  1918. }
  1919. /**
  1920. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  1921. * if value is a number.
  1922. * Buffer.from(str[, encoding])
  1923. * Buffer.from(array)
  1924. * Buffer.from(buffer)
  1925. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  1926. **/
  1927. Buffer.from = function (value, encodingOrOffset, length) {
  1928. return from(null, value, encodingOrOffset, length);
  1929. };
  1930. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1931. Buffer.prototype.__proto__ = Uint8Array.prototype;
  1932. Buffer.__proto__ = Uint8Array;
  1933. }
  1934. function assertSize(size) {
  1935. if (typeof size !== 'number') {
  1936. throw new TypeError('"size" argument must be a number');
  1937. } else if (size < 0) {
  1938. throw new RangeError('"size" argument must not be negative');
  1939. }
  1940. }
  1941. function alloc(that, size, fill, encoding) {
  1942. assertSize(size);
  1943. if (size <= 0) {
  1944. return createBuffer(that, size);
  1945. }
  1946. if (fill !== undefined) {
  1947. // Only pay attention to encoding if it's a string. This
  1948. // prevents accidentally sending in a number that would
  1949. // be interpretted as a start offset.
  1950. return typeof encoding === 'string' ? createBuffer(that, size).fill(fill, encoding) : createBuffer(that, size).fill(fill);
  1951. }
  1952. return createBuffer(that, size);
  1953. }
  1954. /**
  1955. * Creates a new filled Buffer instance.
  1956. * alloc(size[, fill[, encoding]])
  1957. **/
  1958. Buffer.alloc = function (size, fill, encoding) {
  1959. return alloc(null, size, fill, encoding);
  1960. };
  1961. function allocUnsafe(that, size) {
  1962. assertSize(size);
  1963. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
  1964. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  1965. for (var i = 0; i < size; ++i) {
  1966. that[i] = 0;
  1967. }
  1968. }
  1969. return that;
  1970. }
  1971. /**
  1972. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  1973. * */
  1974. Buffer.allocUnsafe = function (size) {
  1975. return allocUnsafe(null, size);
  1976. };
  1977. /**
  1978. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  1979. */
  1980. Buffer.allocUnsafeSlow = function (size) {
  1981. return allocUnsafe(null, size);
  1982. };
  1983. function fromString(that, string, encoding) {
  1984. if (typeof encoding !== 'string' || encoding === '') {
  1985. encoding = 'utf8';
  1986. }
  1987. if (!Buffer.isEncoding(encoding)) {
  1988. throw new TypeError('"encoding" must be a valid string encoding');
  1989. }
  1990. var length = byteLength(string, encoding) | 0;
  1991. that = createBuffer(that, length);
  1992. var actual = that.write(string, encoding);
  1993. if (actual !== length) {
  1994. // Writing a hex string, for example, that contains invalid characters will
  1995. // cause everything after the first invalid character to be ignored. (e.g.
  1996. // 'abxxcd' will be treated as 'ab')
  1997. that = that.slice(0, actual);
  1998. }
  1999. return that;
  2000. }
  2001. function fromArrayLike(that, array) {
  2002. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  2003. that = createBuffer(that, length);
  2004. for (var i = 0; i < length; i += 1) {
  2005. that[i] = array[i] & 255;
  2006. }
  2007. return that;
  2008. }
  2009. function fromArrayBuffer(that, array, byteOffset, length) {
  2010. array.byteLength; // this throws if `array` is not a valid ArrayBuffer
  2011. if (byteOffset < 0 || array.byteLength < byteOffset) {
  2012. throw new RangeError('\'offset\' is out of bounds');
  2013. }
  2014. if (array.byteLength < byteOffset + (length || 0)) {
  2015. throw new RangeError('\'length\' is out of bounds');
  2016. }
  2017. if (byteOffset === undefined && length === undefined) {
  2018. array = new Uint8Array(array);
  2019. } else if (length === undefined) {
  2020. array = new Uint8Array(array, byteOffset);
  2021. } else {
  2022. array = new Uint8Array(array, byteOffset, length);
  2023. }
  2024. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2025. // Return an augmented `Uint8Array` instance, for best performance
  2026. that = array;
  2027. that.__proto__ = Buffer.prototype;
  2028. } else {
  2029. // Fallback: Return an object instance of the Buffer class
  2030. that = fromArrayLike(that, array);
  2031. }
  2032. return that;
  2033. }
  2034. function fromObject(that, obj) {
  2035. if (internalIsBuffer(obj)) {
  2036. var len = checked(obj.length) | 0;
  2037. that = createBuffer(that, len);
  2038. if (that.length === 0) {
  2039. return that;
  2040. }
  2041. obj.copy(that, 0, 0, len);
  2042. return that;
  2043. }
  2044. if (obj) {
  2045. if (typeof ArrayBuffer !== 'undefined' && obj.buffer instanceof ArrayBuffer || 'length' in obj) {
  2046. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  2047. return createBuffer(that, 0);
  2048. }
  2049. return fromArrayLike(that, obj);
  2050. }
  2051. if (obj.type === 'Buffer' && isArray(obj.data)) {
  2052. return fromArrayLike(that, obj.data);
  2053. }
  2054. }
  2055. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.');
  2056. }
  2057. function checked(length) {
  2058. // Note: cannot use `length < kMaxLength()` here because that fails when
  2059. // length is NaN (which is otherwise coerced to zero.)
  2060. if (length >= kMaxLength()) {
  2061. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength().toString(16) + ' bytes');
  2062. }
  2063. return length | 0;
  2064. }
  2065. Buffer.isBuffer = isBuffer;
  2066. function internalIsBuffer(b) {
  2067. return !!(b != null && b._isBuffer);
  2068. }
  2069. Buffer.compare = function compare(a, b) {
  2070. if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
  2071. throw new TypeError('Arguments must be Buffers');
  2072. }
  2073. if (a === b) return 0;
  2074. var x = a.length;
  2075. var y = b.length;
  2076. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  2077. if (a[i] !== b[i]) {
  2078. x = a[i];
  2079. y = b[i];
  2080. break;
  2081. }
  2082. }
  2083. if (x < y) return -1;
  2084. if (y < x) return 1;
  2085. return 0;
  2086. };
  2087. Buffer.isEncoding = function isEncoding(encoding) {
  2088. switch (String(encoding).toLowerCase()) {
  2089. case 'hex':
  2090. case 'utf8':
  2091. case 'utf-8':
  2092. case 'ascii':
  2093. case 'latin1':
  2094. case 'binary':
  2095. case 'base64':
  2096. case 'ucs2':
  2097. case 'ucs-2':
  2098. case 'utf16le':
  2099. case 'utf-16le':
  2100. return true;
  2101. default:
  2102. return false;
  2103. }
  2104. };
  2105. Buffer.concat = function concat(list, length) {
  2106. if (!isArray(list)) {
  2107. throw new TypeError('"list" argument must be an Array of Buffers');
  2108. }
  2109. if (list.length === 0) {
  2110. return Buffer.alloc(0);
  2111. }
  2112. var i;
  2113. if (length === undefined) {
  2114. length = 0;
  2115. for (i = 0; i < list.length; ++i) {
  2116. length += list[i].length;
  2117. }
  2118. }
  2119. var buffer = Buffer.allocUnsafe(length);
  2120. var pos = 0;
  2121. for (i = 0; i < list.length; ++i) {
  2122. var buf = list[i];
  2123. if (!internalIsBuffer(buf)) {
  2124. throw new TypeError('"list" argument must be an Array of Buffers');
  2125. }
  2126. buf.copy(buffer, pos);
  2127. pos += buf.length;
  2128. }
  2129. return buffer;
  2130. };
  2131. function byteLength(string, encoding) {
  2132. if (internalIsBuffer(string)) {
  2133. return string.length;
  2134. }
  2135. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  2136. return string.byteLength;
  2137. }
  2138. if (typeof string !== 'string') {
  2139. string = '' + string;
  2140. }
  2141. var len = string.length;
  2142. if (len === 0) return 0; // Use a for loop to avoid recursion
  2143. var loweredCase = false;
  2144. for (;;) {
  2145. switch (encoding) {
  2146. case 'ascii':
  2147. case 'latin1':
  2148. case 'binary':
  2149. return len;
  2150. case 'utf8':
  2151. case 'utf-8':
  2152. case undefined:
  2153. return utf8ToBytes(string).length;
  2154. case 'ucs2':
  2155. case 'ucs-2':
  2156. case 'utf16le':
  2157. case 'utf-16le':
  2158. return len * 2;
  2159. case 'hex':
  2160. return len >>> 1;
  2161. case 'base64':
  2162. return base64ToBytes(string).length;
  2163. default:
  2164. if (loweredCase) return utf8ToBytes(string).length; // assume utf8
  2165. encoding = ('' + encoding).toLowerCase();
  2166. loweredCase = true;
  2167. }
  2168. }
  2169. }
  2170. Buffer.byteLength = byteLength;
  2171. function slowToString(encoding, start, end) {
  2172. var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  2173. // property of a typed array.
  2174. // This behaves neither like String nor Uint8Array in that we set start/end
  2175. // to their upper/lower bounds if the value passed is out of range.
  2176. // undefined is handled specially as per ECMA-262 6th Edition,
  2177. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  2178. if (start === undefined || start < 0) {
  2179. start = 0;
  2180. } // Return early if start > this.length. Done here to prevent potential uint32
  2181. // coercion fail below.
  2182. if (start > this.length) {
  2183. return '';
  2184. }
  2185. if (end === undefined || end > this.length) {
  2186. end = this.length;
  2187. }
  2188. if (end <= 0) {
  2189. return '';
  2190. } // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  2191. end >>>= 0;
  2192. start >>>= 0;
  2193. if (end <= start) {
  2194. return '';
  2195. }
  2196. if (!encoding) encoding = 'utf8';
  2197. while (true) {
  2198. switch (encoding) {
  2199. case 'hex':
  2200. return hexSlice(this, start, end);
  2201. case 'utf8':
  2202. case 'utf-8':
  2203. return utf8Slice(this, start, end);
  2204. case 'ascii':
  2205. return asciiSlice(this, start, end);
  2206. case 'latin1':
  2207. case 'binary':
  2208. return latin1Slice(this, start, end);
  2209. case 'base64':
  2210. return base64Slice(this, start, end);
  2211. case 'ucs2':
  2212. case 'ucs-2':
  2213. case 'utf16le':
  2214. case 'utf-16le':
  2215. return utf16leSlice(this, start, end);
  2216. default:
  2217. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  2218. encoding = (encoding + '').toLowerCase();
  2219. loweredCase = true;
  2220. }
  2221. }
  2222. } // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  2223. // Buffer instances.
  2224. Buffer.prototype._isBuffer = true;
  2225. function swap(b, n, m) {
  2226. var i = b[n];
  2227. b[n] = b[m];
  2228. b[m] = i;
  2229. }
  2230. Buffer.prototype.swap16 = function swap16() {
  2231. var len = this.length;
  2232. if (len % 2 !== 0) {
  2233. throw new RangeError('Buffer size must be a multiple of 16-bits');
  2234. }
  2235. for (var i = 0; i < len; i += 2) {
  2236. swap(this, i, i + 1);
  2237. }
  2238. return this;
  2239. };
  2240. Buffer.prototype.swap32 = function swap32() {
  2241. var len = this.length;
  2242. if (len % 4 !== 0) {
  2243. throw new RangeError('Buffer size must be a multiple of 32-bits');
  2244. }
  2245. for (var i = 0; i < len; i += 4) {
  2246. swap(this, i, i + 3);
  2247. swap(this, i + 1, i + 2);
  2248. }
  2249. return this;
  2250. };
  2251. Buffer.prototype.swap64 = function swap64() {
  2252. var len = this.length;
  2253. if (len % 8 !== 0) {
  2254. throw new RangeError('Buffer size must be a multiple of 64-bits');
  2255. }
  2256. for (var i = 0; i < len; i += 8) {
  2257. swap(this, i, i + 7);
  2258. swap(this, i + 1, i + 6);
  2259. swap(this, i + 2, i + 5);
  2260. swap(this, i + 3, i + 4);
  2261. }
  2262. return this;
  2263. };
  2264. Buffer.prototype.toString = function toString() {
  2265. var length = this.length | 0;
  2266. if (length === 0) return '';
  2267. if (arguments.length === 0) return utf8Slice(this, 0, length);
  2268. return slowToString.apply(this, arguments);
  2269. };
  2270. Buffer.prototype.equals = function equals(b) {
  2271. if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer');
  2272. if (this === b) return true;
  2273. return Buffer.compare(this, b) === 0;
  2274. };
  2275. Buffer.prototype.inspect = function inspect() {
  2276. var str = '';
  2277. var max = INSPECT_MAX_BYTES;
  2278. if (this.length > 0) {
  2279. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  2280. if (this.length > max) str += ' ... ';
  2281. }
  2282. return '<Buffer ' + str + '>';
  2283. };
  2284. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  2285. if (!internalIsBuffer(target)) {
  2286. throw new TypeError('Argument must be a Buffer');
  2287. }
  2288. if (start === undefined) {
  2289. start = 0;
  2290. }
  2291. if (end === undefined) {
  2292. end = target ? target.length : 0;
  2293. }
  2294. if (thisStart === undefined) {
  2295. thisStart = 0;
  2296. }
  2297. if (thisEnd === undefined) {
  2298. thisEnd = this.length;
  2299. }
  2300. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  2301. throw new RangeError('out of range index');
  2302. }
  2303. if (thisStart >= thisEnd && start >= end) {
  2304. return 0;
  2305. }
  2306. if (thisStart >= thisEnd) {
  2307. return -1;
  2308. }
  2309. if (start >= end) {
  2310. return 1;
  2311. }
  2312. start >>>= 0;
  2313. end >>>= 0;
  2314. thisStart >>>= 0;
  2315. thisEnd >>>= 0;
  2316. if (this === target) return 0;
  2317. var x = thisEnd - thisStart;
  2318. var y = end - start;
  2319. var len = Math.min(x, y);
  2320. var thisCopy = this.slice(thisStart, thisEnd);
  2321. var targetCopy = target.slice(start, end);
  2322. for (var i = 0; i < len; ++i) {
  2323. if (thisCopy[i] !== targetCopy[i]) {
  2324. x = thisCopy[i];
  2325. y = targetCopy[i];
  2326. break;
  2327. }
  2328. }
  2329. if (x < y) return -1;
  2330. if (y < x) return 1;
  2331. return 0;
  2332. }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  2333. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  2334. //
  2335. // Arguments:
  2336. // - buffer - a Buffer to search
  2337. // - val - a string, Buffer, or number
  2338. // - byteOffset - an index into `buffer`; will be clamped to an int32
  2339. // - encoding - an optional encoding, relevant is val is a string
  2340. // - dir - true for indexOf, false for lastIndexOf
  2341. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  2342. // Empty buffer means no match
  2343. if (buffer.length === 0) return -1; // Normalize byteOffset
  2344. if (typeof byteOffset === 'string') {
  2345. encoding = byteOffset;
  2346. byteOffset = 0;
  2347. } else if (byteOffset > 0x7fffffff) {
  2348. byteOffset = 0x7fffffff;
  2349. } else if (byteOffset < -0x80000000) {
  2350. byteOffset = -0x80000000;
  2351. }
  2352. byteOffset = +byteOffset; // Coerce to Number.
  2353. if (isNaN(byteOffset)) {
  2354. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  2355. byteOffset = dir ? 0 : buffer.length - 1;
  2356. } // Normalize byteOffset: negative offsets start from the end of the buffer
  2357. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  2358. if (byteOffset >= buffer.length) {
  2359. if (dir) return -1;else byteOffset = buffer.length - 1;
  2360. } else if (byteOffset < 0) {
  2361. if (dir) byteOffset = 0;else return -1;
  2362. } // Normalize val
  2363. if (typeof val === 'string') {
  2364. val = Buffer.from(val, encoding);
  2365. } // Finally, search either indexOf (if dir is true) or lastIndexOf
  2366. if (internalIsBuffer(val)) {
  2367. // Special case: looking for empty string/buffer always fails
  2368. if (val.length === 0) {
  2369. return -1;
  2370. }
  2371. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  2372. } else if (typeof val === 'number') {
  2373. val = val & 0xFF; // Search for a byte value [0-255]
  2374. if (Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf === 'function') {
  2375. if (dir) {
  2376. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  2377. } else {
  2378. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  2379. }
  2380. }
  2381. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  2382. }
  2383. throw new TypeError('val must be string, number or Buffer');
  2384. }
  2385. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  2386. var indexSize = 1;
  2387. var arrLength = arr.length;
  2388. var valLength = val.length;
  2389. if (encoding !== undefined) {
  2390. encoding = String(encoding).toLowerCase();
  2391. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  2392. if (arr.length < 2 || val.length < 2) {
  2393. return -1;
  2394. }
  2395. indexSize = 2;
  2396. arrLength /= 2;
  2397. valLength /= 2;
  2398. byteOffset /= 2;
  2399. }
  2400. }
  2401. function read(buf, i) {
  2402. if (indexSize === 1) {
  2403. return buf[i];
  2404. } else {
  2405. return buf.readUInt16BE(i * indexSize);
  2406. }
  2407. }
  2408. var i;
  2409. if (dir) {
  2410. var foundIndex = -1;
  2411. for (i = byteOffset; i < arrLength; i++) {
  2412. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  2413. if (foundIndex === -1) foundIndex = i;
  2414. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  2415. } else {
  2416. if (foundIndex !== -1) i -= i - foundIndex;
  2417. foundIndex = -1;
  2418. }
  2419. }
  2420. } else {
  2421. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  2422. for (i = byteOffset; i >= 0; i--) {
  2423. var found = true;
  2424. for (var j = 0; j < valLength; j++) {
  2425. if (read(arr, i + j) !== read(val, j)) {
  2426. found = false;
  2427. break;
  2428. }
  2429. }
  2430. if (found) return i;
  2431. }
  2432. }
  2433. return -1;
  2434. }
  2435. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  2436. return this.indexOf(val, byteOffset, encoding) !== -1;
  2437. };
  2438. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  2439. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  2440. };
  2441. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  2442. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  2443. };
  2444. function hexWrite(buf, string, offset, length) {
  2445. offset = Number(offset) || 0;
  2446. var remaining = buf.length - offset;
  2447. if (!length) {
  2448. length = remaining;
  2449. } else {
  2450. length = Number(length);
  2451. if (length > remaining) {
  2452. length = remaining;
  2453. }
  2454. } // must be an even number of digits
  2455. var strLen = string.length;
  2456. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string');
  2457. if (length > strLen / 2) {
  2458. length = strLen / 2;
  2459. }
  2460. for (var i = 0; i < length; ++i) {
  2461. var parsed = parseInt(string.substr(i * 2, 2), 16);
  2462. if (isNaN(parsed)) return i;
  2463. buf[offset + i] = parsed;
  2464. }
  2465. return i;
  2466. }
  2467. function utf8Write(buf, string, offset, length) {
  2468. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  2469. }
  2470. function asciiWrite(buf, string, offset, length) {
  2471. return blitBuffer(asciiToBytes(string), buf, offset, length);
  2472. }
  2473. function latin1Write(buf, string, offset, length) {
  2474. return asciiWrite(buf, string, offset, length);
  2475. }
  2476. function base64Write(buf, string, offset, length) {
  2477. return blitBuffer(base64ToBytes(string), buf, offset, length);
  2478. }
  2479. function ucs2Write(buf, string, offset, length) {
  2480. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  2481. }
  2482. Buffer.prototype.write = function write(string, offset, length, encoding) {
  2483. // Buffer#write(string)
  2484. if (offset === undefined) {
  2485. encoding = 'utf8';
  2486. length = this.length;
  2487. offset = 0; // Buffer#write(string, encoding)
  2488. } else if (length === undefined && typeof offset === 'string') {
  2489. encoding = offset;
  2490. length = this.length;
  2491. offset = 0; // Buffer#write(string, offset[, length][, encoding])
  2492. } else if (isFinite(offset)) {
  2493. offset = offset | 0;
  2494. if (isFinite(length)) {
  2495. length = length | 0;
  2496. if (encoding === undefined) encoding = 'utf8';
  2497. } else {
  2498. encoding = length;
  2499. length = undefined;
  2500. } // legacy write(string, encoding, offset, length) - remove in v0.13
  2501. } else {
  2502. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  2503. }
  2504. var remaining = this.length - offset;
  2505. if (length === undefined || length > remaining) length = remaining;
  2506. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  2507. throw new RangeError('Attempt to write outside buffer bounds');
  2508. }
  2509. if (!encoding) encoding = 'utf8';
  2510. var loweredCase = false;
  2511. for (;;) {
  2512. switch (encoding) {
  2513. case 'hex':
  2514. return hexWrite(this, string, offset, length);
  2515. case 'utf8':
  2516. case 'utf-8':
  2517. return utf8Write(this, string, offset, length);
  2518. case 'ascii':
  2519. return asciiWrite(this, string, offset, length);
  2520. case 'latin1':
  2521. case 'binary':
  2522. return latin1Write(this, string, offset, length);
  2523. case 'base64':
  2524. // Warning: maxLength not taken into account in base64Write
  2525. return base64Write(this, string, offset, length);
  2526. case 'ucs2':
  2527. case 'ucs-2':
  2528. case 'utf16le':
  2529. case 'utf-16le':
  2530. return ucs2Write(this, string, offset, length);
  2531. default:
  2532. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  2533. encoding = ('' + encoding).toLowerCase();
  2534. loweredCase = true;
  2535. }
  2536. }
  2537. };
  2538. Buffer.prototype.toJSON = function toJSON() {
  2539. return {
  2540. type: 'Buffer',
  2541. data: Array.prototype.slice.call(this._arr || this, 0)
  2542. };
  2543. };
  2544. function base64Slice(buf, start, end) {
  2545. if (start === 0 && end === buf.length) {
  2546. return fromByteArray(buf);
  2547. } else {
  2548. return fromByteArray(buf.slice(start, end));
  2549. }
  2550. }
  2551. function utf8Slice(buf, start, end) {
  2552. end = Math.min(buf.length, end);
  2553. var res = [];
  2554. var i = start;
  2555. while (i < end) {
  2556. var firstByte = buf[i];
  2557. var codePoint = null;
  2558. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  2559. if (i + bytesPerSequence <= end) {
  2560. var secondByte, thirdByte, fourthByte, tempCodePoint;
  2561. switch (bytesPerSequence) {
  2562. case 1:
  2563. if (firstByte < 0x80) {
  2564. codePoint = firstByte;
  2565. }
  2566. break;
  2567. case 2:
  2568. secondByte = buf[i + 1];
  2569. if ((secondByte & 0xC0) === 0x80) {
  2570. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  2571. if (tempCodePoint > 0x7F) {
  2572. codePoint = tempCodePoint;
  2573. }
  2574. }
  2575. break;
  2576. case 3:
  2577. secondByte = buf[i + 1];
  2578. thirdByte = buf[i + 2];
  2579. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  2580. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  2581. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  2582. codePoint = tempCodePoint;
  2583. }
  2584. }
  2585. break;
  2586. case 4:
  2587. secondByte = buf[i + 1];
  2588. thirdByte = buf[i + 2];
  2589. fourthByte = buf[i + 3];
  2590. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  2591. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  2592. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  2593. codePoint = tempCodePoint;
  2594. }
  2595. }
  2596. }
  2597. }
  2598. if (codePoint === null) {
  2599. // we did not generate a valid codePoint so insert a
  2600. // replacement char (U+FFFD) and advance only 1 byte
  2601. codePoint = 0xFFFD;
  2602. bytesPerSequence = 1;
  2603. } else if (codePoint > 0xFFFF) {
  2604. // encode to utf16 (surrogate pair dance)
  2605. codePoint -= 0x10000;
  2606. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  2607. codePoint = 0xDC00 | codePoint & 0x3FF;
  2608. }
  2609. res.push(codePoint);
  2610. i += bytesPerSequence;
  2611. }
  2612. return decodeCodePointsArray(res);
  2613. } // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  2614. // the lowest limit is Chrome, with 0x10000 args.
  2615. // We go 1 magnitude less, for safety
  2616. var MAX_ARGUMENTS_LENGTH = 0x1000;
  2617. function decodeCodePointsArray(codePoints) {
  2618. var len = codePoints.length;
  2619. if (len <= MAX_ARGUMENTS_LENGTH) {
  2620. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  2621. } // Decode in chunks to avoid "call stack size exceeded".
  2622. var res = '';
  2623. var i = 0;
  2624. while (i < len) {
  2625. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  2626. }
  2627. return res;
  2628. }
  2629. function asciiSlice(buf, start, end) {
  2630. var ret = '';
  2631. end = Math.min(buf.length, end);
  2632. for (var i = start; i < end; ++i) {
  2633. ret += String.fromCharCode(buf[i] & 0x7F);
  2634. }
  2635. return ret;
  2636. }
  2637. function latin1Slice(buf, start, end) {
  2638. var ret = '';
  2639. end = Math.min(buf.length, end);
  2640. for (var i = start; i < end; ++i) {
  2641. ret += String.fromCharCode(buf[i]);
  2642. }
  2643. return ret;
  2644. }
  2645. function hexSlice(buf, start, end) {
  2646. var len = buf.length;
  2647. if (!start || start < 0) start = 0;
  2648. if (!end || end < 0 || end > len) end = len;
  2649. var out = '';
  2650. for (var i = start; i < end; ++i) {
  2651. out += toHex(buf[i]);
  2652. }
  2653. return out;
  2654. }
  2655. function utf16leSlice(buf, start, end) {
  2656. var bytes = buf.slice(start, end);
  2657. var res = '';
  2658. for (var i = 0; i < bytes.length; i += 2) {
  2659. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  2660. }
  2661. return res;
  2662. }
  2663. Buffer.prototype.slice = function slice(start, end) {
  2664. var len = this.length;
  2665. start = ~~start;
  2666. end = end === undefined ? len : ~~end;
  2667. if (start < 0) {
  2668. start += len;
  2669. if (start < 0) start = 0;
  2670. } else if (start > len) {
  2671. start = len;
  2672. }
  2673. if (end < 0) {
  2674. end += len;
  2675. if (end < 0) end = 0;
  2676. } else if (end > len) {
  2677. end = len;
  2678. }
  2679. if (end < start) end = start;
  2680. var newBuf;
  2681. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2682. newBuf = this.subarray(start, end);
  2683. newBuf.__proto__ = Buffer.prototype;
  2684. } else {
  2685. var sliceLen = end - start;
  2686. newBuf = new Buffer(sliceLen, undefined);
  2687. for (var i = 0; i < sliceLen; ++i) {
  2688. newBuf[i] = this[i + start];
  2689. }
  2690. }
  2691. return newBuf;
  2692. };
  2693. /*
  2694. * Need to make sure that buffer isn't trying to write out of bounds.
  2695. */
  2696. function checkOffset(offset, ext, length) {
  2697. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  2698. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  2699. }
  2700. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  2701. offset = offset | 0;
  2702. byteLength = byteLength | 0;
  2703. if (!noAssert) checkOffset(offset, byteLength, this.length);
  2704. var val = this[offset];
  2705. var mul = 1;
  2706. var i = 0;
  2707. while (++i < byteLength && (mul *= 0x100)) {
  2708. val += this[offset + i] * mul;
  2709. }
  2710. return val;
  2711. };
  2712. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  2713. offset = offset | 0;
  2714. byteLength = byteLength | 0;
  2715. if (!noAssert) {
  2716. checkOffset(offset, byteLength, this.length);
  2717. }
  2718. var val = this[offset + --byteLength];
  2719. var mul = 1;
  2720. while (byteLength > 0 && (mul *= 0x100)) {
  2721. val += this[offset + --byteLength] * mul;
  2722. }
  2723. return val;
  2724. };
  2725. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  2726. if (!noAssert) checkOffset(offset, 1, this.length);
  2727. return this[offset];
  2728. };
  2729. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  2730. if (!noAssert) checkOffset(offset, 2, this.length);
  2731. return this[offset] | this[offset + 1] << 8;
  2732. };
  2733. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  2734. if (!noAssert) checkOffset(offset, 2, this.length);
  2735. return this[offset] << 8 | this[offset + 1];
  2736. };
  2737. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  2738. if (!noAssert) checkOffset(offset, 4, this.length);
  2739. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  2740. };
  2741. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  2742. if (!noAssert) checkOffset(offset, 4, this.length);
  2743. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  2744. };
  2745. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  2746. offset = offset | 0;
  2747. byteLength = byteLength | 0;
  2748. if (!noAssert) checkOffset(offset, byteLength, this.length);
  2749. var val = this[offset];
  2750. var mul = 1;
  2751. var i = 0;
  2752. while (++i < byteLength && (mul *= 0x100)) {
  2753. val += this[offset + i] * mul;
  2754. }
  2755. mul *= 0x80;
  2756. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  2757. return val;
  2758. };
  2759. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  2760. offset = offset | 0;
  2761. byteLength = byteLength | 0;
  2762. if (!noAssert) checkOffset(offset, byteLength, this.length);
  2763. var i = byteLength;
  2764. var mul = 1;
  2765. var val = this[offset + --i];
  2766. while (i > 0 && (mul *= 0x100)) {
  2767. val += this[offset + --i] * mul;
  2768. }
  2769. mul *= 0x80;
  2770. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  2771. return val;
  2772. };
  2773. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  2774. if (!noAssert) checkOffset(offset, 1, this.length);
  2775. if (!(this[offset] & 0x80)) return this[offset];
  2776. return (0xff - this[offset] + 1) * -1;
  2777. };
  2778. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  2779. if (!noAssert) checkOffset(offset, 2, this.length);
  2780. var val = this[offset] | this[offset + 1] << 8;
  2781. return val & 0x8000 ? val | 0xFFFF0000 : val;
  2782. };
  2783. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  2784. if (!noAssert) checkOffset(offset, 2, this.length);
  2785. var val = this[offset + 1] | this[offset] << 8;
  2786. return val & 0x8000 ? val | 0xFFFF0000 : val;
  2787. };
  2788. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  2789. if (!noAssert) checkOffset(offset, 4, this.length);
  2790. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  2791. };
  2792. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  2793. if (!noAssert) checkOffset(offset, 4, this.length);
  2794. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  2795. };
  2796. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  2797. if (!noAssert) checkOffset(offset, 4, this.length);
  2798. return read(this, offset, true, 23, 4);
  2799. };
  2800. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  2801. if (!noAssert) checkOffset(offset, 4, this.length);
  2802. return read(this, offset, false, 23, 4);
  2803. };
  2804. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  2805. if (!noAssert) checkOffset(offset, 8, this.length);
  2806. return read(this, offset, true, 52, 8);
  2807. };
  2808. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  2809. if (!noAssert) checkOffset(offset, 8, this.length);
  2810. return read(this, offset, false, 52, 8);
  2811. };
  2812. function checkInt(buf, value, offset, ext, max, min) {
  2813. if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  2814. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  2815. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  2816. }
  2817. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  2818. value = +value;
  2819. offset = offset | 0;
  2820. byteLength = byteLength | 0;
  2821. if (!noAssert) {
  2822. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  2823. checkInt(this, value, offset, byteLength, maxBytes, 0);
  2824. }
  2825. var mul = 1;
  2826. var i = 0;
  2827. this[offset] = value & 0xFF;
  2828. while (++i < byteLength && (mul *= 0x100)) {
  2829. this[offset + i] = value / mul & 0xFF;
  2830. }
  2831. return offset + byteLength;
  2832. };
  2833. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  2834. value = +value;
  2835. offset = offset | 0;
  2836. byteLength = byteLength | 0;
  2837. if (!noAssert) {
  2838. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  2839. checkInt(this, value, offset, byteLength, maxBytes, 0);
  2840. }
  2841. var i = byteLength - 1;
  2842. var mul = 1;
  2843. this[offset + i] = value & 0xFF;
  2844. while (--i >= 0 && (mul *= 0x100)) {
  2845. this[offset + i] = value / mul & 0xFF;
  2846. }
  2847. return offset + byteLength;
  2848. };
  2849. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  2850. value = +value;
  2851. offset = offset | 0;
  2852. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  2853. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  2854. this[offset] = value & 0xff;
  2855. return offset + 1;
  2856. };
  2857. function objectWriteUInt16(buf, value, offset, littleEndian) {
  2858. if (value < 0) value = 0xffff + value + 1;
  2859. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  2860. buf[offset + i] = (value & 0xff << 8 * (littleEndian ? i : 1 - i)) >>> (littleEndian ? i : 1 - i) * 8;
  2861. }
  2862. }
  2863. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  2864. value = +value;
  2865. offset = offset | 0;
  2866. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  2867. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2868. this[offset] = value & 0xff;
  2869. this[offset + 1] = value >>> 8;
  2870. } else {
  2871. objectWriteUInt16(this, value, offset, true);
  2872. }
  2873. return offset + 2;
  2874. };
  2875. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  2876. value = +value;
  2877. offset = offset | 0;
  2878. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  2879. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2880. this[offset] = value >>> 8;
  2881. this[offset + 1] = value & 0xff;
  2882. } else {
  2883. objectWriteUInt16(this, value, offset, false);
  2884. }
  2885. return offset + 2;
  2886. };
  2887. function objectWriteUInt32(buf, value, offset, littleEndian) {
  2888. if (value < 0) value = 0xffffffff + value + 1;
  2889. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  2890. buf[offset + i] = value >>> (littleEndian ? i : 3 - i) * 8 & 0xff;
  2891. }
  2892. }
  2893. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  2894. value = +value;
  2895. offset = offset | 0;
  2896. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  2897. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2898. this[offset + 3] = value >>> 24;
  2899. this[offset + 2] = value >>> 16;
  2900. this[offset + 1] = value >>> 8;
  2901. this[offset] = value & 0xff;
  2902. } else {
  2903. objectWriteUInt32(this, value, offset, true);
  2904. }
  2905. return offset + 4;
  2906. };
  2907. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  2908. value = +value;
  2909. offset = offset | 0;
  2910. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  2911. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2912. this[offset] = value >>> 24;
  2913. this[offset + 1] = value >>> 16;
  2914. this[offset + 2] = value >>> 8;
  2915. this[offset + 3] = value & 0xff;
  2916. } else {
  2917. objectWriteUInt32(this, value, offset, false);
  2918. }
  2919. return offset + 4;
  2920. };
  2921. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  2922. value = +value;
  2923. offset = offset | 0;
  2924. if (!noAssert) {
  2925. var limit = Math.pow(2, 8 * byteLength - 1);
  2926. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  2927. }
  2928. var i = 0;
  2929. var mul = 1;
  2930. var sub = 0;
  2931. this[offset] = value & 0xFF;
  2932. while (++i < byteLength && (mul *= 0x100)) {
  2933. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  2934. sub = 1;
  2935. }
  2936. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  2937. }
  2938. return offset + byteLength;
  2939. };
  2940. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  2941. value = +value;
  2942. offset = offset | 0;
  2943. if (!noAssert) {
  2944. var limit = Math.pow(2, 8 * byteLength - 1);
  2945. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  2946. }
  2947. var i = byteLength - 1;
  2948. var mul = 1;
  2949. var sub = 0;
  2950. this[offset + i] = value & 0xFF;
  2951. while (--i >= 0 && (mul *= 0x100)) {
  2952. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  2953. sub = 1;
  2954. }
  2955. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  2956. }
  2957. return offset + byteLength;
  2958. };
  2959. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  2960. value = +value;
  2961. offset = offset | 0;
  2962. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  2963. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
  2964. if (value < 0) value = 0xff + value + 1;
  2965. this[offset] = value & 0xff;
  2966. return offset + 1;
  2967. };
  2968. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  2969. value = +value;
  2970. offset = offset | 0;
  2971. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  2972. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2973. this[offset] = value & 0xff;
  2974. this[offset + 1] = value >>> 8;
  2975. } else {
  2976. objectWriteUInt16(this, value, offset, true);
  2977. }
  2978. return offset + 2;
  2979. };
  2980. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  2981. value = +value;
  2982. offset = offset | 0;
  2983. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  2984. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2985. this[offset] = value >>> 8;
  2986. this[offset + 1] = value & 0xff;
  2987. } else {
  2988. objectWriteUInt16(this, value, offset, false);
  2989. }
  2990. return offset + 2;
  2991. };
  2992. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  2993. value = +value;
  2994. offset = offset | 0;
  2995. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  2996. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2997. this[offset] = value & 0xff;
  2998. this[offset + 1] = value >>> 8;
  2999. this[offset + 2] = value >>> 16;
  3000. this[offset + 3] = value >>> 24;
  3001. } else {
  3002. objectWriteUInt32(this, value, offset, true);
  3003. }
  3004. return offset + 4;
  3005. };
  3006. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  3007. value = +value;
  3008. offset = offset | 0;
  3009. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  3010. if (value < 0) value = 0xffffffff + value + 1;
  3011. if (Buffer.TYPED_ARRAY_SUPPORT) {
  3012. this[offset] = value >>> 24;
  3013. this[offset + 1] = value >>> 16;
  3014. this[offset + 2] = value >>> 8;
  3015. this[offset + 3] = value & 0xff;
  3016. } else {
  3017. objectWriteUInt32(this, value, offset, false);
  3018. }
  3019. return offset + 4;
  3020. };
  3021. function checkIEEE754(buf, value, offset, ext, max, min) {
  3022. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  3023. if (offset < 0) throw new RangeError('Index out of range');
  3024. }
  3025. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  3026. if (!noAssert) {
  3027. checkIEEE754(buf, value, offset, 4);
  3028. }
  3029. write(buf, value, offset, littleEndian, 23, 4);
  3030. return offset + 4;
  3031. }
  3032. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  3033. return writeFloat(this, value, offset, true, noAssert);
  3034. };
  3035. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  3036. return writeFloat(this, value, offset, false, noAssert);
  3037. };
  3038. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  3039. if (!noAssert) {
  3040. checkIEEE754(buf, value, offset, 8);
  3041. }
  3042. write(buf, value, offset, littleEndian, 52, 8);
  3043. return offset + 8;
  3044. }
  3045. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  3046. return writeDouble(this, value, offset, true, noAssert);
  3047. };
  3048. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  3049. return writeDouble(this, value, offset, false, noAssert);
  3050. }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  3051. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  3052. if (!start) start = 0;
  3053. if (!end && end !== 0) end = this.length;
  3054. if (targetStart >= target.length) targetStart = target.length;
  3055. if (!targetStart) targetStart = 0;
  3056. if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
  3057. if (end === start) return 0;
  3058. if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
  3059. if (targetStart < 0) {
  3060. throw new RangeError('targetStart out of bounds');
  3061. }
  3062. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds');
  3063. if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
  3064. if (end > this.length) end = this.length;
  3065. if (target.length - targetStart < end - start) {
  3066. end = target.length - targetStart + start;
  3067. }
  3068. var len = end - start;
  3069. var i;
  3070. if (this === target && start < targetStart && targetStart < end) {
  3071. // descending copy from end
  3072. for (i = len - 1; i >= 0; --i) {
  3073. target[i + targetStart] = this[i + start];
  3074. }
  3075. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  3076. // ascending copy from start
  3077. for (i = 0; i < len; ++i) {
  3078. target[i + targetStart] = this[i + start];
  3079. }
  3080. } else {
  3081. Uint8Array.prototype.set.call(target, this.subarray(start, start + len), targetStart);
  3082. }
  3083. return len;
  3084. }; // Usage:
  3085. // buffer.fill(number[, offset[, end]])
  3086. // buffer.fill(buffer[, offset[, end]])
  3087. // buffer.fill(string[, offset[, end]][, encoding])
  3088. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  3089. // Handle string cases:
  3090. if (typeof val === 'string') {
  3091. if (typeof start === 'string') {
  3092. encoding = start;
  3093. start = 0;
  3094. end = this.length;
  3095. } else if (typeof end === 'string') {
  3096. encoding = end;
  3097. end = this.length;
  3098. }
  3099. if (val.length === 1) {
  3100. var code = val.charCodeAt(0);
  3101. if (code < 256) {
  3102. val = code;
  3103. }
  3104. }
  3105. if (encoding !== undefined && typeof encoding !== 'string') {
  3106. throw new TypeError('encoding must be a string');
  3107. }
  3108. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  3109. throw new TypeError('Unknown encoding: ' + encoding);
  3110. }
  3111. } else if (typeof val === 'number') {
  3112. val = val & 255;
  3113. } // Invalid ranges are not set to a default, so can range check early.
  3114. if (start < 0 || this.length < start || this.length < end) {
  3115. throw new RangeError('Out of range index');
  3116. }
  3117. if (end <= start) {
  3118. return this;
  3119. }
  3120. start = start >>> 0;
  3121. end = end === undefined ? this.length : end >>> 0;
  3122. if (!val) val = 0;
  3123. var i;
  3124. if (typeof val === 'number') {
  3125. for (i = start; i < end; ++i) {
  3126. this[i] = val;
  3127. }
  3128. } else {
  3129. var bytes = internalIsBuffer(val) ? val : utf8ToBytes(new Buffer(val, encoding).toString());
  3130. var len = bytes.length;
  3131. for (i = 0; i < end - start; ++i) {
  3132. this[i + start] = bytes[i % len];
  3133. }
  3134. }
  3135. return this;
  3136. }; // HELPER FUNCTIONS
  3137. // ================
  3138. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
  3139. function base64clean(str) {
  3140. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  3141. str = stringtrim(str).replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to ''
  3142. if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  3143. while (str.length % 4 !== 0) {
  3144. str = str + '=';
  3145. }
  3146. return str;
  3147. }
  3148. function stringtrim(str) {
  3149. if (str.trim) return str.trim();
  3150. return str.replace(/^\s+|\s+$/g, '');
  3151. }
  3152. function toHex(n) {
  3153. if (n < 16) return '0' + n.toString(16);
  3154. return n.toString(16);
  3155. }
  3156. function utf8ToBytes(string, units) {
  3157. units = units || Infinity;
  3158. var codePoint;
  3159. var length = string.length;
  3160. var leadSurrogate = null;
  3161. var bytes = [];
  3162. for (var i = 0; i < length; ++i) {
  3163. codePoint = string.charCodeAt(i); // is surrogate component
  3164. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  3165. // last char was a lead
  3166. if (!leadSurrogate) {
  3167. // no lead yet
  3168. if (codePoint > 0xDBFF) {
  3169. // unexpected trail
  3170. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  3171. continue;
  3172. } else if (i + 1 === length) {
  3173. // unpaired lead
  3174. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  3175. continue;
  3176. } // valid lead
  3177. leadSurrogate = codePoint;
  3178. continue;
  3179. } // 2 leads in a row
  3180. if (codePoint < 0xDC00) {
  3181. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  3182. leadSurrogate = codePoint;
  3183. continue;
  3184. } // valid surrogate pair
  3185. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  3186. } else if (leadSurrogate) {
  3187. // valid bmp char, but last char was a lead
  3188. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  3189. }
  3190. leadSurrogate = null; // encode utf8
  3191. if (codePoint < 0x80) {
  3192. if ((units -= 1) < 0) break;
  3193. bytes.push(codePoint);
  3194. } else if (codePoint < 0x800) {
  3195. if ((units -= 2) < 0) break;
  3196. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  3197. } else if (codePoint < 0x10000) {
  3198. if ((units -= 3) < 0) break;
  3199. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  3200. } else if (codePoint < 0x110000) {
  3201. if ((units -= 4) < 0) break;
  3202. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  3203. } else {
  3204. throw new Error('Invalid code point');
  3205. }
  3206. }
  3207. return bytes;
  3208. }
  3209. function asciiToBytes(str) {
  3210. var byteArray = [];
  3211. for (var i = 0; i < str.length; ++i) {
  3212. // Node's code seems to be doing this and not & 0x7F..
  3213. byteArray.push(str.charCodeAt(i) & 0xFF);
  3214. }
  3215. return byteArray;
  3216. }
  3217. function utf16leToBytes(str, units) {
  3218. var c, hi, lo;
  3219. var byteArray = [];
  3220. for (var i = 0; i < str.length; ++i) {
  3221. if ((units -= 2) < 0) break;
  3222. c = str.charCodeAt(i);
  3223. hi = c >> 8;
  3224. lo = c % 256;
  3225. byteArray.push(lo);
  3226. byteArray.push(hi);
  3227. }
  3228. return byteArray;
  3229. }
  3230. function base64ToBytes(str) {
  3231. return toByteArray(base64clean(str));
  3232. }
  3233. function blitBuffer(src, dst, offset, length) {
  3234. for (var i = 0; i < length; ++i) {
  3235. if (i + offset >= dst.length || i >= src.length) break;
  3236. dst[i + offset] = src[i];
  3237. }
  3238. return i;
  3239. }
  3240. function isnan(val) {
  3241. return val !== val; // eslint-disable-line no-self-compare
  3242. } // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
  3243. // The _isBuffer check is for Safari 5-7 support, because it's missing
  3244. // Object.prototype.constructor. Remove this eventually
  3245. function isBuffer(obj) {
  3246. return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj));
  3247. }
  3248. function isFastBuffer(obj) {
  3249. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
  3250. } // For Node v0.10 support. Remove this eventually.
  3251. function isSlowBuffer(obj) {
  3252. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0));
  3253. }
  3254. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  3255. function unwrapExports (x) {
  3256. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  3257. }
  3258. function createCommonjsModule(fn, module) {
  3259. return module = { exports: {} }, fn(module, module.exports), module.exports;
  3260. }
  3261. function getCjsExportFromNamespace (n) {
  3262. return n && n['default'] || n;
  3263. }
  3264. var fs = getCjsExportFromNamespace(_shim_fs$1);
  3265. /**
  3266. * @class
  3267. */
  3268. var LineByLine =
  3269. /*#__PURE__*/
  3270. function () {
  3271. function LineByLine(file, options) {
  3272. _classCallCheck(this, LineByLine);
  3273. options = options || {};
  3274. if (!options.readChunk) options.readChunk = 1024;
  3275. if (!options.newLineCharacter) {
  3276. options.newLineCharacter = 0x0a; //linux line ending
  3277. } else {
  3278. options.newLineCharacter = options.newLineCharacter.charCodeAt(0);
  3279. }
  3280. if (typeof file === 'number') {
  3281. this.fd = file;
  3282. } else {
  3283. this.fd = fs.openSync(file, 'r');
  3284. }
  3285. this.options = options;
  3286. this.newLineCharacter = options.newLineCharacter;
  3287. this.reset();
  3288. }
  3289. _createClass(LineByLine, [{
  3290. key: "_searchInBuffer",
  3291. value: function _searchInBuffer(buffer, hexNeedle) {
  3292. var found = -1;
  3293. for (var i = 0; i <= buffer.length; i++) {
  3294. var b_byte = buffer[i];
  3295. if (b_byte === hexNeedle) {
  3296. found = i;
  3297. break;
  3298. }
  3299. }
  3300. return found;
  3301. }
  3302. }, {
  3303. key: "reset",
  3304. value: function reset() {
  3305. this.eofReached = false;
  3306. this.linesCache = [];
  3307. this.fdPosition = 0;
  3308. }
  3309. }, {
  3310. key: "close",
  3311. value: function close() {
  3312. fs.closeSync(this.fd);
  3313. this.fd = null;
  3314. }
  3315. }, {
  3316. key: "_extractLines",
  3317. value: function _extractLines(buffer) {
  3318. var line;
  3319. var lines = [];
  3320. var bufferPosition = 0;
  3321. var lastNewLineBufferPosition = 0;
  3322. while (true) {
  3323. var bufferPositionValue = buffer[bufferPosition++];
  3324. if (bufferPositionValue === this.newLineCharacter) {
  3325. line = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  3326. lines.push(line);
  3327. lastNewLineBufferPosition = bufferPosition;
  3328. } else if (!bufferPositionValue) {
  3329. break;
  3330. }
  3331. }
  3332. var leftovers = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  3333. if (leftovers.length) {
  3334. lines.push(leftovers);
  3335. }
  3336. return lines;
  3337. }
  3338. }, {
  3339. key: "_readChunk",
  3340. value: function _readChunk(lineLeftovers) {
  3341. var totalBytesRead = 0;
  3342. var bytesRead;
  3343. var buffers = [];
  3344. do {
  3345. var readBuffer = new Buffer(this.options.readChunk);
  3346. bytesRead = fs.readSync(this.fd, readBuffer, 0, this.options.readChunk, this.fdPosition);
  3347. totalBytesRead = totalBytesRead + bytesRead;
  3348. this.fdPosition = this.fdPosition + bytesRead;
  3349. buffers.push(readBuffer);
  3350. } while (bytesRead && this._searchInBuffer(buffers[buffers.length - 1], this.options.newLineCharacter) === -1);
  3351. var bufferData = Buffer.concat(buffers);
  3352. if (bytesRead < this.options.readChunk) {
  3353. this.eofReached = true;
  3354. bufferData = bufferData.slice(0, totalBytesRead);
  3355. }
  3356. if (totalBytesRead) {
  3357. this.linesCache = this._extractLines(bufferData);
  3358. if (lineLeftovers) {
  3359. this.linesCache[0] = Buffer.concat([lineLeftovers, this.linesCache[0]]);
  3360. }
  3361. }
  3362. return totalBytesRead;
  3363. }
  3364. }, {
  3365. key: "next",
  3366. value: function next() {
  3367. if (!this.fd) return false;
  3368. var line = false;
  3369. if (this.eofReached && this.linesCache.length === 0) {
  3370. return line;
  3371. }
  3372. var bytesRead;
  3373. if (!this.linesCache.length) {
  3374. bytesRead = this._readChunk();
  3375. }
  3376. if (this.linesCache.length) {
  3377. line = this.linesCache.shift();
  3378. var lastLineCharacter = line[line.length - 1];
  3379. if (lastLineCharacter !== 0x0a) {
  3380. bytesRead = this._readChunk(line);
  3381. if (bytesRead) {
  3382. line = this.linesCache.shift();
  3383. }
  3384. }
  3385. }
  3386. if (this.eofReached && this.linesCache.length === 0) {
  3387. this.close();
  3388. }
  3389. if (line && line[line.length - 1] === this.newLineCharacter) {
  3390. line = line.slice(0, line.length - 1);
  3391. }
  3392. return line;
  3393. }
  3394. }]);
  3395. return LineByLine;
  3396. }();
  3397. var readlines = LineByLine;
  3398. var ConfigError =
  3399. /*#__PURE__*/
  3400. function (_Error) {
  3401. _inherits(ConfigError, _Error);
  3402. function ConfigError() {
  3403. _classCallCheck(this, ConfigError);
  3404. return _possibleConstructorReturn(this, _getPrototypeOf(ConfigError).apply(this, arguments));
  3405. }
  3406. return ConfigError;
  3407. }(_wrapNativeSuper(Error));
  3408. var DebugError =
  3409. /*#__PURE__*/
  3410. function (_Error2) {
  3411. _inherits(DebugError, _Error2);
  3412. function DebugError() {
  3413. _classCallCheck(this, DebugError);
  3414. return _possibleConstructorReturn(this, _getPrototypeOf(DebugError).apply(this, arguments));
  3415. }
  3416. return DebugError;
  3417. }(_wrapNativeSuper(Error));
  3418. var UndefinedParserError =
  3419. /*#__PURE__*/
  3420. function (_Error3) {
  3421. _inherits(UndefinedParserError, _Error3);
  3422. function UndefinedParserError() {
  3423. _classCallCheck(this, UndefinedParserError);
  3424. return _possibleConstructorReturn(this, _getPrototypeOf(UndefinedParserError).apply(this, arguments));
  3425. }
  3426. return UndefinedParserError;
  3427. }(_wrapNativeSuper(Error));
  3428. var errors = {
  3429. ConfigError: ConfigError,
  3430. DebugError: DebugError,
  3431. UndefinedParserError: UndefinedParserError
  3432. };
  3433. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  3434. function defaultSetTimout() {
  3435. throw new Error('setTimeout has not been defined');
  3436. }
  3437. function defaultClearTimeout() {
  3438. throw new Error('clearTimeout has not been defined');
  3439. }
  3440. var cachedSetTimeout = defaultSetTimout;
  3441. var cachedClearTimeout = defaultClearTimeout;
  3442. if (typeof global$1.setTimeout === 'function') {
  3443. cachedSetTimeout = setTimeout;
  3444. }
  3445. if (typeof global$1.clearTimeout === 'function') {
  3446. cachedClearTimeout = clearTimeout;
  3447. }
  3448. function runTimeout(fun) {
  3449. if (cachedSetTimeout === setTimeout) {
  3450. //normal enviroments in sane situations
  3451. return setTimeout(fun, 0);
  3452. } // if setTimeout wasn't available but was latter defined
  3453. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  3454. cachedSetTimeout = setTimeout;
  3455. return setTimeout(fun, 0);
  3456. }
  3457. try {
  3458. // when when somebody has screwed with setTimeout but no I.E. maddness
  3459. return cachedSetTimeout(fun, 0);
  3460. } catch (e) {
  3461. try {
  3462. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3463. return cachedSetTimeout.call(null, fun, 0);
  3464. } catch (e) {
  3465. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  3466. return cachedSetTimeout.call(this, fun, 0);
  3467. }
  3468. }
  3469. }
  3470. function runClearTimeout(marker) {
  3471. if (cachedClearTimeout === clearTimeout) {
  3472. //normal enviroments in sane situations
  3473. return clearTimeout(marker);
  3474. } // if clearTimeout wasn't available but was latter defined
  3475. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  3476. cachedClearTimeout = clearTimeout;
  3477. return clearTimeout(marker);
  3478. }
  3479. try {
  3480. // when when somebody has screwed with setTimeout but no I.E. maddness
  3481. return cachedClearTimeout(marker);
  3482. } catch (e) {
  3483. try {
  3484. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3485. return cachedClearTimeout.call(null, marker);
  3486. } catch (e) {
  3487. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  3488. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  3489. return cachedClearTimeout.call(this, marker);
  3490. }
  3491. }
  3492. }
  3493. var queue = [];
  3494. var draining = false;
  3495. var currentQueue;
  3496. var queueIndex = -1;
  3497. function cleanUpNextTick() {
  3498. if (!draining || !currentQueue) {
  3499. return;
  3500. }
  3501. draining = false;
  3502. if (currentQueue.length) {
  3503. queue = currentQueue.concat(queue);
  3504. } else {
  3505. queueIndex = -1;
  3506. }
  3507. if (queue.length) {
  3508. drainQueue();
  3509. }
  3510. }
  3511. function drainQueue() {
  3512. if (draining) {
  3513. return;
  3514. }
  3515. var timeout = runTimeout(cleanUpNextTick);
  3516. draining = true;
  3517. var len = queue.length;
  3518. while (len) {
  3519. currentQueue = queue;
  3520. queue = [];
  3521. while (++queueIndex < len) {
  3522. if (currentQueue) {
  3523. currentQueue[queueIndex].run();
  3524. }
  3525. }
  3526. queueIndex = -1;
  3527. len = queue.length;
  3528. }
  3529. currentQueue = null;
  3530. draining = false;
  3531. runClearTimeout(timeout);
  3532. }
  3533. function nextTick(fun) {
  3534. var args = new Array(arguments.length - 1);
  3535. if (arguments.length > 1) {
  3536. for (var i = 1; i < arguments.length; i++) {
  3537. args[i - 1] = arguments[i];
  3538. }
  3539. }
  3540. queue.push(new Item(fun, args));
  3541. if (queue.length === 1 && !draining) {
  3542. runTimeout(drainQueue);
  3543. }
  3544. } // v8 likes predictible objects
  3545. function Item(fun, array) {
  3546. this.fun = fun;
  3547. this.array = array;
  3548. }
  3549. Item.prototype.run = function () {
  3550. this.fun.apply(null, this.array);
  3551. };
  3552. var title = 'browser';
  3553. var platform = 'browser';
  3554. var browser = true;
  3555. var env = {};
  3556. var argv = [];
  3557. var version$1 = ''; // empty string to avoid regexp issues
  3558. var versions = {};
  3559. var release = {};
  3560. var config = {};
  3561. function noop() {}
  3562. var on = noop;
  3563. var addListener = noop;
  3564. var once = noop;
  3565. var off = noop;
  3566. var removeListener = noop;
  3567. var removeAllListeners = noop;
  3568. var emit = noop;
  3569. function binding(name) {
  3570. throw new Error('process.binding is not supported');
  3571. }
  3572. function cwd() {
  3573. return '/';
  3574. }
  3575. function chdir(dir) {
  3576. throw new Error('process.chdir is not supported');
  3577. }
  3578. function umask() {
  3579. return 0;
  3580. } // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  3581. var performance = global$1.performance || {};
  3582. var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function () {
  3583. return new Date().getTime();
  3584. }; // generate timestamp or delta
  3585. // see http://nodejs.org/api/process.html#process_process_hrtime
  3586. function hrtime(previousTimestamp) {
  3587. var clocktime = performanceNow.call(performance) * 1e-3;
  3588. var seconds = Math.floor(clocktime);
  3589. var nanoseconds = Math.floor(clocktime % 1 * 1e9);
  3590. if (previousTimestamp) {
  3591. seconds = seconds - previousTimestamp[0];
  3592. nanoseconds = nanoseconds - previousTimestamp[1];
  3593. if (nanoseconds < 0) {
  3594. seconds--;
  3595. nanoseconds += 1e9;
  3596. }
  3597. }
  3598. return [seconds, nanoseconds];
  3599. }
  3600. var startTime = new Date();
  3601. function uptime() {
  3602. var currentTime = new Date();
  3603. var dif = currentTime - startTime;
  3604. return dif / 1000;
  3605. }
  3606. var process = {
  3607. nextTick: nextTick,
  3608. title: title,
  3609. browser: browser,
  3610. env: env,
  3611. argv: argv,
  3612. version: version$1,
  3613. versions: versions,
  3614. on: on,
  3615. addListener: addListener,
  3616. once: once,
  3617. off: off,
  3618. removeListener: removeListener,
  3619. removeAllListeners: removeAllListeners,
  3620. emit: emit,
  3621. binding: binding,
  3622. cwd: cwd,
  3623. chdir: chdir,
  3624. umask: umask,
  3625. hrtime: hrtime,
  3626. platform: platform,
  3627. release: release,
  3628. config: config,
  3629. uptime: uptime
  3630. };
  3631. var semver = createCommonjsModule(function (module, exports) {
  3632. exports = module.exports = SemVer;
  3633. var debug;
  3634. /* istanbul ignore next */
  3635. if (_typeof(process) === 'object' && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
  3636. debug = function debug() {
  3637. var args = Array.prototype.slice.call(arguments, 0);
  3638. args.unshift('SEMVER');
  3639. console.log.apply(console, args);
  3640. };
  3641. } else {
  3642. debug = function debug() {};
  3643. } // Note: this is the semver.org version of the spec that it implements
  3644. // Not necessarily the package version of this code.
  3645. exports.SEMVER_SPEC_VERSION = '2.0.0';
  3646. var MAX_LENGTH = 256;
  3647. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
  3648. /* istanbul ignore next */
  3649. 9007199254740991; // Max safe segment length for coercion.
  3650. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  3651. var re = exports.re = [];
  3652. var src = exports.src = [];
  3653. var t = exports.tokens = {};
  3654. var R = 0;
  3655. function tok(n) {
  3656. t[n] = R++;
  3657. } // The following Regular Expressions can be used for tokenizing,
  3658. // validating, and parsing SemVer version strings.
  3659. // ## Numeric Identifier
  3660. // A single `0`, or a non-zero digit followed by zero or more digits.
  3661. tok('NUMERICIDENTIFIER');
  3662. src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  3663. tok('NUMERICIDENTIFIERLOOSE');
  3664. src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  3665. // Zero or more digits, followed by a letter or hyphen, and then zero or
  3666. // more letters, digits, or hyphens.
  3667. tok('NONNUMERICIDENTIFIER');
  3668. src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  3669. // Three dot-separated numeric identifiers.
  3670. tok('MAINVERSION');
  3671. src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' + '(' + src[t.NUMERICIDENTIFIER] + ')\\.' + '(' + src[t.NUMERICIDENTIFIER] + ')';
  3672. tok('MAINVERSIONLOOSE');
  3673. src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  3674. // A numeric identifier, or a non-numeric identifier.
  3675. tok('PRERELEASEIDENTIFIER');
  3676. src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] + '|' + src[t.NONNUMERICIDENTIFIER] + ')';
  3677. tok('PRERELEASEIDENTIFIERLOOSE');
  3678. src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] + '|' + src[t.NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  3679. // Hyphen, followed by one or more dot-separated pre-release version
  3680. // identifiers.
  3681. tok('PRERELEASE');
  3682. src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] + '(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))';
  3683. tok('PRERELEASELOOSE');
  3684. src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  3685. // Any combination of digits, letters, or hyphens.
  3686. tok('BUILDIDENTIFIER');
  3687. src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  3688. // Plus sign, followed by one or more period-separated build metadata
  3689. // identifiers.
  3690. tok('BUILD');
  3691. src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] + '(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  3692. // A main version, followed optionally by a pre-release version and
  3693. // build metadata.
  3694. // Note that the only major, minor, patch, and pre-release sections of
  3695. // the version string are capturing groups. The build metadata is not a
  3696. // capturing group, because it should not ever be used in version
  3697. // comparison.
  3698. tok('FULL');
  3699. tok('FULLPLAIN');
  3700. src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] + src[t.PRERELEASE] + '?' + src[t.BUILD] + '?';
  3701. src[t.FULL] = '^' + src[t.FULLPLAIN] + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  3702. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  3703. // common in the npm registry.
  3704. tok('LOOSEPLAIN');
  3705. src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] + src[t.PRERELEASELOOSE] + '?' + src[t.BUILD] + '?';
  3706. tok('LOOSE');
  3707. src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$';
  3708. tok('GTLT');
  3709. src[t.GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  3710. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  3711. // Only the first item is strictly required.
  3712. tok('XRANGEIDENTIFIERLOOSE');
  3713. src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  3714. tok('XRANGEIDENTIFIER');
  3715. src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*';
  3716. tok('XRANGEPLAIN');
  3717. src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:' + src[t.PRERELEASE] + ')?' + src[t.BUILD] + '?' + ')?)?';
  3718. tok('XRANGEPLAINLOOSE');
  3719. src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[t.PRERELEASELOOSE] + ')?' + src[t.BUILD] + '?' + ')?)?';
  3720. tok('XRANGE');
  3721. src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$';
  3722. tok('XRANGELOOSE');
  3723. src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$'; // Coercion.
  3724. // Extract anything that could conceivably be a part of a valid semver
  3725. tok('COERCE');
  3726. src[t.COERCE] = '(^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])';
  3727. tok('COERCERTL');
  3728. re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g'); // Tilde ranges.
  3729. // Meaning is "reasonably at or greater than"
  3730. tok('LONETILDE');
  3731. src[t.LONETILDE] = '(?:~>?)';
  3732. tok('TILDETRIM');
  3733. src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+';
  3734. re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g');
  3735. var tildeTrimReplace = '$1~';
  3736. tok('TILDE');
  3737. src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$';
  3738. tok('TILDELOOSE');
  3739. src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  3740. // Meaning is "at least and backwards compatible with"
  3741. tok('LONECARET');
  3742. src[t.LONECARET] = '(?:\\^)';
  3743. tok('CARETTRIM');
  3744. src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+';
  3745. re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g');
  3746. var caretTrimReplace = '$1^';
  3747. tok('CARET');
  3748. src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$';
  3749. tok('CARETLOOSE');
  3750. src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  3751. tok('COMPARATORLOOSE');
  3752. src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$';
  3753. tok('COMPARATOR');
  3754. src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  3755. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  3756. tok('COMPARATORTRIM');
  3757. src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')'; // this one has to use the /g flag
  3758. re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g');
  3759. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  3760. // Note that these all use the loose form, because they'll be
  3761. // checked against either the strict or loose comparator form
  3762. // later.
  3763. tok('HYPHENRANGE');
  3764. src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[t.XRANGEPLAIN] + ')' + '\\s*$';
  3765. tok('HYPHENRANGELOOSE');
  3766. src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[t.XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  3767. tok('STAR');
  3768. src[t.STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  3769. // All are flag-free, unless they were created above with a flag.
  3770. for (var i = 0; i < R; i++) {
  3771. debug(i, src[i]);
  3772. if (!re[i]) {
  3773. re[i] = new RegExp(src[i]);
  3774. }
  3775. }
  3776. exports.parse = parse;
  3777. function parse(version, options) {
  3778. if (!options || _typeof(options) !== 'object') {
  3779. options = {
  3780. loose: !!options,
  3781. includePrerelease: false
  3782. };
  3783. }
  3784. if (version instanceof SemVer) {
  3785. return version;
  3786. }
  3787. if (typeof version !== 'string') {
  3788. return null;
  3789. }
  3790. if (version.length > MAX_LENGTH) {
  3791. return null;
  3792. }
  3793. var r = options.loose ? re[t.LOOSE] : re[t.FULL];
  3794. if (!r.test(version)) {
  3795. return null;
  3796. }
  3797. try {
  3798. return new SemVer(version, options);
  3799. } catch (er) {
  3800. return null;
  3801. }
  3802. }
  3803. exports.valid = valid;
  3804. function valid(version, options) {
  3805. var v = parse(version, options);
  3806. return v ? v.version : null;
  3807. }
  3808. exports.clean = clean;
  3809. function clean(version, options) {
  3810. var s = parse(version.trim().replace(/^[=v]+/, ''), options);
  3811. return s ? s.version : null;
  3812. }
  3813. exports.SemVer = SemVer;
  3814. function SemVer(version, options) {
  3815. if (!options || _typeof(options) !== 'object') {
  3816. options = {
  3817. loose: !!options,
  3818. includePrerelease: false
  3819. };
  3820. }
  3821. if (version instanceof SemVer) {
  3822. if (version.loose === options.loose) {
  3823. return version;
  3824. } else {
  3825. version = version.version;
  3826. }
  3827. } else if (typeof version !== 'string') {
  3828. throw new TypeError('Invalid Version: ' + version);
  3829. }
  3830. if (version.length > MAX_LENGTH) {
  3831. throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  3832. }
  3833. if (!(this instanceof SemVer)) {
  3834. return new SemVer(version, options);
  3835. }
  3836. debug('SemVer', version, options);
  3837. this.options = options;
  3838. this.loose = !!options.loose;
  3839. var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
  3840. if (!m) {
  3841. throw new TypeError('Invalid Version: ' + version);
  3842. }
  3843. this.raw = version; // these are actually numbers
  3844. this.major = +m[1];
  3845. this.minor = +m[2];
  3846. this.patch = +m[3];
  3847. if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
  3848. throw new TypeError('Invalid major version');
  3849. }
  3850. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
  3851. throw new TypeError('Invalid minor version');
  3852. }
  3853. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
  3854. throw new TypeError('Invalid patch version');
  3855. } // numberify any prerelease numeric ids
  3856. if (!m[4]) {
  3857. this.prerelease = [];
  3858. } else {
  3859. this.prerelease = m[4].split('.').map(function (id) {
  3860. if (/^[0-9]+$/.test(id)) {
  3861. var num = +id;
  3862. if (num >= 0 && num < MAX_SAFE_INTEGER) {
  3863. return num;
  3864. }
  3865. }
  3866. return id;
  3867. });
  3868. }
  3869. this.build = m[5] ? m[5].split('.') : [];
  3870. this.format();
  3871. }
  3872. SemVer.prototype.format = function () {
  3873. this.version = this.major + '.' + this.minor + '.' + this.patch;
  3874. if (this.prerelease.length) {
  3875. this.version += '-' + this.prerelease.join('.');
  3876. }
  3877. return this.version;
  3878. };
  3879. SemVer.prototype.toString = function () {
  3880. return this.version;
  3881. };
  3882. SemVer.prototype.compare = function (other) {
  3883. debug('SemVer.compare', this.version, this.options, other);
  3884. if (!(other instanceof SemVer)) {
  3885. other = new SemVer(other, this.options);
  3886. }
  3887. return this.compareMain(other) || this.comparePre(other);
  3888. };
  3889. SemVer.prototype.compareMain = function (other) {
  3890. if (!(other instanceof SemVer)) {
  3891. other = new SemVer(other, this.options);
  3892. }
  3893. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  3894. };
  3895. SemVer.prototype.comparePre = function (other) {
  3896. if (!(other instanceof SemVer)) {
  3897. other = new SemVer(other, this.options);
  3898. } // NOT having a prerelease is > having one
  3899. if (this.prerelease.length && !other.prerelease.length) {
  3900. return -1;
  3901. } else if (!this.prerelease.length && other.prerelease.length) {
  3902. return 1;
  3903. } else if (!this.prerelease.length && !other.prerelease.length) {
  3904. return 0;
  3905. }
  3906. var i = 0;
  3907. do {
  3908. var a = this.prerelease[i];
  3909. var b = other.prerelease[i];
  3910. debug('prerelease compare', i, a, b);
  3911. if (a === undefined && b === undefined) {
  3912. return 0;
  3913. } else if (b === undefined) {
  3914. return 1;
  3915. } else if (a === undefined) {
  3916. return -1;
  3917. } else if (a === b) {
  3918. continue;
  3919. } else {
  3920. return compareIdentifiers(a, b);
  3921. }
  3922. } while (++i);
  3923. };
  3924. SemVer.prototype.compareBuild = function (other) {
  3925. if (!(other instanceof SemVer)) {
  3926. other = new SemVer(other, this.options);
  3927. }
  3928. var i = 0;
  3929. do {
  3930. var a = this.build[i];
  3931. var b = other.build[i];
  3932. debug('prerelease compare', i, a, b);
  3933. if (a === undefined && b === undefined) {
  3934. return 0;
  3935. } else if (b === undefined) {
  3936. return 1;
  3937. } else if (a === undefined) {
  3938. return -1;
  3939. } else if (a === b) {
  3940. continue;
  3941. } else {
  3942. return compareIdentifiers(a, b);
  3943. }
  3944. } while (++i);
  3945. }; // preminor will bump the version up to the next minor release, and immediately
  3946. // down to pre-release. premajor and prepatch work the same way.
  3947. SemVer.prototype.inc = function (release, identifier) {
  3948. switch (release) {
  3949. case 'premajor':
  3950. this.prerelease.length = 0;
  3951. this.patch = 0;
  3952. this.minor = 0;
  3953. this.major++;
  3954. this.inc('pre', identifier);
  3955. break;
  3956. case 'preminor':
  3957. this.prerelease.length = 0;
  3958. this.patch = 0;
  3959. this.minor++;
  3960. this.inc('pre', identifier);
  3961. break;
  3962. case 'prepatch':
  3963. // If this is already a prerelease, it will bump to the next version
  3964. // drop any prereleases that might already exist, since they are not
  3965. // relevant at this point.
  3966. this.prerelease.length = 0;
  3967. this.inc('patch', identifier);
  3968. this.inc('pre', identifier);
  3969. break;
  3970. // If the input is a non-prerelease version, this acts the same as
  3971. // prepatch.
  3972. case 'prerelease':
  3973. if (this.prerelease.length === 0) {
  3974. this.inc('patch', identifier);
  3975. }
  3976. this.inc('pre', identifier);
  3977. break;
  3978. case 'major':
  3979. // If this is a pre-major version, bump up to the same major version.
  3980. // Otherwise increment major.
  3981. // 1.0.0-5 bumps to 1.0.0
  3982. // 1.1.0 bumps to 2.0.0
  3983. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
  3984. this.major++;
  3985. }
  3986. this.minor = 0;
  3987. this.patch = 0;
  3988. this.prerelease = [];
  3989. break;
  3990. case 'minor':
  3991. // If this is a pre-minor version, bump up to the same minor version.
  3992. // Otherwise increment minor.
  3993. // 1.2.0-5 bumps to 1.2.0
  3994. // 1.2.1 bumps to 1.3.0
  3995. if (this.patch !== 0 || this.prerelease.length === 0) {
  3996. this.minor++;
  3997. }
  3998. this.patch = 0;
  3999. this.prerelease = [];
  4000. break;
  4001. case 'patch':
  4002. // If this is not a pre-release version, it will increment the patch.
  4003. // If it is a pre-release it will bump up to the same patch version.
  4004. // 1.2.0-5 patches to 1.2.0
  4005. // 1.2.0 patches to 1.2.1
  4006. if (this.prerelease.length === 0) {
  4007. this.patch++;
  4008. }
  4009. this.prerelease = [];
  4010. break;
  4011. // This probably shouldn't be used publicly.
  4012. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  4013. case 'pre':
  4014. if (this.prerelease.length === 0) {
  4015. this.prerelease = [0];
  4016. } else {
  4017. var i = this.prerelease.length;
  4018. while (--i >= 0) {
  4019. if (typeof this.prerelease[i] === 'number') {
  4020. this.prerelease[i]++;
  4021. i = -2;
  4022. }
  4023. }
  4024. if (i === -1) {
  4025. // didn't increment anything
  4026. this.prerelease.push(0);
  4027. }
  4028. }
  4029. if (identifier) {
  4030. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  4031. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  4032. if (this.prerelease[0] === identifier) {
  4033. if (isNaN(this.prerelease[1])) {
  4034. this.prerelease = [identifier, 0];
  4035. }
  4036. } else {
  4037. this.prerelease = [identifier, 0];
  4038. }
  4039. }
  4040. break;
  4041. default:
  4042. throw new Error('invalid increment argument: ' + release);
  4043. }
  4044. this.format();
  4045. this.raw = this.version;
  4046. return this;
  4047. };
  4048. exports.inc = inc;
  4049. function inc(version, release, loose, identifier) {
  4050. if (typeof loose === 'string') {
  4051. identifier = loose;
  4052. loose = undefined;
  4053. }
  4054. try {
  4055. return new SemVer(version, loose).inc(release, identifier).version;
  4056. } catch (er) {
  4057. return null;
  4058. }
  4059. }
  4060. exports.diff = diff;
  4061. function diff(version1, version2) {
  4062. if (eq(version1, version2)) {
  4063. return null;
  4064. } else {
  4065. var v1 = parse(version1);
  4066. var v2 = parse(version2);
  4067. var prefix = '';
  4068. if (v1.prerelease.length || v2.prerelease.length) {
  4069. prefix = 'pre';
  4070. var defaultResult = 'prerelease';
  4071. }
  4072. for (var key in v1) {
  4073. if (key === 'major' || key === 'minor' || key === 'patch') {
  4074. if (v1[key] !== v2[key]) {
  4075. return prefix + key;
  4076. }
  4077. }
  4078. }
  4079. return defaultResult; // may be undefined
  4080. }
  4081. }
  4082. exports.compareIdentifiers = compareIdentifiers;
  4083. var numeric = /^[0-9]+$/;
  4084. function compareIdentifiers(a, b) {
  4085. var anum = numeric.test(a);
  4086. var bnum = numeric.test(b);
  4087. if (anum && bnum) {
  4088. a = +a;
  4089. b = +b;
  4090. }
  4091. return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
  4092. }
  4093. exports.rcompareIdentifiers = rcompareIdentifiers;
  4094. function rcompareIdentifiers(a, b) {
  4095. return compareIdentifiers(b, a);
  4096. }
  4097. exports.major = major;
  4098. function major(a, loose) {
  4099. return new SemVer(a, loose).major;
  4100. }
  4101. exports.minor = minor;
  4102. function minor(a, loose) {
  4103. return new SemVer(a, loose).minor;
  4104. }
  4105. exports.patch = patch;
  4106. function patch(a, loose) {
  4107. return new SemVer(a, loose).patch;
  4108. }
  4109. exports.compare = compare;
  4110. function compare(a, b, loose) {
  4111. return new SemVer(a, loose).compare(new SemVer(b, loose));
  4112. }
  4113. exports.compareLoose = compareLoose;
  4114. function compareLoose(a, b) {
  4115. return compare(a, b, true);
  4116. }
  4117. exports.compareBuild = compareBuild;
  4118. function compareBuild(a, b, loose) {
  4119. var versionA = new SemVer(a, loose);
  4120. var versionB = new SemVer(b, loose);
  4121. return versionA.compare(versionB) || versionA.compareBuild(versionB);
  4122. }
  4123. exports.rcompare = rcompare;
  4124. function rcompare(a, b, loose) {
  4125. return compare(b, a, loose);
  4126. }
  4127. exports.sort = sort;
  4128. function sort(list, loose) {
  4129. return list.sort(function (a, b) {
  4130. return exports.compareBuild(a, b, loose);
  4131. });
  4132. }
  4133. exports.rsort = rsort;
  4134. function rsort(list, loose) {
  4135. return list.sort(function (a, b) {
  4136. return exports.compareBuild(b, a, loose);
  4137. });
  4138. }
  4139. exports.gt = gt;
  4140. function gt(a, b, loose) {
  4141. return compare(a, b, loose) > 0;
  4142. }
  4143. exports.lt = lt;
  4144. function lt(a, b, loose) {
  4145. return compare(a, b, loose) < 0;
  4146. }
  4147. exports.eq = eq;
  4148. function eq(a, b, loose) {
  4149. return compare(a, b, loose) === 0;
  4150. }
  4151. exports.neq = neq;
  4152. function neq(a, b, loose) {
  4153. return compare(a, b, loose) !== 0;
  4154. }
  4155. exports.gte = gte;
  4156. function gte(a, b, loose) {
  4157. return compare(a, b, loose) >= 0;
  4158. }
  4159. exports.lte = lte;
  4160. function lte(a, b, loose) {
  4161. return compare(a, b, loose) <= 0;
  4162. }
  4163. exports.cmp = cmp;
  4164. function cmp(a, op, b, loose) {
  4165. switch (op) {
  4166. case '===':
  4167. if (_typeof(a) === 'object') a = a.version;
  4168. if (_typeof(b) === 'object') b = b.version;
  4169. return a === b;
  4170. case '!==':
  4171. if (_typeof(a) === 'object') a = a.version;
  4172. if (_typeof(b) === 'object') b = b.version;
  4173. return a !== b;
  4174. case '':
  4175. case '=':
  4176. case '==':
  4177. return eq(a, b, loose);
  4178. case '!=':
  4179. return neq(a, b, loose);
  4180. case '>':
  4181. return gt(a, b, loose);
  4182. case '>=':
  4183. return gte(a, b, loose);
  4184. case '<':
  4185. return lt(a, b, loose);
  4186. case '<=':
  4187. return lte(a, b, loose);
  4188. default:
  4189. throw new TypeError('Invalid operator: ' + op);
  4190. }
  4191. }
  4192. exports.Comparator = Comparator;
  4193. function Comparator(comp, options) {
  4194. if (!options || _typeof(options) !== 'object') {
  4195. options = {
  4196. loose: !!options,
  4197. includePrerelease: false
  4198. };
  4199. }
  4200. if (comp instanceof Comparator) {
  4201. if (comp.loose === !!options.loose) {
  4202. return comp;
  4203. } else {
  4204. comp = comp.value;
  4205. }
  4206. }
  4207. if (!(this instanceof Comparator)) {
  4208. return new Comparator(comp, options);
  4209. }
  4210. debug('comparator', comp, options);
  4211. this.options = options;
  4212. this.loose = !!options.loose;
  4213. this.parse(comp);
  4214. if (this.semver === ANY) {
  4215. this.value = '';
  4216. } else {
  4217. this.value = this.operator + this.semver.version;
  4218. }
  4219. debug('comp', this);
  4220. }
  4221. var ANY = {};
  4222. Comparator.prototype.parse = function (comp) {
  4223. var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
  4224. var m = comp.match(r);
  4225. if (!m) {
  4226. throw new TypeError('Invalid comparator: ' + comp);
  4227. }
  4228. this.operator = m[1] !== undefined ? m[1] : '';
  4229. if (this.operator === '=') {
  4230. this.operator = '';
  4231. } // if it literally is just '>' or '' then allow anything.
  4232. if (!m[2]) {
  4233. this.semver = ANY;
  4234. } else {
  4235. this.semver = new SemVer(m[2], this.options.loose);
  4236. }
  4237. };
  4238. Comparator.prototype.toString = function () {
  4239. return this.value;
  4240. };
  4241. Comparator.prototype.test = function (version) {
  4242. debug('Comparator.test', version, this.options.loose);
  4243. if (this.semver === ANY || version === ANY) {
  4244. return true;
  4245. }
  4246. if (typeof version === 'string') {
  4247. try {
  4248. version = new SemVer(version, this.options);
  4249. } catch (er) {
  4250. return false;
  4251. }
  4252. }
  4253. return cmp(version, this.operator, this.semver, this.options);
  4254. };
  4255. Comparator.prototype.intersects = function (comp, options) {
  4256. if (!(comp instanceof Comparator)) {
  4257. throw new TypeError('a Comparator is required');
  4258. }
  4259. if (!options || _typeof(options) !== 'object') {
  4260. options = {
  4261. loose: !!options,
  4262. includePrerelease: false
  4263. };
  4264. }
  4265. var rangeTmp;
  4266. if (this.operator === '') {
  4267. if (this.value === '') {
  4268. return true;
  4269. }
  4270. rangeTmp = new Range(comp.value, options);
  4271. return satisfies(this.value, rangeTmp, options);
  4272. } else if (comp.operator === '') {
  4273. if (comp.value === '') {
  4274. return true;
  4275. }
  4276. rangeTmp = new Range(this.value, options);
  4277. return satisfies(comp.semver, rangeTmp, options);
  4278. }
  4279. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  4280. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  4281. var sameSemVer = this.semver.version === comp.semver.version;
  4282. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  4283. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, options) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  4284. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, options) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  4285. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  4286. };
  4287. exports.Range = Range;
  4288. function Range(range, options) {
  4289. if (!options || _typeof(options) !== 'object') {
  4290. options = {
  4291. loose: !!options,
  4292. includePrerelease: false
  4293. };
  4294. }
  4295. if (range instanceof Range) {
  4296. if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
  4297. return range;
  4298. } else {
  4299. return new Range(range.raw, options);
  4300. }
  4301. }
  4302. if (range instanceof Comparator) {
  4303. return new Range(range.value, options);
  4304. }
  4305. if (!(this instanceof Range)) {
  4306. return new Range(range, options);
  4307. }
  4308. this.options = options;
  4309. this.loose = !!options.loose;
  4310. this.includePrerelease = !!options.includePrerelease; // First, split based on boolean or ||
  4311. this.raw = range;
  4312. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  4313. return this.parseRange(range.trim());
  4314. }, this).filter(function (c) {
  4315. // throw out any that are not relevant for whatever reason
  4316. return c.length;
  4317. });
  4318. if (!this.set.length) {
  4319. throw new TypeError('Invalid SemVer Range: ' + range);
  4320. }
  4321. this.format();
  4322. }
  4323. Range.prototype.format = function () {
  4324. this.range = this.set.map(function (comps) {
  4325. return comps.join(' ').trim();
  4326. }).join('||').trim();
  4327. return this.range;
  4328. };
  4329. Range.prototype.toString = function () {
  4330. return this.range;
  4331. };
  4332. Range.prototype.parseRange = function (range) {
  4333. var loose = this.options.loose;
  4334. range = range.trim(); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  4335. var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
  4336. range = range.replace(hr, hyphenReplace);
  4337. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  4338. range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
  4339. debug('comparator trim', range, re[t.COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  4340. range = range.replace(re[t.TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  4341. range = range.replace(re[t.CARETTRIM], caretTrimReplace); // normalize spaces
  4342. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  4343. // ready to be split into comparators.
  4344. var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
  4345. var set = range.split(' ').map(function (comp) {
  4346. return parseComparator(comp, this.options);
  4347. }, this).join(' ').split(/\s+/);
  4348. if (this.options.loose) {
  4349. // in loose mode, throw out any that are not valid comparators
  4350. set = set.filter(function (comp) {
  4351. return !!comp.match(compRe);
  4352. });
  4353. }
  4354. set = set.map(function (comp) {
  4355. return new Comparator(comp, this.options);
  4356. }, this);
  4357. return set;
  4358. };
  4359. Range.prototype.intersects = function (range, options) {
  4360. if (!(range instanceof Range)) {
  4361. throw new TypeError('a Range is required');
  4362. }
  4363. return this.set.some(function (thisComparators) {
  4364. return isSatisfiable(thisComparators, options) && range.set.some(function (rangeComparators) {
  4365. return isSatisfiable(rangeComparators, options) && thisComparators.every(function (thisComparator) {
  4366. return rangeComparators.every(function (rangeComparator) {
  4367. return thisComparator.intersects(rangeComparator, options);
  4368. });
  4369. });
  4370. });
  4371. });
  4372. }; // take a set of comparators and determine whether there
  4373. // exists a version which can satisfy it
  4374. function isSatisfiable(comparators, options) {
  4375. var result = true;
  4376. var remainingComparators = comparators.slice();
  4377. var testComparator = remainingComparators.pop();
  4378. while (result && remainingComparators.length) {
  4379. result = remainingComparators.every(function (otherComparator) {
  4380. return testComparator.intersects(otherComparator, options);
  4381. });
  4382. testComparator = remainingComparators.pop();
  4383. }
  4384. return result;
  4385. } // Mostly just for testing and legacy API reasons
  4386. exports.toComparators = toComparators;
  4387. function toComparators(range, options) {
  4388. return new Range(range, options).set.map(function (comp) {
  4389. return comp.map(function (c) {
  4390. return c.value;
  4391. }).join(' ').trim().split(' ');
  4392. });
  4393. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  4394. // already replaced the hyphen ranges
  4395. // turn into a set of JUST comparators.
  4396. function parseComparator(comp, options) {
  4397. debug('comp', comp, options);
  4398. comp = replaceCarets(comp, options);
  4399. debug('caret', comp);
  4400. comp = replaceTildes(comp, options);
  4401. debug('tildes', comp);
  4402. comp = replaceXRanges(comp, options);
  4403. debug('xrange', comp);
  4404. comp = replaceStars(comp, options);
  4405. debug('stars', comp);
  4406. return comp;
  4407. }
  4408. function isX(id) {
  4409. return !id || id.toLowerCase() === 'x' || id === '*';
  4410. } // ~, ~> --> * (any, kinda silly)
  4411. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  4412. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  4413. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  4414. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  4415. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  4416. function replaceTildes(comp, options) {
  4417. return comp.trim().split(/\s+/).map(function (comp) {
  4418. return replaceTilde(comp, options);
  4419. }).join(' ');
  4420. }
  4421. function replaceTilde(comp, options) {
  4422. var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
  4423. return comp.replace(r, function (_, M, m, p, pr) {
  4424. debug('tilde', comp, _, M, m, p, pr);
  4425. var ret;
  4426. if (isX(M)) {
  4427. ret = '';
  4428. } else if (isX(m)) {
  4429. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  4430. } else if (isX(p)) {
  4431. // ~1.2 == >=1.2.0 <1.3.0
  4432. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  4433. } else if (pr) {
  4434. debug('replaceTilde pr', pr);
  4435. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
  4436. } else {
  4437. // ~1.2.3 == >=1.2.3 <1.3.0
  4438. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  4439. }
  4440. debug('tilde return', ret);
  4441. return ret;
  4442. });
  4443. } // ^ --> * (any, kinda silly)
  4444. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  4445. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  4446. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  4447. // ^1.2.3 --> >=1.2.3 <2.0.0
  4448. // ^1.2.0 --> >=1.2.0 <2.0.0
  4449. function replaceCarets(comp, options) {
  4450. return comp.trim().split(/\s+/).map(function (comp) {
  4451. return replaceCaret(comp, options);
  4452. }).join(' ');
  4453. }
  4454. function replaceCaret(comp, options) {
  4455. debug('caret', comp, options);
  4456. var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
  4457. return comp.replace(r, function (_, M, m, p, pr) {
  4458. debug('caret', comp, _, M, m, p, pr);
  4459. var ret;
  4460. if (isX(M)) {
  4461. ret = '';
  4462. } else if (isX(m)) {
  4463. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  4464. } else if (isX(p)) {
  4465. if (M === '0') {
  4466. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  4467. } else {
  4468. ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  4469. }
  4470. } else if (pr) {
  4471. debug('replaceCaret pr', pr);
  4472. if (M === '0') {
  4473. if (m === '0') {
  4474. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + m + '.' + (+p + 1);
  4475. } else {
  4476. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
  4477. }
  4478. } else {
  4479. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + (+M + 1) + '.0.0';
  4480. }
  4481. } else {
  4482. debug('no pr');
  4483. if (M === '0') {
  4484. if (m === '0') {
  4485. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);
  4486. } else {
  4487. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  4488. }
  4489. } else {
  4490. ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  4491. }
  4492. }
  4493. debug('caret return', ret);
  4494. return ret;
  4495. });
  4496. }
  4497. function replaceXRanges(comp, options) {
  4498. debug('replaceXRanges', comp, options);
  4499. return comp.split(/\s+/).map(function (comp) {
  4500. return replaceXRange(comp, options);
  4501. }).join(' ');
  4502. }
  4503. function replaceXRange(comp, options) {
  4504. comp = comp.trim();
  4505. var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
  4506. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  4507. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  4508. var xM = isX(M);
  4509. var xm = xM || isX(m);
  4510. var xp = xm || isX(p);
  4511. var anyX = xp;
  4512. if (gtlt === '=' && anyX) {
  4513. gtlt = '';
  4514. } // if we're including prereleases in the match, then we need
  4515. // to fix this to -0, the lowest possible prerelease value
  4516. pr = options.includePrerelease ? '-0' : '';
  4517. if (xM) {
  4518. if (gtlt === '>' || gtlt === '<') {
  4519. // nothing is allowed
  4520. ret = '<0.0.0-0';
  4521. } else {
  4522. // nothing is forbidden
  4523. ret = '*';
  4524. }
  4525. } else if (gtlt && anyX) {
  4526. // we know patch is an x, because we have any x at all.
  4527. // replace X with 0
  4528. if (xm) {
  4529. m = 0;
  4530. }
  4531. p = 0;
  4532. if (gtlt === '>') {
  4533. // >1 => >=2.0.0
  4534. // >1.2 => >=1.3.0
  4535. // >1.2.3 => >= 1.2.4
  4536. gtlt = '>=';
  4537. if (xm) {
  4538. M = +M + 1;
  4539. m = 0;
  4540. p = 0;
  4541. } else {
  4542. m = +m + 1;
  4543. p = 0;
  4544. }
  4545. } else if (gtlt === '<=') {
  4546. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  4547. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  4548. gtlt = '<';
  4549. if (xm) {
  4550. M = +M + 1;
  4551. } else {
  4552. m = +m + 1;
  4553. }
  4554. }
  4555. ret = gtlt + M + '.' + m + '.' + p + pr;
  4556. } else if (xm) {
  4557. ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr;
  4558. } else if (xp) {
  4559. ret = '>=' + M + '.' + m + '.0' + pr + ' <' + M + '.' + (+m + 1) + '.0' + pr;
  4560. }
  4561. debug('xRange return', ret);
  4562. return ret;
  4563. });
  4564. } // Because * is AND-ed with everything else in the comparator,
  4565. // and '' means "any version", just remove the *s entirely.
  4566. function replaceStars(comp, options) {
  4567. debug('replaceStars', comp, options); // Looseness is ignored here. star is always as loose as it gets!
  4568. return comp.trim().replace(re[t.STAR], '');
  4569. } // This function is passed to string.replace(re[t.HYPHENRANGE])
  4570. // M, m, patch, prerelease, build
  4571. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  4572. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  4573. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  4574. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  4575. if (isX(fM)) {
  4576. from = '';
  4577. } else if (isX(fm)) {
  4578. from = '>=' + fM + '.0.0';
  4579. } else if (isX(fp)) {
  4580. from = '>=' + fM + '.' + fm + '.0';
  4581. } else {
  4582. from = '>=' + from;
  4583. }
  4584. if (isX(tM)) {
  4585. to = '';
  4586. } else if (isX(tm)) {
  4587. to = '<' + (+tM + 1) + '.0.0';
  4588. } else if (isX(tp)) {
  4589. to = '<' + tM + '.' + (+tm + 1) + '.0';
  4590. } else if (tpr) {
  4591. to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  4592. } else {
  4593. to = '<=' + to;
  4594. }
  4595. return (from + ' ' + to).trim();
  4596. } // if ANY of the sets match ALL of its comparators, then pass
  4597. Range.prototype.test = function (version) {
  4598. if (!version) {
  4599. return false;
  4600. }
  4601. if (typeof version === 'string') {
  4602. try {
  4603. version = new SemVer(version, this.options);
  4604. } catch (er) {
  4605. return false;
  4606. }
  4607. }
  4608. for (var i = 0; i < this.set.length; i++) {
  4609. if (testSet(this.set[i], version, this.options)) {
  4610. return true;
  4611. }
  4612. }
  4613. return false;
  4614. };
  4615. function testSet(set, version, options) {
  4616. for (var i = 0; i < set.length; i++) {
  4617. if (!set[i].test(version)) {
  4618. return false;
  4619. }
  4620. }
  4621. if (version.prerelease.length && !options.includePrerelease) {
  4622. // Find the set of versions that are allowed to have prereleases
  4623. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  4624. // That should allow `1.2.3-pr.2` to pass.
  4625. // However, `1.2.4-alpha.notready` should NOT be allowed,
  4626. // even though it's within the range set by the comparators.
  4627. for (i = 0; i < set.length; i++) {
  4628. debug(set[i].semver);
  4629. if (set[i].semver === ANY) {
  4630. continue;
  4631. }
  4632. if (set[i].semver.prerelease.length > 0) {
  4633. var allowed = set[i].semver;
  4634. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
  4635. return true;
  4636. }
  4637. }
  4638. } // Version has a -pre, but it's not one of the ones we like.
  4639. return false;
  4640. }
  4641. return true;
  4642. }
  4643. exports.satisfies = satisfies;
  4644. function satisfies(version, range, options) {
  4645. try {
  4646. range = new Range(range, options);
  4647. } catch (er) {
  4648. return false;
  4649. }
  4650. return range.test(version);
  4651. }
  4652. exports.maxSatisfying = maxSatisfying;
  4653. function maxSatisfying(versions, range, options) {
  4654. var max = null;
  4655. var maxSV = null;
  4656. try {
  4657. var rangeObj = new Range(range, options);
  4658. } catch (er) {
  4659. return null;
  4660. }
  4661. versions.forEach(function (v) {
  4662. if (rangeObj.test(v)) {
  4663. // satisfies(v, range, options)
  4664. if (!max || maxSV.compare(v) === -1) {
  4665. // compare(max, v, true)
  4666. max = v;
  4667. maxSV = new SemVer(max, options);
  4668. }
  4669. }
  4670. });
  4671. return max;
  4672. }
  4673. exports.minSatisfying = minSatisfying;
  4674. function minSatisfying(versions, range, options) {
  4675. var min = null;
  4676. var minSV = null;
  4677. try {
  4678. var rangeObj = new Range(range, options);
  4679. } catch (er) {
  4680. return null;
  4681. }
  4682. versions.forEach(function (v) {
  4683. if (rangeObj.test(v)) {
  4684. // satisfies(v, range, options)
  4685. if (!min || minSV.compare(v) === 1) {
  4686. // compare(min, v, true)
  4687. min = v;
  4688. minSV = new SemVer(min, options);
  4689. }
  4690. }
  4691. });
  4692. return min;
  4693. }
  4694. exports.minVersion = minVersion;
  4695. function minVersion(range, loose) {
  4696. range = new Range(range, loose);
  4697. var minver = new SemVer('0.0.0');
  4698. if (range.test(minver)) {
  4699. return minver;
  4700. }
  4701. minver = new SemVer('0.0.0-0');
  4702. if (range.test(minver)) {
  4703. return minver;
  4704. }
  4705. minver = null;
  4706. for (var i = 0; i < range.set.length; ++i) {
  4707. var comparators = range.set[i];
  4708. comparators.forEach(function (comparator) {
  4709. // Clone to avoid manipulating the comparator's semver object.
  4710. var compver = new SemVer(comparator.semver.version);
  4711. switch (comparator.operator) {
  4712. case '>':
  4713. if (compver.prerelease.length === 0) {
  4714. compver.patch++;
  4715. } else {
  4716. compver.prerelease.push(0);
  4717. }
  4718. compver.raw = compver.format();
  4719. /* fallthrough */
  4720. case '':
  4721. case '>=':
  4722. if (!minver || gt(minver, compver)) {
  4723. minver = compver;
  4724. }
  4725. break;
  4726. case '<':
  4727. case '<=':
  4728. /* Ignore maximum versions */
  4729. break;
  4730. /* istanbul ignore next */
  4731. default:
  4732. throw new Error('Unexpected operation: ' + comparator.operator);
  4733. }
  4734. });
  4735. }
  4736. if (minver && range.test(minver)) {
  4737. return minver;
  4738. }
  4739. return null;
  4740. }
  4741. exports.validRange = validRange;
  4742. function validRange(range, options) {
  4743. try {
  4744. // Return '*' instead of '' so that truthiness works.
  4745. // This will throw if it's invalid anyway
  4746. return new Range(range, options).range || '*';
  4747. } catch (er) {
  4748. return null;
  4749. }
  4750. } // Determine if version is less than all the versions possible in the range
  4751. exports.ltr = ltr;
  4752. function ltr(version, range, options) {
  4753. return outside(version, range, '<', options);
  4754. } // Determine if version is greater than all the versions possible in the range.
  4755. exports.gtr = gtr;
  4756. function gtr(version, range, options) {
  4757. return outside(version, range, '>', options);
  4758. }
  4759. exports.outside = outside;
  4760. function outside(version, range, hilo, options) {
  4761. version = new SemVer(version, options);
  4762. range = new Range(range, options);
  4763. var gtfn, ltefn, ltfn, comp, ecomp;
  4764. switch (hilo) {
  4765. case '>':
  4766. gtfn = gt;
  4767. ltefn = lte;
  4768. ltfn = lt;
  4769. comp = '>';
  4770. ecomp = '>=';
  4771. break;
  4772. case '<':
  4773. gtfn = lt;
  4774. ltefn = gte;
  4775. ltfn = gt;
  4776. comp = '<';
  4777. ecomp = '<=';
  4778. break;
  4779. default:
  4780. throw new TypeError('Must provide a hilo val of "<" or ">"');
  4781. } // If it satisifes the range it is not outside
  4782. if (satisfies(version, range, options)) {
  4783. return false;
  4784. } // From now on, variable terms are as if we're in "gtr" mode.
  4785. // but note that everything is flipped for the "ltr" function.
  4786. for (var i = 0; i < range.set.length; ++i) {
  4787. var comparators = range.set[i];
  4788. var high = null;
  4789. var low = null;
  4790. comparators.forEach(function (comparator) {
  4791. if (comparator.semver === ANY) {
  4792. comparator = new Comparator('>=0.0.0');
  4793. }
  4794. high = high || comparator;
  4795. low = low || comparator;
  4796. if (gtfn(comparator.semver, high.semver, options)) {
  4797. high = comparator;
  4798. } else if (ltfn(comparator.semver, low.semver, options)) {
  4799. low = comparator;
  4800. }
  4801. }); // If the edge version comparator has a operator then our version
  4802. // isn't outside it
  4803. if (high.operator === comp || high.operator === ecomp) {
  4804. return false;
  4805. } // If the lowest version comparator has an operator and our version
  4806. // is less than it then it isn't higher than the range
  4807. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  4808. return false;
  4809. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  4810. return false;
  4811. }
  4812. }
  4813. return true;
  4814. }
  4815. exports.prerelease = prerelease;
  4816. function prerelease(version, options) {
  4817. var parsed = parse(version, options);
  4818. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  4819. }
  4820. exports.intersects = intersects;
  4821. function intersects(r1, r2, options) {
  4822. r1 = new Range(r1, options);
  4823. r2 = new Range(r2, options);
  4824. return r1.intersects(r2);
  4825. }
  4826. exports.coerce = coerce;
  4827. function coerce(version, options) {
  4828. if (version instanceof SemVer) {
  4829. return version;
  4830. }
  4831. if (typeof version === 'number') {
  4832. version = String(version);
  4833. }
  4834. if (typeof version !== 'string') {
  4835. return null;
  4836. }
  4837. options = options || {};
  4838. var match = null;
  4839. if (!options.rtl) {
  4840. match = version.match(re[t.COERCE]);
  4841. } else {
  4842. // Find the right-most coercible string that does not share
  4843. // a terminus with a more left-ward coercible string.
  4844. // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
  4845. //
  4846. // Walk through the string checking with a /g regexp
  4847. // Manually set the index so as to pick up overlapping matches.
  4848. // Stop when we get a match that ends at the string end, since no
  4849. // coercible string can be more right-ward without the same terminus.
  4850. var next;
  4851. while ((next = re[t.COERCERTL].exec(version)) && (!match || match.index + match[0].length !== version.length)) {
  4852. if (!match || next.index + next[0].length !== match.index + match[0].length) {
  4853. match = next;
  4854. }
  4855. re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length;
  4856. } // leave it in a clean state
  4857. re[t.COERCERTL].lastIndex = -1;
  4858. }
  4859. if (match === null) {
  4860. return null;
  4861. }
  4862. return parse(match[2] + '.' + (match[3] || '0') + '.' + (match[4] || '0'), options);
  4863. }
  4864. });
  4865. var semver_1 = semver.SEMVER_SPEC_VERSION;
  4866. var semver_2 = semver.re;
  4867. var semver_3 = semver.src;
  4868. var semver_4 = semver.tokens;
  4869. var semver_5 = semver.parse;
  4870. var semver_6 = semver.valid;
  4871. var semver_7 = semver.clean;
  4872. var semver_8 = semver.SemVer;
  4873. var semver_9 = semver.inc;
  4874. var semver_10 = semver.diff;
  4875. var semver_11 = semver.compareIdentifiers;
  4876. var semver_12 = semver.rcompareIdentifiers;
  4877. var semver_13 = semver.major;
  4878. var semver_14 = semver.minor;
  4879. var semver_15 = semver.patch;
  4880. var semver_16 = semver.compare;
  4881. var semver_17 = semver.compareLoose;
  4882. var semver_18 = semver.compareBuild;
  4883. var semver_19 = semver.rcompare;
  4884. var semver_20 = semver.sort;
  4885. var semver_21 = semver.rsort;
  4886. var semver_22 = semver.gt;
  4887. var semver_23 = semver.lt;
  4888. var semver_24 = semver.eq;
  4889. var semver_25 = semver.neq;
  4890. var semver_26 = semver.gte;
  4891. var semver_27 = semver.lte;
  4892. var semver_28 = semver.cmp;
  4893. var semver_29 = semver.Comparator;
  4894. var semver_30 = semver.Range;
  4895. var semver_31 = semver.toComparators;
  4896. var semver_32 = semver.satisfies;
  4897. var semver_33 = semver.maxSatisfying;
  4898. var semver_34 = semver.minSatisfying;
  4899. var semver_35 = semver.minVersion;
  4900. var semver_36 = semver.validRange;
  4901. var semver_37 = semver.ltr;
  4902. var semver_38 = semver.gtr;
  4903. var semver_39 = semver.outside;
  4904. var semver_40 = semver.prerelease;
  4905. var semver_41 = semver.intersects;
  4906. var semver_42 = semver.coerce;
  4907. var arrayify = function arrayify(object, keyName) {
  4908. return Object.keys(object).reduce(function (array, key) {
  4909. return array.concat(Object.assign(_defineProperty({}, keyName, key), object[key]));
  4910. }, []);
  4911. };
  4912. var dedent_1 = createCommonjsModule(function (module) {
  4913. function dedent(strings) {
  4914. var raw = void 0;
  4915. if (typeof strings === "string") {
  4916. // dedent can be used as a plain function
  4917. raw = [strings];
  4918. } else {
  4919. raw = strings.raw;
  4920. } // first, perform interpolation
  4921. var result = "";
  4922. for (var i = 0; i < raw.length; i++) {
  4923. result += raw[i]. // join lines when there is a suppressed newline
  4924. replace(/\\\n[ \t]*/g, ""). // handle escaped backticks
  4925. replace(/\\`/g, "`");
  4926. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  4927. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  4928. }
  4929. } // now strip indentation
  4930. var lines = result.split("\n");
  4931. var mindent = null;
  4932. lines.forEach(function (l) {
  4933. var m = l.match(/^(\s+)\S+/);
  4934. if (m) {
  4935. var indent = m[1].length;
  4936. if (!mindent) {
  4937. // this is the first indented line
  4938. mindent = indent;
  4939. } else {
  4940. mindent = Math.min(mindent, indent);
  4941. }
  4942. }
  4943. });
  4944. if (mindent !== null) {
  4945. result = lines.map(function (l) {
  4946. return l[0] === " " ? l.slice(mindent) : l;
  4947. }).join("\n");
  4948. } // dedent eats leading and trailing whitespace too
  4949. result = result.trim(); // handle escaped newlines at the end to ensure they don't get stripped too
  4950. return result.replace(/\\n/g, "\n");
  4951. }
  4952. {
  4953. module.exports = dedent;
  4954. }
  4955. });
  4956. function _templateObject6() {
  4957. var data = _taggedTemplateLiteral(["\n Require either '@prettier' or '@format' to be present in the file's first docblock comment\n in order for it to be formatted.\n "]);
  4958. _templateObject6 = function _templateObject6() {
  4959. return data;
  4960. };
  4961. return data;
  4962. }
  4963. function _templateObject5() {
  4964. var data = _taggedTemplateLiteral(["\n Format code starting at a given character offset.\n The range will extend backwards to the start of the first line containing the selected statement.\n This option cannot be used with --cursor-offset.\n "]);
  4965. _templateObject5 = function _templateObject5() {
  4966. return data;
  4967. };
  4968. return data;
  4969. }
  4970. function _templateObject4() {
  4971. var data = _taggedTemplateLiteral(["\n Format code ending at a given character offset (exclusive).\n The range will extend forwards to the end of the selected statement.\n This option cannot be used with --cursor-offset.\n "]);
  4972. _templateObject4 = function _templateObject4() {
  4973. return data;
  4974. };
  4975. return data;
  4976. }
  4977. function _templateObject3() {
  4978. var data = _taggedTemplateLiteral(["\n Custom directory that contains prettier plugins in node_modules subdirectory.\n Overrides default behavior when plugins are searched relatively to the location of Prettier.\n Multiple values are accepted.\n "]);
  4979. _templateObject3 = function _templateObject3() {
  4980. return data;
  4981. };
  4982. return data;
  4983. }
  4984. function _templateObject2() {
  4985. var data = _taggedTemplateLiteral(["\n Maintain existing\n (mixed values within one file are normalised by looking at what's used after the first line)\n "]);
  4986. _templateObject2 = function _templateObject2() {
  4987. return data;
  4988. };
  4989. return data;
  4990. }
  4991. function _templateObject() {
  4992. var data = _taggedTemplateLiteral(["\n Print (to stderr) where a cursor at the given position would move to after formatting.\n This option cannot be used with --range-start and --range-end.\n "]);
  4993. _templateObject = function _templateObject() {
  4994. return data;
  4995. };
  4996. return data;
  4997. }
  4998. var CATEGORY_CONFIG = "Config";
  4999. var CATEGORY_EDITOR = "Editor";
  5000. var CATEGORY_FORMAT = "Format";
  5001. var CATEGORY_OTHER = "Other";
  5002. var CATEGORY_OUTPUT = "Output";
  5003. var CATEGORY_GLOBAL = "Global";
  5004. var CATEGORY_SPECIAL = "Special";
  5005. /**
  5006. * @typedef {Object} OptionInfo
  5007. * @property {string} [since] - available since version
  5008. * @property {string} category
  5009. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  5010. * @property {boolean} [array] - indicate it's an array of the specified type
  5011. * @property {OptionValueInfo} [default]
  5012. * @property {OptionRangeInfo} [range] - for type int
  5013. * @property {string} description
  5014. * @property {string} [deprecated] - deprecated since version
  5015. * @property {OptionRedirectInfo} [redirect] - redirect deprecated option
  5016. * @property {(value: any) => boolean} [exception]
  5017. * @property {OptionChoiceInfo[]} [choices] - for type choice
  5018. * @property {string} [cliName]
  5019. * @property {string} [cliCategory]
  5020. * @property {string} [cliDescription]
  5021. *
  5022. * @typedef {number | boolean | string} OptionValue
  5023. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  5024. *
  5025. * @typedef {Object} OptionRedirectInfo
  5026. * @property {string} option
  5027. * @property {OptionValue} value
  5028. *
  5029. * @typedef {Object} OptionRangeInfo
  5030. * @property {number} start - recommended range start
  5031. * @property {number} end - recommended range end
  5032. * @property {number} step - recommended range step
  5033. *
  5034. * @typedef {Object} OptionChoiceInfo
  5035. * @property {boolean | string} value - boolean for the option that is originally boolean type
  5036. * @property {string} description
  5037. * @property {string} [since] - undefined if available since the first version of the option
  5038. * @property {string} [deprecated] - deprecated since version
  5039. * @property {OptionValueInfo} [redirect] - redirect deprecated value
  5040. */
  5041. /** @type {{ [name: string]: OptionInfo }} */
  5042. var options = {
  5043. cursorOffset: {
  5044. since: "1.4.0",
  5045. category: CATEGORY_SPECIAL,
  5046. type: "int",
  5047. default: -1,
  5048. range: {
  5049. start: -1,
  5050. end: Infinity,
  5051. step: 1
  5052. },
  5053. description: dedent_1(_templateObject()),
  5054. cliCategory: CATEGORY_EDITOR
  5055. },
  5056. endOfLine: {
  5057. since: "1.15.0",
  5058. category: CATEGORY_GLOBAL,
  5059. type: "choice",
  5060. default: "auto",
  5061. description: "Which end of line characters to apply.",
  5062. choices: [{
  5063. value: "auto",
  5064. description: dedent_1(_templateObject2())
  5065. }, {
  5066. value: "lf",
  5067. description: "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
  5068. }, {
  5069. value: "crlf",
  5070. description: "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
  5071. }, {
  5072. value: "cr",
  5073. description: "Carriage Return character only (\\r), used very rarely"
  5074. }]
  5075. },
  5076. filepath: {
  5077. since: "1.4.0",
  5078. category: CATEGORY_SPECIAL,
  5079. type: "path",
  5080. description: "Specify the input filepath. This will be used to do parser inference.",
  5081. cliName: "stdin-filepath",
  5082. cliCategory: CATEGORY_OTHER,
  5083. cliDescription: "Path to the file to pretend that stdin comes from."
  5084. },
  5085. insertPragma: {
  5086. since: "1.8.0",
  5087. category: CATEGORY_SPECIAL,
  5088. type: "boolean",
  5089. default: false,
  5090. description: "Insert @format pragma into file's first docblock comment.",
  5091. cliCategory: CATEGORY_OTHER
  5092. },
  5093. parser: {
  5094. since: "0.0.10",
  5095. category: CATEGORY_GLOBAL,
  5096. type: "choice",
  5097. default: [{
  5098. since: "0.0.10",
  5099. value: "babylon"
  5100. }, {
  5101. since: "1.13.0",
  5102. value: undefined
  5103. }],
  5104. description: "Which parser to use.",
  5105. exception: function exception(value) {
  5106. return typeof value === "string" || typeof value === "function";
  5107. },
  5108. choices: [{
  5109. value: "flow",
  5110. description: "Flow"
  5111. }, {
  5112. value: "babylon",
  5113. description: "JavaScript",
  5114. deprecated: "1.16.0",
  5115. redirect: "babel"
  5116. }, {
  5117. value: "babel",
  5118. since: "1.16.0",
  5119. description: "JavaScript"
  5120. }, {
  5121. value: "babel-flow",
  5122. since: "1.16.0",
  5123. description: "Flow"
  5124. }, {
  5125. value: "typescript",
  5126. since: "1.4.0",
  5127. description: "TypeScript"
  5128. }, {
  5129. value: "css",
  5130. since: "1.7.1",
  5131. description: "CSS"
  5132. }, {
  5133. value: "postcss",
  5134. since: "1.4.0",
  5135. description: "CSS/Less/SCSS",
  5136. deprecated: "1.7.1",
  5137. redirect: "css"
  5138. }, {
  5139. value: "less",
  5140. since: "1.7.1",
  5141. description: "Less"
  5142. }, {
  5143. value: "scss",
  5144. since: "1.7.1",
  5145. description: "SCSS"
  5146. }, {
  5147. value: "json",
  5148. since: "1.5.0",
  5149. description: "JSON"
  5150. }, {
  5151. value: "json5",
  5152. since: "1.13.0",
  5153. description: "JSON5"
  5154. }, {
  5155. value: "json-stringify",
  5156. since: "1.13.0",
  5157. description: "JSON.stringify"
  5158. }, {
  5159. value: "graphql",
  5160. since: "1.5.0",
  5161. description: "GraphQL"
  5162. }, {
  5163. value: "markdown",
  5164. since: "1.8.0",
  5165. description: "Markdown"
  5166. }, {
  5167. value: "mdx",
  5168. since: "1.15.0",
  5169. description: "MDX"
  5170. }, {
  5171. value: "vue",
  5172. since: "1.10.0",
  5173. description: "Vue"
  5174. }, {
  5175. value: "yaml",
  5176. since: "1.14.0",
  5177. description: "YAML"
  5178. }, {
  5179. value: "glimmer",
  5180. since: null,
  5181. description: "Handlebars"
  5182. }, {
  5183. value: "html",
  5184. since: "1.15.0",
  5185. description: "HTML"
  5186. }, {
  5187. value: "angular",
  5188. since: "1.15.0",
  5189. description: "Angular"
  5190. }, {
  5191. value: "lwc",
  5192. since: "1.17.0",
  5193. description: "Lightning Web Components"
  5194. }]
  5195. },
  5196. plugins: {
  5197. since: "1.10.0",
  5198. type: "path",
  5199. array: true,
  5200. default: [{
  5201. value: []
  5202. }],
  5203. category: CATEGORY_GLOBAL,
  5204. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  5205. exception: function exception(value) {
  5206. return typeof value === "string" || _typeof(value) === "object";
  5207. },
  5208. cliName: "plugin",
  5209. cliCategory: CATEGORY_CONFIG
  5210. },
  5211. pluginSearchDirs: {
  5212. since: "1.13.0",
  5213. type: "path",
  5214. array: true,
  5215. default: [{
  5216. value: []
  5217. }],
  5218. category: CATEGORY_GLOBAL,
  5219. description: dedent_1(_templateObject3()),
  5220. exception: function exception(value) {
  5221. return typeof value === "string" || _typeof(value) === "object";
  5222. },
  5223. cliName: "plugin-search-dir",
  5224. cliCategory: CATEGORY_CONFIG
  5225. },
  5226. printWidth: {
  5227. since: "0.0.0",
  5228. category: CATEGORY_GLOBAL,
  5229. type: "int",
  5230. default: 80,
  5231. description: "The line length where Prettier will try wrap.",
  5232. range: {
  5233. start: 0,
  5234. end: Infinity,
  5235. step: 1
  5236. }
  5237. },
  5238. rangeEnd: {
  5239. since: "1.4.0",
  5240. category: CATEGORY_SPECIAL,
  5241. type: "int",
  5242. default: Infinity,
  5243. range: {
  5244. start: 0,
  5245. end: Infinity,
  5246. step: 1
  5247. },
  5248. description: dedent_1(_templateObject4()),
  5249. cliCategory: CATEGORY_EDITOR
  5250. },
  5251. rangeStart: {
  5252. since: "1.4.0",
  5253. category: CATEGORY_SPECIAL,
  5254. type: "int",
  5255. default: 0,
  5256. range: {
  5257. start: 0,
  5258. end: Infinity,
  5259. step: 1
  5260. },
  5261. description: dedent_1(_templateObject5()),
  5262. cliCategory: CATEGORY_EDITOR
  5263. },
  5264. requirePragma: {
  5265. since: "1.7.0",
  5266. category: CATEGORY_SPECIAL,
  5267. type: "boolean",
  5268. default: false,
  5269. description: dedent_1(_templateObject6()),
  5270. cliCategory: CATEGORY_OTHER
  5271. },
  5272. tabWidth: {
  5273. type: "int",
  5274. category: CATEGORY_GLOBAL,
  5275. default: 2,
  5276. description: "Number of spaces per indentation level.",
  5277. range: {
  5278. start: 0,
  5279. end: Infinity,
  5280. step: 1
  5281. }
  5282. },
  5283. useFlowParser: {
  5284. since: "0.0.0",
  5285. category: CATEGORY_GLOBAL,
  5286. type: "boolean",
  5287. default: [{
  5288. since: "0.0.0",
  5289. value: false
  5290. }, {
  5291. since: "1.15.0",
  5292. value: undefined
  5293. }],
  5294. deprecated: "0.0.10",
  5295. description: "Use flow parser.",
  5296. redirect: {
  5297. option: "parser",
  5298. value: "flow"
  5299. },
  5300. cliName: "flow-parser"
  5301. },
  5302. useTabs: {
  5303. since: "1.0.0",
  5304. category: CATEGORY_GLOBAL,
  5305. type: "boolean",
  5306. default: false,
  5307. description: "Indent with tabs instead of spaces."
  5308. }
  5309. };
  5310. var coreOptions = {
  5311. CATEGORY_CONFIG: CATEGORY_CONFIG,
  5312. CATEGORY_EDITOR: CATEGORY_EDITOR,
  5313. CATEGORY_FORMAT: CATEGORY_FORMAT,
  5314. CATEGORY_OTHER: CATEGORY_OTHER,
  5315. CATEGORY_OUTPUT: CATEGORY_OUTPUT,
  5316. CATEGORY_GLOBAL: CATEGORY_GLOBAL,
  5317. CATEGORY_SPECIAL: CATEGORY_SPECIAL,
  5318. options: options
  5319. };
  5320. var require$$0 = getCjsExportFromNamespace(_package$1);
  5321. var currentVersion = require$$0.version;
  5322. var coreOptions$1 = coreOptions.options;
  5323. function getSupportInfo(version, opts) {
  5324. opts = Object.assign({
  5325. plugins: [],
  5326. showUnreleased: false,
  5327. showDeprecated: false,
  5328. showInternal: false
  5329. }, opts);
  5330. if (!version) {
  5331. // pre-release version is smaller than the normal version in semver,
  5332. // we need to treat it as the normal one so as to test new features.
  5333. version = currentVersion.split("-", 1)[0];
  5334. }
  5335. var plugins = opts.plugins;
  5336. var options = arrayify(Object.assign(plugins.reduce(function (currentOptions, plugin) {
  5337. return Object.assign(currentOptions, plugin.options);
  5338. }, {}), coreOptions$1), "name").sort(function (a, b) {
  5339. return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
  5340. }).filter(filterSince).filter(filterDeprecated).map(mapDeprecated).map(mapInternal).map(function (option) {
  5341. var newOption = Object.assign({}, option);
  5342. if (Array.isArray(newOption.default)) {
  5343. newOption.default = newOption.default.length === 1 ? newOption.default[0].value : newOption.default.filter(filterSince).sort(function (info1, info2) {
  5344. return semver.compare(info2.since, info1.since);
  5345. })[0].value;
  5346. }
  5347. if (Array.isArray(newOption.choices)) {
  5348. newOption.choices = newOption.choices.filter(filterSince).filter(filterDeprecated).map(mapDeprecated);
  5349. }
  5350. return newOption;
  5351. }).map(function (option) {
  5352. var filteredPlugins = plugins.filter(function (plugin) {
  5353. return plugin.defaultOptions && plugin.defaultOptions[option.name] !== undefined;
  5354. });
  5355. var pluginDefaults = filteredPlugins.reduce(function (reduced, plugin) {
  5356. reduced[plugin.name] = plugin.defaultOptions[option.name];
  5357. return reduced;
  5358. }, {});
  5359. return Object.assign(option, {
  5360. pluginDefaults: pluginDefaults
  5361. });
  5362. });
  5363. var usePostCssParser = semver.lt(version, "1.7.1");
  5364. var useBabylonParser = semver.lt(version, "1.16.0");
  5365. var languages = plugins.reduce(function (all, plugin) {
  5366. return all.concat(plugin.languages || []);
  5367. }, []).filter(filterSince).map(function (language) {
  5368. // Prevent breaking changes
  5369. if (language.name === "Markdown") {
  5370. return Object.assign({}, language, {
  5371. parsers: ["markdown"]
  5372. });
  5373. }
  5374. if (language.name === "TypeScript") {
  5375. return Object.assign({}, language, {
  5376. parsers: ["typescript"]
  5377. });
  5378. } // "babylon" was renamed to "babel" in 1.16.0
  5379. if (useBabylonParser && language.parsers.indexOf("babel") !== -1) {
  5380. return Object.assign({}, language, {
  5381. parsers: language.parsers.map(function (parser) {
  5382. return parser === "babel" ? "babylon" : parser;
  5383. })
  5384. });
  5385. }
  5386. if (usePostCssParser && (language.name === "CSS" || language.group === "CSS")) {
  5387. return Object.assign({}, language, {
  5388. parsers: ["postcss"]
  5389. });
  5390. }
  5391. return language;
  5392. });
  5393. return {
  5394. languages: languages,
  5395. options: options
  5396. };
  5397. function filterSince(object) {
  5398. return opts.showUnreleased || !("since" in object) || object.since && semver.gte(version, object.since);
  5399. }
  5400. function filterDeprecated(object) {
  5401. return opts.showDeprecated || !("deprecated" in object) || object.deprecated && semver.lt(version, object.deprecated);
  5402. }
  5403. function mapDeprecated(object) {
  5404. if (!object.deprecated || opts.showDeprecated) {
  5405. return object;
  5406. }
  5407. var newObject = Object.assign({}, object);
  5408. delete newObject.deprecated;
  5409. delete newObject.redirect;
  5410. return newObject;
  5411. }
  5412. function mapInternal(object) {
  5413. if (opts.showInternal) {
  5414. return object;
  5415. }
  5416. var newObject = Object.assign({}, object);
  5417. delete newObject.cliName;
  5418. delete newObject.cliCategory;
  5419. delete newObject.cliDescription;
  5420. return newObject;
  5421. }
  5422. }
  5423. var support = {
  5424. getSupportInfo: getSupportInfo
  5425. };
  5426. /*! *****************************************************************************
  5427. Copyright (c) Microsoft Corporation. All rights reserved.
  5428. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  5429. this file except in compliance with the License. You may obtain a copy of the
  5430. License at http://www.apache.org/licenses/LICENSE-2.0
  5431. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  5432. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  5433. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  5434. MERCHANTABLITY OR NON-INFRINGEMENT.
  5435. See the Apache Version 2.0 License for specific language governing permissions
  5436. and limitations under the License.
  5437. ***************************************************************************** */
  5438. /* global Reflect, Promise */
  5439. var _extendStatics = function extendStatics(d, b) {
  5440. _extendStatics = Object.setPrototypeOf || {
  5441. __proto__: []
  5442. } instanceof Array && function (d, b) {
  5443. d.__proto__ = b;
  5444. } || function (d, b) {
  5445. for (var p in b) {
  5446. if (b.hasOwnProperty(p)) d[p] = b[p];
  5447. }
  5448. };
  5449. return _extendStatics(d, b);
  5450. };
  5451. function __extends(d, b) {
  5452. _extendStatics(d, b);
  5453. function __() {
  5454. this.constructor = d;
  5455. }
  5456. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5457. }
  5458. var _assign = function __assign() {
  5459. _assign = Object.assign || function __assign(t) {
  5460. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5461. s = arguments[i];
  5462. for (var p in s) {
  5463. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  5464. }
  5465. }
  5466. return t;
  5467. };
  5468. return _assign.apply(this, arguments);
  5469. };
  5470. function __rest(s, e) {
  5471. var t = {};
  5472. for (var p in s) {
  5473. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5474. }
  5475. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  5476. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  5477. }
  5478. return t;
  5479. }
  5480. function __decorate(decorators, target, key, desc) {
  5481. var c = arguments.length,
  5482. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  5483. d;
  5484. if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
  5485. if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5486. }
  5487. return c > 3 && r && Object.defineProperty(target, key, r), r;
  5488. }
  5489. function __param(paramIndex, decorator) {
  5490. return function (target, key) {
  5491. decorator(target, key, paramIndex);
  5492. };
  5493. }
  5494. function __metadata(metadataKey, metadataValue) {
  5495. if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  5496. }
  5497. function __awaiter(thisArg, _arguments, P, generator) {
  5498. return new (P || (P = Promise))(function (resolve, reject) {
  5499. function fulfilled(value) {
  5500. try {
  5501. step(generator.next(value));
  5502. } catch (e) {
  5503. reject(e);
  5504. }
  5505. }
  5506. function rejected(value) {
  5507. try {
  5508. step(generator["throw"](value));
  5509. } catch (e) {
  5510. reject(e);
  5511. }
  5512. }
  5513. function step(result) {
  5514. result.done ? resolve(result.value) : new P(function (resolve) {
  5515. resolve(result.value);
  5516. }).then(fulfilled, rejected);
  5517. }
  5518. step((generator = generator.apply(thisArg, _arguments || [])).next());
  5519. });
  5520. }
  5521. function __generator(thisArg, body) {
  5522. var _ = {
  5523. label: 0,
  5524. sent: function sent() {
  5525. if (t[0] & 1) throw t[1];
  5526. return t[1];
  5527. },
  5528. trys: [],
  5529. ops: []
  5530. },
  5531. f,
  5532. y,
  5533. t,
  5534. g;
  5535. return g = {
  5536. next: verb(0),
  5537. "throw": verb(1),
  5538. "return": verb(2)
  5539. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  5540. return this;
  5541. }), g;
  5542. function verb(n) {
  5543. return function (v) {
  5544. return step([n, v]);
  5545. };
  5546. }
  5547. function step(op) {
  5548. if (f) throw new TypeError("Generator is already executing.");
  5549. while (_) {
  5550. try {
  5551. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  5552. if (y = 0, t) op = [op[0] & 2, t.value];
  5553. switch (op[0]) {
  5554. case 0:
  5555. case 1:
  5556. t = op;
  5557. break;
  5558. case 4:
  5559. _.label++;
  5560. return {
  5561. value: op[1],
  5562. done: false
  5563. };
  5564. case 5:
  5565. _.label++;
  5566. y = op[1];
  5567. op = [0];
  5568. continue;
  5569. case 7:
  5570. op = _.ops.pop();
  5571. _.trys.pop();
  5572. continue;
  5573. default:
  5574. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  5575. _ = 0;
  5576. continue;
  5577. }
  5578. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  5579. _.label = op[1];
  5580. break;
  5581. }
  5582. if (op[0] === 6 && _.label < t[1]) {
  5583. _.label = t[1];
  5584. t = op;
  5585. break;
  5586. }
  5587. if (t && _.label < t[2]) {
  5588. _.label = t[2];
  5589. _.ops.push(op);
  5590. break;
  5591. }
  5592. if (t[2]) _.ops.pop();
  5593. _.trys.pop();
  5594. continue;
  5595. }
  5596. op = body.call(thisArg, _);
  5597. } catch (e) {
  5598. op = [6, e];
  5599. y = 0;
  5600. } finally {
  5601. f = t = 0;
  5602. }
  5603. }
  5604. if (op[0] & 5) throw op[1];
  5605. return {
  5606. value: op[0] ? op[1] : void 0,
  5607. done: true
  5608. };
  5609. }
  5610. }
  5611. function __exportStar(m, exports) {
  5612. for (var p in m) {
  5613. if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  5614. }
  5615. }
  5616. function __values(o) {
  5617. var m = typeof Symbol === "function" && o[Symbol.iterator],
  5618. i = 0;
  5619. if (m) return m.call(o);
  5620. return {
  5621. next: function next() {
  5622. if (o && i >= o.length) o = void 0;
  5623. return {
  5624. value: o && o[i++],
  5625. done: !o
  5626. };
  5627. }
  5628. };
  5629. }
  5630. function __read(o, n) {
  5631. var m = typeof Symbol === "function" && o[Symbol.iterator];
  5632. if (!m) return o;
  5633. var i = m.call(o),
  5634. r,
  5635. ar = [],
  5636. e;
  5637. try {
  5638. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
  5639. ar.push(r.value);
  5640. }
  5641. } catch (error) {
  5642. e = {
  5643. error: error
  5644. };
  5645. } finally {
  5646. try {
  5647. if (r && !r.done && (m = i["return"])) m.call(i);
  5648. } finally {
  5649. if (e) throw e.error;
  5650. }
  5651. }
  5652. return ar;
  5653. }
  5654. function __spread() {
  5655. for (var ar = [], i = 0; i < arguments.length; i++) {
  5656. ar = ar.concat(__read(arguments[i]));
  5657. }
  5658. return ar;
  5659. }
  5660. function __spreadArrays() {
  5661. for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
  5662. s += arguments[i].length;
  5663. }
  5664. for (var r = Array(s), k = 0, i = 0; i < il; i++) {
  5665. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
  5666. r[k] = a[j];
  5667. }
  5668. }
  5669. return r;
  5670. }
  5671. function __await(v) {
  5672. return this instanceof __await ? (this.v = v, this) : new __await(v);
  5673. }
  5674. function __asyncGenerator(thisArg, _arguments, generator) {
  5675. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  5676. var g = generator.apply(thisArg, _arguments || []),
  5677. i,
  5678. q = [];
  5679. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  5680. return this;
  5681. }, i;
  5682. function verb(n) {
  5683. if (g[n]) i[n] = function (v) {
  5684. return new Promise(function (a, b) {
  5685. q.push([n, v, a, b]) > 1 || resume(n, v);
  5686. });
  5687. };
  5688. }
  5689. function resume(n, v) {
  5690. try {
  5691. step(g[n](v));
  5692. } catch (e) {
  5693. settle(q[0][3], e);
  5694. }
  5695. }
  5696. function step(r) {
  5697. r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
  5698. }
  5699. function fulfill(value) {
  5700. resume("next", value);
  5701. }
  5702. function reject(value) {
  5703. resume("throw", value);
  5704. }
  5705. function settle(f, v) {
  5706. if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
  5707. }
  5708. }
  5709. function __asyncDelegator(o) {
  5710. var i, p;
  5711. return i = {}, verb("next"), verb("throw", function (e) {
  5712. throw e;
  5713. }), verb("return"), i[Symbol.iterator] = function () {
  5714. return this;
  5715. }, i;
  5716. function verb(n, f) {
  5717. i[n] = o[n] ? function (v) {
  5718. return (p = !p) ? {
  5719. value: __await(o[n](v)),
  5720. done: n === "return"
  5721. } : f ? f(v) : v;
  5722. } : f;
  5723. }
  5724. }
  5725. function __asyncValues(o) {
  5726. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  5727. var m = o[Symbol.asyncIterator],
  5728. i;
  5729. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  5730. return this;
  5731. }, i);
  5732. function verb(n) {
  5733. i[n] = o[n] && function (v) {
  5734. return new Promise(function (resolve, reject) {
  5735. v = o[n](v), settle(resolve, reject, v.done, v.value);
  5736. });
  5737. };
  5738. }
  5739. function settle(resolve, reject, d, v) {
  5740. Promise.resolve(v).then(function (v) {
  5741. resolve({
  5742. value: v,
  5743. done: d
  5744. });
  5745. }, reject);
  5746. }
  5747. }
  5748. function __makeTemplateObject(cooked, raw) {
  5749. if (Object.defineProperty) {
  5750. Object.defineProperty(cooked, "raw", {
  5751. value: raw
  5752. });
  5753. } else {
  5754. cooked.raw = raw;
  5755. }
  5756. return cooked;
  5757. }
  5758. function __importStar(mod) {
  5759. if (mod && mod.__esModule) return mod;
  5760. var result = {};
  5761. if (mod != null) for (var k in mod) {
  5762. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  5763. }
  5764. result.default = mod;
  5765. return result;
  5766. }
  5767. function __importDefault(mod) {
  5768. return mod && mod.__esModule ? mod : {
  5769. default: mod
  5770. };
  5771. }
  5772. var tslib_es6 = /*#__PURE__*/Object.freeze({
  5773. __proto__: null,
  5774. __extends: __extends,
  5775. get __assign () { return _assign; },
  5776. __rest: __rest,
  5777. __decorate: __decorate,
  5778. __param: __param,
  5779. __metadata: __metadata,
  5780. __awaiter: __awaiter,
  5781. __generator: __generator,
  5782. __exportStar: __exportStar,
  5783. __values: __values,
  5784. __read: __read,
  5785. __spread: __spread,
  5786. __spreadArrays: __spreadArrays,
  5787. __await: __await,
  5788. __asyncGenerator: __asyncGenerator,
  5789. __asyncDelegator: __asyncDelegator,
  5790. __asyncValues: __asyncValues,
  5791. __makeTemplateObject: __makeTemplateObject,
  5792. __importStar: __importStar,
  5793. __importDefault: __importDefault
  5794. });
  5795. var api = createCommonjsModule(function (module, exports) {
  5796. Object.defineProperty(exports, "__esModule", {
  5797. value: true
  5798. });
  5799. exports.apiDescriptor = {
  5800. key: function key(_key) {
  5801. return /^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(_key) ? _key : JSON.stringify(_key);
  5802. },
  5803. value: function value(_value) {
  5804. if (_value === null || _typeof(_value) !== 'object') {
  5805. return JSON.stringify(_value);
  5806. }
  5807. if (Array.isArray(_value)) {
  5808. return "[".concat(_value.map(function (subValue) {
  5809. return exports.apiDescriptor.value(subValue);
  5810. }).join(', '), "]");
  5811. }
  5812. var keys = Object.keys(_value);
  5813. return keys.length === 0 ? '{}' : "{ ".concat(keys.map(function (key) {
  5814. return "".concat(exports.apiDescriptor.key(key), ": ").concat(exports.apiDescriptor.value(_value[key]));
  5815. }).join(', '), " }");
  5816. },
  5817. pair: function pair(_ref) {
  5818. var key = _ref.key,
  5819. value = _ref.value;
  5820. return exports.apiDescriptor.value(_defineProperty({}, key, value));
  5821. }
  5822. };
  5823. });
  5824. unwrapExports(api);
  5825. var api_1 = api.apiDescriptor;
  5826. var tslib_1 = getCjsExportFromNamespace(tslib_es6);
  5827. var descriptors = createCommonjsModule(function (module, exports) {
  5828. Object.defineProperty(exports, "__esModule", {
  5829. value: true
  5830. });
  5831. tslib_1.__exportStar(api, exports);
  5832. });
  5833. unwrapExports(descriptors);
  5834. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  5835. var escapeStringRegexp = function escapeStringRegexp(str) {
  5836. if (typeof str !== 'string') {
  5837. throw new TypeError('Expected a string');
  5838. }
  5839. return str.replace(matchOperatorsRe, '\\$&');
  5840. };
  5841. var colorName = {
  5842. "aliceblue": [240, 248, 255],
  5843. "antiquewhite": [250, 235, 215],
  5844. "aqua": [0, 255, 255],
  5845. "aquamarine": [127, 255, 212],
  5846. "azure": [240, 255, 255],
  5847. "beige": [245, 245, 220],
  5848. "bisque": [255, 228, 196],
  5849. "black": [0, 0, 0],
  5850. "blanchedalmond": [255, 235, 205],
  5851. "blue": [0, 0, 255],
  5852. "blueviolet": [138, 43, 226],
  5853. "brown": [165, 42, 42],
  5854. "burlywood": [222, 184, 135],
  5855. "cadetblue": [95, 158, 160],
  5856. "chartreuse": [127, 255, 0],
  5857. "chocolate": [210, 105, 30],
  5858. "coral": [255, 127, 80],
  5859. "cornflowerblue": [100, 149, 237],
  5860. "cornsilk": [255, 248, 220],
  5861. "crimson": [220, 20, 60],
  5862. "cyan": [0, 255, 255],
  5863. "darkblue": [0, 0, 139],
  5864. "darkcyan": [0, 139, 139],
  5865. "darkgoldenrod": [184, 134, 11],
  5866. "darkgray": [169, 169, 169],
  5867. "darkgreen": [0, 100, 0],
  5868. "darkgrey": [169, 169, 169],
  5869. "darkkhaki": [189, 183, 107],
  5870. "darkmagenta": [139, 0, 139],
  5871. "darkolivegreen": [85, 107, 47],
  5872. "darkorange": [255, 140, 0],
  5873. "darkorchid": [153, 50, 204],
  5874. "darkred": [139, 0, 0],
  5875. "darksalmon": [233, 150, 122],
  5876. "darkseagreen": [143, 188, 143],
  5877. "darkslateblue": [72, 61, 139],
  5878. "darkslategray": [47, 79, 79],
  5879. "darkslategrey": [47, 79, 79],
  5880. "darkturquoise": [0, 206, 209],
  5881. "darkviolet": [148, 0, 211],
  5882. "deeppink": [255, 20, 147],
  5883. "deepskyblue": [0, 191, 255],
  5884. "dimgray": [105, 105, 105],
  5885. "dimgrey": [105, 105, 105],
  5886. "dodgerblue": [30, 144, 255],
  5887. "firebrick": [178, 34, 34],
  5888. "floralwhite": [255, 250, 240],
  5889. "forestgreen": [34, 139, 34],
  5890. "fuchsia": [255, 0, 255],
  5891. "gainsboro": [220, 220, 220],
  5892. "ghostwhite": [248, 248, 255],
  5893. "gold": [255, 215, 0],
  5894. "goldenrod": [218, 165, 32],
  5895. "gray": [128, 128, 128],
  5896. "green": [0, 128, 0],
  5897. "greenyellow": [173, 255, 47],
  5898. "grey": [128, 128, 128],
  5899. "honeydew": [240, 255, 240],
  5900. "hotpink": [255, 105, 180],
  5901. "indianred": [205, 92, 92],
  5902. "indigo": [75, 0, 130],
  5903. "ivory": [255, 255, 240],
  5904. "khaki": [240, 230, 140],
  5905. "lavender": [230, 230, 250],
  5906. "lavenderblush": [255, 240, 245],
  5907. "lawngreen": [124, 252, 0],
  5908. "lemonchiffon": [255, 250, 205],
  5909. "lightblue": [173, 216, 230],
  5910. "lightcoral": [240, 128, 128],
  5911. "lightcyan": [224, 255, 255],
  5912. "lightgoldenrodyellow": [250, 250, 210],
  5913. "lightgray": [211, 211, 211],
  5914. "lightgreen": [144, 238, 144],
  5915. "lightgrey": [211, 211, 211],
  5916. "lightpink": [255, 182, 193],
  5917. "lightsalmon": [255, 160, 122],
  5918. "lightseagreen": [32, 178, 170],
  5919. "lightskyblue": [135, 206, 250],
  5920. "lightslategray": [119, 136, 153],
  5921. "lightslategrey": [119, 136, 153],
  5922. "lightsteelblue": [176, 196, 222],
  5923. "lightyellow": [255, 255, 224],
  5924. "lime": [0, 255, 0],
  5925. "limegreen": [50, 205, 50],
  5926. "linen": [250, 240, 230],
  5927. "magenta": [255, 0, 255],
  5928. "maroon": [128, 0, 0],
  5929. "mediumaquamarine": [102, 205, 170],
  5930. "mediumblue": [0, 0, 205],
  5931. "mediumorchid": [186, 85, 211],
  5932. "mediumpurple": [147, 112, 219],
  5933. "mediumseagreen": [60, 179, 113],
  5934. "mediumslateblue": [123, 104, 238],
  5935. "mediumspringgreen": [0, 250, 154],
  5936. "mediumturquoise": [72, 209, 204],
  5937. "mediumvioletred": [199, 21, 133],
  5938. "midnightblue": [25, 25, 112],
  5939. "mintcream": [245, 255, 250],
  5940. "mistyrose": [255, 228, 225],
  5941. "moccasin": [255, 228, 181],
  5942. "navajowhite": [255, 222, 173],
  5943. "navy": [0, 0, 128],
  5944. "oldlace": [253, 245, 230],
  5945. "olive": [128, 128, 0],
  5946. "olivedrab": [107, 142, 35],
  5947. "orange": [255, 165, 0],
  5948. "orangered": [255, 69, 0],
  5949. "orchid": [218, 112, 214],
  5950. "palegoldenrod": [238, 232, 170],
  5951. "palegreen": [152, 251, 152],
  5952. "paleturquoise": [175, 238, 238],
  5953. "palevioletred": [219, 112, 147],
  5954. "papayawhip": [255, 239, 213],
  5955. "peachpuff": [255, 218, 185],
  5956. "peru": [205, 133, 63],
  5957. "pink": [255, 192, 203],
  5958. "plum": [221, 160, 221],
  5959. "powderblue": [176, 224, 230],
  5960. "purple": [128, 0, 128],
  5961. "rebeccapurple": [102, 51, 153],
  5962. "red": [255, 0, 0],
  5963. "rosybrown": [188, 143, 143],
  5964. "royalblue": [65, 105, 225],
  5965. "saddlebrown": [139, 69, 19],
  5966. "salmon": [250, 128, 114],
  5967. "sandybrown": [244, 164, 96],
  5968. "seagreen": [46, 139, 87],
  5969. "seashell": [255, 245, 238],
  5970. "sienna": [160, 82, 45],
  5971. "silver": [192, 192, 192],
  5972. "skyblue": [135, 206, 235],
  5973. "slateblue": [106, 90, 205],
  5974. "slategray": [112, 128, 144],
  5975. "slategrey": [112, 128, 144],
  5976. "snow": [255, 250, 250],
  5977. "springgreen": [0, 255, 127],
  5978. "steelblue": [70, 130, 180],
  5979. "tan": [210, 180, 140],
  5980. "teal": [0, 128, 128],
  5981. "thistle": [216, 191, 216],
  5982. "tomato": [255, 99, 71],
  5983. "turquoise": [64, 224, 208],
  5984. "violet": [238, 130, 238],
  5985. "wheat": [245, 222, 179],
  5986. "white": [255, 255, 255],
  5987. "whitesmoke": [245, 245, 245],
  5988. "yellow": [255, 255, 0],
  5989. "yellowgreen": [154, 205, 50]
  5990. };
  5991. var conversions = createCommonjsModule(function (module) {
  5992. /* MIT license */
  5993. // NOTE: conversions should only return primitive values (i.e. arrays, or
  5994. // values that give correct `typeof` results).
  5995. // do not use box values types (i.e. Number(), String(), etc.)
  5996. var reverseKeywords = {};
  5997. for (var key in colorName) {
  5998. if (colorName.hasOwnProperty(key)) {
  5999. reverseKeywords[colorName[key]] = key;
  6000. }
  6001. }
  6002. var convert = module.exports = {
  6003. rgb: {
  6004. channels: 3,
  6005. labels: 'rgb'
  6006. },
  6007. hsl: {
  6008. channels: 3,
  6009. labels: 'hsl'
  6010. },
  6011. hsv: {
  6012. channels: 3,
  6013. labels: 'hsv'
  6014. },
  6015. hwb: {
  6016. channels: 3,
  6017. labels: 'hwb'
  6018. },
  6019. cmyk: {
  6020. channels: 4,
  6021. labels: 'cmyk'
  6022. },
  6023. xyz: {
  6024. channels: 3,
  6025. labels: 'xyz'
  6026. },
  6027. lab: {
  6028. channels: 3,
  6029. labels: 'lab'
  6030. },
  6031. lch: {
  6032. channels: 3,
  6033. labels: 'lch'
  6034. },
  6035. hex: {
  6036. channels: 1,
  6037. labels: ['hex']
  6038. },
  6039. keyword: {
  6040. channels: 1,
  6041. labels: ['keyword']
  6042. },
  6043. ansi16: {
  6044. channels: 1,
  6045. labels: ['ansi16']
  6046. },
  6047. ansi256: {
  6048. channels: 1,
  6049. labels: ['ansi256']
  6050. },
  6051. hcg: {
  6052. channels: 3,
  6053. labels: ['h', 'c', 'g']
  6054. },
  6055. apple: {
  6056. channels: 3,
  6057. labels: ['r16', 'g16', 'b16']
  6058. },
  6059. gray: {
  6060. channels: 1,
  6061. labels: ['gray']
  6062. }
  6063. }; // hide .channels and .labels properties
  6064. for (var model in convert) {
  6065. if (convert.hasOwnProperty(model)) {
  6066. if (!('channels' in convert[model])) {
  6067. throw new Error('missing channels property: ' + model);
  6068. }
  6069. if (!('labels' in convert[model])) {
  6070. throw new Error('missing channel labels property: ' + model);
  6071. }
  6072. if (convert[model].labels.length !== convert[model].channels) {
  6073. throw new Error('channel and label counts mismatch: ' + model);
  6074. }
  6075. var channels = convert[model].channels;
  6076. var labels = convert[model].labels;
  6077. delete convert[model].channels;
  6078. delete convert[model].labels;
  6079. Object.defineProperty(convert[model], 'channels', {
  6080. value: channels
  6081. });
  6082. Object.defineProperty(convert[model], 'labels', {
  6083. value: labels
  6084. });
  6085. }
  6086. }
  6087. convert.rgb.hsl = function (rgb) {
  6088. var r = rgb[0] / 255;
  6089. var g = rgb[1] / 255;
  6090. var b = rgb[2] / 255;
  6091. var min = Math.min(r, g, b);
  6092. var max = Math.max(r, g, b);
  6093. var delta = max - min;
  6094. var h;
  6095. var s;
  6096. var l;
  6097. if (max === min) {
  6098. h = 0;
  6099. } else if (r === max) {
  6100. h = (g - b) / delta;
  6101. } else if (g === max) {
  6102. h = 2 + (b - r) / delta;
  6103. } else if (b === max) {
  6104. h = 4 + (r - g) / delta;
  6105. }
  6106. h = Math.min(h * 60, 360);
  6107. if (h < 0) {
  6108. h += 360;
  6109. }
  6110. l = (min + max) / 2;
  6111. if (max === min) {
  6112. s = 0;
  6113. } else if (l <= 0.5) {
  6114. s = delta / (max + min);
  6115. } else {
  6116. s = delta / (2 - max - min);
  6117. }
  6118. return [h, s * 100, l * 100];
  6119. };
  6120. convert.rgb.hsv = function (rgb) {
  6121. var r = rgb[0];
  6122. var g = rgb[1];
  6123. var b = rgb[2];
  6124. var min = Math.min(r, g, b);
  6125. var max = Math.max(r, g, b);
  6126. var delta = max - min;
  6127. var h;
  6128. var s;
  6129. var v;
  6130. if (max === 0) {
  6131. s = 0;
  6132. } else {
  6133. s = delta / max * 1000 / 10;
  6134. }
  6135. if (max === min) {
  6136. h = 0;
  6137. } else if (r === max) {
  6138. h = (g - b) / delta;
  6139. } else if (g === max) {
  6140. h = 2 + (b - r) / delta;
  6141. } else if (b === max) {
  6142. h = 4 + (r - g) / delta;
  6143. }
  6144. h = Math.min(h * 60, 360);
  6145. if (h < 0) {
  6146. h += 360;
  6147. }
  6148. v = max / 255 * 1000 / 10;
  6149. return [h, s, v];
  6150. };
  6151. convert.rgb.hwb = function (rgb) {
  6152. var r = rgb[0];
  6153. var g = rgb[1];
  6154. var b = rgb[2];
  6155. var h = convert.rgb.hsl(rgb)[0];
  6156. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  6157. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  6158. return [h, w * 100, b * 100];
  6159. };
  6160. convert.rgb.cmyk = function (rgb) {
  6161. var r = rgb[0] / 255;
  6162. var g = rgb[1] / 255;
  6163. var b = rgb[2] / 255;
  6164. var c;
  6165. var m;
  6166. var y;
  6167. var k;
  6168. k = Math.min(1 - r, 1 - g, 1 - b);
  6169. c = (1 - r - k) / (1 - k) || 0;
  6170. m = (1 - g - k) / (1 - k) || 0;
  6171. y = (1 - b - k) / (1 - k) || 0;
  6172. return [c * 100, m * 100, y * 100, k * 100];
  6173. };
  6174. /**
  6175. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  6176. * */
  6177. function comparativeDistance(x, y) {
  6178. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  6179. }
  6180. convert.rgb.keyword = function (rgb) {
  6181. var reversed = reverseKeywords[rgb];
  6182. if (reversed) {
  6183. return reversed;
  6184. }
  6185. var currentClosestDistance = Infinity;
  6186. var currentClosestKeyword;
  6187. for (var keyword in colorName) {
  6188. if (colorName.hasOwnProperty(keyword)) {
  6189. var value = colorName[keyword]; // Compute comparative distance
  6190. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  6191. if (distance < currentClosestDistance) {
  6192. currentClosestDistance = distance;
  6193. currentClosestKeyword = keyword;
  6194. }
  6195. }
  6196. }
  6197. return currentClosestKeyword;
  6198. };
  6199. convert.keyword.rgb = function (keyword) {
  6200. return colorName[keyword];
  6201. };
  6202. convert.rgb.xyz = function (rgb) {
  6203. var r = rgb[0] / 255;
  6204. var g = rgb[1] / 255;
  6205. var b = rgb[2] / 255; // assume sRGB
  6206. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  6207. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  6208. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  6209. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  6210. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  6211. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  6212. return [x * 100, y * 100, z * 100];
  6213. };
  6214. convert.rgb.lab = function (rgb) {
  6215. var xyz = convert.rgb.xyz(rgb);
  6216. var x = xyz[0];
  6217. var y = xyz[1];
  6218. var z = xyz[2];
  6219. var l;
  6220. var a;
  6221. var b;
  6222. x /= 95.047;
  6223. y /= 100;
  6224. z /= 108.883;
  6225. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  6226. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  6227. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  6228. l = 116 * y - 16;
  6229. a = 500 * (x - y);
  6230. b = 200 * (y - z);
  6231. return [l, a, b];
  6232. };
  6233. convert.hsl.rgb = function (hsl) {
  6234. var h = hsl[0] / 360;
  6235. var s = hsl[1] / 100;
  6236. var l = hsl[2] / 100;
  6237. var t1;
  6238. var t2;
  6239. var t3;
  6240. var rgb;
  6241. var val;
  6242. if (s === 0) {
  6243. val = l * 255;
  6244. return [val, val, val];
  6245. }
  6246. if (l < 0.5) {
  6247. t2 = l * (1 + s);
  6248. } else {
  6249. t2 = l + s - l * s;
  6250. }
  6251. t1 = 2 * l - t2;
  6252. rgb = [0, 0, 0];
  6253. for (var i = 0; i < 3; i++) {
  6254. t3 = h + 1 / 3 * -(i - 1);
  6255. if (t3 < 0) {
  6256. t3++;
  6257. }
  6258. if (t3 > 1) {
  6259. t3--;
  6260. }
  6261. if (6 * t3 < 1) {
  6262. val = t1 + (t2 - t1) * 6 * t3;
  6263. } else if (2 * t3 < 1) {
  6264. val = t2;
  6265. } else if (3 * t3 < 2) {
  6266. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  6267. } else {
  6268. val = t1;
  6269. }
  6270. rgb[i] = val * 255;
  6271. }
  6272. return rgb;
  6273. };
  6274. convert.hsl.hsv = function (hsl) {
  6275. var h = hsl[0];
  6276. var s = hsl[1] / 100;
  6277. var l = hsl[2] / 100;
  6278. var smin = s;
  6279. var lmin = Math.max(l, 0.01);
  6280. var sv;
  6281. var v;
  6282. l *= 2;
  6283. s *= l <= 1 ? l : 2 - l;
  6284. smin *= lmin <= 1 ? lmin : 2 - lmin;
  6285. v = (l + s) / 2;
  6286. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  6287. return [h, sv * 100, v * 100];
  6288. };
  6289. convert.hsv.rgb = function (hsv) {
  6290. var h = hsv[0] / 60;
  6291. var s = hsv[1] / 100;
  6292. var v = hsv[2] / 100;
  6293. var hi = Math.floor(h) % 6;
  6294. var f = h - Math.floor(h);
  6295. var p = 255 * v * (1 - s);
  6296. var q = 255 * v * (1 - s * f);
  6297. var t = 255 * v * (1 - s * (1 - f));
  6298. v *= 255;
  6299. switch (hi) {
  6300. case 0:
  6301. return [v, t, p];
  6302. case 1:
  6303. return [q, v, p];
  6304. case 2:
  6305. return [p, v, t];
  6306. case 3:
  6307. return [p, q, v];
  6308. case 4:
  6309. return [t, p, v];
  6310. case 5:
  6311. return [v, p, q];
  6312. }
  6313. };
  6314. convert.hsv.hsl = function (hsv) {
  6315. var h = hsv[0];
  6316. var s = hsv[1] / 100;
  6317. var v = hsv[2] / 100;
  6318. var vmin = Math.max(v, 0.01);
  6319. var lmin;
  6320. var sl;
  6321. var l;
  6322. l = (2 - s) * v;
  6323. lmin = (2 - s) * vmin;
  6324. sl = s * vmin;
  6325. sl /= lmin <= 1 ? lmin : 2 - lmin;
  6326. sl = sl || 0;
  6327. l /= 2;
  6328. return [h, sl * 100, l * 100];
  6329. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  6330. convert.hwb.rgb = function (hwb) {
  6331. var h = hwb[0] / 360;
  6332. var wh = hwb[1] / 100;
  6333. var bl = hwb[2] / 100;
  6334. var ratio = wh + bl;
  6335. var i;
  6336. var v;
  6337. var f;
  6338. var n; // wh + bl cant be > 1
  6339. if (ratio > 1) {
  6340. wh /= ratio;
  6341. bl /= ratio;
  6342. }
  6343. i = Math.floor(6 * h);
  6344. v = 1 - bl;
  6345. f = 6 * h - i;
  6346. if ((i & 0x01) !== 0) {
  6347. f = 1 - f;
  6348. }
  6349. n = wh + f * (v - wh); // linear interpolation
  6350. var r;
  6351. var g;
  6352. var b;
  6353. switch (i) {
  6354. default:
  6355. case 6:
  6356. case 0:
  6357. r = v;
  6358. g = n;
  6359. b = wh;
  6360. break;
  6361. case 1:
  6362. r = n;
  6363. g = v;
  6364. b = wh;
  6365. break;
  6366. case 2:
  6367. r = wh;
  6368. g = v;
  6369. b = n;
  6370. break;
  6371. case 3:
  6372. r = wh;
  6373. g = n;
  6374. b = v;
  6375. break;
  6376. case 4:
  6377. r = n;
  6378. g = wh;
  6379. b = v;
  6380. break;
  6381. case 5:
  6382. r = v;
  6383. g = wh;
  6384. b = n;
  6385. break;
  6386. }
  6387. return [r * 255, g * 255, b * 255];
  6388. };
  6389. convert.cmyk.rgb = function (cmyk) {
  6390. var c = cmyk[0] / 100;
  6391. var m = cmyk[1] / 100;
  6392. var y = cmyk[2] / 100;
  6393. var k = cmyk[3] / 100;
  6394. var r;
  6395. var g;
  6396. var b;
  6397. r = 1 - Math.min(1, c * (1 - k) + k);
  6398. g = 1 - Math.min(1, m * (1 - k) + k);
  6399. b = 1 - Math.min(1, y * (1 - k) + k);
  6400. return [r * 255, g * 255, b * 255];
  6401. };
  6402. convert.xyz.rgb = function (xyz) {
  6403. var x = xyz[0] / 100;
  6404. var y = xyz[1] / 100;
  6405. var z = xyz[2] / 100;
  6406. var r;
  6407. var g;
  6408. var b;
  6409. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  6410. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  6411. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  6412. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  6413. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  6414. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  6415. r = Math.min(Math.max(0, r), 1);
  6416. g = Math.min(Math.max(0, g), 1);
  6417. b = Math.min(Math.max(0, b), 1);
  6418. return [r * 255, g * 255, b * 255];
  6419. };
  6420. convert.xyz.lab = function (xyz) {
  6421. var x = xyz[0];
  6422. var y = xyz[1];
  6423. var z = xyz[2];
  6424. var l;
  6425. var a;
  6426. var b;
  6427. x /= 95.047;
  6428. y /= 100;
  6429. z /= 108.883;
  6430. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  6431. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  6432. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  6433. l = 116 * y - 16;
  6434. a = 500 * (x - y);
  6435. b = 200 * (y - z);
  6436. return [l, a, b];
  6437. };
  6438. convert.lab.xyz = function (lab) {
  6439. var l = lab[0];
  6440. var a = lab[1];
  6441. var b = lab[2];
  6442. var x;
  6443. var y;
  6444. var z;
  6445. y = (l + 16) / 116;
  6446. x = a / 500 + y;
  6447. z = y - b / 200;
  6448. var y2 = Math.pow(y, 3);
  6449. var x2 = Math.pow(x, 3);
  6450. var z2 = Math.pow(z, 3);
  6451. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  6452. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  6453. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  6454. x *= 95.047;
  6455. y *= 100;
  6456. z *= 108.883;
  6457. return [x, y, z];
  6458. };
  6459. convert.lab.lch = function (lab) {
  6460. var l = lab[0];
  6461. var a = lab[1];
  6462. var b = lab[2];
  6463. var hr;
  6464. var h;
  6465. var c;
  6466. hr = Math.atan2(b, a);
  6467. h = hr * 360 / 2 / Math.PI;
  6468. if (h < 0) {
  6469. h += 360;
  6470. }
  6471. c = Math.sqrt(a * a + b * b);
  6472. return [l, c, h];
  6473. };
  6474. convert.lch.lab = function (lch) {
  6475. var l = lch[0];
  6476. var c = lch[1];
  6477. var h = lch[2];
  6478. var a;
  6479. var b;
  6480. var hr;
  6481. hr = h / 360 * 2 * Math.PI;
  6482. a = c * Math.cos(hr);
  6483. b = c * Math.sin(hr);
  6484. return [l, a, b];
  6485. };
  6486. convert.rgb.ansi16 = function (args) {
  6487. var r = args[0];
  6488. var g = args[1];
  6489. var b = args[2];
  6490. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  6491. value = Math.round(value / 50);
  6492. if (value === 0) {
  6493. return 30;
  6494. }
  6495. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  6496. if (value === 2) {
  6497. ansi += 60;
  6498. }
  6499. return ansi;
  6500. };
  6501. convert.hsv.ansi16 = function (args) {
  6502. // optimization here; we already know the value and don't need to get
  6503. // it converted for us.
  6504. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  6505. };
  6506. convert.rgb.ansi256 = function (args) {
  6507. var r = args[0];
  6508. var g = args[1];
  6509. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  6510. // black and white. normal palette only has 4 greyscale shades.
  6511. if (r === g && g === b) {
  6512. if (r < 8) {
  6513. return 16;
  6514. }
  6515. if (r > 248) {
  6516. return 231;
  6517. }
  6518. return Math.round((r - 8) / 247 * 24) + 232;
  6519. }
  6520. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  6521. return ansi;
  6522. };
  6523. convert.ansi16.rgb = function (args) {
  6524. var color = args % 10; // handle greyscale
  6525. if (color === 0 || color === 7) {
  6526. if (args > 50) {
  6527. color += 3.5;
  6528. }
  6529. color = color / 10.5 * 255;
  6530. return [color, color, color];
  6531. }
  6532. var mult = (~~(args > 50) + 1) * 0.5;
  6533. var r = (color & 1) * mult * 255;
  6534. var g = (color >> 1 & 1) * mult * 255;
  6535. var b = (color >> 2 & 1) * mult * 255;
  6536. return [r, g, b];
  6537. };
  6538. convert.ansi256.rgb = function (args) {
  6539. // handle greyscale
  6540. if (args >= 232) {
  6541. var c = (args - 232) * 10 + 8;
  6542. return [c, c, c];
  6543. }
  6544. args -= 16;
  6545. var rem;
  6546. var r = Math.floor(args / 36) / 5 * 255;
  6547. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  6548. var b = rem % 6 / 5 * 255;
  6549. return [r, g, b];
  6550. };
  6551. convert.rgb.hex = function (args) {
  6552. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  6553. var string = integer.toString(16).toUpperCase();
  6554. return '000000'.substring(string.length) + string;
  6555. };
  6556. convert.hex.rgb = function (args) {
  6557. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  6558. if (!match) {
  6559. return [0, 0, 0];
  6560. }
  6561. var colorString = match[0];
  6562. if (match[0].length === 3) {
  6563. colorString = colorString.split('').map(function (char) {
  6564. return char + char;
  6565. }).join('');
  6566. }
  6567. var integer = parseInt(colorString, 16);
  6568. var r = integer >> 16 & 0xFF;
  6569. var g = integer >> 8 & 0xFF;
  6570. var b = integer & 0xFF;
  6571. return [r, g, b];
  6572. };
  6573. convert.rgb.hcg = function (rgb) {
  6574. var r = rgb[0] / 255;
  6575. var g = rgb[1] / 255;
  6576. var b = rgb[2] / 255;
  6577. var max = Math.max(Math.max(r, g), b);
  6578. var min = Math.min(Math.min(r, g), b);
  6579. var chroma = max - min;
  6580. var grayscale;
  6581. var hue;
  6582. if (chroma < 1) {
  6583. grayscale = min / (1 - chroma);
  6584. } else {
  6585. grayscale = 0;
  6586. }
  6587. if (chroma <= 0) {
  6588. hue = 0;
  6589. } else if (max === r) {
  6590. hue = (g - b) / chroma % 6;
  6591. } else if (max === g) {
  6592. hue = 2 + (b - r) / chroma;
  6593. } else {
  6594. hue = 4 + (r - g) / chroma + 4;
  6595. }
  6596. hue /= 6;
  6597. hue %= 1;
  6598. return [hue * 360, chroma * 100, grayscale * 100];
  6599. };
  6600. convert.hsl.hcg = function (hsl) {
  6601. var s = hsl[1] / 100;
  6602. var l = hsl[2] / 100;
  6603. var c = 1;
  6604. var f = 0;
  6605. if (l < 0.5) {
  6606. c = 2.0 * s * l;
  6607. } else {
  6608. c = 2.0 * s * (1.0 - l);
  6609. }
  6610. if (c < 1.0) {
  6611. f = (l - 0.5 * c) / (1.0 - c);
  6612. }
  6613. return [hsl[0], c * 100, f * 100];
  6614. };
  6615. convert.hsv.hcg = function (hsv) {
  6616. var s = hsv[1] / 100;
  6617. var v = hsv[2] / 100;
  6618. var c = s * v;
  6619. var f = 0;
  6620. if (c < 1.0) {
  6621. f = (v - c) / (1 - c);
  6622. }
  6623. return [hsv[0], c * 100, f * 100];
  6624. };
  6625. convert.hcg.rgb = function (hcg) {
  6626. var h = hcg[0] / 360;
  6627. var c = hcg[1] / 100;
  6628. var g = hcg[2] / 100;
  6629. if (c === 0.0) {
  6630. return [g * 255, g * 255, g * 255];
  6631. }
  6632. var pure = [0, 0, 0];
  6633. var hi = h % 1 * 6;
  6634. var v = hi % 1;
  6635. var w = 1 - v;
  6636. var mg = 0;
  6637. switch (Math.floor(hi)) {
  6638. case 0:
  6639. pure[0] = 1;
  6640. pure[1] = v;
  6641. pure[2] = 0;
  6642. break;
  6643. case 1:
  6644. pure[0] = w;
  6645. pure[1] = 1;
  6646. pure[2] = 0;
  6647. break;
  6648. case 2:
  6649. pure[0] = 0;
  6650. pure[1] = 1;
  6651. pure[2] = v;
  6652. break;
  6653. case 3:
  6654. pure[0] = 0;
  6655. pure[1] = w;
  6656. pure[2] = 1;
  6657. break;
  6658. case 4:
  6659. pure[0] = v;
  6660. pure[1] = 0;
  6661. pure[2] = 1;
  6662. break;
  6663. default:
  6664. pure[0] = 1;
  6665. pure[1] = 0;
  6666. pure[2] = w;
  6667. }
  6668. mg = (1.0 - c) * g;
  6669. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  6670. };
  6671. convert.hcg.hsv = function (hcg) {
  6672. var c = hcg[1] / 100;
  6673. var g = hcg[2] / 100;
  6674. var v = c + g * (1.0 - c);
  6675. var f = 0;
  6676. if (v > 0.0) {
  6677. f = c / v;
  6678. }
  6679. return [hcg[0], f * 100, v * 100];
  6680. };
  6681. convert.hcg.hsl = function (hcg) {
  6682. var c = hcg[1] / 100;
  6683. var g = hcg[2] / 100;
  6684. var l = g * (1.0 - c) + 0.5 * c;
  6685. var s = 0;
  6686. if (l > 0.0 && l < 0.5) {
  6687. s = c / (2 * l);
  6688. } else if (l >= 0.5 && l < 1.0) {
  6689. s = c / (2 * (1 - l));
  6690. }
  6691. return [hcg[0], s * 100, l * 100];
  6692. };
  6693. convert.hcg.hwb = function (hcg) {
  6694. var c = hcg[1] / 100;
  6695. var g = hcg[2] / 100;
  6696. var v = c + g * (1.0 - c);
  6697. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  6698. };
  6699. convert.hwb.hcg = function (hwb) {
  6700. var w = hwb[1] / 100;
  6701. var b = hwb[2] / 100;
  6702. var v = 1 - b;
  6703. var c = v - w;
  6704. var g = 0;
  6705. if (c < 1) {
  6706. g = (v - c) / (1 - c);
  6707. }
  6708. return [hwb[0], c * 100, g * 100];
  6709. };
  6710. convert.apple.rgb = function (apple) {
  6711. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  6712. };
  6713. convert.rgb.apple = function (rgb) {
  6714. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  6715. };
  6716. convert.gray.rgb = function (args) {
  6717. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  6718. };
  6719. convert.gray.hsl = convert.gray.hsv = function (args) {
  6720. return [0, 0, args[0]];
  6721. };
  6722. convert.gray.hwb = function (gray) {
  6723. return [0, 100, gray[0]];
  6724. };
  6725. convert.gray.cmyk = function (gray) {
  6726. return [0, 0, 0, gray[0]];
  6727. };
  6728. convert.gray.lab = function (gray) {
  6729. return [gray[0], 0, 0];
  6730. };
  6731. convert.gray.hex = function (gray) {
  6732. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  6733. var integer = (val << 16) + (val << 8) + val;
  6734. var string = integer.toString(16).toUpperCase();
  6735. return '000000'.substring(string.length) + string;
  6736. };
  6737. convert.rgb.gray = function (rgb) {
  6738. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  6739. return [val / 255 * 100];
  6740. };
  6741. });
  6742. var conversions_1 = conversions.rgb;
  6743. var conversions_2 = conversions.hsl;
  6744. var conversions_3 = conversions.hsv;
  6745. var conversions_4 = conversions.hwb;
  6746. var conversions_5 = conversions.cmyk;
  6747. var conversions_6 = conversions.xyz;
  6748. var conversions_7 = conversions.lab;
  6749. var conversions_8 = conversions.lch;
  6750. var conversions_9 = conversions.hex;
  6751. var conversions_10 = conversions.keyword;
  6752. var conversions_11 = conversions.ansi16;
  6753. var conversions_12 = conversions.ansi256;
  6754. var conversions_13 = conversions.hcg;
  6755. var conversions_14 = conversions.apple;
  6756. var conversions_15 = conversions.gray;
  6757. /*
  6758. this function routes a model to all other models.
  6759. all functions that are routed have a property `.conversion` attached
  6760. to the returned synthetic function. This property is an array
  6761. of strings, each with the steps in between the 'from' and 'to'
  6762. color models (inclusive).
  6763. conversions that are not possible simply are not included.
  6764. */
  6765. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  6766. var models = Object.keys(conversions);
  6767. function buildGraph() {
  6768. var graph = {};
  6769. for (var len = models.length, i = 0; i < len; i++) {
  6770. graph[models[i]] = {
  6771. // http://jsperf.com/1-vs-infinity
  6772. // micro-opt, but this is simple.
  6773. distance: -1,
  6774. parent: null
  6775. };
  6776. }
  6777. return graph;
  6778. } // https://en.wikipedia.org/wiki/Breadth-first_search
  6779. function deriveBFS(fromModel) {
  6780. var graph = buildGraph();
  6781. var queue = [fromModel]; // unshift -> queue -> pop
  6782. graph[fromModel].distance = 0;
  6783. while (queue.length) {
  6784. var current = queue.pop();
  6785. var adjacents = Object.keys(conversions[current]);
  6786. for (var len = adjacents.length, i = 0; i < len; i++) {
  6787. var adjacent = adjacents[i];
  6788. var node = graph[adjacent];
  6789. if (node.distance === -1) {
  6790. node.distance = graph[current].distance + 1;
  6791. node.parent = current;
  6792. queue.unshift(adjacent);
  6793. }
  6794. }
  6795. }
  6796. return graph;
  6797. }
  6798. function link(from, to) {
  6799. return function (args) {
  6800. return to(from(args));
  6801. };
  6802. }
  6803. function wrapConversion(toModel, graph) {
  6804. var path = [graph[toModel].parent, toModel];
  6805. var fn = conversions[graph[toModel].parent][toModel];
  6806. var cur = graph[toModel].parent;
  6807. while (graph[cur].parent) {
  6808. path.unshift(graph[cur].parent);
  6809. fn = link(conversions[graph[cur].parent][cur], fn);
  6810. cur = graph[cur].parent;
  6811. }
  6812. fn.conversion = path;
  6813. return fn;
  6814. }
  6815. var route = function route(fromModel) {
  6816. var graph = deriveBFS(fromModel);
  6817. var conversion = {};
  6818. var models = Object.keys(graph);
  6819. for (var len = models.length, i = 0; i < len; i++) {
  6820. var toModel = models[i];
  6821. var node = graph[toModel];
  6822. if (node.parent === null) {
  6823. // no possible conversion, or this node is the source model.
  6824. continue;
  6825. }
  6826. conversion[toModel] = wrapConversion(toModel, graph);
  6827. }
  6828. return conversion;
  6829. };
  6830. var convert = {};
  6831. var models$1 = Object.keys(conversions);
  6832. function wrapRaw(fn) {
  6833. var wrappedFn = function wrappedFn(args) {
  6834. if (args === undefined || args === null) {
  6835. return args;
  6836. }
  6837. if (arguments.length > 1) {
  6838. args = Array.prototype.slice.call(arguments);
  6839. }
  6840. return fn(args);
  6841. }; // preserve .conversion property if there is one
  6842. if ('conversion' in fn) {
  6843. wrappedFn.conversion = fn.conversion;
  6844. }
  6845. return wrappedFn;
  6846. }
  6847. function wrapRounded(fn) {
  6848. var wrappedFn = function wrappedFn(args) {
  6849. if (args === undefined || args === null) {
  6850. return args;
  6851. }
  6852. if (arguments.length > 1) {
  6853. args = Array.prototype.slice.call(arguments);
  6854. }
  6855. var result = fn(args); // we're assuming the result is an array here.
  6856. // see notice in conversions.js; don't use box types
  6857. // in conversion functions.
  6858. if (_typeof(result) === 'object') {
  6859. for (var len = result.length, i = 0; i < len; i++) {
  6860. result[i] = Math.round(result[i]);
  6861. }
  6862. }
  6863. return result;
  6864. }; // preserve .conversion property if there is one
  6865. if ('conversion' in fn) {
  6866. wrappedFn.conversion = fn.conversion;
  6867. }
  6868. return wrappedFn;
  6869. }
  6870. models$1.forEach(function (fromModel) {
  6871. convert[fromModel] = {};
  6872. Object.defineProperty(convert[fromModel], 'channels', {
  6873. value: conversions[fromModel].channels
  6874. });
  6875. Object.defineProperty(convert[fromModel], 'labels', {
  6876. value: conversions[fromModel].labels
  6877. });
  6878. var routes = route(fromModel);
  6879. var routeModels = Object.keys(routes);
  6880. routeModels.forEach(function (toModel) {
  6881. var fn = routes[toModel];
  6882. convert[fromModel][toModel] = wrapRounded(fn);
  6883. convert[fromModel][toModel].raw = wrapRaw(fn);
  6884. });
  6885. });
  6886. var colorConvert = convert;
  6887. var ansiStyles = createCommonjsModule(function (module) {
  6888. var wrapAnsi16 = function wrapAnsi16(fn, offset) {
  6889. return function () {
  6890. var code = fn.apply(colorConvert, arguments);
  6891. return "\x1B[".concat(code + offset, "m");
  6892. };
  6893. };
  6894. var wrapAnsi256 = function wrapAnsi256(fn, offset) {
  6895. return function () {
  6896. var code = fn.apply(colorConvert, arguments);
  6897. return "\x1B[".concat(38 + offset, ";5;").concat(code, "m");
  6898. };
  6899. };
  6900. var wrapAnsi16m = function wrapAnsi16m(fn, offset) {
  6901. return function () {
  6902. var rgb = fn.apply(colorConvert, arguments);
  6903. return "\x1B[".concat(38 + offset, ";2;").concat(rgb[0], ";").concat(rgb[1], ";").concat(rgb[2], "m");
  6904. };
  6905. };
  6906. function assembleStyles() {
  6907. var codes = new Map();
  6908. var styles = {
  6909. modifier: {
  6910. reset: [0, 0],
  6911. // 21 isn't widely supported and 22 does the same thing
  6912. bold: [1, 22],
  6913. dim: [2, 22],
  6914. italic: [3, 23],
  6915. underline: [4, 24],
  6916. inverse: [7, 27],
  6917. hidden: [8, 28],
  6918. strikethrough: [9, 29]
  6919. },
  6920. color: {
  6921. black: [30, 39],
  6922. red: [31, 39],
  6923. green: [32, 39],
  6924. yellow: [33, 39],
  6925. blue: [34, 39],
  6926. magenta: [35, 39],
  6927. cyan: [36, 39],
  6928. white: [37, 39],
  6929. gray: [90, 39],
  6930. // Bright color
  6931. redBright: [91, 39],
  6932. greenBright: [92, 39],
  6933. yellowBright: [93, 39],
  6934. blueBright: [94, 39],
  6935. magentaBright: [95, 39],
  6936. cyanBright: [96, 39],
  6937. whiteBright: [97, 39]
  6938. },
  6939. bgColor: {
  6940. bgBlack: [40, 49],
  6941. bgRed: [41, 49],
  6942. bgGreen: [42, 49],
  6943. bgYellow: [43, 49],
  6944. bgBlue: [44, 49],
  6945. bgMagenta: [45, 49],
  6946. bgCyan: [46, 49],
  6947. bgWhite: [47, 49],
  6948. // Bright color
  6949. bgBlackBright: [100, 49],
  6950. bgRedBright: [101, 49],
  6951. bgGreenBright: [102, 49],
  6952. bgYellowBright: [103, 49],
  6953. bgBlueBright: [104, 49],
  6954. bgMagentaBright: [105, 49],
  6955. bgCyanBright: [106, 49],
  6956. bgWhiteBright: [107, 49]
  6957. }
  6958. }; // Fix humans
  6959. styles.color.grey = styles.color.gray;
  6960. for (var _i = 0, _Object$keys = Object.keys(styles); _i < _Object$keys.length; _i++) {
  6961. var groupName = _Object$keys[_i];
  6962. var group = styles[groupName];
  6963. for (var _i3 = 0, _Object$keys3 = Object.keys(group); _i3 < _Object$keys3.length; _i3++) {
  6964. var styleName = _Object$keys3[_i3];
  6965. var style = group[styleName];
  6966. styles[styleName] = {
  6967. open: "\x1B[".concat(style[0], "m"),
  6968. close: "\x1B[".concat(style[1], "m")
  6969. };
  6970. group[styleName] = styles[styleName];
  6971. codes.set(style[0], style[1]);
  6972. }
  6973. Object.defineProperty(styles, groupName, {
  6974. value: group,
  6975. enumerable: false
  6976. });
  6977. Object.defineProperty(styles, 'codes', {
  6978. value: codes,
  6979. enumerable: false
  6980. });
  6981. }
  6982. var ansi2ansi = function ansi2ansi(n) {
  6983. return n;
  6984. };
  6985. var rgb2rgb = function rgb2rgb(r, g, b) {
  6986. return [r, g, b];
  6987. };
  6988. styles.color.close = "\x1B[39m";
  6989. styles.bgColor.close = "\x1B[49m";
  6990. styles.color.ansi = {
  6991. ansi: wrapAnsi16(ansi2ansi, 0)
  6992. };
  6993. styles.color.ansi256 = {
  6994. ansi256: wrapAnsi256(ansi2ansi, 0)
  6995. };
  6996. styles.color.ansi16m = {
  6997. rgb: wrapAnsi16m(rgb2rgb, 0)
  6998. };
  6999. styles.bgColor.ansi = {
  7000. ansi: wrapAnsi16(ansi2ansi, 10)
  7001. };
  7002. styles.bgColor.ansi256 = {
  7003. ansi256: wrapAnsi256(ansi2ansi, 10)
  7004. };
  7005. styles.bgColor.ansi16m = {
  7006. rgb: wrapAnsi16m(rgb2rgb, 10)
  7007. };
  7008. for (var _i2 = 0, _Object$keys2 = Object.keys(colorConvert); _i2 < _Object$keys2.length; _i2++) {
  7009. var key = _Object$keys2[_i2];
  7010. if (_typeof(colorConvert[key]) !== 'object') {
  7011. continue;
  7012. }
  7013. var suite = colorConvert[key];
  7014. if (key === 'ansi16') {
  7015. key = 'ansi';
  7016. }
  7017. if ('ansi16' in suite) {
  7018. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  7019. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  7020. }
  7021. if ('ansi256' in suite) {
  7022. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  7023. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  7024. }
  7025. if ('rgb' in suite) {
  7026. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  7027. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  7028. }
  7029. }
  7030. return styles;
  7031. } // Make the export immutable
  7032. Object.defineProperty(module, 'exports', {
  7033. enumerable: true,
  7034. get: assembleStyles
  7035. });
  7036. });
  7037. var require$$0$1 = {
  7038. EOL: "\n"
  7039. };
  7040. var hasFlag = function hasFlag(flag, argv) {
  7041. argv = argv || process.argv;
  7042. var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  7043. var pos = argv.indexOf(prefix + flag);
  7044. var terminatorPos = argv.indexOf('--');
  7045. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  7046. };
  7047. var env$1 = process.env;
  7048. var forceColor;
  7049. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  7050. forceColor = false;
  7051. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  7052. forceColor = true;
  7053. }
  7054. if ('FORCE_COLOR' in env$1) {
  7055. forceColor = env$1.FORCE_COLOR.length === 0 || parseInt(env$1.FORCE_COLOR, 10) !== 0;
  7056. }
  7057. function translateLevel(level) {
  7058. if (level === 0) {
  7059. return false;
  7060. }
  7061. return {
  7062. level: level,
  7063. hasBasic: true,
  7064. has256: level >= 2,
  7065. has16m: level >= 3
  7066. };
  7067. }
  7068. function supportsColor(stream) {
  7069. if (forceColor === false) {
  7070. return 0;
  7071. }
  7072. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  7073. return 3;
  7074. }
  7075. if (hasFlag('color=256')) {
  7076. return 2;
  7077. }
  7078. if (stream && !stream.isTTY && forceColor !== true) {
  7079. return 0;
  7080. }
  7081. var min = forceColor ? 1 : 0;
  7082. if (process.platform === 'win32') {
  7083. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  7084. // libuv that enables 256 color output on Windows. Anything earlier and it
  7085. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  7086. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  7087. // release that supports 256 colors. Windows 10 build 14931 is the first release
  7088. // that supports 16m/TrueColor.
  7089. var osRelease = require$$0$1.release().split('.');
  7090. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  7091. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  7092. }
  7093. return 1;
  7094. }
  7095. if ('CI' in env$1) {
  7096. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  7097. return sign in env$1;
  7098. }) || env$1.CI_NAME === 'codeship') {
  7099. return 1;
  7100. }
  7101. return min;
  7102. }
  7103. if ('TEAMCITY_VERSION' in env$1) {
  7104. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env$1.TEAMCITY_VERSION) ? 1 : 0;
  7105. }
  7106. if (env$1.COLORTERM === 'truecolor') {
  7107. return 3;
  7108. }
  7109. if ('TERM_PROGRAM' in env$1) {
  7110. var version = parseInt((env$1.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  7111. switch (env$1.TERM_PROGRAM) {
  7112. case 'iTerm.app':
  7113. return version >= 3 ? 3 : 2;
  7114. case 'Apple_Terminal':
  7115. return 2;
  7116. // No default
  7117. }
  7118. }
  7119. if (/-256(color)?$/i.test(env$1.TERM)) {
  7120. return 2;
  7121. }
  7122. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env$1.TERM)) {
  7123. return 1;
  7124. }
  7125. if ('COLORTERM' in env$1) {
  7126. return 1;
  7127. }
  7128. if (env$1.TERM === 'dumb') {
  7129. return min;
  7130. }
  7131. return min;
  7132. }
  7133. function getSupportLevel(stream) {
  7134. var level = supportsColor(stream);
  7135. return translateLevel(level);
  7136. }
  7137. var supportsColor_1 = {
  7138. supportsColor: getSupportLevel,
  7139. stdout: getSupportLevel(process.stdout),
  7140. stderr: getSupportLevel(process.stderr)
  7141. };
  7142. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  7143. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  7144. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  7145. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  7146. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', "\x1B"], ['a', "\x07"]]);
  7147. function unescape(c) {
  7148. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  7149. return String.fromCharCode(parseInt(c.slice(1), 16));
  7150. }
  7151. return ESCAPES.get(c) || c;
  7152. }
  7153. function parseArguments(name, args) {
  7154. var results = [];
  7155. var chunks = args.trim().split(/\s*,\s*/g);
  7156. var matches;
  7157. var _iteratorNormalCompletion = true;
  7158. var _didIteratorError = false;
  7159. var _iteratorError = undefined;
  7160. try {
  7161. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7162. var chunk = _step.value;
  7163. if (!isNaN(chunk)) {
  7164. results.push(Number(chunk));
  7165. } else if (matches = chunk.match(STRING_REGEX)) {
  7166. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  7167. return escape ? unescape(escape) : chr;
  7168. }));
  7169. } else {
  7170. throw new Error("Invalid Chalk template style argument: ".concat(chunk, " (in style '").concat(name, "')"));
  7171. }
  7172. }
  7173. } catch (err) {
  7174. _didIteratorError = true;
  7175. _iteratorError = err;
  7176. } finally {
  7177. try {
  7178. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7179. _iterator.return();
  7180. }
  7181. } finally {
  7182. if (_didIteratorError) {
  7183. throw _iteratorError;
  7184. }
  7185. }
  7186. }
  7187. return results;
  7188. }
  7189. function parseStyle(style) {
  7190. STYLE_REGEX.lastIndex = 0;
  7191. var results = [];
  7192. var matches;
  7193. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  7194. var name = matches[1];
  7195. if (matches[2]) {
  7196. var args = parseArguments(name, matches[2]);
  7197. results.push([name].concat(args));
  7198. } else {
  7199. results.push([name]);
  7200. }
  7201. }
  7202. return results;
  7203. }
  7204. function buildStyle(chalk, styles) {
  7205. var enabled = {};
  7206. var _iteratorNormalCompletion2 = true;
  7207. var _didIteratorError2 = false;
  7208. var _iteratorError2 = undefined;
  7209. try {
  7210. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  7211. var layer = _step2.value;
  7212. var _iteratorNormalCompletion3 = true;
  7213. var _didIteratorError3 = false;
  7214. var _iteratorError3 = undefined;
  7215. try {
  7216. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  7217. var style = _step3.value;
  7218. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  7219. }
  7220. } catch (err) {
  7221. _didIteratorError3 = true;
  7222. _iteratorError3 = err;
  7223. } finally {
  7224. try {
  7225. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  7226. _iterator3.return();
  7227. }
  7228. } finally {
  7229. if (_didIteratorError3) {
  7230. throw _iteratorError3;
  7231. }
  7232. }
  7233. }
  7234. }
  7235. } catch (err) {
  7236. _didIteratorError2 = true;
  7237. _iteratorError2 = err;
  7238. } finally {
  7239. try {
  7240. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  7241. _iterator2.return();
  7242. }
  7243. } finally {
  7244. if (_didIteratorError2) {
  7245. throw _iteratorError2;
  7246. }
  7247. }
  7248. }
  7249. var current = chalk;
  7250. for (var _i = 0, _Object$keys = Object.keys(enabled); _i < _Object$keys.length; _i++) {
  7251. var styleName = _Object$keys[_i];
  7252. if (Array.isArray(enabled[styleName])) {
  7253. if (!(styleName in current)) {
  7254. throw new Error("Unknown Chalk style: ".concat(styleName));
  7255. }
  7256. if (enabled[styleName].length > 0) {
  7257. current = current[styleName].apply(current, enabled[styleName]);
  7258. } else {
  7259. current = current[styleName];
  7260. }
  7261. }
  7262. }
  7263. return current;
  7264. }
  7265. var templates = function templates(chalk, tmp) {
  7266. var styles = [];
  7267. var chunks = [];
  7268. var chunk = []; // eslint-disable-next-line max-params
  7269. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  7270. if (escapeChar) {
  7271. chunk.push(unescape(escapeChar));
  7272. } else if (style) {
  7273. var str = chunk.join('');
  7274. chunk = [];
  7275. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  7276. styles.push({
  7277. inverse: inverse,
  7278. styles: parseStyle(style)
  7279. });
  7280. } else if (close) {
  7281. if (styles.length === 0) {
  7282. throw new Error('Found extraneous } in Chalk template literal');
  7283. }
  7284. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  7285. chunk = [];
  7286. styles.pop();
  7287. } else {
  7288. chunk.push(chr);
  7289. }
  7290. });
  7291. chunks.push(chunk.join(''));
  7292. if (styles.length > 0) {
  7293. var errMsg = "Chalk template literal is missing ".concat(styles.length, " closing bracket").concat(styles.length === 1 ? '' : 's', " (`}`)");
  7294. throw new Error(errMsg);
  7295. }
  7296. return chunks.join('');
  7297. };
  7298. var chalk = createCommonjsModule(function (module) {
  7299. var stdoutColor = supportsColor_1.stdout;
  7300. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  7301. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  7302. var skipModels = new Set(['gray']);
  7303. var styles = Object.create(null);
  7304. function applyOptions(obj, options) {
  7305. options = options || {}; // Detect level if not set manually
  7306. var scLevel = stdoutColor ? stdoutColor.level : 0;
  7307. obj.level = options.level === undefined ? scLevel : options.level;
  7308. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  7309. }
  7310. function Chalk(options) {
  7311. // We check for this.template here since calling `chalk.constructor()`
  7312. // by itself will have a `this` of a previously constructed chalk object
  7313. if (!this || !(this instanceof Chalk) || this.template) {
  7314. var _chalk = {};
  7315. applyOptions(_chalk, options);
  7316. _chalk.template = function () {
  7317. var args = [].slice.call(arguments);
  7318. return chalkTag.apply(null, [_chalk.template].concat(args));
  7319. };
  7320. Object.setPrototypeOf(_chalk, Chalk.prototype);
  7321. Object.setPrototypeOf(_chalk.template, _chalk);
  7322. _chalk.template.constructor = Chalk;
  7323. return _chalk.template;
  7324. }
  7325. applyOptions(this, options);
  7326. } // Use bright blue on Windows as the normal blue color is illegible
  7327. if (isSimpleWindowsTerm) {
  7328. ansiStyles.blue.open = "\x1B[94m";
  7329. }
  7330. var _loop = function _loop() {
  7331. var key = _Object$keys[_i];
  7332. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  7333. styles[key] = {
  7334. get: function get() {
  7335. var codes = ansiStyles[key];
  7336. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  7337. }
  7338. };
  7339. };
  7340. for (var _i = 0, _Object$keys = Object.keys(ansiStyles); _i < _Object$keys.length; _i++) {
  7341. _loop();
  7342. }
  7343. styles.visible = {
  7344. get: function get() {
  7345. return build.call(this, this._styles || [], true, 'visible');
  7346. }
  7347. };
  7348. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  7349. var _loop2 = function _loop2() {
  7350. var model = _Object$keys2[_i2];
  7351. if (skipModels.has(model)) {
  7352. return "continue";
  7353. }
  7354. styles[model] = {
  7355. get: function get() {
  7356. var level = this.level;
  7357. return function () {
  7358. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  7359. var codes = {
  7360. open: open,
  7361. close: ansiStyles.color.close,
  7362. closeRe: ansiStyles.color.closeRe
  7363. };
  7364. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  7365. };
  7366. }
  7367. };
  7368. };
  7369. for (var _i2 = 0, _Object$keys2 = Object.keys(ansiStyles.color.ansi); _i2 < _Object$keys2.length; _i2++) {
  7370. var _ret = _loop2();
  7371. if (_ret === "continue") continue;
  7372. }
  7373. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  7374. var _loop3 = function _loop3() {
  7375. var model = _Object$keys3[_i3];
  7376. if (skipModels.has(model)) {
  7377. return "continue";
  7378. }
  7379. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  7380. styles[bgModel] = {
  7381. get: function get() {
  7382. var level = this.level;
  7383. return function () {
  7384. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  7385. var codes = {
  7386. open: open,
  7387. close: ansiStyles.bgColor.close,
  7388. closeRe: ansiStyles.bgColor.closeRe
  7389. };
  7390. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  7391. };
  7392. }
  7393. };
  7394. };
  7395. for (var _i3 = 0, _Object$keys3 = Object.keys(ansiStyles.bgColor.ansi); _i3 < _Object$keys3.length; _i3++) {
  7396. var _ret2 = _loop3();
  7397. if (_ret2 === "continue") continue;
  7398. }
  7399. var proto = Object.defineProperties(function () {}, styles);
  7400. function build(_styles, _empty, key) {
  7401. var builder = function builder() {
  7402. return applyStyle.apply(builder, arguments);
  7403. };
  7404. builder._styles = _styles;
  7405. builder._empty = _empty;
  7406. var self = this;
  7407. Object.defineProperty(builder, 'level', {
  7408. enumerable: true,
  7409. get: function get() {
  7410. return self.level;
  7411. },
  7412. set: function set(level) {
  7413. self.level = level;
  7414. }
  7415. });
  7416. Object.defineProperty(builder, 'enabled', {
  7417. enumerable: true,
  7418. get: function get() {
  7419. return self.enabled;
  7420. },
  7421. set: function set(enabled) {
  7422. self.enabled = enabled;
  7423. }
  7424. }); // See below for fix regarding invisible grey/dim combination on Windows
  7425. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  7426. // no way to create a function with a different prototype
  7427. builder.__proto__ = proto; // eslint-disable-line no-proto
  7428. return builder;
  7429. }
  7430. function applyStyle() {
  7431. // Support varags, but simply cast to string in case there's only one arg
  7432. var args = arguments;
  7433. var argsLen = args.length;
  7434. var str = String(arguments[0]);
  7435. if (argsLen === 0) {
  7436. return '';
  7437. }
  7438. if (argsLen > 1) {
  7439. // Don't slice `arguments`, it prevents V8 optimizations
  7440. for (var a = 1; a < argsLen; a++) {
  7441. str += ' ' + args[a];
  7442. }
  7443. }
  7444. if (!this.enabled || this.level <= 0 || !str) {
  7445. return this._empty ? '' : str;
  7446. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  7447. // see https://github.com/chalk/chalk/issues/58
  7448. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  7449. var originalDim = ansiStyles.dim.open;
  7450. if (isSimpleWindowsTerm && this.hasGrey) {
  7451. ansiStyles.dim.open = '';
  7452. }
  7453. var _iteratorNormalCompletion = true;
  7454. var _didIteratorError = false;
  7455. var _iteratorError = undefined;
  7456. try {
  7457. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7458. var code = _step.value;
  7459. // Replace any instances already present with a re-opening code
  7460. // otherwise only the part of the string until said closing code
  7461. // will be colored, and the rest will simply be 'plain'.
  7462. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  7463. // after next line to fix a bleed issue on macOS
  7464. // https://github.com/chalk/chalk/pull/92
  7465. str = str.replace(/\r?\n/g, "".concat(code.close, "$&").concat(code.open));
  7466. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  7467. } catch (err) {
  7468. _didIteratorError = true;
  7469. _iteratorError = err;
  7470. } finally {
  7471. try {
  7472. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7473. _iterator.return();
  7474. }
  7475. } finally {
  7476. if (_didIteratorError) {
  7477. throw _iteratorError;
  7478. }
  7479. }
  7480. }
  7481. ansiStyles.dim.open = originalDim;
  7482. return str;
  7483. }
  7484. function chalkTag(chalk, strings) {
  7485. if (!Array.isArray(strings)) {
  7486. // If chalk() was called by itself or with a string,
  7487. // return the string itself as a string.
  7488. return [].slice.call(arguments, 1).join(' ');
  7489. }
  7490. var args = [].slice.call(arguments, 2);
  7491. var parts = [strings.raw[0]];
  7492. for (var i = 1; i < strings.length; i++) {
  7493. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  7494. parts.push(String(strings.raw[i]));
  7495. }
  7496. return templates(chalk, parts.join(''));
  7497. }
  7498. Object.defineProperties(Chalk.prototype, styles);
  7499. module.exports = Chalk(); // eslint-disable-line new-cap
  7500. module.exports.supportsColor = stdoutColor;
  7501. module.exports.default = module.exports; // For TypeScript
  7502. });
  7503. var chalk_1 = chalk.supportsColor;
  7504. var common = createCommonjsModule(function (module, exports) {
  7505. Object.defineProperty(exports, "__esModule", {
  7506. value: true
  7507. });
  7508. exports.commonDeprecatedHandler = function (keyOrPair, redirectTo, _ref) {
  7509. var descriptor = _ref.descriptor;
  7510. var messages = ["".concat(chalk.default.yellow(typeof keyOrPair === 'string' ? descriptor.key(keyOrPair) : descriptor.pair(keyOrPair)), " is deprecated")];
  7511. if (redirectTo) {
  7512. messages.push("we now treat it as ".concat(chalk.default.blue(typeof redirectTo === 'string' ? descriptor.key(redirectTo) : descriptor.pair(redirectTo))));
  7513. }
  7514. return messages.join('; ') + '.';
  7515. };
  7516. });
  7517. unwrapExports(common);
  7518. var common_1 = common.commonDeprecatedHandler;
  7519. var deprecated = createCommonjsModule(function (module, exports) {
  7520. Object.defineProperty(exports, "__esModule", {
  7521. value: true
  7522. });
  7523. tslib_1.__exportStar(common, exports);
  7524. });
  7525. unwrapExports(deprecated);
  7526. var common$1 = createCommonjsModule(function (module, exports) {
  7527. Object.defineProperty(exports, "__esModule", {
  7528. value: true
  7529. });
  7530. exports.commonInvalidHandler = function (key, value, utils) {
  7531. return ["Invalid ".concat(chalk.default.red(utils.descriptor.key(key)), " value."), "Expected ".concat(chalk.default.blue(utils.schemas[key].expected(utils)), ","), "but received ".concat(chalk.default.red(utils.descriptor.value(value)), ".")].join(' ');
  7532. };
  7533. });
  7534. unwrapExports(common$1);
  7535. var common_1$1 = common$1.commonInvalidHandler;
  7536. var invalid = createCommonjsModule(function (module, exports) {
  7537. Object.defineProperty(exports, "__esModule", {
  7538. value: true
  7539. });
  7540. tslib_1.__exportStar(common$1, exports);
  7541. });
  7542. unwrapExports(invalid);
  7543. /* eslint-disable no-nested-ternary */
  7544. var arr = [];
  7545. var charCodeCache = [];
  7546. var leven = function leven(a, b) {
  7547. if (a === b) {
  7548. return 0;
  7549. }
  7550. var swap = a; // Swapping the strings if `a` is longer than `b` so we know which one is the
  7551. // shortest & which one is the longest
  7552. if (a.length > b.length) {
  7553. a = b;
  7554. b = swap;
  7555. }
  7556. var aLen = a.length;
  7557. var bLen = b.length;
  7558. if (aLen === 0) {
  7559. return bLen;
  7560. }
  7561. if (bLen === 0) {
  7562. return aLen;
  7563. } // Performing suffix trimming:
  7564. // We can linearly drop suffix common to both strings since they
  7565. // don't increase distance at all
  7566. // Note: `~-` is the bitwise way to perform a `- 1` operation
  7567. while (aLen > 0 && a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen)) {
  7568. aLen--;
  7569. bLen--;
  7570. }
  7571. if (aLen === 0) {
  7572. return bLen;
  7573. } // Performing prefix trimming
  7574. // We can linearly drop prefix common to both strings since they
  7575. // don't increase distance at all
  7576. var start = 0;
  7577. while (start < aLen && a.charCodeAt(start) === b.charCodeAt(start)) {
  7578. start++;
  7579. }
  7580. aLen -= start;
  7581. bLen -= start;
  7582. if (aLen === 0) {
  7583. return bLen;
  7584. }
  7585. var bCharCode;
  7586. var ret;
  7587. var tmp;
  7588. var tmp2;
  7589. var i = 0;
  7590. var j = 0;
  7591. while (i < aLen) {
  7592. charCodeCache[start + i] = a.charCodeAt(start + i);
  7593. arr[i] = ++i;
  7594. }
  7595. while (j < bLen) {
  7596. bCharCode = b.charCodeAt(start + j);
  7597. tmp = j++;
  7598. ret = j;
  7599. for (i = 0; i < aLen; i++) {
  7600. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  7601. tmp = arr[i];
  7602. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  7603. }
  7604. }
  7605. return ret;
  7606. };
  7607. var leven_1 = createCommonjsModule(function (module, exports) {
  7608. Object.defineProperty(exports, "__esModule", {
  7609. value: true
  7610. });
  7611. exports.levenUnknownHandler = function (key, value, _ref) {
  7612. var descriptor = _ref.descriptor,
  7613. logger = _ref.logger,
  7614. schemas = _ref.schemas;
  7615. var messages = ["Ignored unknown option ".concat(chalk.default.yellow(descriptor.pair({
  7616. key: key,
  7617. value: value
  7618. })), ".")];
  7619. var suggestion = Object.keys(schemas).sort().find(function (knownKey) {
  7620. return leven(key, knownKey) < 3;
  7621. });
  7622. if (suggestion) {
  7623. messages.push("Did you mean ".concat(chalk.default.blue(descriptor.key(suggestion)), "?"));
  7624. }
  7625. logger.warn(messages.join(' '));
  7626. };
  7627. });
  7628. unwrapExports(leven_1);
  7629. var leven_2 = leven_1.levenUnknownHandler;
  7630. var unknown = createCommonjsModule(function (module, exports) {
  7631. Object.defineProperty(exports, "__esModule", {
  7632. value: true
  7633. });
  7634. tslib_1.__exportStar(leven_1, exports);
  7635. });
  7636. unwrapExports(unknown);
  7637. var handlers = createCommonjsModule(function (module, exports) {
  7638. Object.defineProperty(exports, "__esModule", {
  7639. value: true
  7640. });
  7641. tslib_1.__exportStar(deprecated, exports);
  7642. tslib_1.__exportStar(invalid, exports);
  7643. tslib_1.__exportStar(unknown, exports);
  7644. });
  7645. unwrapExports(handlers);
  7646. var schema = createCommonjsModule(function (module, exports) {
  7647. Object.defineProperty(exports, "__esModule", {
  7648. value: true
  7649. });
  7650. var HANDLER_KEYS = ['default', 'expected', 'validate', 'deprecated', 'forward', 'redirect', 'overlap', 'preprocess', 'postprocess'];
  7651. function createSchema(SchemaConstructor, parameters) {
  7652. var schema = new SchemaConstructor(parameters);
  7653. var subSchema = Object.create(schema);
  7654. var _iteratorNormalCompletion = true;
  7655. var _didIteratorError = false;
  7656. var _iteratorError = undefined;
  7657. try {
  7658. for (var _iterator = HANDLER_KEYS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7659. var handlerKey = _step.value;
  7660. if (handlerKey in parameters) {
  7661. subSchema[handlerKey] = normalizeHandler(parameters[handlerKey], schema, Schema.prototype[handlerKey].length);
  7662. }
  7663. }
  7664. } catch (err) {
  7665. _didIteratorError = true;
  7666. _iteratorError = err;
  7667. } finally {
  7668. try {
  7669. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7670. _iterator.return();
  7671. }
  7672. } finally {
  7673. if (_didIteratorError) {
  7674. throw _iteratorError;
  7675. }
  7676. }
  7677. }
  7678. return subSchema;
  7679. }
  7680. exports.createSchema = createSchema;
  7681. var Schema =
  7682. /*#__PURE__*/
  7683. function () {
  7684. function Schema(parameters) {
  7685. _classCallCheck(this, Schema);
  7686. this.name = parameters.name;
  7687. }
  7688. _createClass(Schema, [{
  7689. key: "default",
  7690. value: function _default(_utils) {
  7691. return undefined;
  7692. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  7693. }, {
  7694. key: "expected",
  7695. value: function expected(_utils) {
  7696. return 'nothing';
  7697. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  7698. }, {
  7699. key: "validate",
  7700. value: function validate(_value, _utils) {
  7701. return false;
  7702. }
  7703. }, {
  7704. key: "deprecated",
  7705. value: function deprecated(_value, _utils) {
  7706. return false;
  7707. }
  7708. }, {
  7709. key: "forward",
  7710. value: function forward(_value, _utils) {
  7711. return undefined;
  7712. }
  7713. }, {
  7714. key: "redirect",
  7715. value: function redirect(_value, _utils) {
  7716. return undefined;
  7717. }
  7718. }, {
  7719. key: "overlap",
  7720. value: function overlap(currentValue, _newValue, _utils) {
  7721. return currentValue;
  7722. }
  7723. }, {
  7724. key: "preprocess",
  7725. value: function preprocess(value, _utils) {
  7726. return value;
  7727. }
  7728. }, {
  7729. key: "postprocess",
  7730. value: function postprocess(value, _utils) {
  7731. return value;
  7732. }
  7733. }], [{
  7734. key: "create",
  7735. value: function create(parameters) {
  7736. // @ts-ignore: https://github.com/Microsoft/TypeScript/issues/5863
  7737. return createSchema(this, parameters);
  7738. }
  7739. }]);
  7740. return Schema;
  7741. }();
  7742. exports.Schema = Schema;
  7743. function normalizeHandler(handler, superSchema, handlerArgumentsLength) {
  7744. return typeof handler === 'function' ? function () {
  7745. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  7746. args[_key] = arguments[_key];
  7747. }
  7748. return handler.apply(void 0, _toConsumableArray(args.slice(0, handlerArgumentsLength - 1)).concat([superSchema], _toConsumableArray(args.slice(handlerArgumentsLength - 1))));
  7749. } : function () {
  7750. return handler;
  7751. };
  7752. }
  7753. });
  7754. unwrapExports(schema);
  7755. var schema_1 = schema.createSchema;
  7756. var schema_2 = schema.Schema;
  7757. var alias = createCommonjsModule(function (module, exports) {
  7758. Object.defineProperty(exports, "__esModule", {
  7759. value: true
  7760. });
  7761. var AliasSchema =
  7762. /*#__PURE__*/
  7763. function (_schema_1$Schema) {
  7764. _inherits(AliasSchema, _schema_1$Schema);
  7765. function AliasSchema(parameters) {
  7766. var _this;
  7767. _classCallCheck(this, AliasSchema);
  7768. _this = _possibleConstructorReturn(this, _getPrototypeOf(AliasSchema).call(this, parameters));
  7769. _this._sourceName = parameters.sourceName;
  7770. return _this;
  7771. }
  7772. _createClass(AliasSchema, [{
  7773. key: "expected",
  7774. value: function expected(utils) {
  7775. return utils.schemas[this._sourceName].expected(utils);
  7776. }
  7777. }, {
  7778. key: "validate",
  7779. value: function validate(value, utils) {
  7780. return utils.schemas[this._sourceName].validate(value, utils);
  7781. }
  7782. }, {
  7783. key: "redirect",
  7784. value: function redirect(_value, _utils) {
  7785. return this._sourceName;
  7786. }
  7787. }]);
  7788. return AliasSchema;
  7789. }(schema.Schema);
  7790. exports.AliasSchema = AliasSchema;
  7791. });
  7792. unwrapExports(alias);
  7793. var alias_1 = alias.AliasSchema;
  7794. var any = createCommonjsModule(function (module, exports) {
  7795. Object.defineProperty(exports, "__esModule", {
  7796. value: true
  7797. });
  7798. var AnySchema =
  7799. /*#__PURE__*/
  7800. function (_schema_1$Schema) {
  7801. _inherits(AnySchema, _schema_1$Schema);
  7802. function AnySchema() {
  7803. _classCallCheck(this, AnySchema);
  7804. return _possibleConstructorReturn(this, _getPrototypeOf(AnySchema).apply(this, arguments));
  7805. }
  7806. _createClass(AnySchema, [{
  7807. key: "expected",
  7808. value: function expected() {
  7809. return 'anything';
  7810. }
  7811. }, {
  7812. key: "validate",
  7813. value: function validate() {
  7814. return true;
  7815. }
  7816. }]);
  7817. return AnySchema;
  7818. }(schema.Schema);
  7819. exports.AnySchema = AnySchema;
  7820. });
  7821. unwrapExports(any);
  7822. var any_1 = any.AnySchema;
  7823. var array = createCommonjsModule(function (module, exports) {
  7824. Object.defineProperty(exports, "__esModule", {
  7825. value: true
  7826. });
  7827. var ArraySchema =
  7828. /*#__PURE__*/
  7829. function (_schema_1$Schema) {
  7830. _inherits(ArraySchema, _schema_1$Schema);
  7831. function ArraySchema(_a) {
  7832. var _this;
  7833. _classCallCheck(this, ArraySchema);
  7834. var valueSchema = _a.valueSchema,
  7835. _a$name = _a.name,
  7836. name = _a$name === void 0 ? valueSchema.name : _a$name,
  7837. handlers = tslib_1.__rest(_a, ["valueSchema", "name"]);
  7838. _this = _possibleConstructorReturn(this, _getPrototypeOf(ArraySchema).call(this, Object.assign({}, handlers, {
  7839. name: name
  7840. })));
  7841. _this._valueSchema = valueSchema;
  7842. return _this;
  7843. }
  7844. _createClass(ArraySchema, [{
  7845. key: "expected",
  7846. value: function expected(utils) {
  7847. return "an array of ".concat(this._valueSchema.expected(utils));
  7848. }
  7849. }, {
  7850. key: "validate",
  7851. value: function validate(value, utils) {
  7852. if (!Array.isArray(value)) {
  7853. return false;
  7854. }
  7855. var invalidValues = [];
  7856. var _iteratorNormalCompletion = true;
  7857. var _didIteratorError = false;
  7858. var _iteratorError = undefined;
  7859. try {
  7860. for (var _iterator = value[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7861. var subValue = _step.value;
  7862. var subValidateResult = utils.normalizeValidateResult(this._valueSchema.validate(subValue, utils), subValue);
  7863. if (subValidateResult !== true) {
  7864. invalidValues.push(subValidateResult.value);
  7865. }
  7866. }
  7867. } catch (err) {
  7868. _didIteratorError = true;
  7869. _iteratorError = err;
  7870. } finally {
  7871. try {
  7872. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7873. _iterator.return();
  7874. }
  7875. } finally {
  7876. if (_didIteratorError) {
  7877. throw _iteratorError;
  7878. }
  7879. }
  7880. }
  7881. return invalidValues.length === 0 ? true : {
  7882. value: invalidValues
  7883. };
  7884. }
  7885. }, {
  7886. key: "deprecated",
  7887. value: function deprecated(value, utils) {
  7888. var deprecatedResult = [];
  7889. var _iteratorNormalCompletion2 = true;
  7890. var _didIteratorError2 = false;
  7891. var _iteratorError2 = undefined;
  7892. try {
  7893. for (var _iterator2 = value[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  7894. var subValue = _step2.value;
  7895. var subDeprecatedResult = utils.normalizeDeprecatedResult(this._valueSchema.deprecated(subValue, utils), subValue);
  7896. if (subDeprecatedResult !== false) {
  7897. deprecatedResult.push.apply(deprecatedResult, _toConsumableArray(subDeprecatedResult.map(function (_ref) {
  7898. var deprecatedValue = _ref.value;
  7899. return {
  7900. value: [deprecatedValue]
  7901. };
  7902. })));
  7903. }
  7904. }
  7905. } catch (err) {
  7906. _didIteratorError2 = true;
  7907. _iteratorError2 = err;
  7908. } finally {
  7909. try {
  7910. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  7911. _iterator2.return();
  7912. }
  7913. } finally {
  7914. if (_didIteratorError2) {
  7915. throw _iteratorError2;
  7916. }
  7917. }
  7918. }
  7919. return deprecatedResult;
  7920. }
  7921. }, {
  7922. key: "forward",
  7923. value: function forward(value, utils) {
  7924. var forwardResult = [];
  7925. var _iteratorNormalCompletion3 = true;
  7926. var _didIteratorError3 = false;
  7927. var _iteratorError3 = undefined;
  7928. try {
  7929. for (var _iterator3 = value[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  7930. var subValue = _step3.value;
  7931. var subForwardResult = utils.normalizeForwardResult(this._valueSchema.forward(subValue, utils), subValue);
  7932. forwardResult.push.apply(forwardResult, _toConsumableArray(subForwardResult.map(wrapTransferResult)));
  7933. }
  7934. } catch (err) {
  7935. _didIteratorError3 = true;
  7936. _iteratorError3 = err;
  7937. } finally {
  7938. try {
  7939. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  7940. _iterator3.return();
  7941. }
  7942. } finally {
  7943. if (_didIteratorError3) {
  7944. throw _iteratorError3;
  7945. }
  7946. }
  7947. }
  7948. return forwardResult;
  7949. }
  7950. }, {
  7951. key: "redirect",
  7952. value: function redirect(value, utils) {
  7953. var remain = [];
  7954. var redirect = [];
  7955. var _iteratorNormalCompletion4 = true;
  7956. var _didIteratorError4 = false;
  7957. var _iteratorError4 = undefined;
  7958. try {
  7959. for (var _iterator4 = value[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  7960. var subValue = _step4.value;
  7961. var subRedirectResult = utils.normalizeRedirectResult(this._valueSchema.redirect(subValue, utils), subValue);
  7962. if ('remain' in subRedirectResult) {
  7963. remain.push(subRedirectResult.remain);
  7964. }
  7965. redirect.push.apply(redirect, _toConsumableArray(subRedirectResult.redirect.map(wrapTransferResult)));
  7966. }
  7967. } catch (err) {
  7968. _didIteratorError4 = true;
  7969. _iteratorError4 = err;
  7970. } finally {
  7971. try {
  7972. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  7973. _iterator4.return();
  7974. }
  7975. } finally {
  7976. if (_didIteratorError4) {
  7977. throw _iteratorError4;
  7978. }
  7979. }
  7980. }
  7981. return remain.length === 0 ? {
  7982. redirect: redirect
  7983. } : {
  7984. redirect: redirect,
  7985. remain: remain
  7986. };
  7987. }
  7988. }, {
  7989. key: "overlap",
  7990. value: function overlap(currentValue, newValue) {
  7991. return currentValue.concat(newValue);
  7992. }
  7993. }]);
  7994. return ArraySchema;
  7995. }(schema.Schema);
  7996. exports.ArraySchema = ArraySchema;
  7997. function wrapTransferResult(_ref2) {
  7998. var from = _ref2.from,
  7999. to = _ref2.to;
  8000. return {
  8001. from: [from],
  8002. to: to
  8003. };
  8004. }
  8005. });
  8006. unwrapExports(array);
  8007. var array_1 = array.ArraySchema;
  8008. var boolean_1 = createCommonjsModule(function (module, exports) {
  8009. Object.defineProperty(exports, "__esModule", {
  8010. value: true
  8011. });
  8012. var BooleanSchema =
  8013. /*#__PURE__*/
  8014. function (_schema_1$Schema) {
  8015. _inherits(BooleanSchema, _schema_1$Schema);
  8016. function BooleanSchema() {
  8017. _classCallCheck(this, BooleanSchema);
  8018. return _possibleConstructorReturn(this, _getPrototypeOf(BooleanSchema).apply(this, arguments));
  8019. }
  8020. _createClass(BooleanSchema, [{
  8021. key: "expected",
  8022. value: function expected() {
  8023. return 'true or false';
  8024. }
  8025. }, {
  8026. key: "validate",
  8027. value: function validate(value) {
  8028. return typeof value === 'boolean';
  8029. }
  8030. }]);
  8031. return BooleanSchema;
  8032. }(schema.Schema);
  8033. exports.BooleanSchema = BooleanSchema;
  8034. });
  8035. unwrapExports(boolean_1);
  8036. var boolean_2 = boolean_1.BooleanSchema;
  8037. var utils = createCommonjsModule(function (module, exports) {
  8038. Object.defineProperty(exports, "__esModule", {
  8039. value: true
  8040. });
  8041. function recordFromArray(array, mainKey) {
  8042. var record = Object.create(null);
  8043. var _iteratorNormalCompletion = true;
  8044. var _didIteratorError = false;
  8045. var _iteratorError = undefined;
  8046. try {
  8047. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8048. var value = _step.value;
  8049. var key = value[mainKey]; // istanbul ignore next
  8050. if (record[key]) {
  8051. throw new Error("Duplicate ".concat(mainKey, " ").concat(JSON.stringify(key)));
  8052. } // @ts-ignore
  8053. record[key] = value;
  8054. }
  8055. } catch (err) {
  8056. _didIteratorError = true;
  8057. _iteratorError = err;
  8058. } finally {
  8059. try {
  8060. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8061. _iterator.return();
  8062. }
  8063. } finally {
  8064. if (_didIteratorError) {
  8065. throw _iteratorError;
  8066. }
  8067. }
  8068. }
  8069. return record;
  8070. }
  8071. exports.recordFromArray = recordFromArray;
  8072. function mapFromArray(array, mainKey) {
  8073. var map = new Map();
  8074. var _iteratorNormalCompletion2 = true;
  8075. var _didIteratorError2 = false;
  8076. var _iteratorError2 = undefined;
  8077. try {
  8078. for (var _iterator2 = array[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8079. var value = _step2.value;
  8080. var key = value[mainKey]; // istanbul ignore next
  8081. if (map.has(key)) {
  8082. throw new Error("Duplicate ".concat(mainKey, " ").concat(JSON.stringify(key)));
  8083. }
  8084. map.set(key, value);
  8085. }
  8086. } catch (err) {
  8087. _didIteratorError2 = true;
  8088. _iteratorError2 = err;
  8089. } finally {
  8090. try {
  8091. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8092. _iterator2.return();
  8093. }
  8094. } finally {
  8095. if (_didIteratorError2) {
  8096. throw _iteratorError2;
  8097. }
  8098. }
  8099. }
  8100. return map;
  8101. }
  8102. exports.mapFromArray = mapFromArray;
  8103. function createAutoChecklist() {
  8104. var map = Object.create(null);
  8105. return function (id) {
  8106. var idString = JSON.stringify(id);
  8107. if (map[idString]) {
  8108. return true;
  8109. }
  8110. map[idString] = true;
  8111. return false;
  8112. };
  8113. }
  8114. exports.createAutoChecklist = createAutoChecklist;
  8115. function partition(array, predicate) {
  8116. var trueArray = [];
  8117. var falseArray = [];
  8118. var _iteratorNormalCompletion3 = true;
  8119. var _didIteratorError3 = false;
  8120. var _iteratorError3 = undefined;
  8121. try {
  8122. for (var _iterator3 = array[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  8123. var value = _step3.value;
  8124. if (predicate(value)) {
  8125. trueArray.push(value);
  8126. } else {
  8127. falseArray.push(value);
  8128. }
  8129. }
  8130. } catch (err) {
  8131. _didIteratorError3 = true;
  8132. _iteratorError3 = err;
  8133. } finally {
  8134. try {
  8135. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  8136. _iterator3.return();
  8137. }
  8138. } finally {
  8139. if (_didIteratorError3) {
  8140. throw _iteratorError3;
  8141. }
  8142. }
  8143. }
  8144. return [trueArray, falseArray];
  8145. }
  8146. exports.partition = partition;
  8147. function isInt(value) {
  8148. return value === Math.floor(value);
  8149. }
  8150. exports.isInt = isInt;
  8151. function comparePrimitive(a, b) {
  8152. if (a === b) {
  8153. return 0;
  8154. }
  8155. var typeofA = _typeof(a);
  8156. var typeofB = _typeof(b);
  8157. var orders = ['undefined', 'object', 'boolean', 'number', 'string'];
  8158. if (typeofA !== typeofB) {
  8159. return orders.indexOf(typeofA) - orders.indexOf(typeofB);
  8160. }
  8161. if (typeofA !== 'string') {
  8162. return Number(a) - Number(b);
  8163. }
  8164. return a.localeCompare(b);
  8165. }
  8166. exports.comparePrimitive = comparePrimitive;
  8167. function normalizeDefaultResult(result) {
  8168. return result === undefined ? {} : result;
  8169. }
  8170. exports.normalizeDefaultResult = normalizeDefaultResult;
  8171. function normalizeValidateResult(result, value) {
  8172. return result === true ? true : result === false ? {
  8173. value: value
  8174. } : result;
  8175. }
  8176. exports.normalizeValidateResult = normalizeValidateResult;
  8177. function normalizeDeprecatedResult(result, value) {
  8178. var doNotNormalizeTrue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  8179. return result === false ? false : result === true ? doNotNormalizeTrue ? true : [{
  8180. value: value
  8181. }] : 'value' in result ? [result] : result.length === 0 ? false : result;
  8182. }
  8183. exports.normalizeDeprecatedResult = normalizeDeprecatedResult;
  8184. function normalizeTransferResult(result, value) {
  8185. return typeof result === 'string' || 'key' in result ? {
  8186. from: value,
  8187. to: result
  8188. } : 'from' in result ? {
  8189. from: result.from,
  8190. to: result.to
  8191. } : {
  8192. from: value,
  8193. to: result.to
  8194. };
  8195. }
  8196. exports.normalizeTransferResult = normalizeTransferResult;
  8197. function normalizeForwardResult(result, value) {
  8198. return result === undefined ? [] : Array.isArray(result) ? result.map(function (transferResult) {
  8199. return normalizeTransferResult(transferResult, value);
  8200. }) : [normalizeTransferResult(result, value)];
  8201. }
  8202. exports.normalizeForwardResult = normalizeForwardResult;
  8203. function normalizeRedirectResult(result, value) {
  8204. var redirect = normalizeForwardResult(_typeof(result) === 'object' && 'redirect' in result ? result.redirect : result, value);
  8205. return redirect.length === 0 ? {
  8206. remain: value,
  8207. redirect: redirect
  8208. } : _typeof(result) === 'object' && 'remain' in result ? {
  8209. remain: result.remain,
  8210. redirect: redirect
  8211. } : {
  8212. redirect: redirect
  8213. };
  8214. }
  8215. exports.normalizeRedirectResult = normalizeRedirectResult;
  8216. });
  8217. unwrapExports(utils);
  8218. var utils_1 = utils.recordFromArray;
  8219. var utils_2 = utils.mapFromArray;
  8220. var utils_3 = utils.createAutoChecklist;
  8221. var utils_4 = utils.partition;
  8222. var utils_5 = utils.isInt;
  8223. var utils_6 = utils.comparePrimitive;
  8224. var utils_7 = utils.normalizeDefaultResult;
  8225. var utils_8 = utils.normalizeValidateResult;
  8226. var utils_9 = utils.normalizeDeprecatedResult;
  8227. var utils_10 = utils.normalizeTransferResult;
  8228. var utils_11 = utils.normalizeForwardResult;
  8229. var utils_12 = utils.normalizeRedirectResult;
  8230. var choice = createCommonjsModule(function (module, exports) {
  8231. Object.defineProperty(exports, "__esModule", {
  8232. value: true
  8233. });
  8234. var ChoiceSchema =
  8235. /*#__PURE__*/
  8236. function (_schema_1$Schema) {
  8237. _inherits(ChoiceSchema, _schema_1$Schema);
  8238. function ChoiceSchema(parameters) {
  8239. var _this;
  8240. _classCallCheck(this, ChoiceSchema);
  8241. _this = _possibleConstructorReturn(this, _getPrototypeOf(ChoiceSchema).call(this, parameters));
  8242. _this._choices = utils.mapFromArray(parameters.choices.map(function (choice) {
  8243. return choice && _typeof(choice) === 'object' ? choice : {
  8244. value: choice
  8245. };
  8246. }), 'value');
  8247. return _this;
  8248. }
  8249. _createClass(ChoiceSchema, [{
  8250. key: "expected",
  8251. value: function expected(_ref) {
  8252. var _this2 = this;
  8253. var descriptor = _ref.descriptor;
  8254. var choiceValues = Array.from(this._choices.keys()).map(function (value) {
  8255. return _this2._choices.get(value);
  8256. }).filter(function (choiceInfo) {
  8257. return !choiceInfo.deprecated;
  8258. }).map(function (choiceInfo) {
  8259. return choiceInfo.value;
  8260. }).sort(utils.comparePrimitive).map(descriptor.value);
  8261. var head = choiceValues.slice(0, -2);
  8262. var tail = choiceValues.slice(-2);
  8263. return head.concat(tail.join(' or ')).join(', ');
  8264. }
  8265. }, {
  8266. key: "validate",
  8267. value: function validate(value) {
  8268. return this._choices.has(value);
  8269. }
  8270. }, {
  8271. key: "deprecated",
  8272. value: function deprecated(value) {
  8273. var choiceInfo = this._choices.get(value);
  8274. return choiceInfo && choiceInfo.deprecated ? {
  8275. value: value
  8276. } : false;
  8277. }
  8278. }, {
  8279. key: "forward",
  8280. value: function forward(value) {
  8281. var choiceInfo = this._choices.get(value);
  8282. return choiceInfo ? choiceInfo.forward : undefined;
  8283. }
  8284. }, {
  8285. key: "redirect",
  8286. value: function redirect(value) {
  8287. var choiceInfo = this._choices.get(value);
  8288. return choiceInfo ? choiceInfo.redirect : undefined;
  8289. }
  8290. }]);
  8291. return ChoiceSchema;
  8292. }(schema.Schema);
  8293. exports.ChoiceSchema = ChoiceSchema;
  8294. });
  8295. unwrapExports(choice);
  8296. var choice_1 = choice.ChoiceSchema;
  8297. var number = createCommonjsModule(function (module, exports) {
  8298. Object.defineProperty(exports, "__esModule", {
  8299. value: true
  8300. });
  8301. var NumberSchema =
  8302. /*#__PURE__*/
  8303. function (_schema_1$Schema) {
  8304. _inherits(NumberSchema, _schema_1$Schema);
  8305. function NumberSchema() {
  8306. _classCallCheck(this, NumberSchema);
  8307. return _possibleConstructorReturn(this, _getPrototypeOf(NumberSchema).apply(this, arguments));
  8308. }
  8309. _createClass(NumberSchema, [{
  8310. key: "expected",
  8311. value: function expected() {
  8312. return 'a number';
  8313. }
  8314. }, {
  8315. key: "validate",
  8316. value: function validate(value, _utils) {
  8317. return typeof value === 'number';
  8318. }
  8319. }]);
  8320. return NumberSchema;
  8321. }(schema.Schema);
  8322. exports.NumberSchema = NumberSchema;
  8323. });
  8324. unwrapExports(number);
  8325. var number_1 = number.NumberSchema;
  8326. var integer = createCommonjsModule(function (module, exports) {
  8327. Object.defineProperty(exports, "__esModule", {
  8328. value: true
  8329. });
  8330. var IntegerSchema =
  8331. /*#__PURE__*/
  8332. function (_number_1$NumberSchem) {
  8333. _inherits(IntegerSchema, _number_1$NumberSchem);
  8334. function IntegerSchema() {
  8335. _classCallCheck(this, IntegerSchema);
  8336. return _possibleConstructorReturn(this, _getPrototypeOf(IntegerSchema).apply(this, arguments));
  8337. }
  8338. _createClass(IntegerSchema, [{
  8339. key: "expected",
  8340. value: function expected() {
  8341. return 'an integer';
  8342. }
  8343. }, {
  8344. key: "validate",
  8345. value: function validate(value, utils$1) {
  8346. return utils$1.normalizeValidateResult(_get(_getPrototypeOf(IntegerSchema.prototype), "validate", this).call(this, value, utils$1), value) === true && utils.isInt(value);
  8347. }
  8348. }]);
  8349. return IntegerSchema;
  8350. }(number.NumberSchema);
  8351. exports.IntegerSchema = IntegerSchema;
  8352. });
  8353. unwrapExports(integer);
  8354. var integer_1 = integer.IntegerSchema;
  8355. var string = createCommonjsModule(function (module, exports) {
  8356. Object.defineProperty(exports, "__esModule", {
  8357. value: true
  8358. });
  8359. var StringSchema =
  8360. /*#__PURE__*/
  8361. function (_schema_1$Schema) {
  8362. _inherits(StringSchema, _schema_1$Schema);
  8363. function StringSchema() {
  8364. _classCallCheck(this, StringSchema);
  8365. return _possibleConstructorReturn(this, _getPrototypeOf(StringSchema).apply(this, arguments));
  8366. }
  8367. _createClass(StringSchema, [{
  8368. key: "expected",
  8369. value: function expected() {
  8370. return 'a string';
  8371. }
  8372. }, {
  8373. key: "validate",
  8374. value: function validate(value) {
  8375. return typeof value === 'string';
  8376. }
  8377. }]);
  8378. return StringSchema;
  8379. }(schema.Schema);
  8380. exports.StringSchema = StringSchema;
  8381. });
  8382. unwrapExports(string);
  8383. var string_1 = string.StringSchema;
  8384. var schemas = createCommonjsModule(function (module, exports) {
  8385. Object.defineProperty(exports, "__esModule", {
  8386. value: true
  8387. });
  8388. tslib_1.__exportStar(alias, exports);
  8389. tslib_1.__exportStar(any, exports);
  8390. tslib_1.__exportStar(array, exports);
  8391. tslib_1.__exportStar(boolean_1, exports);
  8392. tslib_1.__exportStar(choice, exports);
  8393. tslib_1.__exportStar(integer, exports);
  8394. tslib_1.__exportStar(number, exports);
  8395. tslib_1.__exportStar(string, exports);
  8396. });
  8397. unwrapExports(schemas);
  8398. var defaults = createCommonjsModule(function (module, exports) {
  8399. Object.defineProperty(exports, "__esModule", {
  8400. value: true
  8401. });
  8402. exports.defaultDescriptor = api.apiDescriptor;
  8403. exports.defaultUnknownHandler = leven_1.levenUnknownHandler;
  8404. exports.defaultInvalidHandler = invalid.commonInvalidHandler;
  8405. exports.defaultDeprecatedHandler = common.commonDeprecatedHandler;
  8406. });
  8407. unwrapExports(defaults);
  8408. var defaults_1 = defaults.defaultDescriptor;
  8409. var defaults_2 = defaults.defaultUnknownHandler;
  8410. var defaults_3 = defaults.defaultInvalidHandler;
  8411. var defaults_4 = defaults.defaultDeprecatedHandler;
  8412. var normalize = createCommonjsModule(function (module, exports) {
  8413. Object.defineProperty(exports, "__esModule", {
  8414. value: true
  8415. });
  8416. exports.normalize = function (options, schemas, opts) {
  8417. return new Normalizer(schemas, opts).normalize(options);
  8418. };
  8419. var Normalizer =
  8420. /*#__PURE__*/
  8421. function () {
  8422. function Normalizer(schemas, opts) {
  8423. _classCallCheck(this, Normalizer);
  8424. // istanbul ignore next
  8425. var _ref = opts || {},
  8426. _ref$logger = _ref.logger,
  8427. logger = _ref$logger === void 0 ? console : _ref$logger,
  8428. _ref$descriptor = _ref.descriptor,
  8429. descriptor = _ref$descriptor === void 0 ? defaults.defaultDescriptor : _ref$descriptor,
  8430. _ref$unknown = _ref.unknown,
  8431. unknown = _ref$unknown === void 0 ? defaults.defaultUnknownHandler : _ref$unknown,
  8432. _ref$invalid = _ref.invalid,
  8433. invalid = _ref$invalid === void 0 ? defaults.defaultInvalidHandler : _ref$invalid,
  8434. _ref$deprecated = _ref.deprecated,
  8435. deprecated = _ref$deprecated === void 0 ? defaults.defaultDeprecatedHandler : _ref$deprecated;
  8436. this._utils = {
  8437. descriptor: descriptor,
  8438. logger:
  8439. /* istanbul ignore next */
  8440. logger || {
  8441. warn: function warn() {}
  8442. },
  8443. schemas: utils.recordFromArray(schemas, 'name'),
  8444. normalizeDefaultResult: utils.normalizeDefaultResult,
  8445. normalizeDeprecatedResult: utils.normalizeDeprecatedResult,
  8446. normalizeForwardResult: utils.normalizeForwardResult,
  8447. normalizeRedirectResult: utils.normalizeRedirectResult,
  8448. normalizeValidateResult: utils.normalizeValidateResult
  8449. };
  8450. this._unknownHandler = unknown;
  8451. this._invalidHandler = invalid;
  8452. this._deprecatedHandler = deprecated;
  8453. this.cleanHistory();
  8454. }
  8455. _createClass(Normalizer, [{
  8456. key: "cleanHistory",
  8457. value: function cleanHistory() {
  8458. this._hasDeprecationWarned = utils.createAutoChecklist();
  8459. }
  8460. }, {
  8461. key: "normalize",
  8462. value: function normalize(options) {
  8463. var _this = this;
  8464. var normalized = {};
  8465. var restOptionsArray = [options];
  8466. var applyNormalization = function applyNormalization() {
  8467. while (restOptionsArray.length !== 0) {
  8468. var currentOptions = restOptionsArray.shift();
  8469. var transferredOptionsArray = _this._applyNormalization(currentOptions, normalized);
  8470. restOptionsArray.push.apply(restOptionsArray, _toConsumableArray(transferredOptionsArray));
  8471. }
  8472. };
  8473. applyNormalization();
  8474. for (var _i = 0, _Object$keys = Object.keys(this._utils.schemas); _i < _Object$keys.length; _i++) {
  8475. var key = _Object$keys[_i];
  8476. var schema = this._utils.schemas[key];
  8477. if (!(key in normalized)) {
  8478. var defaultResult = utils.normalizeDefaultResult(schema.default(this._utils));
  8479. if ('value' in defaultResult) {
  8480. restOptionsArray.push(_defineProperty({}, key, defaultResult.value));
  8481. }
  8482. }
  8483. }
  8484. applyNormalization();
  8485. for (var _i2 = 0, _Object$keys2 = Object.keys(this._utils.schemas); _i2 < _Object$keys2.length; _i2++) {
  8486. var _key = _Object$keys2[_i2];
  8487. var _schema = this._utils.schemas[_key];
  8488. if (_key in normalized) {
  8489. normalized[_key] = _schema.postprocess(normalized[_key], this._utils);
  8490. }
  8491. }
  8492. return normalized;
  8493. }
  8494. }, {
  8495. key: "_applyNormalization",
  8496. value: function _applyNormalization(options, normalized) {
  8497. var _this2 = this;
  8498. var transferredOptionsArray = [];
  8499. var _utils_1$partition = utils.partition(Object.keys(options), function (key) {
  8500. return key in _this2._utils.schemas;
  8501. }),
  8502. _utils_1$partition2 = _slicedToArray(_utils_1$partition, 2),
  8503. knownOptionNames = _utils_1$partition2[0],
  8504. unknownOptionNames = _utils_1$partition2[1];
  8505. var _iteratorNormalCompletion = true;
  8506. var _didIteratorError = false;
  8507. var _iteratorError = undefined;
  8508. try {
  8509. var _loop = function _loop() {
  8510. var key = _step.value;
  8511. var schema = _this2._utils.schemas[key];
  8512. var value = schema.preprocess(options[key], _this2._utils);
  8513. var validateResult = utils.normalizeValidateResult(schema.validate(value, _this2._utils), value);
  8514. if (validateResult !== true) {
  8515. var invalidValue = validateResult.value;
  8516. var errorMessageOrError = _this2._invalidHandler(key, invalidValue, _this2._utils);
  8517. throw typeof errorMessageOrError === 'string' ? new Error(errorMessageOrError) :
  8518. /* istanbul ignore next*/
  8519. errorMessageOrError;
  8520. }
  8521. var appendTransferredOptions = function appendTransferredOptions(_ref2) {
  8522. var from = _ref2.from,
  8523. to = _ref2.to;
  8524. transferredOptionsArray.push(typeof to === 'string' ? _defineProperty({}, to, from) : _defineProperty({}, to.key, to.value));
  8525. };
  8526. var warnDeprecated = function warnDeprecated(_ref5) {
  8527. var currentValue = _ref5.value,
  8528. redirectTo = _ref5.redirectTo;
  8529. var deprecatedResult = utils.normalizeDeprecatedResult(schema.deprecated(currentValue, _this2._utils), value,
  8530. /* doNotNormalizeTrue */
  8531. true);
  8532. if (deprecatedResult === false) {
  8533. return;
  8534. }
  8535. if (deprecatedResult === true) {
  8536. if (!_this2._hasDeprecationWarned(key)) {
  8537. _this2._utils.logger.warn(_this2._deprecatedHandler(key, redirectTo, _this2._utils));
  8538. }
  8539. } else {
  8540. var _iteratorNormalCompletion3 = true;
  8541. var _didIteratorError3 = false;
  8542. var _iteratorError3 = undefined;
  8543. try {
  8544. for (var _iterator3 = deprecatedResult[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  8545. var deprecatedValue = _step3.value.value;
  8546. var pair = {
  8547. key: key,
  8548. value: deprecatedValue
  8549. };
  8550. if (!_this2._hasDeprecationWarned(pair)) {
  8551. var redirectToPair = typeof redirectTo === 'string' ? {
  8552. key: redirectTo,
  8553. value: deprecatedValue
  8554. } : redirectTo;
  8555. _this2._utils.logger.warn(_this2._deprecatedHandler(pair, redirectToPair, _this2._utils));
  8556. }
  8557. }
  8558. } catch (err) {
  8559. _didIteratorError3 = true;
  8560. _iteratorError3 = err;
  8561. } finally {
  8562. try {
  8563. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  8564. _iterator3.return();
  8565. }
  8566. } finally {
  8567. if (_didIteratorError3) {
  8568. throw _iteratorError3;
  8569. }
  8570. }
  8571. }
  8572. }
  8573. };
  8574. var forwardResult = utils.normalizeForwardResult(schema.forward(value, _this2._utils), value);
  8575. forwardResult.forEach(appendTransferredOptions);
  8576. var redirectResult = utils.normalizeRedirectResult(schema.redirect(value, _this2._utils), value);
  8577. redirectResult.redirect.forEach(appendTransferredOptions);
  8578. if ('remain' in redirectResult) {
  8579. var remainingValue = redirectResult.remain;
  8580. normalized[key] = key in normalized ? schema.overlap(normalized[key], remainingValue, _this2._utils) : remainingValue;
  8581. warnDeprecated({
  8582. value: remainingValue
  8583. });
  8584. }
  8585. var _iteratorNormalCompletion4 = true;
  8586. var _didIteratorError4 = false;
  8587. var _iteratorError4 = undefined;
  8588. try {
  8589. for (var _iterator4 = redirectResult.redirect[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  8590. var _step4$value = _step4.value,
  8591. from = _step4$value.from,
  8592. to = _step4$value.to;
  8593. warnDeprecated({
  8594. value: from,
  8595. redirectTo: to
  8596. });
  8597. }
  8598. } catch (err) {
  8599. _didIteratorError4 = true;
  8600. _iteratorError4 = err;
  8601. } finally {
  8602. try {
  8603. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  8604. _iterator4.return();
  8605. }
  8606. } finally {
  8607. if (_didIteratorError4) {
  8608. throw _iteratorError4;
  8609. }
  8610. }
  8611. }
  8612. };
  8613. for (var _iterator = knownOptionNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8614. _loop();
  8615. }
  8616. } catch (err) {
  8617. _didIteratorError = true;
  8618. _iteratorError = err;
  8619. } finally {
  8620. try {
  8621. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8622. _iterator.return();
  8623. }
  8624. } finally {
  8625. if (_didIteratorError) {
  8626. throw _iteratorError;
  8627. }
  8628. }
  8629. }
  8630. var _iteratorNormalCompletion2 = true;
  8631. var _didIteratorError2 = false;
  8632. var _iteratorError2 = undefined;
  8633. try {
  8634. for (var _iterator2 = unknownOptionNames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8635. var key = _step2.value;
  8636. var value = options[key];
  8637. var unknownResult = this._unknownHandler(key, value, this._utils);
  8638. if (unknownResult) {
  8639. for (var _i3 = 0, _Object$keys3 = Object.keys(unknownResult); _i3 < _Object$keys3.length; _i3++) {
  8640. var unknownKey = _Object$keys3[_i3];
  8641. var unknownOption = _defineProperty({}, unknownKey, unknownResult[unknownKey]);
  8642. if (unknownKey in this._utils.schemas) {
  8643. transferredOptionsArray.push(unknownOption);
  8644. } else {
  8645. Object.assign(normalized, unknownOption);
  8646. }
  8647. }
  8648. }
  8649. }
  8650. } catch (err) {
  8651. _didIteratorError2 = true;
  8652. _iteratorError2 = err;
  8653. } finally {
  8654. try {
  8655. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8656. _iterator2.return();
  8657. }
  8658. } finally {
  8659. if (_didIteratorError2) {
  8660. throw _iteratorError2;
  8661. }
  8662. }
  8663. }
  8664. return transferredOptionsArray;
  8665. }
  8666. }]);
  8667. return Normalizer;
  8668. }();
  8669. exports.Normalizer = Normalizer;
  8670. });
  8671. unwrapExports(normalize);
  8672. var normalize_1 = normalize.normalize;
  8673. var normalize_2 = normalize.Normalizer;
  8674. var lib = createCommonjsModule(function (module, exports) {
  8675. Object.defineProperty(exports, "__esModule", {
  8676. value: true
  8677. });
  8678. tslib_1.__exportStar(descriptors, exports);
  8679. tslib_1.__exportStar(handlers, exports);
  8680. tslib_1.__exportStar(schemas, exports);
  8681. tslib_1.__exportStar(normalize, exports);
  8682. tslib_1.__exportStar(schema, exports);
  8683. });
  8684. unwrapExports(lib);
  8685. var array$1 = [];
  8686. var charCodeCache$1 = [];
  8687. var leven$1 = function leven(left, right) {
  8688. if (left === right) {
  8689. return 0;
  8690. }
  8691. var swap = left; // Swapping the strings if `a` is longer than `b` so we know which one is the
  8692. // shortest & which one is the longest
  8693. if (left.length > right.length) {
  8694. left = right;
  8695. right = swap;
  8696. }
  8697. var leftLength = left.length;
  8698. var rightLength = right.length; // Performing suffix trimming:
  8699. // We can linearly drop suffix common to both strings since they
  8700. // don't increase distance at all
  8701. // Note: `~-` is the bitwise way to perform a `- 1` operation
  8702. while (leftLength > 0 && left.charCodeAt(~-leftLength) === right.charCodeAt(~-rightLength)) {
  8703. leftLength--;
  8704. rightLength--;
  8705. } // Performing prefix trimming
  8706. // We can linearly drop prefix common to both strings since they
  8707. // don't increase distance at all
  8708. var start = 0;
  8709. while (start < leftLength && left.charCodeAt(start) === right.charCodeAt(start)) {
  8710. start++;
  8711. }
  8712. leftLength -= start;
  8713. rightLength -= start;
  8714. if (leftLength === 0) {
  8715. return rightLength;
  8716. }
  8717. var bCharCode;
  8718. var result;
  8719. var temp;
  8720. var temp2;
  8721. var i = 0;
  8722. var j = 0;
  8723. while (i < leftLength) {
  8724. charCodeCache$1[i] = left.charCodeAt(start + i);
  8725. array$1[i] = ++i;
  8726. }
  8727. while (j < rightLength) {
  8728. bCharCode = right.charCodeAt(start + j);
  8729. temp = j++;
  8730. result = j;
  8731. for (i = 0; i < leftLength; i++) {
  8732. temp2 = bCharCode === charCodeCache$1[i] ? temp : temp + 1;
  8733. temp = array$1[i]; // eslint-disable-next-line no-multi-assign
  8734. result = array$1[i] = temp > result ? temp2 > result ? result + 1 : temp2 : temp2 > temp ? temp + 1 : temp2;
  8735. }
  8736. }
  8737. return result;
  8738. };
  8739. var leven_1$1 = leven$1; // TODO: Remove this for the next major release
  8740. var default_1 = leven$1;
  8741. leven_1$1.default = default_1;
  8742. var cliDescriptor = {
  8743. key: function key(_key) {
  8744. return _key.length === 1 ? "-".concat(_key) : "--".concat(_key);
  8745. },
  8746. value: function value(_value) {
  8747. return lib.apiDescriptor.value(_value);
  8748. },
  8749. pair: function pair(_ref) {
  8750. var key = _ref.key,
  8751. value = _ref.value;
  8752. return value === false ? "--no-".concat(key) : value === true ? cliDescriptor.key(key) : value === "" ? "".concat(cliDescriptor.key(key), " without an argument") : "".concat(cliDescriptor.key(key), "=").concat(value);
  8753. }
  8754. };
  8755. var FlagSchema =
  8756. /*#__PURE__*/
  8757. function (_vnopts$ChoiceSchema) {
  8758. _inherits(FlagSchema, _vnopts$ChoiceSchema);
  8759. function FlagSchema(_ref2) {
  8760. var _this;
  8761. var name = _ref2.name,
  8762. flags = _ref2.flags;
  8763. _classCallCheck(this, FlagSchema);
  8764. _this = _possibleConstructorReturn(this, _getPrototypeOf(FlagSchema).call(this, {
  8765. name: name,
  8766. choices: flags
  8767. }));
  8768. _this._flags = flags.slice().sort();
  8769. return _this;
  8770. }
  8771. _createClass(FlagSchema, [{
  8772. key: "preprocess",
  8773. value: function preprocess(value, utils) {
  8774. if (typeof value === "string" && value.length !== 0 && this._flags.indexOf(value) === -1) {
  8775. var suggestion = this._flags.find(function (flag) {
  8776. return leven_1$1(flag, value) < 3;
  8777. });
  8778. if (suggestion) {
  8779. utils.logger.warn(["Unknown flag ".concat(chalk.yellow(utils.descriptor.value(value)), ","), "did you mean ".concat(chalk.blue(utils.descriptor.value(suggestion)), "?")].join(" "));
  8780. return suggestion;
  8781. }
  8782. }
  8783. return value;
  8784. }
  8785. }, {
  8786. key: "expected",
  8787. value: function expected() {
  8788. return "a flag";
  8789. }
  8790. }]);
  8791. return FlagSchema;
  8792. }(lib.ChoiceSchema);
  8793. var hasDeprecationWarned;
  8794. function normalizeOptions(options, optionInfos) {
  8795. var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  8796. logger = _ref3.logger,
  8797. _ref3$isCLI = _ref3.isCLI,
  8798. isCLI = _ref3$isCLI === void 0 ? false : _ref3$isCLI,
  8799. _ref3$passThrough = _ref3.passThrough,
  8800. passThrough = _ref3$passThrough === void 0 ? false : _ref3$passThrough;
  8801. var unknown = !passThrough ? lib.levenUnknownHandler : Array.isArray(passThrough) ? function (key, value) {
  8802. return passThrough.indexOf(key) === -1 ? undefined : _defineProperty({}, key, value);
  8803. } : function (key, value) {
  8804. return _defineProperty({}, key, value);
  8805. };
  8806. var descriptor = isCLI ? cliDescriptor : lib.apiDescriptor;
  8807. var schemas = optionInfosToSchemas(optionInfos, {
  8808. isCLI: isCLI
  8809. });
  8810. var normalizer = new lib.Normalizer(schemas, {
  8811. logger: logger,
  8812. unknown: unknown,
  8813. descriptor: descriptor
  8814. });
  8815. var shouldSuppressDuplicateDeprecationWarnings = logger !== false;
  8816. if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) {
  8817. normalizer._hasDeprecationWarned = hasDeprecationWarned;
  8818. }
  8819. var normalized = normalizer.normalize(options);
  8820. if (shouldSuppressDuplicateDeprecationWarnings) {
  8821. hasDeprecationWarned = normalizer._hasDeprecationWarned;
  8822. }
  8823. return normalized;
  8824. }
  8825. function optionInfosToSchemas(optionInfos, _ref6) {
  8826. var isCLI = _ref6.isCLI;
  8827. var schemas = [];
  8828. if (isCLI) {
  8829. schemas.push(lib.AnySchema.create({
  8830. name: "_"
  8831. }));
  8832. }
  8833. var _iteratorNormalCompletion = true;
  8834. var _didIteratorError = false;
  8835. var _iteratorError = undefined;
  8836. try {
  8837. for (var _iterator = optionInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8838. var optionInfo = _step.value;
  8839. schemas.push(optionInfoToSchema(optionInfo, {
  8840. isCLI: isCLI,
  8841. optionInfos: optionInfos
  8842. }));
  8843. if (optionInfo.alias && isCLI) {
  8844. schemas.push(lib.AliasSchema.create({
  8845. name: optionInfo.alias,
  8846. sourceName: optionInfo.name
  8847. }));
  8848. }
  8849. }
  8850. } catch (err) {
  8851. _didIteratorError = true;
  8852. _iteratorError = err;
  8853. } finally {
  8854. try {
  8855. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8856. _iterator.return();
  8857. }
  8858. } finally {
  8859. if (_didIteratorError) {
  8860. throw _iteratorError;
  8861. }
  8862. }
  8863. }
  8864. return schemas;
  8865. }
  8866. function optionInfoToSchema(optionInfo, _ref7) {
  8867. var isCLI = _ref7.isCLI,
  8868. optionInfos = _ref7.optionInfos;
  8869. var SchemaConstructor;
  8870. var parameters = {
  8871. name: optionInfo.name
  8872. };
  8873. var handlers = {};
  8874. switch (optionInfo.type) {
  8875. case "int":
  8876. SchemaConstructor = lib.IntegerSchema;
  8877. if (isCLI) {
  8878. parameters.preprocess = function (value) {
  8879. return Number(value);
  8880. };
  8881. }
  8882. break;
  8883. case "string":
  8884. SchemaConstructor = lib.StringSchema;
  8885. break;
  8886. case "choice":
  8887. SchemaConstructor = lib.ChoiceSchema;
  8888. parameters.choices = optionInfo.choices.map(function (choiceInfo) {
  8889. return _typeof(choiceInfo) === "object" && choiceInfo.redirect ? Object.assign({}, choiceInfo, {
  8890. redirect: {
  8891. to: {
  8892. key: optionInfo.name,
  8893. value: choiceInfo.redirect
  8894. }
  8895. }
  8896. }) : choiceInfo;
  8897. });
  8898. break;
  8899. case "boolean":
  8900. SchemaConstructor = lib.BooleanSchema;
  8901. break;
  8902. case "flag":
  8903. SchemaConstructor = FlagSchema;
  8904. parameters.flags = optionInfos.map(function (optionInfo) {
  8905. return [].concat(optionInfo.alias || [], optionInfo.description ? optionInfo.name : [], optionInfo.oppositeDescription ? "no-".concat(optionInfo.name) : []);
  8906. }).reduce(function (a, b) {
  8907. return a.concat(b);
  8908. }, []);
  8909. break;
  8910. case "path":
  8911. SchemaConstructor = lib.StringSchema;
  8912. break;
  8913. default:
  8914. throw new Error("Unexpected type ".concat(optionInfo.type));
  8915. }
  8916. if (optionInfo.exception) {
  8917. parameters.validate = function (value, schema, utils) {
  8918. return optionInfo.exception(value) || schema.validate(value, utils);
  8919. };
  8920. } else {
  8921. parameters.validate = function (value, schema, utils) {
  8922. return value === undefined || schema.validate(value, utils);
  8923. };
  8924. }
  8925. if (optionInfo.redirect) {
  8926. handlers.redirect = function (value) {
  8927. return !value ? undefined : {
  8928. to: {
  8929. key: optionInfo.redirect.option,
  8930. value: optionInfo.redirect.value
  8931. }
  8932. };
  8933. };
  8934. }
  8935. if (optionInfo.deprecated) {
  8936. handlers.deprecated = true;
  8937. } // allow CLI overriding, e.g., prettier package.json --tab-width 1 --tab-width 2
  8938. if (isCLI && !optionInfo.array) {
  8939. var originalPreprocess = parameters.preprocess || function (x) {
  8940. return x;
  8941. };
  8942. parameters.preprocess = function (value, schema, utils) {
  8943. return schema.preprocess(originalPreprocess(Array.isArray(value) ? value[value.length - 1] : value), utils);
  8944. };
  8945. }
  8946. return optionInfo.array ? lib.ArraySchema.create(Object.assign(isCLI ? {
  8947. preprocess: function preprocess(v) {
  8948. return [].concat(v);
  8949. }
  8950. } : {}, handlers, {
  8951. valueSchema: SchemaConstructor.create(parameters)
  8952. })) : SchemaConstructor.create(Object.assign({}, parameters, handlers));
  8953. }
  8954. function normalizeApiOptions(options, optionInfos, opts) {
  8955. return normalizeOptions(options, optionInfos, opts);
  8956. }
  8957. function normalizeCliOptions(options, optionInfos, opts) {
  8958. return normalizeOptions(options, optionInfos, Object.assign({
  8959. isCLI: true
  8960. }, opts));
  8961. }
  8962. var optionsNormalizer = {
  8963. normalizeApiOptions: normalizeApiOptions,
  8964. normalizeCliOptions: normalizeCliOptions
  8965. };
  8966. var getLast = function getLast(arr) {
  8967. return arr.length > 0 ? arr[arr.length - 1] : null;
  8968. };
  8969. function locStart(node, opts) {
  8970. opts = opts || {}; // Handle nodes with decorators. They should start at the first decorator
  8971. if (!opts.ignoreDecorators && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0) {
  8972. return locStart(node.declaration.decorators[0]);
  8973. }
  8974. if (!opts.ignoreDecorators && node.decorators && node.decorators.length > 0) {
  8975. return locStart(node.decorators[0]);
  8976. }
  8977. if (node.__location) {
  8978. return node.__location.startOffset;
  8979. }
  8980. if (node.range) {
  8981. return node.range[0];
  8982. }
  8983. if (typeof node.start === "number") {
  8984. return node.start;
  8985. }
  8986. if (node.loc) {
  8987. return node.loc.start;
  8988. }
  8989. return null;
  8990. }
  8991. function locEnd(node) {
  8992. var endNode = node.nodes && getLast(node.nodes);
  8993. if (endNode && node.source && !node.source.end) {
  8994. node = endNode;
  8995. }
  8996. if (node.__location) {
  8997. return node.__location.endOffset;
  8998. }
  8999. var loc = node.range ? node.range[1] : typeof node.end === "number" ? node.end : null;
  9000. if (node.typeAnnotation) {
  9001. return Math.max(loc, locEnd(node.typeAnnotation));
  9002. }
  9003. if (node.loc && !loc) {
  9004. return node.loc.end;
  9005. }
  9006. return loc;
  9007. }
  9008. var loc = {
  9009. locStart: locStart,
  9010. locEnd: locEnd
  9011. };
  9012. var jsTokens = createCommonjsModule(function (module, exports) {
  9013. // Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
  9014. // License: MIT. (See LICENSE.)
  9015. Object.defineProperty(exports, "__esModule", {
  9016. value: true
  9017. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  9018. // (run `npm run build`).
  9019. 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;
  9020. exports.matchToToken = function (match) {
  9021. var token = {
  9022. type: "invalid",
  9023. value: match[0],
  9024. closed: undefined
  9025. };
  9026. 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";
  9027. return token;
  9028. };
  9029. });
  9030. unwrapExports(jsTokens);
  9031. var jsTokens_1 = jsTokens.matchToToken;
  9032. var ast = createCommonjsModule(function (module) {
  9033. /*
  9034. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  9035. Redistribution and use in source and binary forms, with or without
  9036. modification, are permitted provided that the following conditions are met:
  9037. * Redistributions of source code must retain the above copyright
  9038. notice, this list of conditions and the following disclaimer.
  9039. * Redistributions in binary form must reproduce the above copyright
  9040. notice, this list of conditions and the following disclaimer in the
  9041. documentation and/or other materials provided with the distribution.
  9042. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  9043. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  9044. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  9045. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  9046. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  9047. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  9048. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  9049. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  9050. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  9051. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9052. */
  9053. (function () {
  9054. function isExpression(node) {
  9055. if (node == null) {
  9056. return false;
  9057. }
  9058. switch (node.type) {
  9059. case 'ArrayExpression':
  9060. case 'AssignmentExpression':
  9061. case 'BinaryExpression':
  9062. case 'CallExpression':
  9063. case 'ConditionalExpression':
  9064. case 'FunctionExpression':
  9065. case 'Identifier':
  9066. case 'Literal':
  9067. case 'LogicalExpression':
  9068. case 'MemberExpression':
  9069. case 'NewExpression':
  9070. case 'ObjectExpression':
  9071. case 'SequenceExpression':
  9072. case 'ThisExpression':
  9073. case 'UnaryExpression':
  9074. case 'UpdateExpression':
  9075. return true;
  9076. }
  9077. return false;
  9078. }
  9079. function isIterationStatement(node) {
  9080. if (node == null) {
  9081. return false;
  9082. }
  9083. switch (node.type) {
  9084. case 'DoWhileStatement':
  9085. case 'ForInStatement':
  9086. case 'ForStatement':
  9087. case 'WhileStatement':
  9088. return true;
  9089. }
  9090. return false;
  9091. }
  9092. function isStatement(node) {
  9093. if (node == null) {
  9094. return false;
  9095. }
  9096. switch (node.type) {
  9097. case 'BlockStatement':
  9098. case 'BreakStatement':
  9099. case 'ContinueStatement':
  9100. case 'DebuggerStatement':
  9101. case 'DoWhileStatement':
  9102. case 'EmptyStatement':
  9103. case 'ExpressionStatement':
  9104. case 'ForInStatement':
  9105. case 'ForStatement':
  9106. case 'IfStatement':
  9107. case 'LabeledStatement':
  9108. case 'ReturnStatement':
  9109. case 'SwitchStatement':
  9110. case 'ThrowStatement':
  9111. case 'TryStatement':
  9112. case 'VariableDeclaration':
  9113. case 'WhileStatement':
  9114. case 'WithStatement':
  9115. return true;
  9116. }
  9117. return false;
  9118. }
  9119. function isSourceElement(node) {
  9120. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  9121. }
  9122. function trailingStatement(node) {
  9123. switch (node.type) {
  9124. case 'IfStatement':
  9125. if (node.alternate != null) {
  9126. return node.alternate;
  9127. }
  9128. return node.consequent;
  9129. case 'LabeledStatement':
  9130. case 'ForStatement':
  9131. case 'ForInStatement':
  9132. case 'WhileStatement':
  9133. case 'WithStatement':
  9134. return node.body;
  9135. }
  9136. return null;
  9137. }
  9138. function isProblematicIfStatement(node) {
  9139. var current;
  9140. if (node.type !== 'IfStatement') {
  9141. return false;
  9142. }
  9143. if (node.alternate == null) {
  9144. return false;
  9145. }
  9146. current = node.consequent;
  9147. do {
  9148. if (current.type === 'IfStatement') {
  9149. if (current.alternate == null) {
  9150. return true;
  9151. }
  9152. }
  9153. current = trailingStatement(current);
  9154. } while (current);
  9155. return false;
  9156. }
  9157. module.exports = {
  9158. isExpression: isExpression,
  9159. isStatement: isStatement,
  9160. isIterationStatement: isIterationStatement,
  9161. isSourceElement: isSourceElement,
  9162. isProblematicIfStatement: isProblematicIfStatement,
  9163. trailingStatement: trailingStatement
  9164. };
  9165. })();
  9166. /* vim: set sw=4 ts=4 et tw=80 : */
  9167. });
  9168. var ast_1 = ast.isExpression;
  9169. var ast_2 = ast.isStatement;
  9170. var ast_3 = ast.isIterationStatement;
  9171. var ast_4 = ast.isSourceElement;
  9172. var ast_5 = ast.isProblematicIfStatement;
  9173. var ast_6 = ast.trailingStatement;
  9174. var code = createCommonjsModule(function (module) {
  9175. /*
  9176. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  9177. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  9178. Redistribution and use in source and binary forms, with or without
  9179. modification, are permitted provided that the following conditions are met:
  9180. * Redistributions of source code must retain the above copyright
  9181. notice, this list of conditions and the following disclaimer.
  9182. * Redistributions in binary form must reproduce the above copyright
  9183. notice, this list of conditions and the following disclaimer in the
  9184. documentation and/or other materials provided with the distribution.
  9185. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  9186. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  9187. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  9188. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  9189. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  9190. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  9191. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  9192. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  9193. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  9194. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9195. */
  9196. (function () {
  9197. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch; // See `tools/generate-identifier-regex.js`.
  9198. ES5Regex = {
  9199. // ECMAScript 5.1/Unicode v9.0.0 NonAsciiIdentifierStart:
  9200. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\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\u0D05-\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\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\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-\u1877\u1880-\u1884\u1887-\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\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\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-\uAB65\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]/,
  9201. // ECMAScript 5.1/Unicode v9.0.0 NonAsciiIdentifierPart:
  9202. NonAsciiIdentifierPart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/
  9203. };
  9204. ES6Regex = {
  9205. // ECMAScript 6/Unicode v9.0.0 NonAsciiIdentifierStart:
  9206. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\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\u0D05-\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\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\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-\u1877\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\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\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-\uAB65\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]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,
  9207. // ECMAScript 6/Unicode v9.0.0 NonAsciiIdentifierPart:
  9208. NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
  9209. };
  9210. function isDecimalDigit(ch) {
  9211. return 0x30 <= ch && ch <= 0x39; // 0..9
  9212. }
  9213. function isHexDigit(ch) {
  9214. return 0x30 <= ch && ch <= 0x39 || // 0..9
  9215. 0x61 <= ch && ch <= 0x66 || // a..f
  9216. 0x41 <= ch && ch <= 0x46; // A..F
  9217. }
  9218. function isOctalDigit(ch) {
  9219. return ch >= 0x30 && ch <= 0x37; // 0..7
  9220. } // 7.2 White Space
  9221. NON_ASCII_WHITESPACES = [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF];
  9222. function isWhiteSpace(ch) {
  9223. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 || ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  9224. } // 7.3 Line Terminators
  9225. function isLineTerminator(ch) {
  9226. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  9227. } // 7.6 Identifier Names and Identifiers
  9228. function fromCodePoint(cp) {
  9229. if (cp <= 0xFFFF) {
  9230. return String.fromCharCode(cp);
  9231. }
  9232. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  9233. var cu2 = String.fromCharCode((cp - 0x10000) % 0x400 + 0xDC00);
  9234. return cu1 + cu2;
  9235. }
  9236. IDENTIFIER_START = new Array(0x80);
  9237. for (ch = 0; ch < 0x80; ++ch) {
  9238. IDENTIFIER_START[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  9239. ch >= 0x41 && ch <= 0x5A || // A..Z
  9240. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  9241. }
  9242. IDENTIFIER_PART = new Array(0x80);
  9243. for (ch = 0; ch < 0x80; ++ch) {
  9244. IDENTIFIER_PART[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  9245. ch >= 0x41 && ch <= 0x5A || // A..Z
  9246. ch >= 0x30 && ch <= 0x39 || // 0..9
  9247. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  9248. }
  9249. function isIdentifierStartES5(ch) {
  9250. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  9251. }
  9252. function isIdentifierPartES5(ch) {
  9253. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  9254. }
  9255. function isIdentifierStartES6(ch) {
  9256. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  9257. }
  9258. function isIdentifierPartES6(ch) {
  9259. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  9260. }
  9261. module.exports = {
  9262. isDecimalDigit: isDecimalDigit,
  9263. isHexDigit: isHexDigit,
  9264. isOctalDigit: isOctalDigit,
  9265. isWhiteSpace: isWhiteSpace,
  9266. isLineTerminator: isLineTerminator,
  9267. isIdentifierStartES5: isIdentifierStartES5,
  9268. isIdentifierPartES5: isIdentifierPartES5,
  9269. isIdentifierStartES6: isIdentifierStartES6,
  9270. isIdentifierPartES6: isIdentifierPartES6
  9271. };
  9272. })();
  9273. /* vim: set sw=4 ts=4 et tw=80 : */
  9274. });
  9275. var code_1 = code.isDecimalDigit;
  9276. var code_2 = code.isHexDigit;
  9277. var code_3 = code.isOctalDigit;
  9278. var code_4 = code.isWhiteSpace;
  9279. var code_5 = code.isLineTerminator;
  9280. var code_6 = code.isIdentifierStartES5;
  9281. var code_7 = code.isIdentifierPartES5;
  9282. var code_8 = code.isIdentifierStartES6;
  9283. var code_9 = code.isIdentifierPartES6;
  9284. var keyword = createCommonjsModule(function (module) {
  9285. /*
  9286. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  9287. Redistribution and use in source and binary forms, with or without
  9288. modification, are permitted provided that the following conditions are met:
  9289. * Redistributions of source code must retain the above copyright
  9290. notice, this list of conditions and the following disclaimer.
  9291. * Redistributions in binary form must reproduce the above copyright
  9292. notice, this list of conditions and the following disclaimer in the
  9293. documentation and/or other materials provided with the distribution.
  9294. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  9295. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  9296. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  9297. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  9298. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  9299. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  9300. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  9301. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  9302. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  9303. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9304. */
  9305. (function () {
  9306. var code$1 = code;
  9307. function isStrictModeReservedWordES6(id) {
  9308. switch (id) {
  9309. case 'implements':
  9310. case 'interface':
  9311. case 'package':
  9312. case 'private':
  9313. case 'protected':
  9314. case 'public':
  9315. case 'static':
  9316. case 'let':
  9317. return true;
  9318. default:
  9319. return false;
  9320. }
  9321. }
  9322. function isKeywordES5(id, strict) {
  9323. // yield should not be treated as keyword under non-strict mode.
  9324. if (!strict && id === 'yield') {
  9325. return false;
  9326. }
  9327. return isKeywordES6(id, strict);
  9328. }
  9329. function isKeywordES6(id, strict) {
  9330. if (strict && isStrictModeReservedWordES6(id)) {
  9331. return true;
  9332. }
  9333. switch (id.length) {
  9334. case 2:
  9335. return id === 'if' || id === 'in' || id === 'do';
  9336. case 3:
  9337. return id === 'var' || id === 'for' || id === 'new' || id === 'try';
  9338. case 4:
  9339. return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
  9340. case 5:
  9341. return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
  9342. case 6:
  9343. return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
  9344. case 7:
  9345. return id === 'default' || id === 'finally' || id === 'extends';
  9346. case 8:
  9347. return id === 'function' || id === 'continue' || id === 'debugger';
  9348. case 10:
  9349. return id === 'instanceof';
  9350. default:
  9351. return false;
  9352. }
  9353. }
  9354. function isReservedWordES5(id, strict) {
  9355. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  9356. }
  9357. function isReservedWordES6(id, strict) {
  9358. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  9359. }
  9360. function isRestrictedWord(id) {
  9361. return id === 'eval' || id === 'arguments';
  9362. }
  9363. function isIdentifierNameES5(id) {
  9364. var i, iz, ch;
  9365. if (id.length === 0) {
  9366. return false;
  9367. }
  9368. ch = id.charCodeAt(0);
  9369. if (!code$1.isIdentifierStartES5(ch)) {
  9370. return false;
  9371. }
  9372. for (i = 1, iz = id.length; i < iz; ++i) {
  9373. ch = id.charCodeAt(i);
  9374. if (!code$1.isIdentifierPartES5(ch)) {
  9375. return false;
  9376. }
  9377. }
  9378. return true;
  9379. }
  9380. function decodeUtf16(lead, trail) {
  9381. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  9382. }
  9383. function isIdentifierNameES6(id) {
  9384. var i, iz, ch, lowCh, check;
  9385. if (id.length === 0) {
  9386. return false;
  9387. }
  9388. check = code$1.isIdentifierStartES6;
  9389. for (i = 0, iz = id.length; i < iz; ++i) {
  9390. ch = id.charCodeAt(i);
  9391. if (0xD800 <= ch && ch <= 0xDBFF) {
  9392. ++i;
  9393. if (i >= iz) {
  9394. return false;
  9395. }
  9396. lowCh = id.charCodeAt(i);
  9397. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  9398. return false;
  9399. }
  9400. ch = decodeUtf16(ch, lowCh);
  9401. }
  9402. if (!check(ch)) {
  9403. return false;
  9404. }
  9405. check = code$1.isIdentifierPartES6;
  9406. }
  9407. return true;
  9408. }
  9409. function isIdentifierES5(id, strict) {
  9410. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  9411. }
  9412. function isIdentifierES6(id, strict) {
  9413. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  9414. }
  9415. module.exports = {
  9416. isKeywordES5: isKeywordES5,
  9417. isKeywordES6: isKeywordES6,
  9418. isReservedWordES5: isReservedWordES5,
  9419. isReservedWordES6: isReservedWordES6,
  9420. isRestrictedWord: isRestrictedWord,
  9421. isIdentifierNameES5: isIdentifierNameES5,
  9422. isIdentifierNameES6: isIdentifierNameES6,
  9423. isIdentifierES5: isIdentifierES5,
  9424. isIdentifierES6: isIdentifierES6
  9425. };
  9426. })();
  9427. /* vim: set sw=4 ts=4 et tw=80 : */
  9428. });
  9429. var keyword_1 = keyword.isKeywordES5;
  9430. var keyword_2 = keyword.isKeywordES6;
  9431. var keyword_3 = keyword.isReservedWordES5;
  9432. var keyword_4 = keyword.isReservedWordES6;
  9433. var keyword_5 = keyword.isRestrictedWord;
  9434. var keyword_6 = keyword.isIdentifierNameES5;
  9435. var keyword_7 = keyword.isIdentifierNameES6;
  9436. var keyword_8 = keyword.isIdentifierES5;
  9437. var keyword_9 = keyword.isIdentifierES6;
  9438. var utils$1 = createCommonjsModule(function (module, exports) {
  9439. /*
  9440. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  9441. Redistribution and use in source and binary forms, with or without
  9442. modification, are permitted provided that the following conditions are met:
  9443. * Redistributions of source code must retain the above copyright
  9444. notice, this list of conditions and the following disclaimer.
  9445. * Redistributions in binary form must reproduce the above copyright
  9446. notice, this list of conditions and the following disclaimer in the
  9447. documentation and/or other materials provided with the distribution.
  9448. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  9449. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  9450. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  9451. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  9452. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  9453. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  9454. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  9455. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  9456. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  9457. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9458. */
  9459. (function () {
  9460. exports.ast = ast;
  9461. exports.code = code;
  9462. exports.keyword = keyword;
  9463. })();
  9464. /* vim: set sw=4 ts=4 et tw=80 : */
  9465. });
  9466. var utils_1$1 = utils$1.ast;
  9467. var utils_2$1 = utils$1.code;
  9468. var utils_3$1 = utils$1.keyword;
  9469. var lib$1 = createCommonjsModule(function (module, exports) {
  9470. Object.defineProperty(exports, "__esModule", {
  9471. value: true
  9472. });
  9473. exports.shouldHighlight = shouldHighlight;
  9474. exports.getChalk = getChalk;
  9475. exports.default = highlight;
  9476. function _jsTokens() {
  9477. var data = _interopRequireWildcard(jsTokens);
  9478. _jsTokens = function _jsTokens() {
  9479. return data;
  9480. };
  9481. return data;
  9482. }
  9483. function _esutils() {
  9484. var data = _interopRequireDefault(utils$1);
  9485. _esutils = function _esutils() {
  9486. return data;
  9487. };
  9488. return data;
  9489. }
  9490. function _chalk() {
  9491. var data = _interopRequireDefault(chalk);
  9492. _chalk = function _chalk() {
  9493. return data;
  9494. };
  9495. return data;
  9496. }
  9497. function _interopRequireDefault(obj) {
  9498. return obj && obj.__esModule ? obj : {
  9499. default: obj
  9500. };
  9501. }
  9502. function _interopRequireWildcard(obj) {
  9503. if (obj && obj.__esModule) {
  9504. return obj;
  9505. } else {
  9506. var newObj = {};
  9507. if (obj != null) {
  9508. for (var key in obj) {
  9509. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  9510. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  9511. if (desc.get || desc.set) {
  9512. Object.defineProperty(newObj, key, desc);
  9513. } else {
  9514. newObj[key] = obj[key];
  9515. }
  9516. }
  9517. }
  9518. }
  9519. newObj.default = obj;
  9520. return newObj;
  9521. }
  9522. }
  9523. function getDefs(chalk) {
  9524. return {
  9525. keyword: chalk.cyan,
  9526. capitalized: chalk.yellow,
  9527. jsx_tag: chalk.yellow,
  9528. punctuator: chalk.yellow,
  9529. number: chalk.magenta,
  9530. string: chalk.green,
  9531. regex: chalk.magenta,
  9532. comment: chalk.grey,
  9533. invalid: chalk.white.bgRed.bold
  9534. };
  9535. }
  9536. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  9537. var JSX_TAG = /^[a-z][\w-]*$/i;
  9538. var BRACKET = /^[()[\]{}]$/;
  9539. function getTokenType(match) {
  9540. var _match$slice = match.slice(-2),
  9541. _match$slice2 = _slicedToArray(_match$slice, 2),
  9542. offset = _match$slice2[0],
  9543. text = _match$slice2[1];
  9544. var token = (0, _jsTokens().matchToToken)(match);
  9545. if (token.type === "name") {
  9546. if (_esutils().default.keyword.isReservedWordES6(token.value)) {
  9547. return "keyword";
  9548. }
  9549. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  9550. return "jsx_tag";
  9551. }
  9552. if (token.value[0] !== token.value[0].toLowerCase()) {
  9553. return "capitalized";
  9554. }
  9555. }
  9556. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  9557. return "bracket";
  9558. }
  9559. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  9560. return "punctuator";
  9561. }
  9562. return token.type;
  9563. }
  9564. function highlightTokens(defs, text) {
  9565. return text.replace(_jsTokens().default, function () {
  9566. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  9567. args[_key] = arguments[_key];
  9568. }
  9569. var type = getTokenType(args);
  9570. var colorize = defs[type];
  9571. if (colorize) {
  9572. return args[0].split(NEWLINE).map(function (str) {
  9573. return colorize(str);
  9574. }).join("\n");
  9575. } else {
  9576. return args[0];
  9577. }
  9578. });
  9579. }
  9580. function shouldHighlight(options) {
  9581. return _chalk().default.supportsColor || options.forceColor;
  9582. }
  9583. function getChalk(options) {
  9584. var chalk = _chalk().default;
  9585. if (options.forceColor) {
  9586. chalk = new (_chalk().default.constructor)({
  9587. enabled: true,
  9588. level: 1
  9589. });
  9590. }
  9591. return chalk;
  9592. }
  9593. function highlight(code) {
  9594. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  9595. if (shouldHighlight(options)) {
  9596. var chalk = getChalk(options);
  9597. var defs = getDefs(chalk);
  9598. return highlightTokens(defs, code);
  9599. } else {
  9600. return code;
  9601. }
  9602. }
  9603. });
  9604. unwrapExports(lib$1);
  9605. var lib_1 = lib$1.shouldHighlight;
  9606. var lib_2 = lib$1.getChalk;
  9607. var lib$2 = createCommonjsModule(function (module, exports) {
  9608. Object.defineProperty(exports, "__esModule", {
  9609. value: true
  9610. });
  9611. exports.codeFrameColumns = codeFrameColumns;
  9612. exports.default = _default;
  9613. function _highlight() {
  9614. var data = _interopRequireWildcard(lib$1);
  9615. _highlight = function _highlight() {
  9616. return data;
  9617. };
  9618. return data;
  9619. }
  9620. function _interopRequireWildcard(obj) {
  9621. if (obj && obj.__esModule) {
  9622. return obj;
  9623. } else {
  9624. var newObj = {};
  9625. if (obj != null) {
  9626. for (var key in obj) {
  9627. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  9628. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  9629. if (desc.get || desc.set) {
  9630. Object.defineProperty(newObj, key, desc);
  9631. } else {
  9632. newObj[key] = obj[key];
  9633. }
  9634. }
  9635. }
  9636. }
  9637. newObj.default = obj;
  9638. return newObj;
  9639. }
  9640. }
  9641. var deprecationWarningShown = false;
  9642. function getDefs(chalk) {
  9643. return {
  9644. gutter: chalk.grey,
  9645. marker: chalk.red.bold,
  9646. message: chalk.red.bold
  9647. };
  9648. }
  9649. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  9650. function getMarkerLines(loc, source, opts) {
  9651. var startLoc = Object.assign({
  9652. column: 0,
  9653. line: -1
  9654. }, loc.start);
  9655. var endLoc = Object.assign({}, startLoc, loc.end);
  9656. var _ref = opts || {},
  9657. _ref$linesAbove = _ref.linesAbove,
  9658. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  9659. _ref$linesBelow = _ref.linesBelow,
  9660. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  9661. var startLine = startLoc.line;
  9662. var startColumn = startLoc.column;
  9663. var endLine = endLoc.line;
  9664. var endColumn = endLoc.column;
  9665. var start = Math.max(startLine - (linesAbove + 1), 0);
  9666. var end = Math.min(source.length, endLine + linesBelow);
  9667. if (startLine === -1) {
  9668. start = 0;
  9669. }
  9670. if (endLine === -1) {
  9671. end = source.length;
  9672. }
  9673. var lineDiff = endLine - startLine;
  9674. var markerLines = {};
  9675. if (lineDiff) {
  9676. for (var i = 0; i <= lineDiff; i++) {
  9677. var lineNumber = i + startLine;
  9678. if (!startColumn) {
  9679. markerLines[lineNumber] = true;
  9680. } else if (i === 0) {
  9681. var sourceLength = source[lineNumber - 1].length;
  9682. markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
  9683. } else if (i === lineDiff) {
  9684. markerLines[lineNumber] = [0, endColumn];
  9685. } else {
  9686. var _sourceLength = source[lineNumber - i].length;
  9687. markerLines[lineNumber] = [0, _sourceLength];
  9688. }
  9689. }
  9690. } else {
  9691. if (startColumn === endColumn) {
  9692. if (startColumn) {
  9693. markerLines[startLine] = [startColumn, 0];
  9694. } else {
  9695. markerLines[startLine] = true;
  9696. }
  9697. } else {
  9698. markerLines[startLine] = [startColumn, endColumn - startColumn];
  9699. }
  9700. }
  9701. return {
  9702. start: start,
  9703. end: end,
  9704. markerLines: markerLines
  9705. };
  9706. }
  9707. function codeFrameColumns(rawLines, loc) {
  9708. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  9709. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
  9710. var chalk = (0, _highlight().getChalk)(opts);
  9711. var defs = getDefs(chalk);
  9712. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  9713. return highlighted ? chalkFn(string) : string;
  9714. };
  9715. var lines = rawLines.split(NEWLINE);
  9716. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  9717. start = _getMarkerLines.start,
  9718. end = _getMarkerLines.end,
  9719. markerLines = _getMarkerLines.markerLines;
  9720. var hasColumns = loc.start && typeof loc.start.column === "number";
  9721. var numberMaxWidth = String(end).length;
  9722. var highlightedLines = highlighted ? (0, _highlight().default)(rawLines, opts) : rawLines;
  9723. var frame = highlightedLines.split(NEWLINE).slice(start, end).map(function (line, index) {
  9724. var number = start + 1 + index;
  9725. var paddedNumber = " ".concat(number).slice(-numberMaxWidth);
  9726. var gutter = " ".concat(paddedNumber, " | ");
  9727. var hasMarker = markerLines[number];
  9728. var lastMarkerLine = !markerLines[number + 1];
  9729. if (hasMarker) {
  9730. var markerLine = "";
  9731. if (Array.isArray(hasMarker)) {
  9732. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  9733. var numberOfMarkers = hasMarker[1] || 1;
  9734. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  9735. if (lastMarkerLine && opts.message) {
  9736. markerLine += " " + maybeHighlight(defs.message, opts.message);
  9737. }
  9738. }
  9739. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  9740. } else {
  9741. return " ".concat(maybeHighlight(defs.gutter, gutter)).concat(line);
  9742. }
  9743. }).join("\n");
  9744. if (opts.message && !hasColumns) {
  9745. frame = "".concat(" ".repeat(numberMaxWidth + 1)).concat(opts.message, "\n").concat(frame);
  9746. }
  9747. if (highlighted) {
  9748. return chalk.reset(frame);
  9749. } else {
  9750. return frame;
  9751. }
  9752. }
  9753. function _default(rawLines, lineNumber, colNumber) {
  9754. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  9755. if (!deprecationWarningShown) {
  9756. deprecationWarningShown = true;
  9757. var message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  9758. if (process.emitWarning) {
  9759. process.emitWarning(message, "DeprecationWarning");
  9760. } else {
  9761. var deprecationError = new Error(message);
  9762. deprecationError.name = "DeprecationWarning";
  9763. console.warn(new Error(message));
  9764. }
  9765. }
  9766. colNumber = Math.max(colNumber, 0);
  9767. var location = {
  9768. start: {
  9769. column: colNumber,
  9770. line: lineNumber
  9771. }
  9772. };
  9773. return codeFrameColumns(rawLines, location, opts);
  9774. }
  9775. });
  9776. unwrapExports(lib$2);
  9777. var lib_1$1 = lib$2.codeFrameColumns;
  9778. var ConfigError$1 = errors.ConfigError;
  9779. var locStart$1 = loc.locStart,
  9780. locEnd$1 = loc.locEnd; // Use defineProperties()/getOwnPropertyDescriptor() to prevent
  9781. // triggering the parsers getters.
  9782. var ownNames = Object.getOwnPropertyNames;
  9783. var ownDescriptor = Object.getOwnPropertyDescriptor;
  9784. function getParsers(options) {
  9785. var parsers = {};
  9786. var _iteratorNormalCompletion = true;
  9787. var _didIteratorError = false;
  9788. var _iteratorError = undefined;
  9789. try {
  9790. for (var _iterator = options.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  9791. var plugin = _step.value;
  9792. if (!plugin.parsers) {
  9793. continue;
  9794. }
  9795. var _iteratorNormalCompletion2 = true;
  9796. var _didIteratorError2 = false;
  9797. var _iteratorError2 = undefined;
  9798. try {
  9799. for (var _iterator2 = ownNames(plugin.parsers)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  9800. var name = _step2.value;
  9801. Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name));
  9802. }
  9803. } catch (err) {
  9804. _didIteratorError2 = true;
  9805. _iteratorError2 = err;
  9806. } finally {
  9807. try {
  9808. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  9809. _iterator2.return();
  9810. }
  9811. } finally {
  9812. if (_didIteratorError2) {
  9813. throw _iteratorError2;
  9814. }
  9815. }
  9816. }
  9817. }
  9818. } catch (err) {
  9819. _didIteratorError = true;
  9820. _iteratorError = err;
  9821. } finally {
  9822. try {
  9823. if (!_iteratorNormalCompletion && _iterator.return != null) {
  9824. _iterator.return();
  9825. }
  9826. } finally {
  9827. if (_didIteratorError) {
  9828. throw _iteratorError;
  9829. }
  9830. }
  9831. }
  9832. return parsers;
  9833. }
  9834. function resolveParser(opts, parsers) {
  9835. parsers = parsers || getParsers(opts);
  9836. if (typeof opts.parser === "function") {
  9837. // Custom parser API always works with JavaScript.
  9838. return {
  9839. parse: opts.parser,
  9840. astFormat: "estree",
  9841. locStart: locStart$1,
  9842. locEnd: locEnd$1
  9843. };
  9844. }
  9845. if (typeof opts.parser === "string") {
  9846. if (Object.prototype.hasOwnProperty.call(parsers, opts.parser)) {
  9847. return parsers[opts.parser];
  9848. }
  9849. /* istanbul ignore next */
  9850. {
  9851. throw new ConfigError$1("Couldn't resolve parser \"".concat(opts.parser, "\". Parsers must be explicitly added to the standalone bundle."));
  9852. }
  9853. }
  9854. }
  9855. function parse(text, opts) {
  9856. var parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call
  9857. // the parsers getters when actually calling the parser `parse` function.
  9858. var parsersForCustomParserApi = Object.keys(parsers).reduce(function (object, parserName) {
  9859. return Object.defineProperty(object, parserName, {
  9860. enumerable: true,
  9861. get: function get() {
  9862. return parsers[parserName].parse;
  9863. }
  9864. });
  9865. }, {});
  9866. var parser = resolveParser(opts, parsers);
  9867. try {
  9868. if (parser.preprocess) {
  9869. text = parser.preprocess(text, opts);
  9870. }
  9871. return {
  9872. text: text,
  9873. ast: parser.parse(text, parsersForCustomParserApi, opts)
  9874. };
  9875. } catch (error) {
  9876. var loc = error.loc;
  9877. if (loc) {
  9878. var codeFrame = lib$2;
  9879. error.codeFrame = codeFrame.codeFrameColumns(text, loc, {
  9880. highlightCode: true
  9881. });
  9882. error.message += "\n" + error.codeFrame;
  9883. throw error;
  9884. }
  9885. /* istanbul ignore next */
  9886. throw error.stack;
  9887. }
  9888. }
  9889. var parser = {
  9890. parse: parse,
  9891. resolveParser: resolveParser
  9892. };
  9893. var UndefinedParserError$1 = errors.UndefinedParserError;
  9894. var getSupportInfo$1 = support.getSupportInfo;
  9895. var resolveParser$1 = parser.resolveParser;
  9896. var hiddenDefaults = {
  9897. astFormat: "estree",
  9898. printer: {},
  9899. originalText: undefined,
  9900. locStart: null,
  9901. locEnd: null
  9902. }; // Copy options and fill in default values.
  9903. function normalize$1(options, opts) {
  9904. opts = opts || {};
  9905. var rawOptions = Object.assign({}, options);
  9906. var supportOptions = getSupportInfo$1(null, {
  9907. plugins: options.plugins,
  9908. showUnreleased: true,
  9909. showDeprecated: true
  9910. }).options;
  9911. var defaults = supportOptions.reduce(function (reduced, optionInfo) {
  9912. return optionInfo.default !== undefined ? Object.assign(reduced, _defineProperty({}, optionInfo.name, optionInfo.default)) : reduced;
  9913. }, Object.assign({}, hiddenDefaults));
  9914. if (!rawOptions.parser) {
  9915. if (!rawOptions.filepath) {
  9916. var logger = opts.logger || console;
  9917. logger.warn("No parser and no filepath given, using 'babel' the parser now " + "but this will throw an error in the future. " + "Please specify a parser or a filepath so one can be inferred.");
  9918. rawOptions.parser = "babel";
  9919. } else {
  9920. rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins);
  9921. if (!rawOptions.parser) {
  9922. throw new UndefinedParserError$1("No parser could be inferred for file: ".concat(rawOptions.filepath));
  9923. }
  9924. }
  9925. }
  9926. var parser = resolveParser$1(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(function (x) {
  9927. return x.name === "parser";
  9928. })], {
  9929. passThrough: true,
  9930. logger: false
  9931. }));
  9932. rawOptions.astFormat = parser.astFormat;
  9933. rawOptions.locEnd = parser.locEnd;
  9934. rawOptions.locStart = parser.locStart;
  9935. var plugin = getPlugin(rawOptions);
  9936. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  9937. var pluginDefaults = supportOptions.filter(function (optionInfo) {
  9938. return optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name] !== undefined;
  9939. }).reduce(function (reduced, optionInfo) {
  9940. return Object.assign(reduced, _defineProperty({}, optionInfo.name, optionInfo.pluginDefaults[plugin.name]));
  9941. }, {});
  9942. var mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  9943. Object.keys(mixedDefaults).forEach(function (k) {
  9944. if (rawOptions[k] == null) {
  9945. rawOptions[k] = mixedDefaults[k];
  9946. }
  9947. });
  9948. if (rawOptions.parser === "json") {
  9949. rawOptions.trailingComma = "none";
  9950. }
  9951. return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({
  9952. passThrough: Object.keys(hiddenDefaults)
  9953. }, opts));
  9954. }
  9955. function getPlugin(options) {
  9956. var astFormat = options.astFormat;
  9957. if (!astFormat) {
  9958. throw new Error("getPlugin() requires astFormat to be set");
  9959. }
  9960. var printerPlugin = options.plugins.find(function (plugin) {
  9961. return plugin.printers && plugin.printers[astFormat];
  9962. });
  9963. if (!printerPlugin) {
  9964. throw new Error("Couldn't find plugin for AST format \"".concat(astFormat, "\""));
  9965. }
  9966. return printerPlugin;
  9967. }
  9968. function getInterpreter(filepath) {
  9969. if (typeof filepath !== "string") {
  9970. return "";
  9971. }
  9972. var fd;
  9973. try {
  9974. fd = fs.openSync(filepath, "r");
  9975. } catch (err) {
  9976. return "";
  9977. }
  9978. try {
  9979. var liner = new readlines(fd);
  9980. var firstLine = liner.next().toString("utf8"); // #!/bin/env node, #!/usr/bin/env node
  9981. var m1 = firstLine.match(/^#!\/(?:usr\/)?bin\/env\s+(\S+)/);
  9982. if (m1) {
  9983. return m1[1];
  9984. } // #!/bin/node, #!/usr/bin/node, #!/usr/local/bin/node
  9985. var m2 = firstLine.match(/^#!\/(?:usr\/(?:local\/)?)?bin\/(\S+)/);
  9986. if (m2) {
  9987. return m2[1];
  9988. }
  9989. return "";
  9990. } catch (err) {
  9991. // There are some weird cases where paths are missing, causing Jest
  9992. // failures. It's unclear what these correspond to in the real world.
  9993. return "";
  9994. } finally {
  9995. try {
  9996. // There are some weird cases where paths are missing, causing Jest
  9997. // failures. It's unclear what these correspond to in the real world.
  9998. fs.closeSync(fd);
  9999. } catch (err) {// nop
  10000. }
  10001. }
  10002. }
  10003. function inferParser(filepath, plugins) {
  10004. var filepathParts = normalizePath(filepath).split("/");
  10005. var filename = filepathParts[filepathParts.length - 1].toLowerCase(); // If the file has no extension, we can try to infer the language from the
  10006. // interpreter in the shebang line, if any; but since this requires FS access,
  10007. // do it last.
  10008. var language = getSupportInfo$1(null, {
  10009. plugins: plugins
  10010. }).languages.find(function (language) {
  10011. return language.since !== null && (language.extensions && language.extensions.some(function (extension) {
  10012. return filename.endsWith(extension);
  10013. }) || language.filenames && language.filenames.find(function (name) {
  10014. return name.toLowerCase() === filename;
  10015. }) || filename.indexOf(".") === -1 && language.interpreters && language.interpreters.indexOf(getInterpreter(filepath)) !== -1);
  10016. });
  10017. return language && language.parsers[0];
  10018. }
  10019. var options$1 = {
  10020. normalize: normalize$1,
  10021. hiddenDefaults: hiddenDefaults,
  10022. inferParser: inferParser
  10023. };
  10024. function massageAST(ast, options, parent) {
  10025. if (Array.isArray(ast)) {
  10026. return ast.map(function (e) {
  10027. return massageAST(e, options, parent);
  10028. }).filter(function (e) {
  10029. return e;
  10030. });
  10031. }
  10032. if (!ast || _typeof(ast) !== "object") {
  10033. return ast;
  10034. }
  10035. var newObj = {};
  10036. for (var _i = 0, _Object$keys = Object.keys(ast); _i < _Object$keys.length; _i++) {
  10037. var key = _Object$keys[_i];
  10038. if (typeof ast[key] !== "function") {
  10039. newObj[key] = massageAST(ast[key], options, ast);
  10040. }
  10041. }
  10042. if (options.printer.massageAstNode) {
  10043. var result = options.printer.massageAstNode(ast, newObj, parent);
  10044. if (result === null) {
  10045. return undefined;
  10046. }
  10047. if (result) {
  10048. return result;
  10049. }
  10050. }
  10051. return newObj;
  10052. }
  10053. var massageAst = massageAST;
  10054. function assert() {}
  10055. assert.ok = function () {};
  10056. assert.strictEqual = function () {};
  10057. /**
  10058. * @param {Doc[]} parts
  10059. * @returns Doc
  10060. */
  10061. function concat(parts) {
  10062. // access the internals of a document directly.
  10063. // if(parts.length === 1) {
  10064. // // If it's a single document, no need to concat it.
  10065. // return parts[0];
  10066. // }
  10067. return {
  10068. type: "concat",
  10069. parts: parts
  10070. };
  10071. }
  10072. /**
  10073. * @param {Doc} contents
  10074. * @returns Doc
  10075. */
  10076. function indent(contents) {
  10077. return {
  10078. type: "indent",
  10079. contents: contents
  10080. };
  10081. }
  10082. /**
  10083. * @param {number} n
  10084. * @param {Doc} contents
  10085. * @returns Doc
  10086. */
  10087. function align(n, contents) {
  10088. return {
  10089. type: "align",
  10090. contents: contents,
  10091. n: n
  10092. };
  10093. }
  10094. /**
  10095. * @param {Doc} contents
  10096. * @param {object} [opts] - TBD ???
  10097. * @returns Doc
  10098. */
  10099. function group(contents, opts) {
  10100. opts = opts || {};
  10101. return {
  10102. type: "group",
  10103. id: opts.id,
  10104. contents: contents,
  10105. break: !!opts.shouldBreak,
  10106. expandedStates: opts.expandedStates
  10107. };
  10108. }
  10109. /**
  10110. * @param {Doc} contents
  10111. * @returns Doc
  10112. */
  10113. function dedentToRoot(contents) {
  10114. return align(-Infinity, contents);
  10115. }
  10116. /**
  10117. * @param {Doc} contents
  10118. * @returns Doc
  10119. */
  10120. function markAsRoot(contents) {
  10121. // @ts-ignore - TBD ???:
  10122. return align({
  10123. type: "root"
  10124. }, contents);
  10125. }
  10126. /**
  10127. * @param {Doc} contents
  10128. * @returns Doc
  10129. */
  10130. function dedent(contents) {
  10131. return align(-1, contents);
  10132. }
  10133. /**
  10134. * @param {Doc[]} states
  10135. * @param {object} [opts] - TBD ???
  10136. * @returns Doc
  10137. */
  10138. function conditionalGroup(states, opts) {
  10139. return group(states[0], Object.assign(opts || {}, {
  10140. expandedStates: states
  10141. }));
  10142. }
  10143. /**
  10144. * @param {Doc[]} parts
  10145. * @returns Doc
  10146. */
  10147. function fill(parts) {
  10148. return {
  10149. type: "fill",
  10150. parts: parts
  10151. };
  10152. }
  10153. /**
  10154. * @param {Doc} [breakContents]
  10155. * @param {Doc} [flatContents]
  10156. * @param {object} [opts] - TBD ???
  10157. * @returns Doc
  10158. */
  10159. function ifBreak(breakContents, flatContents, opts) {
  10160. opts = opts || {};
  10161. return {
  10162. type: "if-break",
  10163. breakContents: breakContents,
  10164. flatContents: flatContents,
  10165. groupId: opts.groupId
  10166. };
  10167. }
  10168. /**
  10169. * @param {Doc} contents
  10170. * @returns Doc
  10171. */
  10172. function lineSuffix(contents) {
  10173. return {
  10174. type: "line-suffix",
  10175. contents: contents
  10176. };
  10177. }
  10178. var lineSuffixBoundary = {
  10179. type: "line-suffix-boundary"
  10180. };
  10181. var breakParent = {
  10182. type: "break-parent"
  10183. };
  10184. var trim = {
  10185. type: "trim"
  10186. };
  10187. var line = {
  10188. type: "line"
  10189. };
  10190. var softline = {
  10191. type: "line",
  10192. soft: true
  10193. };
  10194. var hardline = concat([{
  10195. type: "line",
  10196. hard: true
  10197. }, breakParent]);
  10198. var literalline = concat([{
  10199. type: "line",
  10200. hard: true,
  10201. literal: true
  10202. }, breakParent]);
  10203. var cursor = {
  10204. type: "cursor",
  10205. placeholder: Symbol("cursor")
  10206. };
  10207. /**
  10208. * @param {Doc} sep
  10209. * @param {Doc[]} arr
  10210. * @returns Doc
  10211. */
  10212. function join(sep, arr) {
  10213. var res = [];
  10214. for (var i = 0; i < arr.length; i++) {
  10215. if (i !== 0) {
  10216. res.push(sep);
  10217. }
  10218. res.push(arr[i]);
  10219. }
  10220. return concat(res);
  10221. }
  10222. /**
  10223. * @param {Doc} doc
  10224. * @param {number} size
  10225. * @param {number} tabWidth
  10226. */
  10227. function addAlignmentToDoc(doc, size, tabWidth) {
  10228. var aligned = doc;
  10229. if (size > 0) {
  10230. // Use indent to add tabs for all the levels of tabs we need
  10231. for (var i = 0; i < Math.floor(size / tabWidth); ++i) {
  10232. aligned = indent(aligned);
  10233. } // Use align for all the spaces that are needed
  10234. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  10235. // indentation, so we use -Infinity to reset the indentation to 0
  10236. aligned = align(-Infinity, aligned);
  10237. }
  10238. return aligned;
  10239. }
  10240. var docBuilders = {
  10241. concat: concat,
  10242. join: join,
  10243. line: line,
  10244. softline: softline,
  10245. hardline: hardline,
  10246. literalline: literalline,
  10247. group: group,
  10248. conditionalGroup: conditionalGroup,
  10249. fill: fill,
  10250. lineSuffix: lineSuffix,
  10251. lineSuffixBoundary: lineSuffixBoundary,
  10252. cursor: cursor,
  10253. breakParent: breakParent,
  10254. ifBreak: ifBreak,
  10255. trim: trim,
  10256. indent: indent,
  10257. align: align,
  10258. addAlignmentToDoc: addAlignmentToDoc,
  10259. markAsRoot: markAsRoot,
  10260. dedentToRoot: dedentToRoot,
  10261. dedent: dedent
  10262. };
  10263. var ansiRegex = function ansiRegex(options) {
  10264. options = Object.assign({
  10265. onlyFirst: false
  10266. }, options);
  10267. var pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  10268. return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
  10269. };
  10270. var stripAnsi = function stripAnsi(string) {
  10271. return typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
  10272. };
  10273. var stripAnsi_1 = stripAnsi;
  10274. var default_1$1 = stripAnsi;
  10275. stripAnsi_1.default = default_1$1;
  10276. /* eslint-disable yoda */
  10277. var isFullwidthCodePoint = function isFullwidthCodePoint(codePoint) {
  10278. if (Number.isNaN(codePoint)) {
  10279. return false;
  10280. } // Code points are derived from:
  10281. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  10282. if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo
  10283. codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  10284. codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
  10285. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  10286. 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  10287. 0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals
  10288. 0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A
  10289. 0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables
  10290. 0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs
  10291. 0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms
  10292. 0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants
  10293. 0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms
  10294. 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement
  10295. 0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement
  10296. 0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  10297. 0x20000 <= codePoint && codePoint <= 0x3FFFD)) {
  10298. return true;
  10299. }
  10300. return false;
  10301. };
  10302. var isFullwidthCodePoint_1 = isFullwidthCodePoint;
  10303. var default_1$2 = isFullwidthCodePoint;
  10304. isFullwidthCodePoint_1.default = default_1$2;
  10305. var emojiRegex = function emojiRegex() {
  10306. // https://mths.be/emoji
  10307. return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
  10308. };
  10309. var stringWidth = function stringWidth(string) {
  10310. string = string.replace(emojiRegex(), ' ');
  10311. if (typeof string !== 'string' || string.length === 0) {
  10312. return 0;
  10313. }
  10314. string = stripAnsi_1(string);
  10315. var width = 0;
  10316. for (var i = 0; i < string.length; i++) {
  10317. var code = string.codePointAt(i); // Ignore control characters
  10318. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  10319. continue;
  10320. } // Ignore combining characters
  10321. if (code >= 0x300 && code <= 0x36F) {
  10322. continue;
  10323. } // Surrogates
  10324. if (code > 0xFFFF) {
  10325. i++;
  10326. }
  10327. width += isFullwidthCodePoint_1(code) ? 2 : 1;
  10328. }
  10329. return width;
  10330. };
  10331. var stringWidth_1 = stringWidth; // TODO: remove this in the next major version
  10332. var default_1$3 = stringWidth;
  10333. stringWidth_1.default = default_1$3;
  10334. var notAsciiRegex = /[^\x20-\x7F]/;
  10335. function isExportDeclaration(node) {
  10336. if (node) {
  10337. switch (node.type) {
  10338. case "ExportDefaultDeclaration":
  10339. case "ExportDefaultSpecifier":
  10340. case "DeclareExportDeclaration":
  10341. case "ExportNamedDeclaration":
  10342. case "ExportAllDeclaration":
  10343. return true;
  10344. }
  10345. }
  10346. return false;
  10347. }
  10348. function getParentExportDeclaration(path) {
  10349. var parentNode = path.getParentNode();
  10350. if (path.getName() === "declaration" && isExportDeclaration(parentNode)) {
  10351. return parentNode;
  10352. }
  10353. return null;
  10354. }
  10355. function getPenultimate(arr) {
  10356. if (arr.length > 1) {
  10357. return arr[arr.length - 2];
  10358. }
  10359. return null;
  10360. }
  10361. /**
  10362. * @typedef {{backwards?: boolean}} SkipOptions
  10363. */
  10364. /**
  10365. * @param {string | RegExp} chars
  10366. * @returns {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  10367. */
  10368. function skip(chars) {
  10369. return function (text, index, opts) {
  10370. var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  10371. // to check for failures (did someone say monads?).
  10372. if (index === false) {
  10373. return false;
  10374. }
  10375. var length = text.length;
  10376. var cursor = index;
  10377. while (cursor >= 0 && cursor < length) {
  10378. var c = text.charAt(cursor);
  10379. if (chars instanceof RegExp) {
  10380. if (!chars.test(c)) {
  10381. return cursor;
  10382. }
  10383. } else if (chars.indexOf(c) === -1) {
  10384. return cursor;
  10385. }
  10386. backwards ? cursor-- : cursor++;
  10387. }
  10388. if (cursor === -1 || cursor === length) {
  10389. // If we reached the beginning or end of the file, return the
  10390. // out-of-bounds cursor. It's up to the caller to handle this
  10391. // correctly. We don't want to indicate `false` though if it
  10392. // actually skipped valid characters.
  10393. return cursor;
  10394. }
  10395. return false;
  10396. };
  10397. }
  10398. /**
  10399. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  10400. */
  10401. var skipWhitespace = skip(/\s/);
  10402. /**
  10403. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  10404. */
  10405. var skipSpaces = skip(" \t");
  10406. /**
  10407. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  10408. */
  10409. var skipToLineEnd = skip(",; \t");
  10410. /**
  10411. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  10412. */
  10413. var skipEverythingButNewLine = skip(/[^\r\n]/);
  10414. /**
  10415. * @param {string} text
  10416. * @param {number | false} index
  10417. * @returns {number | false}
  10418. */
  10419. function skipInlineComment(text, index) {
  10420. if (index === false) {
  10421. return false;
  10422. }
  10423. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  10424. for (var i = index + 2; i < text.length; ++i) {
  10425. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  10426. return i + 2;
  10427. }
  10428. }
  10429. }
  10430. return index;
  10431. }
  10432. /**
  10433. * @param {string} text
  10434. * @param {number | false} index
  10435. * @returns {number | false}
  10436. */
  10437. function skipTrailingComment(text, index) {
  10438. if (index === false) {
  10439. return false;
  10440. }
  10441. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  10442. return skipEverythingButNewLine(text, index);
  10443. }
  10444. return index;
  10445. } // This one doesn't use the above helper function because it wants to
  10446. // test \r\n in order and `skip` doesn't support ordering and we only
  10447. // want to skip one newline. It's simple to implement.
  10448. /**
  10449. * @param {string} text
  10450. * @param {number | false} index
  10451. * @param {SkipOptions=} opts
  10452. * @returns {number | false}
  10453. */
  10454. function skipNewline(text, index, opts) {
  10455. var backwards = opts && opts.backwards;
  10456. if (index === false) {
  10457. return false;
  10458. }
  10459. var atIndex = text.charAt(index);
  10460. if (backwards) {
  10461. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  10462. return index - 2;
  10463. }
  10464. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  10465. return index - 1;
  10466. }
  10467. } else {
  10468. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  10469. return index + 2;
  10470. }
  10471. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  10472. return index + 1;
  10473. }
  10474. }
  10475. return index;
  10476. }
  10477. /**
  10478. * @param {string} text
  10479. * @param {number} index
  10480. * @param {SkipOptions=} opts
  10481. * @returns {boolean}
  10482. */
  10483. function hasNewline(text, index, opts) {
  10484. opts = opts || {};
  10485. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  10486. var idx2 = skipNewline(text, idx, opts);
  10487. return idx !== idx2;
  10488. }
  10489. /**
  10490. * @param {string} text
  10491. * @param {number} start
  10492. * @param {number} end
  10493. * @returns {boolean}
  10494. */
  10495. function hasNewlineInRange(text, start, end) {
  10496. for (var i = start; i < end; ++i) {
  10497. if (text.charAt(i) === "\n") {
  10498. return true;
  10499. }
  10500. }
  10501. return false;
  10502. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  10503. /**
  10504. * @template N
  10505. * @param {string} text
  10506. * @param {N} node
  10507. * @param {(node: N) => number} locStart
  10508. */
  10509. function isPreviousLineEmpty(text, node, locStart) {
  10510. /** @type {number | false} */
  10511. var idx = locStart(node) - 1;
  10512. idx = skipSpaces(text, idx, {
  10513. backwards: true
  10514. });
  10515. idx = skipNewline(text, idx, {
  10516. backwards: true
  10517. });
  10518. idx = skipSpaces(text, idx, {
  10519. backwards: true
  10520. });
  10521. var idx2 = skipNewline(text, idx, {
  10522. backwards: true
  10523. });
  10524. return idx !== idx2;
  10525. }
  10526. /**
  10527. * @param {string} text
  10528. * @param {number} index
  10529. * @returns {boolean}
  10530. */
  10531. function isNextLineEmptyAfterIndex(text, index) {
  10532. /** @type {number | false} */
  10533. var oldIdx = null;
  10534. /** @type {number | false} */
  10535. var idx = index;
  10536. while (idx !== oldIdx) {
  10537. // We need to skip all the potential trailing inline comments
  10538. oldIdx = idx;
  10539. idx = skipToLineEnd(text, idx);
  10540. idx = skipInlineComment(text, idx);
  10541. idx = skipSpaces(text, idx);
  10542. }
  10543. idx = skipTrailingComment(text, idx);
  10544. idx = skipNewline(text, idx);
  10545. return idx !== false && hasNewline(text, idx);
  10546. }
  10547. /**
  10548. * @template N
  10549. * @param {string} text
  10550. * @param {N} node
  10551. * @param {(node: N) => number} locEnd
  10552. * @returns {boolean}
  10553. */
  10554. function isNextLineEmpty(text, node, locEnd) {
  10555. return isNextLineEmptyAfterIndex(text, locEnd(node));
  10556. }
  10557. /**
  10558. * @param {string} text
  10559. * @param {number} idx
  10560. * @returns {number | false}
  10561. */
  10562. function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
  10563. /** @type {number | false} */
  10564. var oldIdx = null;
  10565. /** @type {number | false} */
  10566. var nextIdx = idx;
  10567. while (nextIdx !== oldIdx) {
  10568. oldIdx = nextIdx;
  10569. nextIdx = skipSpaces(text, nextIdx);
  10570. nextIdx = skipInlineComment(text, nextIdx);
  10571. nextIdx = skipTrailingComment(text, nextIdx);
  10572. nextIdx = skipNewline(text, nextIdx);
  10573. }
  10574. return nextIdx;
  10575. }
  10576. /**
  10577. * @template N
  10578. * @param {string} text
  10579. * @param {N} node
  10580. * @param {(node: N) => number} locEnd
  10581. * @returns {number | false}
  10582. */
  10583. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  10584. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
  10585. }
  10586. /**
  10587. * @template N
  10588. * @param {string} text
  10589. * @param {N} node
  10590. * @param {(node: N) => number} locEnd
  10591. * @returns {string}
  10592. */
  10593. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  10594. return text.charAt( // @ts-ignore => TBD: can return false, should we define a fallback?
  10595. getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  10596. }
  10597. /**
  10598. * @param {string} text
  10599. * @param {number} index
  10600. * @param {SkipOptions=} opts
  10601. * @returns {boolean}
  10602. */
  10603. function hasSpaces(text, index, opts) {
  10604. opts = opts || {};
  10605. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  10606. return idx !== index;
  10607. }
  10608. /**
  10609. * @param {{range?: [number, number], start?: number}} node
  10610. * @param {number} index
  10611. */
  10612. function setLocStart(node, index) {
  10613. if (node.range) {
  10614. node.range[0] = index;
  10615. } else {
  10616. node.start = index;
  10617. }
  10618. }
  10619. /**
  10620. * @param {{range?: [number, number], end?: number}} node
  10621. * @param {number} index
  10622. */
  10623. function setLocEnd(node, index) {
  10624. if (node.range) {
  10625. node.range[1] = index;
  10626. } else {
  10627. node.end = index;
  10628. }
  10629. }
  10630. var PRECEDENCE = {};
  10631. [["|>"], ["??"], ["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(function (tier, i) {
  10632. tier.forEach(function (op) {
  10633. PRECEDENCE[op] = i;
  10634. });
  10635. });
  10636. function getPrecedence(op) {
  10637. return PRECEDENCE[op];
  10638. }
  10639. var equalityOperators = {
  10640. "==": true,
  10641. "!=": true,
  10642. "===": true,
  10643. "!==": true
  10644. };
  10645. var multiplicativeOperators = {
  10646. "*": true,
  10647. "/": true,
  10648. "%": true
  10649. };
  10650. var bitshiftOperators = {
  10651. ">>": true,
  10652. ">>>": true,
  10653. "<<": true
  10654. };
  10655. function shouldFlatten(parentOp, nodeOp) {
  10656. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  10657. return false;
  10658. } // ** is right-associative
  10659. // x ** y ** z --> x ** (y ** z)
  10660. if (parentOp === "**") {
  10661. return false;
  10662. } // x == y == z --> (x == y) == z
  10663. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  10664. return false;
  10665. } // x * y % z --> (x * y) % z
  10666. if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
  10667. return false;
  10668. } // x * y / z --> (x * y) / z
  10669. // x / y * z --> (x / y) * z
  10670. if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
  10671. return false;
  10672. } // x << y << z --> (x << y) << z
  10673. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  10674. return false;
  10675. }
  10676. return true;
  10677. }
  10678. function isBitwiseOperator(operator) {
  10679. return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
  10680. } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
  10681. // holds) `function`, `class`, or `do {}`. Will be overzealous if there's
  10682. // already necessary grouping parentheses.
  10683. function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
  10684. node = getLeftMost(node);
  10685. switch (node.type) {
  10686. case "FunctionExpression":
  10687. case "ClassExpression":
  10688. case "DoExpression":
  10689. return forbidFunctionClassAndDoExpr;
  10690. case "ObjectExpression":
  10691. return true;
  10692. case "MemberExpression":
  10693. case "OptionalMemberExpression":
  10694. return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  10695. case "TaggedTemplateExpression":
  10696. if (node.tag.type === "FunctionExpression") {
  10697. // IIFEs are always already parenthesized
  10698. return false;
  10699. }
  10700. return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
  10701. case "CallExpression":
  10702. case "OptionalCallExpression":
  10703. if (node.callee.type === "FunctionExpression") {
  10704. // IIFEs are always already parenthesized
  10705. return false;
  10706. }
  10707. return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
  10708. case "ConditionalExpression":
  10709. return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
  10710. case "UpdateExpression":
  10711. return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
  10712. case "BindExpression":
  10713. return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  10714. case "SequenceExpression":
  10715. return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
  10716. case "TSAsExpression":
  10717. return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
  10718. default:
  10719. return false;
  10720. }
  10721. }
  10722. function getLeftMost(node) {
  10723. if (node.left) {
  10724. return getLeftMost(node.left);
  10725. }
  10726. return node;
  10727. }
  10728. /**
  10729. * @param {string} value
  10730. * @param {number} tabWidth
  10731. * @param {number=} startIndex
  10732. * @returns {number}
  10733. */
  10734. function getAlignmentSize(value, tabWidth, startIndex) {
  10735. startIndex = startIndex || 0;
  10736. var size = 0;
  10737. for (var i = startIndex; i < value.length; ++i) {
  10738. if (value[i] === "\t") {
  10739. // Tabs behave in a way that they are aligned to the nearest
  10740. // multiple of tabWidth:
  10741. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  10742. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  10743. size = size + tabWidth - size % tabWidth;
  10744. } else {
  10745. size++;
  10746. }
  10747. }
  10748. return size;
  10749. }
  10750. /**
  10751. * @param {string} value
  10752. * @param {number} tabWidth
  10753. * @returns {number}
  10754. */
  10755. function getIndentSize(value, tabWidth) {
  10756. var lastNewlineIndex = value.lastIndexOf("\n");
  10757. if (lastNewlineIndex === -1) {
  10758. return 0;
  10759. }
  10760. return getAlignmentSize( // All the leading whitespaces
  10761. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0], tabWidth);
  10762. }
  10763. /**
  10764. * @typedef {'"' | "'"} Quote
  10765. */
  10766. /**
  10767. *
  10768. * @param {string} raw
  10769. * @param {Quote} preferredQuote
  10770. * @returns {Quote}
  10771. */
  10772. function getPreferredQuote(raw, preferredQuote) {
  10773. // `rawContent` is the string exactly like it appeared in the input source
  10774. // code, without its enclosing quotes.
  10775. var rawContent = raw.slice(1, -1);
  10776. /** @type {{ quote: '"', regex: RegExp }} */
  10777. var double = {
  10778. quote: '"',
  10779. regex: /"/g
  10780. };
  10781. /** @type {{ quote: "'", regex: RegExp }} */
  10782. var single = {
  10783. quote: "'",
  10784. regex: /'/g
  10785. };
  10786. var preferred = preferredQuote === "'" ? single : double;
  10787. var alternate = preferred === single ? double : single;
  10788. var result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
  10789. // the string, we might want to enclose with the alternate quote instead, to
  10790. // minimize the number of escaped quotes.
  10791. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  10792. var numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  10793. var numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  10794. result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
  10795. }
  10796. return result;
  10797. }
  10798. function printString(raw, options, isDirectiveLiteral) {
  10799. // `rawContent` is the string exactly like it appeared in the input source
  10800. // code, without its enclosing quotes.
  10801. var rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
  10802. // the quotes on a DirectiveLiteral.
  10803. var canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
  10804. /** @type {Quote} */
  10805. var enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
  10806. // change the escape sequences they use.
  10807. // See https://github.com/prettier/prettier/issues/1555
  10808. // and https://tc39.github.io/ecma262/#directive-prologue
  10809. if (isDirectiveLiteral) {
  10810. if (canChangeDirectiveQuotes) {
  10811. return enclosingQuote + rawContent + enclosingQuote;
  10812. }
  10813. return raw;
  10814. } // It might sound unnecessary to use `makeString` even if the string already
  10815. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  10816. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  10817. // sure that we consistently output the minimum amount of escaped quotes.
  10818. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.embeddedInHtml));
  10819. }
  10820. /**
  10821. * @param {string} rawContent
  10822. * @param {Quote} enclosingQuote
  10823. * @param {boolean=} unescapeUnnecessaryEscapes
  10824. * @returns {string}
  10825. */
  10826. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  10827. var otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  10828. var regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
  10829. // enclose `rawContent` with `enclosingQuote`.
  10830. var newContent = rawContent.replace(regex, function (match, escaped, quote) {
  10831. // If we matched an escape, and the escaped character is a quote of the
  10832. // other type than we intend to enclose the string with, there's no need for
  10833. // it to be escaped, so return it _without_ the backslash.
  10834. if (escaped === otherQuote) {
  10835. return escaped;
  10836. } // If we matched an unescaped quote and it is of the _same_ type as we
  10837. // intend to enclose the string with, it must be escaped, so return it with
  10838. // a backslash.
  10839. if (quote === enclosingQuote) {
  10840. return "\\" + quote;
  10841. }
  10842. if (quote) {
  10843. return quote;
  10844. } // Unescape any unnecessarily escaped character.
  10845. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  10846. return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) ? escaped : "\\" + escaped;
  10847. });
  10848. return enclosingQuote + newContent + enclosingQuote;
  10849. }
  10850. function printNumber(rawNumber) {
  10851. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  10852. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  10853. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  10854. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  10855. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  10856. .replace(/\.(?=e|$)/, "");
  10857. }
  10858. /**
  10859. * @param {string} str
  10860. * @param {string} target
  10861. * @returns {number}
  10862. */
  10863. function getMaxContinuousCount(str, target) {
  10864. var results = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
  10865. if (results === null) {
  10866. return 0;
  10867. }
  10868. return results.reduce(function (maxCount, result) {
  10869. return Math.max(maxCount, result.length / target.length);
  10870. }, 0);
  10871. }
  10872. function getMinNotPresentContinuousCount(str, target) {
  10873. var matches = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
  10874. if (matches === null) {
  10875. return 0;
  10876. }
  10877. var countPresent = new Map();
  10878. var max = 0;
  10879. var _iteratorNormalCompletion = true;
  10880. var _didIteratorError = false;
  10881. var _iteratorError = undefined;
  10882. try {
  10883. for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  10884. var match = _step.value;
  10885. var count = match.length / target.length;
  10886. countPresent.set(count, true);
  10887. if (count > max) {
  10888. max = count;
  10889. }
  10890. }
  10891. } catch (err) {
  10892. _didIteratorError = true;
  10893. _iteratorError = err;
  10894. } finally {
  10895. try {
  10896. if (!_iteratorNormalCompletion && _iterator.return != null) {
  10897. _iterator.return();
  10898. }
  10899. } finally {
  10900. if (_didIteratorError) {
  10901. throw _iteratorError;
  10902. }
  10903. }
  10904. }
  10905. for (var i = 1; i < max; i++) {
  10906. if (!countPresent.get(i)) {
  10907. return i;
  10908. }
  10909. }
  10910. return max + 1;
  10911. }
  10912. /**
  10913. * @param {string} text
  10914. * @returns {number}
  10915. */
  10916. function getStringWidth(text) {
  10917. if (!text) {
  10918. return 0;
  10919. } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
  10920. if (!notAsciiRegex.test(text)) {
  10921. return text.length;
  10922. }
  10923. return stringWidth_1(text);
  10924. }
  10925. function hasIgnoreComment(path) {
  10926. var node = path.getValue();
  10927. return hasNodeIgnoreComment(node);
  10928. }
  10929. function hasNodeIgnoreComment(node) {
  10930. return node && node.comments && node.comments.length > 0 && node.comments.some(function (comment) {
  10931. return comment.value.trim() === "prettier-ignore";
  10932. });
  10933. }
  10934. function matchAncestorTypes(path, types, index) {
  10935. index = index || 0;
  10936. types = types.slice();
  10937. while (types.length) {
  10938. var parent = path.getParentNode(index);
  10939. var type = types.shift();
  10940. if (!parent || parent.type !== type) {
  10941. return false;
  10942. }
  10943. index++;
  10944. }
  10945. return true;
  10946. }
  10947. function addCommentHelper(node, comment) {
  10948. var comments = node.comments || (node.comments = []);
  10949. comments.push(comment);
  10950. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  10951. // We already "print" it via the raw text, we don't need to re-print it as a
  10952. // comment
  10953. if (node.type === "JSXText") {
  10954. comment.printed = true;
  10955. }
  10956. }
  10957. function addLeadingComment(node, comment) {
  10958. comment.leading = true;
  10959. comment.trailing = false;
  10960. addCommentHelper(node, comment);
  10961. }
  10962. function addDanglingComment(node, comment) {
  10963. comment.leading = false;
  10964. comment.trailing = false;
  10965. addCommentHelper(node, comment);
  10966. }
  10967. function addTrailingComment(node, comment) {
  10968. comment.leading = false;
  10969. comment.trailing = true;
  10970. addCommentHelper(node, comment);
  10971. }
  10972. function isWithinParentArrayProperty(path, propertyName) {
  10973. var node = path.getValue();
  10974. var parent = path.getParentNode();
  10975. if (parent == null) {
  10976. return false;
  10977. }
  10978. if (!Array.isArray(parent[propertyName])) {
  10979. return false;
  10980. }
  10981. var key = path.getName();
  10982. return parent[propertyName][key] === node;
  10983. }
  10984. function replaceEndOfLineWith(text, replacement) {
  10985. var parts = [];
  10986. var _iteratorNormalCompletion2 = true;
  10987. var _didIteratorError2 = false;
  10988. var _iteratorError2 = undefined;
  10989. try {
  10990. for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  10991. var part = _step2.value;
  10992. if (parts.length !== 0) {
  10993. parts.push(replacement);
  10994. }
  10995. parts.push(part);
  10996. }
  10997. } catch (err) {
  10998. _didIteratorError2 = true;
  10999. _iteratorError2 = err;
  11000. } finally {
  11001. try {
  11002. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  11003. _iterator2.return();
  11004. }
  11005. } finally {
  11006. if (_didIteratorError2) {
  11007. throw _iteratorError2;
  11008. }
  11009. }
  11010. }
  11011. return parts;
  11012. }
  11013. var util = {
  11014. replaceEndOfLineWith: replaceEndOfLineWith,
  11015. getStringWidth: getStringWidth,
  11016. getMaxContinuousCount: getMaxContinuousCount,
  11017. getMinNotPresentContinuousCount: getMinNotPresentContinuousCount,
  11018. getPrecedence: getPrecedence,
  11019. shouldFlatten: shouldFlatten,
  11020. isBitwiseOperator: isBitwiseOperator,
  11021. isExportDeclaration: isExportDeclaration,
  11022. getParentExportDeclaration: getParentExportDeclaration,
  11023. getPenultimate: getPenultimate,
  11024. getLast: getLast,
  11025. getNextNonSpaceNonCommentCharacterIndexWithStartIndex: getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
  11026. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex,
  11027. getNextNonSpaceNonCommentCharacter: getNextNonSpaceNonCommentCharacter,
  11028. skip: skip,
  11029. skipWhitespace: skipWhitespace,
  11030. skipSpaces: skipSpaces,
  11031. skipToLineEnd: skipToLineEnd,
  11032. skipEverythingButNewLine: skipEverythingButNewLine,
  11033. skipInlineComment: skipInlineComment,
  11034. skipTrailingComment: skipTrailingComment,
  11035. skipNewline: skipNewline,
  11036. isNextLineEmptyAfterIndex: isNextLineEmptyAfterIndex,
  11037. isNextLineEmpty: isNextLineEmpty,
  11038. isPreviousLineEmpty: isPreviousLineEmpty,
  11039. hasNewline: hasNewline,
  11040. hasNewlineInRange: hasNewlineInRange,
  11041. hasSpaces: hasSpaces,
  11042. setLocStart: setLocStart,
  11043. setLocEnd: setLocEnd,
  11044. startsWithNoLookaheadToken: startsWithNoLookaheadToken,
  11045. getAlignmentSize: getAlignmentSize,
  11046. getIndentSize: getIndentSize,
  11047. getPreferredQuote: getPreferredQuote,
  11048. printString: printString,
  11049. printNumber: printNumber,
  11050. hasIgnoreComment: hasIgnoreComment,
  11051. hasNodeIgnoreComment: hasNodeIgnoreComment,
  11052. makeString: makeString,
  11053. matchAncestorTypes: matchAncestorTypes,
  11054. addLeadingComment: addLeadingComment,
  11055. addDanglingComment: addDanglingComment,
  11056. addTrailingComment: addTrailingComment,
  11057. isWithinParentArrayProperty: isWithinParentArrayProperty
  11058. };
  11059. function guessEndOfLine(text) {
  11060. var index = text.indexOf("\r");
  11061. if (index >= 0) {
  11062. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  11063. }
  11064. return "lf";
  11065. }
  11066. function convertEndOfLineToChars(value) {
  11067. switch (value) {
  11068. case "cr":
  11069. return "\r";
  11070. case "crlf":
  11071. return "\r\n";
  11072. default:
  11073. return "\n";
  11074. }
  11075. }
  11076. var endOfLine = {
  11077. guessEndOfLine: guessEndOfLine,
  11078. convertEndOfLineToChars: convertEndOfLineToChars
  11079. };
  11080. var getStringWidth$1 = util.getStringWidth;
  11081. var convertEndOfLineToChars$1 = endOfLine.convertEndOfLineToChars;
  11082. var concat$1 = docBuilders.concat,
  11083. fill$1 = docBuilders.fill,
  11084. cursor$1 = docBuilders.cursor;
  11085. /** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
  11086. var groupModeMap;
  11087. var MODE_BREAK = 1;
  11088. var MODE_FLAT = 2;
  11089. function rootIndent() {
  11090. return {
  11091. value: "",
  11092. length: 0,
  11093. queue: []
  11094. };
  11095. }
  11096. function makeIndent(ind, options) {
  11097. return generateInd(ind, {
  11098. type: "indent"
  11099. }, options);
  11100. }
  11101. function makeAlign(ind, n, options) {
  11102. return n === -Infinity ? ind.root || rootIndent() : n < 0 ? generateInd(ind, {
  11103. type: "dedent"
  11104. }, options) : !n ? ind : n.type === "root" ? Object.assign({}, ind, {
  11105. root: ind
  11106. }) : typeof n === "string" ? generateInd(ind, {
  11107. type: "stringAlign",
  11108. n: n
  11109. }, options) : generateInd(ind, {
  11110. type: "numberAlign",
  11111. n: n
  11112. }, options);
  11113. }
  11114. function generateInd(ind, newPart, options) {
  11115. var queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  11116. var value = "";
  11117. var length = 0;
  11118. var lastTabs = 0;
  11119. var lastSpaces = 0;
  11120. var _iteratorNormalCompletion = true;
  11121. var _didIteratorError = false;
  11122. var _iteratorError = undefined;
  11123. try {
  11124. for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  11125. var part = _step.value;
  11126. switch (part.type) {
  11127. case "indent":
  11128. flush();
  11129. if (options.useTabs) {
  11130. addTabs(1);
  11131. } else {
  11132. addSpaces(options.tabWidth);
  11133. }
  11134. break;
  11135. case "stringAlign":
  11136. flush();
  11137. value += part.n;
  11138. length += part.n.length;
  11139. break;
  11140. case "numberAlign":
  11141. lastTabs += 1;
  11142. lastSpaces += part.n;
  11143. break;
  11144. /* istanbul ignore next */
  11145. default:
  11146. throw new Error("Unexpected type '".concat(part.type, "'"));
  11147. }
  11148. }
  11149. } catch (err) {
  11150. _didIteratorError = true;
  11151. _iteratorError = err;
  11152. } finally {
  11153. try {
  11154. if (!_iteratorNormalCompletion && _iterator.return != null) {
  11155. _iterator.return();
  11156. }
  11157. } finally {
  11158. if (_didIteratorError) {
  11159. throw _iteratorError;
  11160. }
  11161. }
  11162. }
  11163. flushSpaces();
  11164. return Object.assign({}, ind, {
  11165. value: value,
  11166. length: length,
  11167. queue: queue
  11168. });
  11169. function addTabs(count) {
  11170. value += "\t".repeat(count);
  11171. length += options.tabWidth * count;
  11172. }
  11173. function addSpaces(count) {
  11174. value += " ".repeat(count);
  11175. length += count;
  11176. }
  11177. function flush() {
  11178. if (options.useTabs) {
  11179. flushTabs();
  11180. } else {
  11181. flushSpaces();
  11182. }
  11183. }
  11184. function flushTabs() {
  11185. if (lastTabs > 0) {
  11186. addTabs(lastTabs);
  11187. }
  11188. resetLast();
  11189. }
  11190. function flushSpaces() {
  11191. if (lastSpaces > 0) {
  11192. addSpaces(lastSpaces);
  11193. }
  11194. resetLast();
  11195. }
  11196. function resetLast() {
  11197. lastTabs = 0;
  11198. lastSpaces = 0;
  11199. }
  11200. }
  11201. function trim$1(out) {
  11202. if (out.length === 0) {
  11203. return 0;
  11204. }
  11205. var trimCount = 0; // Trim whitespace at the end of line
  11206. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[ \t]*$/)) {
  11207. trimCount += out.pop().length;
  11208. }
  11209. if (out.length && typeof out[out.length - 1] === "string") {
  11210. var trimmed = out[out.length - 1].replace(/[ \t]*$/, "");
  11211. trimCount += out[out.length - 1].length - trimmed.length;
  11212. out[out.length - 1] = trimmed;
  11213. }
  11214. return trimCount;
  11215. }
  11216. function fits(next, restCommands, width, options, mustBeFlat) {
  11217. var restIdx = restCommands.length;
  11218. var cmds = [next]; // `out` is only used for width counting because `trim` requires to look
  11219. // backwards for space characters.
  11220. var out = [];
  11221. while (width >= 0) {
  11222. if (cmds.length === 0) {
  11223. if (restIdx === 0) {
  11224. return true;
  11225. }
  11226. cmds.push(restCommands[restIdx - 1]);
  11227. restIdx--;
  11228. continue;
  11229. }
  11230. var x = cmds.pop();
  11231. var ind = x[0];
  11232. var mode = x[1];
  11233. var doc = x[2];
  11234. if (typeof doc === "string") {
  11235. out.push(doc);
  11236. width -= getStringWidth$1(doc);
  11237. } else {
  11238. switch (doc.type) {
  11239. case "concat":
  11240. for (var i = doc.parts.length - 1; i >= 0; i--) {
  11241. cmds.push([ind, mode, doc.parts[i]]);
  11242. }
  11243. break;
  11244. case "indent":
  11245. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  11246. break;
  11247. case "align":
  11248. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  11249. break;
  11250. case "trim":
  11251. width += trim$1(out);
  11252. break;
  11253. case "group":
  11254. if (mustBeFlat && doc.break) {
  11255. return false;
  11256. }
  11257. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  11258. if (doc.id) {
  11259. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  11260. }
  11261. break;
  11262. case "fill":
  11263. for (var _i = doc.parts.length - 1; _i >= 0; _i--) {
  11264. cmds.push([ind, mode, doc.parts[_i]]);
  11265. }
  11266. break;
  11267. case "if-break":
  11268. {
  11269. var groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  11270. if (groupMode === MODE_BREAK) {
  11271. if (doc.breakContents) {
  11272. cmds.push([ind, mode, doc.breakContents]);
  11273. }
  11274. }
  11275. if (groupMode === MODE_FLAT) {
  11276. if (doc.flatContents) {
  11277. cmds.push([ind, mode, doc.flatContents]);
  11278. }
  11279. }
  11280. break;
  11281. }
  11282. case "line":
  11283. switch (mode) {
  11284. // fallthrough
  11285. case MODE_FLAT:
  11286. if (!doc.hard) {
  11287. if (!doc.soft) {
  11288. out.push(" ");
  11289. width -= 1;
  11290. }
  11291. break;
  11292. }
  11293. return true;
  11294. case MODE_BREAK:
  11295. return true;
  11296. }
  11297. break;
  11298. }
  11299. }
  11300. }
  11301. return false;
  11302. }
  11303. function printDocToString(doc, options) {
  11304. groupModeMap = {};
  11305. var width = options.printWidth;
  11306. var newLine = convertEndOfLineToChars$1(options.endOfLine);
  11307. var pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  11308. // while loop which is much faster. The while loop below adds new
  11309. // cmds to the array instead of recursively calling `print`.
  11310. var cmds = [[rootIndent(), MODE_BREAK, doc]];
  11311. var out = [];
  11312. var shouldRemeasure = false;
  11313. var lineSuffix = [];
  11314. while (cmds.length !== 0) {
  11315. var x = cmds.pop();
  11316. var ind = x[0];
  11317. var mode = x[1];
  11318. var _doc = x[2];
  11319. if (typeof _doc === "string") {
  11320. out.push(_doc);
  11321. pos += getStringWidth$1(_doc);
  11322. } else {
  11323. switch (_doc.type) {
  11324. case "cursor":
  11325. out.push(cursor$1.placeholder);
  11326. break;
  11327. case "concat":
  11328. for (var i = _doc.parts.length - 1; i >= 0; i--) {
  11329. cmds.push([ind, mode, _doc.parts[i]]);
  11330. }
  11331. break;
  11332. case "indent":
  11333. cmds.push([makeIndent(ind, options), mode, _doc.contents]);
  11334. break;
  11335. case "align":
  11336. cmds.push([makeAlign(ind, _doc.n, options), mode, _doc.contents]);
  11337. break;
  11338. case "trim":
  11339. pos -= trim$1(out);
  11340. break;
  11341. case "group":
  11342. switch (mode) {
  11343. case MODE_FLAT:
  11344. if (!shouldRemeasure) {
  11345. cmds.push([ind, _doc.break ? MODE_BREAK : MODE_FLAT, _doc.contents]);
  11346. break;
  11347. }
  11348. // fallthrough
  11349. case MODE_BREAK:
  11350. {
  11351. shouldRemeasure = false;
  11352. var next = [ind, MODE_FLAT, _doc.contents];
  11353. var rem = width - pos;
  11354. if (!_doc.break && fits(next, cmds, rem, options)) {
  11355. cmds.push(next);
  11356. } else {
  11357. // Expanded states are a rare case where a document
  11358. // can manually provide multiple representations of
  11359. // itself. It provides an array of documents
  11360. // going from the least expanded (most flattened)
  11361. // representation first to the most expanded. If a
  11362. // group has these, we need to manually go through
  11363. // these states and find the first one that fits.
  11364. if (_doc.expandedStates) {
  11365. var mostExpanded = _doc.expandedStates[_doc.expandedStates.length - 1];
  11366. if (_doc.break) {
  11367. cmds.push([ind, MODE_BREAK, mostExpanded]);
  11368. break;
  11369. } else {
  11370. for (var _i2 = 1; _i2 < _doc.expandedStates.length + 1; _i2++) {
  11371. if (_i2 >= _doc.expandedStates.length) {
  11372. cmds.push([ind, MODE_BREAK, mostExpanded]);
  11373. break;
  11374. } else {
  11375. var state = _doc.expandedStates[_i2];
  11376. var cmd = [ind, MODE_FLAT, state];
  11377. if (fits(cmd, cmds, rem, options)) {
  11378. cmds.push(cmd);
  11379. break;
  11380. }
  11381. }
  11382. }
  11383. }
  11384. } else {
  11385. cmds.push([ind, MODE_BREAK, _doc.contents]);
  11386. }
  11387. }
  11388. break;
  11389. }
  11390. }
  11391. if (_doc.id) {
  11392. groupModeMap[_doc.id] = cmds[cmds.length - 1][1];
  11393. }
  11394. break;
  11395. // Fills each line with as much code as possible before moving to a new
  11396. // line with the same indentation.
  11397. //
  11398. // Expects doc.parts to be an array of alternating content and
  11399. // whitespace. The whitespace contains the linebreaks.
  11400. //
  11401. // For example:
  11402. // ["I", line, "love", line, "monkeys"]
  11403. // or
  11404. // [{ type: group, ... }, softline, { type: group, ... }]
  11405. //
  11406. // It uses this parts structure to handle three main layout cases:
  11407. // * The first two content items fit on the same line without
  11408. // breaking
  11409. // -> output the first content item and the whitespace "flat".
  11410. // * Only the first content item fits on the line without breaking
  11411. // -> output the first content item "flat" and the whitespace with
  11412. // "break".
  11413. // * Neither content item fits on the line without breaking
  11414. // -> output the first content item and the whitespace with "break".
  11415. case "fill":
  11416. {
  11417. var _rem = width - pos;
  11418. var parts = _doc.parts;
  11419. if (parts.length === 0) {
  11420. break;
  11421. }
  11422. var content = parts[0];
  11423. var contentFlatCmd = [ind, MODE_FLAT, content];
  11424. var contentBreakCmd = [ind, MODE_BREAK, content];
  11425. var contentFits = fits(contentFlatCmd, [], _rem, options, true);
  11426. if (parts.length === 1) {
  11427. if (contentFits) {
  11428. cmds.push(contentFlatCmd);
  11429. } else {
  11430. cmds.push(contentBreakCmd);
  11431. }
  11432. break;
  11433. }
  11434. var whitespace = parts[1];
  11435. var whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  11436. var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  11437. if (parts.length === 2) {
  11438. if (contentFits) {
  11439. cmds.push(whitespaceFlatCmd);
  11440. cmds.push(contentFlatCmd);
  11441. } else {
  11442. cmds.push(whitespaceBreakCmd);
  11443. cmds.push(contentBreakCmd);
  11444. }
  11445. break;
  11446. } // At this point we've handled the first pair (context, separator)
  11447. // and will create a new fill doc for the rest of the content.
  11448. // Ideally we wouldn't mutate the array here but coping all the
  11449. // elements to a new array would make this algorithm quadratic,
  11450. // which is unusable for large arrays (e.g. large texts in JSX).
  11451. parts.splice(0, 2);
  11452. var remainingCmd = [ind, mode, fill$1(parts)];
  11453. var secondContent = parts[0];
  11454. var firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$1([content, whitespace, secondContent])];
  11455. var firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], _rem, options, true);
  11456. if (firstAndSecondContentFits) {
  11457. cmds.push(remainingCmd);
  11458. cmds.push(whitespaceFlatCmd);
  11459. cmds.push(contentFlatCmd);
  11460. } else if (contentFits) {
  11461. cmds.push(remainingCmd);
  11462. cmds.push(whitespaceBreakCmd);
  11463. cmds.push(contentFlatCmd);
  11464. } else {
  11465. cmds.push(remainingCmd);
  11466. cmds.push(whitespaceBreakCmd);
  11467. cmds.push(contentBreakCmd);
  11468. }
  11469. break;
  11470. }
  11471. case "if-break":
  11472. {
  11473. var groupMode = _doc.groupId ? groupModeMap[_doc.groupId] : mode;
  11474. if (groupMode === MODE_BREAK) {
  11475. if (_doc.breakContents) {
  11476. cmds.push([ind, mode, _doc.breakContents]);
  11477. }
  11478. }
  11479. if (groupMode === MODE_FLAT) {
  11480. if (_doc.flatContents) {
  11481. cmds.push([ind, mode, _doc.flatContents]);
  11482. }
  11483. }
  11484. break;
  11485. }
  11486. case "line-suffix":
  11487. lineSuffix.push([ind, mode, _doc.contents]);
  11488. break;
  11489. case "line-suffix-boundary":
  11490. if (lineSuffix.length > 0) {
  11491. cmds.push([ind, mode, {
  11492. type: "line",
  11493. hard: true
  11494. }]);
  11495. }
  11496. break;
  11497. case "line":
  11498. switch (mode) {
  11499. case MODE_FLAT:
  11500. if (!_doc.hard) {
  11501. if (!_doc.soft) {
  11502. out.push(" ");
  11503. pos += 1;
  11504. }
  11505. break;
  11506. } else {
  11507. // This line was forced into the output even if we
  11508. // were in flattened mode, so we need to tell the next
  11509. // group that no matter what, it needs to remeasure
  11510. // because the previous measurement didn't accurately
  11511. // capture the entire expression (this is necessary
  11512. // for nested groups)
  11513. shouldRemeasure = true;
  11514. }
  11515. // fallthrough
  11516. case MODE_BREAK:
  11517. if (lineSuffix.length) {
  11518. cmds.push([ind, mode, _doc]);
  11519. [].push.apply(cmds, lineSuffix.reverse());
  11520. lineSuffix = [];
  11521. break;
  11522. }
  11523. if (_doc.literal) {
  11524. if (ind.root) {
  11525. out.push(newLine, ind.root.value);
  11526. pos = ind.root.length;
  11527. } else {
  11528. out.push(newLine);
  11529. pos = 0;
  11530. }
  11531. } else {
  11532. pos -= trim$1(out);
  11533. out.push(newLine + ind.value);
  11534. pos = ind.length;
  11535. }
  11536. break;
  11537. }
  11538. break;
  11539. }
  11540. }
  11541. }
  11542. var cursorPlaceholderIndex = out.indexOf(cursor$1.placeholder);
  11543. if (cursorPlaceholderIndex !== -1) {
  11544. var otherCursorPlaceholderIndex = out.indexOf(cursor$1.placeholder, cursorPlaceholderIndex + 1);
  11545. var beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  11546. var aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  11547. var afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  11548. return {
  11549. formatted: beforeCursor + aroundCursor + afterCursor,
  11550. cursorNodeStart: beforeCursor.length,
  11551. cursorNodeText: aroundCursor
  11552. };
  11553. }
  11554. return {
  11555. formatted: out.join("")
  11556. };
  11557. }
  11558. var docPrinter = {
  11559. printDocToString: printDocToString
  11560. };
  11561. var traverseDocOnExitStackMarker = {};
  11562. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  11563. var docsStack = [doc];
  11564. while (docsStack.length !== 0) {
  11565. var _doc = docsStack.pop();
  11566. if (_doc === traverseDocOnExitStackMarker) {
  11567. onExit(docsStack.pop());
  11568. continue;
  11569. }
  11570. var shouldRecurse = true;
  11571. if (onEnter) {
  11572. if (onEnter(_doc) === false) {
  11573. shouldRecurse = false;
  11574. }
  11575. }
  11576. if (onExit) {
  11577. docsStack.push(_doc);
  11578. docsStack.push(traverseDocOnExitStackMarker);
  11579. }
  11580. if (shouldRecurse) {
  11581. // When there are multiple parts to process,
  11582. // the parts need to be pushed onto the stack in reverse order,
  11583. // so that they are processed in the original order
  11584. // when the stack is popped.
  11585. if (_doc.type === "concat" || _doc.type === "fill") {
  11586. for (var ic = _doc.parts.length, i = ic - 1; i >= 0; --i) {
  11587. docsStack.push(_doc.parts[i]);
  11588. }
  11589. } else if (_doc.type === "if-break") {
  11590. if (_doc.flatContents) {
  11591. docsStack.push(_doc.flatContents);
  11592. }
  11593. if (_doc.breakContents) {
  11594. docsStack.push(_doc.breakContents);
  11595. }
  11596. } else if (_doc.type === "group" && _doc.expandedStates) {
  11597. if (shouldTraverseConditionalGroups) {
  11598. for (var _ic = _doc.expandedStates.length, _i = _ic - 1; _i >= 0; --_i) {
  11599. docsStack.push(_doc.expandedStates[_i]);
  11600. }
  11601. } else {
  11602. docsStack.push(_doc.contents);
  11603. }
  11604. } else if (_doc.contents) {
  11605. docsStack.push(_doc.contents);
  11606. }
  11607. }
  11608. }
  11609. }
  11610. function mapDoc(doc, cb) {
  11611. if (doc.type === "concat" || doc.type === "fill") {
  11612. var parts = doc.parts.map(function (part) {
  11613. return mapDoc(part, cb);
  11614. });
  11615. return cb(Object.assign({}, doc, {
  11616. parts: parts
  11617. }));
  11618. } else if (doc.type === "if-break") {
  11619. var breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  11620. var flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  11621. return cb(Object.assign({}, doc, {
  11622. breakContents: breakContents,
  11623. flatContents: flatContents
  11624. }));
  11625. } else if (doc.contents) {
  11626. var contents = mapDoc(doc.contents, cb);
  11627. return cb(Object.assign({}, doc, {
  11628. contents: contents
  11629. }));
  11630. }
  11631. return cb(doc);
  11632. }
  11633. function findInDoc(doc, fn, defaultValue) {
  11634. var result = defaultValue;
  11635. var hasStopped = false;
  11636. function findInDocOnEnterFn(doc) {
  11637. var maybeResult = fn(doc);
  11638. if (maybeResult !== undefined) {
  11639. hasStopped = true;
  11640. result = maybeResult;
  11641. }
  11642. if (hasStopped) {
  11643. return false;
  11644. }
  11645. }
  11646. traverseDoc(doc, findInDocOnEnterFn);
  11647. return result;
  11648. }
  11649. function isEmpty(n) {
  11650. return typeof n === "string" && n.length === 0;
  11651. }
  11652. function isLineNextFn(doc) {
  11653. if (typeof doc === "string") {
  11654. return false;
  11655. }
  11656. if (doc.type === "line") {
  11657. return true;
  11658. }
  11659. }
  11660. function isLineNext(doc) {
  11661. return findInDoc(doc, isLineNextFn, false);
  11662. }
  11663. function willBreakFn(doc) {
  11664. if (doc.type === "group" && doc.break) {
  11665. return true;
  11666. }
  11667. if (doc.type === "line" && doc.hard) {
  11668. return true;
  11669. }
  11670. if (doc.type === "break-parent") {
  11671. return true;
  11672. }
  11673. }
  11674. function willBreak(doc) {
  11675. return findInDoc(doc, willBreakFn, false);
  11676. }
  11677. function breakParentGroup(groupStack) {
  11678. if (groupStack.length > 0) {
  11679. var parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  11680. // the user is expected to manually handle what breaks.
  11681. if (!parentGroup.expandedStates) {
  11682. parentGroup.break = true;
  11683. }
  11684. }
  11685. return null;
  11686. }
  11687. function propagateBreaks(doc) {
  11688. var alreadyVisitedSet = new Set();
  11689. var groupStack = [];
  11690. function propagateBreaksOnEnterFn(doc) {
  11691. if (doc.type === "break-parent") {
  11692. breakParentGroup(groupStack);
  11693. }
  11694. if (doc.type === "group") {
  11695. groupStack.push(doc);
  11696. if (alreadyVisitedSet.has(doc)) {
  11697. return false;
  11698. }
  11699. alreadyVisitedSet.add(doc);
  11700. }
  11701. }
  11702. function propagateBreaksOnExitFn(doc) {
  11703. if (doc.type === "group") {
  11704. var group = groupStack.pop();
  11705. if (group.break) {
  11706. breakParentGroup(groupStack);
  11707. }
  11708. }
  11709. }
  11710. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
  11711. /* shouldTraverseConditionalGroups */
  11712. true);
  11713. }
  11714. function removeLinesFn(doc) {
  11715. // Force this doc into flat mode by statically converting all
  11716. // lines into spaces (or soft lines into nothing). Hard lines
  11717. // should still output because there's too great of a chance
  11718. // of breaking existing assumptions otherwise.
  11719. if (doc.type === "line" && !doc.hard) {
  11720. return doc.soft ? "" : " ";
  11721. } else if (doc.type === "if-break") {
  11722. return doc.flatContents || "";
  11723. }
  11724. return doc;
  11725. }
  11726. function removeLines(doc) {
  11727. return mapDoc(doc, removeLinesFn);
  11728. }
  11729. function stripTrailingHardline(doc) {
  11730. // HACK remove ending hardline, original PR: #1984
  11731. if (doc.type === "concat" && doc.parts.length !== 0) {
  11732. var lastPart = doc.parts[doc.parts.length - 1];
  11733. if (lastPart.type === "concat") {
  11734. if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
  11735. return {
  11736. type: "concat",
  11737. parts: doc.parts.slice(0, -1)
  11738. };
  11739. }
  11740. return {
  11741. type: "concat",
  11742. parts: doc.parts.slice(0, -1).concat(stripTrailingHardline(lastPart))
  11743. };
  11744. }
  11745. }
  11746. return doc;
  11747. }
  11748. var docUtils = {
  11749. isEmpty: isEmpty,
  11750. willBreak: willBreak,
  11751. isLineNext: isLineNext,
  11752. traverseDoc: traverseDoc,
  11753. findInDoc: findInDoc,
  11754. mapDoc: mapDoc,
  11755. propagateBreaks: propagateBreaks,
  11756. removeLines: removeLines,
  11757. stripTrailingHardline: stripTrailingHardline
  11758. };
  11759. function flattenDoc(doc) {
  11760. if (doc.type === "concat") {
  11761. var res = [];
  11762. for (var i = 0; i < doc.parts.length; ++i) {
  11763. var doc2 = doc.parts[i];
  11764. if (typeof doc2 !== "string" && doc2.type === "concat") {
  11765. [].push.apply(res, flattenDoc(doc2).parts);
  11766. } else {
  11767. var flattened = flattenDoc(doc2);
  11768. if (flattened !== "") {
  11769. res.push(flattened);
  11770. }
  11771. }
  11772. }
  11773. return Object.assign({}, doc, {
  11774. parts: res
  11775. });
  11776. } else if (doc.type === "if-break") {
  11777. return Object.assign({}, doc, {
  11778. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  11779. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  11780. });
  11781. } else if (doc.type === "group") {
  11782. return Object.assign({}, doc, {
  11783. contents: flattenDoc(doc.contents),
  11784. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  11785. });
  11786. } else if (doc.contents) {
  11787. return Object.assign({}, doc, {
  11788. contents: flattenDoc(doc.contents)
  11789. });
  11790. }
  11791. return doc;
  11792. }
  11793. function printDoc(doc) {
  11794. if (typeof doc === "string") {
  11795. return JSON.stringify(doc);
  11796. }
  11797. if (doc.type === "line") {
  11798. if (doc.literal) {
  11799. return "literalline";
  11800. }
  11801. if (doc.hard) {
  11802. return "hardline";
  11803. }
  11804. if (doc.soft) {
  11805. return "softline";
  11806. }
  11807. return "line";
  11808. }
  11809. if (doc.type === "break-parent") {
  11810. return "breakParent";
  11811. }
  11812. if (doc.type === "trim") {
  11813. return "trim";
  11814. }
  11815. if (doc.type === "concat") {
  11816. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  11817. }
  11818. if (doc.type === "indent") {
  11819. return "indent(" + printDoc(doc.contents) + ")";
  11820. }
  11821. if (doc.type === "align") {
  11822. return doc.n === -Infinity ? "dedentToRoot(" + printDoc(doc.contents) + ")" : doc.n < 0 ? "dedent(" + printDoc(doc.contents) + ")" : doc.n.type === "root" ? "markAsRoot(" + printDoc(doc.contents) + ")" : "align(" + JSON.stringify(doc.n) + ", " + printDoc(doc.contents) + ")";
  11823. }
  11824. if (doc.type === "if-break") {
  11825. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  11826. }
  11827. if (doc.type === "group") {
  11828. if (doc.expandedStates) {
  11829. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  11830. }
  11831. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  11832. }
  11833. if (doc.type === "fill") {
  11834. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  11835. }
  11836. if (doc.type === "line-suffix") {
  11837. return "lineSuffix(" + printDoc(doc.contents) + ")";
  11838. }
  11839. if (doc.type === "line-suffix-boundary") {
  11840. return "lineSuffixBoundary";
  11841. }
  11842. throw new Error("Unknown doc type " + doc.type);
  11843. }
  11844. var docDebug = {
  11845. printDocToDebug: function printDocToDebug(doc) {
  11846. return printDoc(flattenDoc(doc));
  11847. }
  11848. };
  11849. var doc = {
  11850. builders: docBuilders,
  11851. printer: docPrinter,
  11852. utils: docUtils,
  11853. debug: docDebug
  11854. };
  11855. var mapDoc$1 = doc.utils.mapDoc;
  11856. function isNextLineEmpty$1(text, node, options) {
  11857. return util.isNextLineEmpty(text, node, options.locEnd);
  11858. }
  11859. function isPreviousLineEmpty$1(text, node, options) {
  11860. return util.isPreviousLineEmpty(text, node, options.locStart);
  11861. }
  11862. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  11863. return util.getNextNonSpaceNonCommentCharacterIndex(text, node, options.locEnd);
  11864. }
  11865. var utilShared = {
  11866. getMaxContinuousCount: util.getMaxContinuousCount,
  11867. getStringWidth: util.getStringWidth,
  11868. getAlignmentSize: util.getAlignmentSize,
  11869. getIndentSize: util.getIndentSize,
  11870. skip: util.skip,
  11871. skipWhitespace: util.skipWhitespace,
  11872. skipSpaces: util.skipSpaces,
  11873. skipNewline: util.skipNewline,
  11874. skipToLineEnd: util.skipToLineEnd,
  11875. skipEverythingButNewLine: util.skipEverythingButNewLine,
  11876. skipInlineComment: util.skipInlineComment,
  11877. skipTrailingComment: util.skipTrailingComment,
  11878. hasNewline: util.hasNewline,
  11879. hasNewlineInRange: util.hasNewlineInRange,
  11880. hasSpaces: util.hasSpaces,
  11881. isNextLineEmpty: isNextLineEmpty$1,
  11882. isNextLineEmptyAfterIndex: util.isNextLineEmptyAfterIndex,
  11883. isPreviousLineEmpty: isPreviousLineEmpty$1,
  11884. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  11885. mapDoc: mapDoc$1,
  11886. // TODO: remove in 2.0, we already exposed it in docUtils
  11887. makeString: util.makeString,
  11888. addLeadingComment: util.addLeadingComment,
  11889. addDanglingComment: util.addDanglingComment,
  11890. addTrailingComment: util.addTrailingComment
  11891. };
  11892. var _require$$0$builders = doc.builders,
  11893. concat$2 = _require$$0$builders.concat,
  11894. hardline$1 = _require$$0$builders.hardline,
  11895. breakParent$1 = _require$$0$builders.breakParent,
  11896. indent$1 = _require$$0$builders.indent,
  11897. lineSuffix$1 = _require$$0$builders.lineSuffix,
  11898. join$1 = _require$$0$builders.join,
  11899. cursor$2 = _require$$0$builders.cursor;
  11900. var hasNewline$1 = util.hasNewline,
  11901. skipNewline$1 = util.skipNewline,
  11902. isPreviousLineEmpty$2 = util.isPreviousLineEmpty;
  11903. var addLeadingComment$1 = utilShared.addLeadingComment,
  11904. addDanglingComment$1 = utilShared.addDanglingComment,
  11905. addTrailingComment$1 = utilShared.addTrailingComment;
  11906. var childNodesCacheKey = Symbol("child-nodes");
  11907. function getSortedChildNodes(node, options, resultArray) {
  11908. if (!node) {
  11909. return;
  11910. }
  11911. var printer = options.printer,
  11912. locStart = options.locStart,
  11913. locEnd = options.locEnd;
  11914. if (resultArray) {
  11915. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  11916. // This reverse insertion sort almost always takes constant
  11917. // time because we almost always (maybe always?) append the
  11918. // nodes in order anyway.
  11919. var i;
  11920. for (i = resultArray.length - 1; i >= 0; --i) {
  11921. if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
  11922. break;
  11923. }
  11924. }
  11925. resultArray.splice(i + 1, 0, node);
  11926. return;
  11927. }
  11928. } else if (node[childNodesCacheKey]) {
  11929. return node[childNodesCacheKey];
  11930. }
  11931. var childNodes;
  11932. if (printer.getCommentChildNodes) {
  11933. childNodes = printer.getCommentChildNodes(node);
  11934. } else if (node && _typeof(node) === "object") {
  11935. childNodes = Object.keys(node).filter(function (n) {
  11936. return n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode";
  11937. }).map(function (n) {
  11938. return node[n];
  11939. });
  11940. }
  11941. if (!childNodes) {
  11942. return;
  11943. }
  11944. if (!resultArray) {
  11945. Object.defineProperty(node, childNodesCacheKey, {
  11946. value: resultArray = [],
  11947. enumerable: false
  11948. });
  11949. }
  11950. childNodes.forEach(function (childNode) {
  11951. getSortedChildNodes(childNode, options, resultArray);
  11952. });
  11953. return resultArray;
  11954. } // As efficiently as possible, decorate the comment object with
  11955. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  11956. // least one of which is guaranteed to be defined.
  11957. function decorateComment(node, comment, options) {
  11958. var locStart = options.locStart,
  11959. locEnd = options.locEnd;
  11960. var childNodes = getSortedChildNodes(node, options);
  11961. var precedingNode;
  11962. var followingNode; // Time to dust off the old binary search robes and wizard hat.
  11963. var left = 0;
  11964. var right = childNodes.length;
  11965. while (left < right) {
  11966. var middle = left + right >> 1;
  11967. var child = childNodes[middle];
  11968. if (locStart(child) - locStart(comment) <= 0 && locEnd(comment) - locEnd(child) <= 0) {
  11969. // The comment is completely contained by this child node.
  11970. comment.enclosingNode = child;
  11971. decorateComment(child, comment, options);
  11972. return; // Abandon the binary search at this level.
  11973. }
  11974. if (locEnd(child) - locStart(comment) <= 0) {
  11975. // This child node falls completely before the comment.
  11976. // Because we will never consider this node or any nodes
  11977. // before it again, this node must be the closest preceding
  11978. // node we have encountered so far.
  11979. precedingNode = child;
  11980. left = middle + 1;
  11981. continue;
  11982. }
  11983. if (locEnd(comment) - locStart(child) <= 0) {
  11984. // This child node falls completely after the comment.
  11985. // Because we will never consider this node or any nodes after
  11986. // it again, this node must be the closest following node we
  11987. // have encountered so far.
  11988. followingNode = child;
  11989. right = middle;
  11990. continue;
  11991. }
  11992. /* istanbul ignore next */
  11993. throw new Error("Comment location overlaps with node location");
  11994. } // We don't want comments inside of different expressions inside of the same
  11995. // template literal to move to another expression.
  11996. if (comment.enclosingNode && comment.enclosingNode.type === "TemplateLiteral") {
  11997. var quasis = comment.enclosingNode.quasis;
  11998. var commentIndex = findExpressionIndexForComment(quasis, comment, options);
  11999. if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
  12000. precedingNode = null;
  12001. }
  12002. if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
  12003. followingNode = null;
  12004. }
  12005. }
  12006. if (precedingNode) {
  12007. comment.precedingNode = precedingNode;
  12008. }
  12009. if (followingNode) {
  12010. comment.followingNode = followingNode;
  12011. }
  12012. }
  12013. function attach(comments, ast, text, options) {
  12014. if (!Array.isArray(comments)) {
  12015. return;
  12016. }
  12017. var tiesToBreak = [];
  12018. var locStart = options.locStart,
  12019. locEnd = options.locEnd;
  12020. comments.forEach(function (comment, i) {
  12021. if (options.parser === "json" || options.parser === "json5" || options.parser === "__js_expression" || options.parser === "__vue_expression") {
  12022. if (locStart(comment) - locStart(ast) <= 0) {
  12023. addLeadingComment$1(ast, comment);
  12024. return;
  12025. }
  12026. if (locEnd(comment) - locEnd(ast) >= 0) {
  12027. addTrailingComment$1(ast, comment);
  12028. return;
  12029. }
  12030. }
  12031. decorateComment(ast, comment, options);
  12032. var precedingNode = comment.precedingNode,
  12033. enclosingNode = comment.enclosingNode,
  12034. followingNode = comment.followingNode;
  12035. var pluginHandleOwnLineComment = options.printer.handleComments && options.printer.handleComments.ownLine ? options.printer.handleComments.ownLine : function () {
  12036. return false;
  12037. };
  12038. var pluginHandleEndOfLineComment = options.printer.handleComments && options.printer.handleComments.endOfLine ? options.printer.handleComments.endOfLine : function () {
  12039. return false;
  12040. };
  12041. var pluginHandleRemainingComment = options.printer.handleComments && options.printer.handleComments.remaining ? options.printer.handleComments.remaining : function () {
  12042. return false;
  12043. };
  12044. var isLastComment = comments.length - 1 === i;
  12045. if (hasNewline$1(text, locStart(comment), {
  12046. backwards: true
  12047. })) {
  12048. // If a comment exists on its own line, prefer a leading comment.
  12049. // We also need to check if it's the first line of the file.
  12050. if (pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)) ; else if (followingNode) {
  12051. // Always a leading comment.
  12052. addLeadingComment$1(followingNode, comment);
  12053. } else if (precedingNode) {
  12054. addTrailingComment$1(precedingNode, comment);
  12055. } else if (enclosingNode) {
  12056. addDanglingComment$1(enclosingNode, comment);
  12057. } else {
  12058. // There are no nodes, let's attach it to the root of the ast
  12059. /* istanbul ignore next */
  12060. addDanglingComment$1(ast, comment);
  12061. }
  12062. } else if (hasNewline$1(text, locEnd(comment))) {
  12063. if (pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)) ; else if (precedingNode) {
  12064. // There is content before this comment on the same line, but
  12065. // none after it, so prefer a trailing comment of the previous node.
  12066. addTrailingComment$1(precedingNode, comment);
  12067. } else if (followingNode) {
  12068. addLeadingComment$1(followingNode, comment);
  12069. } else if (enclosingNode) {
  12070. addDanglingComment$1(enclosingNode, comment);
  12071. } else {
  12072. // There are no nodes, let's attach it to the root of the ast
  12073. /* istanbul ignore next */
  12074. addDanglingComment$1(ast, comment);
  12075. }
  12076. } else {
  12077. if (pluginHandleRemainingComment(comment, text, options, ast, isLastComment)) ; else if (precedingNode && followingNode) {
  12078. // Otherwise, text exists both before and after the comment on
  12079. // the same line. If there is both a preceding and following
  12080. // node, use a tie-breaking algorithm to determine if it should
  12081. // be attached to the next or previous node. In the last case,
  12082. // simply attach the right node;
  12083. var tieCount = tiesToBreak.length;
  12084. if (tieCount > 0) {
  12085. var lastTie = tiesToBreak[tieCount - 1];
  12086. if (lastTie.followingNode !== comment.followingNode) {
  12087. breakTies(tiesToBreak, text, options);
  12088. }
  12089. }
  12090. tiesToBreak.push(comment);
  12091. } else if (precedingNode) {
  12092. addTrailingComment$1(precedingNode, comment);
  12093. } else if (followingNode) {
  12094. addLeadingComment$1(followingNode, comment);
  12095. } else if (enclosingNode) {
  12096. addDanglingComment$1(enclosingNode, comment);
  12097. } else {
  12098. // There are no nodes, let's attach it to the root of the ast
  12099. /* istanbul ignore next */
  12100. addDanglingComment$1(ast, comment);
  12101. }
  12102. }
  12103. });
  12104. breakTies(tiesToBreak, text, options);
  12105. comments.forEach(function (comment) {
  12106. // These node references were useful for breaking ties, but we
  12107. // don't need them anymore, and they create cycles in the AST that
  12108. // may lead to infinite recursion if we don't delete them here.
  12109. delete comment.precedingNode;
  12110. delete comment.enclosingNode;
  12111. delete comment.followingNode;
  12112. });
  12113. }
  12114. function breakTies(tiesToBreak, text, options) {
  12115. var tieCount = tiesToBreak.length;
  12116. if (tieCount === 0) {
  12117. return;
  12118. }
  12119. var _tiesToBreak$ = tiesToBreak[0],
  12120. precedingNode = _tiesToBreak$.precedingNode,
  12121. followingNode = _tiesToBreak$.followingNode;
  12122. var gapEndPos = options.locStart(followingNode); // Iterate backwards through tiesToBreak, examining the gaps
  12123. // between the tied comments. In order to qualify as leading, a
  12124. // comment must be separated from followingNode by an unbroken series of
  12125. // gaps (or other comments). Gaps should only contain whitespace or open
  12126. // parentheses.
  12127. var indexOfFirstLeadingComment;
  12128. for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
  12129. var comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  12130. assert.strictEqual(comment.precedingNode, precedingNode);
  12131. assert.strictEqual(comment.followingNode, followingNode);
  12132. var gap = text.slice(options.locEnd(comment), gapEndPos);
  12133. if (/^[\s(]*$/.test(gap)) {
  12134. gapEndPos = options.locStart(comment);
  12135. } else {
  12136. // The gap string contained something other than whitespace or open
  12137. // parentheses.
  12138. break;
  12139. }
  12140. }
  12141. tiesToBreak.forEach(function (comment, i) {
  12142. if (i < indexOfFirstLeadingComment) {
  12143. addTrailingComment$1(precedingNode, comment);
  12144. } else {
  12145. addLeadingComment$1(followingNode, comment);
  12146. }
  12147. });
  12148. tiesToBreak.length = 0;
  12149. }
  12150. function printComment(commentPath, options) {
  12151. var comment = commentPath.getValue();
  12152. comment.printed = true;
  12153. return options.printer.printComment(commentPath, options);
  12154. }
  12155. function findExpressionIndexForComment(quasis, comment, options) {
  12156. var startPos = options.locStart(comment) - 1;
  12157. for (var i = 1; i < quasis.length; ++i) {
  12158. if (startPos < getQuasiRange(quasis[i]).start) {
  12159. return i - 1;
  12160. }
  12161. } // We haven't found it, it probably means that some of the locations are off.
  12162. // Let's just return the first one.
  12163. /* istanbul ignore next */
  12164. return 0;
  12165. }
  12166. function getQuasiRange(expr) {
  12167. if (expr.start !== undefined) {
  12168. // Babel
  12169. return {
  12170. start: expr.start,
  12171. end: expr.end
  12172. };
  12173. } // Flow
  12174. return {
  12175. start: expr.range[0],
  12176. end: expr.range[1]
  12177. };
  12178. }
  12179. function printLeadingComment(commentPath, print, options) {
  12180. var comment = commentPath.getValue();
  12181. var contents = printComment(commentPath, options);
  12182. if (!contents) {
  12183. return "";
  12184. }
  12185. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // Leading block comments should see if they need to stay on the
  12186. // same line or not.
  12187. if (isBlock) {
  12188. return concat$2([contents, hasNewline$1(options.originalText, options.locEnd(comment)) ? hardline$1 : " "]);
  12189. }
  12190. return concat$2([contents, hardline$1]);
  12191. }
  12192. function printTrailingComment(commentPath, print, options) {
  12193. var comment = commentPath.getValue();
  12194. var contents = printComment(commentPath, options);
  12195. if (!contents) {
  12196. return "";
  12197. }
  12198. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // We don't want the line to break
  12199. // when the parentParentNode is a ClassDeclaration/-Expression
  12200. // And the parentNode is in the superClass property
  12201. var parentNode = commentPath.getNode(1);
  12202. var parentParentNode = commentPath.getNode(2);
  12203. var isParentSuperClass = parentParentNode && (parentParentNode.type === "ClassDeclaration" || parentParentNode.type === "ClassExpression") && parentParentNode.superClass === parentNode;
  12204. if (hasNewline$1(options.originalText, options.locStart(comment), {
  12205. backwards: true
  12206. })) {
  12207. // This allows comments at the end of nested structures:
  12208. // {
  12209. // x: 1,
  12210. // y: 2
  12211. // // A comment
  12212. // }
  12213. // Those kinds of comments are almost always leading comments, but
  12214. // here it doesn't go "outside" the block and turns it into a
  12215. // trailing comment for `2`. We can simulate the above by checking
  12216. // if this a comment on its own line; normal trailing comments are
  12217. // always at the end of another expression.
  12218. var isLineBeforeEmpty = isPreviousLineEmpty$2(options.originalText, comment, options.locStart);
  12219. return lineSuffix$1(concat$2([hardline$1, isLineBeforeEmpty ? hardline$1 : "", contents]));
  12220. } else if (isBlock || isParentSuperClass) {
  12221. // Trailing block comments never need a newline
  12222. return concat$2([" ", contents]);
  12223. }
  12224. return concat$2([lineSuffix$1(concat$2([" ", contents])), !isBlock ? breakParent$1 : ""]);
  12225. }
  12226. function printDanglingComments(path, options, sameIndent, filter) {
  12227. var parts = [];
  12228. var node = path.getValue();
  12229. if (!node || !node.comments) {
  12230. return "";
  12231. }
  12232. path.each(function (commentPath) {
  12233. var comment = commentPath.getValue();
  12234. if (comment && !comment.leading && !comment.trailing && (!filter || filter(comment))) {
  12235. parts.push(printComment(commentPath, options));
  12236. }
  12237. }, "comments");
  12238. if (parts.length === 0) {
  12239. return "";
  12240. }
  12241. if (sameIndent) {
  12242. return join$1(hardline$1, parts);
  12243. }
  12244. return indent$1(concat$2([hardline$1, join$1(hardline$1, parts)]));
  12245. }
  12246. function prependCursorPlaceholder(path, options, printed) {
  12247. if (path.getNode() === options.cursorNode && path.getValue()) {
  12248. return concat$2([cursor$2, printed, cursor$2]);
  12249. }
  12250. return printed;
  12251. }
  12252. function printComments(path, print, options, needsSemi) {
  12253. var value = path.getValue();
  12254. var printed = print(path);
  12255. var comments = value && value.comments;
  12256. if (!comments || comments.length === 0) {
  12257. return prependCursorPlaceholder(path, options, printed);
  12258. }
  12259. var leadingParts = [];
  12260. var trailingParts = [needsSemi ? ";" : "", printed];
  12261. path.each(function (commentPath) {
  12262. var comment = commentPath.getValue();
  12263. var leading = comment.leading,
  12264. trailing = comment.trailing;
  12265. if (leading) {
  12266. var contents = printLeadingComment(commentPath, print, options);
  12267. if (!contents) {
  12268. return;
  12269. }
  12270. leadingParts.push(contents);
  12271. var text = options.originalText;
  12272. var index = skipNewline$1(text, options.locEnd(comment));
  12273. if (index !== false && hasNewline$1(text, index)) {
  12274. leadingParts.push(hardline$1);
  12275. }
  12276. } else if (trailing) {
  12277. trailingParts.push(printTrailingComment(commentPath, print, options));
  12278. }
  12279. }, "comments");
  12280. return prependCursorPlaceholder(path, options, concat$2(leadingParts.concat(trailingParts)));
  12281. }
  12282. var comments = {
  12283. attach: attach,
  12284. printComments: printComments,
  12285. printDanglingComments: printDanglingComments,
  12286. getSortedChildNodes: getSortedChildNodes
  12287. };
  12288. function FastPath(value) {
  12289. assert.ok(this instanceof FastPath);
  12290. this.stack = [value];
  12291. } // The name of the current property is always the penultimate element of
  12292. // this.stack, and always a String.
  12293. FastPath.prototype.getName = function getName() {
  12294. var s = this.stack;
  12295. var len = s.length;
  12296. if (len > 1) {
  12297. return s[len - 2];
  12298. } // Since the name is always a string, null is a safe sentinel value to
  12299. // return if we do not know the name of the (root) value.
  12300. /* istanbul ignore next */
  12301. return null;
  12302. }; // The value of the current property is always the final element of
  12303. // this.stack.
  12304. FastPath.prototype.getValue = function getValue() {
  12305. var s = this.stack;
  12306. return s[s.length - 1];
  12307. };
  12308. function getNodeHelper(path, count) {
  12309. var stackIndex = getNodeStackIndexHelper(path.stack, count);
  12310. return stackIndex === -1 ? null : path.stack[stackIndex];
  12311. }
  12312. function getNodeStackIndexHelper(stack, count) {
  12313. for (var i = stack.length - 1; i >= 0; i -= 2) {
  12314. var value = stack[i];
  12315. if (value && !Array.isArray(value) && --count < 0) {
  12316. return i;
  12317. }
  12318. }
  12319. return -1;
  12320. }
  12321. FastPath.prototype.getNode = function getNode(count) {
  12322. return getNodeHelper(this, ~~count);
  12323. };
  12324. FastPath.prototype.getParentNode = function getParentNode(count) {
  12325. return getNodeHelper(this, ~~count + 1);
  12326. }; // Temporarily push properties named by string arguments given after the
  12327. // callback function onto this.stack, then call the callback with a
  12328. // reference to this (modified) FastPath object. Note that the stack will
  12329. // be restored to its original state after the callback is finished, so it
  12330. // is probably a mistake to retain a reference to the path.
  12331. FastPath.prototype.call = function call(callback
  12332. /*, name1, name2, ... */
  12333. ) {
  12334. var s = this.stack;
  12335. var origLen = s.length;
  12336. var value = s[origLen - 1];
  12337. var argc = arguments.length;
  12338. for (var i = 1; i < argc; ++i) {
  12339. var name = arguments[i];
  12340. value = value[name];
  12341. s.push(name, value);
  12342. }
  12343. var result = callback(this);
  12344. s.length = origLen;
  12345. return result;
  12346. };
  12347. FastPath.prototype.callParent = function callParent(callback, count) {
  12348. var stackIndex = getNodeStackIndexHelper(this.stack, ~~count + 1);
  12349. var parentValues = this.stack.splice(stackIndex + 1);
  12350. var result = callback(this);
  12351. Array.prototype.push.apply(this.stack, parentValues);
  12352. return result;
  12353. }; // Similar to FastPath.prototype.call, except that the value obtained by
  12354. // accessing this.getValue()[name1][name2]... should be array-like. The
  12355. // callback will be called with a reference to this path object for each
  12356. // element of the array.
  12357. FastPath.prototype.each = function each(callback
  12358. /*, name1, name2, ... */
  12359. ) {
  12360. var s = this.stack;
  12361. var origLen = s.length;
  12362. var value = s[origLen - 1];
  12363. var argc = arguments.length;
  12364. for (var i = 1; i < argc; ++i) {
  12365. var name = arguments[i];
  12366. value = value[name];
  12367. s.push(name, value);
  12368. }
  12369. for (var _i = 0; _i < value.length; ++_i) {
  12370. if (_i in value) {
  12371. s.push(_i, value[_i]); // If the callback needs to know the value of i, call
  12372. // path.getName(), assuming path is the parameter name.
  12373. callback(this);
  12374. s.length -= 2;
  12375. }
  12376. }
  12377. s.length = origLen;
  12378. }; // Similar to FastPath.prototype.each, except that the results of the
  12379. // callback function invocations are stored in an array and returned at
  12380. // the end of the iteration.
  12381. FastPath.prototype.map = function map(callback
  12382. /*, name1, name2, ... */
  12383. ) {
  12384. var s = this.stack;
  12385. var origLen = s.length;
  12386. var value = s[origLen - 1];
  12387. var argc = arguments.length;
  12388. for (var i = 1; i < argc; ++i) {
  12389. var name = arguments[i];
  12390. value = value[name];
  12391. s.push(name, value);
  12392. }
  12393. var result = new Array(value.length);
  12394. for (var _i2 = 0; _i2 < value.length; ++_i2) {
  12395. if (_i2 in value) {
  12396. s.push(_i2, value[_i2]);
  12397. result[_i2] = callback(this, _i2);
  12398. s.length -= 2;
  12399. }
  12400. }
  12401. s.length = origLen;
  12402. return result;
  12403. };
  12404. var fastPath = FastPath;
  12405. var normalize$2 = options$1.normalize;
  12406. function printSubtree(path, print, options, printAstToDoc) {
  12407. if (options.printer.embed) {
  12408. return options.printer.embed(path, print, function (text, partialNextOptions) {
  12409. return textToDoc(text, partialNextOptions, options, printAstToDoc);
  12410. }, options);
  12411. }
  12412. }
  12413. function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) {
  12414. var nextOptions = normalize$2(Object.assign({}, parentOptions, partialNextOptions, {
  12415. parentParser: parentOptions.parser,
  12416. embeddedInHtml: !!(parentOptions.embeddedInHtml || parentOptions.parser === "html" || parentOptions.parser === "vue" || parentOptions.parser === "angular" || parentOptions.parser === "lwc"),
  12417. originalText: text
  12418. }), {
  12419. passThrough: true
  12420. });
  12421. var result = parser.parse(text, nextOptions);
  12422. var ast = result.ast;
  12423. text = result.text;
  12424. var astComments = ast.comments;
  12425. delete ast.comments;
  12426. comments.attach(astComments, ast, text, nextOptions);
  12427. return printAstToDoc(ast, nextOptions);
  12428. }
  12429. var multiparser = {
  12430. printSubtree: printSubtree
  12431. };
  12432. var doc$1 = doc;
  12433. var docBuilders$1 = doc$1.builders;
  12434. var concat$3 = docBuilders$1.concat;
  12435. var hardline$2 = docBuilders$1.hardline;
  12436. var addAlignmentToDoc$1 = docBuilders$1.addAlignmentToDoc;
  12437. var docUtils$1 = doc$1.utils;
  12438. /**
  12439. * Takes an abstract syntax tree (AST) and recursively converts it to a
  12440. * document (series of printing primitives).
  12441. *
  12442. * This is done by descending down the AST recursively. The recursion
  12443. * involves two functions that call each other:
  12444. *
  12445. * 1. printGenerically(), which is defined as an inner function here.
  12446. * It basically takes care of node caching.
  12447. * 2. callPluginPrintFunction(), which checks for some options, and
  12448. * ultimately calls the print() function provided by the plugin.
  12449. *
  12450. * The plugin function will call printGenerically() again for child nodes
  12451. * of the current node, which will do its housekeeping, then call the
  12452. * plugin function again, and so on.
  12453. *
  12454. * All the while, these functions pass a "path" variable around, which
  12455. * is a stack-like data structure (FastPath) that maintains the current
  12456. * state of the recursion. It is called "path", because it represents
  12457. * the path to the current node through the Abstract Syntax Tree.
  12458. */
  12459. function printAstToDoc(ast, options) {
  12460. var alignmentSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  12461. var printer = options.printer;
  12462. if (printer.preprocess) {
  12463. ast = printer.preprocess(ast, options);
  12464. }
  12465. var cache = new Map();
  12466. function printGenerically(path, args) {
  12467. var node = path.getValue();
  12468. var shouldCache = node && _typeof(node) === "object" && args === undefined;
  12469. if (shouldCache && cache.has(node)) {
  12470. return cache.get(node);
  12471. } // We let JSXElement print its comments itself because it adds () around
  12472. // UnionTypeAnnotation has to align the child without the comments
  12473. var res;
  12474. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path, options)) {
  12475. res = callPluginPrintFunction(path, options, printGenerically, args);
  12476. } else {
  12477. // printComments will call the plugin print function and check for
  12478. // comments to print
  12479. res = comments.printComments(path, function (p) {
  12480. return callPluginPrintFunction(p, options, printGenerically, args);
  12481. }, options, args && args.needsSemi);
  12482. }
  12483. if (shouldCache) {
  12484. cache.set(node, res);
  12485. }
  12486. return res;
  12487. }
  12488. var doc = printGenerically(new fastPath(ast));
  12489. if (alignmentSize > 0) {
  12490. // Add a hardline to make the indents take effect
  12491. // It should be removed in index.js format()
  12492. doc = addAlignmentToDoc$1(concat$3([hardline$2, doc]), alignmentSize, options.tabWidth);
  12493. }
  12494. docUtils$1.propagateBreaks(doc);
  12495. return doc;
  12496. }
  12497. function callPluginPrintFunction(path, options, printPath, args) {
  12498. assert.ok(path instanceof fastPath);
  12499. var node = path.getValue();
  12500. var printer = options.printer; // Escape hatch
  12501. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path)) {
  12502. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  12503. }
  12504. if (node) {
  12505. try {
  12506. // Potentially switch to a different parser
  12507. var sub = multiparser.printSubtree(path, printPath, options, printAstToDoc);
  12508. if (sub) {
  12509. return sub;
  12510. }
  12511. } catch (error) {
  12512. /* istanbul ignore if */
  12513. if (commonjsGlobal.PRETTIER_DEBUG) {
  12514. throw error;
  12515. } // Continue with current parser
  12516. }
  12517. }
  12518. return printer.print(path, options, printPath, args);
  12519. }
  12520. var astToDoc = printAstToDoc;
  12521. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  12522. var resultStartNode = startNodeAndParents.node;
  12523. var resultEndNode = endNodeAndParents.node;
  12524. if (resultStartNode === resultEndNode) {
  12525. return {
  12526. startNode: resultStartNode,
  12527. endNode: resultEndNode
  12528. };
  12529. }
  12530. var _iteratorNormalCompletion = true;
  12531. var _didIteratorError = false;
  12532. var _iteratorError = undefined;
  12533. try {
  12534. for (var _iterator = endNodeAndParents.parentNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  12535. var endParent = _step.value;
  12536. if (endParent.type !== "Program" && endParent.type !== "File" && opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)) {
  12537. resultEndNode = endParent;
  12538. } else {
  12539. break;
  12540. }
  12541. }
  12542. } catch (err) {
  12543. _didIteratorError = true;
  12544. _iteratorError = err;
  12545. } finally {
  12546. try {
  12547. if (!_iteratorNormalCompletion && _iterator.return != null) {
  12548. _iterator.return();
  12549. }
  12550. } finally {
  12551. if (_didIteratorError) {
  12552. throw _iteratorError;
  12553. }
  12554. }
  12555. }
  12556. var _iteratorNormalCompletion2 = true;
  12557. var _didIteratorError2 = false;
  12558. var _iteratorError2 = undefined;
  12559. try {
  12560. for (var _iterator2 = startNodeAndParents.parentNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  12561. var startParent = _step2.value;
  12562. if (startParent.type !== "Program" && startParent.type !== "File" && opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)) {
  12563. resultStartNode = startParent;
  12564. } else {
  12565. break;
  12566. }
  12567. }
  12568. } catch (err) {
  12569. _didIteratorError2 = true;
  12570. _iteratorError2 = err;
  12571. } finally {
  12572. try {
  12573. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  12574. _iterator2.return();
  12575. }
  12576. } finally {
  12577. if (_didIteratorError2) {
  12578. throw _iteratorError2;
  12579. }
  12580. }
  12581. }
  12582. return {
  12583. startNode: resultStartNode,
  12584. endNode: resultEndNode
  12585. };
  12586. }
  12587. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  12588. predicate = predicate || function () {
  12589. return true;
  12590. };
  12591. parentNodes = parentNodes || [];
  12592. var start = options.locStart(node, options.locStart);
  12593. var end = options.locEnd(node, options.locEnd);
  12594. if (start <= offset && offset <= end) {
  12595. var _iteratorNormalCompletion3 = true;
  12596. var _didIteratorError3 = false;
  12597. var _iteratorError3 = undefined;
  12598. try {
  12599. for (var _iterator3 = comments.getSortedChildNodes(node, options)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  12600. var childNode = _step3.value;
  12601. var childResult = findNodeAtOffset(childNode, offset, options, predicate, [node].concat(parentNodes));
  12602. if (childResult) {
  12603. return childResult;
  12604. }
  12605. }
  12606. } catch (err) {
  12607. _didIteratorError3 = true;
  12608. _iteratorError3 = err;
  12609. } finally {
  12610. try {
  12611. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  12612. _iterator3.return();
  12613. }
  12614. } finally {
  12615. if (_didIteratorError3) {
  12616. throw _iteratorError3;
  12617. }
  12618. }
  12619. }
  12620. if (predicate(node)) {
  12621. return {
  12622. node: node,
  12623. parentNodes: parentNodes
  12624. };
  12625. }
  12626. }
  12627. } // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  12628. function isSourceElement(opts, node) {
  12629. if (node == null) {
  12630. return false;
  12631. } // JS and JS like to avoid repetitions
  12632. var jsSourceElements = ["FunctionDeclaration", "BlockStatement", "BreakStatement", "ContinueStatement", "DebuggerStatement", "DoWhileStatement", "EmptyStatement", "ExpressionStatement", "ForInStatement", "ForStatement", "IfStatement", "LabeledStatement", "ReturnStatement", "SwitchStatement", "ThrowStatement", "TryStatement", "VariableDeclaration", "WhileStatement", "WithStatement", "ClassDeclaration", // ES 2015
  12633. "ImportDeclaration", // Module
  12634. "ExportDefaultDeclaration", // Module
  12635. "ExportNamedDeclaration", // Module
  12636. "ExportAllDeclaration", // Module
  12637. "TypeAlias", // Flow
  12638. "InterfaceDeclaration", // Flow, TypeScript
  12639. "TypeAliasDeclaration", // TypeScript
  12640. "ExportAssignment", // TypeScript
  12641. "ExportDeclaration" // TypeScript
  12642. ];
  12643. var jsonSourceElements = ["ObjectExpression", "ArrayExpression", "StringLiteral", "NumericLiteral", "BooleanLiteral", "NullLiteral"];
  12644. var graphqlSourceElements = ["OperationDefinition", "FragmentDefinition", "VariableDefinition", "TypeExtensionDefinition", "ObjectTypeDefinition", "FieldDefinition", "DirectiveDefinition", "EnumTypeDefinition", "EnumValueDefinition", "InputValueDefinition", "InputObjectTypeDefinition", "SchemaDefinition", "OperationTypeDefinition", "InterfaceTypeDefinition", "UnionTypeDefinition", "ScalarTypeDefinition"];
  12645. switch (opts.parser) {
  12646. case "flow":
  12647. case "babel":
  12648. case "typescript":
  12649. return jsSourceElements.indexOf(node.type) > -1;
  12650. case "json":
  12651. return jsonSourceElements.indexOf(node.type) > -1;
  12652. case "graphql":
  12653. return graphqlSourceElements.indexOf(node.kind) > -1;
  12654. case "vue":
  12655. return node.tag !== "root";
  12656. }
  12657. return false;
  12658. }
  12659. function calculateRange(text, opts, ast) {
  12660. // Contract the range so that it has non-whitespace characters at its endpoints.
  12661. // This ensures we can format a range that doesn't end on a node.
  12662. var rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  12663. var startNonWhitespace = Math.max(opts.rangeStart + rangeStringOrig.search(/\S/), opts.rangeStart);
  12664. var endNonWhitespace;
  12665. for (endNonWhitespace = opts.rangeEnd; endNonWhitespace > opts.rangeStart; --endNonWhitespace) {
  12666. if (text[endNonWhitespace - 1].match(/\S/)) {
  12667. break;
  12668. }
  12669. }
  12670. var startNodeAndParents = findNodeAtOffset(ast, startNonWhitespace, opts, function (node) {
  12671. return isSourceElement(opts, node);
  12672. });
  12673. var endNodeAndParents = findNodeAtOffset(ast, endNonWhitespace, opts, function (node) {
  12674. return isSourceElement(opts, node);
  12675. });
  12676. if (!startNodeAndParents || !endNodeAndParents) {
  12677. return {
  12678. rangeStart: 0,
  12679. rangeEnd: 0
  12680. };
  12681. }
  12682. var siblingAncestors = findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts);
  12683. var startNode = siblingAncestors.startNode,
  12684. endNode = siblingAncestors.endNode;
  12685. var rangeStart = Math.min(opts.locStart(startNode, opts.locStart), opts.locStart(endNode, opts.locStart));
  12686. var rangeEnd = Math.max(opts.locEnd(startNode, opts.locEnd), opts.locEnd(endNode, opts.locEnd));
  12687. return {
  12688. rangeStart: rangeStart,
  12689. rangeEnd: rangeEnd
  12690. };
  12691. }
  12692. var rangeUtil = {
  12693. calculateRange: calculateRange,
  12694. findNodeAtOffset: findNodeAtOffset
  12695. };
  12696. var diff = getCjsExportFromNamespace(index_es6);
  12697. var normalizeOptions$1 = options$1.normalize;
  12698. var guessEndOfLine$1 = endOfLine.guessEndOfLine,
  12699. convertEndOfLineToChars$2 = endOfLine.convertEndOfLineToChars;
  12700. var mapDoc$2 = doc.utils.mapDoc,
  12701. _printDocToString = doc.printer.printDocToString,
  12702. printDocToDebug = doc.debug.printDocToDebug;
  12703. var UTF8BOM = 0xfeff;
  12704. var CURSOR = Symbol("cursor");
  12705. var PLACEHOLDERS = {
  12706. cursorOffset: "<<<PRETTIER_CURSOR>>>",
  12707. rangeStart: "<<<PRETTIER_RANGE_START>>>",
  12708. rangeEnd: "<<<PRETTIER_RANGE_END>>>"
  12709. };
  12710. function ensureAllCommentsPrinted(astComments) {
  12711. if (!astComments) {
  12712. return;
  12713. }
  12714. for (var i = 0; i < astComments.length; ++i) {
  12715. if (astComments[i].value.trim() === "prettier-ignore") {
  12716. // If there's a prettier-ignore, we're not printing that sub-tree so we
  12717. // don't know if the comments was printed or not.
  12718. return;
  12719. }
  12720. }
  12721. astComments.forEach(function (comment) {
  12722. if (!comment.printed) {
  12723. throw new Error('Comment "' + comment.value.trim() + '" was not printed. Please report this error!');
  12724. }
  12725. delete comment.printed;
  12726. });
  12727. }
  12728. function attachComments(text, ast, opts) {
  12729. var astComments = ast.comments;
  12730. if (astComments) {
  12731. delete ast.comments;
  12732. comments.attach(astComments, ast, text, opts);
  12733. }
  12734. ast.tokens = [];
  12735. opts.originalText = opts.parser === "yaml" ? text : text.trimRight();
  12736. return astComments;
  12737. }
  12738. function coreFormat(text, opts, addAlignmentSize) {
  12739. if (!text || !text.trim().length) {
  12740. return {
  12741. formatted: "",
  12742. cursorOffset: 0
  12743. };
  12744. }
  12745. addAlignmentSize = addAlignmentSize || 0;
  12746. var parsed = parser.parse(text, opts);
  12747. var ast = parsed.ast;
  12748. text = parsed.text;
  12749. if (opts.cursorOffset >= 0) {
  12750. var nodeResult = rangeUtil.findNodeAtOffset(ast, opts.cursorOffset, opts);
  12751. if (nodeResult && nodeResult.node) {
  12752. opts.cursorNode = nodeResult.node;
  12753. }
  12754. }
  12755. var astComments = attachComments(text, ast, opts);
  12756. var doc = astToDoc(ast, opts, addAlignmentSize);
  12757. var eol = convertEndOfLineToChars$2(opts.endOfLine);
  12758. var result = _printDocToString(opts.endOfLine === "lf" ? doc : mapDoc$2(doc, function (currentDoc) {
  12759. return typeof currentDoc === "string" && currentDoc.indexOf("\n") !== -1 ? currentDoc.replace(/\n/g, eol) : currentDoc;
  12760. }), opts);
  12761. ensureAllCommentsPrinted(astComments); // Remove extra leading indentation as well as the added indentation after last newline
  12762. if (addAlignmentSize > 0) {
  12763. var trimmed = result.formatted.trim();
  12764. if (result.cursorNodeStart !== undefined) {
  12765. result.cursorNodeStart -= result.formatted.indexOf(trimmed);
  12766. }
  12767. result.formatted = trimmed + convertEndOfLineToChars$2(opts.endOfLine);
  12768. }
  12769. if (opts.cursorOffset >= 0) {
  12770. var oldCursorNodeStart;
  12771. var oldCursorNodeText;
  12772. var cursorOffsetRelativeToOldCursorNode;
  12773. var newCursorNodeStart;
  12774. var newCursorNodeText;
  12775. if (opts.cursorNode && result.cursorNodeText) {
  12776. oldCursorNodeStart = opts.locStart(opts.cursorNode);
  12777. oldCursorNodeText = text.slice(oldCursorNodeStart, opts.locEnd(opts.cursorNode));
  12778. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset - oldCursorNodeStart;
  12779. newCursorNodeStart = result.cursorNodeStart;
  12780. newCursorNodeText = result.cursorNodeText;
  12781. } else {
  12782. oldCursorNodeStart = 0;
  12783. oldCursorNodeText = text;
  12784. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset;
  12785. newCursorNodeStart = 0;
  12786. newCursorNodeText = result.formatted;
  12787. }
  12788. if (oldCursorNodeText === newCursorNodeText) {
  12789. return {
  12790. formatted: result.formatted,
  12791. cursorOffset: newCursorNodeStart + cursorOffsetRelativeToOldCursorNode
  12792. };
  12793. } // diff old and new cursor node texts, with a special cursor
  12794. // symbol inserted to find out where it moves to
  12795. var oldCursorNodeCharArray = oldCursorNodeText.split("");
  12796. oldCursorNodeCharArray.splice(cursorOffsetRelativeToOldCursorNode, 0, CURSOR);
  12797. var newCursorNodeCharArray = newCursorNodeText.split("");
  12798. var cursorNodeDiff = diff.diffArrays(oldCursorNodeCharArray, newCursorNodeCharArray);
  12799. var cursorOffset = newCursorNodeStart;
  12800. var _iteratorNormalCompletion = true;
  12801. var _didIteratorError = false;
  12802. var _iteratorError = undefined;
  12803. try {
  12804. for (var _iterator = cursorNodeDiff[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  12805. var entry = _step.value;
  12806. if (entry.removed) {
  12807. if (entry.value.indexOf(CURSOR) > -1) {
  12808. break;
  12809. }
  12810. } else {
  12811. cursorOffset += entry.count;
  12812. }
  12813. }
  12814. } catch (err) {
  12815. _didIteratorError = true;
  12816. _iteratorError = err;
  12817. } finally {
  12818. try {
  12819. if (!_iteratorNormalCompletion && _iterator.return != null) {
  12820. _iterator.return();
  12821. }
  12822. } finally {
  12823. if (_didIteratorError) {
  12824. throw _iteratorError;
  12825. }
  12826. }
  12827. }
  12828. return {
  12829. formatted: result.formatted,
  12830. cursorOffset: cursorOffset
  12831. };
  12832. }
  12833. return {
  12834. formatted: result.formatted
  12835. };
  12836. }
  12837. function formatRange(text, opts) {
  12838. var parsed = parser.parse(text, opts);
  12839. var ast = parsed.ast;
  12840. text = parsed.text;
  12841. var range = rangeUtil.calculateRange(text, opts, ast);
  12842. var rangeStart = range.rangeStart;
  12843. var rangeEnd = range.rangeEnd;
  12844. var rangeString = text.slice(rangeStart, rangeEnd); // Try to extend the range backwards to the beginning of the line.
  12845. // This is so we can detect indentation correctly and restore it.
  12846. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  12847. var rangeStart2 = Math.min(rangeStart, text.lastIndexOf("\n", rangeStart) + 1);
  12848. var indentString = text.slice(rangeStart2, rangeStart);
  12849. var alignmentSize = util.getAlignmentSize(indentString, opts.tabWidth);
  12850. var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
  12851. rangeStart: 0,
  12852. rangeEnd: Infinity,
  12853. // track the cursor offset only if it's within our range
  12854. cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
  12855. }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
  12856. // we need to remove the newline that was inserted by the `format` call.
  12857. var rangeTrimmed = rangeResult.formatted.trimRight();
  12858. var rangeLeft = text.slice(0, rangeStart);
  12859. var rangeRight = text.slice(rangeEnd);
  12860. var cursorOffset = opts.cursorOffset;
  12861. if (opts.cursorOffset >= rangeEnd) {
  12862. // handle the case where the cursor was past the end of the range
  12863. cursorOffset = opts.cursorOffset - rangeEnd + (rangeStart + rangeTrimmed.length);
  12864. } else if (rangeResult.cursorOffset !== undefined) {
  12865. // handle the case where the cursor was in the range
  12866. cursorOffset = rangeResult.cursorOffset + rangeStart;
  12867. } // keep the cursor as it was if it was before the start of the range
  12868. var formatted;
  12869. if (opts.endOfLine === "lf") {
  12870. formatted = rangeLeft + rangeTrimmed + rangeRight;
  12871. } else {
  12872. var eol = convertEndOfLineToChars$2(opts.endOfLine);
  12873. if (cursorOffset >= 0) {
  12874. var parts = [rangeLeft, rangeTrimmed, rangeRight];
  12875. var partIndex = 0;
  12876. var partOffset = cursorOffset;
  12877. while (partIndex < parts.length) {
  12878. var part = parts[partIndex];
  12879. if (partOffset < part.length) {
  12880. parts[partIndex] = parts[partIndex].slice(0, partOffset) + PLACEHOLDERS.cursorOffset + parts[partIndex].slice(partOffset);
  12881. break;
  12882. }
  12883. partIndex++;
  12884. partOffset -= part.length;
  12885. }
  12886. var newRangeLeft = parts[0],
  12887. newRangeTrimmed = parts[1],
  12888. newRangeRight = parts[2];
  12889. formatted = (newRangeLeft.replace(/\n/g, eol) + newRangeTrimmed + newRangeRight.replace(/\n/g, eol)).replace(PLACEHOLDERS.cursorOffset, function (_, index) {
  12890. cursorOffset = index;
  12891. return "";
  12892. });
  12893. } else {
  12894. formatted = rangeLeft.replace(/\n/g, eol) + rangeTrimmed + rangeRight.replace(/\n/g, eol);
  12895. }
  12896. }
  12897. return {
  12898. formatted: formatted,
  12899. cursorOffset: cursorOffset
  12900. };
  12901. }
  12902. function format(text, opts) {
  12903. var selectedParser = parser.resolveParser(opts);
  12904. var hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  12905. if (opts.requirePragma && !hasPragma) {
  12906. return {
  12907. formatted: text
  12908. };
  12909. }
  12910. if (opts.endOfLine === "auto") {
  12911. opts.endOfLine = guessEndOfLine$1(text);
  12912. }
  12913. var hasCursor = opts.cursorOffset >= 0;
  12914. var hasRangeStart = opts.rangeStart > 0;
  12915. var hasRangeEnd = opts.rangeEnd < text.length; // get rid of CR/CRLF parsing
  12916. if (text.indexOf("\r") !== -1) {
  12917. var offsetKeys = [hasCursor && "cursorOffset", hasRangeStart && "rangeStart", hasRangeEnd && "rangeEnd"].filter(Boolean).sort(function (aKey, bKey) {
  12918. return opts[aKey] - opts[bKey];
  12919. });
  12920. for (var i = offsetKeys.length - 1; i >= 0; i--) {
  12921. var key = offsetKeys[i];
  12922. text = text.slice(0, opts[key]) + PLACEHOLDERS[key] + text.slice(opts[key]);
  12923. }
  12924. text = text.replace(/\r\n?/g, "\n");
  12925. var _loop = function _loop(_i) {
  12926. var key = offsetKeys[_i];
  12927. text = text.replace(PLACEHOLDERS[key], function (_, index) {
  12928. opts[key] = index;
  12929. return "";
  12930. });
  12931. };
  12932. for (var _i = 0; _i < offsetKeys.length; _i++) {
  12933. _loop(_i);
  12934. }
  12935. }
  12936. var hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  12937. if (hasUnicodeBOM) {
  12938. text = text.substring(1);
  12939. if (hasCursor) {
  12940. opts.cursorOffset++;
  12941. }
  12942. if (hasRangeStart) {
  12943. opts.rangeStart++;
  12944. }
  12945. if (hasRangeEnd) {
  12946. opts.rangeEnd++;
  12947. }
  12948. }
  12949. if (!hasCursor) {
  12950. opts.cursorOffset = -1;
  12951. }
  12952. if (opts.rangeStart < 0) {
  12953. opts.rangeStart = 0;
  12954. }
  12955. if (opts.rangeEnd > text.length) {
  12956. opts.rangeEnd = text.length;
  12957. }
  12958. var result = hasRangeStart || hasRangeEnd ? formatRange(text, opts) : coreFormat(opts.insertPragma && opts.printer.insertPragma && !hasPragma ? opts.printer.insertPragma(text) : text, opts);
  12959. if (hasUnicodeBOM) {
  12960. result.formatted = String.fromCharCode(UTF8BOM) + result.formatted;
  12961. if (hasCursor) {
  12962. result.cursorOffset++;
  12963. }
  12964. }
  12965. return result;
  12966. }
  12967. var core = {
  12968. formatWithCursor: function formatWithCursor(text, opts) {
  12969. opts = normalizeOptions$1(opts);
  12970. return format(text, opts);
  12971. },
  12972. parse: function parse(text, opts, massage) {
  12973. opts = normalizeOptions$1(opts);
  12974. if (text.indexOf("\r") !== -1) {
  12975. text = text.replace(/\r\n?/g, "\n");
  12976. }
  12977. var parsed = parser.parse(text, opts);
  12978. if (massage) {
  12979. parsed.ast = massageAst(parsed.ast, opts);
  12980. }
  12981. return parsed;
  12982. },
  12983. formatAST: function formatAST(ast, opts) {
  12984. opts = normalizeOptions$1(opts);
  12985. var doc = astToDoc(ast, opts);
  12986. return _printDocToString(doc, opts);
  12987. },
  12988. // Doesn't handle shebang for now
  12989. formatDoc: function formatDoc(doc, opts) {
  12990. var debug = printDocToDebug(doc);
  12991. opts = normalizeOptions$1(Object.assign({}, opts, {
  12992. parser: "babel"
  12993. }));
  12994. return format(debug, opts).formatted;
  12995. },
  12996. printToDoc: function printToDoc(text, opts) {
  12997. opts = normalizeOptions$1(opts);
  12998. var parsed = parser.parse(text, opts);
  12999. var ast = parsed.ast;
  13000. text = parsed.text;
  13001. attachComments(text, ast, opts);
  13002. return astToDoc(ast, opts);
  13003. },
  13004. printDocToString: function printDocToString(doc, opts) {
  13005. return _printDocToString(doc, normalizeOptions$1(opts));
  13006. }
  13007. };
  13008. var index = [
  13009. "a",
  13010. "abbr",
  13011. "acronym",
  13012. "address",
  13013. "applet",
  13014. "area",
  13015. "article",
  13016. "aside",
  13017. "audio",
  13018. "b",
  13019. "base",
  13020. "basefont",
  13021. "bdi",
  13022. "bdo",
  13023. "bgsound",
  13024. "big",
  13025. "blink",
  13026. "blockquote",
  13027. "body",
  13028. "br",
  13029. "button",
  13030. "canvas",
  13031. "caption",
  13032. "center",
  13033. "cite",
  13034. "code",
  13035. "col",
  13036. "colgroup",
  13037. "command",
  13038. "content",
  13039. "data",
  13040. "datalist",
  13041. "dd",
  13042. "del",
  13043. "details",
  13044. "dfn",
  13045. "dialog",
  13046. "dir",
  13047. "div",
  13048. "dl",
  13049. "dt",
  13050. "element",
  13051. "em",
  13052. "embed",
  13053. "fieldset",
  13054. "figcaption",
  13055. "figure",
  13056. "font",
  13057. "footer",
  13058. "form",
  13059. "frame",
  13060. "frameset",
  13061. "h1",
  13062. "h2",
  13063. "h3",
  13064. "h4",
  13065. "h5",
  13066. "h6",
  13067. "head",
  13068. "header",
  13069. "hgroup",
  13070. "hr",
  13071. "html",
  13072. "i",
  13073. "iframe",
  13074. "image",
  13075. "img",
  13076. "input",
  13077. "ins",
  13078. "isindex",
  13079. "kbd",
  13080. "keygen",
  13081. "label",
  13082. "legend",
  13083. "li",
  13084. "link",
  13085. "listing",
  13086. "main",
  13087. "map",
  13088. "mark",
  13089. "marquee",
  13090. "math",
  13091. "menu",
  13092. "menuitem",
  13093. "meta",
  13094. "meter",
  13095. "multicol",
  13096. "nav",
  13097. "nextid",
  13098. "nobr",
  13099. "noembed",
  13100. "noframes",
  13101. "noscript",
  13102. "object",
  13103. "ol",
  13104. "optgroup",
  13105. "option",
  13106. "output",
  13107. "p",
  13108. "param",
  13109. "picture",
  13110. "plaintext",
  13111. "pre",
  13112. "progress",
  13113. "q",
  13114. "rb",
  13115. "rbc",
  13116. "rp",
  13117. "rt",
  13118. "rtc",
  13119. "ruby",
  13120. "s",
  13121. "samp",
  13122. "script",
  13123. "section",
  13124. "select",
  13125. "shadow",
  13126. "slot",
  13127. "small",
  13128. "source",
  13129. "spacer",
  13130. "span",
  13131. "strike",
  13132. "strong",
  13133. "style",
  13134. "sub",
  13135. "summary",
  13136. "sup",
  13137. "svg",
  13138. "table",
  13139. "tbody",
  13140. "td",
  13141. "template",
  13142. "textarea",
  13143. "tfoot",
  13144. "th",
  13145. "thead",
  13146. "time",
  13147. "title",
  13148. "tr",
  13149. "track",
  13150. "tt",
  13151. "u",
  13152. "ul",
  13153. "var",
  13154. "video",
  13155. "wbr",
  13156. "xmp"
  13157. ];
  13158. var htmlTagNames = /*#__PURE__*/Object.freeze({
  13159. __proto__: null,
  13160. 'default': index
  13161. });
  13162. var htmlTagNames$1 = getCjsExportFromNamespace(htmlTagNames);
  13163. function clean(ast, newObj, parent) {
  13164. ["raw", // front-matter
  13165. "raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(function (name) {
  13166. delete newObj[name];
  13167. });
  13168. if (ast.type === "yaml") {
  13169. delete newObj.value;
  13170. } // --insert-pragma
  13171. if (ast.type === "css-comment" && parent.type === "css-root" && parent.nodes.length !== 0 && ( // first non-front-matter comment
  13172. parent.nodes[0] === ast || (parent.nodes[0].type === "yaml" || parent.nodes[0].type === "toml") && parent.nodes[1] === ast)) {
  13173. /**
  13174. * something
  13175. *
  13176. * @format
  13177. */
  13178. delete newObj.text; // standalone pragma
  13179. if (/^\*\s*@(format|prettier)\s*$/.test(ast.text)) {
  13180. return null;
  13181. }
  13182. }
  13183. if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
  13184. delete newObj.value;
  13185. }
  13186. if (ast.type === "css-rule") {
  13187. delete newObj.params;
  13188. }
  13189. if (ast.type === "selector-combinator") {
  13190. newObj.value = newObj.value.replace(/\s+/g, " ");
  13191. }
  13192. if (ast.type === "media-feature") {
  13193. newObj.value = newObj.value.replace(/ /g, "");
  13194. }
  13195. if (ast.type === "value-word" && (ast.isColor && ast.isHex || ["initial", "inherit", "unset", "revert"].indexOf(newObj.value.replace().toLowerCase()) !== -1) || ast.type === "media-feature" || ast.type === "selector-root-invalid" || ast.type === "selector-pseudo") {
  13196. newObj.value = newObj.value.toLowerCase();
  13197. }
  13198. if (ast.type === "css-decl") {
  13199. newObj.prop = newObj.prop.toLowerCase();
  13200. }
  13201. if (ast.type === "css-atrule" || ast.type === "css-import") {
  13202. newObj.name = newObj.name.toLowerCase();
  13203. }
  13204. if (ast.type === "value-number") {
  13205. newObj.unit = newObj.unit.toLowerCase();
  13206. }
  13207. if ((ast.type === "media-feature" || ast.type === "media-keyword" || ast.type === "media-type" || ast.type === "media-unknown" || ast.type === "media-url" || ast.type === "media-value" || ast.type === "selector-attribute" || ast.type === "selector-string" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "value-string") && newObj.value) {
  13208. newObj.value = cleanCSSStrings(newObj.value);
  13209. }
  13210. if (ast.type === "selector-attribute") {
  13211. newObj.attribute = newObj.attribute.trim();
  13212. if (newObj.namespace) {
  13213. if (typeof newObj.namespace === "string") {
  13214. newObj.namespace = newObj.namespace.trim();
  13215. if (newObj.namespace.length === 0) {
  13216. newObj.namespace = true;
  13217. }
  13218. }
  13219. }
  13220. if (newObj.value) {
  13221. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  13222. delete newObj.quoted;
  13223. }
  13224. }
  13225. if ((ast.type === "media-value" || ast.type === "media-type" || ast.type === "value-number" || ast.type === "selector-root-invalid" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "selector-tag") && newObj.value) {
  13226. newObj.value = newObj.value.replace(/([\d.eE+-]+)([a-zA-Z]*)/g, function (match, numStr, unit) {
  13227. var num = Number(numStr);
  13228. return isNaN(num) ? match : num + unit.toLowerCase();
  13229. });
  13230. }
  13231. if (ast.type === "selector-tag") {
  13232. var lowercasedValue = ast.value.toLowerCase();
  13233. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  13234. newObj.value = lowercasedValue;
  13235. }
  13236. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  13237. newObj.value = lowercasedValue;
  13238. }
  13239. } // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
  13240. if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
  13241. delete newObj.value;
  13242. } // Workaround for SCSS nested properties
  13243. if (ast.type === "selector-unknown") {
  13244. delete newObj.value;
  13245. }
  13246. }
  13247. function cleanCSSStrings(value) {
  13248. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  13249. }
  13250. var clean_1 = clean;
  13251. var _require$$0$builders$1 = doc.builders,
  13252. hardline$3 = _require$$0$builders$1.hardline,
  13253. literalline$1 = _require$$0$builders$1.literalline,
  13254. concat$4 = _require$$0$builders$1.concat,
  13255. markAsRoot$1 = _require$$0$builders$1.markAsRoot,
  13256. mapDoc$3 = doc.utils.mapDoc;
  13257. function embed(path, print, textToDoc
  13258. /*, options */
  13259. ) {
  13260. var node = path.getValue();
  13261. if (node.type === "yaml") {
  13262. return markAsRoot$1(concat$4(["---", hardline$3, node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  13263. parser: "yaml"
  13264. })) : "", "---", hardline$3]));
  13265. }
  13266. return null;
  13267. function replaceNewlinesWithLiterallines(doc) {
  13268. return mapDoc$3(doc, function (currentDoc) {
  13269. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$4(currentDoc.split(/(\n)/g).map(function (v, i) {
  13270. return i % 2 === 0 ? v : literalline$1;
  13271. })) : currentDoc;
  13272. });
  13273. }
  13274. }
  13275. var embed_1 = embed;
  13276. var detectNewline = createCommonjsModule(function (module) {
  13277. module.exports = function (str) {
  13278. if (typeof str !== 'string') {
  13279. throw new TypeError('Expected a string');
  13280. }
  13281. var newlines = str.match(/(?:\r?\n)/g) || [];
  13282. if (newlines.length === 0) {
  13283. return null;
  13284. }
  13285. var crlf = newlines.filter(function (el) {
  13286. return el === '\r\n';
  13287. }).length;
  13288. var lf = newlines.length - crlf;
  13289. return crlf > lf ? '\r\n' : '\n';
  13290. };
  13291. module.exports.graceful = function (str) {
  13292. return module.exports(str) || '\n';
  13293. };
  13294. });
  13295. var detectNewline_1 = detectNewline.graceful;
  13296. var build = createCommonjsModule(function (module, exports) {
  13297. Object.defineProperty(exports, '__esModule', {
  13298. value: true
  13299. });
  13300. exports.extract = extract;
  13301. exports.strip = strip;
  13302. exports.parse = parse;
  13303. exports.parseWithComments = parseWithComments;
  13304. exports.print = print;
  13305. function _os() {
  13306. var data = require$$0$1;
  13307. _os = function _os() {
  13308. return data;
  13309. };
  13310. return data;
  13311. }
  13312. function _detectNewline() {
  13313. var data = _interopRequireDefault(detectNewline);
  13314. _detectNewline = function _detectNewline() {
  13315. return data;
  13316. };
  13317. return data;
  13318. }
  13319. function _interopRequireDefault(obj) {
  13320. return obj && obj.__esModule ? obj : {
  13321. default: obj
  13322. };
  13323. }
  13324. /**
  13325. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  13326. *
  13327. * This source code is licensed under the MIT license found in the
  13328. * LICENSE file in the root directory of this source tree.
  13329. */
  13330. var commentEndRe = /\*\/$/;
  13331. var commentStartRe = /^\/\*\*/;
  13332. var docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
  13333. var lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
  13334. var ltrimNewlineRe = /^(\r?\n)+/;
  13335. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  13336. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  13337. var stringStartRe = /(\r?\n|^) *\* ?/g;
  13338. function extract(contents) {
  13339. var match = contents.match(docblockRe);
  13340. return match ? match[0].trimLeft() : '';
  13341. }
  13342. function strip(contents) {
  13343. var match = contents.match(docblockRe);
  13344. return match && match[0] ? contents.substring(match[0].length) : contents;
  13345. }
  13346. function parse(docblock) {
  13347. return parseWithComments(docblock).pragmas;
  13348. }
  13349. function parseWithComments(docblock) {
  13350. var line = (0, _detectNewline().default)(docblock) || _os().EOL;
  13351. docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  13352. var prev = '';
  13353. while (prev !== docblock) {
  13354. prev = docblock;
  13355. docblock = docblock.replace(multilineRe, "".concat(line, "$1 $2").concat(line));
  13356. }
  13357. docblock = docblock.replace(ltrimNewlineRe, '').trimRight();
  13358. var result = Object.create(null);
  13359. var comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').trimRight();
  13360. var match;
  13361. while (match = propertyRe.exec(docblock)) {
  13362. // strip linecomments from pragmas
  13363. var nextPragma = match[2].replace(lineCommentRe, '');
  13364. if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
  13365. result[match[1]] = [].concat(result[match[1]], nextPragma);
  13366. } else {
  13367. result[match[1]] = nextPragma;
  13368. }
  13369. }
  13370. return {
  13371. comments: comments,
  13372. pragmas: result
  13373. };
  13374. }
  13375. function print(_ref) {
  13376. var _ref$comments = _ref.comments,
  13377. comments = _ref$comments === void 0 ? '' : _ref$comments,
  13378. _ref$pragmas = _ref.pragmas,
  13379. pragmas = _ref$pragmas === void 0 ? {} : _ref$pragmas;
  13380. var line = (0, _detectNewline().default)(comments) || _os().EOL;
  13381. var head = '/**';
  13382. var start = ' *';
  13383. var tail = ' */';
  13384. var keys = Object.keys(pragmas);
  13385. var printedObject = keys.map(function (key) {
  13386. return printKeyValues(key, pragmas[key]);
  13387. }).reduce(function (arr, next) {
  13388. return arr.concat(next);
  13389. }, []).map(function (keyValue) {
  13390. return start + ' ' + keyValue + line;
  13391. }).join('');
  13392. if (!comments) {
  13393. if (keys.length === 0) {
  13394. return '';
  13395. }
  13396. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  13397. var value = pragmas[keys[0]];
  13398. return "".concat(head, " ").concat(printKeyValues(keys[0], value)[0]).concat(tail);
  13399. }
  13400. }
  13401. var printedComments = comments.split(line).map(function (textLine) {
  13402. return "".concat(start, " ").concat(textLine);
  13403. }).join(line) + line;
  13404. return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail;
  13405. }
  13406. function printKeyValues(key, valueOrArray) {
  13407. return [].concat(valueOrArray).map(function (value) {
  13408. return "@".concat(key, " ").concat(value).trim();
  13409. });
  13410. }
  13411. });
  13412. unwrapExports(build);
  13413. var build_1 = build.extract;
  13414. var build_2 = build.strip;
  13415. var build_3 = build.parse;
  13416. var build_4 = build.parseWithComments;
  13417. var build_5 = build.print;
  13418. function hasPragma(text) {
  13419. var pragmas = Object.keys(build.parse(build.extract(text)));
  13420. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  13421. }
  13422. function insertPragma(text) {
  13423. var parsedDocblock = build.parseWithComments(build.extract(text));
  13424. var pragmas = Object.assign({
  13425. format: ""
  13426. }, parsedDocblock.pragmas);
  13427. var newDocblock = build.print({
  13428. pragmas: pragmas,
  13429. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  13430. }).replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
  13431. var strippedText = build.strip(text);
  13432. var separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  13433. return newDocblock + separatingNewlines + strippedText;
  13434. }
  13435. var pragma = {
  13436. hasPragma: hasPragma,
  13437. insertPragma: insertPragma
  13438. };
  13439. var DELIMITER_MAP = {
  13440. "---": "yaml",
  13441. "+++": "toml"
  13442. };
  13443. function parse$1(text) {
  13444. var delimiterRegex = Object.keys(DELIMITER_MAP).map(escapeStringRegexp).join("|");
  13445. var match = text.match( // trailing spaces after delimiters are allowed
  13446. new RegExp("^(".concat(delimiterRegex, ")[^\\n\\S]*\\n(?:([\\s\\S]*?)\\n)?\\1[^\\n\\S]*(\\n|$)")));
  13447. if (match === null) {
  13448. return {
  13449. frontMatter: null,
  13450. content: text
  13451. };
  13452. }
  13453. var raw = match[0].replace(/\n$/, "");
  13454. var delimiter = match[1];
  13455. var value = match[2];
  13456. return {
  13457. frontMatter: {
  13458. type: DELIMITER_MAP[delimiter],
  13459. value: value,
  13460. raw: raw
  13461. },
  13462. content: match[0].replace(/[^\n]/g, " ") + text.slice(match[0].length)
  13463. };
  13464. }
  13465. var frontMatter = parse$1;
  13466. function hasPragma$1(text) {
  13467. return pragma.hasPragma(frontMatter(text).content);
  13468. }
  13469. function insertPragma$1(text) {
  13470. var _parseFrontMatter = frontMatter(text),
  13471. frontMatter$1 = _parseFrontMatter.frontMatter,
  13472. content = _parseFrontMatter.content;
  13473. return (frontMatter$1 ? frontMatter$1.raw + "\n\n" : "") + pragma.insertPragma(content);
  13474. }
  13475. var pragma$1 = {
  13476. hasPragma: hasPragma$1,
  13477. insertPragma: insertPragma$1
  13478. };
  13479. var colorAdjusterFunctions = ["red", "green", "blue", "alpha", "a", "rgb", "hue", "h", "saturation", "s", "lightness", "l", "whiteness", "w", "blackness", "b", "tint", "shade", "blend", "blenda", "contrast", "hsl", "hsla", "hwb", "hwba"];
  13480. function getAncestorCounter(path, typeOrTypes) {
  13481. var types = [].concat(typeOrTypes);
  13482. var counter = -1;
  13483. var ancestorNode;
  13484. while (ancestorNode = path.getParentNode(++counter)) {
  13485. if (types.indexOf(ancestorNode.type) !== -1) {
  13486. return counter;
  13487. }
  13488. }
  13489. return -1;
  13490. }
  13491. function getAncestorNode(path, typeOrTypes) {
  13492. var counter = getAncestorCounter(path, typeOrTypes);
  13493. return counter === -1 ? null : path.getParentNode(counter);
  13494. }
  13495. function getPropOfDeclNode(path) {
  13496. var declAncestorNode = getAncestorNode(path, "css-decl");
  13497. return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
  13498. }
  13499. function isSCSS(parser, text) {
  13500. var hasExplicitParserChoice = parser === "less" || parser === "scss";
  13501. var IS_POSSIBLY_SCSS = /(\w\s*: [^}:]+|#){|@import[^\n]+(url|,)/;
  13502. return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
  13503. }
  13504. function isWideKeywords(value) {
  13505. return ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== -1;
  13506. }
  13507. function isKeyframeAtRuleKeywords(path, value) {
  13508. var atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  13509. return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].indexOf(value.toLowerCase()) !== -1;
  13510. }
  13511. function maybeToLowerCase(value) {
  13512. return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
  13513. }
  13514. function insideValueFunctionNode(path, functionName) {
  13515. var funcAncestorNode = getAncestorNode(path, "value-func");
  13516. return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
  13517. }
  13518. function insideICSSRuleNode(path) {
  13519. var ruleAncestorNode = getAncestorNode(path, "css-rule");
  13520. return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
  13521. }
  13522. function insideAtRuleNode(path, atRuleNameOrAtRuleNames) {
  13523. var atRuleNames = [].concat(atRuleNameOrAtRuleNames);
  13524. var atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  13525. return atRuleAncestorNode && atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1;
  13526. }
  13527. function insideURLFunctionInImportAtRuleNode(path) {
  13528. var node = path.getValue();
  13529. var atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  13530. return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
  13531. }
  13532. function isURLFunctionNode(node) {
  13533. return node.type === "value-func" && node.value.toLowerCase() === "url";
  13534. }
  13535. function isLastNode(path, node) {
  13536. var parentNode = path.getParentNode();
  13537. if (!parentNode) {
  13538. return false;
  13539. }
  13540. var nodes = parentNode.nodes;
  13541. return nodes && nodes.indexOf(node) === nodes.length - 1;
  13542. }
  13543. function isHTMLTag(value) {
  13544. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  13545. }
  13546. function isDetachedRulesetDeclarationNode(node) {
  13547. // If a Less file ends up being parsed with the SCSS parser, Less
  13548. // variable declarations will be parsed as atrules with names ending
  13549. // with a colon, so keep the original case then.
  13550. if (!node.selector) {
  13551. return false;
  13552. }
  13553. return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
  13554. }
  13555. function isForKeywordNode(node) {
  13556. return node.type === "value-word" && ["from", "through", "end"].indexOf(node.value) !== -1;
  13557. }
  13558. function isIfElseKeywordNode(node) {
  13559. return node.type === "value-word" && ["and", "or", "not"].indexOf(node.value) !== -1;
  13560. }
  13561. function isEachKeywordNode(node) {
  13562. return node.type === "value-word" && node.value === "in";
  13563. }
  13564. function isMultiplicationNode(node) {
  13565. return node.type === "value-operator" && node.value === "*";
  13566. }
  13567. function isDivisionNode(node) {
  13568. return node.type === "value-operator" && node.value === "/";
  13569. }
  13570. function isAdditionNode(node) {
  13571. return node.type === "value-operator" && node.value === "+";
  13572. }
  13573. function isSubtractionNode(node) {
  13574. return node.type === "value-operator" && node.value === "-";
  13575. }
  13576. function isModuloNode(node) {
  13577. return node.type === "value-operator" && node.value === "%";
  13578. }
  13579. function isMathOperatorNode(node) {
  13580. return isMultiplicationNode(node) || isDivisionNode(node) || isAdditionNode(node) || isSubtractionNode(node) || isModuloNode(node);
  13581. }
  13582. function isEqualityOperatorNode(node) {
  13583. return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1;
  13584. }
  13585. function isRelationalOperatorNode(node) {
  13586. return node.type === "value-word" && ["<", ">", "<=", ">="].indexOf(node.value) !== -1;
  13587. }
  13588. function isSCSSControlDirectiveNode(node) {
  13589. return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1;
  13590. }
  13591. function isSCSSNestedPropertyNode(node) {
  13592. if (!node.selector) {
  13593. return false;
  13594. }
  13595. return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
  13596. }
  13597. function isDetachedRulesetCallNode(node) {
  13598. return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
  13599. }
  13600. function isTemplatePlaceholderNode(node) {
  13601. return node.name.startsWith("prettier-placeholder");
  13602. }
  13603. function isTemplatePropNode(node) {
  13604. return node.prop.startsWith("@prettier-placeholder");
  13605. }
  13606. function isPostcssSimpleVarNode(currentNode, nextNode) {
  13607. return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
  13608. }
  13609. function hasComposesNode(node) {
  13610. return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
  13611. }
  13612. function hasParensAroundNode(node) {
  13613. return node.value && node.value.group && node.value.group.group && node.value.group.group.type === "value-paren_group" && node.value.group.group.open !== null && node.value.group.group.close !== null;
  13614. }
  13615. function hasEmptyRawBefore(node) {
  13616. return node.raws && node.raws.before === "";
  13617. }
  13618. function isKeyValuePairNode(node) {
  13619. return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
  13620. }
  13621. function isKeyValuePairInParenGroupNode(node) {
  13622. return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode(node.groups[0]);
  13623. }
  13624. function isSCSSMapItemNode(path) {
  13625. var node = path.getValue(); // Ignore empty item (i.e. `$key: ()`)
  13626. if (node.groups.length === 0) {
  13627. return false;
  13628. }
  13629. var parentParentNode = path.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
  13630. if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
  13631. return false;
  13632. }
  13633. var declNode = getAncestorNode(path, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
  13634. if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
  13635. return true;
  13636. } // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
  13637. if (isKeyValuePairInParenGroupNode(parentParentNode)) {
  13638. return true;
  13639. } // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
  13640. if (parentParentNode.type === "value-func") {
  13641. return true;
  13642. }
  13643. return false;
  13644. }
  13645. function isInlineValueCommentNode(node) {
  13646. return node.type === "value-comment" && node.inline;
  13647. }
  13648. function isHashNode(node) {
  13649. return node.type === "value-word" && node.value === "#";
  13650. }
  13651. function isLeftCurlyBraceNode(node) {
  13652. return node.type === "value-word" && node.value === "{";
  13653. }
  13654. function isRightCurlyBraceNode(node) {
  13655. return node.type === "value-word" && node.value === "}";
  13656. }
  13657. function isWordNode(node) {
  13658. return ["value-word", "value-atword"].indexOf(node.type) !== -1;
  13659. }
  13660. function isColonNode(node) {
  13661. return node.type === "value-colon";
  13662. }
  13663. function isMediaAndSupportsKeywords(node) {
  13664. return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
  13665. }
  13666. function isColorAdjusterFuncNode(node) {
  13667. if (node.type !== "value-func") {
  13668. return false;
  13669. }
  13670. return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
  13671. }
  13672. var utils$2 = {
  13673. getAncestorCounter: getAncestorCounter,
  13674. getAncestorNode: getAncestorNode,
  13675. getPropOfDeclNode: getPropOfDeclNode,
  13676. maybeToLowerCase: maybeToLowerCase,
  13677. insideValueFunctionNode: insideValueFunctionNode,
  13678. insideICSSRuleNode: insideICSSRuleNode,
  13679. insideAtRuleNode: insideAtRuleNode,
  13680. insideURLFunctionInImportAtRuleNode: insideURLFunctionInImportAtRuleNode,
  13681. isKeyframeAtRuleKeywords: isKeyframeAtRuleKeywords,
  13682. isHTMLTag: isHTMLTag,
  13683. isWideKeywords: isWideKeywords,
  13684. isSCSS: isSCSS,
  13685. isLastNode: isLastNode,
  13686. isSCSSControlDirectiveNode: isSCSSControlDirectiveNode,
  13687. isDetachedRulesetDeclarationNode: isDetachedRulesetDeclarationNode,
  13688. isRelationalOperatorNode: isRelationalOperatorNode,
  13689. isEqualityOperatorNode: isEqualityOperatorNode,
  13690. isMultiplicationNode: isMultiplicationNode,
  13691. isDivisionNode: isDivisionNode,
  13692. isAdditionNode: isAdditionNode,
  13693. isSubtractionNode: isSubtractionNode,
  13694. isModuloNode: isModuloNode,
  13695. isMathOperatorNode: isMathOperatorNode,
  13696. isEachKeywordNode: isEachKeywordNode,
  13697. isForKeywordNode: isForKeywordNode,
  13698. isURLFunctionNode: isURLFunctionNode,
  13699. isIfElseKeywordNode: isIfElseKeywordNode,
  13700. hasComposesNode: hasComposesNode,
  13701. hasParensAroundNode: hasParensAroundNode,
  13702. hasEmptyRawBefore: hasEmptyRawBefore,
  13703. isSCSSNestedPropertyNode: isSCSSNestedPropertyNode,
  13704. isDetachedRulesetCallNode: isDetachedRulesetCallNode,
  13705. isTemplatePlaceholderNode: isTemplatePlaceholderNode,
  13706. isTemplatePropNode: isTemplatePropNode,
  13707. isPostcssSimpleVarNode: isPostcssSimpleVarNode,
  13708. isKeyValuePairNode: isKeyValuePairNode,
  13709. isKeyValuePairInParenGroupNode: isKeyValuePairInParenGroupNode,
  13710. isSCSSMapItemNode: isSCSSMapItemNode,
  13711. isInlineValueCommentNode: isInlineValueCommentNode,
  13712. isHashNode: isHashNode,
  13713. isLeftCurlyBraceNode: isLeftCurlyBraceNode,
  13714. isRightCurlyBraceNode: isRightCurlyBraceNode,
  13715. isWordNode: isWordNode,
  13716. isColonNode: isColonNode,
  13717. isMediaAndSupportsKeywords: isMediaAndSupportsKeywords,
  13718. isColorAdjusterFuncNode: isColorAdjusterFuncNode
  13719. };
  13720. var insertPragma$2 = pragma$1.insertPragma;
  13721. var printNumber$1 = util.printNumber,
  13722. printString$1 = util.printString,
  13723. hasIgnoreComment$1 = util.hasIgnoreComment,
  13724. hasNewline$2 = util.hasNewline;
  13725. var isNextLineEmpty$2 = utilShared.isNextLineEmpty;
  13726. var _require$$3$builders = doc.builders,
  13727. concat$5 = _require$$3$builders.concat,
  13728. join$2 = _require$$3$builders.join,
  13729. line$1 = _require$$3$builders.line,
  13730. hardline$4 = _require$$3$builders.hardline,
  13731. softline$1 = _require$$3$builders.softline,
  13732. group$1 = _require$$3$builders.group,
  13733. fill$2 = _require$$3$builders.fill,
  13734. indent$2 = _require$$3$builders.indent,
  13735. dedent$1 = _require$$3$builders.dedent,
  13736. ifBreak$1 = _require$$3$builders.ifBreak,
  13737. removeLines$1 = doc.utils.removeLines;
  13738. var getAncestorNode$1 = utils$2.getAncestorNode,
  13739. getPropOfDeclNode$1 = utils$2.getPropOfDeclNode,
  13740. maybeToLowerCase$1 = utils$2.maybeToLowerCase,
  13741. insideValueFunctionNode$1 = utils$2.insideValueFunctionNode,
  13742. insideICSSRuleNode$1 = utils$2.insideICSSRuleNode,
  13743. insideAtRuleNode$1 = utils$2.insideAtRuleNode,
  13744. insideURLFunctionInImportAtRuleNode$1 = utils$2.insideURLFunctionInImportAtRuleNode,
  13745. isKeyframeAtRuleKeywords$1 = utils$2.isKeyframeAtRuleKeywords,
  13746. isHTMLTag$1 = utils$2.isHTMLTag,
  13747. isWideKeywords$1 = utils$2.isWideKeywords,
  13748. isSCSS$1 = utils$2.isSCSS,
  13749. isLastNode$1 = utils$2.isLastNode,
  13750. isSCSSControlDirectiveNode$1 = utils$2.isSCSSControlDirectiveNode,
  13751. isDetachedRulesetDeclarationNode$1 = utils$2.isDetachedRulesetDeclarationNode,
  13752. isRelationalOperatorNode$1 = utils$2.isRelationalOperatorNode,
  13753. isEqualityOperatorNode$1 = utils$2.isEqualityOperatorNode,
  13754. isMultiplicationNode$1 = utils$2.isMultiplicationNode,
  13755. isDivisionNode$1 = utils$2.isDivisionNode,
  13756. isAdditionNode$1 = utils$2.isAdditionNode,
  13757. isSubtractionNode$1 = utils$2.isSubtractionNode,
  13758. isMathOperatorNode$1 = utils$2.isMathOperatorNode,
  13759. isEachKeywordNode$1 = utils$2.isEachKeywordNode,
  13760. isForKeywordNode$1 = utils$2.isForKeywordNode,
  13761. isURLFunctionNode$1 = utils$2.isURLFunctionNode,
  13762. isIfElseKeywordNode$1 = utils$2.isIfElseKeywordNode,
  13763. hasComposesNode$1 = utils$2.hasComposesNode,
  13764. hasParensAroundNode$1 = utils$2.hasParensAroundNode,
  13765. hasEmptyRawBefore$1 = utils$2.hasEmptyRawBefore,
  13766. isKeyValuePairNode$1 = utils$2.isKeyValuePairNode,
  13767. isDetachedRulesetCallNode$1 = utils$2.isDetachedRulesetCallNode,
  13768. isTemplatePlaceholderNode$1 = utils$2.isTemplatePlaceholderNode,
  13769. isTemplatePropNode$1 = utils$2.isTemplatePropNode,
  13770. isPostcssSimpleVarNode$1 = utils$2.isPostcssSimpleVarNode,
  13771. isSCSSMapItemNode$1 = utils$2.isSCSSMapItemNode,
  13772. isInlineValueCommentNode$1 = utils$2.isInlineValueCommentNode,
  13773. isHashNode$1 = utils$2.isHashNode,
  13774. isLeftCurlyBraceNode$1 = utils$2.isLeftCurlyBraceNode,
  13775. isRightCurlyBraceNode$1 = utils$2.isRightCurlyBraceNode,
  13776. isWordNode$1 = utils$2.isWordNode,
  13777. isColonNode$1 = utils$2.isColonNode,
  13778. isMediaAndSupportsKeywords$1 = utils$2.isMediaAndSupportsKeywords,
  13779. isColorAdjusterFuncNode$1 = utils$2.isColorAdjusterFuncNode;
  13780. function shouldPrintComma(options) {
  13781. switch (options.trailingComma) {
  13782. case "all":
  13783. case "es5":
  13784. return true;
  13785. case "none":
  13786. default:
  13787. return false;
  13788. }
  13789. }
  13790. function genericPrint(path, options, print) {
  13791. var node = path.getValue();
  13792. /* istanbul ignore if */
  13793. if (!node) {
  13794. return "";
  13795. }
  13796. if (typeof node === "string") {
  13797. return node;
  13798. }
  13799. switch (node.type) {
  13800. case "yaml":
  13801. case "toml":
  13802. return concat$5([node.raw, hardline$4]);
  13803. case "css-root":
  13804. {
  13805. var nodes = printNodeSequence(path, options, print);
  13806. if (nodes.parts.length) {
  13807. return concat$5([nodes, hardline$4]);
  13808. }
  13809. return nodes;
  13810. }
  13811. case "css-comment":
  13812. {
  13813. if (node.raws.content) {
  13814. return node.raws.content;
  13815. }
  13816. var text = options.originalText.slice(options.locStart(node), options.locEnd(node));
  13817. var rawText = node.raws.text || node.text; // Workaround a bug where the location is off.
  13818. // https://github.com/postcss/postcss-scss/issues/63
  13819. if (text.indexOf(rawText) === -1) {
  13820. if (node.raws.inline) {
  13821. return concat$5(["// ", rawText]);
  13822. }
  13823. return concat$5(["/* ", rawText, " */"]);
  13824. }
  13825. return text;
  13826. }
  13827. case "css-rule":
  13828. {
  13829. return concat$5([path.call(print, "selector"), node.important ? " !important" : "", node.nodes ? concat$5([" {", node.nodes.length > 0 ? indent$2(concat$5([hardline$4, printNodeSequence(path, options, print)])) : "", hardline$4, "}", isDetachedRulesetDeclarationNode$1(node) ? ";" : ""]) : ";"]);
  13830. }
  13831. case "css-decl":
  13832. {
  13833. var parentNode = path.getParentNode();
  13834. return concat$5([node.raws.before.replace(/[\s;]/g, ""), insideICSSRuleNode$1(path) ? node.prop : maybeToLowerCase$1(node.prop), node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(), node.extend ? "" : " ", hasComposesNode$1(node) ? removeLines$1(path.call(print, "value")) : path.call(print, "value"), node.raws.important ? node.raws.important.replace(/\s*!\s*important/i, " !important") : node.important ? " !important" : "", node.raws.scssDefault ? node.raws.scssDefault.replace(/\s*!default/i, " !default") : node.scssDefault ? " !default" : "", node.raws.scssGlobal ? node.raws.scssGlobal.replace(/\s*!global/i, " !global") : node.scssGlobal ? " !global" : "", node.nodes ? concat$5([" {", indent$2(concat$5([softline$1, printNodeSequence(path, options, print)])), softline$1, "}"]) : isTemplatePropNode$1(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
  13835. }
  13836. case "css-atrule":
  13837. {
  13838. var _parentNode = path.getParentNode();
  13839. return concat$5(["@", // If a Less file ends up being parsed with the SCSS parser, Less
  13840. // variable declarations will be parsed as at-rules with names ending
  13841. // with a colon, so keep the original case then.
  13842. isDetachedRulesetCallNode$1(node) || node.name.endsWith(":") ? node.name : maybeToLowerCase$1(node.name), node.params ? concat$5([isDetachedRulesetCallNode$1(node) ? "" : isTemplatePlaceholderNode$1(node) && /^\s*\n/.test(node.raws.afterName) ? /^\s*\n\s*\n/.test(node.raws.afterName) ? concat$5([hardline$4, hardline$4]) : hardline$4 : " ", path.call(print, "params")]) : "", node.selector ? indent$2(concat$5([" ", path.call(print, "selector")])) : "", node.value ? group$1(concat$5([" ", path.call(print, "value"), isSCSSControlDirectiveNode$1(node) ? hasParensAroundNode$1(node) ? " " : line$1 : ""])) : node.name === "else" ? " " : "", node.nodes ? concat$5([isSCSSControlDirectiveNode$1(node) ? "" : " ", "{", indent$2(concat$5([node.nodes.length > 0 ? softline$1 : "", printNodeSequence(path, options, print)])), softline$1, "}"]) : isTemplatePlaceholderNode$1(node) && !_parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
  13843. }
  13844. // postcss-media-query-parser
  13845. case "media-query-list":
  13846. {
  13847. var parts = [];
  13848. path.each(function (childPath) {
  13849. var node = childPath.getValue();
  13850. if (node.type === "media-query" && node.value === "") {
  13851. return;
  13852. }
  13853. parts.push(childPath.call(print));
  13854. }, "nodes");
  13855. return group$1(indent$2(join$2(line$1, parts)));
  13856. }
  13857. case "media-query":
  13858. {
  13859. return concat$5([join$2(" ", path.map(print, "nodes")), isLastNode$1(path, node) ? "" : ","]);
  13860. }
  13861. case "media-type":
  13862. {
  13863. return adjustNumbers(adjustStrings(node.value, options));
  13864. }
  13865. case "media-feature-expression":
  13866. {
  13867. if (!node.nodes) {
  13868. return node.value;
  13869. }
  13870. return concat$5(["(", concat$5(path.map(print, "nodes")), ")"]);
  13871. }
  13872. case "media-feature":
  13873. {
  13874. return maybeToLowerCase$1(adjustStrings(node.value.replace(/ +/g, " "), options));
  13875. }
  13876. case "media-colon":
  13877. {
  13878. return concat$5([node.value, " "]);
  13879. }
  13880. case "media-value":
  13881. {
  13882. return adjustNumbers(adjustStrings(node.value, options));
  13883. }
  13884. case "media-keyword":
  13885. {
  13886. return adjustStrings(node.value, options);
  13887. }
  13888. case "media-url":
  13889. {
  13890. return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
  13891. }
  13892. case "media-unknown":
  13893. {
  13894. return node.value;
  13895. }
  13896. // postcss-selector-parser
  13897. case "selector-root":
  13898. {
  13899. return group$1(concat$5([insideAtRuleNode$1(path, "custom-selector") ? concat$5([getAncestorNode$1(path, "css-atrule").customSelector, line$1]) : "", join$2(concat$5([",", insideAtRuleNode$1(path, ["extend", "custom-selector", "nest"]) ? line$1 : hardline$4]), path.map(print, "nodes"))]));
  13900. }
  13901. case "selector-selector":
  13902. {
  13903. return group$1(indent$2(concat$5(path.map(print, "nodes"))));
  13904. }
  13905. case "selector-comment":
  13906. {
  13907. return node.value;
  13908. }
  13909. case "selector-string":
  13910. {
  13911. return adjustStrings(node.value, options);
  13912. }
  13913. case "selector-tag":
  13914. {
  13915. var _parentNode2 = path.getParentNode();
  13916. var index = _parentNode2 && _parentNode2.nodes.indexOf(node);
  13917. var prevNode = index && _parentNode2.nodes[index - 1];
  13918. return concat$5([node.namespace ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", prevNode.type === "selector-nesting" ? node.value : adjustNumbers(isHTMLTag$1(node.value) || isKeyframeAtRuleKeywords$1(path, node.value) ? node.value.toLowerCase() : node.value)]);
  13919. }
  13920. case "selector-id":
  13921. {
  13922. return concat$5(["#", node.value]);
  13923. }
  13924. case "selector-class":
  13925. {
  13926. return concat$5([".", adjustNumbers(adjustStrings(node.value, options))]);
  13927. }
  13928. case "selector-attribute":
  13929. {
  13930. return concat$5(["[", node.namespace ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.attribute.trim(), node.operator ? node.operator : "", node.value ? quoteAttributeValue(adjustStrings(node.value.trim(), options), options) : "", node.insensitive ? " i" : "", "]"]);
  13931. }
  13932. case "selector-combinator":
  13933. {
  13934. if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
  13935. var _parentNode3 = path.getParentNode();
  13936. var _leading = _parentNode3.type === "selector-selector" && _parentNode3.nodes[0] === node ? "" : line$1;
  13937. return concat$5([_leading, node.value, isLastNode$1(path, node) ? "" : " "]);
  13938. }
  13939. var leading = node.value.trim().startsWith("(") ? line$1 : "";
  13940. var value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$1;
  13941. return concat$5([leading, value]);
  13942. }
  13943. case "selector-universal":
  13944. {
  13945. return concat$5([node.namespace ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.value]);
  13946. }
  13947. case "selector-pseudo":
  13948. {
  13949. return concat$5([maybeToLowerCase$1(node.value), node.nodes && node.nodes.length > 0 ? concat$5(["(", join$2(", ", path.map(print, "nodes")), ")"]) : ""]);
  13950. }
  13951. case "selector-nesting":
  13952. {
  13953. return node.value;
  13954. }
  13955. case "selector-unknown":
  13956. {
  13957. var ruleAncestorNode = getAncestorNode$1(path, "css-rule"); // Nested SCSS property
  13958. if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
  13959. return adjustNumbers(adjustStrings(maybeToLowerCase$1(node.value), options));
  13960. }
  13961. return node.value;
  13962. }
  13963. // postcss-values-parser
  13964. case "value-value":
  13965. case "value-root":
  13966. {
  13967. return path.call(print, "group");
  13968. }
  13969. case "value-comment":
  13970. {
  13971. return concat$5([node.inline ? "//" : "/*", node.value, node.inline ? "" : "*/"]);
  13972. }
  13973. case "value-comma_group":
  13974. {
  13975. var _parentNode4 = path.getParentNode();
  13976. var parentParentNode = path.getParentNode(1);
  13977. var declAncestorProp = getPropOfDeclNode$1(path);
  13978. var isGridValue = declAncestorProp && _parentNode4.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
  13979. var atRuleAncestorNode = getAncestorNode$1(path, "css-atrule");
  13980. var isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode$1(atRuleAncestorNode);
  13981. var printed = path.map(print, "groups");
  13982. var _parts = [];
  13983. var insideURLFunction = insideValueFunctionNode$1(path, "url");
  13984. var insideSCSSInterpolationInString = false;
  13985. var didBreak = false;
  13986. for (var i = 0; i < node.groups.length; ++i) {
  13987. _parts.push(printed[i]); // Ignore value inside `url()`
  13988. if (insideURLFunction) {
  13989. continue;
  13990. }
  13991. var iPrevNode = node.groups[i - 1];
  13992. var iNode = node.groups[i];
  13993. var iNextNode = node.groups[i + 1];
  13994. var iNextNextNode = node.groups[i + 2]; // Ignore after latest node (i.e. before semicolon)
  13995. if (!iNextNode) {
  13996. continue;
  13997. } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
  13998. var isStartSCSSInterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
  13999. var isEndingSCSSInterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
  14000. if (isStartSCSSInterpolationInString || isEndingSCSSInterpolationInString) {
  14001. insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
  14002. continue;
  14003. }
  14004. if (insideSCSSInterpolationInString) {
  14005. continue;
  14006. } // Ignore colon (i.e. `:`)
  14007. if (isColonNode$1(iNode) || isColonNode$1(iNextNode)) {
  14008. continue;
  14009. } // Ignore `@` in Less (i.e. `@@var;`)
  14010. if (iNode.type === "value-atword" && iNode.value === "") {
  14011. continue;
  14012. } // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  14013. if (iNode.value === "~") {
  14014. continue;
  14015. } // Ignore escape `\`
  14016. if (iNode.value && iNode.value.indexOf("\\") !== -1 && iNextNode && iNextNode.type !== "value-comment") {
  14017. continue;
  14018. } // Ignore escaped `/`
  14019. if (iPrevNode && iPrevNode.value && iPrevNode.value.indexOf("\\") === iPrevNode.value.length - 1 && iNode.type === "value-operator" && iNode.value === "/") {
  14020. continue;
  14021. } // Ignore `\` (i.e. `$variable: \@small;`)
  14022. if (iNode.value === "\\") {
  14023. continue;
  14024. } // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
  14025. if (isPostcssSimpleVarNode$1(iNode, iNextNode)) {
  14026. continue;
  14027. } // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
  14028. if (isHashNode$1(iNode) || isLeftCurlyBraceNode$1(iNode) || isRightCurlyBraceNode$1(iNextNode) || isLeftCurlyBraceNode$1(iNextNode) && hasEmptyRawBefore$1(iNextNode) || isRightCurlyBraceNode$1(iNode) && hasEmptyRawBefore$1(iNextNode)) {
  14029. continue;
  14030. } // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
  14031. if (iNode.value === "--" && isHashNode$1(iNextNode)) {
  14032. continue;
  14033. } // Formatting math operations
  14034. var isMathOperator = isMathOperatorNode$1(iNode);
  14035. var isNextMathOperator = isMathOperatorNode$1(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
  14036. // (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
  14037. // (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
  14038. if ((isMathOperator && isHashNode$1(iNextNode) || isNextMathOperator && isRightCurlyBraceNode$1(iNode)) && hasEmptyRawBefore$1(iNextNode)) {
  14039. continue;
  14040. } // Print spaces before and after addition and subtraction math operators as is in `calc` function
  14041. // due to the fact that it is not valid syntax
  14042. // (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
  14043. if (insideValueFunctionNode$1(path, "calc") && (isAdditionNode$1(iNode) || isAdditionNode$1(iNextNode) || isSubtractionNode$1(iNode) || isSubtractionNode$1(iNextNode)) && hasEmptyRawBefore$1(iNextNode)) {
  14044. continue;
  14045. } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
  14046. // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
  14047. var isColorAdjusterNode = (isAdditionNode$1(iNode) || isSubtractionNode$1(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode$1(parentParentNode) && !hasEmptyRawBefore$1(iNextNode);
  14048. var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode$1(iNextNextNode) || iNode.type === "value-func" || isWordNode$1(iNode);
  14049. var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode$1(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode$1(iPrevNode); // Formatting `/`, `+`, `-` sign
  14050. if (!(isMultiplicationNode$1(iNextNode) || isMultiplicationNode$1(iNode)) && !insideValueFunctionNode$1(path, "calc") && !isColorAdjusterNode && (isDivisionNode$1(iNextNode) && !requireSpaceBeforeOperator || isDivisionNode$1(iNode) && !requireSpaceAfterOperator || isAdditionNode$1(iNextNode) && !requireSpaceBeforeOperator || isAdditionNode$1(iNode) && !requireSpaceAfterOperator || isSubtractionNode$1(iNextNode) || isSubtractionNode$1(iNode)) && (hasEmptyRawBefore$1(iNextNode) || isMathOperator && (!iPrevNode || iPrevNode && isMathOperatorNode$1(iPrevNode)))) {
  14051. continue;
  14052. } // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
  14053. if (isInlineValueCommentNode$1(iNode)) {
  14054. _parts.push(hardline$4);
  14055. continue;
  14056. } // Handle keywords in SCSS control directive
  14057. if (isControlDirective && (isEqualityOperatorNode$1(iNextNode) || isRelationalOperatorNode$1(iNextNode) || isIfElseKeywordNode$1(iNextNode) || isEachKeywordNode$1(iNode) || isForKeywordNode$1(iNode))) {
  14058. _parts.push(" ");
  14059. continue;
  14060. } // At-rule `namespace` should be in one line
  14061. if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
  14062. _parts.push(" ");
  14063. continue;
  14064. } // Formatting `grid` property
  14065. if (isGridValue) {
  14066. if (iNode.source && iNextNode.source && iNode.source.start.line !== iNextNode.source.start.line) {
  14067. _parts.push(hardline$4);
  14068. didBreak = true;
  14069. } else {
  14070. _parts.push(" ");
  14071. }
  14072. continue;
  14073. } // Add `space` before next math operation
  14074. // Note: `grip` property have `/` delimiter and it is not math operation, so
  14075. // `grid` property handles above
  14076. if (isNextMathOperator) {
  14077. _parts.push(" ");
  14078. continue;
  14079. } // Be default all values go through `line`
  14080. _parts.push(line$1);
  14081. }
  14082. if (didBreak) {
  14083. _parts.unshift(hardline$4);
  14084. }
  14085. if (isControlDirective) {
  14086. return group$1(indent$2(concat$5(_parts)));
  14087. } // Indent is not needed for import url when url is very long
  14088. // and node has two groups
  14089. // when type is value-comma_group
  14090. // example @import url("verylongurl") projection,tv
  14091. if (insideURLFunctionInImportAtRuleNode$1(path)) {
  14092. return group$1(fill$2(_parts));
  14093. }
  14094. return group$1(indent$2(fill$2(_parts)));
  14095. }
  14096. case "value-paren_group":
  14097. {
  14098. var _parentNode5 = path.getParentNode();
  14099. if (_parentNode5 && isURLFunctionNode$1(_parentNode5) && (node.groups.length === 1 || node.groups.length > 0 && node.groups[0].type === "value-comma_group" && node.groups[0].groups.length > 0 && node.groups[0].groups[0].type === "value-word" && node.groups[0].groups[0].value.startsWith("data:"))) {
  14100. return concat$5([node.open ? path.call(print, "open") : "", join$2(",", path.map(print, "groups")), node.close ? path.call(print, "close") : ""]);
  14101. }
  14102. if (!node.open) {
  14103. var _printed = path.map(print, "groups");
  14104. var res = [];
  14105. for (var _i = 0; _i < _printed.length; _i++) {
  14106. if (_i !== 0) {
  14107. res.push(concat$5([",", line$1]));
  14108. }
  14109. res.push(_printed[_i]);
  14110. }
  14111. return group$1(indent$2(fill$2(res)));
  14112. }
  14113. var isSCSSMapItem = isSCSSMapItemNode$1(path);
  14114. return group$1(concat$5([node.open ? path.call(print, "open") : "", indent$2(concat$5([softline$1, join$2(concat$5([",", line$1]), path.map(function (childPath) {
  14115. var node = childPath.getValue();
  14116. var printed = print(childPath); // Key/Value pair in open paren already indented
  14117. if (isKeyValuePairNode$1(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
  14118. printed.contents.contents.parts[1] = group$1(printed.contents.contents.parts[1]);
  14119. return group$1(dedent$1(printed));
  14120. }
  14121. return printed;
  14122. }, "groups"))])), ifBreak$1(isSCSS$1(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma(options) ? "," : ""), softline$1, node.close ? path.call(print, "close") : ""]), {
  14123. shouldBreak: isSCSSMapItem
  14124. });
  14125. }
  14126. case "value-func":
  14127. {
  14128. return concat$5([node.value, insideAtRuleNode$1(path, "supports") && isMediaAndSupportsKeywords$1(node) ? " " : "", path.call(print, "group")]);
  14129. }
  14130. case "value-paren":
  14131. {
  14132. return node.value;
  14133. }
  14134. case "value-number":
  14135. {
  14136. return concat$5([printCssNumber(node.value), maybeToLowerCase$1(node.unit)]);
  14137. }
  14138. case "value-operator":
  14139. {
  14140. return node.value;
  14141. }
  14142. case "value-word":
  14143. {
  14144. if (node.isColor && node.isHex || isWideKeywords$1(node.value)) {
  14145. return node.value.toLowerCase();
  14146. }
  14147. return node.value;
  14148. }
  14149. case "value-colon":
  14150. {
  14151. return concat$5([node.value, // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
  14152. insideValueFunctionNode$1(path, "url") ? "" : line$1]);
  14153. }
  14154. case "value-comma":
  14155. {
  14156. return concat$5([node.value, " "]);
  14157. }
  14158. case "value-string":
  14159. {
  14160. return printString$1(node.raws.quote + node.value + node.raws.quote, options);
  14161. }
  14162. case "value-atword":
  14163. {
  14164. return concat$5(["@", node.value]);
  14165. }
  14166. case "value-unicode-range":
  14167. {
  14168. return node.value;
  14169. }
  14170. case "value-unknown":
  14171. {
  14172. return node.value;
  14173. }
  14174. default:
  14175. /* istanbul ignore next */
  14176. throw new Error("Unknown postcss type ".concat(JSON.stringify(node.type)));
  14177. }
  14178. }
  14179. function printNodeSequence(path, options, print) {
  14180. var node = path.getValue();
  14181. var parts = [];
  14182. var i = 0;
  14183. path.map(function (pathChild) {
  14184. var prevNode = node.nodes[i - 1];
  14185. if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
  14186. var childNode = pathChild.getValue();
  14187. parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
  14188. } else {
  14189. parts.push(pathChild.call(print));
  14190. }
  14191. if (i !== node.nodes.length - 1) {
  14192. if (node.nodes[i + 1].type === "css-comment" && !hasNewline$2(options.originalText, options.locStart(node.nodes[i + 1]), {
  14193. backwards: true
  14194. }) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml" || node.nodes[i + 1].type === "css-atrule" && node.nodes[i + 1].name === "else" && node.nodes[i].type !== "css-comment") {
  14195. parts.push(" ");
  14196. } else {
  14197. parts.push(hardline$4);
  14198. if (isNextLineEmpty$2(options.originalText, pathChild.getValue(), options) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml") {
  14199. parts.push(hardline$4);
  14200. }
  14201. }
  14202. }
  14203. i++;
  14204. }, "nodes");
  14205. return concat$5(parts);
  14206. }
  14207. var STRING_REGEX$1 = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  14208. var NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  14209. var STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  14210. var WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  14211. var ADJUST_NUMBERS_REGEX = RegExp(STRING_REGEX$1.source + "|" + "(".concat(WORD_PART_REGEX.source, ")?") + "(".concat(NUMBER_REGEX.source, ")") + "(".concat(STANDARD_UNIT_REGEX.source, ")?"), "g");
  14212. function adjustStrings(value, options) {
  14213. return value.replace(STRING_REGEX$1, function (match) {
  14214. return printString$1(match, options);
  14215. });
  14216. }
  14217. function quoteAttributeValue(value, options) {
  14218. var quote = options.singleQuote ? "'" : '"';
  14219. return value.includes('"') || value.includes("'") ? value : quote + value + quote;
  14220. }
  14221. function adjustNumbers(value) {
  14222. return value.replace(ADJUST_NUMBERS_REGEX, function (match, quote, wordPart, number, unit) {
  14223. return !wordPart && number ? (wordPart || "") + printCssNumber(number) + maybeToLowerCase$1(unit || "") : match;
  14224. });
  14225. }
  14226. function printCssNumber(rawNumber) {
  14227. return printNumber$1(rawNumber) // Remove trailing `.0`.
  14228. .replace(/\.0(?=$|e)/, "");
  14229. }
  14230. var printerPostcss = {
  14231. print: genericPrint,
  14232. embed: embed_1,
  14233. insertPragma: insertPragma$2,
  14234. hasPrettierIgnore: hasIgnoreComment$1,
  14235. massageAstNode: clean_1
  14236. };
  14237. var CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  14238. var commonOptions = {
  14239. bracketSpacing: {
  14240. since: "0.0.0",
  14241. category: CATEGORY_COMMON,
  14242. type: "boolean",
  14243. default: true,
  14244. description: "Print spaces between brackets.",
  14245. oppositeDescription: "Do not print spaces between brackets."
  14246. },
  14247. singleQuote: {
  14248. since: "0.0.0",
  14249. category: CATEGORY_COMMON,
  14250. type: "boolean",
  14251. default: false,
  14252. description: "Use single quotes instead of double quotes."
  14253. },
  14254. proseWrap: {
  14255. since: "1.8.2",
  14256. category: CATEGORY_COMMON,
  14257. type: "choice",
  14258. default: [{
  14259. since: "1.8.2",
  14260. value: true
  14261. }, {
  14262. since: "1.9.0",
  14263. value: "preserve"
  14264. }],
  14265. description: "How to wrap prose.",
  14266. choices: [{
  14267. since: "1.9.0",
  14268. value: "always",
  14269. description: "Wrap prose if it exceeds the print width."
  14270. }, {
  14271. since: "1.9.0",
  14272. value: "never",
  14273. description: "Do not wrap prose."
  14274. }, {
  14275. since: "1.9.0",
  14276. value: "preserve",
  14277. description: "Wrap prose as-is."
  14278. }, {
  14279. value: false,
  14280. deprecated: "1.9.0",
  14281. redirect: "never"
  14282. }, {
  14283. value: true,
  14284. deprecated: "1.9.0",
  14285. redirect: "always"
  14286. }]
  14287. }
  14288. };
  14289. var options$2 = {
  14290. singleQuote: commonOptions.singleQuote
  14291. };
  14292. var createLanguage = function createLanguage(linguistData, transform) {
  14293. var language = {};
  14294. for (var key in linguistData) {
  14295. var newKey = key === "languageId" ? "linguistLanguageId" : key;
  14296. language[newKey] = linguistData[key];
  14297. }
  14298. return transform(language);
  14299. };
  14300. var name$1 = "CSS";
  14301. var type = "markup";
  14302. var tmScope = "source.css";
  14303. var aceMode = "css";
  14304. var codemirrorMode = "css";
  14305. var codemirrorMimeType = "text/css";
  14306. var color = "#563d7c";
  14307. var extensions = [
  14308. ".css"
  14309. ];
  14310. var languageId = 50;
  14311. var CSS = {
  14312. name: name$1,
  14313. type: type,
  14314. tmScope: tmScope,
  14315. aceMode: aceMode,
  14316. codemirrorMode: codemirrorMode,
  14317. codemirrorMimeType: codemirrorMimeType,
  14318. color: color,
  14319. extensions: extensions,
  14320. languageId: languageId
  14321. };
  14322. var CSS$1 = /*#__PURE__*/Object.freeze({
  14323. __proto__: null,
  14324. name: name$1,
  14325. type: type,
  14326. tmScope: tmScope,
  14327. aceMode: aceMode,
  14328. codemirrorMode: codemirrorMode,
  14329. codemirrorMimeType: codemirrorMimeType,
  14330. color: color,
  14331. extensions: extensions,
  14332. languageId: languageId,
  14333. 'default': CSS
  14334. });
  14335. var name$2 = "PostCSS";
  14336. var type$1 = "markup";
  14337. var tmScope$1 = "source.postcss";
  14338. var group$2 = "CSS";
  14339. var extensions$1 = [
  14340. ".pcss"
  14341. ];
  14342. var aceMode$1 = "text";
  14343. var languageId$1 = 262764437;
  14344. var PostCSS = {
  14345. name: name$2,
  14346. type: type$1,
  14347. tmScope: tmScope$1,
  14348. group: group$2,
  14349. extensions: extensions$1,
  14350. aceMode: aceMode$1,
  14351. languageId: languageId$1
  14352. };
  14353. var PostCSS$1 = /*#__PURE__*/Object.freeze({
  14354. __proto__: null,
  14355. name: name$2,
  14356. type: type$1,
  14357. tmScope: tmScope$1,
  14358. group: group$2,
  14359. extensions: extensions$1,
  14360. aceMode: aceMode$1,
  14361. languageId: languageId$1,
  14362. 'default': PostCSS
  14363. });
  14364. var name$3 = "Less";
  14365. var type$2 = "markup";
  14366. var group$3 = "CSS";
  14367. var extensions$2 = [
  14368. ".less"
  14369. ];
  14370. var tmScope$2 = "source.css.less";
  14371. var aceMode$2 = "less";
  14372. var codemirrorMode$1 = "css";
  14373. var codemirrorMimeType$1 = "text/css";
  14374. var languageId$2 = 198;
  14375. var Less = {
  14376. name: name$3,
  14377. type: type$2,
  14378. group: group$3,
  14379. extensions: extensions$2,
  14380. tmScope: tmScope$2,
  14381. aceMode: aceMode$2,
  14382. codemirrorMode: codemirrorMode$1,
  14383. codemirrorMimeType: codemirrorMimeType$1,
  14384. languageId: languageId$2
  14385. };
  14386. var Less$1 = /*#__PURE__*/Object.freeze({
  14387. __proto__: null,
  14388. name: name$3,
  14389. type: type$2,
  14390. group: group$3,
  14391. extensions: extensions$2,
  14392. tmScope: tmScope$2,
  14393. aceMode: aceMode$2,
  14394. codemirrorMode: codemirrorMode$1,
  14395. codemirrorMimeType: codemirrorMimeType$1,
  14396. languageId: languageId$2,
  14397. 'default': Less
  14398. });
  14399. var name$4 = "SCSS";
  14400. var type$3 = "markup";
  14401. var tmScope$3 = "source.css.scss";
  14402. var group$4 = "CSS";
  14403. var aceMode$3 = "scss";
  14404. var codemirrorMode$2 = "css";
  14405. var codemirrorMimeType$2 = "text/x-scss";
  14406. var extensions$3 = [
  14407. ".scss"
  14408. ];
  14409. var languageId$3 = 329;
  14410. var SCSS = {
  14411. name: name$4,
  14412. type: type$3,
  14413. tmScope: tmScope$3,
  14414. group: group$4,
  14415. aceMode: aceMode$3,
  14416. codemirrorMode: codemirrorMode$2,
  14417. codemirrorMimeType: codemirrorMimeType$2,
  14418. extensions: extensions$3,
  14419. languageId: languageId$3
  14420. };
  14421. var SCSS$1 = /*#__PURE__*/Object.freeze({
  14422. __proto__: null,
  14423. name: name$4,
  14424. type: type$3,
  14425. tmScope: tmScope$3,
  14426. group: group$4,
  14427. aceMode: aceMode$3,
  14428. codemirrorMode: codemirrorMode$2,
  14429. codemirrorMimeType: codemirrorMimeType$2,
  14430. extensions: extensions$3,
  14431. languageId: languageId$3,
  14432. 'default': SCSS
  14433. });
  14434. var require$$0$2 = getCjsExportFromNamespace(CSS$1);
  14435. var require$$1 = getCjsExportFromNamespace(PostCSS$1);
  14436. var require$$2 = getCjsExportFromNamespace(Less$1);
  14437. var require$$3 = getCjsExportFromNamespace(SCSS$1);
  14438. var languages = [createLanguage(require$$0$2, function (data) {
  14439. return Object.assign(data, {
  14440. since: "1.4.0",
  14441. parsers: ["css"],
  14442. vscodeLanguageIds: ["css"]
  14443. });
  14444. }), createLanguage(require$$1, function (data) {
  14445. return Object.assign(data, {
  14446. since: "1.4.0",
  14447. parsers: ["css"],
  14448. vscodeLanguageIds: ["postcss"],
  14449. extensions: data.extensions.concat(".postcss")
  14450. });
  14451. }), createLanguage(require$$2, function (data) {
  14452. return Object.assign(data, {
  14453. since: "1.4.0",
  14454. parsers: ["less"],
  14455. vscodeLanguageIds: ["less"]
  14456. });
  14457. }), createLanguage(require$$3, function (data) {
  14458. return Object.assign(data, {
  14459. since: "1.4.0",
  14460. parsers: ["scss"],
  14461. vscodeLanguageIds: ["scss"]
  14462. });
  14463. })];
  14464. var printers = {
  14465. postcss: printerPostcss
  14466. };
  14467. var languageCss = {
  14468. languages: languages,
  14469. options: options$2,
  14470. printers: printers
  14471. };
  14472. function hasPragma$2(text) {
  14473. return /^\s*#[^\n\S]*@(format|prettier)\s*(\n|$)/.test(text);
  14474. }
  14475. function insertPragma$3(text) {
  14476. return "# @format\n\n" + text;
  14477. }
  14478. var pragma$2 = {
  14479. hasPragma: hasPragma$2,
  14480. insertPragma: insertPragma$3
  14481. };
  14482. var _require$$0$builders$2 = doc.builders,
  14483. concat$6 = _require$$0$builders$2.concat,
  14484. join$3 = _require$$0$builders$2.join,
  14485. hardline$5 = _require$$0$builders$2.hardline,
  14486. line$2 = _require$$0$builders$2.line,
  14487. softline$2 = _require$$0$builders$2.softline,
  14488. group$5 = _require$$0$builders$2.group,
  14489. indent$3 = _require$$0$builders$2.indent,
  14490. ifBreak$2 = _require$$0$builders$2.ifBreak;
  14491. var hasIgnoreComment$2 = util.hasIgnoreComment;
  14492. var isNextLineEmpty$3 = utilShared.isNextLineEmpty;
  14493. var insertPragma$4 = pragma$2.insertPragma;
  14494. function genericPrint$1(path, options, print) {
  14495. var n = path.getValue();
  14496. if (!n) {
  14497. return "";
  14498. }
  14499. if (typeof n === "string") {
  14500. return n;
  14501. }
  14502. switch (n.kind) {
  14503. case "Document":
  14504. {
  14505. var parts = [];
  14506. path.map(function (pathChild, index) {
  14507. parts.push(concat$6([pathChild.call(print)]));
  14508. if (index !== n.definitions.length - 1) {
  14509. parts.push(hardline$5);
  14510. if (isNextLineEmpty$3(options.originalText, pathChild.getValue(), options)) {
  14511. parts.push(hardline$5);
  14512. }
  14513. }
  14514. }, "definitions");
  14515. return concat$6([concat$6(parts), hardline$5]);
  14516. }
  14517. case "OperationDefinition":
  14518. {
  14519. var hasOperation = options.originalText[options.locStart(n)] !== "{";
  14520. var hasName = !!n.name;
  14521. return concat$6([hasOperation ? n.operation : "", hasOperation && hasName ? concat$6([" ", path.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$5(concat$6(["(", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.map(print, "variableDefinitions"))])), softline$2, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? !hasOperation && !hasName ? "" : " " : "", path.call(print, "selectionSet")]);
  14522. }
  14523. case "FragmentDefinition":
  14524. {
  14525. return concat$6(["fragment ", path.call(print, "name"), n.variableDefinitions && n.variableDefinitions.length ? group$5(concat$6(["(", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.map(print, "variableDefinitions"))])), softline$2, ")"])) : "", " on ", path.call(print, "typeCondition"), printDirectives(path, print, n), " ", path.call(print, "selectionSet")]);
  14526. }
  14527. case "SelectionSet":
  14528. {
  14529. return concat$6(["{", indent$3(concat$6([hardline$5, join$3(hardline$5, path.call(function (selectionsPath) {
  14530. return printSequence(selectionsPath, options, print);
  14531. }, "selections"))])), hardline$5, "}"]);
  14532. }
  14533. case "Field":
  14534. {
  14535. return group$5(concat$6([n.alias ? concat$6([path.call(print, "alias"), ": "]) : "", path.call(print, "name"), n.arguments.length > 0 ? group$5(concat$6(["(", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.call(function (argsPath) {
  14536. return printSequence(argsPath, options, print);
  14537. }, "arguments"))])), softline$2, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? " " : "", path.call(print, "selectionSet")]));
  14538. }
  14539. case "Name":
  14540. {
  14541. return n.value;
  14542. }
  14543. case "StringValue":
  14544. {
  14545. if (n.block) {
  14546. return concat$6(['"""', hardline$5, join$3(hardline$5, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$5, '"""']);
  14547. }
  14548. return concat$6(['"', n.value.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\n"), '"']);
  14549. }
  14550. case "IntValue":
  14551. case "FloatValue":
  14552. case "EnumValue":
  14553. {
  14554. return n.value;
  14555. }
  14556. case "BooleanValue":
  14557. {
  14558. return n.value ? "true" : "false";
  14559. }
  14560. case "NullValue":
  14561. {
  14562. return "null";
  14563. }
  14564. case "Variable":
  14565. {
  14566. return concat$6(["$", path.call(print, "name")]);
  14567. }
  14568. case "ListValue":
  14569. {
  14570. return group$5(concat$6(["[", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.map(print, "values"))])), softline$2, "]"]));
  14571. }
  14572. case "ObjectValue":
  14573. {
  14574. return group$5(concat$6(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.map(print, "fields"))])), softline$2, ifBreak$2("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"]));
  14575. }
  14576. case "ObjectField":
  14577. case "Argument":
  14578. {
  14579. return concat$6([path.call(print, "name"), ": ", path.call(print, "value")]);
  14580. }
  14581. case "Directive":
  14582. {
  14583. return concat$6(["@", path.call(print, "name"), n.arguments.length > 0 ? group$5(concat$6(["(", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.call(function (argsPath) {
  14584. return printSequence(argsPath, options, print);
  14585. }, "arguments"))])), softline$2, ")"])) : ""]);
  14586. }
  14587. case "NamedType":
  14588. {
  14589. return path.call(print, "name");
  14590. }
  14591. case "VariableDefinition":
  14592. {
  14593. return concat$6([path.call(print, "variable"), ": ", path.call(print, "type"), n.defaultValue ? concat$6([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]);
  14594. }
  14595. case "TypeExtensionDefinition":
  14596. {
  14597. return concat$6(["extend ", path.call(print, "definition")]);
  14598. }
  14599. case "ObjectTypeExtension":
  14600. case "ObjectTypeDefinition":
  14601. {
  14602. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path.call(print, "name"), n.interfaces.length > 0 ? concat$6([" implements ", join$3(determineInterfaceSeparator(options.originalText.substr(options.locStart(n), options.locEnd(n))), path.map(print, "interfaces"))]) : "", printDirectives(path, print, n), n.fields.length > 0 ? concat$6([" {", indent$3(concat$6([hardline$5, join$3(hardline$5, path.call(function (fieldsPath) {
  14603. return printSequence(fieldsPath, options, print);
  14604. }, "fields"))])), hardline$5, "}"]) : ""]);
  14605. }
  14606. case "FieldDefinition":
  14607. {
  14608. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", path.call(print, "name"), n.arguments.length > 0 ? group$5(concat$6(["(", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.call(function (argsPath) {
  14609. return printSequence(argsPath, options, print);
  14610. }, "arguments"))])), softline$2, ")"])) : "", ": ", path.call(print, "type"), printDirectives(path, print, n)]);
  14611. }
  14612. case "DirectiveDefinition":
  14613. {
  14614. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", "directive ", "@", path.call(print, "name"), n.arguments.length > 0 ? group$5(concat$6(["(", indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", ", "), softline$2]), path.call(function (argsPath) {
  14615. return printSequence(argsPath, options, print);
  14616. }, "arguments"))])), softline$2, ")"])) : "", concat$6([" on ", join$3(" | ", path.map(print, "locations"))])]);
  14617. }
  14618. case "EnumTypeExtension":
  14619. case "EnumTypeDefinition":
  14620. {
  14621. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path.call(print, "name"), printDirectives(path, print, n), n.values.length > 0 ? concat$6([" {", indent$3(concat$6([hardline$5, join$3(hardline$5, path.call(function (valuesPath) {
  14622. return printSequence(valuesPath, options, print);
  14623. }, "values"))])), hardline$5, "}"]) : ""]);
  14624. }
  14625. case "EnumValueDefinition":
  14626. {
  14627. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", path.call(print, "name"), printDirectives(path, print, n)]);
  14628. }
  14629. case "InputValueDefinition":
  14630. {
  14631. return concat$6([path.call(print, "description"), n.description ? n.description.block ? hardline$5 : line$2 : "", path.call(print, "name"), ": ", path.call(print, "type"), n.defaultValue ? concat$6([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]);
  14632. }
  14633. case "InputObjectTypeExtension":
  14634. case "InputObjectTypeDefinition":
  14635. {
  14636. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path.call(print, "name"), printDirectives(path, print, n), n.fields.length > 0 ? concat$6([" {", indent$3(concat$6([hardline$5, join$3(hardline$5, path.call(function (fieldsPath) {
  14637. return printSequence(fieldsPath, options, print);
  14638. }, "fields"))])), hardline$5, "}"]) : ""]);
  14639. }
  14640. case "SchemaDefinition":
  14641. {
  14642. return concat$6(["schema", printDirectives(path, print, n), " {", n.operationTypes.length > 0 ? indent$3(concat$6([hardline$5, join$3(hardline$5, path.call(function (opsPath) {
  14643. return printSequence(opsPath, options, print);
  14644. }, "operationTypes"))])) : "", hardline$5, "}"]);
  14645. }
  14646. case "OperationTypeDefinition":
  14647. {
  14648. return concat$6([path.call(print, "operation"), ": ", path.call(print, "type")]);
  14649. }
  14650. case "InterfaceTypeExtension":
  14651. case "InterfaceTypeDefinition":
  14652. {
  14653. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path.call(print, "name"), printDirectives(path, print, n), n.fields.length > 0 ? concat$6([" {", indent$3(concat$6([hardline$5, join$3(hardline$5, path.call(function (fieldsPath) {
  14654. return printSequence(fieldsPath, options, print);
  14655. }, "fields"))])), hardline$5, "}"]) : ""]);
  14656. }
  14657. case "FragmentSpread":
  14658. {
  14659. return concat$6(["...", path.call(print, "name"), printDirectives(path, print, n)]);
  14660. }
  14661. case "InlineFragment":
  14662. {
  14663. return concat$6(["...", n.typeCondition ? concat$6([" on ", path.call(print, "typeCondition")]) : "", printDirectives(path, print, n), " ", path.call(print, "selectionSet")]);
  14664. }
  14665. case "UnionTypeExtension":
  14666. case "UnionTypeDefinition":
  14667. {
  14668. return group$5(concat$6([path.call(print, "description"), n.description ? hardline$5 : "", group$5(concat$6([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path.call(print, "name"), printDirectives(path, print, n), n.types.length > 0 ? concat$6([" =", ifBreak$2("", " "), indent$3(concat$6([ifBreak$2(concat$6([line$2, " "])), join$3(concat$6([line$2, "| "]), path.map(print, "types"))]))]) : ""]))]));
  14669. }
  14670. case "ScalarTypeExtension":
  14671. case "ScalarTypeDefinition":
  14672. {
  14673. return concat$6([path.call(print, "description"), n.description ? hardline$5 : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path.call(print, "name"), printDirectives(path, print, n)]);
  14674. }
  14675. case "NonNullType":
  14676. {
  14677. return concat$6([path.call(print, "type"), "!"]);
  14678. }
  14679. case "ListType":
  14680. {
  14681. return concat$6(["[", path.call(print, "type"), "]"]);
  14682. }
  14683. default:
  14684. /* istanbul ignore next */
  14685. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  14686. }
  14687. }
  14688. function printDirectives(path, print, n) {
  14689. if (n.directives.length === 0) {
  14690. return "";
  14691. }
  14692. return concat$6([" ", group$5(indent$3(concat$6([softline$2, join$3(concat$6([ifBreak$2("", " "), softline$2]), path.map(print, "directives"))])))]);
  14693. }
  14694. function printSequence(sequencePath, options, print) {
  14695. var count = sequencePath.getValue().length;
  14696. return sequencePath.map(function (path, i) {
  14697. var printed = print(path);
  14698. if (isNextLineEmpty$3(options.originalText, path.getValue(), options) && i < count - 1) {
  14699. return concat$6([printed, hardline$5]);
  14700. }
  14701. return printed;
  14702. });
  14703. }
  14704. function canAttachComment(node) {
  14705. return node.kind && node.kind !== "Comment";
  14706. }
  14707. function printComment$1(commentPath) {
  14708. var comment = commentPath.getValue();
  14709. if (comment.kind === "Comment") {
  14710. return "#" + comment.value.trimRight();
  14711. }
  14712. throw new Error("Not a comment: " + JSON.stringify(comment));
  14713. }
  14714. function determineInterfaceSeparator(originalSource) {
  14715. var start = originalSource.indexOf("implements");
  14716. if (start === -1) {
  14717. throw new Error("Must implement interfaces: " + originalSource);
  14718. }
  14719. var end = originalSource.indexOf("{");
  14720. if (end === -1) {
  14721. end = originalSource.length;
  14722. }
  14723. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  14724. }
  14725. function clean$1(node, newNode
  14726. /*, parent*/
  14727. ) {
  14728. delete newNode.loc;
  14729. delete newNode.comments;
  14730. }
  14731. var printerGraphql = {
  14732. print: genericPrint$1,
  14733. massageAstNode: clean$1,
  14734. hasPrettierIgnore: hasIgnoreComment$2,
  14735. insertPragma: insertPragma$4,
  14736. printComment: printComment$1,
  14737. canAttachComment: canAttachComment
  14738. };
  14739. var options$3 = {
  14740. bracketSpacing: commonOptions.bracketSpacing
  14741. };
  14742. var name$5 = "GraphQL";
  14743. var type$4 = "data";
  14744. var extensions$4 = [
  14745. ".graphql",
  14746. ".gql",
  14747. ".graphqls"
  14748. ];
  14749. var tmScope$4 = "source.graphql";
  14750. var aceMode$4 = "text";
  14751. var languageId$4 = 139;
  14752. var GraphQL = {
  14753. name: name$5,
  14754. type: type$4,
  14755. extensions: extensions$4,
  14756. tmScope: tmScope$4,
  14757. aceMode: aceMode$4,
  14758. languageId: languageId$4
  14759. };
  14760. var GraphQL$1 = /*#__PURE__*/Object.freeze({
  14761. __proto__: null,
  14762. name: name$5,
  14763. type: type$4,
  14764. extensions: extensions$4,
  14765. tmScope: tmScope$4,
  14766. aceMode: aceMode$4,
  14767. languageId: languageId$4,
  14768. 'default': GraphQL
  14769. });
  14770. var require$$0$3 = getCjsExportFromNamespace(GraphQL$1);
  14771. var languages$1 = [createLanguage(require$$0$3, function (data) {
  14772. return Object.assign(data, {
  14773. since: "1.5.0",
  14774. parsers: ["graphql"],
  14775. vscodeLanguageIds: ["graphql"]
  14776. });
  14777. })];
  14778. var printers$1 = {
  14779. graphql: printerGraphql
  14780. };
  14781. var languageGraphql = {
  14782. languages: languages$1,
  14783. options: options$3,
  14784. printers: printers$1
  14785. };
  14786. var _require$$0$builders$3 = doc.builders,
  14787. concat$7 = _require$$0$builders$3.concat,
  14788. join$4 = _require$$0$builders$3.join,
  14789. softline$3 = _require$$0$builders$3.softline,
  14790. hardline$6 = _require$$0$builders$3.hardline,
  14791. line$3 = _require$$0$builders$3.line,
  14792. group$6 = _require$$0$builders$3.group,
  14793. indent$4 = _require$$0$builders$3.indent,
  14794. ifBreak$3 = _require$$0$builders$3.ifBreak; // http://w3c.github.io/html/single-page.html#void-elements
  14795. var voidTags = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]; // Formatter based on @glimmerjs/syntax's built-in test formatter:
  14796. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  14797. function printChildren(path, options, print) {
  14798. return concat$7(path.map(function (childPath, childIndex) {
  14799. var childNode = path.getValue();
  14800. var isFirstNode = childIndex === 0;
  14801. var isLastNode = childIndex == path.getParentNode(0).children.length - 1;
  14802. var isLastNodeInMultiNodeList = isLastNode && !isFirstNode;
  14803. var isWhitespace = isWhitespaceNode(childNode);
  14804. if (isWhitespace && isLastNodeInMultiNodeList) {
  14805. return print(childPath, options, print);
  14806. } else if (isFirstNode) {
  14807. return concat$7([softline$3, print(childPath, options, print)]);
  14808. }
  14809. return print(childPath, options, print);
  14810. }, "children"));
  14811. }
  14812. function print(path, options, print) {
  14813. var n = path.getValue();
  14814. /* istanbul ignore if*/
  14815. if (!n) {
  14816. return "";
  14817. }
  14818. switch (n.type) {
  14819. case "Block":
  14820. case "Program":
  14821. case "Template":
  14822. {
  14823. return group$6(concat$7(path.map(print, "body").filter(function (text) {
  14824. return text !== "";
  14825. })));
  14826. }
  14827. case "ElementNode":
  14828. {
  14829. var tagFirstChar = n.tag[0];
  14830. var isLocal = n.tag.indexOf(".") !== -1;
  14831. var isGlimmerComponent = tagFirstChar.toUpperCase() === tagFirstChar || isLocal;
  14832. var hasChildren = n.children.length > 0;
  14833. var hasNonWhitespaceChildren = n.children.some(function (n) {
  14834. return !isWhitespaceNode(n);
  14835. });
  14836. var isVoid = isGlimmerComponent && (!hasChildren || !hasNonWhitespaceChildren) || voidTags.indexOf(n.tag) !== -1;
  14837. var closeTagForNoBreak = isVoid ? concat$7([" />", softline$3]) : ">";
  14838. var closeTagForBreak = isVoid ? "/>" : ">";
  14839. var _getParams = function _getParams(path, print) {
  14840. return indent$4(concat$7([n.attributes.length ? line$3 : "", join$4(line$3, path.map(print, "attributes")), n.modifiers.length ? line$3 : "", join$4(line$3, path.map(print, "modifiers")), n.comments.length ? line$3 : "", join$4(line$3, path.map(print, "comments"))]));
  14841. };
  14842. var nextNode = getNextNode(path);
  14843. return concat$7([group$6(concat$7(["<", n.tag, _getParams(path, print), n.blockParams.length ? " as |".concat(n.blockParams.join(" "), "|") : "", ifBreak$3(softline$3, ""), ifBreak$3(closeTagForBreak, closeTagForNoBreak)])), !isVoid ? group$6(concat$7([hasNonWhitespaceChildren ? indent$4(printChildren(path, options, print)) : "", ifBreak$3(hasChildren ? hardline$6 : "", ""), concat$7(["</", n.tag, ">"])])) : "", nextNode && nextNode.type === "ElementNode" ? hardline$6 : ""]);
  14844. }
  14845. case "BlockStatement":
  14846. {
  14847. var pp = path.getParentNode(1);
  14848. var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
  14849. var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
  14850. var indentElse = hasElseIf ? function (a) {
  14851. return a;
  14852. } : indent$4;
  14853. if (n.inverse) {
  14854. return concat$7([isElseIf ? concat$7(["{{else ", printPathParams(path, print), "}}"]) : printOpenBlock(path, print), indent$4(concat$7([hardline$6, path.call(print, "program")])), n.inverse && !hasElseIf ? concat$7([hardline$6, "{{else}}"]) : "", n.inverse ? indentElse(concat$7([hardline$6, path.call(print, "inverse")])) : "", isElseIf ? "" : concat$7([hardline$6, printCloseBlock(path, print)])]);
  14855. } else if (isElseIf) {
  14856. return concat$7([concat$7(["{{else ", printPathParams(path, print), "}}"]), indent$4(concat$7([hardline$6, path.call(print, "program")]))]);
  14857. }
  14858. var _hasNonWhitespaceChildren = n.program.body.some(function (n) {
  14859. return !isWhitespaceNode(n);
  14860. });
  14861. return concat$7([printOpenBlock(path, print), group$6(concat$7([indent$4(concat$7([softline$3, path.call(print, "program")])), _hasNonWhitespaceChildren ? hardline$6 : softline$3, printCloseBlock(path, print)]))]);
  14862. }
  14863. case "ElementModifierStatement":
  14864. case "MustacheStatement":
  14865. {
  14866. var _pp = path.getParentNode(1);
  14867. var isConcat = _pp && _pp.type === "ConcatStatement";
  14868. return group$6(concat$7([n.escaped === false ? "{{{" : "{{", printPathParams(path, print, {
  14869. group: false
  14870. }), isConcat ? "" : softline$3, n.escaped === false ? "}}}" : "}}"]));
  14871. }
  14872. case "SubExpression":
  14873. {
  14874. var params = getParams(path, print);
  14875. var printedParams = params.length > 0 ? indent$4(concat$7([line$3, group$6(join$4(line$3, params))])) : "";
  14876. return group$6(concat$7(["(", printPath(path, print), printedParams, softline$3, ")"]));
  14877. }
  14878. case "AttrNode":
  14879. {
  14880. var isText = n.value.type === "TextNode";
  14881. if (isText && n.value.loc.start.column === n.value.loc.end.column) {
  14882. return concat$7([n.name]);
  14883. }
  14884. var value = path.call(print, "value");
  14885. var quotedValue = isText ? printStringLiteral(value.parts.join(), options) : value;
  14886. return concat$7([n.name, "=", quotedValue]);
  14887. }
  14888. case "ConcatStatement":
  14889. {
  14890. return concat$7(['"', group$6(indent$4(join$4(softline$3, path.map(function (partPath) {
  14891. return print(partPath);
  14892. }, "parts").filter(function (a) {
  14893. return a !== "";
  14894. })))), '"']);
  14895. }
  14896. case "Hash":
  14897. {
  14898. return concat$7([join$4(line$3, path.map(print, "pairs"))]);
  14899. }
  14900. case "HashPair":
  14901. {
  14902. return concat$7([n.key, "=", path.call(print, "value")]);
  14903. }
  14904. case "TextNode":
  14905. {
  14906. var maxLineBreaksToPreserve = 2;
  14907. var isFirstElement = !getPreviousNode(path);
  14908. var isLastElement = !getNextNode(path);
  14909. var isWhitespaceOnly = !/\S/.test(n.chars);
  14910. var lineBreaksCount = countNewLines(n.chars);
  14911. var hasBlockParent = path.getParentNode(0).type === "Block";
  14912. var hasElementParent = path.getParentNode(0).type === "ElementNode";
  14913. var hasTemplateParent = path.getParentNode(0).type === "Template";
  14914. var leadingLineBreaksCount = countLeadingNewLines(n.chars);
  14915. var trailingLineBreaksCount = countTrailingNewLines(n.chars);
  14916. if ((isFirstElement || isLastElement) && isWhitespaceOnly && (hasBlockParent || hasElementParent || hasTemplateParent)) {
  14917. return "";
  14918. }
  14919. if (isWhitespaceOnly && lineBreaksCount) {
  14920. leadingLineBreaksCount = Math.min(lineBreaksCount, maxLineBreaksToPreserve);
  14921. trailingLineBreaksCount = 0;
  14922. } else {
  14923. if (isNextNodeOfType(path, "ElementNode") || isNextNodeOfType(path, "BlockStatement")) {
  14924. trailingLineBreaksCount = Math.max(trailingLineBreaksCount, 1);
  14925. }
  14926. if (isPreviousNodeOfSomeType(path, ["ElementNode"]) || isPreviousNodeOfSomeType(path, ["BlockStatement"])) {
  14927. leadingLineBreaksCount = Math.max(leadingLineBreaksCount, 1);
  14928. }
  14929. }
  14930. var leadingSpace = "";
  14931. var trailingSpace = ""; // preserve a space inside of an attribute node where whitespace present,
  14932. // when next to mustache statement.
  14933. var inAttrNode = path.stack.indexOf("attributes") >= 0;
  14934. if (inAttrNode) {
  14935. var parentNode = path.getParentNode(0);
  14936. var _isConcat = parentNode.type === "ConcatStatement";
  14937. if (_isConcat) {
  14938. var parts = parentNode.parts;
  14939. var partIndex = parts.indexOf(n);
  14940. if (partIndex > 0) {
  14941. var partType = parts[partIndex - 1].type;
  14942. var isMustache = partType === "MustacheStatement";
  14943. if (isMustache) {
  14944. leadingSpace = " ";
  14945. }
  14946. }
  14947. if (partIndex < parts.length - 1) {
  14948. var _partType = parts[partIndex + 1].type;
  14949. var _isMustache = _partType === "MustacheStatement";
  14950. if (_isMustache) {
  14951. trailingSpace = " ";
  14952. }
  14953. }
  14954. }
  14955. } else {
  14956. if (trailingLineBreaksCount === 0 && isNextNodeOfType(path, "MustacheStatement")) {
  14957. trailingSpace = " ";
  14958. }
  14959. if (leadingLineBreaksCount === 0 && isPreviousNodeOfSomeType(path, ["MustacheStatement"])) {
  14960. leadingSpace = " ";
  14961. }
  14962. if (isFirstElement) {
  14963. leadingLineBreaksCount = 0;
  14964. leadingSpace = "";
  14965. }
  14966. if (isLastElement) {
  14967. trailingLineBreaksCount = 0;
  14968. trailingSpace = "";
  14969. }
  14970. }
  14971. return concat$7([].concat(_toConsumableArray(generateHardlines(leadingLineBreaksCount, maxLineBreaksToPreserve)), [n.chars.replace(/^[\s ]+/g, leadingSpace).replace(/[\s ]+$/, trailingSpace)], _toConsumableArray(generateHardlines(trailingLineBreaksCount, maxLineBreaksToPreserve))).filter(Boolean));
  14972. }
  14973. case "MustacheCommentStatement":
  14974. {
  14975. var dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  14976. return concat$7(["{{!", dashes, n.value, dashes, "}}"]);
  14977. }
  14978. case "PathExpression":
  14979. {
  14980. return n.original;
  14981. }
  14982. case "BooleanLiteral":
  14983. {
  14984. return String(n.value);
  14985. }
  14986. case "CommentStatement":
  14987. {
  14988. return concat$7(["<!--", n.value, "-->"]);
  14989. }
  14990. case "StringLiteral":
  14991. {
  14992. return printStringLiteral(n.value, options);
  14993. }
  14994. case "NumberLiteral":
  14995. {
  14996. return String(n.value);
  14997. }
  14998. case "UndefinedLiteral":
  14999. {
  15000. return "undefined";
  15001. }
  15002. case "NullLiteral":
  15003. {
  15004. return "null";
  15005. }
  15006. /* istanbul ignore next */
  15007. default:
  15008. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  15009. }
  15010. }
  15011. /**
  15012. * Prints a string literal with the correct surrounding quotes based on
  15013. * `options.singleQuote` and the number of escaped quotes contained in
  15014. * the string literal. This function is the glimmer equivalent of `printString`
  15015. * in `common/util`, but has differences because of the way escaped characters
  15016. * are treated in hbs string literals.
  15017. * @param {string} stringLiteral - the string literal value
  15018. * @param {object} options - the prettier options object
  15019. */
  15020. function printStringLiteral(stringLiteral, options) {
  15021. var double = {
  15022. quote: '"',
  15023. regex: /"/g
  15024. };
  15025. var single = {
  15026. quote: "'",
  15027. regex: /'/g
  15028. };
  15029. var preferred = options.singleQuote ? single : double;
  15030. var alternate = preferred === single ? double : single;
  15031. var shouldUseAlternateQuote = false; // If `stringLiteral` contains at least one of the quote preferred for
  15032. // enclosing the string, we might want to enclose with the alternate quote
  15033. // instead, to minimize the number of escaped quotes.
  15034. if (stringLiteral.includes(preferred.quote) || stringLiteral.includes(alternate.quote)) {
  15035. var numPreferredQuotes = (stringLiteral.match(preferred.regex) || []).length;
  15036. var numAlternateQuotes = (stringLiteral.match(alternate.regex) || []).length;
  15037. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  15038. }
  15039. var enclosingQuote = shouldUseAlternateQuote ? alternate : preferred;
  15040. var escapedStringLiteral = stringLiteral.replace(enclosingQuote.regex, "\\".concat(enclosingQuote.quote));
  15041. return "".concat(enclosingQuote.quote).concat(escapedStringLiteral).concat(enclosingQuote.quote);
  15042. }
  15043. function printPath(path, print) {
  15044. return path.call(print, "path");
  15045. }
  15046. function getParams(path, print) {
  15047. var node = path.getValue();
  15048. var parts = [];
  15049. if (node.params.length > 0) {
  15050. parts = parts.concat(path.map(print, "params"));
  15051. }
  15052. if (node.hash && node.hash.pairs.length > 0) {
  15053. parts.push(path.call(print, "hash"));
  15054. }
  15055. return parts;
  15056. }
  15057. function printPathParams(path, print, options) {
  15058. var parts = [];
  15059. options = Object.assign({
  15060. group: true
  15061. }, options || {});
  15062. parts.push(printPath(path, print));
  15063. parts = parts.concat(getParams(path, print));
  15064. if (!options.group) {
  15065. return indent$4(join$4(line$3, parts));
  15066. }
  15067. return indent$4(group$6(join$4(line$3, parts)));
  15068. }
  15069. function printBlockParams(path) {
  15070. var block = path.getValue();
  15071. if (!block.program || !block.program.blockParams.length) {
  15072. return "";
  15073. }
  15074. return concat$7([" as |", block.program.blockParams.join(" "), "|"]);
  15075. }
  15076. function printOpenBlock(path, print) {
  15077. return group$6(concat$7(["{{#", printPathParams(path, print), printBlockParams(path), softline$3, "}}"]));
  15078. }
  15079. function printCloseBlock(path, print) {
  15080. return concat$7(["{{/", path.call(print, "path"), "}}"]);
  15081. }
  15082. function isWhitespaceNode(node) {
  15083. return node.type === "TextNode" && !/\S/.test(node.chars);
  15084. }
  15085. function getPreviousNode(path) {
  15086. var node = path.getValue();
  15087. var parentNode = path.getParentNode(0);
  15088. var children = parentNode.children || parentNode.body;
  15089. if (children) {
  15090. var nodeIndex = children.indexOf(node);
  15091. if (nodeIndex > 0) {
  15092. var previousNode = children[nodeIndex - 1];
  15093. return previousNode;
  15094. }
  15095. }
  15096. }
  15097. function getNextNode(path) {
  15098. var node = path.getValue();
  15099. var parentNode = path.getParentNode(0);
  15100. var children = parentNode.children || parentNode.body;
  15101. if (children) {
  15102. var nodeIndex = children.indexOf(node);
  15103. if (nodeIndex < children.length) {
  15104. var nextNode = children[nodeIndex + 1];
  15105. return nextNode;
  15106. }
  15107. }
  15108. }
  15109. function isPreviousNodeOfSomeType(path, types) {
  15110. var previousNode = getPreviousNode(path);
  15111. if (previousNode) {
  15112. return types.some(function (type) {
  15113. return previousNode.type === type;
  15114. });
  15115. }
  15116. return false;
  15117. }
  15118. function isNextNodeOfType(path, type) {
  15119. var nextNode = getNextNode(path);
  15120. return nextNode && nextNode.type === type;
  15121. }
  15122. function clean$2(ast, newObj) {
  15123. delete newObj.loc;
  15124. delete newObj.selfClosing; // (Glimmer/HTML) ignore TextNode whitespace
  15125. if (ast.type === "TextNode") {
  15126. if (ast.chars.replace(/\s+/, "") === "") {
  15127. return null;
  15128. }
  15129. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  15130. }
  15131. }
  15132. function countNewLines(string) {
  15133. /* istanbul ignore next */
  15134. string = typeof string === "string" ? string : "";
  15135. return string.split("\n").length - 1;
  15136. }
  15137. function countLeadingNewLines(string) {
  15138. /* istanbul ignore next */
  15139. string = typeof string === "string" ? string : "";
  15140. var newLines = (string.match(/^([^\S\r\n]*[\r\n])+/g) || [])[0] || "";
  15141. return countNewLines(newLines);
  15142. }
  15143. function countTrailingNewLines(string) {
  15144. /* istanbul ignore next */
  15145. string = typeof string === "string" ? string : "";
  15146. var newLines = (string.match(/([\r\n][^\S\r\n]*)+$/g) || [])[0] || "";
  15147. return countNewLines(newLines);
  15148. }
  15149. function generateHardlines() {
  15150. var number = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  15151. var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  15152. return new Array(Math.min(number, max)).fill(hardline$6);
  15153. }
  15154. var printerGlimmer = {
  15155. print: print,
  15156. massageAstNode: clean$2
  15157. };
  15158. var name$6 = "Handlebars";
  15159. var type$5 = "markup";
  15160. var group$7 = "HTML";
  15161. var aliases = [
  15162. "hbs",
  15163. "htmlbars"
  15164. ];
  15165. var extensions$5 = [
  15166. ".handlebars",
  15167. ".hbs"
  15168. ];
  15169. var tmScope$5 = "text.html.handlebars";
  15170. var aceMode$5 = "handlebars";
  15171. var languageId$5 = 155;
  15172. var Handlebars = {
  15173. name: name$6,
  15174. type: type$5,
  15175. group: group$7,
  15176. aliases: aliases,
  15177. extensions: extensions$5,
  15178. tmScope: tmScope$5,
  15179. aceMode: aceMode$5,
  15180. languageId: languageId$5
  15181. };
  15182. var Handlebars$1 = /*#__PURE__*/Object.freeze({
  15183. __proto__: null,
  15184. name: name$6,
  15185. type: type$5,
  15186. group: group$7,
  15187. aliases: aliases,
  15188. extensions: extensions$5,
  15189. tmScope: tmScope$5,
  15190. aceMode: aceMode$5,
  15191. languageId: languageId$5,
  15192. 'default': Handlebars
  15193. });
  15194. var require$$0$4 = getCjsExportFromNamespace(Handlebars$1);
  15195. var languages$2 = [createLanguage(require$$0$4, function (data) {
  15196. return Object.assign(data, {
  15197. since: null,
  15198. // unreleased
  15199. parsers: ["glimmer"],
  15200. vscodeLanguageIds: ["handlebars"]
  15201. });
  15202. })];
  15203. var printers$2 = {
  15204. glimmer: printerGlimmer
  15205. };
  15206. var languageHandlebars = {
  15207. languages: languages$2,
  15208. printers: printers$2
  15209. };
  15210. var clean$3 = function clean(ast, newNode) {
  15211. delete newNode.sourceSpan;
  15212. delete newNode.startSourceSpan;
  15213. delete newNode.endSourceSpan;
  15214. delete newNode.nameSpan;
  15215. delete newNode.valueSpan;
  15216. if (ast.type === "text" || ast.type === "comment") {
  15217. return null;
  15218. } // may be formatted by multiparser
  15219. if (ast.type === "yaml" || ast.type === "toml") {
  15220. return null;
  15221. }
  15222. if (ast.type === "attribute") {
  15223. delete newNode.value;
  15224. }
  15225. if (ast.type === "docType") {
  15226. delete newNode.value;
  15227. }
  15228. };
  15229. var json = {
  15230. "CSS_DISPLAY_TAGS": {
  15231. "area": "none",
  15232. "base": "none",
  15233. "basefont": "none",
  15234. "datalist": "none",
  15235. "head": "none",
  15236. "link": "none",
  15237. "meta": "none",
  15238. "noembed": "none",
  15239. "noframes": "none",
  15240. "param": "none",
  15241. "rp": "none",
  15242. "script": "block",
  15243. "source": "block",
  15244. "style": "none",
  15245. "template": "inline",
  15246. "track": "block",
  15247. "title": "none",
  15248. "html": "block",
  15249. "body": "block",
  15250. "address": "block",
  15251. "blockquote": "block",
  15252. "center": "block",
  15253. "div": "block",
  15254. "figure": "block",
  15255. "figcaption": "block",
  15256. "footer": "block",
  15257. "form": "block",
  15258. "header": "block",
  15259. "hr": "block",
  15260. "legend": "block",
  15261. "listing": "block",
  15262. "main": "block",
  15263. "p": "block",
  15264. "plaintext": "block",
  15265. "pre": "block",
  15266. "xmp": "block",
  15267. "slot": "contents",
  15268. "ruby": "ruby",
  15269. "rt": "ruby-text",
  15270. "article": "block",
  15271. "aside": "block",
  15272. "h1": "block",
  15273. "h2": "block",
  15274. "h3": "block",
  15275. "h4": "block",
  15276. "h5": "block",
  15277. "h6": "block",
  15278. "hgroup": "block",
  15279. "nav": "block",
  15280. "section": "block",
  15281. "dir": "block",
  15282. "dd": "block",
  15283. "dl": "block",
  15284. "dt": "block",
  15285. "ol": "block",
  15286. "ul": "block",
  15287. "li": "list-item",
  15288. "table": "table",
  15289. "caption": "table-caption",
  15290. "colgroup": "table-column-group",
  15291. "col": "table-column",
  15292. "thead": "table-header-group",
  15293. "tbody": "table-row-group",
  15294. "tfoot": "table-footer-group",
  15295. "tr": "table-row",
  15296. "td": "table-cell",
  15297. "th": "table-cell",
  15298. "fieldset": "block",
  15299. "button": "inline-block",
  15300. "video": "inline-block",
  15301. "audio": "inline-block"
  15302. },
  15303. "CSS_DISPLAY_DEFAULT": "inline",
  15304. "CSS_WHITE_SPACE_TAGS": {
  15305. "listing": "pre",
  15306. "plaintext": "pre",
  15307. "pre": "pre",
  15308. "xmp": "pre",
  15309. "nobr": "nowrap",
  15310. "table": "initial",
  15311. "textarea": "pre-wrap"
  15312. },
  15313. "CSS_WHITE_SPACE_DEFAULT": "normal"
  15314. };
  15315. var a = [
  15316. "accesskey",
  15317. "charset",
  15318. "coords",
  15319. "download",
  15320. "href",
  15321. "hreflang",
  15322. "name",
  15323. "ping",
  15324. "referrerpolicy",
  15325. "rel",
  15326. "rev",
  15327. "shape",
  15328. "tabindex",
  15329. "target",
  15330. "type"
  15331. ];
  15332. var abbr = [
  15333. "title"
  15334. ];
  15335. var applet = [
  15336. "align",
  15337. "alt",
  15338. "archive",
  15339. "code",
  15340. "codebase",
  15341. "height",
  15342. "hspace",
  15343. "name",
  15344. "object",
  15345. "vspace",
  15346. "width"
  15347. ];
  15348. var area = [
  15349. "accesskey",
  15350. "alt",
  15351. "coords",
  15352. "download",
  15353. "href",
  15354. "hreflang",
  15355. "nohref",
  15356. "ping",
  15357. "referrerpolicy",
  15358. "rel",
  15359. "shape",
  15360. "tabindex",
  15361. "target",
  15362. "type"
  15363. ];
  15364. var audio = [
  15365. "autoplay",
  15366. "controls",
  15367. "crossorigin",
  15368. "loop",
  15369. "muted",
  15370. "preload",
  15371. "src"
  15372. ];
  15373. var base = [
  15374. "href",
  15375. "target"
  15376. ];
  15377. var basefont = [
  15378. "color",
  15379. "face",
  15380. "size"
  15381. ];
  15382. var bdo = [
  15383. "dir"
  15384. ];
  15385. var blockquote = [
  15386. "cite"
  15387. ];
  15388. var body = [
  15389. "alink",
  15390. "background",
  15391. "bgcolor",
  15392. "link",
  15393. "text",
  15394. "vlink"
  15395. ];
  15396. var br = [
  15397. "clear"
  15398. ];
  15399. var button = [
  15400. "accesskey",
  15401. "autofocus",
  15402. "disabled",
  15403. "form",
  15404. "formaction",
  15405. "formenctype",
  15406. "formmethod",
  15407. "formnovalidate",
  15408. "formtarget",
  15409. "name",
  15410. "tabindex",
  15411. "type",
  15412. "value"
  15413. ];
  15414. var canvas = [
  15415. "height",
  15416. "width"
  15417. ];
  15418. var caption = [
  15419. "align"
  15420. ];
  15421. var col = [
  15422. "align",
  15423. "char",
  15424. "charoff",
  15425. "span",
  15426. "valign",
  15427. "width"
  15428. ];
  15429. var colgroup = [
  15430. "align",
  15431. "char",
  15432. "charoff",
  15433. "span",
  15434. "valign",
  15435. "width"
  15436. ];
  15437. var data = [
  15438. "value"
  15439. ];
  15440. var del = [
  15441. "cite",
  15442. "datetime"
  15443. ];
  15444. var details = [
  15445. "open"
  15446. ];
  15447. var dfn = [
  15448. "title"
  15449. ];
  15450. var dialog = [
  15451. "open"
  15452. ];
  15453. var dir = [
  15454. "compact"
  15455. ];
  15456. var div = [
  15457. "align"
  15458. ];
  15459. var dl = [
  15460. "compact"
  15461. ];
  15462. var embed$1 = [
  15463. "height",
  15464. "src",
  15465. "type",
  15466. "width"
  15467. ];
  15468. var fieldset = [
  15469. "disabled",
  15470. "form",
  15471. "name"
  15472. ];
  15473. var font = [
  15474. "color",
  15475. "face",
  15476. "size"
  15477. ];
  15478. var form = [
  15479. "accept",
  15480. "accept-charset",
  15481. "action",
  15482. "autocomplete",
  15483. "enctype",
  15484. "method",
  15485. "name",
  15486. "novalidate",
  15487. "target"
  15488. ];
  15489. var frame = [
  15490. "frameborder",
  15491. "longdesc",
  15492. "marginheight",
  15493. "marginwidth",
  15494. "name",
  15495. "noresize",
  15496. "scrolling",
  15497. "src"
  15498. ];
  15499. var frameset = [
  15500. "cols",
  15501. "rows"
  15502. ];
  15503. var h1 = [
  15504. "align"
  15505. ];
  15506. var h2 = [
  15507. "align"
  15508. ];
  15509. var h3 = [
  15510. "align"
  15511. ];
  15512. var h4 = [
  15513. "align"
  15514. ];
  15515. var h5 = [
  15516. "align"
  15517. ];
  15518. var h6 = [
  15519. "align"
  15520. ];
  15521. var head = [
  15522. "profile"
  15523. ];
  15524. var hr = [
  15525. "align",
  15526. "noshade",
  15527. "size",
  15528. "width"
  15529. ];
  15530. var html = [
  15531. "manifest",
  15532. "version"
  15533. ];
  15534. var iframe = [
  15535. "align",
  15536. "allow",
  15537. "allowfullscreen",
  15538. "allowpaymentrequest",
  15539. "allowusermedia",
  15540. "frameborder",
  15541. "height",
  15542. "longdesc",
  15543. "marginheight",
  15544. "marginwidth",
  15545. "name",
  15546. "referrerpolicy",
  15547. "sandbox",
  15548. "scrolling",
  15549. "src",
  15550. "srcdoc",
  15551. "width"
  15552. ];
  15553. var img = [
  15554. "align",
  15555. "alt",
  15556. "border",
  15557. "crossorigin",
  15558. "decoding",
  15559. "height",
  15560. "hspace",
  15561. "ismap",
  15562. "longdesc",
  15563. "name",
  15564. "referrerpolicy",
  15565. "sizes",
  15566. "src",
  15567. "srcset",
  15568. "usemap",
  15569. "vspace",
  15570. "width"
  15571. ];
  15572. var input = [
  15573. "accept",
  15574. "accesskey",
  15575. "align",
  15576. "alt",
  15577. "autocomplete",
  15578. "autofocus",
  15579. "checked",
  15580. "dirname",
  15581. "disabled",
  15582. "form",
  15583. "formaction",
  15584. "formenctype",
  15585. "formmethod",
  15586. "formnovalidate",
  15587. "formtarget",
  15588. "height",
  15589. "ismap",
  15590. "list",
  15591. "max",
  15592. "maxlength",
  15593. "min",
  15594. "minlength",
  15595. "multiple",
  15596. "name",
  15597. "pattern",
  15598. "placeholder",
  15599. "readonly",
  15600. "required",
  15601. "size",
  15602. "src",
  15603. "step",
  15604. "tabindex",
  15605. "title",
  15606. "type",
  15607. "usemap",
  15608. "value",
  15609. "width"
  15610. ];
  15611. var ins = [
  15612. "cite",
  15613. "datetime"
  15614. ];
  15615. var isindex = [
  15616. "prompt"
  15617. ];
  15618. var label = [
  15619. "accesskey",
  15620. "for",
  15621. "form"
  15622. ];
  15623. var legend = [
  15624. "accesskey",
  15625. "align"
  15626. ];
  15627. var li = [
  15628. "type",
  15629. "value"
  15630. ];
  15631. var link$1 = [
  15632. "as",
  15633. "charset",
  15634. "color",
  15635. "crossorigin",
  15636. "href",
  15637. "hreflang",
  15638. "imagesizes",
  15639. "imagesrcset",
  15640. "integrity",
  15641. "media",
  15642. "nonce",
  15643. "referrerpolicy",
  15644. "rel",
  15645. "rev",
  15646. "sizes",
  15647. "target",
  15648. "title",
  15649. "type"
  15650. ];
  15651. var map = [
  15652. "name"
  15653. ];
  15654. var menu = [
  15655. "compact"
  15656. ];
  15657. var meta = [
  15658. "charset",
  15659. "content",
  15660. "http-equiv",
  15661. "name",
  15662. "scheme"
  15663. ];
  15664. var meter = [
  15665. "high",
  15666. "low",
  15667. "max",
  15668. "min",
  15669. "optimum",
  15670. "value"
  15671. ];
  15672. var object = [
  15673. "align",
  15674. "archive",
  15675. "border",
  15676. "classid",
  15677. "codebase",
  15678. "codetype",
  15679. "data",
  15680. "declare",
  15681. "form",
  15682. "height",
  15683. "hspace",
  15684. "name",
  15685. "standby",
  15686. "tabindex",
  15687. "type",
  15688. "typemustmatch",
  15689. "usemap",
  15690. "vspace",
  15691. "width"
  15692. ];
  15693. var ol = [
  15694. "compact",
  15695. "reversed",
  15696. "start",
  15697. "type"
  15698. ];
  15699. var optgroup = [
  15700. "disabled",
  15701. "label"
  15702. ];
  15703. var option = [
  15704. "disabled",
  15705. "label",
  15706. "selected",
  15707. "value"
  15708. ];
  15709. var output = [
  15710. "for",
  15711. "form",
  15712. "name"
  15713. ];
  15714. var p = [
  15715. "align"
  15716. ];
  15717. var param = [
  15718. "name",
  15719. "type",
  15720. "value",
  15721. "valuetype"
  15722. ];
  15723. var pre = [
  15724. "width"
  15725. ];
  15726. var progress = [
  15727. "max",
  15728. "value"
  15729. ];
  15730. var q = [
  15731. "cite"
  15732. ];
  15733. var script = [
  15734. "async",
  15735. "charset",
  15736. "crossorigin",
  15737. "defer",
  15738. "integrity",
  15739. "language",
  15740. "nomodule",
  15741. "nonce",
  15742. "referrerpolicy",
  15743. "src",
  15744. "type"
  15745. ];
  15746. var select = [
  15747. "autocomplete",
  15748. "autofocus",
  15749. "disabled",
  15750. "form",
  15751. "multiple",
  15752. "name",
  15753. "required",
  15754. "size",
  15755. "tabindex"
  15756. ];
  15757. var slot = [
  15758. "name"
  15759. ];
  15760. var source = [
  15761. "media",
  15762. "sizes",
  15763. "src",
  15764. "srcset",
  15765. "type"
  15766. ];
  15767. var style = [
  15768. "media",
  15769. "nonce",
  15770. "title",
  15771. "type"
  15772. ];
  15773. var table = [
  15774. "align",
  15775. "bgcolor",
  15776. "border",
  15777. "cellpadding",
  15778. "cellspacing",
  15779. "frame",
  15780. "rules",
  15781. "summary",
  15782. "width"
  15783. ];
  15784. var tbody = [
  15785. "align",
  15786. "char",
  15787. "charoff",
  15788. "valign"
  15789. ];
  15790. var td = [
  15791. "abbr",
  15792. "align",
  15793. "axis",
  15794. "bgcolor",
  15795. "char",
  15796. "charoff",
  15797. "colspan",
  15798. "headers",
  15799. "height",
  15800. "nowrap",
  15801. "rowspan",
  15802. "scope",
  15803. "valign",
  15804. "width"
  15805. ];
  15806. var textarea = [
  15807. "accesskey",
  15808. "autocomplete",
  15809. "autofocus",
  15810. "cols",
  15811. "dirname",
  15812. "disabled",
  15813. "form",
  15814. "maxlength",
  15815. "minlength",
  15816. "name",
  15817. "placeholder",
  15818. "readonly",
  15819. "required",
  15820. "rows",
  15821. "tabindex",
  15822. "wrap"
  15823. ];
  15824. var tfoot = [
  15825. "align",
  15826. "char",
  15827. "charoff",
  15828. "valign"
  15829. ];
  15830. var th = [
  15831. "abbr",
  15832. "align",
  15833. "axis",
  15834. "bgcolor",
  15835. "char",
  15836. "charoff",
  15837. "colspan",
  15838. "headers",
  15839. "height",
  15840. "nowrap",
  15841. "rowspan",
  15842. "scope",
  15843. "valign",
  15844. "width"
  15845. ];
  15846. var thead = [
  15847. "align",
  15848. "char",
  15849. "charoff",
  15850. "valign"
  15851. ];
  15852. var time = [
  15853. "datetime"
  15854. ];
  15855. var tr = [
  15856. "align",
  15857. "bgcolor",
  15858. "char",
  15859. "charoff",
  15860. "valign"
  15861. ];
  15862. var track = [
  15863. "default",
  15864. "kind",
  15865. "label",
  15866. "src",
  15867. "srclang"
  15868. ];
  15869. var ul = [
  15870. "compact",
  15871. "type"
  15872. ];
  15873. var video = [
  15874. "autoplay",
  15875. "controls",
  15876. "crossorigin",
  15877. "height",
  15878. "loop",
  15879. "muted",
  15880. "playsinline",
  15881. "poster",
  15882. "preload",
  15883. "src",
  15884. "width"
  15885. ];
  15886. var index$1 = {
  15887. "*": [
  15888. "accesskey",
  15889. "autocapitalize",
  15890. "autofocus",
  15891. "class",
  15892. "contenteditable",
  15893. "dir",
  15894. "draggable",
  15895. "enterkeyhint",
  15896. "hidden",
  15897. "id",
  15898. "inputmode",
  15899. "is",
  15900. "itemid",
  15901. "itemprop",
  15902. "itemref",
  15903. "itemscope",
  15904. "itemtype",
  15905. "lang",
  15906. "nonce",
  15907. "slot",
  15908. "spellcheck",
  15909. "style",
  15910. "tabindex",
  15911. "title",
  15912. "translate"
  15913. ],
  15914. a: a,
  15915. abbr: abbr,
  15916. applet: applet,
  15917. area: area,
  15918. audio: audio,
  15919. base: base,
  15920. basefont: basefont,
  15921. bdo: bdo,
  15922. blockquote: blockquote,
  15923. body: body,
  15924. br: br,
  15925. button: button,
  15926. canvas: canvas,
  15927. caption: caption,
  15928. col: col,
  15929. colgroup: colgroup,
  15930. data: data,
  15931. del: del,
  15932. details: details,
  15933. dfn: dfn,
  15934. dialog: dialog,
  15935. dir: dir,
  15936. div: div,
  15937. dl: dl,
  15938. embed: embed$1,
  15939. fieldset: fieldset,
  15940. font: font,
  15941. form: form,
  15942. frame: frame,
  15943. frameset: frameset,
  15944. h1: h1,
  15945. h2: h2,
  15946. h3: h3,
  15947. h4: h4,
  15948. h5: h5,
  15949. h6: h6,
  15950. head: head,
  15951. hr: hr,
  15952. html: html,
  15953. iframe: iframe,
  15954. img: img,
  15955. input: input,
  15956. ins: ins,
  15957. isindex: isindex,
  15958. label: label,
  15959. legend: legend,
  15960. li: li,
  15961. link: link$1,
  15962. map: map,
  15963. menu: menu,
  15964. meta: meta,
  15965. meter: meter,
  15966. object: object,
  15967. ol: ol,
  15968. optgroup: optgroup,
  15969. option: option,
  15970. output: output,
  15971. p: p,
  15972. param: param,
  15973. pre: pre,
  15974. progress: progress,
  15975. q: q,
  15976. script: script,
  15977. select: select,
  15978. slot: slot,
  15979. source: source,
  15980. style: style,
  15981. table: table,
  15982. tbody: tbody,
  15983. td: td,
  15984. textarea: textarea,
  15985. tfoot: tfoot,
  15986. th: th,
  15987. thead: thead,
  15988. time: time,
  15989. tr: tr,
  15990. track: track,
  15991. ul: ul,
  15992. video: video
  15993. };
  15994. var htmlElementAttributes = /*#__PURE__*/Object.freeze({
  15995. __proto__: null,
  15996. a: a,
  15997. abbr: abbr,
  15998. applet: applet,
  15999. area: area,
  16000. audio: audio,
  16001. base: base,
  16002. basefont: basefont,
  16003. bdo: bdo,
  16004. blockquote: blockquote,
  16005. body: body,
  16006. br: br,
  16007. button: button,
  16008. canvas: canvas,
  16009. caption: caption,
  16010. col: col,
  16011. colgroup: colgroup,
  16012. data: data,
  16013. del: del,
  16014. details: details,
  16015. dfn: dfn,
  16016. dialog: dialog,
  16017. dir: dir,
  16018. div: div,
  16019. dl: dl,
  16020. embed: embed$1,
  16021. fieldset: fieldset,
  16022. font: font,
  16023. form: form,
  16024. frame: frame,
  16025. frameset: frameset,
  16026. h1: h1,
  16027. h2: h2,
  16028. h3: h3,
  16029. h4: h4,
  16030. h5: h5,
  16031. h6: h6,
  16032. head: head,
  16033. hr: hr,
  16034. html: html,
  16035. iframe: iframe,
  16036. img: img,
  16037. input: input,
  16038. ins: ins,
  16039. isindex: isindex,
  16040. label: label,
  16041. legend: legend,
  16042. li: li,
  16043. link: link$1,
  16044. map: map,
  16045. menu: menu,
  16046. meta: meta,
  16047. meter: meter,
  16048. object: object,
  16049. ol: ol,
  16050. optgroup: optgroup,
  16051. option: option,
  16052. output: output,
  16053. p: p,
  16054. param: param,
  16055. pre: pre,
  16056. progress: progress,
  16057. q: q,
  16058. script: script,
  16059. select: select,
  16060. slot: slot,
  16061. source: source,
  16062. style: style,
  16063. table: table,
  16064. tbody: tbody,
  16065. td: td,
  16066. textarea: textarea,
  16067. tfoot: tfoot,
  16068. th: th,
  16069. thead: thead,
  16070. time: time,
  16071. tr: tr,
  16072. track: track,
  16073. ul: ul,
  16074. video: video,
  16075. 'default': index$1
  16076. });
  16077. var htmlElementAttributes$1 = getCjsExportFromNamespace(htmlElementAttributes);
  16078. var CSS_DISPLAY_TAGS = json.CSS_DISPLAY_TAGS,
  16079. CSS_DISPLAY_DEFAULT = json.CSS_DISPLAY_DEFAULT,
  16080. CSS_WHITE_SPACE_TAGS = json.CSS_WHITE_SPACE_TAGS,
  16081. CSS_WHITE_SPACE_DEFAULT = json.CSS_WHITE_SPACE_DEFAULT;
  16082. var HTML_TAGS = arrayToMap(htmlTagNames$1);
  16083. var HTML_ELEMENT_ATTRIBUTES = mapObject(htmlElementAttributes$1, arrayToMap);
  16084. function arrayToMap(array) {
  16085. var map = Object.create(null);
  16086. var _iteratorNormalCompletion = true;
  16087. var _didIteratorError = false;
  16088. var _iteratorError = undefined;
  16089. try {
  16090. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  16091. var value = _step.value;
  16092. map[value] = true;
  16093. }
  16094. } catch (err) {
  16095. _didIteratorError = true;
  16096. _iteratorError = err;
  16097. } finally {
  16098. try {
  16099. if (!_iteratorNormalCompletion && _iterator.return != null) {
  16100. _iterator.return();
  16101. }
  16102. } finally {
  16103. if (_didIteratorError) {
  16104. throw _iteratorError;
  16105. }
  16106. }
  16107. }
  16108. return map;
  16109. }
  16110. function mapObject(object, fn) {
  16111. var newObject = Object.create(null);
  16112. for (var _i = 0, _Object$keys = Object.keys(object); _i < _Object$keys.length; _i++) {
  16113. var key = _Object$keys[_i];
  16114. newObject[key] = fn(object[key], key);
  16115. }
  16116. return newObject;
  16117. }
  16118. function shouldPreserveContent(node, options) {
  16119. if (node.type === "element" && node.fullName === "template" && node.attrMap.lang && node.attrMap.lang !== "html") {
  16120. return true;
  16121. } // unterminated node in ie conditional comment
  16122. // e.g. <!--[if lt IE 9]><html><![endif]-->
  16123. if (node.type === "ieConditionalComment" && node.lastChild && !node.lastChild.isSelfClosing && !node.lastChild.endSourceSpan) {
  16124. return true;
  16125. } // incomplete html in ie conditional comment
  16126. // e.g. <!--[if lt IE 9]></div><![endif]-->
  16127. if (node.type === "ieConditionalComment" && !node.complete) {
  16128. return true;
  16129. } // top-level elements (excluding <template>, <style> and <script>) in Vue SFC are considered custom block
  16130. // custom blocks can be written in other languages so we should preserve them to not break the code
  16131. if (options.parser === "vue" && node.type === "element" && node.parent.type === "root" && ["template", "style", "script", // vue parser can be used for vue dom template as well, so we should still format top-level <html>
  16132. "html"].indexOf(node.fullName) === -1) {
  16133. return true;
  16134. } // TODO: handle non-text children in <pre>
  16135. if (isPreLikeNode(node) && node.children.some(function (child) {
  16136. return child.type !== "text" && child.type !== "interpolation";
  16137. })) {
  16138. return true;
  16139. }
  16140. return false;
  16141. }
  16142. function hasPrettierIgnore(node) {
  16143. if (node.type === "attribute" || isTextLikeNode(node)) {
  16144. return false;
  16145. }
  16146. if (!node.parent) {
  16147. return false;
  16148. }
  16149. if (typeof node.index !== "number" || node.index === 0) {
  16150. return false;
  16151. }
  16152. var prevNode = node.parent.children[node.index - 1];
  16153. return isPrettierIgnore(prevNode);
  16154. }
  16155. function isPrettierIgnore(node) {
  16156. return node.type === "comment" && node.value.trim() === "prettier-ignore";
  16157. }
  16158. function getPrettierIgnoreAttributeCommentData(value) {
  16159. var match = value.trim().match(/^prettier-ignore-attribute(?:\s+([^]+))?$/);
  16160. if (!match) {
  16161. return false;
  16162. }
  16163. if (!match[1]) {
  16164. return true;
  16165. }
  16166. return match[1].split(/\s+/);
  16167. }
  16168. /** there's no opening/closing tag or it's considered not breakable */
  16169. function isTextLikeNode(node) {
  16170. return node.type === "text" || node.type === "comment";
  16171. }
  16172. function isScriptLikeTag(node) {
  16173. return node.type === "element" && (node.fullName === "script" || node.fullName === "style" || node.fullName === "svg:style");
  16174. }
  16175. function isFrontMatterNode(node) {
  16176. return node.type === "yaml" || node.type === "toml";
  16177. }
  16178. function canHaveInterpolation(node) {
  16179. return node.children && !isScriptLikeTag(node);
  16180. }
  16181. function isWhitespaceSensitiveNode(node) {
  16182. return isScriptLikeTag(node) || node.type === "interpolation" || isIndentationSensitiveNode(node);
  16183. }
  16184. function isIndentationSensitiveNode(node) {
  16185. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  16186. }
  16187. function isLeadingSpaceSensitiveNode(node) {
  16188. var isLeadingSpaceSensitive = _isLeadingSpaceSensitiveNode();
  16189. if (isLeadingSpaceSensitive && !node.prev && node.parent && node.parent.tagDefinition && node.parent.tagDefinition.ignoreFirstLf) {
  16190. return node.type === "interpolation";
  16191. }
  16192. return isLeadingSpaceSensitive;
  16193. function _isLeadingSpaceSensitiveNode() {
  16194. if (isFrontMatterNode(node)) {
  16195. return false;
  16196. }
  16197. if ((node.type === "text" || node.type === "interpolation") && node.prev && (node.prev.type === "text" || node.prev.type === "interpolation")) {
  16198. return true;
  16199. }
  16200. if (!node.parent || node.parent.cssDisplay === "none") {
  16201. return false;
  16202. }
  16203. if (isPreLikeNode(node.parent)) {
  16204. return true;
  16205. }
  16206. if (!node.prev && (node.parent.type === "root" || isScriptLikeTag(node.parent) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  16207. return false;
  16208. }
  16209. if (node.prev && !isNextLeadingSpaceSensitiveCssDisplay(node.prev.cssDisplay)) {
  16210. return false;
  16211. }
  16212. return true;
  16213. }
  16214. }
  16215. function isTrailingSpaceSensitiveNode(node) {
  16216. if (isFrontMatterNode(node)) {
  16217. return false;
  16218. }
  16219. if ((node.type === "text" || node.type === "interpolation") && node.next && (node.next.type === "text" || node.next.type === "interpolation")) {
  16220. return true;
  16221. }
  16222. if (!node.parent || node.parent.cssDisplay === "none") {
  16223. return false;
  16224. }
  16225. if (isPreLikeNode(node.parent)) {
  16226. return true;
  16227. }
  16228. if (!node.next && (node.parent.type === "root" || isScriptLikeTag(node.parent) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  16229. return false;
  16230. }
  16231. if (node.next && !isPrevTrailingSpaceSensitiveCssDisplay(node.next.cssDisplay)) {
  16232. return false;
  16233. }
  16234. return true;
  16235. }
  16236. function isDanglingSpaceSensitiveNode(node) {
  16237. return isDanglingSpaceSensitiveCssDisplay(node.cssDisplay) && !isScriptLikeTag(node);
  16238. }
  16239. function forceNextEmptyLine(node) {
  16240. return isFrontMatterNode(node) || node.next && node.sourceSpan.end.line + 1 < node.next.sourceSpan.start.line;
  16241. }
  16242. /** firstChild leadingSpaces and lastChild trailingSpaces */
  16243. function forceBreakContent(node) {
  16244. return forceBreakChildren(node) || node.type === "element" && node.children.length !== 0 && (["body", "script", "style"].indexOf(node.name) !== -1 || node.children.some(function (child) {
  16245. return hasNonTextChild(child);
  16246. })) || node.firstChild && node.firstChild === node.lastChild && hasLeadingLineBreak(node.firstChild) && (!node.lastChild.isTrailingSpaceSensitive || hasTrailingLineBreak(node.lastChild));
  16247. }
  16248. /** spaces between children */
  16249. function forceBreakChildren(node) {
  16250. return node.type === "element" && node.children.length !== 0 && (["html", "head", "ul", "ol", "select"].indexOf(node.name) !== -1 || node.cssDisplay.startsWith("table") && node.cssDisplay !== "table-cell");
  16251. }
  16252. function preferHardlineAsLeadingSpaces(node) {
  16253. return preferHardlineAsSurroundingSpaces(node) || node.prev && preferHardlineAsTrailingSpaces(node.prev) || hasSurroundingLineBreak(node);
  16254. }
  16255. function preferHardlineAsTrailingSpaces(node) {
  16256. return preferHardlineAsSurroundingSpaces(node) || node.type === "element" && node.fullName === "br" || hasSurroundingLineBreak(node);
  16257. }
  16258. function hasSurroundingLineBreak(node) {
  16259. return hasLeadingLineBreak(node) && hasTrailingLineBreak(node);
  16260. }
  16261. function hasLeadingLineBreak(node) {
  16262. return node.hasLeadingSpaces && (node.prev ? node.prev.sourceSpan.end.line < node.sourceSpan.start.line : node.parent.type === "root" || node.parent.startSourceSpan.end.line < node.sourceSpan.start.line);
  16263. }
  16264. function hasTrailingLineBreak(node) {
  16265. return node.hasTrailingSpaces && (node.next ? node.next.sourceSpan.start.line > node.sourceSpan.end.line : node.parent.type === "root" || node.parent.endSourceSpan.start.line > node.sourceSpan.end.line);
  16266. }
  16267. function preferHardlineAsSurroundingSpaces(node) {
  16268. switch (node.type) {
  16269. case "ieConditionalComment":
  16270. case "comment":
  16271. case "directive":
  16272. return true;
  16273. case "element":
  16274. return ["script", "select"].indexOf(node.name) !== -1;
  16275. }
  16276. return false;
  16277. }
  16278. function getLastDescendant(node) {
  16279. return node.lastChild ? getLastDescendant(node.lastChild) : node;
  16280. }
  16281. function hasNonTextChild(node) {
  16282. return node.children && node.children.some(function (child) {
  16283. return child.type !== "text";
  16284. });
  16285. }
  16286. function inferScriptParser(node) {
  16287. if (node.name === "script" && !node.attrMap.src) {
  16288. if (!node.attrMap.lang && !node.attrMap.type || node.attrMap.type === "module" || node.attrMap.type === "text/javascript" || node.attrMap.type === "text/babel" || node.attrMap.type === "application/javascript") {
  16289. return "babel";
  16290. }
  16291. if (node.attrMap.type === "application/x-typescript" || node.attrMap.lang === "ts" || node.attrMap.lang === "tsx") {
  16292. return "typescript";
  16293. }
  16294. if (node.attrMap.type === "text/markdown") {
  16295. return "markdown";
  16296. }
  16297. if (node.attrMap.type.endsWith("json") || node.attrMap.type.endsWith("importmap")) {
  16298. return "json";
  16299. }
  16300. }
  16301. if (node.name === "style") {
  16302. if (!node.attrMap.lang || node.attrMap.lang === "postcss" || node.attrMap.lang === "css") {
  16303. return "css";
  16304. }
  16305. if (node.attrMap.lang === "scss") {
  16306. return "scss";
  16307. }
  16308. if (node.attrMap.lang === "less") {
  16309. return "less";
  16310. }
  16311. }
  16312. return null;
  16313. }
  16314. function isBlockLikeCssDisplay(cssDisplay) {
  16315. return cssDisplay === "block" || cssDisplay === "list-item" || cssDisplay.startsWith("table");
  16316. }
  16317. function isFirstChildLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  16318. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  16319. }
  16320. function isLastChildTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  16321. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  16322. }
  16323. function isPrevTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  16324. return !isBlockLikeCssDisplay(cssDisplay);
  16325. }
  16326. function isNextLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  16327. return !isBlockLikeCssDisplay(cssDisplay);
  16328. }
  16329. function isDanglingSpaceSensitiveCssDisplay(cssDisplay) {
  16330. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  16331. }
  16332. function isPreLikeNode(node) {
  16333. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  16334. }
  16335. function countParents(path) {
  16336. var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  16337. return true;
  16338. };
  16339. var counter = 0;
  16340. for (var i = path.stack.length - 1; i >= 0; i--) {
  16341. var value = path.stack[i];
  16342. if (value && _typeof(value) === "object" && !Array.isArray(value) && predicate(value)) {
  16343. counter++;
  16344. }
  16345. }
  16346. return counter;
  16347. }
  16348. function hasParent(node, fn) {
  16349. var current = node;
  16350. while (current) {
  16351. if (fn(current)) {
  16352. return true;
  16353. }
  16354. current = current.parent;
  16355. }
  16356. return false;
  16357. }
  16358. function getNodeCssStyleDisplay(node, options) {
  16359. if (node.prev && node.prev.type === "comment") {
  16360. // <!-- display: block -->
  16361. var match = node.prev.value.match(/^\s*display:\s*([a-z]+)\s*$/);
  16362. if (match) {
  16363. return match[1];
  16364. }
  16365. }
  16366. var isInSvgForeignObject = false;
  16367. if (node.type === "element" && node.namespace === "svg") {
  16368. if (hasParent(node, function (parent) {
  16369. return parent.fullName === "svg:foreignObject";
  16370. })) {
  16371. isInSvgForeignObject = true;
  16372. } else {
  16373. return node.name === "svg" ? "inline-block" : "block";
  16374. }
  16375. }
  16376. switch (options.htmlWhitespaceSensitivity) {
  16377. case "strict":
  16378. return "inline";
  16379. case "ignore":
  16380. return "block";
  16381. default:
  16382. return node.type === "element" && (!node.namespace || isInSvgForeignObject) && CSS_DISPLAY_TAGS[node.name] || CSS_DISPLAY_DEFAULT;
  16383. }
  16384. }
  16385. function getNodeCssStyleWhiteSpace(node) {
  16386. return node.type === "element" && !node.namespace && CSS_WHITE_SPACE_TAGS[node.name] || CSS_WHITE_SPACE_DEFAULT;
  16387. }
  16388. function getMinIndentation(text) {
  16389. var minIndentation = Infinity;
  16390. var _iteratorNormalCompletion2 = true;
  16391. var _didIteratorError2 = false;
  16392. var _iteratorError2 = undefined;
  16393. try {
  16394. for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  16395. var lineText = _step2.value;
  16396. if (lineText.length === 0) {
  16397. continue;
  16398. }
  16399. if (/\S/.test(lineText[0])) {
  16400. return 0;
  16401. }
  16402. var indentation = lineText.match(/^\s*/)[0].length;
  16403. if (lineText.length === indentation) {
  16404. continue;
  16405. }
  16406. if (indentation < minIndentation) {
  16407. minIndentation = indentation;
  16408. }
  16409. }
  16410. } catch (err) {
  16411. _didIteratorError2 = true;
  16412. _iteratorError2 = err;
  16413. } finally {
  16414. try {
  16415. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  16416. _iterator2.return();
  16417. }
  16418. } finally {
  16419. if (_didIteratorError2) {
  16420. throw _iteratorError2;
  16421. }
  16422. }
  16423. }
  16424. return minIndentation === Infinity ? 0 : minIndentation;
  16425. }
  16426. function dedentString(text) {
  16427. var minIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getMinIndentation(text);
  16428. return minIndent === 0 ? text : text.split("\n").map(function (lineText) {
  16429. return lineText.slice(minIndent);
  16430. }).join("\n");
  16431. }
  16432. function normalizeParts(parts) {
  16433. var newParts = [];
  16434. var restParts = parts.slice();
  16435. while (restParts.length !== 0) {
  16436. var part = restParts.shift();
  16437. if (!part) {
  16438. continue;
  16439. }
  16440. if (part.type === "concat") {
  16441. Array.prototype.unshift.apply(restParts, part.parts);
  16442. continue;
  16443. }
  16444. if (newParts.length !== 0 && typeof newParts[newParts.length - 1] === "string" && typeof part === "string") {
  16445. newParts.push(newParts.pop() + part);
  16446. continue;
  16447. }
  16448. newParts.push(part);
  16449. }
  16450. return newParts;
  16451. }
  16452. function identity(x) {
  16453. return x;
  16454. }
  16455. function shouldNotPrintClosingTag(node, options) {
  16456. return !node.isSelfClosing && !node.endSourceSpan && (hasPrettierIgnore(node) || shouldPreserveContent(node.parent, options));
  16457. }
  16458. function countChars(text, char) {
  16459. var counter = 0;
  16460. for (var i = 0; i < text.length; i++) {
  16461. if (text[i] === char) {
  16462. counter++;
  16463. }
  16464. }
  16465. return counter;
  16466. }
  16467. function unescapeQuoteEntities(text) {
  16468. return text.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  16469. }
  16470. var utils$3 = {
  16471. HTML_ELEMENT_ATTRIBUTES: HTML_ELEMENT_ATTRIBUTES,
  16472. HTML_TAGS: HTML_TAGS,
  16473. canHaveInterpolation: canHaveInterpolation,
  16474. countChars: countChars,
  16475. countParents: countParents,
  16476. dedentString: dedentString,
  16477. forceBreakChildren: forceBreakChildren,
  16478. forceBreakContent: forceBreakContent,
  16479. forceNextEmptyLine: forceNextEmptyLine,
  16480. getLastDescendant: getLastDescendant,
  16481. getNodeCssStyleDisplay: getNodeCssStyleDisplay,
  16482. getNodeCssStyleWhiteSpace: getNodeCssStyleWhiteSpace,
  16483. getPrettierIgnoreAttributeCommentData: getPrettierIgnoreAttributeCommentData,
  16484. hasPrettierIgnore: hasPrettierIgnore,
  16485. identity: identity,
  16486. inferScriptParser: inferScriptParser,
  16487. isDanglingSpaceSensitiveNode: isDanglingSpaceSensitiveNode,
  16488. isFrontMatterNode: isFrontMatterNode,
  16489. isIndentationSensitiveNode: isIndentationSensitiveNode,
  16490. isLeadingSpaceSensitiveNode: isLeadingSpaceSensitiveNode,
  16491. isPreLikeNode: isPreLikeNode,
  16492. isScriptLikeTag: isScriptLikeTag,
  16493. isTextLikeNode: isTextLikeNode,
  16494. isTrailingSpaceSensitiveNode: isTrailingSpaceSensitiveNode,
  16495. isWhitespaceSensitiveNode: isWhitespaceSensitiveNode,
  16496. normalizeParts: normalizeParts,
  16497. preferHardlineAsLeadingSpaces: preferHardlineAsLeadingSpaces,
  16498. preferHardlineAsTrailingSpaces: preferHardlineAsTrailingSpaces,
  16499. shouldNotPrintClosingTag: shouldNotPrintClosingTag,
  16500. shouldPreserveContent: shouldPreserveContent,
  16501. unescapeQuoteEntities: unescapeQuoteEntities
  16502. };
  16503. var canHaveInterpolation$1 = utils$3.canHaveInterpolation,
  16504. getNodeCssStyleDisplay$1 = utils$3.getNodeCssStyleDisplay,
  16505. isDanglingSpaceSensitiveNode$1 = utils$3.isDanglingSpaceSensitiveNode,
  16506. isIndentationSensitiveNode$1 = utils$3.isIndentationSensitiveNode,
  16507. isLeadingSpaceSensitiveNode$1 = utils$3.isLeadingSpaceSensitiveNode,
  16508. isTrailingSpaceSensitiveNode$1 = utils$3.isTrailingSpaceSensitiveNode,
  16509. isWhitespaceSensitiveNode$1 = utils$3.isWhitespaceSensitiveNode;
  16510. var PREPROCESS_PIPELINE = [removeIgnorableFirstLf, mergeIeConditonalStartEndCommentIntoElementOpeningTag, mergeCdataIntoText, extractInterpolation, extractWhitespaces, addCssDisplay, addIsSelfClosing, addHasHtmComponentClosingTag, addIsSpaceSensitive, mergeSimpleElementIntoText];
  16511. function preprocess(ast, options) {
  16512. var _iteratorNormalCompletion = true;
  16513. var _didIteratorError = false;
  16514. var _iteratorError = undefined;
  16515. try {
  16516. for (var _iterator = PREPROCESS_PIPELINE[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  16517. var fn = _step.value;
  16518. ast = fn(ast, options);
  16519. }
  16520. } catch (err) {
  16521. _didIteratorError = true;
  16522. _iteratorError = err;
  16523. } finally {
  16524. try {
  16525. if (!_iteratorNormalCompletion && _iterator.return != null) {
  16526. _iterator.return();
  16527. }
  16528. } finally {
  16529. if (_didIteratorError) {
  16530. throw _iteratorError;
  16531. }
  16532. }
  16533. }
  16534. return ast;
  16535. }
  16536. function removeIgnorableFirstLf(ast
  16537. /*, options */
  16538. ) {
  16539. return ast.map(function (node) {
  16540. if (node.type === "element" && node.tagDefinition.ignoreFirstLf && node.children.length !== 0 && node.children[0].type === "text" && node.children[0].value[0] === "\n") {
  16541. var text = node.children[0];
  16542. return node.clone({
  16543. children: text.value.length === 1 ? node.children.slice(1) : [].concat(text.clone({
  16544. value: text.value.slice(1)
  16545. }), node.children.slice(1))
  16546. });
  16547. }
  16548. return node;
  16549. });
  16550. }
  16551. function mergeIeConditonalStartEndCommentIntoElementOpeningTag(ast
  16552. /*, options */
  16553. ) {
  16554. /**
  16555. * <!--[if ...]><!--><target><!--<![endif]-->
  16556. */
  16557. var isTarget = function isTarget(node) {
  16558. return node.type === "element" && node.prev && node.prev.type === "ieConditionalStartComment" && node.prev.sourceSpan.end.offset === node.startSourceSpan.start.offset && node.firstChild && node.firstChild.type === "ieConditionalEndComment" && node.firstChild.sourceSpan.start.offset === node.startSourceSpan.end.offset;
  16559. };
  16560. return ast.map(function (node) {
  16561. if (node.children) {
  16562. var isTargetResults = node.children.map(isTarget);
  16563. if (isTargetResults.some(Boolean)) {
  16564. var newChildren = [];
  16565. for (var i = 0; i < node.children.length; i++) {
  16566. var child = node.children[i];
  16567. if (isTargetResults[i + 1]) {
  16568. // ieConditionalStartComment
  16569. continue;
  16570. }
  16571. if (isTargetResults[i]) {
  16572. var ieConditionalStartComment = child.prev;
  16573. var ieConditionalEndComment = child.firstChild;
  16574. var ParseSourceSpan = child.sourceSpan.constructor;
  16575. var startSourceSpan = new ParseSourceSpan(ieConditionalStartComment.sourceSpan.start, ieConditionalEndComment.sourceSpan.end);
  16576. var sourceSpan = new ParseSourceSpan(startSourceSpan.start, child.sourceSpan.end);
  16577. newChildren.push(child.clone({
  16578. condition: ieConditionalStartComment.condition,
  16579. sourceSpan: sourceSpan,
  16580. startSourceSpan: startSourceSpan,
  16581. children: child.children.slice(1)
  16582. }));
  16583. continue;
  16584. }
  16585. newChildren.push(child);
  16586. }
  16587. return node.clone({
  16588. children: newChildren
  16589. });
  16590. }
  16591. }
  16592. return node;
  16593. });
  16594. }
  16595. function mergeNodeIntoText(ast, shouldMerge, getValue) {
  16596. return ast.map(function (node) {
  16597. if (node.children) {
  16598. var shouldMergeResults = node.children.map(shouldMerge);
  16599. if (shouldMergeResults.some(Boolean)) {
  16600. var newChildren = [];
  16601. for (var i = 0; i < node.children.length; i++) {
  16602. var child = node.children[i];
  16603. if (child.type !== "text" && !shouldMergeResults[i]) {
  16604. newChildren.push(child);
  16605. continue;
  16606. }
  16607. var newChild = child.type === "text" ? child : child.clone({
  16608. type: "text",
  16609. value: getValue(child)
  16610. });
  16611. if (newChildren.length === 0 || newChildren[newChildren.length - 1].type !== "text") {
  16612. newChildren.push(newChild);
  16613. continue;
  16614. }
  16615. var lastChild = newChildren.pop();
  16616. var ParseSourceSpan = lastChild.sourceSpan.constructor;
  16617. newChildren.push(lastChild.clone({
  16618. value: lastChild.value + newChild.value,
  16619. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, newChild.sourceSpan.end)
  16620. }));
  16621. }
  16622. return node.clone({
  16623. children: newChildren
  16624. });
  16625. }
  16626. }
  16627. return node;
  16628. });
  16629. }
  16630. function mergeCdataIntoText(ast
  16631. /*, options */
  16632. ) {
  16633. return mergeNodeIntoText(ast, function (node) {
  16634. return node.type === "cdata";
  16635. }, function (node) {
  16636. return "<![CDATA[".concat(node.value, "]]>");
  16637. });
  16638. }
  16639. function mergeSimpleElementIntoText(ast
  16640. /*, options */
  16641. ) {
  16642. var isSimpleElement = function isSimpleElement(node) {
  16643. return node.type === "element" && node.attrs.length === 0 && node.children.length === 1 && node.firstChild.type === "text" && // \xA0: non-breaking whitespace
  16644. !/[^\S\xA0]/.test(node.children[0].value) && !node.firstChild.hasLeadingSpaces && !node.firstChild.hasTrailingSpaces && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces && node.prev && node.prev.type === "text" && node.next && node.next.type === "text";
  16645. };
  16646. return ast.map(function (node) {
  16647. if (node.children) {
  16648. var isSimpleElementResults = node.children.map(isSimpleElement);
  16649. if (isSimpleElementResults.some(Boolean)) {
  16650. var newChildren = [];
  16651. for (var i = 0; i < node.children.length; i++) {
  16652. var child = node.children[i];
  16653. if (isSimpleElementResults[i]) {
  16654. var lastChild = newChildren.pop();
  16655. var nextChild = node.children[++i];
  16656. var ParseSourceSpan = node.sourceSpan.constructor;
  16657. var isTrailingSpaceSensitive = nextChild.isTrailingSpaceSensitive,
  16658. hasTrailingSpaces = nextChild.hasTrailingSpaces;
  16659. newChildren.push(lastChild.clone({
  16660. value: lastChild.value + "<".concat(child.rawName, ">") + child.firstChild.value + "</".concat(child.rawName, ">") + nextChild.value,
  16661. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, nextChild.sourceSpan.end),
  16662. isTrailingSpaceSensitive: isTrailingSpaceSensitive,
  16663. hasTrailingSpaces: hasTrailingSpaces
  16664. }));
  16665. } else {
  16666. newChildren.push(child);
  16667. }
  16668. }
  16669. return node.clone({
  16670. children: newChildren
  16671. });
  16672. }
  16673. }
  16674. return node;
  16675. });
  16676. }
  16677. function extractInterpolation(ast, options) {
  16678. if (options.parser === "html") {
  16679. return ast;
  16680. }
  16681. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  16682. return ast.map(function (node) {
  16683. if (!canHaveInterpolation$1(node)) {
  16684. return node;
  16685. }
  16686. var newChildren = [];
  16687. var _iteratorNormalCompletion2 = true;
  16688. var _didIteratorError2 = false;
  16689. var _iteratorError2 = undefined;
  16690. try {
  16691. for (var _iterator2 = node.children[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  16692. var child = _step2.value;
  16693. if (child.type !== "text") {
  16694. newChildren.push(child);
  16695. continue;
  16696. }
  16697. var ParseSourceSpan = child.sourceSpan.constructor;
  16698. var startSourceSpan = child.sourceSpan.start;
  16699. var endSourceSpan = null;
  16700. var components = child.value.split(interpolationRegex);
  16701. for (var i = 0; i < components.length; i++, startSourceSpan = endSourceSpan) {
  16702. var value = components[i];
  16703. if (i % 2 === 0) {
  16704. endSourceSpan = startSourceSpan.moveBy(value.length);
  16705. if (value.length !== 0) {
  16706. newChildren.push({
  16707. type: "text",
  16708. value: value,
  16709. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan)
  16710. });
  16711. }
  16712. continue;
  16713. }
  16714. endSourceSpan = startSourceSpan.moveBy(value.length + 4); // `{{` + `}}`
  16715. newChildren.push({
  16716. type: "interpolation",
  16717. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan),
  16718. children: value.length === 0 ? [] : [{
  16719. type: "text",
  16720. value: value,
  16721. sourceSpan: new ParseSourceSpan(startSourceSpan.moveBy(2), endSourceSpan.moveBy(-2))
  16722. }]
  16723. });
  16724. }
  16725. }
  16726. } catch (err) {
  16727. _didIteratorError2 = true;
  16728. _iteratorError2 = err;
  16729. } finally {
  16730. try {
  16731. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  16732. _iterator2.return();
  16733. }
  16734. } finally {
  16735. if (_didIteratorError2) {
  16736. throw _iteratorError2;
  16737. }
  16738. }
  16739. }
  16740. return node.clone({
  16741. children: newChildren
  16742. });
  16743. });
  16744. }
  16745. /**
  16746. * - add `hasLeadingSpaces` field
  16747. * - add `hasTrailingSpaces` field
  16748. * - add `hasDanglingSpaces` field for parent nodes
  16749. * - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes
  16750. * - remove insensitive whitespaces
  16751. */
  16752. function extractWhitespaces(ast
  16753. /*, options*/
  16754. ) {
  16755. var TYPE_WHITESPACE = "whitespace";
  16756. return ast.map(function (node) {
  16757. if (!node.children) {
  16758. return node;
  16759. }
  16760. if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "text" && node.children[0].value.trim().length === 0) {
  16761. return node.clone({
  16762. children: [],
  16763. hasDanglingSpaces: node.children.length !== 0
  16764. });
  16765. }
  16766. var isWhitespaceSensitive = isWhitespaceSensitiveNode$1(node);
  16767. var isIndentationSensitive = isIndentationSensitiveNode$1(node);
  16768. return node.clone({
  16769. isWhitespaceSensitive: isWhitespaceSensitive,
  16770. isIndentationSensitive: isIndentationSensitive,
  16771. children: node.children // extract whitespace nodes
  16772. .reduce(function (newChildren, child) {
  16773. if (child.type !== "text" || isWhitespaceSensitive) {
  16774. return newChildren.concat(child);
  16775. }
  16776. var localChildren = [];
  16777. var _child$value$match = child.value.match(/^(\s*)([\s\S]*?)(\s*)$/),
  16778. _child$value$match2 = _slicedToArray(_child$value$match, 4),
  16779. leadingSpaces = _child$value$match2[1],
  16780. text = _child$value$match2[2],
  16781. trailingSpaces = _child$value$match2[3];
  16782. if (leadingSpaces) {
  16783. localChildren.push({
  16784. type: TYPE_WHITESPACE
  16785. });
  16786. }
  16787. var ParseSourceSpan = child.sourceSpan.constructor;
  16788. if (text) {
  16789. localChildren.push({
  16790. type: "text",
  16791. value: text,
  16792. sourceSpan: new ParseSourceSpan(child.sourceSpan.start.moveBy(leadingSpaces.length), child.sourceSpan.end.moveBy(-trailingSpaces.length))
  16793. });
  16794. }
  16795. if (trailingSpaces) {
  16796. localChildren.push({
  16797. type: TYPE_WHITESPACE
  16798. });
  16799. }
  16800. return newChildren.concat(localChildren);
  16801. }, []) // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes
  16802. .reduce(function (newChildren, child, i, children) {
  16803. if (child.type === TYPE_WHITESPACE) {
  16804. return newChildren;
  16805. }
  16806. var hasLeadingSpaces = i !== 0 && children[i - 1].type === TYPE_WHITESPACE;
  16807. var hasTrailingSpaces = i !== children.length - 1 && children[i + 1].type === TYPE_WHITESPACE;
  16808. return newChildren.concat(Object.assign({}, child, {
  16809. hasLeadingSpaces: hasLeadingSpaces,
  16810. hasTrailingSpaces: hasTrailingSpaces
  16811. }));
  16812. }, [])
  16813. });
  16814. });
  16815. }
  16816. function addIsSelfClosing(ast
  16817. /*, options */
  16818. ) {
  16819. return ast.map(function (node) {
  16820. return Object.assign(node, {
  16821. isSelfClosing: !node.children || node.type === "element" && (node.tagDefinition.isVoid || // self-closing
  16822. node.startSourceSpan === node.endSourceSpan)
  16823. });
  16824. });
  16825. }
  16826. function addHasHtmComponentClosingTag(ast, options) {
  16827. return ast.map(function (node) {
  16828. return node.type !== "element" ? node : Object.assign(node, {
  16829. hasHtmComponentClosingTag: node.endSourceSpan && /^<\s*\/\s*\/\s*>$/.test(options.originalText.slice(node.endSourceSpan.start.offset, node.endSourceSpan.end.offset))
  16830. });
  16831. });
  16832. }
  16833. function addCssDisplay(ast, options) {
  16834. return ast.map(function (node) {
  16835. return Object.assign(node, {
  16836. cssDisplay: getNodeCssStyleDisplay$1(node, options)
  16837. });
  16838. });
  16839. }
  16840. /**
  16841. * - add `isLeadingSpaceSensitive` field
  16842. * - add `isTrailingSpaceSensitive` field
  16843. * - add `isDanglingSpaceSensitive` field for parent nodes
  16844. */
  16845. function addIsSpaceSensitive(ast
  16846. /*, options */
  16847. ) {
  16848. return ast.map(function (node) {
  16849. if (!node.children) {
  16850. return node;
  16851. }
  16852. if (node.children.length === 0) {
  16853. return node.clone({
  16854. isDanglingSpaceSensitive: isDanglingSpaceSensitiveNode$1(node)
  16855. });
  16856. }
  16857. return node.clone({
  16858. children: node.children.map(function (child) {
  16859. return Object.assign({}, child, {
  16860. isLeadingSpaceSensitive: isLeadingSpaceSensitiveNode$1(child),
  16861. isTrailingSpaceSensitive: isTrailingSpaceSensitiveNode$1(child)
  16862. });
  16863. }).map(function (child, index, children) {
  16864. return Object.assign({}, child, {
  16865. isLeadingSpaceSensitive: index === 0 ? child.isLeadingSpaceSensitive : children[index - 1].isTrailingSpaceSensitive && child.isLeadingSpaceSensitive,
  16866. isTrailingSpaceSensitive: index === children.length - 1 ? child.isTrailingSpaceSensitive : children[index + 1].isLeadingSpaceSensitive && child.isTrailingSpaceSensitive
  16867. });
  16868. })
  16869. });
  16870. });
  16871. }
  16872. var preprocess_1 = preprocess;
  16873. function hasPragma$3(text) {
  16874. return /^\s*<!--\s*@(format|prettier)\s*-->/.test(text);
  16875. }
  16876. function insertPragma$5(text) {
  16877. return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, "");
  16878. }
  16879. var pragma$3 = {
  16880. hasPragma: hasPragma$3,
  16881. insertPragma: insertPragma$5
  16882. };
  16883. var _require$$0$builders$4 = doc.builders,
  16884. concat$8 = _require$$0$builders$4.concat,
  16885. group$8 = _require$$0$builders$4.group;
  16886. /**
  16887. * v-for="... in ..."
  16888. * v-for="... of ..."
  16889. * v-for="(..., ...) in ..."
  16890. * v-for="(..., ...) of ..."
  16891. */
  16892. function printVueFor(value, textToDoc) {
  16893. var _parseVueFor = parseVueFor(value),
  16894. left = _parseVueFor.left,
  16895. operator = _parseVueFor.operator,
  16896. right = _parseVueFor.right;
  16897. return concat$8([group$8(textToDoc("function _(".concat(left, ") {}"), {
  16898. parser: "babel",
  16899. __isVueForBindingLeft: true
  16900. })), " ", operator, " ", textToDoc(right, {
  16901. parser: "__js_expression"
  16902. })]);
  16903. } // modified from https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/parser/index.js#L370-L387
  16904. function parseVueFor(value) {
  16905. var forAliasRE = /([^]*?)\s+(in|of)\s+([^]*)/;
  16906. var forIteratorRE = /,([^,}\]]*)(?:,([^,}\]]*))?$/;
  16907. var stripParensRE = /^\(|\)$/g;
  16908. var inMatch = value.match(forAliasRE);
  16909. if (!inMatch) {
  16910. return;
  16911. }
  16912. var res = {};
  16913. res.for = inMatch[3].trim();
  16914. var alias = inMatch[1].trim().replace(stripParensRE, "");
  16915. var iteratorMatch = alias.match(forIteratorRE);
  16916. if (iteratorMatch) {
  16917. res.alias = alias.replace(forIteratorRE, "");
  16918. res.iterator1 = iteratorMatch[1].trim();
  16919. if (iteratorMatch[2]) {
  16920. res.iterator2 = iteratorMatch[2].trim();
  16921. }
  16922. } else {
  16923. res.alias = alias;
  16924. }
  16925. return {
  16926. left: "".concat([res.alias, res.iterator1, res.iterator2].filter(Boolean).join(",")),
  16927. operator: inMatch[2],
  16928. right: res.for
  16929. };
  16930. }
  16931. function printVueSlotScope(value, textToDoc) {
  16932. return textToDoc("function _(".concat(value, ") {}"), {
  16933. parser: "babel",
  16934. __isVueSlotScope: true
  16935. });
  16936. }
  16937. function isVueEventBindingExpression(eventBindingValue) {
  16938. // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/codegen/events.js#L3-L4
  16939. // arrow function or anonymous function
  16940. var fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/; // simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b])
  16941. var simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/; // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104
  16942. var value = eventBindingValue.trim();
  16943. return fnExpRE.test(value) || simplePathRE.test(value);
  16944. }
  16945. var syntaxVue = {
  16946. isVueEventBindingExpression: isVueEventBindingExpression,
  16947. printVueFor: printVueFor,
  16948. printVueSlotScope: printVueSlotScope
  16949. };
  16950. var parseSrcset = createCommonjsModule(function (module) {
  16951. /**
  16952. * Srcset Parser
  16953. *
  16954. * By Alex Bell | MIT License
  16955. *
  16956. * JS Parser for the string value that appears in markup <img srcset="here">
  16957. *
  16958. * @returns Array [{url: _, d: _, w: _, h:_}, ...]
  16959. *
  16960. * Based super duper closely on the reference algorithm at:
  16961. * https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute
  16962. *
  16963. * Most comments are copied in directly from the spec
  16964. * (except for comments in parens).
  16965. */
  16966. (function (root, factory) {
  16967. if ( module.exports) {
  16968. // Node. Does not work with strict CommonJS, but
  16969. // only CommonJS-like environments that support module.exports,
  16970. // like Node.
  16971. module.exports = factory();
  16972. } else {
  16973. // Browser globals (root is window)
  16974. root.parseSrcset = factory();
  16975. }
  16976. })(commonjsGlobal, function () {
  16977. // 1. Let input be the value passed to this algorithm.
  16978. return function (input, options) {
  16979. var logger = options && options.logger || console; // UTILITY FUNCTIONS
  16980. // Manual is faster than RegEx
  16981. // http://bjorn.tipling.com/state-and-regular-expressions-in-javascript
  16982. // http://jsperf.com/whitespace-character/5
  16983. function isSpace(c) {
  16984. return c === " " || // space
  16985. c === "\t" || // horizontal tab
  16986. c === "\n" || // new line
  16987. c === "\f" || // form feed
  16988. c === "\r"; // carriage return
  16989. }
  16990. function collectCharacters(regEx) {
  16991. var chars,
  16992. match = regEx.exec(input.substring(pos));
  16993. if (match) {
  16994. chars = match[0];
  16995. pos += chars.length;
  16996. return chars;
  16997. }
  16998. }
  16999. var inputLength = input.length,
  17000. // (Don't use \s, to avoid matching non-breaking space)
  17001. regexLeadingSpaces = /^[ \t\n\r\u000c]+/,
  17002. regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/,
  17003. regexLeadingNotSpaces = /^[^ \t\n\r\u000c]+/,
  17004. regexTrailingCommas = /[,]+$/,
  17005. regexNonNegativeInteger = /^\d+$/,
  17006. // ( Positive or negative or unsigned integers or decimals, without or without exponents.
  17007. // Must include at least one digit.
  17008. // According to spec tests any decimal point must be followed by a digit.
  17009. // No leading plus sign is allowed.)
  17010. // https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
  17011. regexFloatingPoint = /^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,
  17012. url,
  17013. descriptors,
  17014. currentDescriptor,
  17015. state,
  17016. c,
  17017. // 2. Let position be a pointer into input, initially pointing at the start
  17018. // of the string.
  17019. pos = 0,
  17020. // 3. Let candidates be an initially empty source set.
  17021. candidates = []; // 4. Splitting loop: Collect a sequence of characters that are space
  17022. // characters or U+002C COMMA characters. If any U+002C COMMA characters
  17023. // were collected, that is a parse error.
  17024. while (true) {
  17025. collectCharacters(regexLeadingCommasOrSpaces); // 5. If position is past the end of input, return candidates and abort these steps.
  17026. if (pos >= inputLength) {
  17027. return candidates; // (we're done, this is the sole return path)
  17028. } // 6. Collect a sequence of characters that are not space characters,
  17029. // and let that be url.
  17030. url = collectCharacters(regexLeadingNotSpaces); // 7. Let descriptors be a new empty list.
  17031. descriptors = []; // 8. If url ends with a U+002C COMMA character (,), follow these substeps:
  17032. // (1). Remove all trailing U+002C COMMA characters from url. If this removed
  17033. // more than one character, that is a parse error.
  17034. if (url.slice(-1) === ",") {
  17035. url = url.replace(regexTrailingCommas, ""); // (Jump ahead to step 9 to skip tokenization and just push the candidate).
  17036. parseDescriptors(); // Otherwise, follow these substeps:
  17037. } else {
  17038. tokenize();
  17039. } // (close else of step 8)
  17040. // 16. Return to the step labeled splitting loop.
  17041. } // (Close of big while loop.)
  17042. /**
  17043. * Tokenizes descriptor properties prior to parsing
  17044. * Returns undefined.
  17045. */
  17046. function tokenize() {
  17047. // 8.1. Descriptor tokeniser: Skip whitespace
  17048. collectCharacters(regexLeadingSpaces); // 8.2. Let current descriptor be the empty string.
  17049. currentDescriptor = ""; // 8.3. Let state be in descriptor.
  17050. state = "in descriptor";
  17051. while (true) {
  17052. // 8.4. Let c be the character at position.
  17053. c = input.charAt(pos); // Do the following depending on the value of state.
  17054. // For the purpose of this step, "EOF" is a special character representing
  17055. // that position is past the end of input.
  17056. // In descriptor
  17057. if (state === "in descriptor") {
  17058. // Do the following, depending on the value of c:
  17059. // Space character
  17060. // If current descriptor is not empty, append current descriptor to
  17061. // descriptors and let current descriptor be the empty string.
  17062. // Set state to after descriptor.
  17063. if (isSpace(c)) {
  17064. if (currentDescriptor) {
  17065. descriptors.push(currentDescriptor);
  17066. currentDescriptor = "";
  17067. state = "after descriptor";
  17068. } // U+002C COMMA (,)
  17069. // Advance position to the next character in input. If current descriptor
  17070. // is not empty, append current descriptor to descriptors. Jump to the step
  17071. // labeled descriptor parser.
  17072. } else if (c === ",") {
  17073. pos += 1;
  17074. if (currentDescriptor) {
  17075. descriptors.push(currentDescriptor);
  17076. }
  17077. parseDescriptors();
  17078. return; // U+0028 LEFT PARENTHESIS (()
  17079. // Append c to current descriptor. Set state to in parens.
  17080. } else if (c === "(") {
  17081. currentDescriptor = currentDescriptor + c;
  17082. state = "in parens"; // EOF
  17083. // If current descriptor is not empty, append current descriptor to
  17084. // descriptors. Jump to the step labeled descriptor parser.
  17085. } else if (c === "") {
  17086. if (currentDescriptor) {
  17087. descriptors.push(currentDescriptor);
  17088. }
  17089. parseDescriptors();
  17090. return; // Anything else
  17091. // Append c to current descriptor.
  17092. } else {
  17093. currentDescriptor = currentDescriptor + c;
  17094. } // (end "in descriptor"
  17095. // In parens
  17096. } else if (state === "in parens") {
  17097. // U+0029 RIGHT PARENTHESIS ())
  17098. // Append c to current descriptor. Set state to in descriptor.
  17099. if (c === ")") {
  17100. currentDescriptor = currentDescriptor + c;
  17101. state = "in descriptor"; // EOF
  17102. // Append current descriptor to descriptors. Jump to the step labeled
  17103. // descriptor parser.
  17104. } else if (c === "") {
  17105. descriptors.push(currentDescriptor);
  17106. parseDescriptors();
  17107. return; // Anything else
  17108. // Append c to current descriptor.
  17109. } else {
  17110. currentDescriptor = currentDescriptor + c;
  17111. } // After descriptor
  17112. } else if (state === "after descriptor") {
  17113. // Do the following, depending on the value of c:
  17114. // Space character: Stay in this state.
  17115. if (isSpace(c)) ; else if (c === "") {
  17116. parseDescriptors();
  17117. return; // Anything else
  17118. // Set state to in descriptor. Set position to the previous character in input.
  17119. } else {
  17120. state = "in descriptor";
  17121. pos -= 1;
  17122. }
  17123. } // Advance position to the next character in input.
  17124. pos += 1; // Repeat this step.
  17125. } // (close while true loop)
  17126. }
  17127. /**
  17128. * Adds descriptor properties to a candidate, pushes to the candidates array
  17129. * @return undefined
  17130. */
  17131. // Declared outside of the while loop so that it's only created once.
  17132. function parseDescriptors() {
  17133. // 9. Descriptor parser: Let error be no.
  17134. var pError = false,
  17135. // 10. Let width be absent.
  17136. // 11. Let density be absent.
  17137. // 12. Let future-compat-h be absent. (We're implementing it now as h)
  17138. w,
  17139. d,
  17140. h,
  17141. i,
  17142. candidate = {},
  17143. desc,
  17144. lastChar,
  17145. value,
  17146. intVal,
  17147. floatVal; // 13. For each descriptor in descriptors, run the appropriate set of steps
  17148. // from the following list:
  17149. for (i = 0; i < descriptors.length; i++) {
  17150. desc = descriptors[i];
  17151. lastChar = desc[desc.length - 1];
  17152. value = desc.substring(0, desc.length - 1);
  17153. intVal = parseInt(value, 10);
  17154. floatVal = parseFloat(value); // If the descriptor consists of a valid non-negative integer followed by
  17155. // a U+0077 LATIN SMALL LETTER W character
  17156. if (regexNonNegativeInteger.test(value) && lastChar === "w") {
  17157. // If width and density are not both absent, then let error be yes.
  17158. if (w || d) {
  17159. pError = true;
  17160. } // Apply the rules for parsing non-negative integers to the descriptor.
  17161. // If the result is zero, let error be yes.
  17162. // Otherwise, let width be the result.
  17163. if (intVal === 0) {
  17164. pError = true;
  17165. } else {
  17166. w = intVal;
  17167. } // If the descriptor consists of a valid floating-point number followed by
  17168. // a U+0078 LATIN SMALL LETTER X character
  17169. } else if (regexFloatingPoint.test(value) && lastChar === "x") {
  17170. // If width, density and future-compat-h are not all absent, then let error
  17171. // be yes.
  17172. if (w || d || h) {
  17173. pError = true;
  17174. } // Apply the rules for parsing floating-point number values to the descriptor.
  17175. // If the result is less than zero, let error be yes. Otherwise, let density
  17176. // be the result.
  17177. if (floatVal < 0) {
  17178. pError = true;
  17179. } else {
  17180. d = floatVal;
  17181. } // If the descriptor consists of a valid non-negative integer followed by
  17182. // a U+0068 LATIN SMALL LETTER H character
  17183. } else if (regexNonNegativeInteger.test(value) && lastChar === "h") {
  17184. // If height and density are not both absent, then let error be yes.
  17185. if (h || d) {
  17186. pError = true;
  17187. } // Apply the rules for parsing non-negative integers to the descriptor.
  17188. // If the result is zero, let error be yes. Otherwise, let future-compat-h
  17189. // be the result.
  17190. if (intVal === 0) {
  17191. pError = true;
  17192. } else {
  17193. h = intVal;
  17194. } // Anything else, Let error be yes.
  17195. } else {
  17196. pError = true;
  17197. }
  17198. } // (close step 13 for loop)
  17199. // 15. If error is still no, then append a new image source to candidates whose
  17200. // URL is url, associated with a width width if not absent and a pixel
  17201. // density density if not absent. Otherwise, there is a parse error.
  17202. if (!pError) {
  17203. candidate.url = url;
  17204. if (w) {
  17205. candidate.w = w;
  17206. }
  17207. if (d) {
  17208. candidate.d = d;
  17209. }
  17210. if (h) {
  17211. candidate.h = h;
  17212. }
  17213. candidates.push(candidate);
  17214. } else if (logger && logger.error) {
  17215. logger.error("Invalid srcset descriptor found in '" + input + "' at '" + desc + "'.");
  17216. }
  17217. } // (close parseDescriptors fn)
  17218. };
  17219. });
  17220. });
  17221. var _require$$0$builders$5 = doc.builders,
  17222. concat$9 = _require$$0$builders$5.concat,
  17223. ifBreak$4 = _require$$0$builders$5.ifBreak,
  17224. join$5 = _require$$0$builders$5.join,
  17225. line$4 = _require$$0$builders$5.line;
  17226. function printImgSrcset(value) {
  17227. var srcset = parseSrcset(value, {
  17228. logger: {
  17229. error: function error(message) {
  17230. throw new Error(message);
  17231. }
  17232. }
  17233. });
  17234. var hasW = srcset.some(function (src) {
  17235. return src.w;
  17236. });
  17237. var hasH = srcset.some(function (src) {
  17238. return src.h;
  17239. });
  17240. var hasX = srcset.some(function (src) {
  17241. return src.d;
  17242. });
  17243. if (hasW + hasH + hasX !== 1) {
  17244. throw new Error("Mixed descriptor in srcset is not supported");
  17245. }
  17246. var key = hasW ? "w" : hasH ? "h" : "d";
  17247. var unit = hasW ? "w" : hasH ? "h" : "x";
  17248. var getMax = function getMax(values) {
  17249. return Math.max.apply(Math, values);
  17250. };
  17251. var urls = srcset.map(function (src) {
  17252. return src.url;
  17253. });
  17254. var maxUrlLength = getMax(urls.map(function (url) {
  17255. return url.length;
  17256. }));
  17257. var descriptors = srcset.map(function (src) {
  17258. return src[key];
  17259. }).map(function (descriptor) {
  17260. return descriptor ? descriptor.toString() : "";
  17261. });
  17262. var descriptorLeftLengths = descriptors.map(function (descriptor) {
  17263. var index = descriptor.indexOf(".");
  17264. return index === -1 ? descriptor.length : index;
  17265. });
  17266. var maxDescriptorLeftLength = getMax(descriptorLeftLengths);
  17267. return join$5(concat$9([",", line$4]), urls.map(function (url, index) {
  17268. var parts = [url];
  17269. var descriptor = descriptors[index];
  17270. if (descriptor) {
  17271. var urlPadding = maxUrlLength - url.length + 1;
  17272. var descriptorPadding = maxDescriptorLeftLength - descriptorLeftLengths[index];
  17273. var alignment = " ".repeat(urlPadding + descriptorPadding);
  17274. parts.push(ifBreak$4(alignment, " "), descriptor + unit);
  17275. }
  17276. return concat$9(parts);
  17277. }));
  17278. }
  17279. var syntaxAttribute = {
  17280. printImgSrcset: printImgSrcset
  17281. };
  17282. var builders = doc.builders,
  17283. _require$$0$utils = doc.utils,
  17284. stripTrailingHardline$1 = _require$$0$utils.stripTrailingHardline,
  17285. mapDoc$4 = _require$$0$utils.mapDoc;
  17286. var breakParent$2 = builders.breakParent,
  17287. dedentToRoot$1 = builders.dedentToRoot,
  17288. fill$3 = builders.fill,
  17289. group$9 = builders.group,
  17290. hardline$7 = builders.hardline,
  17291. ifBreak$5 = builders.ifBreak,
  17292. indent$5 = builders.indent,
  17293. join$6 = builders.join,
  17294. line$5 = builders.line,
  17295. literalline$2 = builders.literalline,
  17296. markAsRoot$2 = builders.markAsRoot,
  17297. softline$4 = builders.softline;
  17298. var countChars$1 = utils$3.countChars,
  17299. countParents$1 = utils$3.countParents,
  17300. dedentString$1 = utils$3.dedentString,
  17301. forceBreakChildren$1 = utils$3.forceBreakChildren,
  17302. forceBreakContent$1 = utils$3.forceBreakContent,
  17303. forceNextEmptyLine$1 = utils$3.forceNextEmptyLine,
  17304. getLastDescendant$1 = utils$3.getLastDescendant,
  17305. getPrettierIgnoreAttributeCommentData$1 = utils$3.getPrettierIgnoreAttributeCommentData,
  17306. hasPrettierIgnore$1 = utils$3.hasPrettierIgnore,
  17307. inferScriptParser$1 = utils$3.inferScriptParser,
  17308. isScriptLikeTag$1 = utils$3.isScriptLikeTag,
  17309. isTextLikeNode$1 = utils$3.isTextLikeNode,
  17310. normalizeParts$1 = utils$3.normalizeParts,
  17311. preferHardlineAsLeadingSpaces$1 = utils$3.preferHardlineAsLeadingSpaces,
  17312. shouldNotPrintClosingTag$1 = utils$3.shouldNotPrintClosingTag,
  17313. shouldPreserveContent$1 = utils$3.shouldPreserveContent,
  17314. unescapeQuoteEntities$1 = utils$3.unescapeQuoteEntities;
  17315. var replaceEndOfLineWith$1 = util.replaceEndOfLineWith;
  17316. var insertPragma$6 = pragma$3.insertPragma;
  17317. var printVueFor$1 = syntaxVue.printVueFor,
  17318. printVueSlotScope$1 = syntaxVue.printVueSlotScope,
  17319. isVueEventBindingExpression$1 = syntaxVue.isVueEventBindingExpression;
  17320. var printImgSrcset$1 = syntaxAttribute.printImgSrcset;
  17321. function concat$a(parts) {
  17322. var newParts = normalizeParts$1(parts);
  17323. return newParts.length === 0 ? "" : newParts.length === 1 ? newParts[0] : builders.concat(newParts);
  17324. }
  17325. function embed$2(path, print, textToDoc, options) {
  17326. var node = path.getValue();
  17327. switch (node.type) {
  17328. case "text":
  17329. {
  17330. if (isScriptLikeTag$1(node.parent)) {
  17331. var parser = inferScriptParser$1(node.parent);
  17332. if (parser) {
  17333. var value = parser === "markdown" ? dedentString$1(node.value.replace(/^[^\S\n]*?\n/, "")) : node.value;
  17334. return builders.concat([concat$a([breakParent$2, printOpeningTagPrefix(node, options), stripTrailingHardline$1(textToDoc(value, {
  17335. parser: parser
  17336. })), printClosingTagSuffix(node, options)])]);
  17337. }
  17338. } else if (node.parent.type === "interpolation") {
  17339. return concat$a([indent$5(concat$a([line$5, textToDoc(node.value, Object.assign({
  17340. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  17341. }, options.parser === "angular" ? {
  17342. parser: "__ng_interpolation",
  17343. trailingComma: "none"
  17344. } : options.parser === "vue" ? {
  17345. parser: "__vue_expression"
  17346. } : {
  17347. parser: "__js_expression"
  17348. }))])), node.parent.next && needsToBorrowPrevClosingTagEndMarker(node.parent.next) ? " " : line$5]);
  17349. }
  17350. break;
  17351. }
  17352. case "attribute":
  17353. {
  17354. if (!node.value) {
  17355. break;
  17356. } // lit-html: html`<my-element obj=${obj}></my-element>`
  17357. if (/^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  17358. return concat$a([node.rawName, "=", node.value]);
  17359. } // lwc: html`<my-element data-for={value}></my-element>`
  17360. if (options.parser === "lwc") {
  17361. var interpolationRegex = /^\{[\s\S]*\}$/;
  17362. if (interpolationRegex.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  17363. return concat$a([node.rawName, "=", node.value]);
  17364. }
  17365. }
  17366. var embeddedAttributeValueDoc = printEmbeddedAttributeValue(node, function (code, opts) {
  17367. return (// strictly prefer single quote to avoid unnecessary html entity escape
  17368. textToDoc(code, Object.assign({
  17369. __isInHtmlAttribute: true
  17370. }, opts))
  17371. );
  17372. }, options);
  17373. if (embeddedAttributeValueDoc) {
  17374. return concat$a([node.rawName, '="', group$9(mapDoc$4(embeddedAttributeValueDoc, function (doc) {
  17375. return typeof doc === "string" ? doc.replace(/"/g, "&quot;") : doc;
  17376. })), '"']);
  17377. }
  17378. break;
  17379. }
  17380. case "yaml":
  17381. return markAsRoot$2(concat$a(["---", hardline$7, node.value.trim().length === 0 ? "" : textToDoc(node.value, {
  17382. parser: "yaml"
  17383. }), "---"]));
  17384. }
  17385. }
  17386. function genericPrint$2(path, options, print) {
  17387. var node = path.getValue();
  17388. switch (node.type) {
  17389. case "root":
  17390. // use original concat to not break stripTrailingHardline
  17391. return builders.concat([group$9(printChildren$1(path, options, print)), hardline$7]);
  17392. case "element":
  17393. case "ieConditionalComment":
  17394. {
  17395. /**
  17396. * do not break:
  17397. *
  17398. * <div>{{
  17399. * ~
  17400. * interpolation
  17401. * }}</div>
  17402. * ~
  17403. *
  17404. * exception: break if the opening tag breaks
  17405. *
  17406. * <div
  17407. * long
  17408. * ~
  17409. * >{{
  17410. * interpolation
  17411. * }}</div
  17412. * ~
  17413. * >
  17414. */
  17415. var shouldHugContent = node.children.length === 1 && node.firstChild.type === "interpolation" && node.firstChild.isLeadingSpaceSensitive && !node.firstChild.hasLeadingSpaces && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces;
  17416. var attrGroupId = Symbol("element-attr-group-id");
  17417. return concat$a([group$9(concat$a([group$9(printOpeningTag(path, options, print), {
  17418. id: attrGroupId
  17419. }), node.children.length === 0 ? node.hasDanglingSpaces && node.isDanglingSpaceSensitive ? line$5 : "" : concat$a([forceBreakContent$1(node) ? breakParent$2 : "", function (childrenDoc) {
  17420. return shouldHugContent ? ifBreak$5(indent$5(childrenDoc), childrenDoc, {
  17421. groupId: attrGroupId
  17422. }) : isScriptLikeTag$1(node) && node.parent.type === "root" && options.parser === "vue" && !options.vueIndentScriptAndStyle ? childrenDoc : indent$5(childrenDoc);
  17423. }(concat$a([shouldHugContent ? ifBreak$5(softline$4, "", {
  17424. groupId: attrGroupId
  17425. }) : node.firstChild.hasLeadingSpaces && node.firstChild.isLeadingSpaceSensitive ? line$5 : node.firstChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive ? dedentToRoot$1(softline$4) : softline$4, printChildren$1(path, options, print)])), (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? " " : "" : shouldHugContent ? ifBreak$5(softline$4, "", {
  17426. groupId: attrGroupId
  17427. }) : node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? line$5 : (node.lastChild.type === "comment" || node.lastChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive) && new RegExp("\\n\\s{".concat(options.tabWidth * countParents$1(path, function (n) {
  17428. return n.parent && n.parent.type !== "root";
  17429. }), "}$")).test(node.lastChild.value) ?
  17430. /**
  17431. * <div>
  17432. * <pre>
  17433. * something
  17434. * </pre>
  17435. * ~
  17436. * </div>
  17437. */
  17438. "" : softline$4])])), printClosingTag(node, options)]);
  17439. }
  17440. case "ieConditionalStartComment":
  17441. case "ieConditionalEndComment":
  17442. return concat$a([printOpeningTagStart(node), printClosingTagEnd(node)]);
  17443. case "interpolation":
  17444. return concat$a([printOpeningTagStart(node, options), concat$a(path.map(print, "children")), printClosingTagEnd(node, options)]);
  17445. case "text":
  17446. {
  17447. if (node.parent.type === "interpolation") {
  17448. // replace the trailing literalline with hardline for better readability
  17449. var trailingNewlineRegex = /\n[^\S\n]*?$/;
  17450. var hasTrailingNewline = trailingNewlineRegex.test(node.value);
  17451. var value = hasTrailingNewline ? node.value.replace(trailingNewlineRegex, "") : node.value;
  17452. return concat$a([concat$a(replaceEndOfLineWith$1(value, literalline$2)), hasTrailingNewline ? hardline$7 : ""]);
  17453. }
  17454. return fill$3(normalizeParts$1([].concat(printOpeningTagPrefix(node, options), getTextValueParts(node), printClosingTagSuffix(node, options))));
  17455. }
  17456. case "docType":
  17457. return concat$a([group$9(concat$a([printOpeningTagStart(node, options), " ", node.value.replace(/^html\b/i, "html").replace(/\s+/g, " ")])), printClosingTagEnd(node, options)]);
  17458. case "comment":
  17459. {
  17460. return concat$a([printOpeningTagPrefix(node, options), concat$a(replaceEndOfLineWith$1(options.originalText.slice(options.locStart(node), options.locEnd(node)), literalline$2)), printClosingTagSuffix(node, options)]);
  17461. }
  17462. case "attribute":
  17463. {
  17464. if (node.value === null) {
  17465. return node.rawName;
  17466. }
  17467. var _value = unescapeQuoteEntities$1(node.value);
  17468. var singleQuoteCount = countChars$1(_value, "'");
  17469. var doubleQuoteCount = countChars$1(_value, '"');
  17470. var quote = singleQuoteCount < doubleQuoteCount ? "'" : '"';
  17471. return concat$a([node.rawName, concat$a(["=", quote, concat$a(replaceEndOfLineWith$1(quote === '"' ? _value.replace(/"/g, "&quot;") : _value.replace(/'/g, "&apos;"), literalline$2)), quote])]);
  17472. }
  17473. case "yaml":
  17474. case "toml":
  17475. return concat$a(replaceEndOfLineWith$1(node.raw, literalline$2));
  17476. default:
  17477. throw new Error("Unexpected node type ".concat(node.type));
  17478. }
  17479. }
  17480. function printChildren$1(path, options, print) {
  17481. var node = path.getValue();
  17482. if (forceBreakChildren$1(node)) {
  17483. return concat$a([breakParent$2, concat$a(path.map(function (childPath) {
  17484. var childNode = childPath.getValue();
  17485. var prevBetweenLine = !childNode.prev ? "" : printBetweenLine(childNode.prev, childNode);
  17486. return concat$a([!prevBetweenLine ? "" : concat$a([prevBetweenLine, forceNextEmptyLine$1(childNode.prev) ? hardline$7 : ""]), printChild(childPath)]);
  17487. }, "children"))]);
  17488. }
  17489. var groupIds = node.children.map(function () {
  17490. return Symbol("");
  17491. });
  17492. return concat$a(path.map(function (childPath, childIndex) {
  17493. var childNode = childPath.getValue();
  17494. if (isTextLikeNode$1(childNode)) {
  17495. if (childNode.prev && isTextLikeNode$1(childNode.prev)) {
  17496. var _prevBetweenLine = printBetweenLine(childNode.prev, childNode);
  17497. if (_prevBetweenLine) {
  17498. if (forceNextEmptyLine$1(childNode.prev)) {
  17499. return concat$a([hardline$7, hardline$7, printChild(childPath)]);
  17500. }
  17501. return concat$a([_prevBetweenLine, printChild(childPath)]);
  17502. }
  17503. }
  17504. return printChild(childPath);
  17505. }
  17506. var prevParts = [];
  17507. var leadingParts = [];
  17508. var trailingParts = [];
  17509. var nextParts = [];
  17510. var prevBetweenLine = childNode.prev ? printBetweenLine(childNode.prev, childNode) : "";
  17511. var nextBetweenLine = childNode.next ? printBetweenLine(childNode, childNode.next) : "";
  17512. if (prevBetweenLine) {
  17513. if (forceNextEmptyLine$1(childNode.prev)) {
  17514. prevParts.push(hardline$7, hardline$7);
  17515. } else if (prevBetweenLine === hardline$7) {
  17516. prevParts.push(hardline$7);
  17517. } else {
  17518. if (isTextLikeNode$1(childNode.prev)) {
  17519. leadingParts.push(prevBetweenLine);
  17520. } else {
  17521. leadingParts.push(ifBreak$5("", softline$4, {
  17522. groupId: groupIds[childIndex - 1]
  17523. }));
  17524. }
  17525. }
  17526. }
  17527. if (nextBetweenLine) {
  17528. if (forceNextEmptyLine$1(childNode)) {
  17529. if (isTextLikeNode$1(childNode.next)) {
  17530. nextParts.push(hardline$7, hardline$7);
  17531. }
  17532. } else if (nextBetweenLine === hardline$7) {
  17533. if (isTextLikeNode$1(childNode.next)) {
  17534. nextParts.push(hardline$7);
  17535. }
  17536. } else {
  17537. trailingParts.push(nextBetweenLine);
  17538. }
  17539. }
  17540. return concat$a([].concat(prevParts, group$9(concat$a([concat$a(leadingParts), group$9(concat$a([printChild(childPath), concat$a(trailingParts)]), {
  17541. id: groupIds[childIndex]
  17542. })])), nextParts));
  17543. }, "children"));
  17544. function printChild(childPath) {
  17545. var child = childPath.getValue();
  17546. if (hasPrettierIgnore$1(child)) {
  17547. return concat$a([].concat(printOpeningTagPrefix(child, options), replaceEndOfLineWith$1(options.originalText.slice(options.locStart(child) + (child.prev && needsToBorrowNextOpeningTagStartMarker(child.prev) ? printOpeningTagStartMarker(child).length : 0), options.locEnd(child) - (child.next && needsToBorrowPrevClosingTagEndMarker(child.next) ? printClosingTagEndMarker(child, options).length : 0)), literalline$2), printClosingTagSuffix(child, options)));
  17548. }
  17549. if (shouldPreserveContent$1(child, options)) {
  17550. return concat$a([].concat(printOpeningTagPrefix(child, options), group$9(printOpeningTag(childPath, options, print)), replaceEndOfLineWith$1(options.originalText.slice(child.startSourceSpan.end.offset + (child.firstChild && needsToBorrowParentOpeningTagEndMarker(child.firstChild) ? -printOpeningTagEndMarker(child).length : 0), child.endSourceSpan.start.offset + (child.lastChild && needsToBorrowParentClosingTagStartMarker(child.lastChild) ? printClosingTagStartMarker(child, options).length : needsToBorrowLastChildClosingTagEndMarker(child) ? -printClosingTagEndMarker(child.lastChild, options).length : 0)), literalline$2), printClosingTag(child, options), printClosingTagSuffix(child, options)));
  17551. }
  17552. return print(childPath);
  17553. }
  17554. function printBetweenLine(prevNode, nextNode) {
  17555. return isTextLikeNode$1(prevNode) && isTextLikeNode$1(nextNode) ? prevNode.isTrailingSpaceSensitive ? prevNode.hasTrailingSpaces ? preferHardlineAsLeadingSpaces$1(nextNode) ? hardline$7 : line$5 : "" : preferHardlineAsLeadingSpaces$1(nextNode) ? hardline$7 : softline$4 : needsToBorrowNextOpeningTagStartMarker(prevNode) && (
  17556. /**
  17557. * 123<a
  17558. * ~
  17559. * ><b>
  17560. */
  17561. nextNode.firstChild ||
  17562. /**
  17563. * 123<!--
  17564. * ~
  17565. * -->
  17566. */
  17567. nextNode.isSelfClosing ||
  17568. /**
  17569. * 123<span
  17570. * ~
  17571. * attr
  17572. */
  17573. nextNode.type === "element" && nextNode.attrs.length !== 0) ||
  17574. /**
  17575. * <img
  17576. * src="long"
  17577. * ~
  17578. * />123
  17579. */
  17580. prevNode.type === "element" && prevNode.isSelfClosing && needsToBorrowPrevClosingTagEndMarker(nextNode) ? "" : !nextNode.isLeadingSpaceSensitive || preferHardlineAsLeadingSpaces$1(nextNode) ||
  17581. /**
  17582. * Want to write us a letter? Use our<a
  17583. * ><b><a>mailing address</a></b></a
  17584. * ~
  17585. * >.
  17586. */
  17587. needsToBorrowPrevClosingTagEndMarker(nextNode) && prevNode.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild) && prevNode.lastChild.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild.lastChild) ? hardline$7 : nextNode.hasLeadingSpaces ? line$5 : softline$4;
  17588. }
  17589. }
  17590. function printOpeningTag(path, options, print) {
  17591. var node = path.getValue();
  17592. var forceNotToBreakAttrContent = node.type === "element" && node.fullName === "script" && node.attrs.length === 1 && node.attrs[0].fullName === "src" && node.children.length === 0;
  17593. return concat$a([printOpeningTagStart(node, options), !node.attrs || node.attrs.length === 0 ? node.isSelfClosing ?
  17594. /**
  17595. * <br />
  17596. * ^
  17597. */
  17598. " " : "" : concat$a([indent$5(concat$a([forceNotToBreakAttrContent ? " " : line$5, join$6(line$5, function (ignoreAttributeData) {
  17599. var hasPrettierIgnoreAttribute = typeof ignoreAttributeData === "boolean" ? function () {
  17600. return ignoreAttributeData;
  17601. } : Array.isArray(ignoreAttributeData) ? function (attr) {
  17602. return ignoreAttributeData.indexOf(attr.rawName) !== -1;
  17603. } : function () {
  17604. return false;
  17605. };
  17606. return path.map(function (attrPath) {
  17607. var attr = attrPath.getValue();
  17608. return hasPrettierIgnoreAttribute(attr) ? concat$a(replaceEndOfLineWith$1(options.originalText.slice(options.locStart(attr), options.locEnd(attr)), literalline$2)) : print(attrPath);
  17609. }, "attrs");
  17610. }(node.prev && node.prev.type === "comment" && getPrettierIgnoreAttributeCommentData$1(node.prev.value)))])),
  17611. /**
  17612. * 123<a
  17613. * attr
  17614. * ~
  17615. * >456
  17616. */
  17617. node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ||
  17618. /**
  17619. * <span
  17620. * >123<meta
  17621. * ~
  17622. * /></span>
  17623. */
  17624. node.isSelfClosing && needsToBorrowLastChildClosingTagEndMarker(node.parent) ? "" : node.isSelfClosing ? forceNotToBreakAttrContent ? " " : line$5 : forceNotToBreakAttrContent ? "" : softline$4]), node.isSelfClosing ? "" : printOpeningTagEnd(node)]);
  17625. }
  17626. function printOpeningTagStart(node, options) {
  17627. return node.prev && needsToBorrowNextOpeningTagStartMarker(node.prev) ? "" : concat$a([printOpeningTagPrefix(node, options), printOpeningTagStartMarker(node)]);
  17628. }
  17629. function printOpeningTagEnd(node) {
  17630. return node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ? "" : printOpeningTagEndMarker(node);
  17631. }
  17632. function printClosingTag(node, options) {
  17633. return concat$a([node.isSelfClosing ? "" : printClosingTagStart(node, options), printClosingTagEnd(node, options)]);
  17634. }
  17635. function printClosingTagStart(node, options) {
  17636. return node.lastChild && needsToBorrowParentClosingTagStartMarker(node.lastChild) ? "" : concat$a([printClosingTagPrefix(node, options), printClosingTagStartMarker(node, options)]);
  17637. }
  17638. function printClosingTagEnd(node, options) {
  17639. return (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? "" : concat$a([printClosingTagEndMarker(node, options), printClosingTagSuffix(node, options)]);
  17640. }
  17641. function needsToBorrowNextOpeningTagStartMarker(node) {
  17642. /**
  17643. * 123<p
  17644. * ^^
  17645. * >
  17646. */
  17647. return node.next && !isTextLikeNode$1(node.next) && isTextLikeNode$1(node) && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces;
  17648. }
  17649. function needsToBorrowParentOpeningTagEndMarker(node) {
  17650. /**
  17651. * <p
  17652. * >123
  17653. * ^
  17654. *
  17655. * <p
  17656. * ><a
  17657. * ^
  17658. */
  17659. return !node.prev && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  17660. }
  17661. function needsToBorrowPrevClosingTagEndMarker(node) {
  17662. /**
  17663. * <p></p
  17664. * >123
  17665. * ^
  17666. *
  17667. * <p></p
  17668. * ><a
  17669. * ^
  17670. */
  17671. return node.prev && !isTextLikeNode$1(node.prev) && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  17672. }
  17673. function needsToBorrowLastChildClosingTagEndMarker(node) {
  17674. /**
  17675. * <p
  17676. * ><a></a
  17677. * ></p
  17678. * ^
  17679. * >
  17680. */
  17681. return node.lastChild && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces && !isTextLikeNode$1(getLastDescendant$1(node.lastChild));
  17682. }
  17683. function needsToBorrowParentClosingTagStartMarker(node) {
  17684. /**
  17685. * <p>
  17686. * 123</p
  17687. * ^^^
  17688. * >
  17689. *
  17690. * 123</b
  17691. * ></a
  17692. * ^^^
  17693. * >
  17694. */
  17695. return !node.next && !node.hasTrailingSpaces && node.isTrailingSpaceSensitive && isTextLikeNode$1(getLastDescendant$1(node));
  17696. }
  17697. function printOpeningTagPrefix(node, options) {
  17698. return needsToBorrowParentOpeningTagEndMarker(node) ? printOpeningTagEndMarker(node.parent) : needsToBorrowPrevClosingTagEndMarker(node) ? printClosingTagEndMarker(node.prev, options) : "";
  17699. }
  17700. function printClosingTagPrefix(node, options) {
  17701. return needsToBorrowLastChildClosingTagEndMarker(node) ? printClosingTagEndMarker(node.lastChild, options) : "";
  17702. }
  17703. function printClosingTagSuffix(node, options) {
  17704. return needsToBorrowParentClosingTagStartMarker(node) ? printClosingTagStartMarker(node.parent, options) : needsToBorrowNextOpeningTagStartMarker(node) ? printOpeningTagStartMarker(node.next) : "";
  17705. }
  17706. function printOpeningTagStartMarker(node) {
  17707. switch (node.type) {
  17708. case "ieConditionalComment":
  17709. case "ieConditionalStartComment":
  17710. return "<!--[if ".concat(node.condition);
  17711. case "ieConditionalEndComment":
  17712. return "<!--<!";
  17713. case "interpolation":
  17714. return "{{";
  17715. case "docType":
  17716. return "<!DOCTYPE";
  17717. case "element":
  17718. if (node.condition) {
  17719. return "<!--[if ".concat(node.condition, "]><!--><").concat(node.rawName);
  17720. }
  17721. // fall through
  17722. default:
  17723. return "<".concat(node.rawName);
  17724. }
  17725. }
  17726. function printOpeningTagEndMarker(node) {
  17727. assert(!node.isSelfClosing);
  17728. switch (node.type) {
  17729. case "ieConditionalComment":
  17730. return "]>";
  17731. case "element":
  17732. if (node.condition) {
  17733. return "><!--<![endif]-->";
  17734. }
  17735. // fall through
  17736. default:
  17737. return ">";
  17738. }
  17739. }
  17740. function printClosingTagStartMarker(node, options) {
  17741. assert(!node.isSelfClosing);
  17742. if (shouldNotPrintClosingTag$1(node, options)) {
  17743. return "";
  17744. }
  17745. switch (node.type) {
  17746. case "ieConditionalComment":
  17747. return "<!";
  17748. case "element":
  17749. if (node.hasHtmComponentClosingTag) {
  17750. return "<//";
  17751. }
  17752. // fall through
  17753. default:
  17754. return "</".concat(node.rawName);
  17755. }
  17756. }
  17757. function printClosingTagEndMarker(node, options) {
  17758. if (shouldNotPrintClosingTag$1(node, options)) {
  17759. return "";
  17760. }
  17761. switch (node.type) {
  17762. case "ieConditionalComment":
  17763. case "ieConditionalEndComment":
  17764. return "[endif]-->";
  17765. case "ieConditionalStartComment":
  17766. return "]><!-->";
  17767. case "interpolation":
  17768. return "}}";
  17769. case "element":
  17770. if (node.isSelfClosing) {
  17771. return "/>";
  17772. }
  17773. // fall through
  17774. default:
  17775. return ">";
  17776. }
  17777. }
  17778. function getTextValueParts(node) {
  17779. var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : node.value;
  17780. return node.parent.isWhitespaceSensitive ? node.parent.isIndentationSensitive ? replaceEndOfLineWith$1(value, literalline$2) : replaceEndOfLineWith$1(dedentString$1(value.replace(/^\s*?\n|\n\s*?$/g, "")), hardline$7) : // https://infra.spec.whatwg.org/#ascii-whitespace
  17781. join$6(line$5, value.split(/[\t\n\f\r ]+/)).parts;
  17782. }
  17783. function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
  17784. var isKeyMatched = function isKeyMatched(patterns) {
  17785. return new RegExp(patterns.join("|")).test(node.fullName);
  17786. };
  17787. var getValue = function getValue() {
  17788. return unescapeQuoteEntities$1(node.value);
  17789. };
  17790. var shouldHug = false;
  17791. var __onHtmlBindingRoot = function __onHtmlBindingRoot(root) {
  17792. var rootNode = root.type === "NGRoot" ? root.node.type === "NGMicrosyntax" && root.node.body.length === 1 && root.node.body[0].type === "NGMicrosyntaxExpression" ? root.node.body[0].expression : root.node : root.type === "JsExpressionRoot" ? root.node : root;
  17793. if (rootNode && (rootNode.type === "ObjectExpression" || rootNode.type === "ArrayExpression")) {
  17794. shouldHug = true;
  17795. }
  17796. };
  17797. var printHug = function printHug(doc) {
  17798. return group$9(doc);
  17799. };
  17800. var printExpand = function printExpand(doc) {
  17801. return group$9(concat$a([indent$5(concat$a([softline$4, doc])), softline$4]));
  17802. };
  17803. var printMaybeHug = function printMaybeHug(doc) {
  17804. return shouldHug ? printHug(doc) : printExpand(doc);
  17805. };
  17806. var textToDoc = function textToDoc(code, opts) {
  17807. return originalTextToDoc(code, Object.assign({
  17808. __onHtmlBindingRoot: __onHtmlBindingRoot
  17809. }, opts));
  17810. };
  17811. if (node.fullName === "srcset" && (node.parent.fullName === "img" || node.parent.fullName === "source")) {
  17812. return printExpand(printImgSrcset$1(getValue()));
  17813. }
  17814. if (options.parser === "vue") {
  17815. if (node.fullName === "v-for") {
  17816. return printVueFor$1(getValue(), textToDoc);
  17817. }
  17818. if (node.fullName === "slot-scope") {
  17819. return printVueSlotScope$1(getValue(), textToDoc);
  17820. }
  17821. /**
  17822. * @click="jsStatement"
  17823. * @click="jsExpression"
  17824. * v-on:click="jsStatement"
  17825. * v-on:click="jsExpression"
  17826. */
  17827. var vueEventBindingPatterns = ["^@", "^v-on:"];
  17828. /**
  17829. * :class="vueExpression"
  17830. * v-bind:id="vueExpression"
  17831. */
  17832. var vueExpressionBindingPatterns = ["^:", "^v-bind:"];
  17833. /**
  17834. * v-if="jsExpression"
  17835. */
  17836. var jsExpressionBindingPatterns = ["^v-"];
  17837. if (isKeyMatched(vueEventBindingPatterns)) {
  17838. var value = getValue();
  17839. return printMaybeHug(isVueEventBindingExpression$1(value) ? textToDoc(value, {
  17840. parser: "__js_expression"
  17841. }) : stripTrailingHardline$1(textToDoc(value, {
  17842. parser: "__vue_event_binding"
  17843. })));
  17844. }
  17845. if (isKeyMatched(vueExpressionBindingPatterns)) {
  17846. return printMaybeHug(textToDoc(getValue(), {
  17847. parser: "__vue_expression"
  17848. }));
  17849. }
  17850. if (isKeyMatched(jsExpressionBindingPatterns)) {
  17851. return printMaybeHug(textToDoc(getValue(), {
  17852. parser: "__js_expression"
  17853. }));
  17854. }
  17855. }
  17856. if (options.parser === "angular") {
  17857. var ngTextToDoc = function ngTextToDoc(code, opts) {
  17858. return (// angular does not allow trailing comma
  17859. textToDoc(code, Object.assign({
  17860. trailingComma: "none"
  17861. }, opts))
  17862. );
  17863. };
  17864. /**
  17865. * *directive="angularDirective"
  17866. */
  17867. var ngDirectiveBindingPatterns = ["^\\*"];
  17868. /**
  17869. * (click)="angularStatement"
  17870. * on-click="angularStatement"
  17871. */
  17872. var ngStatementBindingPatterns = ["^\\(.+\\)$", "^on-"];
  17873. /**
  17874. * [target]="angularExpression"
  17875. * bind-target="angularExpression"
  17876. * [(target)]="angularExpression"
  17877. * bindon-target="angularExpression"
  17878. */
  17879. var ngExpressionBindingPatterns = ["^\\[.+\\]$", "^bind(on)?-"];
  17880. /**
  17881. * i18n="longDescription"
  17882. * i18n-attr="longDescription"
  17883. */
  17884. var ngI18nPatterns = ["^i18n(-.+)?$"];
  17885. if (isKeyMatched(ngStatementBindingPatterns)) {
  17886. return printMaybeHug(ngTextToDoc(getValue(), {
  17887. parser: "__ng_action"
  17888. }));
  17889. }
  17890. if (isKeyMatched(ngExpressionBindingPatterns)) {
  17891. return printMaybeHug(ngTextToDoc(getValue(), {
  17892. parser: "__ng_binding"
  17893. }));
  17894. }
  17895. if (isKeyMatched(ngI18nPatterns)) {
  17896. return printExpand(fill$3(getTextValueParts(node, getValue())));
  17897. }
  17898. if (isKeyMatched(ngDirectiveBindingPatterns)) {
  17899. return printMaybeHug(ngTextToDoc(getValue(), {
  17900. parser: "__ng_directive"
  17901. }));
  17902. }
  17903. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  17904. var _value2 = getValue();
  17905. if (interpolationRegex.test(_value2)) {
  17906. var parts = [];
  17907. _value2.split(interpolationRegex).forEach(function (part, index) {
  17908. if (index % 2 === 0) {
  17909. parts.push(concat$a(replaceEndOfLineWith$1(part, literalline$2)));
  17910. } else {
  17911. try {
  17912. parts.push(group$9(concat$a(["{{", indent$5(concat$a([line$5, ngTextToDoc(part, {
  17913. parser: "__ng_interpolation",
  17914. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  17915. })])), line$5, "}}"])));
  17916. } catch (e) {
  17917. parts.push("{{", concat$a(replaceEndOfLineWith$1(part, literalline$2)), "}}");
  17918. }
  17919. }
  17920. });
  17921. return group$9(concat$a(parts));
  17922. }
  17923. }
  17924. return null;
  17925. }
  17926. var printerHtml = {
  17927. preprocess: preprocess_1,
  17928. print: genericPrint$2,
  17929. insertPragma: insertPragma$6,
  17930. massageAstNode: clean$3,
  17931. embed: embed$2
  17932. };
  17933. var CATEGORY_HTML = "HTML"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  17934. var options$4 = {
  17935. htmlWhitespaceSensitivity: {
  17936. since: "1.15.0",
  17937. category: CATEGORY_HTML,
  17938. type: "choice",
  17939. default: "css",
  17940. description: "How to handle whitespaces in HTML.",
  17941. choices: [{
  17942. value: "css",
  17943. description: "Respect the default value of CSS display property."
  17944. }, {
  17945. value: "strict",
  17946. description: "Whitespaces are considered sensitive."
  17947. }, {
  17948. value: "ignore",
  17949. description: "Whitespaces are considered insensitive."
  17950. }]
  17951. },
  17952. vueIndentScriptAndStyle: {
  17953. since: "1.19.0",
  17954. category: CATEGORY_HTML,
  17955. type: "boolean",
  17956. default: false,
  17957. description: "Indent script and style tags in Vue files."
  17958. }
  17959. };
  17960. var name$7 = "HTML";
  17961. var type$6 = "markup";
  17962. var tmScope$6 = "text.html.basic";
  17963. var aceMode$6 = "html";
  17964. var codemirrorMode$3 = "htmlmixed";
  17965. var codemirrorMimeType$3 = "text/html";
  17966. var color$1 = "#e34c26";
  17967. var aliases$1 = [
  17968. "xhtml"
  17969. ];
  17970. var extensions$6 = [
  17971. ".html",
  17972. ".htm",
  17973. ".html.hl",
  17974. ".inc",
  17975. ".st",
  17976. ".xht",
  17977. ".xhtml"
  17978. ];
  17979. var languageId$6 = 146;
  17980. var HTML = {
  17981. name: name$7,
  17982. type: type$6,
  17983. tmScope: tmScope$6,
  17984. aceMode: aceMode$6,
  17985. codemirrorMode: codemirrorMode$3,
  17986. codemirrorMimeType: codemirrorMimeType$3,
  17987. color: color$1,
  17988. aliases: aliases$1,
  17989. extensions: extensions$6,
  17990. languageId: languageId$6
  17991. };
  17992. var HTML$1 = /*#__PURE__*/Object.freeze({
  17993. __proto__: null,
  17994. name: name$7,
  17995. type: type$6,
  17996. tmScope: tmScope$6,
  17997. aceMode: aceMode$6,
  17998. codemirrorMode: codemirrorMode$3,
  17999. codemirrorMimeType: codemirrorMimeType$3,
  18000. color: color$1,
  18001. aliases: aliases$1,
  18002. extensions: extensions$6,
  18003. languageId: languageId$6,
  18004. 'default': HTML
  18005. });
  18006. var name$8 = "Vue";
  18007. var type$7 = "markup";
  18008. var color$2 = "#2c3e50";
  18009. var extensions$7 = [
  18010. ".vue"
  18011. ];
  18012. var tmScope$7 = "text.html.vue";
  18013. var aceMode$7 = "html";
  18014. var languageId$7 = 391;
  18015. var Vue = {
  18016. name: name$8,
  18017. type: type$7,
  18018. color: color$2,
  18019. extensions: extensions$7,
  18020. tmScope: tmScope$7,
  18021. aceMode: aceMode$7,
  18022. languageId: languageId$7
  18023. };
  18024. var Vue$1 = /*#__PURE__*/Object.freeze({
  18025. __proto__: null,
  18026. name: name$8,
  18027. type: type$7,
  18028. color: color$2,
  18029. extensions: extensions$7,
  18030. tmScope: tmScope$7,
  18031. aceMode: aceMode$7,
  18032. languageId: languageId$7,
  18033. 'default': Vue
  18034. });
  18035. var require$$0$5 = getCjsExportFromNamespace(HTML$1);
  18036. var require$$1$1 = getCjsExportFromNamespace(Vue$1);
  18037. var languages$3 = [createLanguage(require$$0$5, function (data) {
  18038. return Object.assign(data, {
  18039. name: "Angular",
  18040. since: "1.15.0",
  18041. parsers: ["angular"],
  18042. vscodeLanguageIds: ["html"],
  18043. extensions: [".component.html"],
  18044. filenames: []
  18045. });
  18046. }), createLanguage(require$$0$5, function (data) {
  18047. return Object.assign(data, {
  18048. since: "1.15.0",
  18049. parsers: ["html"],
  18050. vscodeLanguageIds: ["html"],
  18051. extensions: data.extensions.concat([".mjml" // MJML is considered XML in Linguist but it should be formatted as HTML
  18052. ])
  18053. });
  18054. }), createLanguage(require$$0$5, function (data) {
  18055. return Object.assign(data, {
  18056. name: "Lightning Web Components",
  18057. since: "1.17.0",
  18058. parsers: ["lwc"],
  18059. vscodeLanguageIds: ["html"],
  18060. extensions: [],
  18061. filenames: []
  18062. });
  18063. }), createLanguage(require$$1$1, function (data) {
  18064. return Object.assign(data, {
  18065. since: "1.10.0",
  18066. parsers: ["vue"],
  18067. vscodeLanguageIds: ["vue"]
  18068. });
  18069. })];
  18070. var printers$3 = {
  18071. html: printerHtml
  18072. };
  18073. var languageHtml = {
  18074. languages: languages$3,
  18075. printers: printers$3,
  18076. options: options$4
  18077. };
  18078. var addLeadingComment$2 = utilShared.addLeadingComment,
  18079. addTrailingComment$2 = utilShared.addTrailingComment,
  18080. addDanglingComment$2 = utilShared.addDanglingComment;
  18081. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  18082. var precedingNode = comment.precedingNode,
  18083. enclosingNode = comment.enclosingNode,
  18084. followingNode = comment.followingNode;
  18085. if (handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleMemberExpressionComments(enclosingNode, followingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleImportSpecifierComments(enclosingNode, comment) || handleForComments(enclosingNode, precedingNode, comment) || handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) || handleAssignmentPatternComments(enclosingNode, comment) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options)) {
  18086. return true;
  18087. }
  18088. return false;
  18089. }
  18090. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  18091. var precedingNode = comment.precedingNode,
  18092. enclosingNode = comment.enclosingNode,
  18093. followingNode = comment.followingNode;
  18094. if (handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) || handleImportSpecifierComments(enclosingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleLabeledStatementComments(enclosingNode, comment) || handleCallExpressionComments(precedingNode, enclosingNode, comment) || handlePropertyComments(enclosingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleTypeAliasComments(enclosingNode, followingNode, comment) || handleVariableDeclaratorComments(enclosingNode, followingNode, comment)) {
  18095. return true;
  18096. }
  18097. return false;
  18098. }
  18099. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  18100. var precedingNode = comment.precedingNode,
  18101. enclosingNode = comment.enclosingNode,
  18102. followingNode = comment.followingNode;
  18103. if (handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) || handleCommentInEmptyParens(text, enclosingNode, comment, options) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleCommentAfterArrowParams(text, enclosingNode, comment, options) || handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) || handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) || handleBreakAndContinueStatementComments(enclosingNode, comment)) {
  18104. return true;
  18105. }
  18106. return false;
  18107. }
  18108. function addBlockStatementFirstComment(node, comment) {
  18109. var body = node.body.filter(function (n) {
  18110. return n.type !== "EmptyStatement";
  18111. });
  18112. if (body.length === 0) {
  18113. addDanglingComment$2(node, comment);
  18114. } else {
  18115. addLeadingComment$2(body[0], comment);
  18116. }
  18117. }
  18118. function addBlockOrNotComment(node, comment) {
  18119. if (node.type === "BlockStatement") {
  18120. addBlockStatementFirstComment(node, comment);
  18121. } else {
  18122. addLeadingComment$2(node, comment);
  18123. }
  18124. } // There are often comments before the else clause of if statements like
  18125. //
  18126. // if (1) { ... }
  18127. // // comment
  18128. // else { ... }
  18129. //
  18130. // They are being attached as leading comments of the BlockExpression which
  18131. // is not well printed. What we want is to instead move the comment inside
  18132. // of the block and make it leadingComment of the first element of the block
  18133. // or dangling comment of the block if there is nothing inside
  18134. //
  18135. // if (1) { ... }
  18136. // else {
  18137. // // comment
  18138. // ...
  18139. // }
  18140. function handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  18141. if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) {
  18142. return false;
  18143. } // We unfortunately have no way using the AST or location of nodes to know
  18144. // if the comment is positioned before the condition parenthesis:
  18145. // if (a /* comment */) {}
  18146. // The only workaround I found is to look at the next character to see if
  18147. // it is a ).
  18148. var nextCharacter = util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  18149. if (nextCharacter === ")") {
  18150. addTrailingComment$2(precedingNode, comment);
  18151. return true;
  18152. } // Comments before `else`:
  18153. // - treat as trailing comments of the consequent, if it's a BlockStatement
  18154. // - treat as a dangling comment otherwise
  18155. if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
  18156. if (precedingNode.type === "BlockStatement") {
  18157. addTrailingComment$2(precedingNode, comment);
  18158. } else {
  18159. addDanglingComment$2(enclosingNode, comment);
  18160. }
  18161. return true;
  18162. }
  18163. if (followingNode.type === "BlockStatement") {
  18164. addBlockStatementFirstComment(followingNode, comment);
  18165. return true;
  18166. }
  18167. if (followingNode.type === "IfStatement") {
  18168. addBlockOrNotComment(followingNode.consequent, comment);
  18169. return true;
  18170. } // For comments positioned after the condition parenthesis in an if statement
  18171. // before the consequent without brackets on, such as
  18172. // if (a) /* comment */ true,
  18173. // we look at the next character to see if the following node
  18174. // is the consequent for the if statement
  18175. if (enclosingNode.consequent === followingNode) {
  18176. addLeadingComment$2(followingNode, comment);
  18177. return true;
  18178. }
  18179. return false;
  18180. }
  18181. function handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  18182. if (!enclosingNode || enclosingNode.type !== "WhileStatement" || !followingNode) {
  18183. return false;
  18184. } // We unfortunately have no way using the AST or location of nodes to know
  18185. // if the comment is positioned before the condition parenthesis:
  18186. // while (a /* comment */) {}
  18187. // The only workaround I found is to look at the next character to see if
  18188. // it is a ).
  18189. var nextCharacter = util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  18190. if (nextCharacter === ")") {
  18191. addTrailingComment$2(precedingNode, comment);
  18192. return true;
  18193. }
  18194. if (followingNode.type === "BlockStatement") {
  18195. addBlockStatementFirstComment(followingNode, comment);
  18196. return true;
  18197. }
  18198. return false;
  18199. } // Same as IfStatement but for TryStatement
  18200. function handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) {
  18201. if (!enclosingNode || enclosingNode.type !== "TryStatement" && enclosingNode.type !== "CatchClause" || !followingNode) {
  18202. return false;
  18203. }
  18204. if (enclosingNode.type === "CatchClause" && precedingNode) {
  18205. addTrailingComment$2(precedingNode, comment);
  18206. return true;
  18207. }
  18208. if (followingNode.type === "BlockStatement") {
  18209. addBlockStatementFirstComment(followingNode, comment);
  18210. return true;
  18211. }
  18212. if (followingNode.type === "TryStatement") {
  18213. addBlockOrNotComment(followingNode.finalizer, comment);
  18214. return true;
  18215. }
  18216. if (followingNode.type === "CatchClause") {
  18217. addBlockOrNotComment(followingNode.body, comment);
  18218. return true;
  18219. }
  18220. return false;
  18221. }
  18222. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  18223. if (enclosingNode && (enclosingNode.type === "MemberExpression" || enclosingNode.type === "OptionalMemberExpression") && followingNode && followingNode.type === "Identifier") {
  18224. addLeadingComment$2(enclosingNode, comment);
  18225. return true;
  18226. }
  18227. return false;
  18228. }
  18229. function handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) {
  18230. var isSameLineAsPrecedingNode = precedingNode && !util.hasNewlineInRange(text, options.locEnd(precedingNode), options.locStart(comment));
  18231. if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && enclosingNode.type === "ConditionalExpression" && followingNode) {
  18232. addLeadingComment$2(followingNode, comment);
  18233. return true;
  18234. }
  18235. return false;
  18236. }
  18237. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  18238. if (enclosingNode && (enclosingNode.type === "ObjectProperty" || enclosingNode.type === "Property") && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === "AssignmentPattern") {
  18239. addTrailingComment$2(enclosingNode.value.left, comment);
  18240. return true;
  18241. }
  18242. return false;
  18243. }
  18244. function handleClassComments(enclosingNode, precedingNode, followingNode, comment) {
  18245. if (enclosingNode && (enclosingNode.type === "ClassDeclaration" || enclosingNode.type === "ClassExpression") && enclosingNode.decorators && enclosingNode.decorators.length > 0 && !(followingNode && followingNode.type === "Decorator")) {
  18246. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  18247. addLeadingComment$2(enclosingNode, comment);
  18248. } else {
  18249. addTrailingComment$2(enclosingNode.decorators[enclosingNode.decorators.length - 1], comment);
  18250. }
  18251. return true;
  18252. }
  18253. return false;
  18254. }
  18255. function handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) {
  18256. // This is only needed for estree parsers (flow, typescript) to attach
  18257. // after a method name:
  18258. // obj = { fn /*comment*/() {} };
  18259. if (enclosingNode && precedingNode && (enclosingNode.type === "Property" || enclosingNode.type === "MethodDefinition") && precedingNode.type === "Identifier" && enclosingNode.key === precedingNode && // special Property case: { key: /*comment*/(value) };
  18260. // comment should be attached to value instead of key
  18261. util.getNextNonSpaceNonCommentCharacter(text, precedingNode, options.locEnd) !== ":") {
  18262. addTrailingComment$2(precedingNode, comment);
  18263. return true;
  18264. } // Print comments between decorators and class methods as a trailing comment
  18265. // on the decorator node instead of the method node
  18266. if (precedingNode && enclosingNode && precedingNode.type === "Decorator" && (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "TSAbstractClassProperty" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "MethodDefinition")) {
  18267. addTrailingComment$2(precedingNode, comment);
  18268. return true;
  18269. }
  18270. return false;
  18271. }
  18272. function handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) {
  18273. if (util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== "(") {
  18274. return false;
  18275. }
  18276. if (precedingNode && enclosingNode && (enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "MethodDefinition" || enclosingNode.type === "ObjectMethod")) {
  18277. addTrailingComment$2(precedingNode, comment);
  18278. return true;
  18279. }
  18280. return false;
  18281. }
  18282. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  18283. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  18284. return false;
  18285. }
  18286. var index = utilShared.getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
  18287. if (text.substr(index, 2) === "=>") {
  18288. addDanglingComment$2(enclosingNode, comment);
  18289. return true;
  18290. }
  18291. return false;
  18292. }
  18293. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  18294. if (util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== ")") {
  18295. return false;
  18296. } // Only add dangling comments to fix the case when no params are present,
  18297. // i.e. a function without any argument.
  18298. if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || (enclosingNode.type === "CallExpression" || enclosingNode.type === "OptionalCallExpression" || enclosingNode.type === "NewExpression") && enclosingNode.arguments.length === 0)) {
  18299. addDanglingComment$2(enclosingNode, comment);
  18300. return true;
  18301. }
  18302. if (enclosingNode && enclosingNode.type === "MethodDefinition" && enclosingNode.value.params.length === 0) {
  18303. addDanglingComment$2(enclosingNode.value, comment);
  18304. return true;
  18305. }
  18306. return false;
  18307. }
  18308. function handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  18309. // Type definitions functions
  18310. if (precedingNode && precedingNode.type === "FunctionTypeParam" && enclosingNode && enclosingNode.type === "FunctionTypeAnnotation" && followingNode && followingNode.type !== "FunctionTypeParam") {
  18311. addTrailingComment$2(precedingNode, comment);
  18312. return true;
  18313. } // Real functions
  18314. if (precedingNode && (precedingNode.type === "Identifier" || precedingNode.type === "AssignmentPattern") && enclosingNode && (enclosingNode.type === "ArrowFunctionExpression" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "ObjectMethod" || enclosingNode.type === "ClassMethod") && util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) === ")") {
  18315. addTrailingComment$2(precedingNode, comment);
  18316. return true;
  18317. }
  18318. if (enclosingNode && enclosingNode.type === "FunctionDeclaration" && followingNode && followingNode.type === "BlockStatement") {
  18319. var functionParamRightParenIndex = function () {
  18320. if (enclosingNode.params.length !== 0) {
  18321. return util.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(util.getLast(enclosingNode.params)));
  18322. }
  18323. var functionParamLeftParenIndex = util.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(enclosingNode.id));
  18324. return util.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, functionParamLeftParenIndex + 1);
  18325. }();
  18326. if (options.locStart(comment) > functionParamRightParenIndex) {
  18327. addBlockStatementFirstComment(followingNode, comment);
  18328. return true;
  18329. }
  18330. }
  18331. return false;
  18332. }
  18333. function handleImportSpecifierComments(enclosingNode, comment) {
  18334. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  18335. addLeadingComment$2(enclosingNode, comment);
  18336. return true;
  18337. }
  18338. return false;
  18339. }
  18340. function handleLabeledStatementComments(enclosingNode, comment) {
  18341. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  18342. addLeadingComment$2(enclosingNode, comment);
  18343. return true;
  18344. }
  18345. return false;
  18346. }
  18347. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  18348. if (enclosingNode && (enclosingNode.type === "ContinueStatement" || enclosingNode.type === "BreakStatement") && !enclosingNode.label) {
  18349. addTrailingComment$2(enclosingNode, comment);
  18350. return true;
  18351. }
  18352. return false;
  18353. }
  18354. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  18355. if (enclosingNode && (enclosingNode.type === "CallExpression" || enclosingNode.type === "OptionalCallExpression") && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
  18356. addLeadingComment$2(enclosingNode.arguments[0], comment);
  18357. return true;
  18358. }
  18359. return false;
  18360. }
  18361. function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
  18362. if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
  18363. addTrailingComment$2(precedingNode, comment);
  18364. return true;
  18365. }
  18366. return false;
  18367. }
  18368. function handlePropertyComments(enclosingNode, comment) {
  18369. if (enclosingNode && (enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty")) {
  18370. addLeadingComment$2(enclosingNode, comment);
  18371. return true;
  18372. }
  18373. return false;
  18374. }
  18375. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  18376. // With Flow the enclosingNode is undefined so use the AST instead.
  18377. if (ast && ast.body && ast.body.length === 0) {
  18378. if (isLastComment) {
  18379. addDanglingComment$2(ast, comment);
  18380. } else {
  18381. addLeadingComment$2(ast, comment);
  18382. }
  18383. return true;
  18384. } else if (enclosingNode && enclosingNode.type === "Program" && enclosingNode.body.length === 0 && enclosingNode.directives && enclosingNode.directives.length === 0) {
  18385. if (isLastComment) {
  18386. addDanglingComment$2(enclosingNode, comment);
  18387. } else {
  18388. addLeadingComment$2(enclosingNode, comment);
  18389. }
  18390. return true;
  18391. }
  18392. return false;
  18393. }
  18394. function handleForComments(enclosingNode, precedingNode, comment) {
  18395. if (enclosingNode && (enclosingNode.type === "ForInStatement" || enclosingNode.type === "ForOfStatement")) {
  18396. addLeadingComment$2(enclosingNode, comment);
  18397. return true;
  18398. }
  18399. return false;
  18400. }
  18401. function handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) {
  18402. if (precedingNode && precedingNode.type === "ImportSpecifier" && enclosingNode && enclosingNode.type === "ImportDeclaration" && util.hasNewline(text, options.locEnd(comment))) {
  18403. addTrailingComment$2(precedingNode, comment);
  18404. return true;
  18405. }
  18406. return false;
  18407. }
  18408. function handleAssignmentPatternComments(enclosingNode, comment) {
  18409. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  18410. addLeadingComment$2(enclosingNode, comment);
  18411. return true;
  18412. }
  18413. return false;
  18414. }
  18415. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  18416. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  18417. addLeadingComment$2(enclosingNode, comment);
  18418. return true;
  18419. }
  18420. return false;
  18421. }
  18422. function handleVariableDeclaratorComments(enclosingNode, followingNode, comment) {
  18423. if (enclosingNode && (enclosingNode.type === "VariableDeclarator" || enclosingNode.type === "AssignmentExpression") && followingNode && (followingNode.type === "ObjectExpression" || followingNode.type === "ArrayExpression" || followingNode.type === "TemplateLiteral" || followingNode.type === "TaggedTemplateExpression")) {
  18424. addLeadingComment$2(followingNode, comment);
  18425. return true;
  18426. }
  18427. return false;
  18428. }
  18429. function handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) {
  18430. if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
  18431. return false;
  18432. }
  18433. if (followingNode && followingNode.type === "TSTypeParameter" && followingNode.name) {
  18434. addLeadingComment$2(followingNode.name, comment);
  18435. return true;
  18436. }
  18437. if (precedingNode && precedingNode.type === "TSTypeParameter" && precedingNode.constraint) {
  18438. addTrailingComment$2(precedingNode.constraint, comment);
  18439. return true;
  18440. }
  18441. return false;
  18442. }
  18443. function isBlockComment(comment) {
  18444. return comment.type === "Block" || comment.type === "CommentBlock";
  18445. }
  18446. function hasLeadingComment(node) {
  18447. var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  18448. return true;
  18449. };
  18450. if (node.leadingComments) {
  18451. return node.leadingComments.some(fn);
  18452. }
  18453. if (node.comments) {
  18454. return node.comments.some(function (comment) {
  18455. return comment.leading && fn(comment);
  18456. });
  18457. }
  18458. return false;
  18459. }
  18460. var comments$1 = {
  18461. handleOwnLineComment: handleOwnLineComment,
  18462. handleEndOfLineComment: handleEndOfLineComment,
  18463. handleRemainingComment: handleRemainingComment,
  18464. hasLeadingComment: hasLeadingComment,
  18465. isBlockComment: isBlockComment
  18466. };
  18467. var isBlockComment$1 = comments$1.isBlockComment,
  18468. hasLeadingComment$1 = comments$1.hasLeadingComment;
  18469. var _require$$1$builders = doc.builders,
  18470. indent$6 = _require$$1$builders.indent,
  18471. join$7 = _require$$1$builders.join,
  18472. hardline$8 = _require$$1$builders.hardline,
  18473. softline$5 = _require$$1$builders.softline,
  18474. literalline$3 = _require$$1$builders.literalline,
  18475. concat$b = _require$$1$builders.concat,
  18476. group$a = _require$$1$builders.group,
  18477. dedentToRoot$2 = _require$$1$builders.dedentToRoot,
  18478. _require$$1$utils = doc.utils,
  18479. mapDoc$5 = _require$$1$utils.mapDoc,
  18480. stripTrailingHardline$2 = _require$$1$utils.stripTrailingHardline;
  18481. function embed$3(path, print, textToDoc, options) {
  18482. var node = path.getValue();
  18483. var parent = path.getParentNode();
  18484. var parentParent = path.getParentNode(1);
  18485. switch (node.type) {
  18486. case "TemplateLiteral":
  18487. {
  18488. var isCss = [isStyledJsx, isStyledComponents, isCssProp, isAngularComponentStyles].some(function (isIt) {
  18489. return isIt(path);
  18490. });
  18491. if (isCss) {
  18492. // Get full template literal with expressions replaced by placeholders
  18493. var rawQuasis = node.quasis.map(function (q) {
  18494. return q.value.raw;
  18495. });
  18496. var placeholderID = 0;
  18497. var text = rawQuasis.reduce(function (prevVal, currVal, idx) {
  18498. return idx == 0 ? currVal : prevVal + "@prettier-placeholder-" + placeholderID++ + "-id" + currVal;
  18499. }, "");
  18500. var doc = textToDoc(text, {
  18501. parser: "css"
  18502. });
  18503. return transformCssDoc(doc, path, print);
  18504. }
  18505. /*
  18506. * react-relay and graphql-tag
  18507. * graphql`...`
  18508. * graphql.experimental`...`
  18509. * gql`...`
  18510. *
  18511. * This intentionally excludes Relay Classic tags, as Prettier does not
  18512. * support Relay Classic formatting.
  18513. */
  18514. if (isGraphQL(path)) {
  18515. var expressionDocs = node.expressions ? path.map(print, "expressions") : [];
  18516. var numQuasis = node.quasis.length;
  18517. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  18518. return "``";
  18519. }
  18520. var parts = [];
  18521. for (var i = 0; i < numQuasis; i++) {
  18522. var templateElement = node.quasis[i];
  18523. var isFirst = i === 0;
  18524. var isLast = i === numQuasis - 1;
  18525. var _text = templateElement.value.cooked; // Bail out if any of the quasis have an invalid escape sequence
  18526. // (which would make the `cooked` value be `null` or `undefined`)
  18527. if (typeof _text !== "string") {
  18528. return null;
  18529. }
  18530. var lines = _text.split("\n");
  18531. var numLines = lines.length;
  18532. var expressionDoc = expressionDocs[i];
  18533. var startsWithBlankLine = numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  18534. var endsWithBlankLine = numLines > 2 && lines[numLines - 1].trim() === "" && lines[numLines - 2].trim() === "";
  18535. var commentsAndWhitespaceOnly = lines.every(function (line) {
  18536. return /^\s*(?:#[^\r\n]*)?$/.test(line);
  18537. }); // Bail out if an interpolation occurs within a comment.
  18538. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  18539. return null;
  18540. }
  18541. var _doc = null;
  18542. if (commentsAndWhitespaceOnly) {
  18543. _doc = printGraphqlComments(lines);
  18544. } else {
  18545. _doc = stripTrailingHardline$2(textToDoc(_text, {
  18546. parser: "graphql"
  18547. }));
  18548. }
  18549. if (_doc) {
  18550. _doc = escapeTemplateCharacters(_doc, false);
  18551. if (!isFirst && startsWithBlankLine) {
  18552. parts.push("");
  18553. }
  18554. parts.push(_doc);
  18555. if (!isLast && endsWithBlankLine) {
  18556. parts.push("");
  18557. }
  18558. } else if (!isFirst && !isLast && startsWithBlankLine) {
  18559. parts.push("");
  18560. }
  18561. if (expressionDoc) {
  18562. parts.push(concat$b(["${", expressionDoc, "}"]));
  18563. }
  18564. }
  18565. return concat$b(["`", indent$6(concat$b([hardline$8, join$7(hardline$8, parts)])), hardline$8, "`"]);
  18566. }
  18567. var htmlParser = isHtml(path) ? "html" : isAngularComponentTemplate(path) ? "angular" : undefined;
  18568. if (htmlParser) {
  18569. return printHtmlTemplateLiteral(path, print, textToDoc, htmlParser, options.embeddedInHtml);
  18570. }
  18571. break;
  18572. }
  18573. case "TemplateElement":
  18574. {
  18575. /**
  18576. * md`...`
  18577. * markdown`...`
  18578. */
  18579. if (parentParent && parentParent.type === "TaggedTemplateExpression" && parent.quasis.length === 1 && parentParent.tag.type === "Identifier" && (parentParent.tag.name === "md" || parentParent.tag.name === "markdown")) {
  18580. var _text2 = parent.quasis[0].value.raw.replace(/((?:\\\\)*)\\`/g, function (_, backslashes) {
  18581. return "\\".repeat(backslashes.length / 2) + "`";
  18582. });
  18583. var indentation = getIndentation(_text2);
  18584. var hasIndent = indentation !== "";
  18585. return concat$b([hasIndent ? indent$6(concat$b([softline$5, printMarkdown(_text2.replace(new RegExp("^".concat(indentation), "gm"), ""))])) : concat$b([literalline$3, dedentToRoot$2(printMarkdown(_text2))]), softline$5]);
  18586. }
  18587. break;
  18588. }
  18589. }
  18590. function printMarkdown(text) {
  18591. var doc = textToDoc(text, {
  18592. parser: "markdown",
  18593. __inJsTemplate: true
  18594. });
  18595. return stripTrailingHardline$2(escapeTemplateCharacters(doc, true));
  18596. }
  18597. }
  18598. function getIndentation(str) {
  18599. var firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  18600. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  18601. }
  18602. function uncook(cookedValue) {
  18603. return cookedValue.replace(/([\\`]|\$\{)/g, "\\$1");
  18604. }
  18605. function escapeTemplateCharacters(doc, raw) {
  18606. return mapDoc$5(doc, function (currentDoc) {
  18607. if (!currentDoc.parts) {
  18608. return currentDoc;
  18609. }
  18610. var parts = [];
  18611. currentDoc.parts.forEach(function (part) {
  18612. if (typeof part === "string") {
  18613. parts.push(raw ? part.replace(/(\\*)`/g, "$1$1\\`") : uncook(part));
  18614. } else {
  18615. parts.push(part);
  18616. }
  18617. });
  18618. return Object.assign({}, currentDoc, {
  18619. parts: parts
  18620. });
  18621. });
  18622. }
  18623. function transformCssDoc(quasisDoc, path, print) {
  18624. var parentNode = path.getValue();
  18625. var isEmpty = parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  18626. if (isEmpty) {
  18627. return "``";
  18628. }
  18629. var expressionDocs = parentNode.expressions ? path.map(print, "expressions") : [];
  18630. var newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  18631. /* istanbul ignore if */
  18632. if (!newDoc) {
  18633. throw new Error("Couldn't insert all the expressions");
  18634. }
  18635. return concat$b(["`", indent$6(concat$b([hardline$8, stripTrailingHardline$2(newDoc)])), softline$5, "`"]);
  18636. } // Search all the placeholders in the quasisDoc tree
  18637. // and replace them with the expression docs one by one
  18638. // returns a new doc with all the placeholders replaced,
  18639. // or null if it couldn't replace any expression
  18640. function replacePlaceholders(quasisDoc, expressionDocs) {
  18641. if (!expressionDocs || !expressionDocs.length) {
  18642. return quasisDoc;
  18643. }
  18644. var expressions = expressionDocs.slice();
  18645. var replaceCounter = 0;
  18646. var newDoc = mapDoc$5(quasisDoc, function (doc) {
  18647. if (!doc || !doc.parts || !doc.parts.length) {
  18648. return doc;
  18649. }
  18650. var parts = doc.parts;
  18651. var atIndex = parts.indexOf("@");
  18652. var placeholderIndex = atIndex + 1;
  18653. if (atIndex > -1 && typeof parts[placeholderIndex] === "string" && parts[placeholderIndex].startsWith("prettier-placeholder")) {
  18654. // If placeholder is split, join it
  18655. var at = parts[atIndex];
  18656. var placeholder = parts[placeholderIndex];
  18657. var rest = parts.slice(placeholderIndex + 1);
  18658. parts = parts.slice(0, atIndex).concat([at + placeholder]).concat(rest);
  18659. }
  18660. var atPlaceholderIndex = parts.findIndex(function (part) {
  18661. return typeof part === "string" && part.startsWith("@prettier-placeholder");
  18662. });
  18663. if (atPlaceholderIndex > -1) {
  18664. var _placeholder = parts[atPlaceholderIndex];
  18665. var _rest = parts.slice(atPlaceholderIndex + 1);
  18666. var placeholderMatch = _placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
  18667. var placeholderID = placeholderMatch[1]; // When the expression has a suffix appended, like:
  18668. // animation: linear ${time}s ease-out;
  18669. var suffix = placeholderMatch[2];
  18670. var expression = expressions[placeholderID];
  18671. replaceCounter++;
  18672. parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(_rest);
  18673. }
  18674. return Object.assign({}, doc, {
  18675. parts: parts
  18676. });
  18677. });
  18678. return expressions.length === replaceCounter ? newDoc : null;
  18679. }
  18680. function printGraphqlComments(lines) {
  18681. var parts = [];
  18682. var seenComment = false;
  18683. lines.map(function (textLine) {
  18684. return textLine.trim();
  18685. }).forEach(function (textLine, i, array) {
  18686. // Lines are either whitespace only, or a comment (with potential whitespace
  18687. // around it). Drop whitespace-only lines.
  18688. if (textLine === "") {
  18689. return;
  18690. }
  18691. if (array[i - 1] === "" && seenComment) {
  18692. // If a non-first comment is preceded by a blank (whitespace only) line,
  18693. // add in a blank line.
  18694. parts.push(concat$b([hardline$8, textLine]));
  18695. } else {
  18696. parts.push(textLine);
  18697. }
  18698. seenComment = true;
  18699. }); // If `lines` was whitespace only, return `null`.
  18700. return parts.length === 0 ? null : join$7(hardline$8, parts);
  18701. }
  18702. /**
  18703. * Template literal in these contexts:
  18704. * <style jsx>{`div{color:red}`}</style>
  18705. * css``
  18706. * css.global``
  18707. * css.resolve``
  18708. */
  18709. function isStyledJsx(path) {
  18710. var node = path.getValue();
  18711. var parent = path.getParentNode();
  18712. var parentParent = path.getParentNode(1);
  18713. return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(function (attribute) {
  18714. return attribute.name.name === "jsx";
  18715. }) || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "Identifier" && parent.tag.name === "css" || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "MemberExpression" && parent.tag.object.name === "css" && (parent.tag.property.name === "global" || parent.tag.property.name === "resolve");
  18716. }
  18717. /**
  18718. * Angular Components can have:
  18719. * - Inline HTML template
  18720. * - Inline CSS styles
  18721. *
  18722. * ...which are both within template literals somewhere
  18723. * inside of the Component decorator factory.
  18724. *
  18725. * E.g.
  18726. * @Component({
  18727. * template: `<div>...</div>`,
  18728. * styles: [`h1 { color: blue; }`]
  18729. * })
  18730. */
  18731. function isAngularComponentStyles(path) {
  18732. return isPathMatch(path, [function (node) {
  18733. return node.type === "TemplateLiteral";
  18734. }, function (node, name) {
  18735. return node.type === "ArrayExpression" && name === "elements";
  18736. }, function (node, name) {
  18737. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "styles" && name === "value";
  18738. }].concat(getAngularComponentObjectExpressionPredicates()));
  18739. }
  18740. function isAngularComponentTemplate(path) {
  18741. return isPathMatch(path, [function (node) {
  18742. return node.type === "TemplateLiteral";
  18743. }, function (node, name) {
  18744. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "template" && name === "value";
  18745. }].concat(getAngularComponentObjectExpressionPredicates()));
  18746. }
  18747. function getAngularComponentObjectExpressionPredicates() {
  18748. return [function (node, name) {
  18749. return node.type === "ObjectExpression" && name === "properties";
  18750. }, function (node, name) {
  18751. return node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "Component" && name === "arguments";
  18752. }, function (node, name) {
  18753. return node.type === "Decorator" && name === "expression";
  18754. }];
  18755. }
  18756. /**
  18757. * styled-components template literals
  18758. */
  18759. function isStyledComponents(path) {
  18760. var parent = path.getParentNode();
  18761. if (!parent || parent.type !== "TaggedTemplateExpression") {
  18762. return false;
  18763. }
  18764. var tag = parent.tag;
  18765. switch (tag.type) {
  18766. case "MemberExpression":
  18767. return (// styled.foo``
  18768. isStyledIdentifier(tag.object) || // Component.extend``
  18769. isStyledExtend(tag)
  18770. );
  18771. case "CallExpression":
  18772. return (// styled(Component)``
  18773. isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attrs({})``
  18774. isStyledIdentifier(tag.callee.object.object) || // Component.extend.attrs({})``
  18775. isStyledExtend(tag.callee.object)) || // styled(Component).attrs({})``
  18776. tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
  18777. );
  18778. case "Identifier":
  18779. // css``
  18780. return tag.name === "css";
  18781. default:
  18782. return false;
  18783. }
  18784. }
  18785. /**
  18786. * JSX element with CSS prop
  18787. */
  18788. function isCssProp(path) {
  18789. var parent = path.getParentNode();
  18790. var parentParent = path.getParentNode(1);
  18791. return parentParent && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" && parentParent.name.type === "JSXIdentifier" && parentParent.name.name === "css";
  18792. }
  18793. function isStyledIdentifier(node) {
  18794. return node.type === "Identifier" && node.name === "styled";
  18795. }
  18796. function isStyledExtend(node) {
  18797. return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
  18798. }
  18799. /*
  18800. * react-relay and graphql-tag
  18801. * graphql`...`
  18802. * graphql.experimental`...`
  18803. * gql`...`
  18804. * GraphQL comment block
  18805. *
  18806. * This intentionally excludes Relay Classic tags, as Prettier does not
  18807. * support Relay Classic formatting.
  18808. */
  18809. function isGraphQL(path) {
  18810. var node = path.getValue();
  18811. var parent = path.getParentNode();
  18812. return hasLanguageComment(node, "GraphQL") || parent && (parent.type === "TaggedTemplateExpression" && (parent.tag.type === "MemberExpression" && parent.tag.object.name === "graphql" && parent.tag.property.name === "experimental" || parent.tag.type === "Identifier" && (parent.tag.name === "gql" || parent.tag.name === "graphql")) || parent.type === "CallExpression" && parent.callee.type === "Identifier" && parent.callee.name === "graphql");
  18813. }
  18814. function hasLanguageComment(node, languageName) {
  18815. // This checks for a leading comment that is exactly `/* GraphQL */`
  18816. // In order to be in line with other implementations of this comment tag
  18817. // we will not trim the comment value and we will expect exactly one space on
  18818. // either side of the GraphQL string
  18819. // Also see ./clean.js
  18820. return hasLeadingComment$1(node, function (comment) {
  18821. return isBlockComment$1(comment) && comment.value === " ".concat(languageName, " ");
  18822. });
  18823. }
  18824. function isPathMatch(path, predicateStack) {
  18825. var stack = path.stack.slice();
  18826. var name = null;
  18827. var node = stack.pop();
  18828. var _iteratorNormalCompletion = true;
  18829. var _didIteratorError = false;
  18830. var _iteratorError = undefined;
  18831. try {
  18832. for (var _iterator = predicateStack[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  18833. var predicate = _step.value;
  18834. if (node === undefined) {
  18835. return false;
  18836. } // skip index/array
  18837. if (typeof name === "number") {
  18838. name = stack.pop();
  18839. node = stack.pop();
  18840. }
  18841. if (!predicate(node, name)) {
  18842. return false;
  18843. }
  18844. name = stack.pop();
  18845. node = stack.pop();
  18846. }
  18847. } catch (err) {
  18848. _didIteratorError = true;
  18849. _iteratorError = err;
  18850. } finally {
  18851. try {
  18852. if (!_iteratorNormalCompletion && _iterator.return != null) {
  18853. _iterator.return();
  18854. }
  18855. } finally {
  18856. if (_didIteratorError) {
  18857. throw _iteratorError;
  18858. }
  18859. }
  18860. }
  18861. return true;
  18862. }
  18863. /**
  18864. * - html`...`
  18865. * - HTML comment block
  18866. */
  18867. function isHtml(path) {
  18868. var node = path.getValue();
  18869. return hasLanguageComment(node, "HTML") || isPathMatch(path, [function (node) {
  18870. return node.type === "TemplateLiteral";
  18871. }, function (node, name) {
  18872. return node.type === "TaggedTemplateExpression" && node.tag.type === "Identifier" && node.tag.name === "html" && name === "quasi";
  18873. }]);
  18874. } // The counter is needed to distinguish nested embeds.
  18875. var htmlTemplateLiteralCounter = 0;
  18876. function printHtmlTemplateLiteral(path, print, textToDoc, parser, escapeClosingScriptTag) {
  18877. var node = path.getValue();
  18878. var counter = htmlTemplateLiteralCounter;
  18879. htmlTemplateLiteralCounter = htmlTemplateLiteralCounter + 1 >>> 0;
  18880. var composePlaceholder = function composePlaceholder(index) {
  18881. return "PRETTIER_HTML_PLACEHOLDER_".concat(index, "_").concat(counter, "_IN_JS");
  18882. };
  18883. var text = node.quasis.map(function (quasi, index, quasis) {
  18884. return index === quasis.length - 1 ? quasi.value.cooked : quasi.value.cooked + composePlaceholder(index);
  18885. }).join("");
  18886. var expressionDocs = path.map(print, "expressions");
  18887. if (expressionDocs.length === 0 && text.trim().length === 0) {
  18888. return "``";
  18889. }
  18890. var placeholderRegex = RegExp(composePlaceholder("(\\d+)"), "g");
  18891. var contentDoc = mapDoc$5(stripTrailingHardline$2(textToDoc(text, {
  18892. parser: parser
  18893. })), function (doc) {
  18894. if (typeof doc !== "string") {
  18895. return doc;
  18896. }
  18897. var parts = [];
  18898. var components = doc.split(placeholderRegex);
  18899. for (var i = 0; i < components.length; i++) {
  18900. var component = components[i];
  18901. if (i % 2 === 0) {
  18902. if (component) {
  18903. component = uncook(component);
  18904. if (escapeClosingScriptTag) {
  18905. component = component.replace(/<\/(script)\b/gi, "<\\/$1");
  18906. }
  18907. parts.push(component);
  18908. }
  18909. continue;
  18910. }
  18911. var placeholderIndex = +component;
  18912. parts.push(concat$b(["${", group$a(expressionDocs[placeholderIndex]), "}"]));
  18913. }
  18914. return concat$b(parts);
  18915. });
  18916. return group$a(concat$b(["`", indent$6(concat$b([hardline$8, group$a(contentDoc)])), softline$5, "`"]));
  18917. }
  18918. var embed_1$1 = embed$3;
  18919. function clean$4(ast, newObj, parent) {
  18920. ["range", "raw", "comments", "leadingComments", "trailingComments", "extra", "start", "end", "flags", "errors"].forEach(function (name) {
  18921. delete newObj[name];
  18922. });
  18923. if (ast.type === "BigIntLiteral") {
  18924. newObj.value = newObj.value.toLowerCase();
  18925. } // We remove extra `;` and add them when needed
  18926. if (ast.type === "EmptyStatement") {
  18927. return null;
  18928. } // We move text around, including whitespaces and add {" "}
  18929. if (ast.type === "JSXText") {
  18930. return null;
  18931. }
  18932. if (ast.type === "JSXExpressionContainer" && ast.expression.type === "Literal" && ast.expression.value === " ") {
  18933. return null;
  18934. } // We remove unneeded parens around same-operator LogicalExpressions
  18935. if (isUnbalancedLogicalTree(newObj)) {
  18936. return rebalanceLogicalTree(newObj);
  18937. } // (TypeScript) Ignore `static` in `constructor(static p) {}`
  18938. // and `export` in `constructor(export p) {}`
  18939. if (ast.type === "TSParameterProperty" && ast.accessibility === null && !ast.readonly) {
  18940. return {
  18941. type: "Identifier",
  18942. name: ast.parameter.name,
  18943. typeAnnotation: newObj.parameter.typeAnnotation,
  18944. decorators: newObj.decorators
  18945. };
  18946. } // (TypeScript) ignore empty `specifiers` array
  18947. if (ast.type === "TSNamespaceExportDeclaration" && ast.specifiers && ast.specifiers.length === 0) {
  18948. delete newObj.specifiers;
  18949. } // We convert <div></div> to <div />
  18950. if (ast.type === "JSXOpeningElement") {
  18951. delete newObj.selfClosing;
  18952. }
  18953. if (ast.type === "JSXElement") {
  18954. delete newObj.closingElement;
  18955. } // We change {'key': value} into {key: value}
  18956. if ((ast.type === "Property" || ast.type === "ObjectProperty" || ast.type === "MethodDefinition" || ast.type === "ClassProperty" || ast.type === "TSPropertySignature" || ast.type === "ObjectTypeProperty") && _typeof(ast.key) === "object" && ast.key && (ast.key.type === "Literal" || ast.key.type === "StringLiteral" || ast.key.type === "Identifier")) {
  18957. delete newObj.key;
  18958. }
  18959. if (ast.type === "OptionalMemberExpression" && ast.optional === false) {
  18960. newObj.type = "MemberExpression";
  18961. delete newObj.optional;
  18962. } // Remove raw and cooked values from TemplateElement when it's CSS
  18963. // styled-jsx
  18964. if (ast.type === "JSXElement" && ast.openingElement.name.name === "style" && ast.openingElement.attributes.some(function (attr) {
  18965. return attr.name.name === "jsx";
  18966. })) {
  18967. var templateLiterals = newObj.children.filter(function (child) {
  18968. return child.type === "JSXExpressionContainer" && child.expression.type === "TemplateLiteral";
  18969. }).map(function (container) {
  18970. return container.expression;
  18971. });
  18972. var quasis = templateLiterals.reduce(function (quasis, templateLiteral) {
  18973. return quasis.concat(templateLiteral.quasis);
  18974. }, []);
  18975. quasis.forEach(function (q) {
  18976. return delete q.value;
  18977. });
  18978. } // CSS template literals in css prop
  18979. if (ast.type === "JSXAttribute" && ast.name.name === "css" && ast.value.type === "JSXExpressionContainer" && ast.value.expression.type === "TemplateLiteral") {
  18980. newObj.value.expression.quasis.forEach(function (q) {
  18981. return delete q.value;
  18982. });
  18983. } // Angular Components: Inline HTML template and Inline CSS styles
  18984. var expression = ast.expression || ast.callee;
  18985. if (ast.type === "Decorator" && expression.type === "CallExpression" && expression.callee.name === "Component" && expression.arguments.length === 1) {
  18986. var astProps = ast.expression.arguments[0].properties;
  18987. newObj.expression.arguments[0].properties.forEach(function (prop, index) {
  18988. var templateLiteral = null;
  18989. switch (astProps[index].key.name) {
  18990. case "styles":
  18991. if (prop.value.type === "ArrayExpression") {
  18992. templateLiteral = prop.value.elements[0];
  18993. }
  18994. break;
  18995. case "template":
  18996. if (prop.value.type === "TemplateLiteral") {
  18997. templateLiteral = prop.value;
  18998. }
  18999. break;
  19000. }
  19001. if (templateLiteral) {
  19002. templateLiteral.quasis.forEach(function (q) {
  19003. return delete q.value;
  19004. });
  19005. }
  19006. });
  19007. } // styled-components, graphql, markdown
  19008. if (ast.type === "TaggedTemplateExpression" && (ast.tag.type === "MemberExpression" || ast.tag.type === "Identifier" && (ast.tag.name === "gql" || ast.tag.name === "graphql" || ast.tag.name === "css" || ast.tag.name === "md" || ast.tag.name === "markdown" || ast.tag.name === "html") || ast.tag.type === "CallExpression")) {
  19009. newObj.quasi.quasis.forEach(function (quasi) {
  19010. return delete quasi.value;
  19011. });
  19012. }
  19013. if (ast.type === "TemplateLiteral") {
  19014. // This checks for a leading comment that is exactly `/* GraphQL */`
  19015. // In order to be in line with other implementations of this comment tag
  19016. // we will not trim the comment value and we will expect exactly one space on
  19017. // either side of the GraphQL string
  19018. // Also see ./embed.js
  19019. var hasLanguageComment = ast.leadingComments && ast.leadingComments.some(function (comment) {
  19020. return comment.type === "CommentBlock" && ["GraphQL", "HTML"].some(function (languageName) {
  19021. return comment.value === " ".concat(languageName, " ");
  19022. });
  19023. });
  19024. if (hasLanguageComment || parent.type === "CallExpression" && parent.callee.name === "graphql") {
  19025. newObj.quasis.forEach(function (quasi) {
  19026. return delete quasi.value;
  19027. });
  19028. }
  19029. }
  19030. }
  19031. function isUnbalancedLogicalTree(newObj) {
  19032. return newObj.type === "LogicalExpression" && newObj.right.type === "LogicalExpression" && newObj.operator === newObj.right.operator;
  19033. }
  19034. function rebalanceLogicalTree(newObj) {
  19035. if (isUnbalancedLogicalTree(newObj)) {
  19036. return rebalanceLogicalTree({
  19037. type: "LogicalExpression",
  19038. operator: newObj.operator,
  19039. left: rebalanceLogicalTree({
  19040. type: "LogicalExpression",
  19041. operator: newObj.operator,
  19042. left: newObj.left,
  19043. right: newObj.right.left,
  19044. loc: {}
  19045. }),
  19046. right: newObj.right.right,
  19047. loc: {}
  19048. });
  19049. }
  19050. return newObj;
  19051. }
  19052. var clean_1$1 = clean$4;
  19053. var getLast$1 = util.getLast,
  19054. hasNewline$3 = util.hasNewline,
  19055. hasNewlineInRange$1 = util.hasNewlineInRange,
  19056. hasIgnoreComment$3 = util.hasIgnoreComment,
  19057. hasNodeIgnoreComment$1 = util.hasNodeIgnoreComment,
  19058. skipWhitespace$1 = util.skipWhitespace;
  19059. var isIdentifierName = utils$1.keyword.isIdentifierNameES5; // We match any whitespace except line terminators because
  19060. // Flow annotation comments cannot be split across lines. For example:
  19061. //
  19062. // (this /*
  19063. // : any */).foo = 5;
  19064. //
  19065. // is not picked up by Flow (see https://github.com/facebook/flow/issues/7050), so
  19066. // removing the newline would create a type annotation that the user did not intend
  19067. // to create.
  19068. var NON_LINE_TERMINATING_WHITE_SPACE = "(?:(?=.)\\s)";
  19069. var FLOW_SHORTHAND_ANNOTATION = new RegExp("^".concat(NON_LINE_TERMINATING_WHITE_SPACE, "*:"));
  19070. var FLOW_ANNOTATION = new RegExp("^".concat(NON_LINE_TERMINATING_WHITE_SPACE, "*::"));
  19071. function hasFlowShorthandAnnotationComment(node) {
  19072. // https://flow.org/en/docs/types/comments/
  19073. // Syntax example: const r = new (window.Request /*: Class<Request> */)("");
  19074. return node.extra && node.extra.parenthesized && node.trailingComments && node.trailingComments[0].value.match(FLOW_SHORTHAND_ANNOTATION);
  19075. }
  19076. function hasFlowAnnotationComment(comments) {
  19077. return comments && comments[0].value.match(FLOW_ANNOTATION);
  19078. }
  19079. function hasNode(node, fn) {
  19080. if (!node || _typeof(node) !== "object") {
  19081. return false;
  19082. }
  19083. if (Array.isArray(node)) {
  19084. return node.some(function (value) {
  19085. return hasNode(value, fn);
  19086. });
  19087. }
  19088. var result = fn(node);
  19089. return typeof result === "boolean" ? result : Object.keys(node).some(function (key) {
  19090. return hasNode(node[key], fn);
  19091. });
  19092. }
  19093. function hasNakedLeftSide(node) {
  19094. return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression" || node.type === "ConditionalExpression" || node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || node.type === "UpdateExpression" && !node.prefix || node.type === "TSAsExpression" || node.type === "TSNonNullExpression";
  19095. }
  19096. function getLeftSide(node) {
  19097. if (node.expressions) {
  19098. return node.expressions[0];
  19099. }
  19100. return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
  19101. }
  19102. function getLeftSidePathName(path, node) {
  19103. if (node.expressions) {
  19104. return ["expressions", 0];
  19105. }
  19106. if (node.left) {
  19107. return ["left"];
  19108. }
  19109. if (node.test) {
  19110. return ["test"];
  19111. }
  19112. if (node.object) {
  19113. return ["object"];
  19114. }
  19115. if (node.callee) {
  19116. return ["callee"];
  19117. }
  19118. if (node.tag) {
  19119. return ["tag"];
  19120. }
  19121. if (node.argument) {
  19122. return ["argument"];
  19123. }
  19124. if (node.expression) {
  19125. return ["expression"];
  19126. }
  19127. throw new Error("Unexpected node has no left side", node);
  19128. }
  19129. function isLiteral(node) {
  19130. return node.type === "BooleanLiteral" || node.type === "DirectiveLiteral" || node.type === "Literal" || node.type === "NullLiteral" || node.type === "NumericLiteral" || node.type === "RegExpLiteral" || node.type === "StringLiteral" || node.type === "TemplateLiteral" || node.type === "TSTypeLiteral" || node.type === "JSXText";
  19131. }
  19132. function isNumericLiteral(node) {
  19133. return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
  19134. }
  19135. function isStringLiteral(node) {
  19136. return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
  19137. }
  19138. function isObjectType(n) {
  19139. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  19140. }
  19141. function isFunctionOrArrowExpression(node) {
  19142. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
  19143. }
  19144. function isFunctionOrArrowExpressionWithBody(node) {
  19145. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement";
  19146. }
  19147. function isTemplateLiteral(node) {
  19148. return node.type === "TemplateLiteral";
  19149. } // `inject` is used in AngularJS 1.x, `async` in Angular 2+
  19150. // example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
  19151. function isAngularTestWrapper(node) {
  19152. return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject" || node.callee.name === "fakeAsync");
  19153. }
  19154. function isJSXNode(node) {
  19155. return node.type === "JSXElement" || node.type === "JSXFragment";
  19156. }
  19157. function isTheOnlyJSXElementInMarkdown(options, path) {
  19158. if (options.parentParser !== "markdown" && options.parentParser !== "mdx") {
  19159. return false;
  19160. }
  19161. var node = path.getNode();
  19162. if (!node.expression || !isJSXNode(node.expression)) {
  19163. return false;
  19164. }
  19165. var parent = path.getParentNode();
  19166. return parent.type === "Program" && parent.body.length == 1;
  19167. } // Detect an expression node representing `{" "}`
  19168. function isJSXWhitespaceExpression(node) {
  19169. return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
  19170. }
  19171. function isMemberExpressionChain(node) {
  19172. if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
  19173. return false;
  19174. }
  19175. if (node.object.type === "Identifier") {
  19176. return true;
  19177. }
  19178. return isMemberExpressionChain(node.object);
  19179. }
  19180. function isGetterOrSetter(node) {
  19181. return node.kind === "get" || node.kind === "set";
  19182. }
  19183. function sameLocStart(nodeA, nodeB, options) {
  19184. return options.locStart(nodeA) === options.locStart(nodeB);
  19185. } // TODO: This is a bad hack and we need a better way to distinguish between
  19186. // arrow functions and otherwise
  19187. function isFunctionNotation(node, options) {
  19188. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  19189. } // Hack to differentiate between the following two which have the same ast
  19190. // type T = { method: () => void };
  19191. // type T = { method(): void };
  19192. function isObjectTypePropertyAFunction(node, options) {
  19193. return (node.type === "ObjectTypeProperty" || node.type === "ObjectTypeInternalSlot") && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
  19194. } // Hack to differentiate between the following two which have the same ast
  19195. // declare function f(a): void;
  19196. // var f: (a) => void;
  19197. function isTypeAnnotationAFunction(node, options) {
  19198. return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
  19199. }
  19200. function isBinaryish(node) {
  19201. return node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression";
  19202. }
  19203. function isMemberish(node) {
  19204. return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && node.object;
  19205. }
  19206. function isSimpleFlowType(node) {
  19207. var flowTypeAnnotations = ["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"];
  19208. return node && flowTypeAnnotations.indexOf(node.type) !== -1 && !(node.type === "GenericTypeAnnotation" && node.typeParameters);
  19209. }
  19210. var unitTestRe = /^(skip|[fx]?(it|describe|test))$/;
  19211. function isSkipOrOnlyBlock(node) {
  19212. return (node.callee.type === "MemberExpression" || node.callee.type === "OptionalMemberExpression") && node.callee.object.type === "Identifier" && node.callee.property.type === "Identifier" && unitTestRe.test(node.callee.object.name) && (node.callee.property.name === "only" || node.callee.property.name === "skip");
  19213. }
  19214. function isUnitTestSetUp(n) {
  19215. var unitTestSetUpRe = /^(before|after)(Each|All)$/;
  19216. return n.callee.type === "Identifier" && unitTestSetUpRe.test(n.callee.name) && n.arguments.length === 1;
  19217. } // eg; `describe("some string", (done) => {})`
  19218. function isTestCall(n, parent) {
  19219. if (n.type !== "CallExpression") {
  19220. return false;
  19221. }
  19222. if (n.arguments.length === 1) {
  19223. if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
  19224. return isFunctionOrArrowExpression(n.arguments[0]);
  19225. }
  19226. if (isUnitTestSetUp(n)) {
  19227. return isAngularTestWrapper(n.arguments[0]);
  19228. }
  19229. } else if (n.arguments.length === 2 || n.arguments.length === 3) {
  19230. if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
  19231. // it("name", () => { ... }, 2500)
  19232. if (n.arguments[2] && !isNumericLiteral(n.arguments[2])) {
  19233. return false;
  19234. }
  19235. return (n.arguments.length === 2 ? isFunctionOrArrowExpression(n.arguments[1]) : isFunctionOrArrowExpressionWithBody(n.arguments[1]) && n.arguments[1].params.length <= 1) || isAngularTestWrapper(n.arguments[1]);
  19236. }
  19237. }
  19238. return false;
  19239. }
  19240. function hasLeadingComment$2(node) {
  19241. return node.comments && node.comments.some(function (comment) {
  19242. return comment.leading;
  19243. });
  19244. }
  19245. function hasTrailingComment(node) {
  19246. return node.comments && node.comments.some(function (comment) {
  19247. return comment.trailing;
  19248. });
  19249. }
  19250. function isCallOrOptionalCallExpression(node) {
  19251. return node.type === "CallExpression" || node.type === "OptionalCallExpression";
  19252. }
  19253. function hasDanglingComments(node) {
  19254. return node.comments && node.comments.some(function (comment) {
  19255. return !comment.leading && !comment.trailing;
  19256. });
  19257. }
  19258. /** identify if an angular expression seems to have side effects */
  19259. function hasNgSideEffect(path) {
  19260. return hasNode(path.getValue(), function (node) {
  19261. switch (node.type) {
  19262. case undefined:
  19263. return false;
  19264. case "CallExpression":
  19265. case "OptionalCallExpression":
  19266. case "AssignmentExpression":
  19267. return true;
  19268. }
  19269. });
  19270. }
  19271. function isNgForOf(node, index, parentNode) {
  19272. return node.type === "NGMicrosyntaxKeyedExpression" && node.key.name === "of" && index === 1 && parentNode.body[0].type === "NGMicrosyntaxLet" && parentNode.body[0].value === null;
  19273. }
  19274. /** @param node {import("estree").TemplateLiteral} */
  19275. function isSimpleTemplateLiteral(node) {
  19276. if (node.expressions.length === 0) {
  19277. return false;
  19278. }
  19279. return node.expressions.every(function (expr) {
  19280. // Disallow comments since printDocToString can't print them here
  19281. if (expr.comments) {
  19282. return false;
  19283. } // Allow `x` and `this`
  19284. if (expr.type === "Identifier" || expr.type === "ThisExpression") {
  19285. return true;
  19286. } // Allow `a.b.c`, `a.b[c]`, and `this.x.y`
  19287. if (expr.type === "MemberExpression" || expr.type === "OptionalMemberExpression") {
  19288. var head = expr;
  19289. while (head.type === "MemberExpression" || head.type === "OptionalMemberExpression") {
  19290. if (head.property.type !== "Identifier" && head.property.type !== "Literal" && head.property.type !== "StringLiteral" && head.property.type !== "NumericLiteral") {
  19291. return false;
  19292. }
  19293. head = head.object;
  19294. if (head.comments) {
  19295. return false;
  19296. }
  19297. }
  19298. if (head.type === "Identifier" || head.type === "ThisExpression") {
  19299. return true;
  19300. }
  19301. return false;
  19302. }
  19303. return false;
  19304. });
  19305. }
  19306. function getFlowVariance(path) {
  19307. if (!path.variance) {
  19308. return null;
  19309. } // Babel 7.0 currently uses variance node type, and flow should
  19310. // follow suit soon:
  19311. // https://github.com/babel/babel/issues/4722
  19312. var variance = path.variance.kind || path.variance;
  19313. switch (variance) {
  19314. case "plus":
  19315. return "+";
  19316. case "minus":
  19317. return "-";
  19318. default:
  19319. /* istanbul ignore next */
  19320. return variance;
  19321. }
  19322. }
  19323. function classPropMayCauseASIProblems(path) {
  19324. var node = path.getNode();
  19325. if (node.type !== "ClassProperty") {
  19326. return false;
  19327. }
  19328. var name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
  19329. // so isn't properly tested yet.
  19330. if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
  19331. return true;
  19332. }
  19333. }
  19334. function classChildNeedsASIProtection(node) {
  19335. if (!node) {
  19336. return;
  19337. }
  19338. if (node.static || node.accessibility // TypeScript
  19339. ) {
  19340. return false;
  19341. }
  19342. if (!node.computed) {
  19343. var name = node.key && node.key.name;
  19344. if (name === "in" || name === "instanceof") {
  19345. return true;
  19346. }
  19347. }
  19348. switch (node.type) {
  19349. case "ClassProperty":
  19350. case "TSAbstractClassProperty":
  19351. return node.computed;
  19352. case "MethodDefinition": // Flow
  19353. case "TSAbstractMethodDefinition": // TypeScript
  19354. case "ClassMethod":
  19355. case "ClassPrivateMethod":
  19356. {
  19357. // Babel
  19358. var isAsync = node.value ? node.value.async : node.async;
  19359. var isGenerator = node.value ? node.value.generator : node.generator;
  19360. if (isAsync || node.kind === "get" || node.kind === "set") {
  19361. return false;
  19362. }
  19363. if (node.computed || isGenerator) {
  19364. return true;
  19365. }
  19366. return false;
  19367. }
  19368. case "TSIndexSignature":
  19369. return true;
  19370. default:
  19371. /* istanbul ignore next */
  19372. return false;
  19373. }
  19374. }
  19375. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  19376. if (tokenNode === "+") {
  19377. return "+" + keyword;
  19378. } else if (tokenNode === "-") {
  19379. return "-" + keyword;
  19380. }
  19381. return keyword;
  19382. }
  19383. function hasNewlineBetweenOrAfterDecorators(node, options) {
  19384. return hasNewlineInRange$1(options.originalText, options.locStart(node.decorators[0]), options.locEnd(getLast$1(node.decorators))) || hasNewline$3(options.originalText, options.locEnd(getLast$1(node.decorators)));
  19385. } // Only space, newline, carriage return, and tab are treated as whitespace
  19386. // inside JSX.
  19387. var jsxWhitespaceChars = " \n\r\t";
  19388. var matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)");
  19389. var containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]"); // Meaningful if it contains non-whitespace characters,
  19390. // or it contains whitespace without a new line.
  19391. function isMeaningfulJSXText(node) {
  19392. return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
  19393. }
  19394. function hasJsxIgnoreComment(path) {
  19395. var node = path.getValue();
  19396. var parent = path.getParentNode();
  19397. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  19398. return false;
  19399. } // Lookup the previous sibling, ignoring any empty JSXText elements
  19400. var index = parent.children.indexOf(node);
  19401. var prevSibling = null;
  19402. for (var i = index; i > 0; i--) {
  19403. var candidate = parent.children[i - 1];
  19404. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  19405. continue;
  19406. }
  19407. prevSibling = candidate;
  19408. break;
  19409. }
  19410. return prevSibling && prevSibling.type === "JSXExpressionContainer" && prevSibling.expression.type === "JSXEmptyExpression" && prevSibling.expression.comments && prevSibling.expression.comments.find(function (comment) {
  19411. return comment.value.trim() === "prettier-ignore";
  19412. });
  19413. }
  19414. function isEmptyJSXElement(node) {
  19415. if (node.children.length === 0) {
  19416. return true;
  19417. }
  19418. if (node.children.length > 1) {
  19419. return false;
  19420. } // if there is one text child and does not contain any meaningful text
  19421. // we can treat the element as empty.
  19422. var child = node.children[0];
  19423. return isLiteral(child) && !isMeaningfulJSXText(child);
  19424. }
  19425. function hasPrettierIgnore$2(path) {
  19426. return hasIgnoreComment$3(path) || hasJsxIgnoreComment(path);
  19427. }
  19428. function isLastStatement(path) {
  19429. var parent = path.getParentNode();
  19430. if (!parent) {
  19431. return true;
  19432. }
  19433. var node = path.getValue();
  19434. var body = (parent.body || parent.consequent).filter(function (stmt) {
  19435. return stmt.type !== "EmptyStatement";
  19436. });
  19437. return body && body[body.length - 1] === node;
  19438. }
  19439. function isFlowAnnotationComment(text, typeAnnotation, options) {
  19440. var start = options.locStart(typeAnnotation);
  19441. var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
  19442. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  19443. }
  19444. function hasLeadingOwnLineComment(text, node, options) {
  19445. if (isJSXNode(node)) {
  19446. return hasNodeIgnoreComment$1(node);
  19447. }
  19448. var res = node.comments && node.comments.some(function (comment) {
  19449. return comment.leading && hasNewline$3(text, options.locEnd(comment));
  19450. });
  19451. return res;
  19452. } // This recurses the return argument, looking for the first token
  19453. // (the leftmost leaf node) and, if it (or its parents) has any
  19454. // leadingComments, returns true (so it can be wrapped in parens).
  19455. function returnArgumentHasLeadingComment(options, argument) {
  19456. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  19457. return true;
  19458. }
  19459. if (hasNakedLeftSide(argument)) {
  19460. var leftMost = argument;
  19461. var newLeftMost;
  19462. while (newLeftMost = getLeftSide(leftMost)) {
  19463. leftMost = newLeftMost;
  19464. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  19465. return true;
  19466. }
  19467. }
  19468. }
  19469. return false;
  19470. }
  19471. function isStringPropSafeToCoerceToIdentifier(node, options) {
  19472. return isStringLiteral(node.key) && isIdentifierName(node.key.value) && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty");
  19473. }
  19474. function isJestEachTemplateLiteral(node, parentNode) {
  19475. /**
  19476. * describe.each`table`(name, fn)
  19477. * describe.only.each`table`(name, fn)
  19478. * describe.skip.each`table`(name, fn)
  19479. * test.each`table`(name, fn)
  19480. * test.only.each`table`(name, fn)
  19481. * test.skip.each`table`(name, fn)
  19482. *
  19483. * Ref: https://github.com/facebook/jest/pull/6102
  19484. */
  19485. var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
  19486. return parentNode.type === "TaggedTemplateExpression" && parentNode.quasi === node && parentNode.tag.type === "MemberExpression" && parentNode.tag.property.type === "Identifier" && parentNode.tag.property.name === "each" && (parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.name) || parentNode.tag.object.type === "MemberExpression" && parentNode.tag.object.property.type === "Identifier" && (parentNode.tag.object.property.name === "only" || parentNode.tag.object.property.name === "skip") && parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.object.name));
  19487. }
  19488. function templateLiteralHasNewLines(template) {
  19489. return template.quasis.some(function (quasi) {
  19490. return quasi.value.raw.includes("\n");
  19491. });
  19492. }
  19493. function isTemplateOnItsOwnLine(n, text, options) {
  19494. return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$3(text, options.locStart(n), {
  19495. backwards: true
  19496. });
  19497. }
  19498. function needsHardlineAfterDanglingComment(node) {
  19499. if (!node.comments) {
  19500. return false;
  19501. }
  19502. var lastDanglingComment = getLast$1(node.comments.filter(function (comment) {
  19503. return !comment.leading && !comment.trailing;
  19504. }));
  19505. return lastDanglingComment && !comments$1.isBlockComment(lastDanglingComment);
  19506. } // If we have nested conditional expressions, we want to print them in JSX mode
  19507. // if there's at least one JSXElement somewhere in the tree.
  19508. //
  19509. // A conditional expression chain like this should be printed in normal mode,
  19510. // because there aren't JSXElements anywhere in it:
  19511. //
  19512. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  19513. //
  19514. // But a conditional expression chain like this should be printed in JSX mode,
  19515. // because there is a JSXElement in the last ConditionalExpression:
  19516. //
  19517. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  19518. //
  19519. // This type of ConditionalExpression chain is structured like this in the AST:
  19520. //
  19521. // ConditionalExpression {
  19522. // test: ...,
  19523. // consequent: ...,
  19524. // alternate: ConditionalExpression {
  19525. // test: ...,
  19526. // consequent: ...,
  19527. // alternate: ConditionalExpression {
  19528. // test: ...,
  19529. // consequent: ...,
  19530. // alternate: ...,
  19531. // }
  19532. // }
  19533. // }
  19534. //
  19535. // We want to traverse over that shape and convert it into a flat structure so
  19536. // that we can find if there's a JSXElement somewhere inside.
  19537. function getConditionalChainContents(node) {
  19538. // Given this code:
  19539. //
  19540. // // Using a ConditionalExpression as the consequent is uncommon, but should
  19541. // // be handled.
  19542. // A ? B : C ? D : E ? F ? G : H : I
  19543. //
  19544. // which has this AST:
  19545. //
  19546. // ConditionalExpression {
  19547. // test: Identifier(A),
  19548. // consequent: Identifier(B),
  19549. // alternate: ConditionalExpression {
  19550. // test: Identifier(C),
  19551. // consequent: Identifier(D),
  19552. // alternate: ConditionalExpression {
  19553. // test: Identifier(E),
  19554. // consequent: ConditionalExpression {
  19555. // test: Identifier(F),
  19556. // consequent: Identifier(G),
  19557. // alternate: Identifier(H),
  19558. // },
  19559. // alternate: Identifier(I),
  19560. // }
  19561. // }
  19562. // }
  19563. //
  19564. // we should return this Array:
  19565. //
  19566. // [
  19567. // Identifier(A),
  19568. // Identifier(B),
  19569. // Identifier(C),
  19570. // Identifier(D),
  19571. // Identifier(E),
  19572. // Identifier(F),
  19573. // Identifier(G),
  19574. // Identifier(H),
  19575. // Identifier(I)
  19576. // ];
  19577. //
  19578. // This loses the information about whether each node was the test,
  19579. // consequent, or alternate, but we don't care about that here- we are only
  19580. // flattening this structure to find if there's any JSXElements inside.
  19581. var nonConditionalExpressions = [];
  19582. function recurse(node) {
  19583. if (node.type === "ConditionalExpression") {
  19584. recurse(node.test);
  19585. recurse(node.consequent);
  19586. recurse(node.alternate);
  19587. } else {
  19588. nonConditionalExpressions.push(node);
  19589. }
  19590. }
  19591. recurse(node);
  19592. return nonConditionalExpressions;
  19593. }
  19594. function conditionalExpressionChainContainsJSX(node) {
  19595. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  19596. } // Logic to check for args with multiple anonymous functions. For instance,
  19597. // the following call should be split on multiple lines for readability:
  19598. // source.pipe(map((x) => x + x), filter((x) => x % 2 === 0))
  19599. function isFunctionCompositionArgs(args) {
  19600. if (args.length <= 1) {
  19601. return false;
  19602. }
  19603. var count = 0;
  19604. var _iteratorNormalCompletion = true;
  19605. var _didIteratorError = false;
  19606. var _iteratorError = undefined;
  19607. try {
  19608. for (var _iterator = args[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  19609. var arg = _step.value;
  19610. if (isFunctionOrArrowExpression(arg)) {
  19611. count += 1;
  19612. if (count > 1) {
  19613. return true;
  19614. }
  19615. } else if (isCallOrOptionalCallExpression(arg)) {
  19616. var _iteratorNormalCompletion2 = true;
  19617. var _didIteratorError2 = false;
  19618. var _iteratorError2 = undefined;
  19619. try {
  19620. for (var _iterator2 = arg.arguments[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  19621. var childArg = _step2.value;
  19622. if (isFunctionOrArrowExpression(childArg)) {
  19623. return true;
  19624. }
  19625. }
  19626. } catch (err) {
  19627. _didIteratorError2 = true;
  19628. _iteratorError2 = err;
  19629. } finally {
  19630. try {
  19631. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  19632. _iterator2.return();
  19633. }
  19634. } finally {
  19635. if (_didIteratorError2) {
  19636. throw _iteratorError2;
  19637. }
  19638. }
  19639. }
  19640. }
  19641. }
  19642. } catch (err) {
  19643. _didIteratorError = true;
  19644. _iteratorError = err;
  19645. } finally {
  19646. try {
  19647. if (!_iteratorNormalCompletion && _iterator.return != null) {
  19648. _iterator.return();
  19649. }
  19650. } finally {
  19651. if (_didIteratorError) {
  19652. throw _iteratorError;
  19653. }
  19654. }
  19655. }
  19656. return false;
  19657. } // Logic to determine if a call is a “long curried function call”.
  19658. // See https://github.com/prettier/prettier/issues/1420.
  19659. //
  19660. // `connect(a, b, c)(d)`
  19661. // In the above call expression, the second call is the parent node and the
  19662. // first call is the current node.
  19663. function isLongCurriedCallExpression(path) {
  19664. var node = path.getValue();
  19665. var parent = path.getParentNode();
  19666. return isCallOrOptionalCallExpression(node) && isCallOrOptionalCallExpression(parent) && parent.callee === node && node.arguments.length > parent.arguments.length && parent.arguments.length > 0;
  19667. }
  19668. function rawText(node) {
  19669. return node.extra ? node.extra.raw : node.raw;
  19670. }
  19671. function identity$1(x) {
  19672. return x;
  19673. }
  19674. function isTSXFile(options) {
  19675. return options.filepath && /\.tsx$/i.test(options.filepath);
  19676. }
  19677. var utils$4 = {
  19678. classChildNeedsASIProtection: classChildNeedsASIProtection,
  19679. classPropMayCauseASIProblems: classPropMayCauseASIProblems,
  19680. conditionalExpressionChainContainsJSX: conditionalExpressionChainContainsJSX,
  19681. getFlowVariance: getFlowVariance,
  19682. getLeftSidePathName: getLeftSidePathName,
  19683. getTypeScriptMappedTypeModifier: getTypeScriptMappedTypeModifier,
  19684. hasDanglingComments: hasDanglingComments,
  19685. hasFlowAnnotationComment: hasFlowAnnotationComment,
  19686. hasFlowShorthandAnnotationComment: hasFlowShorthandAnnotationComment,
  19687. hasLeadingComment: hasLeadingComment$2,
  19688. hasLeadingOwnLineComment: hasLeadingOwnLineComment,
  19689. hasNakedLeftSide: hasNakedLeftSide,
  19690. hasNewlineBetweenOrAfterDecorators: hasNewlineBetweenOrAfterDecorators,
  19691. hasNgSideEffect: hasNgSideEffect,
  19692. hasNode: hasNode,
  19693. hasPrettierIgnore: hasPrettierIgnore$2,
  19694. hasTrailingComment: hasTrailingComment,
  19695. identity: identity$1,
  19696. isBinaryish: isBinaryish,
  19697. isCallOrOptionalCallExpression: isCallOrOptionalCallExpression,
  19698. isEmptyJSXElement: isEmptyJSXElement,
  19699. isFlowAnnotationComment: isFlowAnnotationComment,
  19700. isFunctionCompositionArgs: isFunctionCompositionArgs,
  19701. isFunctionNotation: isFunctionNotation,
  19702. isFunctionOrArrowExpression: isFunctionOrArrowExpression,
  19703. isGetterOrSetter: isGetterOrSetter,
  19704. isJestEachTemplateLiteral: isJestEachTemplateLiteral,
  19705. isJSXNode: isJSXNode,
  19706. isJSXWhitespaceExpression: isJSXWhitespaceExpression,
  19707. isLastStatement: isLastStatement,
  19708. isLiteral: isLiteral,
  19709. isLongCurriedCallExpression: isLongCurriedCallExpression,
  19710. isMeaningfulJSXText: isMeaningfulJSXText,
  19711. isMemberExpressionChain: isMemberExpressionChain,
  19712. isMemberish: isMemberish,
  19713. isNgForOf: isNgForOf,
  19714. isNumericLiteral: isNumericLiteral,
  19715. isObjectType: isObjectType,
  19716. isObjectTypePropertyAFunction: isObjectTypePropertyAFunction,
  19717. isSimpleFlowType: isSimpleFlowType,
  19718. isSimpleTemplateLiteral: isSimpleTemplateLiteral,
  19719. isStringLiteral: isStringLiteral,
  19720. isStringPropSafeToCoerceToIdentifier: isStringPropSafeToCoerceToIdentifier,
  19721. isTemplateOnItsOwnLine: isTemplateOnItsOwnLine,
  19722. isTestCall: isTestCall,
  19723. isTheOnlyJSXElementInMarkdown: isTheOnlyJSXElementInMarkdown,
  19724. isTSXFile: isTSXFile,
  19725. isTypeAnnotationAFunction: isTypeAnnotationAFunction,
  19726. matchJsxWhitespaceRegex: matchJsxWhitespaceRegex,
  19727. needsHardlineAfterDanglingComment: needsHardlineAfterDanglingComment,
  19728. rawText: rawText,
  19729. returnArgumentHasLeadingComment: returnArgumentHasLeadingComment
  19730. };
  19731. var getLeftSidePathName$1 = utils$4.getLeftSidePathName,
  19732. hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment,
  19733. hasNakedLeftSide$1 = utils$4.hasNakedLeftSide,
  19734. hasNode$1 = utils$4.hasNode;
  19735. function hasClosureCompilerTypeCastComment(text, path) {
  19736. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  19737. // Syntax example: var x = /** @type {string} */ (fruit);
  19738. var n = path.getValue();
  19739. return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
  19740. function hasAncestorTypeCastComment(index) {
  19741. var ancestor = path.getParentNode(index);
  19742. return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
  19743. }
  19744. function hasTypeCastComment(node) {
  19745. return node.comments && node.comments.some(function (comment) {
  19746. return comment.leading && comments$1.isBlockComment(comment) && isTypeCastComment(comment.value);
  19747. });
  19748. }
  19749. function isParenthesized(node) {
  19750. // Closure typecast comments only really make sense when _not_ using
  19751. // typescript or flow parsers, so we take advantage of the babel parser's
  19752. // parenthesized expressions.
  19753. return node.extra && node.extra.parenthesized;
  19754. }
  19755. function isTypeCastComment(comment) {
  19756. var cleaned = comment.trim().split("\n").map(function (line) {
  19757. return line.replace(/^[\s*]+/, "");
  19758. }).join(" ").trim();
  19759. if (!/^@type\s*\{[^]+\}$/.test(cleaned)) {
  19760. return false;
  19761. }
  19762. var isCompletelyClosed = false;
  19763. var unpairedBracketCount = 0;
  19764. var _iteratorNormalCompletion = true;
  19765. var _didIteratorError = false;
  19766. var _iteratorError = undefined;
  19767. try {
  19768. for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  19769. var char = _step.value;
  19770. if (char === "{") {
  19771. if (isCompletelyClosed) {
  19772. return false;
  19773. }
  19774. unpairedBracketCount++;
  19775. } else if (char === "}") {
  19776. if (unpairedBracketCount === 0) {
  19777. return false;
  19778. }
  19779. unpairedBracketCount--;
  19780. if (unpairedBracketCount === 0) {
  19781. isCompletelyClosed = true;
  19782. }
  19783. }
  19784. }
  19785. } catch (err) {
  19786. _didIteratorError = true;
  19787. _iteratorError = err;
  19788. } finally {
  19789. try {
  19790. if (!_iteratorNormalCompletion && _iterator.return != null) {
  19791. _iterator.return();
  19792. }
  19793. } finally {
  19794. if (_didIteratorError) {
  19795. throw _iteratorError;
  19796. }
  19797. }
  19798. }
  19799. return unpairedBracketCount === 0;
  19800. }
  19801. }
  19802. function needsParens(path, options) {
  19803. var parent = path.getParentNode();
  19804. if (!parent) {
  19805. return false;
  19806. }
  19807. var name = path.getName();
  19808. var node = path.getNode(); // If the value of this path is some child of a Node and not a Node
  19809. // itself, then it doesn't need parentheses. Only Node objects (in
  19810. // fact, only Expression nodes) need parentheses.
  19811. if (path.getValue() !== node) {
  19812. return false;
  19813. } // to avoid unexpected `}}` in HTML interpolations
  19814. if (options.__isInHtmlInterpolation && !options.bracketSpacing && endsWithRightBracket(node) && isFollowedByRightBracket(path)) {
  19815. return true;
  19816. } // Only statements don't need parentheses.
  19817. if (isStatement(node)) {
  19818. return false;
  19819. } // Closure compiler requires that type casted expressions to be surrounded by
  19820. // parentheses.
  19821. if (hasClosureCompilerTypeCastComment(options.originalText, path)) {
  19822. return true;
  19823. }
  19824. if ( // Preserve parens if we have a Flow annotation comment, unless we're using the Flow
  19825. // parser. The Flow parser turns Flow comments into type annotation nodes in its
  19826. // AST, which we handle separately.
  19827. options.parser !== "flow" && hasFlowShorthandAnnotationComment$1(path.getValue())) {
  19828. return true;
  19829. } // Identifiers never need parentheses.
  19830. if (node.type === "Identifier") {
  19831. // ...unless those identifiers are embed placeholders. They might be substituted by complex
  19832. // expressions, so the parens around them should not be dropped. Example (JS-in-HTML-in-JS):
  19833. // let tpl = html`<script> f((${expr}) / 2); </script>`;
  19834. // If the inner JS formatter removes the parens, the expression might change its meaning:
  19835. // f((a + b) / 2) vs f(a + b / 2)
  19836. if (node.extra && node.extra.parenthesized && /^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(node.name)) {
  19837. return true;
  19838. }
  19839. return false;
  19840. }
  19841. if (parent.type === "ParenthesizedExpression") {
  19842. return false;
  19843. } // Add parens around the extends clause of a class. It is needed for almost
  19844. // all expressions.
  19845. if ((parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node && (node.type === "ArrowFunctionExpression" || node.type === "AssignmentExpression" || node.type === "AwaitExpression" || node.type === "BinaryExpression" || node.type === "ConditionalExpression" || node.type === "LogicalExpression" || node.type === "NewExpression" || node.type === "ObjectExpression" || node.type === "ParenthesizedExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "UnaryExpression" || node.type === "UpdateExpression" || node.type === "YieldExpression")) {
  19846. return true;
  19847. } // `export default function` or `export default class` can't be followed by
  19848. // anything after. So an expression like `export default (function(){}).toString()`
  19849. // needs to be followed by a parentheses
  19850. if (parent.type === "ExportDefaultDeclaration") {
  19851. return shouldWrapFunctionForExportDefault(path, options);
  19852. }
  19853. if (parent.type === "Decorator" && parent.expression === node) {
  19854. var hasCallExpression = false;
  19855. var hasMemberExpression = false;
  19856. var current = node;
  19857. while (current) {
  19858. switch (current.type) {
  19859. case "MemberExpression":
  19860. hasMemberExpression = true;
  19861. current = current.object;
  19862. break;
  19863. case "CallExpression":
  19864. if (
  19865. /** @(x().y) */
  19866. hasMemberExpression ||
  19867. /** @(x().y()) */
  19868. hasCallExpression) {
  19869. return true;
  19870. }
  19871. hasCallExpression = true;
  19872. current = current.callee;
  19873. break;
  19874. case "Identifier":
  19875. return false;
  19876. default:
  19877. return true;
  19878. }
  19879. }
  19880. return true;
  19881. }
  19882. if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
  19883. util.startsWithNoLookaheadToken(node,
  19884. /* forbidFunctionClassAndDoExpr */
  19885. false) || parent.type === "ExpressionStatement" && util.startsWithNoLookaheadToken(node,
  19886. /* forbidFunctionClassAndDoExpr */
  19887. true)) {
  19888. return true;
  19889. }
  19890. switch (node.type) {
  19891. case "SpreadElement":
  19892. case "SpreadProperty":
  19893. return parent.type === "MemberExpression" && name === "object" && parent.object === node;
  19894. case "UpdateExpression":
  19895. if (parent.type === "UnaryExpression") {
  19896. return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-");
  19897. }
  19898. // else fallthrough
  19899. case "UnaryExpression":
  19900. switch (parent.type) {
  19901. case "UnaryExpression":
  19902. return node.operator === parent.operator && (node.operator === "+" || node.operator === "-");
  19903. case "BindExpression":
  19904. return true;
  19905. case "MemberExpression":
  19906. case "OptionalMemberExpression":
  19907. return name === "object";
  19908. case "TaggedTemplateExpression":
  19909. return true;
  19910. case "NewExpression":
  19911. case "CallExpression":
  19912. case "OptionalCallExpression":
  19913. return name === "callee";
  19914. case "BinaryExpression":
  19915. return parent.operator === "**" && name === "left";
  19916. case "TSNonNullExpression":
  19917. return true;
  19918. default:
  19919. return false;
  19920. }
  19921. case "BinaryExpression":
  19922. {
  19923. if (parent.type === "UpdateExpression") {
  19924. return true;
  19925. }
  19926. var isLeftOfAForStatement = function isLeftOfAForStatement(node) {
  19927. var i = 0;
  19928. while (node) {
  19929. var _parent = path.getParentNode(i++);
  19930. if (!_parent) {
  19931. return false;
  19932. }
  19933. if (_parent.type === "ForStatement" && _parent.init === node) {
  19934. return true;
  19935. }
  19936. node = _parent;
  19937. }
  19938. return false;
  19939. };
  19940. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  19941. return true;
  19942. }
  19943. }
  19944. // fallthrough
  19945. case "TSTypeAssertion":
  19946. case "TSAsExpression":
  19947. case "LogicalExpression":
  19948. switch (parent.type) {
  19949. case "ConditionalExpression":
  19950. return node.type === "TSAsExpression";
  19951. case "CallExpression":
  19952. case "NewExpression":
  19953. case "OptionalCallExpression":
  19954. return name === "callee";
  19955. case "ClassExpression":
  19956. case "ClassDeclaration":
  19957. return name === "superClass" && parent.superClass === node;
  19958. case "TSTypeAssertion":
  19959. case "TaggedTemplateExpression":
  19960. case "UnaryExpression":
  19961. case "JSXSpreadAttribute":
  19962. case "SpreadElement":
  19963. case "SpreadProperty":
  19964. case "BindExpression":
  19965. case "AwaitExpression":
  19966. case "TSAsExpression":
  19967. case "TSNonNullExpression":
  19968. case "UpdateExpression":
  19969. return true;
  19970. case "MemberExpression":
  19971. case "OptionalMemberExpression":
  19972. return name === "object";
  19973. case "AssignmentExpression":
  19974. return parent.left === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression");
  19975. case "LogicalExpression":
  19976. if (node.type === "LogicalExpression") {
  19977. return parent.operator !== node.operator;
  19978. }
  19979. // else fallthrough
  19980. case "BinaryExpression":
  19981. {
  19982. if (!node.operator && node.type !== "TSTypeAssertion") {
  19983. return true;
  19984. }
  19985. var po = parent.operator;
  19986. var pp = util.getPrecedence(po);
  19987. var no = node.operator;
  19988. var np = util.getPrecedence(no);
  19989. if (pp > np) {
  19990. return true;
  19991. }
  19992. if (pp === np && name === "right") {
  19993. assert.strictEqual(parent.right, node);
  19994. return true;
  19995. }
  19996. if (pp === np && !util.shouldFlatten(po, no)) {
  19997. return true;
  19998. }
  19999. if (pp < np && no === "%") {
  20000. return po === "+" || po === "-";
  20001. } // Add parenthesis when working with bitwise operators
  20002. // It's not strictly needed but helps with code understanding
  20003. if (util.isBitwiseOperator(po)) {
  20004. return true;
  20005. }
  20006. return false;
  20007. }
  20008. default:
  20009. return false;
  20010. }
  20011. case "SequenceExpression":
  20012. switch (parent.type) {
  20013. case "ReturnStatement":
  20014. return false;
  20015. case "ForStatement":
  20016. // Although parentheses wouldn't hurt around sequence
  20017. // expressions in the head of for loops, traditional style
  20018. // dictates that e.g. i++, j++ should not be wrapped with
  20019. // parentheses.
  20020. return false;
  20021. case "ExpressionStatement":
  20022. return name !== "expression";
  20023. case "ArrowFunctionExpression":
  20024. // We do need parentheses, but SequenceExpressions are handled
  20025. // specially when printing bodies of arrow functions.
  20026. return name !== "body";
  20027. default:
  20028. // Otherwise err on the side of overparenthesization, adding
  20029. // explicit exceptions above if this proves overzealous.
  20030. return true;
  20031. }
  20032. case "YieldExpression":
  20033. if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") {
  20034. return true;
  20035. }
  20036. // else fallthrough
  20037. case "AwaitExpression":
  20038. switch (parent.type) {
  20039. case "TaggedTemplateExpression":
  20040. case "UnaryExpression":
  20041. case "BinaryExpression":
  20042. case "LogicalExpression":
  20043. case "SpreadElement":
  20044. case "SpreadProperty":
  20045. case "TSAsExpression":
  20046. case "TSNonNullExpression":
  20047. case "BindExpression":
  20048. return true;
  20049. case "MemberExpression":
  20050. case "OptionalMemberExpression":
  20051. return name === "object";
  20052. case "NewExpression":
  20053. case "CallExpression":
  20054. case "OptionalCallExpression":
  20055. return name === "callee";
  20056. case "ConditionalExpression":
  20057. return parent.test === node;
  20058. default:
  20059. return false;
  20060. }
  20061. case "TSConditionalType":
  20062. if (parent.type === "TSConditionalType" && node === parent.extendsType) {
  20063. return true;
  20064. }
  20065. // fallthrough
  20066. case "TSFunctionType":
  20067. case "TSConstructorType":
  20068. if (parent.type === "TSConditionalType" && node === parent.checkType) {
  20069. return true;
  20070. }
  20071. // fallthrough
  20072. case "TSUnionType":
  20073. case "TSIntersectionType":
  20074. if (parent.type === "TSUnionType" || parent.type === "TSIntersectionType") {
  20075. return true;
  20076. }
  20077. // fallthrough
  20078. case "TSTypeOperator":
  20079. case "TSInferType":
  20080. return parent.type === "TSArrayType" || parent.type === "TSOptionalType" || parent.type === "TSRestType" || parent.type === "TSIndexedAccessType" && node === parent.objectType || parent.type === "TSTypeOperator";
  20081. case "ArrayTypeAnnotation":
  20082. return parent.type === "NullableTypeAnnotation";
  20083. case "IntersectionTypeAnnotation":
  20084. case "UnionTypeAnnotation":
  20085. return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation";
  20086. case "NullableTypeAnnotation":
  20087. return parent.type === "ArrayTypeAnnotation";
  20088. case "FunctionTypeAnnotation":
  20089. {
  20090. var ancestor = parent.type === "NullableTypeAnnotation" ? path.getParentNode(1) : parent;
  20091. return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses
  20092. // are really needed, but since ??T doesn't make sense this check
  20093. // will almost never be true.
  20094. ancestor.type === "NullableTypeAnnotation";
  20095. }
  20096. case "StringLiteral":
  20097. case "NumericLiteral":
  20098. case "Literal":
  20099. if (typeof node.value === "string" && parent.type === "ExpressionStatement" && ( // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  20100. // See corresponding workaround in printer.js case: "Literal"
  20101. options.parser !== "typescript" && !parent.directive || options.parser === "typescript" && options.originalText.substr(options.locStart(node) - 1, 1) === "(")) {
  20102. // To avoid becoming a directive
  20103. var grandParent = path.getParentNode(1);
  20104. return grandParent.type === "Program" || grandParent.type === "BlockStatement";
  20105. }
  20106. return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node;
  20107. case "AssignmentExpression":
  20108. {
  20109. var _grandParent = path.getParentNode(1);
  20110. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  20111. return true;
  20112. } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) {
  20113. return false;
  20114. } else if (parent.type === "TSPropertySignature" && parent.name === node) {
  20115. return false;
  20116. } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) {
  20117. return false;
  20118. } else if (parent.type === "ExpressionStatement") {
  20119. return node.left.type === "ObjectPattern";
  20120. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  20121. return false;
  20122. } else if (parent.type === "AssignmentExpression") {
  20123. return false;
  20124. } else if (parent.type === "SequenceExpression" && _grandParent && _grandParent.type === "ForStatement" && (_grandParent.init === parent || _grandParent.update === parent)) {
  20125. return false;
  20126. } else if (parent.type === "Property" && parent.value === node) {
  20127. return false;
  20128. } else if (parent.type === "NGChainedExpression") {
  20129. return false;
  20130. }
  20131. return true;
  20132. }
  20133. case "ConditionalExpression":
  20134. switch (parent.type) {
  20135. case "TaggedTemplateExpression":
  20136. case "UnaryExpression":
  20137. case "SpreadElement":
  20138. case "SpreadProperty":
  20139. case "BinaryExpression":
  20140. case "LogicalExpression":
  20141. case "NGPipeExpression":
  20142. case "ExportDefaultDeclaration":
  20143. case "AwaitExpression":
  20144. case "JSXSpreadAttribute":
  20145. case "TSTypeAssertion":
  20146. case "TypeCastExpression":
  20147. case "TSAsExpression":
  20148. case "TSNonNullExpression":
  20149. return true;
  20150. case "NewExpression":
  20151. case "CallExpression":
  20152. case "OptionalCallExpression":
  20153. return name === "callee";
  20154. case "ConditionalExpression":
  20155. return name === "test" && parent.test === node;
  20156. case "MemberExpression":
  20157. case "OptionalMemberExpression":
  20158. return name === "object";
  20159. default:
  20160. return false;
  20161. }
  20162. case "FunctionExpression":
  20163. switch (parent.type) {
  20164. case "NewExpression":
  20165. case "CallExpression":
  20166. case "OptionalCallExpression":
  20167. // Not always necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  20168. // Is necessary if it is `expression` of `ExpressionStatement`.
  20169. return name === "callee";
  20170. case "TaggedTemplateExpression":
  20171. return true;
  20172. // This is basically a kind of IIFE.
  20173. default:
  20174. return false;
  20175. }
  20176. case "ArrowFunctionExpression":
  20177. switch (parent.type) {
  20178. case "NewExpression":
  20179. case "CallExpression":
  20180. case "OptionalCallExpression":
  20181. return name === "callee";
  20182. case "MemberExpression":
  20183. case "OptionalMemberExpression":
  20184. return name === "object";
  20185. case "TSAsExpression":
  20186. case "BindExpression":
  20187. case "TaggedTemplateExpression":
  20188. case "UnaryExpression":
  20189. case "LogicalExpression":
  20190. case "BinaryExpression":
  20191. case "AwaitExpression":
  20192. case "TSTypeAssertion":
  20193. return true;
  20194. case "ConditionalExpression":
  20195. return name === "test";
  20196. default:
  20197. return false;
  20198. }
  20199. case "ClassExpression":
  20200. switch (parent.type) {
  20201. case "NewExpression":
  20202. return name === "callee" && parent.callee === node;
  20203. default:
  20204. return false;
  20205. }
  20206. case "OptionalMemberExpression":
  20207. case "OptionalCallExpression":
  20208. if ((parent.type === "MemberExpression" && name === "object" || parent.type === "CallExpression" && name === "callee") && // workaround for https://github.com/facebook/flow/issues/8159
  20209. !(options.parser === "flow" && parent.range[0] === node.range[0])) {
  20210. return true;
  20211. }
  20212. // fallthrough
  20213. case "CallExpression":
  20214. case "MemberExpression":
  20215. case "TaggedTemplateExpression":
  20216. case "TSNonNullExpression":
  20217. if ((parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee") {
  20218. var object = node;
  20219. while (object) {
  20220. switch (object.type) {
  20221. case "CallExpression":
  20222. case "OptionalCallExpression":
  20223. return true;
  20224. case "MemberExpression":
  20225. case "OptionalMemberExpression":
  20226. case "BindExpression":
  20227. object = object.object;
  20228. break;
  20229. // tagged templates are basically member expressions from a grammar perspective
  20230. // see https://tc39.github.io/ecma262/#prod-MemberExpression
  20231. case "TaggedTemplateExpression":
  20232. object = object.tag;
  20233. break;
  20234. case "TSNonNullExpression":
  20235. object = object.expression;
  20236. break;
  20237. default:
  20238. return false;
  20239. }
  20240. }
  20241. }
  20242. return false;
  20243. case "BindExpression":
  20244. return (parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee" || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && name === "object";
  20245. case "NGPipeExpression":
  20246. if (parent.type === "NGRoot" || parent.type === "NGMicrosyntaxExpression" || parent.type === "ObjectProperty" || parent.type === "ArrayExpression" || (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && parent.arguments[name] === node || parent.type === "NGPipeExpression" && name === "right" || parent.type === "MemberExpression" && name === "property" || parent.type === "AssignmentExpression") {
  20247. return false;
  20248. }
  20249. return true;
  20250. case "JSXFragment":
  20251. case "JSXElement":
  20252. return name === "callee" || parent.type !== "ArrayExpression" && parent.type !== "ArrowFunctionExpression" && parent.type !== "AssignmentExpression" && parent.type !== "AssignmentPattern" && parent.type !== "BinaryExpression" && parent.type !== "CallExpression" && parent.type !== "ConditionalExpression" && parent.type !== "ExpressionStatement" && parent.type !== "JsExpressionRoot" && parent.type !== "JSXAttribute" && parent.type !== "JSXElement" && parent.type !== "JSXExpressionContainer" && parent.type !== "JSXFragment" && parent.type !== "LogicalExpression" && parent.type !== "ObjectProperty" && parent.type !== "OptionalCallExpression" && parent.type !== "Property" && parent.type !== "ReturnStatement" && parent.type !== "TypeCastExpression" && parent.type !== "VariableDeclarator";
  20253. case "TypeAnnotation":
  20254. return name === "returnType" && parent.type === "ArrowFunctionExpression" && includesFunctionTypeInObjectType(node);
  20255. }
  20256. return false;
  20257. }
  20258. function isStatement(node) {
  20259. return node.type === "BlockStatement" || node.type === "BreakStatement" || node.type === "ClassBody" || node.type === "ClassDeclaration" || node.type === "ClassMethod" || node.type === "ClassProperty" || node.type === "ClassPrivateProperty" || node.type === "ContinueStatement" || node.type === "DebuggerStatement" || node.type === "DeclareClass" || node.type === "DeclareExportAllDeclaration" || node.type === "DeclareExportDeclaration" || node.type === "DeclareFunction" || node.type === "DeclareInterface" || node.type === "DeclareModule" || node.type === "DeclareModuleExports" || node.type === "DeclareVariable" || node.type === "DoWhileStatement" || node.type === "EnumDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExpressionStatement" || node.type === "ForAwaitStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || node.type === "FunctionDeclaration" || node.type === "IfStatement" || node.type === "ImportDeclaration" || node.type === "InterfaceDeclaration" || node.type === "LabeledStatement" || node.type === "MethodDefinition" || node.type === "ReturnStatement" || node.type === "SwitchStatement" || node.type === "ThrowStatement" || node.type === "TryStatement" || node.type === "TSDeclareFunction" || node.type === "TSEnumDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSModuleDeclaration" || node.type === "TSNamespaceExportDeclaration" || node.type === "TypeAlias" || node.type === "VariableDeclaration" || node.type === "WhileStatement" || node.type === "WithStatement";
  20260. }
  20261. function includesFunctionTypeInObjectType(node) {
  20262. return hasNode$1(node, function (n1) {
  20263. return n1.type === "ObjectTypeAnnotation" && hasNode$1(n1, function (n2) {
  20264. return n2.type === "FunctionTypeAnnotation" || undefined;
  20265. }) || undefined;
  20266. });
  20267. }
  20268. function endsWithRightBracket(node) {
  20269. switch (node.type) {
  20270. case "ObjectExpression":
  20271. return true;
  20272. default:
  20273. return false;
  20274. }
  20275. }
  20276. function isFollowedByRightBracket(path) {
  20277. var node = path.getValue();
  20278. var parent = path.getParentNode();
  20279. var name = path.getName();
  20280. switch (parent.type) {
  20281. case "NGPipeExpression":
  20282. if (typeof name === "number" && parent.arguments[name] === node && parent.arguments.length - 1 === name) {
  20283. return path.callParent(isFollowedByRightBracket);
  20284. }
  20285. break;
  20286. case "ObjectProperty":
  20287. if (name === "value") {
  20288. var parentParent = path.getParentNode(1);
  20289. return parentParent.properties[parentParent.properties.length - 1] === parent;
  20290. }
  20291. break;
  20292. case "BinaryExpression":
  20293. case "LogicalExpression":
  20294. if (name === "right") {
  20295. return path.callParent(isFollowedByRightBracket);
  20296. }
  20297. break;
  20298. case "ConditionalExpression":
  20299. if (name === "alternate") {
  20300. return path.callParent(isFollowedByRightBracket);
  20301. }
  20302. break;
  20303. case "UnaryExpression":
  20304. if (parent.prefix) {
  20305. return path.callParent(isFollowedByRightBracket);
  20306. }
  20307. break;
  20308. }
  20309. return false;
  20310. }
  20311. function shouldWrapFunctionForExportDefault(path, options) {
  20312. var node = path.getValue();
  20313. var parent = path.getParentNode();
  20314. if (node.type === "FunctionExpression" || node.type === "ClassExpression") {
  20315. return parent.type === "ExportDefaultDeclaration" || // in some cases the function is already wrapped
  20316. // (e.g. `export default (function() {})();`)
  20317. // in this case we don't need to add extra parens
  20318. !needsParens(path, options);
  20319. }
  20320. if (!hasNakedLeftSide$1(node) || parent.type !== "ExportDefaultDeclaration" && needsParens(path, options)) {
  20321. return false;
  20322. }
  20323. return path.call.apply(path, [function (childPath) {
  20324. return shouldWrapFunctionForExportDefault(childPath, options);
  20325. }].concat(getLeftSidePathName$1(path, node)));
  20326. }
  20327. var needsParens_1 = needsParens;
  20328. var _require$$0$builders$6 = doc.builders,
  20329. concat$c = _require$$0$builders$6.concat,
  20330. join$8 = _require$$0$builders$6.join,
  20331. line$6 = _require$$0$builders$6.line;
  20332. function printHtmlBinding(path, options, print) {
  20333. var node = path.getValue();
  20334. if (options.__onHtmlBindingRoot && path.getName() === null) {
  20335. options.__onHtmlBindingRoot(node);
  20336. }
  20337. if (node.type !== "File") {
  20338. return;
  20339. }
  20340. if (options.__isVueForBindingLeft) {
  20341. return path.call(function (functionDeclarationPath) {
  20342. var _functionDeclarationP = functionDeclarationPath.getValue(),
  20343. params = _functionDeclarationP.params;
  20344. return concat$c([params.length > 1 ? "(" : "", join$8(concat$c([",", line$6]), functionDeclarationPath.map(print, "params")), params.length > 1 ? ")" : ""]);
  20345. }, "program", "body", 0);
  20346. }
  20347. if (options.__isVueSlotScope) {
  20348. return path.call(function (functionDeclarationPath) {
  20349. return join$8(concat$c([",", line$6]), functionDeclarationPath.map(print, "params"));
  20350. }, "program", "body", 0);
  20351. }
  20352. } // based on https://github.com/prettier/prettier/blob/master/src/language-html/syntax-vue.js isVueEventBindingExpression()
  20353. function isVueEventBindingExpression$2(node) {
  20354. switch (node.type) {
  20355. case "MemberExpression":
  20356. switch (node.property.type) {
  20357. case "Identifier":
  20358. case "NumericLiteral":
  20359. case "StringLiteral":
  20360. return isVueEventBindingExpression$2(node.object);
  20361. }
  20362. return false;
  20363. case "Identifier":
  20364. return true;
  20365. default:
  20366. return false;
  20367. }
  20368. }
  20369. var htmlBinding = {
  20370. isVueEventBindingExpression: isVueEventBindingExpression$2,
  20371. printHtmlBinding: printHtmlBinding
  20372. };
  20373. function preprocess$1(ast, options) {
  20374. switch (options.parser) {
  20375. case "json":
  20376. case "json5":
  20377. case "json-stringify":
  20378. case "__js_expression":
  20379. case "__vue_expression":
  20380. return Object.assign({}, ast, {
  20381. type: options.parser.startsWith("__") ? "JsExpressionRoot" : "JsonRoot",
  20382. node: ast,
  20383. comments: []
  20384. });
  20385. default:
  20386. return ast;
  20387. }
  20388. }
  20389. var preprocess_1$1 = preprocess$1;
  20390. var getParentExportDeclaration$1 = util.getParentExportDeclaration,
  20391. isExportDeclaration$1 = util.isExportDeclaration,
  20392. shouldFlatten$1 = util.shouldFlatten,
  20393. getNextNonSpaceNonCommentCharacter$1 = util.getNextNonSpaceNonCommentCharacter,
  20394. hasNewline$4 = util.hasNewline,
  20395. hasNewlineInRange$2 = util.hasNewlineInRange,
  20396. getLast$2 = util.getLast,
  20397. getStringWidth$2 = util.getStringWidth,
  20398. printString$2 = util.printString,
  20399. printNumber$2 = util.printNumber,
  20400. hasIgnoreComment$4 = util.hasIgnoreComment,
  20401. hasNodeIgnoreComment$2 = util.hasNodeIgnoreComment,
  20402. getPenultimate$1 = util.getPenultimate,
  20403. startsWithNoLookaheadToken$1 = util.startsWithNoLookaheadToken,
  20404. getIndentSize$1 = util.getIndentSize,
  20405. matchAncestorTypes$1 = util.matchAncestorTypes,
  20406. getPreferredQuote$1 = util.getPreferredQuote;
  20407. var isNextLineEmpty$4 = utilShared.isNextLineEmpty,
  20408. isNextLineEmptyAfterIndex$1 = utilShared.isNextLineEmptyAfterIndex,
  20409. getNextNonSpaceNonCommentCharacterIndex$2 = utilShared.getNextNonSpaceNonCommentCharacterIndex;
  20410. var insertPragma$7 = pragma.insertPragma;
  20411. var printHtmlBinding$1 = htmlBinding.printHtmlBinding,
  20412. isVueEventBindingExpression$3 = htmlBinding.isVueEventBindingExpression;
  20413. var classChildNeedsASIProtection$1 = utils$4.classChildNeedsASIProtection,
  20414. classPropMayCauseASIProblems$1 = utils$4.classPropMayCauseASIProblems,
  20415. conditionalExpressionChainContainsJSX$1 = utils$4.conditionalExpressionChainContainsJSX,
  20416. getFlowVariance$1 = utils$4.getFlowVariance,
  20417. getLeftSidePathName$2 = utils$4.getLeftSidePathName,
  20418. getTypeScriptMappedTypeModifier$1 = utils$4.getTypeScriptMappedTypeModifier,
  20419. hasDanglingComments$1 = utils$4.hasDanglingComments,
  20420. hasFlowAnnotationComment$1 = utils$4.hasFlowAnnotationComment,
  20421. hasFlowShorthandAnnotationComment$2 = utils$4.hasFlowShorthandAnnotationComment,
  20422. hasLeadingComment$3 = utils$4.hasLeadingComment,
  20423. hasLeadingOwnLineComment$1 = utils$4.hasLeadingOwnLineComment,
  20424. hasNakedLeftSide$2 = utils$4.hasNakedLeftSide,
  20425. hasNewlineBetweenOrAfterDecorators$1 = utils$4.hasNewlineBetweenOrAfterDecorators,
  20426. hasNgSideEffect$1 = utils$4.hasNgSideEffect,
  20427. hasPrettierIgnore$3 = utils$4.hasPrettierIgnore,
  20428. hasTrailingComment$1 = utils$4.hasTrailingComment,
  20429. identity$2 = utils$4.identity,
  20430. isBinaryish$1 = utils$4.isBinaryish,
  20431. isCallOrOptionalCallExpression$1 = utils$4.isCallOrOptionalCallExpression,
  20432. isEmptyJSXElement$1 = utils$4.isEmptyJSXElement,
  20433. isFlowAnnotationComment$1 = utils$4.isFlowAnnotationComment,
  20434. isFunctionCompositionArgs$1 = utils$4.isFunctionCompositionArgs,
  20435. isFunctionNotation$1 = utils$4.isFunctionNotation,
  20436. isFunctionOrArrowExpression$1 = utils$4.isFunctionOrArrowExpression,
  20437. isGetterOrSetter$1 = utils$4.isGetterOrSetter,
  20438. isJestEachTemplateLiteral$1 = utils$4.isJestEachTemplateLiteral,
  20439. isJSXNode$1 = utils$4.isJSXNode,
  20440. isJSXWhitespaceExpression$1 = utils$4.isJSXWhitespaceExpression,
  20441. isLastStatement$1 = utils$4.isLastStatement,
  20442. isLiteral$1 = utils$4.isLiteral,
  20443. isLongCurriedCallExpression$1 = utils$4.isLongCurriedCallExpression,
  20444. isMeaningfulJSXText$1 = utils$4.isMeaningfulJSXText,
  20445. isMemberExpressionChain$1 = utils$4.isMemberExpressionChain,
  20446. isMemberish$1 = utils$4.isMemberish,
  20447. isNgForOf$1 = utils$4.isNgForOf,
  20448. isNumericLiteral$1 = utils$4.isNumericLiteral,
  20449. isObjectType$1 = utils$4.isObjectType,
  20450. isObjectTypePropertyAFunction$1 = utils$4.isObjectTypePropertyAFunction,
  20451. isSimpleFlowType$1 = utils$4.isSimpleFlowType,
  20452. isSimpleTemplateLiteral$1 = utils$4.isSimpleTemplateLiteral,
  20453. isStringLiteral$1 = utils$4.isStringLiteral,
  20454. isStringPropSafeToCoerceToIdentifier$1 = utils$4.isStringPropSafeToCoerceToIdentifier,
  20455. isTemplateOnItsOwnLine$1 = utils$4.isTemplateOnItsOwnLine,
  20456. isTestCall$1 = utils$4.isTestCall,
  20457. isTheOnlyJSXElementInMarkdown$1 = utils$4.isTheOnlyJSXElementInMarkdown,
  20458. isTSXFile$1 = utils$4.isTSXFile,
  20459. isTypeAnnotationAFunction$1 = utils$4.isTypeAnnotationAFunction,
  20460. matchJsxWhitespaceRegex$1 = utils$4.matchJsxWhitespaceRegex,
  20461. needsHardlineAfterDanglingComment$1 = utils$4.needsHardlineAfterDanglingComment,
  20462. rawText$1 = utils$4.rawText,
  20463. returnArgumentHasLeadingComment$1 = utils$4.returnArgumentHasLeadingComment;
  20464. var needsQuoteProps = new WeakMap();
  20465. var _require$$5$builders = doc.builders,
  20466. concat$d = _require$$5$builders.concat,
  20467. join$9 = _require$$5$builders.join,
  20468. line$7 = _require$$5$builders.line,
  20469. hardline$9 = _require$$5$builders.hardline,
  20470. softline$6 = _require$$5$builders.softline,
  20471. literalline$4 = _require$$5$builders.literalline,
  20472. group$b = _require$$5$builders.group,
  20473. indent$7 = _require$$5$builders.indent,
  20474. align$1 = _require$$5$builders.align,
  20475. conditionalGroup$1 = _require$$5$builders.conditionalGroup,
  20476. fill$4 = _require$$5$builders.fill,
  20477. ifBreak$6 = _require$$5$builders.ifBreak,
  20478. breakParent$3 = _require$$5$builders.breakParent,
  20479. lineSuffixBoundary$1 = _require$$5$builders.lineSuffixBoundary,
  20480. addAlignmentToDoc$2 = _require$$5$builders.addAlignmentToDoc,
  20481. dedent$2 = _require$$5$builders.dedent,
  20482. _require$$5$utils = doc.utils,
  20483. willBreak$1 = _require$$5$utils.willBreak,
  20484. isLineNext$1 = _require$$5$utils.isLineNext,
  20485. isEmpty$1 = _require$$5$utils.isEmpty,
  20486. removeLines$2 = _require$$5$utils.removeLines,
  20487. printDocToString$1 = doc.printer.printDocToString;
  20488. var uid = 0;
  20489. function shouldPrintComma$1(options, level) {
  20490. level = level || "es5";
  20491. switch (options.trailingComma) {
  20492. case "all":
  20493. if (level === "all") {
  20494. return true;
  20495. }
  20496. // fallthrough
  20497. case "es5":
  20498. if (level === "es5") {
  20499. return true;
  20500. }
  20501. // fallthrough
  20502. case "none":
  20503. default:
  20504. return false;
  20505. }
  20506. }
  20507. function genericPrint$3(path, options, printPath, args) {
  20508. var node = path.getValue();
  20509. var needsParens = false;
  20510. var linesWithoutParens = printPathNoParens(path, options, printPath, args);
  20511. if (!node || isEmpty$1(linesWithoutParens)) {
  20512. return linesWithoutParens;
  20513. }
  20514. var parentExportDecl = getParentExportDeclaration$1(path);
  20515. var decorators = [];
  20516. if (node.type === "ClassMethod" || node.type === "ClassPrivateMethod" || node.type === "ClassProperty" || node.type === "TSAbstractClassProperty" || node.type === "ClassPrivateProperty" || node.type === "MethodDefinition" || node.type === "TSAbstractMethodDefinition") ; else if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration and the decorator
  20517. // was written before the export, the export will be responsible
  20518. // for printing the decorators.
  20519. !(parentExportDecl && options.locStart(parentExportDecl, {
  20520. ignoreDecorators: true
  20521. }) > options.locStart(node.decorators[0]))) {
  20522. var shouldBreak = node.type === "ClassExpression" || node.type === "ClassDeclaration" || hasNewlineBetweenOrAfterDecorators$1(node, options);
  20523. var separator = shouldBreak ? hardline$9 : line$7;
  20524. path.each(function (decoratorPath) {
  20525. var decorator = decoratorPath.getValue();
  20526. if (decorator.expression) {
  20527. decorator = decorator.expression;
  20528. } else {
  20529. decorator = decorator.callee;
  20530. }
  20531. decorators.push(printPath(decoratorPath), separator);
  20532. }, "decorators");
  20533. if (parentExportDecl) {
  20534. decorators.unshift(hardline$9);
  20535. }
  20536. } else if (isExportDeclaration$1(node) && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0 && // Only print decorators here if they were written before the export,
  20537. // otherwise they are printed by the node.declaration
  20538. options.locStart(node, {
  20539. ignoreDecorators: true
  20540. }) > options.locStart(node.declaration.decorators[0])) {
  20541. // Export declarations are responsible for printing any decorators
  20542. // that logically apply to node.declaration.
  20543. path.each(function (decoratorPath) {
  20544. var decorator = decoratorPath.getValue();
  20545. var prefix = decorator.type === "Decorator" ? "" : "@";
  20546. decorators.push(prefix, printPath(decoratorPath), hardline$9);
  20547. }, "declaration", "decorators");
  20548. } else {
  20549. // Nodes with decorators can't have parentheses, so we can avoid
  20550. // computing pathNeedsParens() except in this case.
  20551. needsParens = needsParens_1(path, options);
  20552. }
  20553. var parts = [];
  20554. if (needsParens) {
  20555. parts.unshift("(");
  20556. }
  20557. parts.push(linesWithoutParens);
  20558. if (needsParens) {
  20559. var _node = path.getValue();
  20560. if (hasFlowShorthandAnnotationComment$2(_node)) {
  20561. parts.push(" /*");
  20562. parts.push(_node.trailingComments[0].value.trimLeft());
  20563. parts.push("*/");
  20564. _node.trailingComments[0].printed = true;
  20565. }
  20566. parts.push(")");
  20567. }
  20568. if (decorators.length > 0) {
  20569. return group$b(concat$d(decorators.concat(parts)));
  20570. }
  20571. return concat$d(parts);
  20572. }
  20573. function printDecorators(path, options, print) {
  20574. var node = path.getValue();
  20575. return group$b(concat$d([join$9(line$7, path.map(print, "decorators")), hasNewlineBetweenOrAfterDecorators$1(node, options) ? hardline$9 : line$7]));
  20576. }
  20577. /**
  20578. * The following is the shared logic for
  20579. * ternary operators, namely ConditionalExpression
  20580. * and TSConditionalType
  20581. * @typedef {Object} OperatorOptions
  20582. * @property {() => Array<string | Doc>} beforeParts - Parts to print before the `?`.
  20583. * @property {(breakClosingParen: boolean) => Array<string | Doc>} afterParts - Parts to print after the conditional expression.
  20584. * @property {boolean} shouldCheckJsx - Whether to check for and print in JSX mode.
  20585. * @property {string} conditionalNodeType - The type of the conditional expression node, ie "ConditionalExpression" or "TSConditionalType".
  20586. * @property {string} consequentNodePropertyName - The property at which the consequent node can be found on the main node, eg "consequent".
  20587. * @property {string} alternateNodePropertyName - The property at which the alternate node can be found on the main node, eg "alternate".
  20588. * @property {string} testNodePropertyName - The property at which the test node can be found on the main node, eg "test".
  20589. * @property {boolean} breakNested - Whether to break all nested ternaries when one breaks.
  20590. * @param {FastPath} path - The path to the ConditionalExpression/TSConditionalType node.
  20591. * @param {Options} options - Prettier options
  20592. * @param {Function} print - Print function to call recursively
  20593. * @param {OperatorOptions} operatorOptions
  20594. * @returns Doc
  20595. */
  20596. function printTernaryOperator(path, options, print, operatorOptions) {
  20597. var node = path.getValue();
  20598. var testNode = node[operatorOptions.testNodePropertyName];
  20599. var consequentNode = node[operatorOptions.consequentNodePropertyName];
  20600. var alternateNode = node[operatorOptions.alternateNodePropertyName];
  20601. var parts = []; // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  20602. // See tests/jsx/conditional-expression.js for more info.
  20603. var jsxMode = false;
  20604. var parent = path.getParentNode();
  20605. var forceNoIndent = parent.type === operatorOptions.conditionalNodeType; // Find the outermost non-ConditionalExpression parent, and the outermost
  20606. // ConditionalExpression parent. We'll use these to determine if we should
  20607. // print in JSX mode.
  20608. var currentParent;
  20609. var previousParent;
  20610. var i = 0;
  20611. do {
  20612. previousParent = currentParent || node;
  20613. currentParent = path.getParentNode(i);
  20614. i++;
  20615. } while (currentParent && currentParent.type === operatorOptions.conditionalNodeType);
  20616. var firstNonConditionalParent = currentParent || parent;
  20617. var lastConditionalParent = previousParent;
  20618. if (operatorOptions.shouldCheckJsx && (isJSXNode$1(testNode) || isJSXNode$1(consequentNode) || isJSXNode$1(alternateNode) || conditionalExpressionChainContainsJSX$1(lastConditionalParent))) {
  20619. jsxMode = true;
  20620. forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in
  20621. // parens when using ?: within JSX, because the parens are analogous to
  20622. // curly braces in an if statement.
  20623. var wrap = function wrap(doc) {
  20624. return concat$d([ifBreak$6("(", ""), indent$7(concat$d([softline$6, doc])), softline$6, ifBreak$6(")", "")]);
  20625. }; // The only things we don't wrap are:
  20626. // * Nested conditional expressions in alternates
  20627. // * null
  20628. var isNull = function isNull(node) {
  20629. return node.type === "NullLiteral" || node.type === "Literal" && node.value === null;
  20630. };
  20631. parts.push(" ? ", isNull(consequentNode) ? path.call(print, operatorOptions.consequentNodePropertyName) : wrap(path.call(print, operatorOptions.consequentNodePropertyName)), " : ", alternateNode.type === operatorOptions.conditionalNodeType || isNull(alternateNode) ? path.call(print, operatorOptions.alternateNodePropertyName) : wrap(path.call(print, operatorOptions.alternateNodePropertyName)));
  20632. } else {
  20633. // normal mode
  20634. var part = concat$d([line$7, "? ", consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$6("", "(") : "", align$1(2, path.call(print, operatorOptions.consequentNodePropertyName)), consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$6("", ")") : "", line$7, ": ", alternateNode.type === operatorOptions.conditionalNodeType ? path.call(print, operatorOptions.alternateNodePropertyName) : align$1(2, path.call(print, operatorOptions.alternateNodePropertyName))]);
  20635. parts.push(parent.type !== operatorOptions.conditionalNodeType || parent[operatorOptions.alternateNodePropertyName] === node ? part : options.useTabs ? dedent$2(indent$7(part)) : align$1(Math.max(0, options.tabWidth - 2), part));
  20636. } // We want a whole chain of ConditionalExpressions to all
  20637. // break if any of them break. That means we should only group around the
  20638. // outer-most ConditionalExpression.
  20639. var maybeGroup = function maybeGroup(doc) {
  20640. return operatorOptions.breakNested ? parent === firstNonConditionalParent ? group$b(doc) : doc : group$b(doc);
  20641. }; // Break the closing paren to keep the chain right after it:
  20642. // (a
  20643. // ? b
  20644. // : c
  20645. // ).call()
  20646. var breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression" || parent.type === "NGPipeExpression" && parent.left === node && operatorOptions.breakNested) && !parent.computed;
  20647. return maybeGroup(concat$d([].concat(function (testDoc) {
  20648. return (
  20649. /**
  20650. * a
  20651. * ? b
  20652. * : multiline
  20653. * test
  20654. * node
  20655. * ^^ align(2)
  20656. * ? d
  20657. * : e
  20658. */
  20659. parent.type === operatorOptions.conditionalNodeType && parent[operatorOptions.alternateNodePropertyName] === node ? align$1(2, testDoc) : testDoc
  20660. );
  20661. }(concat$d(operatorOptions.beforeParts())), forceNoIndent ? concat$d(parts) : indent$7(concat$d(parts)), operatorOptions.afterParts(breakClosingParen))));
  20662. }
  20663. function printPathNoParens(path, options, print, args) {
  20664. var n = path.getValue();
  20665. var semi = options.semi ? ";" : "";
  20666. if (!n) {
  20667. return "";
  20668. }
  20669. if (typeof n === "string") {
  20670. return n;
  20671. }
  20672. var htmlBinding = printHtmlBinding$1(path, options, print);
  20673. if (htmlBinding) {
  20674. return htmlBinding;
  20675. }
  20676. var parts = [];
  20677. switch (n.type) {
  20678. case "JsExpressionRoot":
  20679. return path.call(print, "node");
  20680. case "JsonRoot":
  20681. return concat$d([path.call(print, "node"), hardline$9]);
  20682. case "File":
  20683. // Print @babel/parser's InterpreterDirective here so that
  20684. // leading comments on the `Program` node get printed after the hashbang.
  20685. if (n.program && n.program.interpreter) {
  20686. parts.push(path.call(function (programPath) {
  20687. return programPath.call(print, "interpreter");
  20688. }, "program"));
  20689. }
  20690. parts.push(path.call(print, "program"));
  20691. return concat$d(parts);
  20692. case "Program":
  20693. // Babel 6
  20694. if (n.directives) {
  20695. path.each(function (childPath) {
  20696. parts.push(print(childPath), semi, hardline$9);
  20697. if (isNextLineEmpty$4(options.originalText, childPath.getValue(), options)) {
  20698. parts.push(hardline$9);
  20699. }
  20700. }, "directives");
  20701. }
  20702. parts.push(path.call(function (bodyPath) {
  20703. return printStatementSequence(bodyPath, options, print);
  20704. }, "body"));
  20705. parts.push(comments.printDanglingComments(path, options,
  20706. /* sameIndent */
  20707. true)); // Only force a trailing newline if there were any contents.
  20708. if (n.body.length || n.comments) {
  20709. parts.push(hardline$9);
  20710. }
  20711. return concat$d(parts);
  20712. // Babel extension.
  20713. case "EmptyStatement":
  20714. return "";
  20715. case "ExpressionStatement":
  20716. // Detect Flow-parsed directives
  20717. if (n.directive) {
  20718. return concat$d([nodeStr(n.expression, options, true), semi]);
  20719. }
  20720. if (options.parser === "__vue_event_binding") {
  20721. var parent = path.getParentNode();
  20722. if (parent.type === "Program" && parent.body.length === 1 && parent.body[0] === n) {
  20723. return concat$d([path.call(print, "expression"), isVueEventBindingExpression$3(n.expression) ? ";" : ""]);
  20724. }
  20725. } // Do not append semicolon after the only JSX element in a program
  20726. return concat$d([path.call(print, "expression"), isTheOnlyJSXElementInMarkdown$1(options, path) ? "" : semi]);
  20727. // Babel extension.
  20728. case "ParenthesizedExpression":
  20729. return concat$d(["(", path.call(print, "expression"), ")"]);
  20730. case "AssignmentExpression":
  20731. return printAssignment(n.left, path.call(print, "left"), concat$d([" ", n.operator]), n.right, path.call(print, "right"), options);
  20732. case "BinaryExpression":
  20733. case "LogicalExpression":
  20734. case "NGPipeExpression":
  20735. {
  20736. var _parent = path.getParentNode();
  20737. var parentParent = path.getParentNode(1);
  20738. var isInsideParenthesis = n !== _parent.body && (_parent.type === "IfStatement" || _parent.type === "WhileStatement" || _parent.type === "SwitchStatement" || _parent.type === "DoWhileStatement");
  20739. var _parts = printBinaryishExpressions(path, print, options,
  20740. /* isNested */
  20741. false, isInsideParenthesis); // if (
  20742. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  20743. // ) {
  20744. //
  20745. // looks super weird, we want to break the children if the parent breaks
  20746. //
  20747. // if (
  20748. // this.hasPlugin("dynamicImports") &&
  20749. // this.lookahead().type === tt.parenLeft
  20750. // ) {
  20751. if (isInsideParenthesis) {
  20752. return concat$d(_parts);
  20753. } // Break between the parens in
  20754. // unaries or in a member or specific call expression, i.e.
  20755. //
  20756. // (
  20757. // a &&
  20758. // b &&
  20759. // c
  20760. // ).call()
  20761. if ((_parent.type === "CallExpression" || _parent.type === "OptionalCallExpression") && _parent.callee === n || _parent.type === "UnaryExpression" || (_parent.type === "MemberExpression" || _parent.type === "OptionalMemberExpression") && !_parent.computed) {
  20762. return group$b(concat$d([indent$7(concat$d([softline$6, concat$d(_parts)])), softline$6]));
  20763. } // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  20764. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  20765. var shouldNotIndent = _parent.type === "ReturnStatement" || _parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n.type !== "NGPipeExpression" && (_parent.type === "NGRoot" && options.parser === "__ng_binding" || _parent.type === "NGMicrosyntaxExpression" && parentParent.type === "NGMicrosyntax" && parentParent.body.length === 1) || n === _parent.body && _parent.type === "ArrowFunctionExpression" || n !== _parent.body && _parent.type === "ForStatement" || _parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement" && parentParent.type !== "CallExpression" && parentParent.type !== "OptionalCallExpression";
  20766. var shouldIndentIfInlining = _parent.type === "AssignmentExpression" || _parent.type === "VariableDeclarator" || _parent.type === "ClassProperty" || _parent.type === "TSAbstractClassProperty" || _parent.type === "ClassPrivateProperty" || _parent.type === "ObjectProperty" || _parent.type === "Property";
  20767. var samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(n.operator, n.left.operator);
  20768. if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
  20769. return group$b(concat$d(_parts));
  20770. }
  20771. if (_parts.length === 0) {
  20772. return "";
  20773. } // If the right part is a JSX node, we include it in a separate group to
  20774. // prevent it breaking the whole chain, so we can print the expression like:
  20775. //
  20776. // foo && bar && (
  20777. // <Foo>
  20778. // <Bar />
  20779. // </Foo>
  20780. // )
  20781. var hasJSX = isJSXNode$1(n.right);
  20782. var rest = concat$d(hasJSX ? _parts.slice(1, -1) : _parts.slice(1));
  20783. var groupId = Symbol("logicalChain-" + ++uid);
  20784. var chain = group$b(concat$d([// Don't include the initial expression in the indentation
  20785. // level. The first item is guaranteed to be the first
  20786. // left-most expression.
  20787. _parts.length > 0 ? _parts[0] : "", indent$7(rest)]), {
  20788. id: groupId
  20789. });
  20790. if (!hasJSX) {
  20791. return chain;
  20792. }
  20793. var jsxPart = getLast$2(_parts);
  20794. return group$b(concat$d([chain, ifBreak$6(indent$7(jsxPart), jsxPart, {
  20795. groupId: groupId
  20796. })]));
  20797. }
  20798. case "AssignmentPattern":
  20799. return concat$d([path.call(print, "left"), " = ", path.call(print, "right")]);
  20800. case "TSTypeAssertion":
  20801. {
  20802. var shouldBreakAfterCast = !(n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression");
  20803. var castGroup = group$b(concat$d(["<", indent$7(concat$d([softline$6, path.call(print, "typeAnnotation")])), softline$6, ">"]));
  20804. var exprContents = concat$d([ifBreak$6("("), indent$7(concat$d([softline$6, path.call(print, "expression")])), softline$6, ifBreak$6(")")]);
  20805. if (shouldBreakAfterCast) {
  20806. return conditionalGroup$1([concat$d([castGroup, path.call(print, "expression")]), concat$d([castGroup, group$b(exprContents, {
  20807. shouldBreak: true
  20808. })]), concat$d([castGroup, path.call(print, "expression")])]);
  20809. }
  20810. return group$b(concat$d([castGroup, path.call(print, "expression")]));
  20811. }
  20812. case "OptionalMemberExpression":
  20813. case "MemberExpression":
  20814. {
  20815. var _parent2 = path.getParentNode();
  20816. var firstNonMemberParent;
  20817. var i = 0;
  20818. do {
  20819. firstNonMemberParent = path.getParentNode(i);
  20820. i++;
  20821. } while (firstNonMemberParent && (firstNonMemberParent.type === "MemberExpression" || firstNonMemberParent.type === "OptionalMemberExpression" || firstNonMemberParent.type === "TSNonNullExpression"));
  20822. var shouldInline = firstNonMemberParent && (firstNonMemberParent.type === "NewExpression" || firstNonMemberParent.type === "BindExpression" || firstNonMemberParent.type === "VariableDeclarator" && firstNonMemberParent.id.type !== "Identifier" || firstNonMemberParent.type === "AssignmentExpression" && firstNonMemberParent.left.type !== "Identifier") || n.computed || n.object.type === "Identifier" && n.property.type === "Identifier" && _parent2.type !== "MemberExpression" && _parent2.type !== "OptionalMemberExpression";
  20823. return concat$d([path.call(print, "object"), shouldInline ? printMemberLookup(path, options, print) : group$b(indent$7(concat$d([softline$6, printMemberLookup(path, options, print)])))]);
  20824. }
  20825. case "MetaProperty":
  20826. return concat$d([path.call(print, "meta"), ".", path.call(print, "property")]);
  20827. case "BindExpression":
  20828. if (n.object) {
  20829. parts.push(path.call(print, "object"));
  20830. }
  20831. parts.push(group$b(indent$7(concat$d([softline$6, printBindExpressionCallee(path, options, print)]))));
  20832. return concat$d(parts);
  20833. case "Identifier":
  20834. {
  20835. return concat$d([n.name, printOptionalToken(path), printTypeAnnotation(path, options, print)]);
  20836. }
  20837. case "V8IntrinsicIdentifier":
  20838. return concat$d(["%", n.name]);
  20839. case "SpreadElement":
  20840. case "SpreadElementPattern":
  20841. case "RestProperty":
  20842. case "SpreadProperty":
  20843. case "SpreadPropertyPattern":
  20844. case "RestElement":
  20845. case "ObjectTypeSpreadProperty":
  20846. return concat$d(["...", path.call(print, "argument"), printTypeAnnotation(path, options, print)]);
  20847. case "FunctionDeclaration":
  20848. case "FunctionExpression":
  20849. parts.push(printFunctionDeclaration(path, print, options));
  20850. if (!n.body) {
  20851. parts.push(semi);
  20852. }
  20853. return concat$d(parts);
  20854. case "ArrowFunctionExpression":
  20855. {
  20856. if (n.async) {
  20857. parts.push("async ");
  20858. }
  20859. if (shouldPrintParamsWithoutParens(path, options)) {
  20860. parts.push(path.call(print, "params", 0));
  20861. } else {
  20862. parts.push(group$b(concat$d([printFunctionParams(path, print, options,
  20863. /* expandLast */
  20864. args && (args.expandLastArg || args.expandFirstArg),
  20865. /* printTypeParams */
  20866. true), printReturnType(path, print, options)])));
  20867. }
  20868. var dangling = comments.printDanglingComments(path, options,
  20869. /* sameIndent */
  20870. true, function (comment) {
  20871. var nextCharacter = getNextNonSpaceNonCommentCharacterIndex$2(options.originalText, comment, options);
  20872. return options.originalText.substr(nextCharacter, 2) === "=>";
  20873. });
  20874. if (dangling) {
  20875. parts.push(" ", dangling);
  20876. }
  20877. parts.push(" =>");
  20878. var body = path.call(function (bodyPath) {
  20879. return print(bodyPath, args);
  20880. }, "body"); // We want to always keep these types of nodes on the same line
  20881. // as the arrow.
  20882. if (!hasLeadingOwnLineComment$1(options.originalText, n.body, options) && (n.body.type === "ArrayExpression" || n.body.type === "ObjectExpression" || n.body.type === "BlockStatement" || isJSXNode$1(n.body) || isTemplateOnItsOwnLine$1(n.body, options.originalText, options) || n.body.type === "ArrowFunctionExpression" || n.body.type === "DoExpression")) {
  20883. return group$b(concat$d([concat$d(parts), " ", body]));
  20884. } // We handle sequence expressions as the body of arrows specially,
  20885. // so that the required parentheses end up on their own lines.
  20886. if (n.body.type === "SequenceExpression") {
  20887. return group$b(concat$d([concat$d(parts), group$b(concat$d([" (", indent$7(concat$d([softline$6, body])), softline$6, ")"]))]));
  20888. } // if the arrow function is expanded as last argument, we are adding a
  20889. // level of indentation and need to add a softline to align the closing )
  20890. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  20891. // we should align the expression's closing } with the line with the opening {.
  20892. var shouldAddSoftLine = (args && args.expandLastArg || path.getParentNode().type === "JSXExpressionContainer") && !(n.comments && n.comments.length);
  20893. var printTrailingComma = args && args.expandLastArg && shouldPrintComma$1(options, "all"); // In order to avoid confusion between
  20894. // a => a ? a : a
  20895. // a <= a ? a : a
  20896. var shouldAddParens = n.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken$1(n.body,
  20897. /* forbidFunctionAndClass */
  20898. false);
  20899. return group$b(concat$d([concat$d(parts), group$b(concat$d([indent$7(concat$d([line$7, shouldAddParens ? ifBreak$6("", "(") : "", body, shouldAddParens ? ifBreak$6("", ")") : ""])), shouldAddSoftLine ? concat$d([ifBreak$6(printTrailingComma ? "," : ""), softline$6]) : ""]))]));
  20900. }
  20901. case "YieldExpression":
  20902. parts.push("yield");
  20903. if (n.delegate) {
  20904. parts.push("*");
  20905. }
  20906. if (n.argument) {
  20907. parts.push(" ", path.call(print, "argument"));
  20908. }
  20909. return concat$d(parts);
  20910. case "AwaitExpression":
  20911. {
  20912. parts.push("await ", path.call(print, "argument"));
  20913. var _parent3 = path.getParentNode();
  20914. if ((_parent3.type === "CallExpression" || _parent3.type === "OptionalCallExpression") && _parent3.callee === n || (_parent3.type === "MemberExpression" || _parent3.type === "OptionalMemberExpression") && _parent3.object === n) {
  20915. return group$b(concat$d([indent$7(concat$d([softline$6, concat$d(parts)])), softline$6]));
  20916. }
  20917. return concat$d(parts);
  20918. }
  20919. case "ImportSpecifier":
  20920. if (n.importKind) {
  20921. parts.push(path.call(print, "importKind"), " ");
  20922. }
  20923. parts.push(path.call(print, "imported"));
  20924. if (n.local && n.local.name !== n.imported.name) {
  20925. parts.push(" as ", path.call(print, "local"));
  20926. }
  20927. return concat$d(parts);
  20928. case "ExportSpecifier":
  20929. parts.push(path.call(print, "local"));
  20930. if (n.exported && n.exported.name !== n.local.name) {
  20931. parts.push(" as ", path.call(print, "exported"));
  20932. }
  20933. return concat$d(parts);
  20934. case "ImportNamespaceSpecifier":
  20935. parts.push("* as ");
  20936. parts.push(path.call(print, "local"));
  20937. return concat$d(parts);
  20938. case "ImportDefaultSpecifier":
  20939. return path.call(print, "local");
  20940. case "TSExportAssignment":
  20941. return concat$d(["export = ", path.call(print, "expression"), semi]);
  20942. case "ExportDefaultDeclaration":
  20943. case "ExportNamedDeclaration":
  20944. return printExportDeclaration(path, options, print);
  20945. case "ExportAllDeclaration":
  20946. parts.push("export ");
  20947. if (n.exportKind === "type") {
  20948. parts.push("type ");
  20949. }
  20950. parts.push("* from ", path.call(print, "source"), semi);
  20951. return concat$d(parts);
  20952. case "ExportNamespaceSpecifier":
  20953. case "ExportDefaultSpecifier":
  20954. return path.call(print, "exported");
  20955. case "ImportDeclaration":
  20956. {
  20957. parts.push("import ");
  20958. if (n.importKind && n.importKind !== "value") {
  20959. parts.push(n.importKind + " ");
  20960. }
  20961. var standalones = [];
  20962. var grouped = [];
  20963. if (n.specifiers && n.specifiers.length > 0) {
  20964. path.each(function (specifierPath) {
  20965. var value = specifierPath.getValue();
  20966. if (value.type === "ImportDefaultSpecifier" || value.type === "ImportNamespaceSpecifier") {
  20967. standalones.push(print(specifierPath));
  20968. } else {
  20969. grouped.push(print(specifierPath));
  20970. }
  20971. }, "specifiers");
  20972. if (standalones.length > 0) {
  20973. parts.push(join$9(", ", standalones));
  20974. }
  20975. if (standalones.length > 0 && grouped.length > 0) {
  20976. parts.push(", ");
  20977. }
  20978. if (grouped.length === 1 && standalones.length === 0 && n.specifiers && !n.specifiers.some(function (node) {
  20979. return node.comments;
  20980. })) {
  20981. parts.push(concat$d(["{", options.bracketSpacing ? " " : "", concat$d(grouped), options.bracketSpacing ? " " : "", "}"]));
  20982. } else if (grouped.length >= 1) {
  20983. parts.push(group$b(concat$d(["{", indent$7(concat$d([options.bracketSpacing ? line$7 : softline$6, join$9(concat$d([",", line$7]), grouped)])), ifBreak$6(shouldPrintComma$1(options) ? "," : ""), options.bracketSpacing ? line$7 : softline$6, "}"])));
  20984. }
  20985. parts.push(" from ");
  20986. } else if (n.importKind && n.importKind === "type" || // import {} from 'x'
  20987. /{\s*}/.test(options.originalText.slice(options.locStart(n), options.locStart(n.source)))) {
  20988. parts.push("{} from ");
  20989. }
  20990. parts.push(path.call(print, "source"), semi);
  20991. return concat$d(parts);
  20992. }
  20993. case "Import":
  20994. return "import";
  20995. case "TSModuleBlock":
  20996. case "BlockStatement":
  20997. {
  20998. var naked = path.call(function (bodyPath) {
  20999. return printStatementSequence(bodyPath, options, print);
  21000. }, "body");
  21001. var hasContent = n.body.find(function (node) {
  21002. return node.type !== "EmptyStatement";
  21003. });
  21004. var hasDirectives = n.directives && n.directives.length > 0;
  21005. var _parent4 = path.getParentNode();
  21006. var _parentParent = path.getParentNode(1);
  21007. if (!hasContent && !hasDirectives && !hasDanglingComments$1(n) && (_parent4.type === "ArrowFunctionExpression" || _parent4.type === "FunctionExpression" || _parent4.type === "FunctionDeclaration" || _parent4.type === "ObjectMethod" || _parent4.type === "ClassMethod" || _parent4.type === "ClassPrivateMethod" || _parent4.type === "ForStatement" || _parent4.type === "WhileStatement" || _parent4.type === "DoWhileStatement" || _parent4.type === "DoExpression" || _parent4.type === "CatchClause" && !_parentParent.finalizer || _parent4.type === "TSModuleDeclaration")) {
  21008. return "{}";
  21009. }
  21010. parts.push("{"); // Babel 6
  21011. if (hasDirectives) {
  21012. path.each(function (childPath) {
  21013. parts.push(indent$7(concat$d([hardline$9, print(childPath), semi])));
  21014. if (isNextLineEmpty$4(options.originalText, childPath.getValue(), options)) {
  21015. parts.push(hardline$9);
  21016. }
  21017. }, "directives");
  21018. }
  21019. if (hasContent) {
  21020. parts.push(indent$7(concat$d([hardline$9, naked])));
  21021. }
  21022. parts.push(comments.printDanglingComments(path, options));
  21023. parts.push(hardline$9, "}");
  21024. return concat$d(parts);
  21025. }
  21026. case "ReturnStatement":
  21027. parts.push("return");
  21028. if (n.argument) {
  21029. if (returnArgumentHasLeadingComment$1(options, n.argument)) {
  21030. parts.push(concat$d([" (", indent$7(concat$d([hardline$9, path.call(print, "argument")])), hardline$9, ")"]));
  21031. } else if (n.argument.type === "LogicalExpression" || n.argument.type === "BinaryExpression" || n.argument.type === "SequenceExpression") {
  21032. parts.push(group$b(concat$d([ifBreak$6(" (", " "), indent$7(concat$d([softline$6, path.call(print, "argument")])), softline$6, ifBreak$6(")")])));
  21033. } else {
  21034. parts.push(" ", path.call(print, "argument"));
  21035. }
  21036. }
  21037. if (hasDanglingComments$1(n)) {
  21038. parts.push(" ", comments.printDanglingComments(path, options,
  21039. /* sameIndent */
  21040. true));
  21041. }
  21042. parts.push(semi);
  21043. return concat$d(parts);
  21044. case "NewExpression":
  21045. case "OptionalCallExpression":
  21046. case "CallExpression":
  21047. {
  21048. var isNew = n.type === "NewExpression";
  21049. var optional = printOptionalToken(path);
  21050. if ( // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  21051. // define calls, as a unit.
  21052. // e.g. `define(["some/lib", (lib) => {`
  21053. !isNew && n.callee.type === "Identifier" && (n.callee.name === "require" || n.callee.name === "define") || // Template literals as single arguments
  21054. n.arguments.length === 1 && isTemplateOnItsOwnLine$1(n.arguments[0], options.originalText, options) || // Keep test declarations on a single line
  21055. // e.g. `it('long name', () => {`
  21056. !isNew && isTestCall$1(n, path.getParentNode())) {
  21057. return concat$d([isNew ? "new " : "", path.call(print, "callee"), optional, printFunctionTypeParameters(path, options, print), concat$d(["(", join$9(", ", path.map(print, "arguments")), ")"])]);
  21058. } // Inline Flow annotation comments following Identifiers in Call nodes need to
  21059. // stay with the Identifier. For example:
  21060. //
  21061. // foo /*:: <SomeGeneric> */(bar);
  21062. //
  21063. // Here, we ensure that such comments stay between the Identifier and the Callee.
  21064. var isIdentifierWithFlowAnnotation = n.callee.type === "Identifier" && hasFlowAnnotationComment$1(n.callee.trailingComments);
  21065. if (isIdentifierWithFlowAnnotation) {
  21066. n.callee.trailingComments[0].printed = true;
  21067. } // We detect calls on member lookups and possibly print them in a
  21068. // special chain format. See `printMemberChain` for more info.
  21069. if (!isNew && isMemberish$1(n.callee)) {
  21070. return printMemberChain(path, options, print);
  21071. }
  21072. var contents = concat$d([isNew ? "new " : "", path.call(print, "callee"), optional, isIdentifierWithFlowAnnotation ? "/*:: ".concat(n.callee.trailingComments[0].value.substring(2).trim(), " */") : "", printFunctionTypeParameters(path, options, print), printArgumentsList(path, options, print)]); // We group here when the callee is itself a call expression.
  21073. // See `isLongCurriedCallExpression` for more info.
  21074. if (isCallOrOptionalCallExpression$1(n.callee)) {
  21075. return group$b(contents);
  21076. }
  21077. return contents;
  21078. }
  21079. case "TSInterfaceDeclaration":
  21080. if (n.declare) {
  21081. parts.push("declare ");
  21082. }
  21083. parts.push(n.abstract ? "abstract " : "", printTypeScriptModifiers(path, options, print), "interface ", path.call(print, "id"), n.typeParameters ? path.call(print, "typeParameters") : "", " ");
  21084. if (n.extends && n.extends.length) {
  21085. parts.push(group$b(indent$7(concat$d([softline$6, "extends ", (n.extends.length === 1 ? identity$2 : indent$7)(join$9(concat$d([",", line$7]), path.map(print, "extends"))), " "]))));
  21086. }
  21087. parts.push(path.call(print, "body"));
  21088. return concat$d(parts);
  21089. case "ObjectTypeInternalSlot":
  21090. return concat$d([n.static ? "static " : "", "[[", path.call(print, "id"), "]]", printOptionalToken(path), n.method ? "" : ": ", path.call(print, "value")]);
  21091. case "ObjectExpression":
  21092. case "ObjectPattern":
  21093. case "ObjectTypeAnnotation":
  21094. case "TSInterfaceBody":
  21095. case "TSTypeLiteral":
  21096. {
  21097. var propertiesField;
  21098. if (n.type === "TSTypeLiteral") {
  21099. propertiesField = "members";
  21100. } else if (n.type === "TSInterfaceBody") {
  21101. propertiesField = "body";
  21102. } else {
  21103. propertiesField = "properties";
  21104. }
  21105. var isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  21106. var fields = [];
  21107. if (isTypeAnnotation) {
  21108. fields.push("indexers", "callProperties", "internalSlots");
  21109. }
  21110. fields.push(propertiesField);
  21111. var firstProperty = fields.map(function (field) {
  21112. return n[field][0];
  21113. }).sort(function (a, b) {
  21114. return options.locStart(a) - options.locStart(b);
  21115. })[0];
  21116. var _parent5 = path.getParentNode(0);
  21117. var isFlowInterfaceLikeBody = isTypeAnnotation && _parent5 && (_parent5.type === "InterfaceDeclaration" || _parent5.type === "DeclareInterface" || _parent5.type === "DeclareClass") && path.getName() === "body";
  21118. var shouldBreak = n.type === "TSInterfaceBody" || isFlowInterfaceLikeBody || n.type === "ObjectPattern" && _parent5.type !== "FunctionDeclaration" && _parent5.type !== "FunctionExpression" && _parent5.type !== "ArrowFunctionExpression" && _parent5.type !== "ObjectMethod" && _parent5.type !== "ClassMethod" && _parent5.type !== "ClassPrivateMethod" && _parent5.type !== "AssignmentPattern" && _parent5.type !== "CatchClause" && n.properties.some(function (property) {
  21119. return property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern");
  21120. }) || n.type !== "ObjectPattern" && firstProperty && hasNewlineInRange$2(options.originalText, options.locStart(n), options.locStart(firstProperty));
  21121. var separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" ? ifBreak$6(semi, ";") : ",";
  21122. var leftBrace = n.exact ? "{|" : "{";
  21123. var rightBrace = n.exact ? "|}" : "}"; // Unfortunately, things are grouped together in the ast can be
  21124. // interleaved in the source code. So we need to reorder them before
  21125. // printing them.
  21126. var propsAndLoc = [];
  21127. fields.forEach(function (field) {
  21128. path.each(function (childPath) {
  21129. var node = childPath.getValue();
  21130. propsAndLoc.push({
  21131. node: node,
  21132. printed: print(childPath),
  21133. loc: options.locStart(node)
  21134. });
  21135. }, field);
  21136. });
  21137. var separatorParts = [];
  21138. var props = propsAndLoc.sort(function (a, b) {
  21139. return a.loc - b.loc;
  21140. }).map(function (prop) {
  21141. var result = concat$d(separatorParts.concat(group$b(prop.printed)));
  21142. separatorParts = [separator, line$7];
  21143. if ((prop.node.type === "TSPropertySignature" || prop.node.type === "TSMethodSignature" || prop.node.type === "TSConstructSignatureDeclaration") && hasNodeIgnoreComment$2(prop.node)) {
  21144. separatorParts.shift();
  21145. }
  21146. if (isNextLineEmpty$4(options.originalText, prop.node, options)) {
  21147. separatorParts.push(hardline$9);
  21148. }
  21149. return result;
  21150. });
  21151. if (n.inexact) {
  21152. props.push(concat$d(separatorParts.concat(group$b("..."))));
  21153. }
  21154. var lastElem = getLast$2(n[propertiesField]);
  21155. var canHaveTrailingSeparator = !(lastElem && (lastElem.type === "RestProperty" || lastElem.type === "RestElement" || hasNodeIgnoreComment$2(lastElem) || n.inexact));
  21156. var content;
  21157. if (props.length === 0) {
  21158. if (!hasDanglingComments$1(n)) {
  21159. return concat$d([leftBrace, rightBrace, printTypeAnnotation(path, options, print)]);
  21160. }
  21161. content = group$b(concat$d([leftBrace, comments.printDanglingComments(path, options), softline$6, rightBrace, printOptionalToken(path), printTypeAnnotation(path, options, print)]));
  21162. } else {
  21163. content = concat$d([leftBrace, indent$7(concat$d([options.bracketSpacing ? line$7 : softline$6, concat$d(props)])), ifBreak$6(canHaveTrailingSeparator && (separator !== "," || shouldPrintComma$1(options)) ? separator : ""), concat$d([options.bracketSpacing ? line$7 : softline$6, rightBrace]), printOptionalToken(path), printTypeAnnotation(path, options, print)]);
  21164. } // If we inline the object as first argument of the parent, we don't want
  21165. // to create another group so that the object breaks before the return
  21166. // type
  21167. var parentParentParent = path.getParentNode(2);
  21168. if (n.type === "ObjectPattern" && _parent5 && shouldHugArguments(_parent5) && !n.decorators && _parent5.params[0] === n || shouldHugType(n) && parentParentParent && shouldHugArguments(parentParentParent) && parentParentParent.params[0].typeAnnotation && parentParentParent.params[0].typeAnnotation.typeAnnotation === n) {
  21169. return content;
  21170. }
  21171. return group$b(content, {
  21172. shouldBreak: shouldBreak
  21173. });
  21174. }
  21175. // Babel 6
  21176. case "ObjectProperty": // Non-standard AST node type.
  21177. case "Property":
  21178. if (n.method || n.kind === "get" || n.kind === "set") {
  21179. return printMethod(path, options, print);
  21180. }
  21181. if (n.shorthand) {
  21182. parts.push(path.call(print, "value"));
  21183. } else {
  21184. parts.push(printAssignment(n.key, printPropertyKey(path, options, print), ":", n.value, path.call(print, "value"), options));
  21185. }
  21186. return concat$d(parts);
  21187. // Babel 6
  21188. case "ClassMethod":
  21189. case "ClassPrivateMethod":
  21190. case "MethodDefinition":
  21191. case "TSAbstractMethodDefinition":
  21192. if (n.decorators && n.decorators.length !== 0) {
  21193. parts.push(printDecorators(path, options, print));
  21194. }
  21195. if (n.accessibility) {
  21196. parts.push(n.accessibility + " ");
  21197. }
  21198. if (n.static) {
  21199. parts.push("static ");
  21200. }
  21201. if (n.type === "TSAbstractMethodDefinition") {
  21202. parts.push("abstract ");
  21203. }
  21204. parts.push(printMethod(path, options, print));
  21205. return concat$d(parts);
  21206. case "ObjectMethod":
  21207. return printMethod(path, options, print);
  21208. case "Decorator":
  21209. return concat$d(["@", path.call(print, "expression"), path.call(print, "callee")]);
  21210. case "ArrayExpression":
  21211. case "ArrayPattern":
  21212. if (n.elements.length === 0) {
  21213. if (!hasDanglingComments$1(n)) {
  21214. parts.push("[]");
  21215. } else {
  21216. parts.push(group$b(concat$d(["[", comments.printDanglingComments(path, options), softline$6, "]"])));
  21217. }
  21218. } else {
  21219. var _lastElem = getLast$2(n.elements);
  21220. var canHaveTrailingComma = !(_lastElem && _lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which
  21221. // changes its length based on the number of commas. The algorithm
  21222. // is that if the last argument is null, we need to force insert
  21223. // a comma to ensure JavaScript recognizes it.
  21224. // [,].length === 1
  21225. // [1,].length === 1
  21226. // [1,,].length === 2
  21227. //
  21228. // Note that getLast returns null if the array is empty, but
  21229. // we already check for an empty array just above so we are safe
  21230. var needsForcedTrailingComma = canHaveTrailingComma && _lastElem === null;
  21231. var _shouldBreak = n.elements.length > 1 && n.elements.every(function (element, i, elements) {
  21232. var elementType = element && element.type;
  21233. if (elementType !== "ArrayExpression" && elementType !== "ObjectExpression") {
  21234. return false;
  21235. }
  21236. var nextElement = elements[i + 1];
  21237. if (nextElement && elementType !== nextElement.type) {
  21238. return false;
  21239. }
  21240. var itemsKey = elementType === "ArrayExpression" ? "elements" : "properties";
  21241. return element[itemsKey] && element[itemsKey].length > 1;
  21242. });
  21243. parts.push(group$b(concat$d(["[", indent$7(concat$d([softline$6, printArrayItems(path, options, "elements", print)])), needsForcedTrailingComma ? "," : "", ifBreak$6(canHaveTrailingComma && !needsForcedTrailingComma && shouldPrintComma$1(options) ? "," : ""), comments.printDanglingComments(path, options,
  21244. /* sameIndent */
  21245. true), softline$6, "]"]), {
  21246. shouldBreak: _shouldBreak
  21247. }));
  21248. }
  21249. parts.push(printOptionalToken(path), printTypeAnnotation(path, options, print));
  21250. return concat$d(parts);
  21251. case "SequenceExpression":
  21252. {
  21253. var _parent6 = path.getParentNode(0);
  21254. if (_parent6.type === "ExpressionStatement" || _parent6.type === "ForStatement") {
  21255. // For ExpressionStatements and for-loop heads, which are among
  21256. // the few places a SequenceExpression appears unparenthesized, we want
  21257. // to indent expressions after the first.
  21258. var _parts2 = [];
  21259. path.each(function (p) {
  21260. if (p.getName() === 0) {
  21261. _parts2.push(print(p));
  21262. } else {
  21263. _parts2.push(",", indent$7(concat$d([line$7, print(p)])));
  21264. }
  21265. }, "expressions");
  21266. return group$b(concat$d(_parts2));
  21267. }
  21268. return group$b(concat$d([join$9(concat$d([",", line$7]), path.map(print, "expressions"))]));
  21269. }
  21270. case "ThisExpression":
  21271. return "this";
  21272. case "Super":
  21273. return "super";
  21274. case "NullLiteral":
  21275. // Babel 6 Literal split
  21276. return "null";
  21277. case "RegExpLiteral":
  21278. // Babel 6 Literal split
  21279. return printRegex(n);
  21280. case "NumericLiteral":
  21281. // Babel 6 Literal split
  21282. return printNumber$2(n.extra.raw);
  21283. case "BigIntLiteral":
  21284. // babel: n.extra.raw, typescript: n.raw, flow: n.bigint
  21285. return (n.bigint || (n.extra ? n.extra.raw : n.raw)).toLowerCase();
  21286. case "BooleanLiteral": // Babel 6 Literal split
  21287. case "StringLiteral": // Babel 6 Literal split
  21288. case "Literal":
  21289. {
  21290. if (n.regex) {
  21291. return printRegex(n.regex);
  21292. }
  21293. if (typeof n.value === "number") {
  21294. return printNumber$2(n.raw);
  21295. }
  21296. if (typeof n.value !== "string") {
  21297. return "" + n.value;
  21298. } // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  21299. // See corresponding workaround in needs-parens.js
  21300. var grandParent = path.getParentNode(1);
  21301. var isTypeScriptDirective = options.parser === "typescript" && typeof n.value === "string" && grandParent && (grandParent.type === "Program" || grandParent.type === "BlockStatement");
  21302. return nodeStr(n, options, isTypeScriptDirective);
  21303. }
  21304. case "Directive":
  21305. return path.call(print, "value");
  21306. // Babel 6
  21307. case "DirectiveLiteral":
  21308. return nodeStr(n, options);
  21309. case "UnaryExpression":
  21310. parts.push(n.operator);
  21311. if (/[a-z]$/.test(n.operator)) {
  21312. parts.push(" ");
  21313. }
  21314. if (n.argument.comments && n.argument.comments.length > 0) {
  21315. parts.push(group$b(concat$d(["(", indent$7(concat$d([softline$6, path.call(print, "argument")])), softline$6, ")"])));
  21316. } else {
  21317. parts.push(path.call(print, "argument"));
  21318. }
  21319. return concat$d(parts);
  21320. case "UpdateExpression":
  21321. parts.push(path.call(print, "argument"), n.operator);
  21322. if (n.prefix) {
  21323. parts.reverse();
  21324. }
  21325. return concat$d(parts);
  21326. case "ConditionalExpression":
  21327. return printTernaryOperator(path, options, print, {
  21328. beforeParts: function beforeParts() {
  21329. return [path.call(print, "test")];
  21330. },
  21331. afterParts: function afterParts(breakClosingParen) {
  21332. return [breakClosingParen ? softline$6 : ""];
  21333. },
  21334. shouldCheckJsx: true,
  21335. conditionalNodeType: "ConditionalExpression",
  21336. consequentNodePropertyName: "consequent",
  21337. alternateNodePropertyName: "alternate",
  21338. testNodePropertyName: "test",
  21339. breakNested: true
  21340. });
  21341. case "VariableDeclaration":
  21342. {
  21343. var printed = path.map(function (childPath) {
  21344. return print(childPath);
  21345. }, "declarations"); // We generally want to terminate all variable declarations with a
  21346. // semicolon, except when they in the () part of for loops.
  21347. var parentNode = path.getParentNode();
  21348. var isParentForLoop = parentNode.type === "ForStatement" || parentNode.type === "ForInStatement" || parentNode.type === "ForOfStatement" || parentNode.type === "ForAwaitStatement";
  21349. var hasValue = n.declarations.some(function (decl) {
  21350. return decl.init;
  21351. });
  21352. var firstVariable;
  21353. if (printed.length === 1 && !n.declarations[0].comments) {
  21354. firstVariable = printed[0];
  21355. } else if (printed.length > 0) {
  21356. // Indent first var to comply with eslint one-var rule
  21357. firstVariable = indent$7(printed[0]);
  21358. }
  21359. parts = [n.declare ? "declare " : "", n.kind, firstVariable ? concat$d([" ", firstVariable]) : "", indent$7(concat$d(printed.slice(1).map(function (p) {
  21360. return concat$d([",", hasValue && !isParentForLoop ? hardline$9 : line$7, p]);
  21361. })))];
  21362. if (!(isParentForLoop && parentNode.body !== n)) {
  21363. parts.push(semi);
  21364. }
  21365. return group$b(concat$d(parts));
  21366. }
  21367. case "TSTypeAliasDeclaration":
  21368. {
  21369. if (n.declare) {
  21370. parts.push("declare ");
  21371. }
  21372. var _printed = printAssignmentRight(n.id, n.typeAnnotation, n.typeAnnotation && path.call(print, "typeAnnotation"), options);
  21373. parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", _printed, semi);
  21374. return group$b(concat$d(parts));
  21375. }
  21376. case "VariableDeclarator":
  21377. return printAssignment(n.id, path.call(print, "id"), " =", n.init, n.init && path.call(print, "init"), options);
  21378. case "WithStatement":
  21379. return group$b(concat$d(["with (", path.call(print, "object"), ")", adjustClause(n.body, path.call(print, "body"))]));
  21380. case "IfStatement":
  21381. {
  21382. var con = adjustClause(n.consequent, path.call(print, "consequent"));
  21383. var opening = group$b(concat$d(["if (", group$b(concat$d([indent$7(concat$d([softline$6, path.call(print, "test")])), softline$6])), ")", con]));
  21384. parts.push(opening);
  21385. if (n.alternate) {
  21386. var commentOnOwnLine = hasTrailingComment$1(n.consequent) && n.consequent.comments.some(function (comment) {
  21387. return comment.trailing && !comments$1.isBlockComment(comment);
  21388. }) || needsHardlineAfterDanglingComment$1(n);
  21389. var elseOnSameLine = n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  21390. parts.push(elseOnSameLine ? " " : hardline$9);
  21391. if (hasDanglingComments$1(n)) {
  21392. parts.push(comments.printDanglingComments(path, options, true), commentOnOwnLine ? hardline$9 : " ");
  21393. }
  21394. parts.push("else", group$b(adjustClause(n.alternate, path.call(print, "alternate"), n.alternate.type === "IfStatement")));
  21395. }
  21396. return concat$d(parts);
  21397. }
  21398. case "ForStatement":
  21399. {
  21400. var _body = adjustClause(n.body, path.call(print, "body")); // We want to keep dangling comments above the loop to stay consistent.
  21401. // Any comment positioned between the for statement and the parentheses
  21402. // is going to be printed before the statement.
  21403. var _dangling = comments.printDanglingComments(path, options,
  21404. /* sameLine */
  21405. true);
  21406. var printedComments = _dangling ? concat$d([_dangling, softline$6]) : "";
  21407. if (!n.init && !n.test && !n.update) {
  21408. return concat$d([printedComments, group$b(concat$d(["for (;;)", _body]))]);
  21409. }
  21410. return concat$d([printedComments, group$b(concat$d(["for (", group$b(concat$d([indent$7(concat$d([softline$6, path.call(print, "init"), ";", line$7, path.call(print, "test"), ";", line$7, path.call(print, "update")])), softline$6])), ")", _body]))]);
  21411. }
  21412. case "WhileStatement":
  21413. return group$b(concat$d(["while (", group$b(concat$d([indent$7(concat$d([softline$6, path.call(print, "test")])), softline$6])), ")", adjustClause(n.body, path.call(print, "body"))]));
  21414. case "ForInStatement":
  21415. // Note: esprima can't actually parse "for each (".
  21416. return group$b(concat$d([n.each ? "for each (" : "for (", path.call(print, "left"), " in ", path.call(print, "right"), ")", adjustClause(n.body, path.call(print, "body"))]));
  21417. case "ForOfStatement":
  21418. case "ForAwaitStatement":
  21419. {
  21420. // Babel 7 removed ForAwaitStatement in favor of ForOfStatement
  21421. // with `"await": true`:
  21422. // https://github.com/estree/estree/pull/138
  21423. var isAwait = n.type === "ForAwaitStatement" || n.await;
  21424. return group$b(concat$d(["for", isAwait ? " await" : "", " (", path.call(print, "left"), " of ", path.call(print, "right"), ")", adjustClause(n.body, path.call(print, "body"))]));
  21425. }
  21426. case "DoWhileStatement":
  21427. {
  21428. var clause = adjustClause(n.body, path.call(print, "body"));
  21429. var doBody = group$b(concat$d(["do", clause]));
  21430. parts = [doBody];
  21431. if (n.body.type === "BlockStatement") {
  21432. parts.push(" ");
  21433. } else {
  21434. parts.push(hardline$9);
  21435. }
  21436. parts.push("while (");
  21437. parts.push(group$b(concat$d([indent$7(concat$d([softline$6, path.call(print, "test")])), softline$6])), ")", semi);
  21438. return concat$d(parts);
  21439. }
  21440. case "DoExpression":
  21441. return concat$d(["do ", path.call(print, "body")]);
  21442. case "BreakStatement":
  21443. parts.push("break");
  21444. if (n.label) {
  21445. parts.push(" ", path.call(print, "label"));
  21446. }
  21447. parts.push(semi);
  21448. return concat$d(parts);
  21449. case "ContinueStatement":
  21450. parts.push("continue");
  21451. if (n.label) {
  21452. parts.push(" ", path.call(print, "label"));
  21453. }
  21454. parts.push(semi);
  21455. return concat$d(parts);
  21456. case "LabeledStatement":
  21457. if (n.body.type === "EmptyStatement") {
  21458. return concat$d([path.call(print, "label"), ":;"]);
  21459. }
  21460. return concat$d([path.call(print, "label"), ": ", path.call(print, "body")]);
  21461. case "TryStatement":
  21462. return concat$d(["try ", path.call(print, "block"), n.handler ? concat$d([" ", path.call(print, "handler")]) : "", n.finalizer ? concat$d([" finally ", path.call(print, "finalizer")]) : ""]);
  21463. case "CatchClause":
  21464. if (n.param) {
  21465. var hasComments = n.param.comments && n.param.comments.some(function (comment) {
  21466. return !comments$1.isBlockComment(comment) || comment.leading && hasNewline$4(options.originalText, options.locEnd(comment)) || comment.trailing && hasNewline$4(options.originalText, options.locStart(comment), {
  21467. backwards: true
  21468. });
  21469. });
  21470. var param = path.call(print, "param");
  21471. return concat$d(["catch ", hasComments ? concat$d(["(", indent$7(concat$d([softline$6, param])), softline$6, ") "]) : concat$d(["(", param, ") "]), path.call(print, "body")]);
  21472. }
  21473. return concat$d(["catch ", path.call(print, "body")]);
  21474. case "ThrowStatement":
  21475. return concat$d(["throw ", path.call(print, "argument"), semi]);
  21476. // Note: ignoring n.lexical because it has no printing consequences.
  21477. case "SwitchStatement":
  21478. return concat$d([group$b(concat$d(["switch (", indent$7(concat$d([softline$6, path.call(print, "discriminant")])), softline$6, ")"])), " {", n.cases.length > 0 ? indent$7(concat$d([hardline$9, join$9(hardline$9, path.map(function (casePath) {
  21479. var caseNode = casePath.getValue();
  21480. return concat$d([casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && isNextLineEmpty$4(options.originalText, caseNode, options) ? hardline$9 : ""]);
  21481. }, "cases"))])) : "", hardline$9, "}"]);
  21482. case "SwitchCase":
  21483. {
  21484. if (n.test) {
  21485. parts.push("case ", path.call(print, "test"), ":");
  21486. } else {
  21487. parts.push("default:");
  21488. }
  21489. var consequent = n.consequent.filter(function (node) {
  21490. return node.type !== "EmptyStatement";
  21491. });
  21492. if (consequent.length > 0) {
  21493. var cons = path.call(function (consequentPath) {
  21494. return printStatementSequence(consequentPath, options, print);
  21495. }, "consequent");
  21496. parts.push(consequent.length === 1 && consequent[0].type === "BlockStatement" ? concat$d([" ", cons]) : indent$7(concat$d([hardline$9, cons])));
  21497. }
  21498. return concat$d(parts);
  21499. }
  21500. // JSX extensions below.
  21501. case "DebuggerStatement":
  21502. return concat$d(["debugger", semi]);
  21503. case "JSXAttribute":
  21504. parts.push(path.call(print, "name"));
  21505. if (n.value) {
  21506. var res;
  21507. if (isStringLiteral$1(n.value)) {
  21508. var raw = rawText$1(n.value); // Unescape all quotes so we get an accurate preferred quote
  21509. var final = raw.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  21510. var quote = getPreferredQuote$1(final, options.jsxSingleQuote ? "'" : '"');
  21511. var _escape = quote === "'" ? "&apos;" : "&quot;";
  21512. final = final.slice(1, -1).replace(new RegExp(quote, "g"), _escape);
  21513. res = concat$d([quote, final, quote]);
  21514. } else {
  21515. res = path.call(print, "value");
  21516. }
  21517. parts.push("=", res);
  21518. }
  21519. return concat$d(parts);
  21520. case "JSXIdentifier":
  21521. return "" + n.name;
  21522. case "JSXNamespacedName":
  21523. return join$9(":", [path.call(print, "namespace"), path.call(print, "name")]);
  21524. case "JSXMemberExpression":
  21525. return join$9(".", [path.call(print, "object"), path.call(print, "property")]);
  21526. case "TSQualifiedName":
  21527. return join$9(".", [path.call(print, "left"), path.call(print, "right")]);
  21528. case "JSXSpreadAttribute":
  21529. case "JSXSpreadChild":
  21530. {
  21531. return concat$d(["{", path.call(function (p) {
  21532. var printed = concat$d(["...", print(p)]);
  21533. var n = p.getValue();
  21534. if (!n.comments || !n.comments.length) {
  21535. return printed;
  21536. }
  21537. return concat$d([indent$7(concat$d([softline$6, comments.printComments(p, function () {
  21538. return printed;
  21539. }, options)])), softline$6]);
  21540. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), "}"]);
  21541. }
  21542. case "JSXExpressionContainer":
  21543. {
  21544. var _parent7 = path.getParentNode(0);
  21545. var preventInline = _parent7.type === "JSXAttribute" && n.expression.comments && n.expression.comments.length > 0;
  21546. var _shouldInline = !preventInline && (n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression" || n.expression.type === "ArrowFunctionExpression" || n.expression.type === "CallExpression" || n.expression.type === "OptionalCallExpression" || n.expression.type === "FunctionExpression" || n.expression.type === "JSXEmptyExpression" || n.expression.type === "TemplateLiteral" || n.expression.type === "TaggedTemplateExpression" || n.expression.type === "DoExpression" || isJSXNode$1(_parent7) && (n.expression.type === "ConditionalExpression" || isBinaryish$1(n.expression)));
  21547. if (_shouldInline) {
  21548. return group$b(concat$d(["{", path.call(print, "expression"), lineSuffixBoundary$1, "}"]));
  21549. }
  21550. return group$b(concat$d(["{", indent$7(concat$d([softline$6, path.call(print, "expression")])), softline$6, lineSuffixBoundary$1, "}"]));
  21551. }
  21552. case "JSXFragment":
  21553. case "JSXElement":
  21554. {
  21555. var elem = comments.printComments(path, function () {
  21556. return printJSXElement(path, options, print);
  21557. }, options);
  21558. return maybeWrapJSXElementInParens(path, elem, options);
  21559. }
  21560. case "JSXOpeningElement":
  21561. {
  21562. var _n = path.getValue();
  21563. var nameHasComments = _n.name && _n.name.comments && _n.name.comments.length > 0 || _n.typeParameters && _n.typeParameters.comments && _n.typeParameters.comments.length > 0; // Don't break self-closing elements with no attributes and no comments
  21564. if (_n.selfClosing && !_n.attributes.length && !nameHasComments) {
  21565. return concat$d(["<", path.call(print, "name"), path.call(print, "typeParameters"), " />"]);
  21566. } // don't break up opening elements with a single long text attribute
  21567. if (_n.attributes && _n.attributes.length === 1 && _n.attributes[0].value && isStringLiteral$1(_n.attributes[0].value) && !_n.attributes[0].value.value.includes("\n") && // We should break for the following cases:
  21568. // <div
  21569. // // comment
  21570. // attr="value"
  21571. // >
  21572. // <div
  21573. // attr="value"
  21574. // // comment
  21575. // >
  21576. !nameHasComments && (!_n.attributes[0].comments || !_n.attributes[0].comments.length)) {
  21577. return group$b(concat$d(["<", path.call(print, "name"), path.call(print, "typeParameters"), " ", concat$d(path.map(print, "attributes")), _n.selfClosing ? " />" : ">"]));
  21578. }
  21579. var lastAttrHasTrailingComments = _n.attributes.length && hasTrailingComment$1(getLast$2(_n.attributes));
  21580. var bracketSameLine = // Simple tags (no attributes and no comment in tag name) should be
  21581. // kept unbroken regardless of `jsxBracketSameLine`
  21582. !_n.attributes.length && !nameHasComments || options.jsxBracketSameLine && ( // We should print the bracket in a new line for the following cases:
  21583. // <div
  21584. // // comment
  21585. // >
  21586. // <div
  21587. // attr // comment
  21588. // >
  21589. !nameHasComments || _n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
  21590. // string literal with newlines
  21591. var _shouldBreak2 = _n.attributes && _n.attributes.some(function (attr) {
  21592. return attr.value && isStringLiteral$1(attr.value) && attr.value.value.includes("\n");
  21593. });
  21594. return group$b(concat$d(["<", path.call(print, "name"), path.call(print, "typeParameters"), concat$d([indent$7(concat$d(path.map(function (attr) {
  21595. return concat$d([line$7, print(attr)]);
  21596. }, "attributes"))), _n.selfClosing ? line$7 : bracketSameLine ? ">" : softline$6]), _n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
  21597. shouldBreak: _shouldBreak2
  21598. });
  21599. }
  21600. case "JSXClosingElement":
  21601. return concat$d(["</", path.call(print, "name"), ">"]);
  21602. case "JSXOpeningFragment":
  21603. case "JSXClosingFragment":
  21604. {
  21605. var hasComment = n.comments && n.comments.length;
  21606. var hasOwnLineComment = hasComment && !n.comments.every(comments$1.isBlockComment);
  21607. var isOpeningFragment = n.type === "JSXOpeningFragment";
  21608. return concat$d([isOpeningFragment ? "<" : "</", indent$7(concat$d([hasOwnLineComment ? hardline$9 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path, options, true)])), hasOwnLineComment ? hardline$9 : "", ">"]);
  21609. }
  21610. case "JSXText":
  21611. /* istanbul ignore next */
  21612. throw new Error("JSXTest should be handled by JSXElement");
  21613. case "JSXEmptyExpression":
  21614. {
  21615. var requiresHardline = n.comments && !n.comments.every(comments$1.isBlockComment);
  21616. return concat$d([comments.printDanglingComments(path, options,
  21617. /* sameIndent */
  21618. !requiresHardline), requiresHardline ? hardline$9 : ""]);
  21619. }
  21620. case "ClassBody":
  21621. if (!n.comments && n.body.length === 0) {
  21622. return "{}";
  21623. }
  21624. return concat$d(["{", n.body.length > 0 ? indent$7(concat$d([hardline$9, path.call(function (bodyPath) {
  21625. return printStatementSequence(bodyPath, options, print);
  21626. }, "body")])) : comments.printDanglingComments(path, options), hardline$9, "}"]);
  21627. case "ClassProperty":
  21628. case "TSAbstractClassProperty":
  21629. case "ClassPrivateProperty":
  21630. {
  21631. if (n.decorators && n.decorators.length !== 0) {
  21632. parts.push(printDecorators(path, options, print));
  21633. }
  21634. if (n.accessibility) {
  21635. parts.push(n.accessibility + " ");
  21636. }
  21637. if (n.declare) {
  21638. parts.push("declare ");
  21639. }
  21640. if (n.static) {
  21641. parts.push("static ");
  21642. }
  21643. if (n.type === "TSAbstractClassProperty") {
  21644. parts.push("abstract ");
  21645. }
  21646. if (n.readonly) {
  21647. parts.push("readonly ");
  21648. }
  21649. var variance = getFlowVariance$1(n);
  21650. if (variance) {
  21651. parts.push(variance);
  21652. }
  21653. parts.push(printPropertyKey(path, options, print), printOptionalToken(path), printTypeAnnotation(path, options, print));
  21654. if (n.value) {
  21655. parts.push(" =", printAssignmentRight(n.key, n.value, path.call(print, "value"), options));
  21656. }
  21657. parts.push(semi);
  21658. return group$b(concat$d(parts));
  21659. }
  21660. case "ClassDeclaration":
  21661. case "ClassExpression":
  21662. if (n.declare) {
  21663. parts.push("declare ");
  21664. }
  21665. parts.push(concat$d(printClass(path, options, print)));
  21666. return concat$d(parts);
  21667. case "TSInterfaceHeritage":
  21668. parts.push(path.call(print, "expression"));
  21669. if (n.typeParameters) {
  21670. parts.push(path.call(print, "typeParameters"));
  21671. }
  21672. return concat$d(parts);
  21673. case "TemplateElement":
  21674. return join$9(literalline$4, n.value.raw.split(/\r?\n/g));
  21675. case "TemplateLiteral":
  21676. {
  21677. var expressions = path.map(print, "expressions");
  21678. var _parentNode = path.getParentNode();
  21679. if (isJestEachTemplateLiteral$1(n, _parentNode)) {
  21680. var _printed2 = printJestEachTemplateLiteral(n, expressions, options);
  21681. if (_printed2) {
  21682. return _printed2;
  21683. }
  21684. }
  21685. var isSimple = isSimpleTemplateLiteral$1(n);
  21686. if (isSimple) {
  21687. expressions = expressions.map(function (doc) {
  21688. return printDocToString$1(doc, Object.assign({}, options, {
  21689. printWidth: Infinity
  21690. })).formatted;
  21691. });
  21692. }
  21693. parts.push(lineSuffixBoundary$1, "`");
  21694. path.each(function (childPath) {
  21695. var i = childPath.getName();
  21696. parts.push(print(childPath));
  21697. if (i < expressions.length) {
  21698. // For a template literal of the following form:
  21699. // `someQuery {
  21700. // ${call({
  21701. // a,
  21702. // b,
  21703. // })}
  21704. // }`
  21705. // the expression is on its own line (there is a \n in the previous
  21706. // quasi literal), therefore we want to indent the JavaScript
  21707. // expression inside at the beginning of ${ instead of the beginning
  21708. // of the `.
  21709. var tabWidth = options.tabWidth;
  21710. var quasi = childPath.getValue();
  21711. var indentSize = getIndentSize$1(quasi.value.raw, tabWidth);
  21712. var _printed3 = expressions[i];
  21713. if (!isSimple) {
  21714. // Breaks at the template element boundaries (${ and }) are preferred to breaking
  21715. // in the middle of a MemberExpression
  21716. if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression") {
  21717. _printed3 = concat$d([indent$7(concat$d([softline$6, _printed3])), softline$6]);
  21718. }
  21719. }
  21720. var aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$1(-Infinity, _printed3) : addAlignmentToDoc$2(_printed3, indentSize, tabWidth);
  21721. parts.push(group$b(concat$d(["${", aligned, lineSuffixBoundary$1, "}"])));
  21722. }
  21723. }, "quasis");
  21724. parts.push("`");
  21725. return concat$d(parts);
  21726. }
  21727. // These types are unprintable because they serve as abstract
  21728. // supertypes for other (printable) types.
  21729. case "TaggedTemplateExpression":
  21730. return concat$d([path.call(print, "tag"), path.call(print, "typeParameters"), path.call(print, "quasi")]);
  21731. case "Node":
  21732. case "Printable":
  21733. case "SourceLocation":
  21734. case "Position":
  21735. case "Statement":
  21736. case "Function":
  21737. case "Pattern":
  21738. case "Expression":
  21739. case "Declaration":
  21740. case "Specifier":
  21741. case "NamedSpecifier":
  21742. case "Comment":
  21743. case "MemberTypeAnnotation": // Flow
  21744. case "Type":
  21745. /* istanbul ignore next */
  21746. throw new Error("unprintable type: " + JSON.stringify(n.type));
  21747. // Type Annotations for Facebook Flow, typically stripped out or
  21748. // transformed away before printing.
  21749. case "TypeAnnotation":
  21750. case "TSTypeAnnotation":
  21751. if (n.typeAnnotation) {
  21752. return path.call(print, "typeAnnotation");
  21753. }
  21754. /* istanbul ignore next */
  21755. return "";
  21756. case "TSTupleType":
  21757. case "TupleTypeAnnotation":
  21758. {
  21759. var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  21760. return group$b(concat$d(["[", indent$7(concat$d([softline$6, printArrayItems(path, options, typesField, print)])), ifBreak$6(shouldPrintComma$1(options, "all") ? "," : ""), comments.printDanglingComments(path, options,
  21761. /* sameIndent */
  21762. true), softline$6, "]"]));
  21763. }
  21764. case "ExistsTypeAnnotation":
  21765. return "*";
  21766. case "EmptyTypeAnnotation":
  21767. return "empty";
  21768. case "AnyTypeAnnotation":
  21769. return "any";
  21770. case "MixedTypeAnnotation":
  21771. return "mixed";
  21772. case "ArrayTypeAnnotation":
  21773. return concat$d([path.call(print, "elementType"), "[]"]);
  21774. case "BooleanTypeAnnotation":
  21775. return "boolean";
  21776. case "BooleanLiteralTypeAnnotation":
  21777. return "" + n.value;
  21778. case "DeclareClass":
  21779. return printFlowDeclaration(path, printClass(path, options, print));
  21780. case "TSDeclareFunction":
  21781. // For TypeScript the TSDeclareFunction node shares the AST
  21782. // structure with FunctionDeclaration
  21783. return concat$d([n.declare ? "declare " : "", printFunctionDeclaration(path, print, options), semi]);
  21784. case "DeclareFunction":
  21785. return printFlowDeclaration(path, ["function ", path.call(print, "id"), n.predicate ? " " : "", path.call(print, "predicate"), semi]);
  21786. case "DeclareModule":
  21787. return printFlowDeclaration(path, ["module ", path.call(print, "id"), " ", path.call(print, "body")]);
  21788. case "DeclareModuleExports":
  21789. return printFlowDeclaration(path, ["module.exports", ": ", path.call(print, "typeAnnotation"), semi]);
  21790. case "DeclareVariable":
  21791. return printFlowDeclaration(path, ["var ", path.call(print, "id"), semi]);
  21792. case "DeclareExportAllDeclaration":
  21793. return concat$d(["declare export * from ", path.call(print, "source")]);
  21794. case "DeclareExportDeclaration":
  21795. return concat$d(["declare ", printExportDeclaration(path, options, print)]);
  21796. case "DeclareOpaqueType":
  21797. case "OpaqueType":
  21798. {
  21799. parts.push("opaque type ", path.call(print, "id"), path.call(print, "typeParameters"));
  21800. if (n.supertype) {
  21801. parts.push(": ", path.call(print, "supertype"));
  21802. }
  21803. if (n.impltype) {
  21804. parts.push(" = ", path.call(print, "impltype"));
  21805. }
  21806. parts.push(semi);
  21807. if (n.type === "DeclareOpaqueType") {
  21808. return printFlowDeclaration(path, parts);
  21809. }
  21810. return concat$d(parts);
  21811. }
  21812. case "EnumDeclaration":
  21813. return concat$d(["enum ", path.call(print, "id"), " ", path.call(print, "body")]);
  21814. case "EnumBooleanBody":
  21815. case "EnumNumberBody":
  21816. case "EnumStringBody":
  21817. case "EnumSymbolBody":
  21818. {
  21819. if (n.type === "EnumSymbolBody" || n.explicitType) {
  21820. var type = null;
  21821. switch (n.type) {
  21822. case "EnumBooleanBody":
  21823. type = "boolean";
  21824. break;
  21825. case "EnumNumberBody":
  21826. type = "number";
  21827. break;
  21828. case "EnumStringBody":
  21829. type = "string";
  21830. break;
  21831. case "EnumSymbolBody":
  21832. type = "symbol";
  21833. break;
  21834. }
  21835. parts.push("of ", type, " ");
  21836. }
  21837. if (n.members.length === 0) {
  21838. parts.push(group$b(concat$d(["{", comments.printDanglingComments(path, options), softline$6, "}"])));
  21839. } else {
  21840. parts.push(group$b(concat$d(["{", indent$7(concat$d([hardline$9, printArrayItems(path, options, "members", print), shouldPrintComma$1(options) ? "," : ""])), comments.printDanglingComments(path, options,
  21841. /* sameIndent */
  21842. true), hardline$9, "}"])));
  21843. }
  21844. return concat$d(parts);
  21845. }
  21846. case "EnumBooleanMember":
  21847. case "EnumNumberMember":
  21848. case "EnumStringMember":
  21849. return concat$d([path.call(print, "id"), " = ", _typeof(n.init) === "object" ? path.call(print, "init") : String(n.init)]);
  21850. case "EnumDefaultedMember":
  21851. return path.call(print, "id");
  21852. case "FunctionTypeAnnotation":
  21853. case "TSFunctionType":
  21854. {
  21855. // FunctionTypeAnnotation is ambiguous:
  21856. // declare function foo(a: B): void; OR
  21857. // var A: (a: B) => void;
  21858. var _parent8 = path.getParentNode(0);
  21859. var _parentParent2 = path.getParentNode(1);
  21860. var _parentParentParent = path.getParentNode(2);
  21861. var isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || !((_parent8.type === "ObjectTypeProperty" || _parent8.type === "ObjectTypeInternalSlot") && !getFlowVariance$1(_parent8) && !_parent8.optional && options.locStart(_parent8) === options.locStart(n) || _parent8.type === "ObjectTypeCallProperty" || _parentParentParent && _parentParentParent.type === "DeclareFunction");
  21862. var needsColon = isArrowFunctionTypeAnnotation && (_parent8.type === "TypeAnnotation" || _parent8.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
  21863. // printing ":" as part of the expression and it would put parenthesis
  21864. // around :(
  21865. var needsParens = needsColon && isArrowFunctionTypeAnnotation && (_parent8.type === "TypeAnnotation" || _parent8.type === "TSTypeAnnotation") && _parentParent2.type === "ArrowFunctionExpression";
  21866. if (isObjectTypePropertyAFunction$1(_parent8, options)) {
  21867. isArrowFunctionTypeAnnotation = true;
  21868. needsColon = true;
  21869. }
  21870. if (needsParens) {
  21871. parts.push("(");
  21872. }
  21873. parts.push(printFunctionParams(path, print, options,
  21874. /* expandArg */
  21875. false,
  21876. /* printTypeParams */
  21877. true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
  21878. // needs to be added separately.
  21879. if (n.returnType || n.predicate || n.typeAnnotation) {
  21880. parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path.call(print, "returnType"), path.call(print, "predicate"), path.call(print, "typeAnnotation"));
  21881. }
  21882. if (needsParens) {
  21883. parts.push(")");
  21884. }
  21885. return group$b(concat$d(parts));
  21886. }
  21887. case "TSRestType":
  21888. return concat$d(["...", path.call(print, "typeAnnotation")]);
  21889. case "TSOptionalType":
  21890. return concat$d([path.call(print, "typeAnnotation"), "?"]);
  21891. case "FunctionTypeParam":
  21892. return concat$d([path.call(print, "name"), printOptionalToken(path), n.name ? ": " : "", path.call(print, "typeAnnotation")]);
  21893. case "GenericTypeAnnotation":
  21894. return concat$d([path.call(print, "id"), path.call(print, "typeParameters")]);
  21895. case "DeclareInterface":
  21896. case "InterfaceDeclaration":
  21897. case "InterfaceTypeAnnotation":
  21898. {
  21899. if (n.type === "DeclareInterface" || n.declare) {
  21900. parts.push("declare ");
  21901. }
  21902. parts.push("interface");
  21903. if (n.type === "DeclareInterface" || n.type === "InterfaceDeclaration") {
  21904. parts.push(" ", path.call(print, "id"), path.call(print, "typeParameters"));
  21905. }
  21906. if (n["extends"].length > 0) {
  21907. parts.push(group$b(indent$7(concat$d([line$7, "extends ", (n.extends.length === 1 ? identity$2 : indent$7)(join$9(concat$d([",", line$7]), path.map(print, "extends")))]))));
  21908. }
  21909. parts.push(" ", path.call(print, "body"));
  21910. return group$b(concat$d(parts));
  21911. }
  21912. case "ClassImplements":
  21913. case "InterfaceExtends":
  21914. return concat$d([path.call(print, "id"), path.call(print, "typeParameters")]);
  21915. case "TSClassImplements":
  21916. return concat$d([path.call(print, "expression"), path.call(print, "typeParameters")]);
  21917. case "TSIntersectionType":
  21918. case "IntersectionTypeAnnotation":
  21919. {
  21920. var types = path.map(print, "types");
  21921. var result = [];
  21922. var wasIndented = false;
  21923. for (var _i = 0; _i < types.length; ++_i) {
  21924. if (_i === 0) {
  21925. result.push(types[_i]);
  21926. } else if (isObjectType$1(n.types[_i - 1]) && isObjectType$1(n.types[_i])) {
  21927. // If both are objects, don't indent
  21928. result.push(concat$d([" & ", wasIndented ? indent$7(types[_i]) : types[_i]]));
  21929. } else if (!isObjectType$1(n.types[_i - 1]) && !isObjectType$1(n.types[_i])) {
  21930. // If no object is involved, go to the next line if it breaks
  21931. result.push(indent$7(concat$d([" &", line$7, types[_i]])));
  21932. } else {
  21933. // If you go from object to non-object or vis-versa, then inline it
  21934. if (_i > 1) {
  21935. wasIndented = true;
  21936. }
  21937. result.push(" & ", _i > 1 ? indent$7(types[_i]) : types[_i]);
  21938. }
  21939. }
  21940. return group$b(concat$d(result));
  21941. }
  21942. case "TSUnionType":
  21943. case "UnionTypeAnnotation":
  21944. {
  21945. // single-line variation
  21946. // A | B | C
  21947. // multi-line variation
  21948. // | A
  21949. // | B
  21950. // | C
  21951. var _parent9 = path.getParentNode(); // If there's a leading comment, the parent is doing the indentation
  21952. var shouldIndent = _parent9.type !== "TypeParameterInstantiation" && _parent9.type !== "TSTypeParameterInstantiation" && _parent9.type !== "GenericTypeAnnotation" && _parent9.type !== "TSTypeReference" && _parent9.type !== "TSTypeAssertion" && _parent9.type !== "TupleTypeAnnotation" && _parent9.type !== "TSTupleType" && !(_parent9.type === "FunctionTypeParam" && !_parent9.name) && !((_parent9.type === "TypeAlias" || _parent9.type === "VariableDeclarator" || _parent9.type === "TSTypeAliasDeclaration") && hasLeadingOwnLineComment$1(options.originalText, n, options)); // {
  21953. // a: string
  21954. // } | null | void
  21955. // should be inlined and not be printed in the multi-line variant
  21956. var shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
  21957. // | child1
  21958. // // comment
  21959. // | child2
  21960. var _printed4 = path.map(function (typePath) {
  21961. var printedType = typePath.call(print);
  21962. if (!shouldHug) {
  21963. printedType = align$1(2, printedType);
  21964. }
  21965. return comments.printComments(typePath, function () {
  21966. return printedType;
  21967. }, options);
  21968. }, "types");
  21969. if (shouldHug) {
  21970. return join$9(" | ", _printed4);
  21971. }
  21972. var shouldAddStartLine = shouldIndent && !hasLeadingOwnLineComment$1(options.originalText, n, options);
  21973. var code = concat$d([ifBreak$6(concat$d([shouldAddStartLine ? line$7 : "", "| "])), join$9(concat$d([line$7, "| "]), _printed4)]);
  21974. if (needsParens_1(path, options)) {
  21975. return group$b(concat$d([indent$7(code), softline$6]));
  21976. }
  21977. if (_parent9.type === "TupleTypeAnnotation" && _parent9.types.length > 1 || _parent9.type === "TSTupleType" && _parent9.elementTypes.length > 1) {
  21978. return group$b(concat$d([indent$7(concat$d([ifBreak$6(concat$d(["(", softline$6])), code])), softline$6, ifBreak$6(")")]));
  21979. }
  21980. return group$b(shouldIndent ? indent$7(code) : code);
  21981. }
  21982. case "NullableTypeAnnotation":
  21983. return concat$d(["?", path.call(print, "typeAnnotation")]);
  21984. case "TSNullKeyword":
  21985. case "NullLiteralTypeAnnotation":
  21986. return "null";
  21987. case "ThisTypeAnnotation":
  21988. return "this";
  21989. case "NumberTypeAnnotation":
  21990. return "number";
  21991. case "ObjectTypeCallProperty":
  21992. if (n.static) {
  21993. parts.push("static ");
  21994. }
  21995. parts.push(path.call(print, "value"));
  21996. return concat$d(parts);
  21997. case "ObjectTypeIndexer":
  21998. {
  21999. var _variance = getFlowVariance$1(n);
  22000. return concat$d([_variance || "", "[", path.call(print, "id"), n.id ? ": " : "", path.call(print, "key"), "]: ", path.call(print, "value")]);
  22001. }
  22002. case "ObjectTypeProperty":
  22003. {
  22004. var _variance2 = getFlowVariance$1(n);
  22005. var modifier = "";
  22006. if (n.proto) {
  22007. modifier = "proto ";
  22008. } else if (n.static) {
  22009. modifier = "static ";
  22010. }
  22011. return concat$d([modifier, isGetterOrSetter$1(n) ? n.kind + " " : "", _variance2 || "", printPropertyKey(path, options, print), printOptionalToken(path), isFunctionNotation$1(n, options) ? "" : ": ", path.call(print, "value")]);
  22012. }
  22013. case "QualifiedTypeIdentifier":
  22014. return concat$d([path.call(print, "qualification"), ".", path.call(print, "id")]);
  22015. case "StringLiteralTypeAnnotation":
  22016. return nodeStr(n, options);
  22017. case "NumberLiteralTypeAnnotation":
  22018. assert.strictEqual(_typeof(n.value), "number");
  22019. if (n.extra != null) {
  22020. return printNumber$2(n.extra.raw);
  22021. }
  22022. return printNumber$2(n.raw);
  22023. case "StringTypeAnnotation":
  22024. return "string";
  22025. case "DeclareTypeAlias":
  22026. case "TypeAlias":
  22027. {
  22028. if (n.type === "DeclareTypeAlias" || n.declare) {
  22029. parts.push("declare ");
  22030. }
  22031. var _printed5 = printAssignmentRight(n.id, n.right, path.call(print, "right"), options);
  22032. parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", _printed5, semi);
  22033. return group$b(concat$d(parts));
  22034. }
  22035. case "TypeCastExpression":
  22036. {
  22037. var value = path.getValue(); // Flow supports a comment syntax for specifying type annotations: https://flow.org/en/docs/types/comments/.
  22038. // Unfortunately, its parser doesn't differentiate between comment annotations and regular
  22039. // annotations when producing an AST. So to preserve parentheses around type casts that use
  22040. // the comment syntax, we need to hackily read the source itself to see if the code contains
  22041. // a type annotation comment.
  22042. //
  22043. // Note that we're able to use the normal whitespace regex here because the Flow parser has
  22044. // already deemed this AST node to be a type cast. Only the Babel parser needs the
  22045. // non-line-break whitespace regex, which is why hasFlowShorthandAnnotationComment() is
  22046. // implemented differently.
  22047. var commentSyntax = value && value.typeAnnotation && value.typeAnnotation.range && options.originalText.substring(value.typeAnnotation.range[0]).match(/^\/\*\s*:/);
  22048. return concat$d(["(", path.call(print, "expression"), commentSyntax ? " /*" : "", ": ", path.call(print, "typeAnnotation"), commentSyntax ? " */" : "", ")"]);
  22049. }
  22050. case "TypeParameterDeclaration":
  22051. case "TypeParameterInstantiation":
  22052. {
  22053. var _value = path.getValue();
  22054. var commentStart = _value.range ? options.originalText.substring(0, _value.range[0]).lastIndexOf("/*") : -1; // As noted in the TypeCastExpression comments above, we're able to use a normal whitespace regex here
  22055. // because we know for sure that this is a type definition.
  22056. var _commentSyntax = commentStart >= 0 && options.originalText.substring(commentStart).match(/^\/\*\s*::/);
  22057. if (_commentSyntax) {
  22058. return concat$d(["/*:: ", printTypeParameters(path, options, print, "params"), " */"]);
  22059. }
  22060. return printTypeParameters(path, options, print, "params");
  22061. }
  22062. case "TSTypeParameterDeclaration":
  22063. case "TSTypeParameterInstantiation":
  22064. return printTypeParameters(path, options, print, "params");
  22065. case "TSTypeParameter":
  22066. case "TypeParameter":
  22067. {
  22068. var _parent10 = path.getParentNode();
  22069. if (_parent10.type === "TSMappedType") {
  22070. parts.push("[", path.call(print, "name"));
  22071. if (n.constraint) {
  22072. parts.push(" in ", path.call(print, "constraint"));
  22073. }
  22074. parts.push("]");
  22075. return concat$d(parts);
  22076. }
  22077. var _variance3 = getFlowVariance$1(n);
  22078. if (_variance3) {
  22079. parts.push(_variance3);
  22080. }
  22081. parts.push(path.call(print, "name"));
  22082. if (n.bound) {
  22083. parts.push(": ");
  22084. parts.push(path.call(print, "bound"));
  22085. }
  22086. if (n.constraint) {
  22087. parts.push(" extends ", path.call(print, "constraint"));
  22088. }
  22089. if (n["default"]) {
  22090. parts.push(" = ", path.call(print, "default"));
  22091. } // Keep comma if the file extension is .tsx and
  22092. // has one type parameter that isn't extend with any types.
  22093. // Because, otherwise formatted result will be invalid as tsx.
  22094. var _grandParent = path.getNode(2);
  22095. if (_parent10.params && _parent10.params.length === 1 && isTSXFile$1(options) && !n.constraint && _grandParent.type === "ArrowFunctionExpression") {
  22096. parts.push(",");
  22097. }
  22098. return concat$d(parts);
  22099. }
  22100. case "TypeofTypeAnnotation":
  22101. return concat$d(["typeof ", path.call(print, "argument")]);
  22102. case "VoidTypeAnnotation":
  22103. return "void";
  22104. case "InferredPredicate":
  22105. return "%checks";
  22106. // Unhandled types below. If encountered, nodes of these types should
  22107. // be either left alone or desugared into AST types that are fully
  22108. // supported by the pretty-printer.
  22109. case "DeclaredPredicate":
  22110. return concat$d(["%checks(", path.call(print, "value"), ")"]);
  22111. case "TSAbstractKeyword":
  22112. return "abstract";
  22113. case "TSAnyKeyword":
  22114. return "any";
  22115. case "TSAsyncKeyword":
  22116. return "async";
  22117. case "TSBooleanKeyword":
  22118. return "boolean";
  22119. case "TSBigIntKeyword":
  22120. return "bigint";
  22121. case "TSConstKeyword":
  22122. return "const";
  22123. case "TSDeclareKeyword":
  22124. return "declare";
  22125. case "TSExportKeyword":
  22126. return "export";
  22127. case "TSNeverKeyword":
  22128. return "never";
  22129. case "TSNumberKeyword":
  22130. return "number";
  22131. case "TSObjectKeyword":
  22132. return "object";
  22133. case "TSProtectedKeyword":
  22134. return "protected";
  22135. case "TSPrivateKeyword":
  22136. return "private";
  22137. case "TSPublicKeyword":
  22138. return "public";
  22139. case "TSReadonlyKeyword":
  22140. return "readonly";
  22141. case "TSSymbolKeyword":
  22142. return "symbol";
  22143. case "TSStaticKeyword":
  22144. return "static";
  22145. case "TSStringKeyword":
  22146. return "string";
  22147. case "TSUndefinedKeyword":
  22148. return "undefined";
  22149. case "TSUnknownKeyword":
  22150. return "unknown";
  22151. case "TSVoidKeyword":
  22152. return "void";
  22153. case "TSAsExpression":
  22154. return concat$d([path.call(print, "expression"), " as ", path.call(print, "typeAnnotation")]);
  22155. case "TSArrayType":
  22156. return concat$d([path.call(print, "elementType"), "[]"]);
  22157. case "TSPropertySignature":
  22158. {
  22159. if (n.export) {
  22160. parts.push("export ");
  22161. }
  22162. if (n.accessibility) {
  22163. parts.push(n.accessibility + " ");
  22164. }
  22165. if (n.static) {
  22166. parts.push("static ");
  22167. }
  22168. if (n.readonly) {
  22169. parts.push("readonly ");
  22170. }
  22171. parts.push(printPropertyKey(path, options, print), printOptionalToken(path));
  22172. if (n.typeAnnotation) {
  22173. parts.push(": ");
  22174. parts.push(path.call(print, "typeAnnotation"));
  22175. } // This isn't valid semantically, but it's in the AST so we can print it.
  22176. if (n.initializer) {
  22177. parts.push(" = ", path.call(print, "initializer"));
  22178. }
  22179. return concat$d(parts);
  22180. }
  22181. case "TSParameterProperty":
  22182. if (n.accessibility) {
  22183. parts.push(n.accessibility + " ");
  22184. }
  22185. if (n.export) {
  22186. parts.push("export ");
  22187. }
  22188. if (n.static) {
  22189. parts.push("static ");
  22190. }
  22191. if (n.readonly) {
  22192. parts.push("readonly ");
  22193. }
  22194. parts.push(path.call(print, "parameter"));
  22195. return concat$d(parts);
  22196. case "TSTypeReference":
  22197. return concat$d([path.call(print, "typeName"), printTypeParameters(path, options, print, "typeParameters")]);
  22198. case "TSTypeQuery":
  22199. return concat$d(["typeof ", path.call(print, "exprName")]);
  22200. case "TSIndexSignature":
  22201. {
  22202. var _parent11 = path.getParentNode();
  22203. return concat$d([n.export ? "export " : "", n.accessibility ? concat$d([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", n.parameters ? concat$d(path.map(print, "parameters")) : "", "]: ", path.call(print, "typeAnnotation"), _parent11.type === "ClassBody" ? semi : ""]);
  22204. }
  22205. case "TSTypePredicate":
  22206. return concat$d([n.asserts ? "asserts " : "", path.call(print, "parameterName"), n.typeAnnotation ? concat$d([" is ", path.call(print, "typeAnnotation")]) : ""]);
  22207. case "TSNonNullExpression":
  22208. return concat$d([path.call(print, "expression"), "!"]);
  22209. case "TSThisType":
  22210. return "this";
  22211. case "TSImportType":
  22212. return concat$d([!n.isTypeOf ? "" : "typeof ", "import(", path.call(print, "parameter"), ")", !n.qualifier ? "" : concat$d([".", path.call(print, "qualifier")]), printTypeParameters(path, options, print, "typeParameters")]);
  22213. case "TSLiteralType":
  22214. return path.call(print, "literal");
  22215. case "TSIndexedAccessType":
  22216. return concat$d([path.call(print, "objectType"), "[", path.call(print, "indexType"), "]"]);
  22217. case "TSConstructSignatureDeclaration":
  22218. case "TSCallSignatureDeclaration":
  22219. case "TSConstructorType":
  22220. {
  22221. if (n.type !== "TSCallSignatureDeclaration") {
  22222. parts.push("new ");
  22223. }
  22224. parts.push(group$b(printFunctionParams(path, print, options,
  22225. /* expandArg */
  22226. false,
  22227. /* printTypeParams */
  22228. true)));
  22229. if (n.returnType) {
  22230. var isType = n.type === "TSConstructorType";
  22231. parts.push(isType ? " => " : ": ", path.call(print, "returnType"));
  22232. }
  22233. return concat$d(parts);
  22234. }
  22235. case "TSTypeOperator":
  22236. return concat$d([n.operator, " ", path.call(print, "typeAnnotation")]);
  22237. case "TSMappedType":
  22238. {
  22239. var _shouldBreak3 = hasNewlineInRange$2(options.originalText, options.locStart(n), options.locEnd(n));
  22240. return group$b(concat$d(["{", indent$7(concat$d([options.bracketSpacing ? line$7 : softline$6, n.readonly ? concat$d([getTypeScriptMappedTypeModifier$1(n.readonly, "readonly"), " "]) : "", printTypeScriptModifiers(path, options, print), path.call(print, "typeParameter"), n.optional ? getTypeScriptMappedTypeModifier$1(n.optional, "?") : "", ": ", path.call(print, "typeAnnotation"), ifBreak$6(semi, "")])), comments.printDanglingComments(path, options,
  22241. /* sameIndent */
  22242. true), options.bracketSpacing ? line$7 : softline$6, "}"]), {
  22243. shouldBreak: _shouldBreak3
  22244. });
  22245. }
  22246. case "TSMethodSignature":
  22247. parts.push(n.accessibility ? concat$d([n.accessibility, " "]) : "", n.export ? "export " : "", n.static ? "static " : "", n.readonly ? "readonly " : "", n.computed ? "[" : "", path.call(print, "key"), n.computed ? "]" : "", printOptionalToken(path), printFunctionParams(path, print, options,
  22248. /* expandArg */
  22249. false,
  22250. /* printTypeParams */
  22251. true));
  22252. if (n.returnType) {
  22253. parts.push(": ", path.call(print, "returnType"));
  22254. }
  22255. return group$b(concat$d(parts));
  22256. case "TSNamespaceExportDeclaration":
  22257. parts.push("export as namespace ", path.call(print, "id"));
  22258. if (options.semi) {
  22259. parts.push(";");
  22260. }
  22261. return group$b(concat$d(parts));
  22262. case "TSEnumDeclaration":
  22263. if (n.declare) {
  22264. parts.push("declare ");
  22265. }
  22266. if (n.modifiers) {
  22267. parts.push(printTypeScriptModifiers(path, options, print));
  22268. }
  22269. if (n.const) {
  22270. parts.push("const ");
  22271. }
  22272. parts.push("enum ", path.call(print, "id"), " ");
  22273. if (n.members.length === 0) {
  22274. parts.push(group$b(concat$d(["{", comments.printDanglingComments(path, options), softline$6, "}"])));
  22275. } else {
  22276. parts.push(group$b(concat$d(["{", indent$7(concat$d([hardline$9, printArrayItems(path, options, "members", print), shouldPrintComma$1(options, "es5") ? "," : ""])), comments.printDanglingComments(path, options,
  22277. /* sameIndent */
  22278. true), hardline$9, "}"])));
  22279. }
  22280. return concat$d(parts);
  22281. case "TSEnumMember":
  22282. parts.push(path.call(print, "id"));
  22283. if (n.initializer) {
  22284. parts.push(" = ", path.call(print, "initializer"));
  22285. }
  22286. return concat$d(parts);
  22287. case "TSImportEqualsDeclaration":
  22288. if (n.isExport) {
  22289. parts.push("export ");
  22290. }
  22291. parts.push("import ", path.call(print, "id"), " = ", path.call(print, "moduleReference"));
  22292. if (options.semi) {
  22293. parts.push(";");
  22294. }
  22295. return group$b(concat$d(parts));
  22296. case "TSExternalModuleReference":
  22297. return concat$d(["require(", path.call(print, "expression"), ")"]);
  22298. case "TSModuleDeclaration":
  22299. {
  22300. var _parent12 = path.getParentNode();
  22301. var isExternalModule = isLiteral$1(n.id);
  22302. var parentIsDeclaration = _parent12.type === "TSModuleDeclaration";
  22303. var bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  22304. if (parentIsDeclaration) {
  22305. parts.push(".");
  22306. } else {
  22307. if (n.declare) {
  22308. parts.push("declare ");
  22309. }
  22310. parts.push(printTypeScriptModifiers(path, options, print));
  22311. var textBetweenNodeAndItsId = options.originalText.slice(options.locStart(n), options.locStart(n.id)); // Global declaration looks like this:
  22312. // (declare)? global { ... }
  22313. var isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(textBetweenNodeAndItsId);
  22314. if (!isGlobalDeclaration) {
  22315. parts.push(isExternalModule || /(^|\s)module(\s|$)/.test(textBetweenNodeAndItsId) ? "module " : "namespace ");
  22316. }
  22317. }
  22318. parts.push(path.call(print, "id"));
  22319. if (bodyIsDeclaration) {
  22320. parts.push(path.call(print, "body"));
  22321. } else if (n.body) {
  22322. parts.push(" ", group$b(path.call(print, "body")));
  22323. } else {
  22324. parts.push(semi);
  22325. }
  22326. return concat$d(parts);
  22327. }
  22328. case "PrivateName":
  22329. return concat$d(["#", path.call(print, "id")]);
  22330. case "TSConditionalType":
  22331. return printTernaryOperator(path, options, print, {
  22332. beforeParts: function beforeParts() {
  22333. return [path.call(print, "checkType"), " ", "extends", " ", path.call(print, "extendsType")];
  22334. },
  22335. afterParts: function afterParts() {
  22336. return [];
  22337. },
  22338. shouldCheckJsx: false,
  22339. conditionalNodeType: "TSConditionalType",
  22340. consequentNodePropertyName: "trueType",
  22341. alternateNodePropertyName: "falseType",
  22342. testNodePropertyName: "checkType",
  22343. breakNested: true
  22344. });
  22345. case "TSInferType":
  22346. return concat$d(["infer", " ", path.call(print, "typeParameter")]);
  22347. case "InterpreterDirective":
  22348. parts.push("#!", n.value, hardline$9);
  22349. if (isNextLineEmpty$4(options.originalText, n, options)) {
  22350. parts.push(hardline$9);
  22351. }
  22352. return concat$d(parts);
  22353. case "NGRoot":
  22354. return concat$d([].concat(path.call(print, "node"), !n.node.comments || n.node.comments.length === 0 ? [] : concat$d([" //", n.node.comments[0].value.trimRight()])));
  22355. case "NGChainedExpression":
  22356. return group$b(join$9(concat$d([";", line$7]), path.map(function (childPath) {
  22357. return hasNgSideEffect$1(childPath) ? print(childPath) : concat$d(["(", print(childPath), ")"]);
  22358. }, "expressions")));
  22359. case "NGEmptyExpression":
  22360. return "";
  22361. case "NGQuotedExpression":
  22362. return concat$d([n.prefix, ":", n.value]);
  22363. case "NGMicrosyntax":
  22364. return concat$d(path.map(function (childPath, index) {
  22365. return concat$d([index === 0 ? "" : isNgForOf$1(childPath.getValue(), index, n) ? " " : concat$d([";", line$7]), print(childPath)]);
  22366. }, "body"));
  22367. case "NGMicrosyntaxKey":
  22368. return /^[a-z_$][a-z0-9_$]*(-[a-z_$][a-z0-9_$])*$/i.test(n.name) ? n.name : JSON.stringify(n.name);
  22369. case "NGMicrosyntaxExpression":
  22370. return concat$d([path.call(print, "expression"), n.alias === null ? "" : concat$d([" as ", path.call(print, "alias")])]);
  22371. case "NGMicrosyntaxKeyedExpression":
  22372. {
  22373. var index = path.getName();
  22374. var _parentNode2 = path.getParentNode();
  22375. var shouldNotPrintColon = isNgForOf$1(n, index, _parentNode2) || (index === 1 && (n.key.name === "then" || n.key.name === "else") || index === 2 && n.key.name === "else" && _parentNode2.body[index - 1].type === "NGMicrosyntaxKeyedExpression" && _parentNode2.body[index - 1].key.name === "then") && _parentNode2.body[0].type === "NGMicrosyntaxExpression";
  22376. return concat$d([path.call(print, "key"), shouldNotPrintColon ? " " : ": ", path.call(print, "expression")]);
  22377. }
  22378. case "NGMicrosyntaxLet":
  22379. return concat$d(["let ", path.call(print, "key"), n.value === null ? "" : concat$d([" = ", path.call(print, "value")])]);
  22380. case "NGMicrosyntaxAs":
  22381. return concat$d([path.call(print, "key"), " as ", path.call(print, "alias")]);
  22382. case "ArgumentPlaceholder":
  22383. return "?";
  22384. default:
  22385. /* istanbul ignore next */
  22386. throw new Error("unknown type: " + JSON.stringify(n.type));
  22387. }
  22388. }
  22389. function printStatementSequence(path, options, print) {
  22390. var printed = [];
  22391. var bodyNode = path.getNode();
  22392. var isClass = bodyNode.type === "ClassBody";
  22393. path.map(function (stmtPath, i) {
  22394. var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
  22395. // "statements," it's safer simply to skip them.
  22396. /* istanbul ignore if */
  22397. if (!stmt) {
  22398. return;
  22399. } // Skip printing EmptyStatement nodes to avoid leaving stray
  22400. // semicolons lying around.
  22401. if (stmt.type === "EmptyStatement") {
  22402. return;
  22403. }
  22404. var stmtPrinted = print(stmtPath);
  22405. var text = options.originalText;
  22406. var parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
  22407. // don't prepend the only JSX element in a program with semicolon
  22408. if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown$1(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
  22409. if (stmt.comments && stmt.comments.some(function (comment) {
  22410. return comment.leading;
  22411. })) {
  22412. parts.push(print(stmtPath, {
  22413. needsSemi: true
  22414. }));
  22415. } else {
  22416. parts.push(";", stmtPrinted);
  22417. }
  22418. } else {
  22419. parts.push(stmtPrinted);
  22420. }
  22421. if (!options.semi && isClass) {
  22422. if (classPropMayCauseASIProblems$1(stmtPath)) {
  22423. parts.push(";");
  22424. } else if (stmt.type === "ClassProperty") {
  22425. var nextChild = bodyNode.body[i + 1];
  22426. if (classChildNeedsASIProtection$1(nextChild)) {
  22427. parts.push(";");
  22428. }
  22429. }
  22430. }
  22431. if (isNextLineEmpty$4(text, stmt, options) && !isLastStatement$1(stmtPath)) {
  22432. parts.push(hardline$9);
  22433. }
  22434. printed.push(concat$d(parts));
  22435. });
  22436. return join$9(hardline$9, printed);
  22437. }
  22438. function printPropertyKey(path, options, print) {
  22439. var node = path.getNode();
  22440. if (node.computed) {
  22441. return concat$d(["[", path.call(print, "key"), "]"]);
  22442. }
  22443. var parent = path.getParentNode();
  22444. var key = node.key;
  22445. if (options.quoteProps === "consistent" && !needsQuoteProps.has(parent)) {
  22446. var objectHasStringProp = (parent.properties || parent.body || parent.members).some(function (prop) {
  22447. return !prop.computed && prop.key && isStringLiteral$1(prop.key) && !isStringPropSafeToCoerceToIdentifier$1(prop, options);
  22448. });
  22449. needsQuoteProps.set(parent, objectHasStringProp);
  22450. }
  22451. if (key.type === "Identifier" && (options.parser === "json" || options.quoteProps === "consistent" && needsQuoteProps.get(parent))) {
  22452. // a -> "a"
  22453. var prop = printString$2(JSON.stringify(key.name), options);
  22454. return path.call(function (keyPath) {
  22455. return comments.printComments(keyPath, function () {
  22456. return prop;
  22457. }, options);
  22458. }, "key");
  22459. }
  22460. if (isStringPropSafeToCoerceToIdentifier$1(node, options) && (options.quoteProps === "as-needed" || options.quoteProps === "consistent" && !needsQuoteProps.get(parent))) {
  22461. // 'a' -> a
  22462. return path.call(function (keyPath) {
  22463. return comments.printComments(keyPath, function () {
  22464. return key.value;
  22465. }, options);
  22466. }, "key");
  22467. }
  22468. return path.call(print, "key");
  22469. }
  22470. function printMethod(path, options, print) {
  22471. var node = path.getNode();
  22472. var kind = node.kind;
  22473. var value = node.value || node;
  22474. var parts = [];
  22475. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  22476. if (value.async) {
  22477. parts.push("async ");
  22478. }
  22479. if (value.generator) {
  22480. parts.push("*");
  22481. }
  22482. } else {
  22483. assert.ok(kind === "get" || kind === "set");
  22484. parts.push(kind, " ");
  22485. }
  22486. parts.push(printPropertyKey(path, options, print), node.optional || node.key.optional ? "?" : "", node === value ? printMethodInternal(path, options, print) : path.call(function (path) {
  22487. return printMethodInternal(path, options, print);
  22488. }, "value"));
  22489. return concat$d(parts);
  22490. }
  22491. function printMethodInternal(path, options, print) {
  22492. var parts = [printFunctionTypeParameters(path, options, print), group$b(concat$d([printFunctionParams(path, print, options), printReturnType(path, print, options)]))];
  22493. if (path.getNode().body) {
  22494. parts.push(" ", path.call(print, "body"));
  22495. } else {
  22496. parts.push(options.semi ? ";" : "");
  22497. }
  22498. return concat$d(parts);
  22499. }
  22500. function couldGroupArg(arg) {
  22501. return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertion" && couldGroupArg(arg.expression) || arg.type === "TSAsExpression" && couldGroupArg(arg.expression) || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && ( // we want to avoid breaking inside composite return types but not simple keywords
  22502. // https://github.com/prettier/prettier/issues/4070
  22503. // export class Thing implements OtherThing {
  22504. // do: (type: Type) => Provider<Prop> = memoize(
  22505. // (type: ObjectType): Provider<Opts> => {}
  22506. // );
  22507. // }
  22508. // https://github.com/prettier/prettier/issues/6099
  22509. // app.get("/", (req, res): void => {
  22510. // res.send("Hello World!");
  22511. // });
  22512. !arg.returnType || !arg.returnType.typeAnnotation || arg.returnType.typeAnnotation.type !== "TSTypeReference") && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode$1(arg.body));
  22513. }
  22514. function shouldGroupLastArg(args) {
  22515. var lastArg = getLast$2(args);
  22516. var penultimateArg = getPenultimate$1(args);
  22517. return !hasLeadingComment$3(lastArg) && !hasTrailingComment$1(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
  22518. // disable last element expansion.
  22519. !penultimateArg || penultimateArg.type !== lastArg.type);
  22520. }
  22521. function shouldGroupFirstArg(args) {
  22522. if (args.length !== 2) {
  22523. return false;
  22524. }
  22525. var firstArg = args[0];
  22526. var secondArg = args[1];
  22527. return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && secondArg.type !== "FunctionExpression" && secondArg.type !== "ArrowFunctionExpression" && secondArg.type !== "ConditionalExpression" && !couldGroupArg(secondArg);
  22528. }
  22529. function printJestEachTemplateLiteral(node, expressions, options) {
  22530. /**
  22531. * a | b | expected
  22532. * ${1} | ${1} | ${2}
  22533. * ${1} | ${2} | ${3}
  22534. * ${2} | ${1} | ${3}
  22535. */
  22536. var headerNames = node.quasis[0].value.raw.trim().split(/\s*\|\s*/);
  22537. if (headerNames.length > 1 || headerNames.some(function (headerName) {
  22538. return headerName.length !== 0;
  22539. })) {
  22540. var parts = [];
  22541. var stringifiedExpressions = expressions.map(function (doc) {
  22542. return "${" + printDocToString$1(doc, Object.assign({}, options, {
  22543. printWidth: Infinity,
  22544. endOfLine: "lf"
  22545. })).formatted + "}";
  22546. });
  22547. var tableBody = [{
  22548. hasLineBreak: false,
  22549. cells: []
  22550. }];
  22551. for (var i = 1; i < node.quasis.length; i++) {
  22552. var row = tableBody[tableBody.length - 1];
  22553. var correspondingExpression = stringifiedExpressions[i - 1];
  22554. row.cells.push(correspondingExpression);
  22555. if (correspondingExpression.indexOf("\n") !== -1) {
  22556. row.hasLineBreak = true;
  22557. }
  22558. if (node.quasis[i].value.raw.indexOf("\n") !== -1) {
  22559. tableBody.push({
  22560. hasLineBreak: false,
  22561. cells: []
  22562. });
  22563. }
  22564. }
  22565. var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
  22566. return Math.max(maxColumnCount, row.cells.length);
  22567. }, headerNames.length);
  22568. var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
  22569. return 0;
  22570. });
  22571. var table = [{
  22572. cells: headerNames
  22573. }].concat(tableBody.filter(function (row) {
  22574. return row.cells.length !== 0;
  22575. }));
  22576. table.filter(function (row) {
  22577. return !row.hasLineBreak;
  22578. }).forEach(function (row) {
  22579. row.cells.forEach(function (cell, index) {
  22580. maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$2(cell));
  22581. });
  22582. });
  22583. parts.push(lineSuffixBoundary$1, "`", indent$7(concat$d([hardline$9, join$9(hardline$9, table.map(function (row) {
  22584. return join$9(" | ", row.cells.map(function (cell, index) {
  22585. return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$2(cell));
  22586. }));
  22587. }))])), hardline$9, "`");
  22588. return concat$d(parts);
  22589. }
  22590. }
  22591. function printArgumentsList(path, options, print) {
  22592. var node = path.getValue();
  22593. var args = node.arguments;
  22594. if (args.length === 0) {
  22595. return concat$d(["(", comments.printDanglingComments(path, options,
  22596. /* sameIndent */
  22597. true), ")"]);
  22598. } // useEffect(() => { ... }, [foo, bar, baz])
  22599. if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].params.length === 0 && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.find(function (arg) {
  22600. return arg.comments;
  22601. })) {
  22602. return concat$d(["(", path.call(print, "arguments", 0), ", ", path.call(print, "arguments", 1), ")"]);
  22603. } // func(
  22604. // ({
  22605. // a,
  22606. // b
  22607. // }) => {}
  22608. // );
  22609. function shouldBreakForArrowFunctionInArguments(arg, argPath) {
  22610. if (!arg || arg.type !== "ArrowFunctionExpression" || !arg.body || arg.body.type !== "BlockStatement" || !arg.params || arg.params.length < 1) {
  22611. return false;
  22612. }
  22613. var shouldBreak = false;
  22614. argPath.each(function (paramPath) {
  22615. var printed = concat$d([print(paramPath)]);
  22616. shouldBreak = shouldBreak || willBreak$1(printed);
  22617. }, "params");
  22618. return shouldBreak;
  22619. }
  22620. var anyArgEmptyLine = false;
  22621. var shouldBreakForArrowFunction = false;
  22622. var hasEmptyLineFollowingFirstArg = false;
  22623. var lastArgIndex = args.length - 1;
  22624. var printedArguments = path.map(function (argPath, index) {
  22625. var arg = argPath.getNode();
  22626. var parts = [print(argPath)];
  22627. if (index === lastArgIndex) ; else if (isNextLineEmpty$4(options.originalText, arg, options)) {
  22628. if (index === 0) {
  22629. hasEmptyLineFollowingFirstArg = true;
  22630. }
  22631. anyArgEmptyLine = true;
  22632. parts.push(",", hardline$9, hardline$9);
  22633. } else {
  22634. parts.push(",", line$7);
  22635. }
  22636. shouldBreakForArrowFunction = shouldBreakForArrowFunctionInArguments(arg, argPath);
  22637. return concat$d(parts);
  22638. }, "arguments");
  22639. var maybeTrailingComma = // Dynamic imports cannot have trailing commas
  22640. !(node.callee && node.callee.type === "Import") && shouldPrintComma$1(options, "all") ? "," : "";
  22641. function allArgsBrokenOut() {
  22642. return group$b(concat$d(["(", indent$7(concat$d([line$7, concat$d(printedArguments)])), maybeTrailingComma, line$7, ")"]), {
  22643. shouldBreak: true
  22644. });
  22645. }
  22646. if (isFunctionCompositionArgs$1(args)) {
  22647. return allArgsBrokenOut();
  22648. }
  22649. var shouldGroupFirst = shouldGroupFirstArg(args);
  22650. var shouldGroupLast = shouldGroupLastArg(args);
  22651. if (shouldGroupFirst || shouldGroupLast) {
  22652. var shouldBreak = (shouldGroupFirst ? printedArguments.slice(1).some(willBreak$1) : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine || shouldBreakForArrowFunction; // We want to print the last argument with a special flag
  22653. var printedExpanded;
  22654. var i = 0;
  22655. path.each(function (argPath) {
  22656. if (shouldGroupFirst && i === 0) {
  22657. printedExpanded = [concat$d([argPath.call(function (p) {
  22658. return print(p, {
  22659. expandFirstArg: true
  22660. });
  22661. }), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$9 : line$7, hasEmptyLineFollowingFirstArg ? hardline$9 : ""])].concat(printedArguments.slice(1));
  22662. }
  22663. if (shouldGroupLast && i === args.length - 1) {
  22664. printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(function (p) {
  22665. return print(p, {
  22666. expandLastArg: true
  22667. });
  22668. }));
  22669. }
  22670. i++;
  22671. }, "arguments");
  22672. var somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  22673. var simpleConcat = concat$d(["(", concat$d(printedExpanded), ")"]);
  22674. return concat$d([somePrintedArgumentsWillBreak ? breakParent$3 : "", conditionalGroup$1([!somePrintedArgumentsWillBreak && !node.typeArguments && !node.typeParameters ? simpleConcat : ifBreak$6(allArgsBrokenOut(), simpleConcat), shouldGroupFirst ? concat$d(["(", group$b(printedExpanded[0], {
  22675. shouldBreak: true
  22676. }), concat$d(printedExpanded.slice(1)), ")"]) : concat$d(["(", concat$d(printedArguments.slice(0, -1)), group$b(getLast$2(printedExpanded), {
  22677. shouldBreak: true
  22678. }), ")"]), allArgsBrokenOut()], {
  22679. shouldBreak: shouldBreak
  22680. })]);
  22681. }
  22682. var contents = concat$d(["(", indent$7(concat$d([softline$6, concat$d(printedArguments)])), ifBreak$6(maybeTrailingComma), softline$6, ")"]);
  22683. if (isLongCurriedCallExpression$1(path)) {
  22684. // By not wrapping the arguments in a group, the printer prioritizes
  22685. // breaking up these arguments rather than the args of the parent call.
  22686. return contents;
  22687. }
  22688. return group$b(contents, {
  22689. shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
  22690. });
  22691. }
  22692. function printTypeAnnotation(path, options, print) {
  22693. var node = path.getValue();
  22694. if (!node.typeAnnotation) {
  22695. return "";
  22696. }
  22697. var parentNode = path.getParentNode();
  22698. var isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
  22699. var isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
  22700. if (isFlowAnnotationComment$1(options.originalText, node.typeAnnotation, options)) {
  22701. return concat$d([" /*: ", path.call(print, "typeAnnotation"), " */"]);
  22702. }
  22703. return concat$d([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path.call(print, "typeAnnotation")]);
  22704. }
  22705. function printFunctionTypeParameters(path, options, print) {
  22706. var fun = path.getValue();
  22707. if (fun.typeArguments) {
  22708. return path.call(print, "typeArguments");
  22709. }
  22710. if (fun.typeParameters) {
  22711. return path.call(print, "typeParameters");
  22712. }
  22713. return "";
  22714. }
  22715. function printFunctionParams(path, print, options, expandArg, printTypeParams) {
  22716. var fun = path.getValue();
  22717. var parent = path.getParentNode();
  22718. var paramsField = fun.parameters ? "parameters" : "params";
  22719. var isParametersInTestCall = isTestCall$1(parent);
  22720. var shouldHugParameters = shouldHugArguments(fun);
  22721. var shouldExpandParameters = expandArg && !(fun[paramsField] && fun[paramsField].some(function (n) {
  22722. return n.comments;
  22723. }));
  22724. var typeParams = printTypeParams ? printFunctionTypeParameters(path, options, print) : "";
  22725. var printed = [];
  22726. if (fun[paramsField]) {
  22727. var lastArgIndex = fun[paramsField].length - 1;
  22728. printed = path.map(function (childPath, index) {
  22729. var parts = [];
  22730. var param = childPath.getValue();
  22731. parts.push(print(childPath));
  22732. if (index === lastArgIndex) {
  22733. if (fun.rest) {
  22734. parts.push(",", line$7);
  22735. }
  22736. } else if (isParametersInTestCall || shouldHugParameters || shouldExpandParameters) {
  22737. parts.push(", ");
  22738. } else if (isNextLineEmpty$4(options.originalText, param, options)) {
  22739. parts.push(",", hardline$9, hardline$9);
  22740. } else {
  22741. parts.push(",", line$7);
  22742. }
  22743. return concat$d(parts);
  22744. }, paramsField);
  22745. }
  22746. if (fun.rest) {
  22747. printed.push(concat$d(["...", path.call(print, "rest")]));
  22748. }
  22749. if (printed.length === 0) {
  22750. return concat$d([typeParams, "(", comments.printDanglingComments(path, options,
  22751. /* sameIndent */
  22752. true, function (comment) {
  22753. return getNextNonSpaceNonCommentCharacter$1(options.originalText, comment, options.locEnd) === ")";
  22754. }), ")"]);
  22755. }
  22756. var lastParam = getLast$2(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
  22757. // params of the first/last argument, we don't want the arguments to break and instead
  22758. // want the whole expression to be on a new line.
  22759. //
  22760. // Good: Bad:
  22761. // verylongcall( verylongcall((
  22762. // (a, b) => { a,
  22763. // } b,
  22764. // }) ) => {
  22765. // })
  22766. if (shouldExpandParameters) {
  22767. return group$b(concat$d([removeLines$2(typeParams), "(", concat$d(printed.map(removeLines$2)), ")"]));
  22768. } // Single object destructuring should hug
  22769. //
  22770. // function({
  22771. // a,
  22772. // b,
  22773. // c
  22774. // }) {}
  22775. var hasNotParameterDecorator = fun[paramsField].every(function (param) {
  22776. return !param.decorators;
  22777. });
  22778. if (shouldHugParameters && hasNotParameterDecorator) {
  22779. return concat$d([typeParams, "(", concat$d(printed), ")"]);
  22780. } // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  22781. if (isParametersInTestCall) {
  22782. return concat$d([typeParams, "(", concat$d(printed), ")"]);
  22783. }
  22784. var isFlowShorthandWithOneArg = (isObjectTypePropertyAFunction$1(parent, options) || isTypeAnnotationAFunction$1(parent, options) || parent.type === "TypeAlias" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || parent.type === "IntersectionTypeAnnotation" || parent.type === "FunctionTypeAnnotation" && parent.returnType === fun) && fun[paramsField].length === 1 && fun[paramsField][0].name === null && fun[paramsField][0].typeAnnotation && fun.typeParameters === null && isSimpleFlowType$1(fun[paramsField][0].typeAnnotation) && !fun.rest;
  22785. if (isFlowShorthandWithOneArg) {
  22786. if (options.arrowParens === "always") {
  22787. return concat$d(["(", concat$d(printed), ")"]);
  22788. }
  22789. return concat$d(printed);
  22790. }
  22791. var canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  22792. return concat$d([typeParams, "(", indent$7(concat$d([softline$6, concat$d(printed)])), ifBreak$6(canHaveTrailingComma && shouldPrintComma$1(options, "all") ? "," : ""), softline$6, ")"]);
  22793. }
  22794. function shouldPrintParamsWithoutParens(path, options) {
  22795. if (options.arrowParens === "always") {
  22796. return false;
  22797. }
  22798. if (options.arrowParens === "avoid") {
  22799. var node = path.getValue();
  22800. return canPrintParamsWithoutParens(node);
  22801. } // Fallback default; should be unreachable
  22802. return false;
  22803. }
  22804. function canPrintParamsWithoutParens(node) {
  22805. return node.params.length === 1 && !node.rest && !node.typeParameters && !hasDanglingComments$1(node) && node.params[0].type === "Identifier" && !node.params[0].typeAnnotation && !node.params[0].comments && !node.params[0].optional && !node.predicate && !node.returnType;
  22806. }
  22807. function printFunctionDeclaration(path, print, options) {
  22808. var n = path.getValue();
  22809. var parts = [];
  22810. if (n.async) {
  22811. parts.push("async ");
  22812. }
  22813. parts.push("function");
  22814. if (n.generator) {
  22815. parts.push("*");
  22816. }
  22817. if (n.id) {
  22818. parts.push(" ", path.call(print, "id"));
  22819. }
  22820. parts.push(printFunctionTypeParameters(path, options, print), group$b(concat$d([printFunctionParams(path, print, options), printReturnType(path, print, options)])), n.body ? " " : "", path.call(print, "body"));
  22821. return concat$d(parts);
  22822. }
  22823. function printReturnType(path, print, options) {
  22824. var n = path.getValue();
  22825. var returnType = path.call(print, "returnType");
  22826. if (n.returnType && isFlowAnnotationComment$1(options.originalText, n.returnType, options)) {
  22827. return concat$d([" /*: ", returnType, " */"]);
  22828. }
  22829. var parts = [returnType]; // prepend colon to TypeScript type annotation
  22830. if (n.returnType && n.returnType.typeAnnotation) {
  22831. parts.unshift(": ");
  22832. }
  22833. if (n.predicate) {
  22834. // The return type will already add the colon, but otherwise we
  22835. // need to do it ourselves
  22836. parts.push(n.returnType ? " " : ": ", path.call(print, "predicate"));
  22837. }
  22838. return concat$d(parts);
  22839. }
  22840. function printExportDeclaration(path, options, print) {
  22841. var decl = path.getValue();
  22842. var semi = options.semi ? ";" : "";
  22843. var parts = ["export "];
  22844. var isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  22845. if (isDefault) {
  22846. parts.push("default ");
  22847. }
  22848. parts.push(comments.printDanglingComments(path, options,
  22849. /* sameIndent */
  22850. true));
  22851. if (needsHardlineAfterDanglingComment$1(decl)) {
  22852. parts.push(hardline$9);
  22853. }
  22854. if (decl.declaration) {
  22855. parts.push(path.call(print, "declaration"));
  22856. if (isDefault && decl.declaration.type !== "ClassDeclaration" && decl.declaration.type !== "FunctionDeclaration" && decl.declaration.type !== "TSInterfaceDeclaration" && decl.declaration.type !== "DeclareClass" && decl.declaration.type !== "DeclareFunction" && decl.declaration.type !== "TSDeclareFunction") {
  22857. parts.push(semi);
  22858. }
  22859. } else {
  22860. if (decl.specifiers && decl.specifiers.length > 0) {
  22861. var specifiers = [];
  22862. var defaultSpecifiers = [];
  22863. var namespaceSpecifiers = [];
  22864. path.each(function (specifierPath) {
  22865. var specifierType = path.getValue().type;
  22866. if (specifierType === "ExportSpecifier") {
  22867. specifiers.push(print(specifierPath));
  22868. } else if (specifierType === "ExportDefaultSpecifier") {
  22869. defaultSpecifiers.push(print(specifierPath));
  22870. } else if (specifierType === "ExportNamespaceSpecifier") {
  22871. namespaceSpecifiers.push(concat$d(["* as ", print(specifierPath)]));
  22872. }
  22873. }, "specifiers");
  22874. var isNamespaceFollowed = namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  22875. var isDefaultFollowed = defaultSpecifiers.length !== 0 && (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  22876. var canBreak = specifiers.length > 1 || defaultSpecifiers.length > 0 || decl.specifiers && decl.specifiers.some(function (node) {
  22877. return node.comments;
  22878. });
  22879. var printed = "";
  22880. if (specifiers.length !== 0) {
  22881. if (canBreak) {
  22882. printed = group$b(concat$d(["{", indent$7(concat$d([options.bracketSpacing ? line$7 : softline$6, join$9(concat$d([",", line$7]), specifiers)])), ifBreak$6(shouldPrintComma$1(options) ? "," : ""), options.bracketSpacing ? line$7 : softline$6, "}"]));
  22883. } else {
  22884. printed = concat$d(["{", options.bracketSpacing ? " " : "", concat$d(specifiers), options.bracketSpacing ? " " : "", "}"]);
  22885. }
  22886. }
  22887. parts.push(decl.exportKind === "type" ? "type " : "", concat$d(defaultSpecifiers), concat$d([isDefaultFollowed ? ", " : ""]), concat$d(namespaceSpecifiers), concat$d([isNamespaceFollowed ? ", " : ""]), printed);
  22888. } else {
  22889. parts.push("{}");
  22890. }
  22891. if (decl.source) {
  22892. parts.push(" from ", path.call(print, "source"));
  22893. }
  22894. parts.push(semi);
  22895. }
  22896. return concat$d(parts);
  22897. }
  22898. function printFlowDeclaration(path, parts) {
  22899. var parentExportDecl = getParentExportDeclaration$1(path);
  22900. if (parentExportDecl) {
  22901. assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  22902. } else {
  22903. // If the parent node has type DeclareExportDeclaration, then it
  22904. // will be responsible for printing the "declare" token. Otherwise
  22905. // it needs to be printed with this non-exported declaration node.
  22906. parts.unshift("declare ");
  22907. }
  22908. return concat$d(parts);
  22909. }
  22910. function printTypeScriptModifiers(path, options, print) {
  22911. var n = path.getValue();
  22912. if (!n.modifiers || !n.modifiers.length) {
  22913. return "";
  22914. }
  22915. return concat$d([join$9(" ", path.map(print, "modifiers")), " "]);
  22916. }
  22917. function printTypeParameters(path, options, print, paramsKey) {
  22918. var n = path.getValue();
  22919. if (!n[paramsKey]) {
  22920. return "";
  22921. } // for TypeParameterDeclaration typeParameters is a single node
  22922. if (!Array.isArray(n[paramsKey])) {
  22923. return path.call(print, paramsKey);
  22924. }
  22925. var grandparent = path.getNode(2);
  22926. var greatGreatGrandParent = path.getNode(4);
  22927. var isParameterInTestCall = grandparent != null && isTestCall$1(grandparent);
  22928. var shouldInline = isParameterInTestCall || n[paramsKey].length === 0 || n[paramsKey].length === 1 && (shouldHugType(n[paramsKey][0]) || n[paramsKey][0].type === "GenericTypeAnnotation" && shouldHugType(n[paramsKey][0].id) || n[paramsKey][0].type === "TSTypeReference" && shouldHugType(n[paramsKey][0].typeName) || n[paramsKey][0].type === "NullableTypeAnnotation" || // See https://github.com/prettier/prettier/pull/6467 for the context.
  22929. greatGreatGrandParent && greatGreatGrandParent.type === "VariableDeclarator" && grandparent && grandparent.type === "TSTypeAnnotation" && n[paramsKey][0].type !== "TSUnionType" && n[paramsKey][0].type !== "UnionTypeAnnotation" && n[paramsKey][0].type !== "TSConditionalType" && n[paramsKey][0].type !== "TSMappedType");
  22930. if (shouldInline) {
  22931. return concat$d(["<", join$9(", ", path.map(print, paramsKey)), ">"]);
  22932. }
  22933. return group$b(concat$d(["<", indent$7(concat$d([softline$6, join$9(concat$d([",", line$7]), path.map(print, paramsKey))])), ifBreak$6(options.parser !== "typescript" && shouldPrintComma$1(options, "all") ? "," : ""), softline$6, ">"]));
  22934. }
  22935. function printClass(path, options, print) {
  22936. var n = path.getValue();
  22937. var parts = [];
  22938. if (n.abstract) {
  22939. parts.push("abstract ");
  22940. }
  22941. parts.push("class");
  22942. if (n.id) {
  22943. parts.push(" ", path.call(print, "id"));
  22944. }
  22945. parts.push(path.call(print, "typeParameters"));
  22946. var partsGroup = [];
  22947. if (n.superClass) {
  22948. var printed = concat$d(["extends ", path.call(print, "superClass"), path.call(print, "superTypeParameters")]); // Keep old behaviour of extends in same line
  22949. // If there is only on extends and there are not comments
  22950. if ((!n.implements || n.implements.length === 0) && (!n.superClass.comments || n.superClass.comments.length === 0)) {
  22951. parts.push(concat$d([" ", path.call(function (superClass) {
  22952. return comments.printComments(superClass, function () {
  22953. return printed;
  22954. }, options);
  22955. }, "superClass")]));
  22956. } else {
  22957. partsGroup.push(group$b(concat$d([line$7, path.call(function (superClass) {
  22958. return comments.printComments(superClass, function () {
  22959. return printed;
  22960. }, options);
  22961. }, "superClass")])));
  22962. }
  22963. } else if (n.extends && n.extends.length > 0) {
  22964. parts.push(" extends ", join$9(", ", path.map(print, "extends")));
  22965. }
  22966. if (n["mixins"] && n["mixins"].length > 0) {
  22967. partsGroup.push(line$7, "mixins ", group$b(indent$7(join$9(concat$d([",", line$7]), path.map(print, "mixins")))));
  22968. }
  22969. if (n["implements"] && n["implements"].length > 0) {
  22970. partsGroup.push(line$7, "implements", group$b(indent$7(concat$d([line$7, join$9(concat$d([",", line$7]), path.map(print, "implements"))]))));
  22971. }
  22972. if (partsGroup.length > 0) {
  22973. parts.push(group$b(indent$7(concat$d(partsGroup))));
  22974. }
  22975. if (n.body && n.body.comments && hasLeadingOwnLineComment$1(options.originalText, n.body, options)) {
  22976. parts.push(hardline$9);
  22977. } else {
  22978. parts.push(" ");
  22979. }
  22980. parts.push(path.call(print, "body"));
  22981. return parts;
  22982. }
  22983. function printOptionalToken(path) {
  22984. var node = path.getValue();
  22985. if (!node.optional || // It's an optional computed method parsed by typescript-estree.
  22986. // "?" is printed in `printMethod`.
  22987. node.type === "Identifier" && node === path.getParentNode().key) {
  22988. return "";
  22989. }
  22990. if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
  22991. return "?.";
  22992. }
  22993. return "?";
  22994. }
  22995. function printMemberLookup(path, options, print) {
  22996. var property = path.call(print, "property");
  22997. var n = path.getValue();
  22998. var optional = printOptionalToken(path);
  22999. if (!n.computed) {
  23000. return concat$d([optional, ".", property]);
  23001. }
  23002. if (!n.property || isNumericLiteral$1(n.property)) {
  23003. return concat$d([optional, "[", property, "]"]);
  23004. }
  23005. return group$b(concat$d([optional, "[", indent$7(concat$d([softline$6, property])), softline$6, "]"]));
  23006. }
  23007. function printBindExpressionCallee(path, options, print) {
  23008. return concat$d(["::", path.call(print, "callee")]);
  23009. } // We detect calls on member expressions specially to format a
  23010. // common pattern better. The pattern we are looking for is this:
  23011. //
  23012. // arr
  23013. // .map(x => x + 1)
  23014. // .filter(x => x > 10)
  23015. // .some(x => x % 2)
  23016. //
  23017. // The way it is structured in the AST is via a nested sequence of
  23018. // MemberExpression and CallExpression. We need to traverse the AST
  23019. // and make groups out of it to print it in the desired way.
  23020. function printMemberChain(path, options, print) {
  23021. // The first phase is to linearize the AST by traversing it down.
  23022. //
  23023. // a().b()
  23024. // has the following AST structure:
  23025. // CallExpression(MemberExpression(CallExpression(Identifier)))
  23026. // and we transform it into
  23027. // [Identifier, CallExpression, MemberExpression, CallExpression]
  23028. var printedNodes = []; // Here we try to retain one typed empty line after each call expression or
  23029. // the first group whether it is in parentheses or not
  23030. function shouldInsertEmptyLineAfter(node) {
  23031. var originalText = options.originalText;
  23032. var nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$2(originalText, node, options);
  23033. var nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
  23034. // line after that parenthesis
  23035. if (nextChar == ")") {
  23036. return isNextLineEmptyAfterIndex$1(originalText, nextCharIndex + 1, options);
  23037. }
  23038. return isNextLineEmpty$4(originalText, node, options);
  23039. }
  23040. function rec(path) {
  23041. var node = path.getValue();
  23042. if ((node.type === "CallExpression" || node.type === "OptionalCallExpression") && (isMemberish$1(node.callee) || node.callee.type === "CallExpression" || node.callee.type === "OptionalCallExpression")) {
  23043. printedNodes.unshift({
  23044. node: node,
  23045. printed: concat$d([comments.printComments(path, function () {
  23046. return concat$d([printOptionalToken(path), printFunctionTypeParameters(path, options, print), printArgumentsList(path, options, print)]);
  23047. }, options), shouldInsertEmptyLineAfter(node) ? hardline$9 : ""])
  23048. });
  23049. path.call(function (callee) {
  23050. return rec(callee);
  23051. }, "callee");
  23052. } else if (isMemberish$1(node)) {
  23053. printedNodes.unshift({
  23054. node: node,
  23055. needsParens: needsParens_1(path, options),
  23056. printed: comments.printComments(path, function () {
  23057. return node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup(path, options, print) : printBindExpressionCallee(path, options, print);
  23058. }, options)
  23059. });
  23060. path.call(function (object) {
  23061. return rec(object);
  23062. }, "object");
  23063. } else if (node.type === "TSNonNullExpression") {
  23064. printedNodes.unshift({
  23065. node: node,
  23066. printed: comments.printComments(path, function () {
  23067. return "!";
  23068. }, options)
  23069. });
  23070. path.call(function (expression) {
  23071. return rec(expression);
  23072. }, "expression");
  23073. } else {
  23074. printedNodes.unshift({
  23075. node: node,
  23076. printed: path.call(print)
  23077. });
  23078. }
  23079. } // Note: the comments of the root node have already been printed, so we
  23080. // need to extract this first call without printing them as they would
  23081. // if handled inside of the recursive call.
  23082. var node = path.getValue();
  23083. printedNodes.unshift({
  23084. node: node,
  23085. printed: concat$d([printOptionalToken(path), printFunctionTypeParameters(path, options, print), printArgumentsList(path, options, print)])
  23086. });
  23087. path.call(function (callee) {
  23088. return rec(callee);
  23089. }, "callee"); // Once we have a linear list of printed nodes, we want to create groups out
  23090. // of it.
  23091. //
  23092. // a().b.c().d().e
  23093. // will be grouped as
  23094. // [
  23095. // [Identifier, CallExpression],
  23096. // [MemberExpression, MemberExpression, CallExpression],
  23097. // [MemberExpression, CallExpression],
  23098. // [MemberExpression],
  23099. // ]
  23100. // so that we can print it as
  23101. // a()
  23102. // .b.c()
  23103. // .d()
  23104. // .e
  23105. // The first group is the first node followed by
  23106. // - as many CallExpression as possible
  23107. // < fn()()() >.something()
  23108. // - as many array accessors as possible
  23109. // < fn()[0][1][2] >.something()
  23110. // - then, as many MemberExpression as possible but the last one
  23111. // < this.items >.something()
  23112. var groups = [];
  23113. var currentGroup = [printedNodes[0]];
  23114. var i = 1;
  23115. for (; i < printedNodes.length; ++i) {
  23116. if (printedNodes[i].node.type === "TSNonNullExpression" || printedNodes[i].node.type === "OptionalCallExpression" || printedNodes[i].node.type === "CallExpression" || (printedNodes[i].node.type === "MemberExpression" || printedNodes[i].node.type === "OptionalMemberExpression") && printedNodes[i].node.computed && isNumericLiteral$1(printedNodes[i].node.property)) {
  23117. currentGroup.push(printedNodes[i]);
  23118. } else {
  23119. break;
  23120. }
  23121. }
  23122. if (printedNodes[0].node.type !== "CallExpression" && printedNodes[0].node.type !== "OptionalCallExpression") {
  23123. for (; i + 1 < printedNodes.length; ++i) {
  23124. if (isMemberish$1(printedNodes[i].node) && isMemberish$1(printedNodes[i + 1].node)) {
  23125. currentGroup.push(printedNodes[i]);
  23126. } else {
  23127. break;
  23128. }
  23129. }
  23130. }
  23131. groups.push(currentGroup);
  23132. currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
  23133. // a sequence of CallExpression. To compute it, we keep adding things to the
  23134. // group until we has seen a CallExpression in the past and reach a
  23135. // MemberExpression
  23136. var hasSeenCallExpression = false;
  23137. for (; i < printedNodes.length; ++i) {
  23138. if (hasSeenCallExpression && isMemberish$1(printedNodes[i].node)) {
  23139. // [0] should be appended at the end of the group instead of the
  23140. // beginning of the next one
  23141. if (printedNodes[i].node.computed && isNumericLiteral$1(printedNodes[i].node.property)) {
  23142. currentGroup.push(printedNodes[i]);
  23143. continue;
  23144. }
  23145. groups.push(currentGroup);
  23146. currentGroup = [];
  23147. hasSeenCallExpression = false;
  23148. }
  23149. if (printedNodes[i].node.type === "CallExpression" || printedNodes[i].node.type === "OptionalCallExpression") {
  23150. hasSeenCallExpression = true;
  23151. }
  23152. currentGroup.push(printedNodes[i]);
  23153. if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(function (comment) {
  23154. return comment.trailing;
  23155. })) {
  23156. groups.push(currentGroup);
  23157. currentGroup = [];
  23158. hasSeenCallExpression = false;
  23159. }
  23160. }
  23161. if (currentGroup.length > 0) {
  23162. groups.push(currentGroup);
  23163. } // There are cases like Object.keys(), Observable.of(), _.values() where
  23164. // they are the subject of all the chained calls and therefore should
  23165. // be kept on the same line:
  23166. //
  23167. // Object.keys(items)
  23168. // .filter(x => x)
  23169. // .map(x => x)
  23170. //
  23171. // In order to detect those cases, we use an heuristic: if the first
  23172. // node is an identifier with the name starting with a capital
  23173. // letter or just a sequence of _$. The rationale is that they are
  23174. // likely to be factories.
  23175. function isFactory(name) {
  23176. return /^[A-Z]|^[_$]+$/.test(name);
  23177. } // In case the Identifier is shorter than tab width, we can keep the
  23178. // first call in a single line, if it's an ExpressionStatement.
  23179. //
  23180. // d3.scaleLinear()
  23181. // .domain([0, 100])
  23182. // .range([0, width]);
  23183. //
  23184. function isShort(name) {
  23185. return name.length <= options.tabWidth;
  23186. }
  23187. function shouldNotWrap(groups) {
  23188. var parent = path.getParentNode();
  23189. var isExpression = parent && parent.type === "ExpressionStatement";
  23190. var hasComputed = groups[1].length && groups[1][0].node.computed;
  23191. if (groups[0].length === 1) {
  23192. var firstNode = groups[0][0].node;
  23193. return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpression && isShort(firstNode.name) || hasComputed);
  23194. }
  23195. var lastNode = getLast$2(groups[0]).node;
  23196. return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
  23197. }
  23198. var shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
  23199. function printGroup(printedGroup) {
  23200. var printed = printedGroup.map(function (tuple) {
  23201. return tuple.printed;
  23202. }); // Checks if the last node (i.e. the parent node) needs parens and print
  23203. // accordingly
  23204. if (printedGroup.length > 0 && printedGroup[printedGroup.length - 1].needsParens) {
  23205. return concat$d(["("].concat(_toConsumableArray(printed), [")"]));
  23206. }
  23207. return concat$d(printed);
  23208. }
  23209. function printIndentedGroup(groups) {
  23210. if (groups.length === 0) {
  23211. return "";
  23212. }
  23213. return indent$7(group$b(concat$d([hardline$9, join$9(hardline$9, groups.map(printGroup))])));
  23214. }
  23215. var printedGroups = groups.map(printGroup);
  23216. var oneLine = concat$d(printedGroups);
  23217. var cutoff = shouldMerge ? 3 : 2;
  23218. var flatGroups = groups.slice(0, cutoff).reduce(function (res, group) {
  23219. return res.concat(group);
  23220. }, []);
  23221. var hasComment = flatGroups.slice(1, -1).some(function (node) {
  23222. return hasLeadingComment$3(node.node);
  23223. }) || flatGroups.slice(0, -1).some(function (node) {
  23224. return hasTrailingComment$1(node.node);
  23225. }) || groups[cutoff] && hasLeadingComment$3(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
  23226. // render everything concatenated together.
  23227. if (groups.length <= cutoff && !hasComment) {
  23228. if (isLongCurriedCallExpression$1(path)) {
  23229. return oneLine;
  23230. }
  23231. return group$b(oneLine);
  23232. } // Find out the last node in the first group and check if it has an
  23233. // empty line after
  23234. var lastNodeBeforeIndent = getLast$2(shouldMerge ? groups.slice(1, 2)[0] : groups[0]).node;
  23235. var shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "CallExpression" && lastNodeBeforeIndent.type !== "OptionalCallExpression" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  23236. var expanded = concat$d([printGroup(groups[0]), shouldMerge ? concat$d(groups.slice(1, 2).map(printGroup)) : "", shouldHaveEmptyLineBeforeIndent ? hardline$9 : "", printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))]);
  23237. var callExpressions = printedNodes.map(function (_ref) {
  23238. var node = _ref.node;
  23239. return node;
  23240. }).filter(isCallOrOptionalCallExpression$1); // We don't want to print in one line if there's:
  23241. // * A comment.
  23242. // * 3 or more chained calls.
  23243. // * Any group but the last one has a hard line.
  23244. // If the last group is a function it's okay to inline if it fits.
  23245. if (hasComment || callExpressions.length >= 3 || printedGroups.slice(0, -1).some(willBreak$1) ||
  23246. /**
  23247. * scopes.filter(scope => scope.value !== '').map((scope, i) => {
  23248. * // multi line content
  23249. * })
  23250. */
  23251. function (lastGroupDoc, lastGroupNode) {
  23252. return isCallOrOptionalCallExpression$1(lastGroupNode) && willBreak$1(lastGroupDoc);
  23253. }(getLast$2(printedGroups), getLast$2(getLast$2(groups)).node) && callExpressions.slice(0, -1).some(function (n) {
  23254. return n.arguments.some(isFunctionOrArrowExpression$1);
  23255. })) {
  23256. return group$b(expanded);
  23257. }
  23258. return concat$d([// We only need to check `oneLine` because if `expanded` is chosen
  23259. // that means that the parent group has already been broken
  23260. // naturally
  23261. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$3 : "", conditionalGroup$1([oneLine, expanded])]);
  23262. }
  23263. function separatorNoWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  23264. if (isFacebookTranslationTag) {
  23265. return "";
  23266. }
  23267. if (childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement) {
  23268. return child.length === 1 ? softline$6 : hardline$9;
  23269. }
  23270. return softline$6;
  23271. }
  23272. function separatorWithWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  23273. if (isFacebookTranslationTag) {
  23274. return hardline$9;
  23275. }
  23276. if (child.length === 1) {
  23277. return childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement ? hardline$9 : softline$6;
  23278. }
  23279. return hardline$9;
  23280. } // JSX Children are strange, mostly for two reasons:
  23281. // 1. JSX reads newlines into string values, instead of skipping them like JS
  23282. // 2. up to one whitespace between elements within a line is significant,
  23283. // but not between lines.
  23284. //
  23285. // Leading, trailing, and lone whitespace all need to
  23286. // turn themselves into the rather ugly `{' '}` when breaking.
  23287. //
  23288. // We print JSX using the `fill` doc primitive.
  23289. // This requires that we give it an array of alternating
  23290. // content and whitespace elements.
  23291. // To ensure this we add dummy `""` content elements as needed.
  23292. function printJSXChildren(path, options, print, jsxWhitespace, isFacebookTranslationTag) {
  23293. var n = path.getValue();
  23294. var children = []; // using `map` instead of `each` because it provides `i`
  23295. path.map(function (childPath, i) {
  23296. var child = childPath.getValue();
  23297. if (isLiteral$1(child)) {
  23298. var text = rawText$1(child); // Contains a non-whitespace character
  23299. if (isMeaningfulJSXText$1(child)) {
  23300. var words = text.split(matchJsxWhitespaceRegex$1); // Starts with whitespace
  23301. if (words[0] === "") {
  23302. children.push("");
  23303. words.shift();
  23304. if (/\n/.test(words[0])) {
  23305. var next = n.children[i + 1];
  23306. children.push(separatorWithWhitespace(isFacebookTranslationTag, words[1], child, next));
  23307. } else {
  23308. children.push(jsxWhitespace);
  23309. }
  23310. words.shift();
  23311. }
  23312. var endWhitespace; // Ends with whitespace
  23313. if (getLast$2(words) === "") {
  23314. words.pop();
  23315. endWhitespace = words.pop();
  23316. } // This was whitespace only without a new line.
  23317. if (words.length === 0) {
  23318. return;
  23319. }
  23320. words.forEach(function (word, i) {
  23321. if (i % 2 === 1) {
  23322. children.push(line$7);
  23323. } else {
  23324. children.push(word);
  23325. }
  23326. });
  23327. if (endWhitespace !== undefined) {
  23328. if (/\n/.test(endWhitespace)) {
  23329. var _next = n.children[i + 1];
  23330. children.push(separatorWithWhitespace(isFacebookTranslationTag, getLast$2(children), child, _next));
  23331. } else {
  23332. children.push(jsxWhitespace);
  23333. }
  23334. } else {
  23335. var _next2 = n.children[i + 1];
  23336. children.push(separatorNoWhitespace(isFacebookTranslationTag, getLast$2(children), child, _next2));
  23337. }
  23338. } else if (/\n/.test(text)) {
  23339. // Keep (up to one) blank line between tags/expressions/text.
  23340. // Note: We don't keep blank lines between text elements.
  23341. if (text.match(/\n/g).length > 1) {
  23342. children.push("");
  23343. children.push(hardline$9);
  23344. }
  23345. } else {
  23346. children.push("");
  23347. children.push(jsxWhitespace);
  23348. }
  23349. } else {
  23350. var printedChild = print(childPath);
  23351. children.push(printedChild);
  23352. var _next3 = n.children[i + 1];
  23353. var directlyFollowedByMeaningfulText = _next3 && isMeaningfulJSXText$1(_next3);
  23354. if (directlyFollowedByMeaningfulText) {
  23355. var firstWord = rawText$1(_next3).trim().split(matchJsxWhitespaceRegex$1)[0];
  23356. children.push(separatorNoWhitespace(isFacebookTranslationTag, firstWord, child, _next3));
  23357. } else {
  23358. children.push(hardline$9);
  23359. }
  23360. }
  23361. }, "children");
  23362. return children;
  23363. } // JSX expands children from the inside-out, instead of the outside-in.
  23364. // This is both to break children before attributes,
  23365. // and to ensure that when children break, their parents do as well.
  23366. //
  23367. // Any element that is written without any newlines and fits on a single line
  23368. // is left that way.
  23369. // Not only that, any user-written-line containing multiple JSX siblings
  23370. // should also be kept on one line if possible,
  23371. // so each user-written-line is wrapped in its own group.
  23372. //
  23373. // Elements that contain newlines or don't fit on a single line (recursively)
  23374. // are fully-split, using hardline and shouldBreak: true.
  23375. //
  23376. // To support that case properly, all leading and trailing spaces
  23377. // are stripped from the list of children, and replaced with a single hardline.
  23378. function printJSXElement(path, options, print) {
  23379. var n = path.getValue();
  23380. if (n.type === "JSXElement" && isEmptyJSXElement$1(n)) {
  23381. return concat$d([path.call(print, "openingElement"), path.call(print, "closingElement")]);
  23382. }
  23383. var openingLines = n.type === "JSXElement" ? path.call(print, "openingElement") : path.call(print, "openingFragment");
  23384. var closingLines = n.type === "JSXElement" ? path.call(print, "closingElement") : path.call(print, "closingFragment");
  23385. if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
  23386. return concat$d([openingLines, concat$d(path.map(print, "children")), closingLines]);
  23387. } // Convert `{" "}` to text nodes containing a space.
  23388. // This makes it easy to turn them into `jsxWhitespace` which
  23389. // can then print as either a space or `{" "}` when breaking.
  23390. n.children = n.children.map(function (child) {
  23391. if (isJSXWhitespaceExpression$1(child)) {
  23392. return {
  23393. type: "JSXText",
  23394. value: " ",
  23395. raw: " "
  23396. };
  23397. }
  23398. return child;
  23399. });
  23400. var containsTag = n.children.filter(isJSXNode$1).length > 0;
  23401. var containsMultipleExpressions = n.children.filter(function (child) {
  23402. return child.type === "JSXExpressionContainer";
  23403. }).length > 1;
  23404. var containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
  23405. var forcedBreak = willBreak$1(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
  23406. var rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  23407. var jsxWhitespace = ifBreak$6(concat$d([rawJsxWhitespace, softline$6]), " ");
  23408. var isFacebookTranslationTag = n.openingElement && n.openingElement.name && n.openingElement.name.name === "fbt";
  23409. var children = printJSXChildren(path, options, print, jsxWhitespace, isFacebookTranslationTag);
  23410. var containsText = n.children.filter(function (child) {
  23411. return isMeaningfulJSXText$1(child);
  23412. }).length > 0; // We can end up we multiple whitespace elements with empty string
  23413. // content between them.
  23414. // We need to remove empty whitespace and softlines before JSX whitespace
  23415. // to get the correct output.
  23416. for (var i = children.length - 2; i >= 0; i--) {
  23417. var isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  23418. var isPairOfHardlines = children[i] === hardline$9 && children[i + 1] === "" && children[i + 2] === hardline$9;
  23419. var isLineFollowedByJSXWhitespace = (children[i] === softline$6 || children[i] === hardline$9) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  23420. var isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$6 || children[i + 2] === hardline$9);
  23421. var isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  23422. var isPairOfHardOrSoftLines = children[i] === softline$6 && children[i + 1] === "" && children[i + 2] === hardline$9 || children[i] === hardline$9 && children[i + 1] === "" && children[i + 2] === softline$6;
  23423. if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace || isPairOfHardOrSoftLines) {
  23424. children.splice(i, 2);
  23425. } else if (isJSXWhitespaceFollowedByLine) {
  23426. children.splice(i + 1, 2);
  23427. }
  23428. } // Trim trailing lines (or empty strings)
  23429. while (children.length && (isLineNext$1(getLast$2(children)) || isEmpty$1(getLast$2(children)))) {
  23430. children.pop();
  23431. } // Trim leading lines (or empty strings)
  23432. while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
  23433. children.shift();
  23434. children.shift();
  23435. } // Tweak how we format children if outputting this element over multiple lines.
  23436. // Also detect whether we will force this element to output over multiple lines.
  23437. var multilineChildren = [];
  23438. children.forEach(function (child, i) {
  23439. // There are a number of situations where we need to ensure we display
  23440. // whitespace as `{" "}` when outputting this element over multiple lines.
  23441. if (child === jsxWhitespace) {
  23442. if (i === 1 && children[i - 1] === "") {
  23443. if (children.length === 2) {
  23444. // Solitary whitespace
  23445. multilineChildren.push(rawJsxWhitespace);
  23446. return;
  23447. } // Leading whitespace
  23448. multilineChildren.push(concat$d([rawJsxWhitespace, hardline$9]));
  23449. return;
  23450. } else if (i === children.length - 1) {
  23451. // Trailing whitespace
  23452. multilineChildren.push(rawJsxWhitespace);
  23453. return;
  23454. } else if (children[i - 1] === "" && children[i - 2] === hardline$9) {
  23455. // Whitespace after line break
  23456. multilineChildren.push(rawJsxWhitespace);
  23457. return;
  23458. }
  23459. }
  23460. multilineChildren.push(child);
  23461. if (willBreak$1(child)) {
  23462. forcedBreak = true;
  23463. }
  23464. }); // If there is text we use `fill` to fit as much onto each line as possible.
  23465. // When there is no text (just tags and expressions) we use `group`
  23466. // to output each on a separate line.
  23467. var content = containsText ? fill$4(multilineChildren) : group$b(concat$d(multilineChildren), {
  23468. shouldBreak: true
  23469. });
  23470. var multiLineElem = group$b(concat$d([openingLines, indent$7(concat$d([hardline$9, content])), hardline$9, closingLines]));
  23471. if (forcedBreak) {
  23472. return multiLineElem;
  23473. }
  23474. return conditionalGroup$1([group$b(concat$d([openingLines, concat$d(children), closingLines])), multiLineElem]);
  23475. }
  23476. function maybeWrapJSXElementInParens(path, elem, options) {
  23477. var parent = path.getParentNode();
  23478. if (!parent) {
  23479. return elem;
  23480. }
  23481. var NO_WRAP_PARENTS = {
  23482. ArrayExpression: true,
  23483. JSXAttribute: true,
  23484. JSXElement: true,
  23485. JSXExpressionContainer: true,
  23486. JSXFragment: true,
  23487. ExpressionStatement: true,
  23488. CallExpression: true,
  23489. OptionalCallExpression: true,
  23490. ConditionalExpression: true,
  23491. JsExpressionRoot: true
  23492. };
  23493. if (NO_WRAP_PARENTS[parent.type]) {
  23494. return elem;
  23495. }
  23496. var shouldBreak = matchAncestorTypes$1(path, ["ArrowFunctionExpression", "CallExpression", "JSXExpressionContainer"]) || matchAncestorTypes$1(path, ["ArrowFunctionExpression", "OptionalCallExpression", "JSXExpressionContainer"]);
  23497. var needsParens = needsParens_1(path, options);
  23498. return group$b(concat$d([needsParens ? "" : ifBreak$6("("), indent$7(concat$d([softline$6, elem])), softline$6, needsParens ? "" : ifBreak$6(")")]), {
  23499. shouldBreak: shouldBreak
  23500. });
  23501. }
  23502. function shouldInlineLogicalExpression(node) {
  23503. if (node.type !== "LogicalExpression") {
  23504. return false;
  23505. }
  23506. if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
  23507. return true;
  23508. }
  23509. if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
  23510. return true;
  23511. }
  23512. if (isJSXNode$1(node.right)) {
  23513. return true;
  23514. }
  23515. return false;
  23516. } // For binary expressions to be consistent, we need to group
  23517. // subsequent operators with the same precedence level under a single
  23518. // group. Otherwise they will be nested such that some of them break
  23519. // onto new lines but not all. Operators with the same precedence
  23520. // level should either all break or not. Because we group them by
  23521. // precedence level and the AST is structured based on precedence
  23522. // level, things are naturally broken up correctly, i.e. `&&` is
  23523. // broken before `+`.
  23524. function printBinaryishExpressions(path, print, options, isNested, isInsideParenthesis) {
  23525. var parts = [];
  23526. var node = path.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
  23527. if (isBinaryish$1(node)) {
  23528. // Put all operators with the same precedence level in the same
  23529. // group. The reason we only need to do this with the `left`
  23530. // expression is because given an expression like `1 + 2 - 3`, it
  23531. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  23532. // is where the rest of the expression will exist. Binary
  23533. // expressions on the right side mean they have a difference
  23534. // precedence level and should be treated as a separate group, so
  23535. // print them normally. (This doesn't hold for the `**` operator,
  23536. // which is unique in that it is right-associative.)
  23537. if (shouldFlatten$1(node.operator, node.left.operator)) {
  23538. // Flatten them out by recursively calling this function.
  23539. parts = parts.concat(path.call(function (left) {
  23540. return printBinaryishExpressions(left, print, options,
  23541. /* isNested */
  23542. true, isInsideParenthesis);
  23543. }, "left"));
  23544. } else {
  23545. parts.push(path.call(print, "left"));
  23546. }
  23547. var shouldInline = shouldInlineLogicalExpression(node);
  23548. var lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node.right, options);
  23549. var operator = node.type === "NGPipeExpression" ? "|" : node.operator;
  23550. var rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$b(indent$7(concat$d([softline$6, ": ", join$9(concat$d([softline$6, ":", ifBreak$6(" ")]), path.map(print, "arguments").map(function (arg) {
  23551. return align$1(2, group$b(arg));
  23552. }))]))) : "";
  23553. var right = shouldInline ? concat$d([operator, " ", path.call(print, "right"), rightSuffix]) : concat$d([lineBeforeOperator ? softline$6 : "", operator, lineBeforeOperator ? " " : line$7, path.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
  23554. // in order to avoid having a small right part like -1 be on its own line.
  23555. var parent = path.getParentNode();
  23556. var shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
  23557. parts.push(" ", shouldGroup ? group$b(right) : right); // The root comments are already printed, but we need to manually print
  23558. // the other ones since we don't call the normal print on BinaryExpression,
  23559. // only for the left and right parts
  23560. if (isNested && node.comments) {
  23561. parts = comments.printComments(path, function () {
  23562. return concat$d(parts);
  23563. }, options);
  23564. }
  23565. } else {
  23566. // Our stopping case. Simply print the node normally.
  23567. parts.push(path.call(print));
  23568. }
  23569. return parts;
  23570. }
  23571. function printAssignmentRight(leftNode, rightNode, printedRight, options) {
  23572. if (hasLeadingOwnLineComment$1(options.originalText, rightNode, options)) {
  23573. return indent$7(concat$d([hardline$9, printedRight]));
  23574. }
  23575. var canBreak = isBinaryish$1(rightNode) && !shouldInlineLogicalExpression(rightNode) || rightNode.type === "ConditionalExpression" && isBinaryish$1(rightNode.test) && !shouldInlineLogicalExpression(rightNode.test) || rightNode.type === "StringLiteralTypeAnnotation" || rightNode.type === "ClassExpression" && rightNode.decorators && rightNode.decorators.length || (leftNode.type === "Identifier" || isStringLiteral$1(leftNode) || leftNode.type === "MemberExpression") && (isStringLiteral$1(rightNode) || isMemberExpressionChain$1(rightNode)) && // do not put values on a separate line from the key in json
  23576. options.parser !== "json" && options.parser !== "json5" || rightNode.type === "SequenceExpression";
  23577. if (canBreak) {
  23578. return group$b(indent$7(concat$d([line$7, printedRight])));
  23579. }
  23580. return concat$d([" ", printedRight]);
  23581. }
  23582. function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
  23583. if (!rightNode) {
  23584. return printedLeft;
  23585. }
  23586. var printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
  23587. return group$b(concat$d([printedLeft, operator, printed]));
  23588. }
  23589. function adjustClause(node, clause, forceSpace) {
  23590. if (node.type === "EmptyStatement") {
  23591. return ";";
  23592. }
  23593. if (node.type === "BlockStatement" || forceSpace) {
  23594. return concat$d([" ", clause]);
  23595. }
  23596. return indent$7(concat$d([line$7, clause]));
  23597. }
  23598. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  23599. var raw = rawText$1(node);
  23600. var isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  23601. return printString$2(raw, options, isDirectiveLiteral);
  23602. }
  23603. function printRegex(node) {
  23604. var flags = node.flags.split("").sort().join("");
  23605. return "/".concat(node.pattern, "/").concat(flags);
  23606. }
  23607. function exprNeedsASIProtection(path, options) {
  23608. var node = path.getValue();
  23609. var maybeASIProblem = needsParens_1(path, options) || node.type === "ParenthesizedExpression" || node.type === "TypeCastExpression" || node.type === "ArrowFunctionExpression" && !shouldPrintParamsWithoutParens(path, options) || node.type === "ArrayExpression" || node.type === "ArrayPattern" || node.type === "UnaryExpression" && node.prefix && (node.operator === "+" || node.operator === "-") || node.type === "TemplateLiteral" || node.type === "TemplateElement" || isJSXNode$1(node) || node.type === "BindExpression" && !node.object || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
  23610. if (maybeASIProblem) {
  23611. return true;
  23612. }
  23613. if (!hasNakedLeftSide$2(node)) {
  23614. return false;
  23615. }
  23616. return path.call.apply(path, [function (childPath) {
  23617. return exprNeedsASIProtection(childPath, options);
  23618. }].concat(getLeftSidePathName$2(path, node)));
  23619. }
  23620. function stmtNeedsASIProtection(path, options) {
  23621. var node = path.getNode();
  23622. if (node.type !== "ExpressionStatement") {
  23623. return false;
  23624. }
  23625. return path.call(function (childPath) {
  23626. return exprNeedsASIProtection(childPath, options);
  23627. }, "expression");
  23628. }
  23629. function shouldHugType(node) {
  23630. if (isSimpleFlowType$1(node) || isObjectType$1(node)) {
  23631. return true;
  23632. }
  23633. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  23634. var voidCount = node.types.filter(function (n) {
  23635. return n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword";
  23636. }).length;
  23637. var objectCount = node.types.filter(function (n) {
  23638. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
  23639. n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference";
  23640. }).length;
  23641. if (node.types.length - 1 === voidCount && objectCount > 0) {
  23642. return true;
  23643. }
  23644. }
  23645. return false;
  23646. }
  23647. function shouldHugArguments(fun) {
  23648. return fun && fun.params && fun.params.length === 1 && !fun.params[0].comments && (fun.params[0].type === "ObjectPattern" || fun.params[0].type === "ArrayPattern" || fun.params[0].type === "Identifier" && fun.params[0].typeAnnotation && (fun.params[0].typeAnnotation.type === "TypeAnnotation" || fun.params[0].typeAnnotation.type === "TSTypeAnnotation") && isObjectType$1(fun.params[0].typeAnnotation.typeAnnotation) || fun.params[0].type === "FunctionTypeParam" && isObjectType$1(fun.params[0].typeAnnotation) || fun.params[0].type === "AssignmentPattern" && (fun.params[0].left.type === "ObjectPattern" || fun.params[0].left.type === "ArrayPattern") && (fun.params[0].right.type === "Identifier" || fun.params[0].right.type === "ObjectExpression" && fun.params[0].right.properties.length === 0 || fun.params[0].right.type === "ArrayExpression" && fun.params[0].right.elements.length === 0)) && !fun.rest;
  23649. }
  23650. function printArrayItems(path, options, printPath, print) {
  23651. var printedElements = [];
  23652. var separatorParts = [];
  23653. path.each(function (childPath) {
  23654. printedElements.push(concat$d(separatorParts));
  23655. printedElements.push(group$b(print(childPath)));
  23656. separatorParts = [",", line$7];
  23657. if (childPath.getValue() && isNextLineEmpty$4(options.originalText, childPath.getValue(), options)) {
  23658. separatorParts.push(softline$6);
  23659. }
  23660. }, printPath);
  23661. return concat$d(printedElements);
  23662. }
  23663. function willPrintOwnComments(path
  23664. /*, options */
  23665. ) {
  23666. var node = path.getValue();
  23667. var parent = path.getParentNode();
  23668. return (node && (isJSXNode$1(node) || hasFlowShorthandAnnotationComment$2(node) || parent && (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && (hasFlowAnnotationComment$1(node.leadingComments) || hasFlowAnnotationComment$1(node.trailingComments))) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && !hasIgnoreComment$4(path);
  23669. }
  23670. function canAttachComment$1(node) {
  23671. return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import";
  23672. }
  23673. function printComment$2(commentPath, options) {
  23674. var comment = commentPath.getValue();
  23675. switch (comment.type) {
  23676. case "CommentBlock":
  23677. case "Block":
  23678. {
  23679. if (isIndentableBlockComment(comment)) {
  23680. var printed = printIndentableBlockComment(comment); // We need to prevent an edge case of a previous trailing comment
  23681. // printed as a `lineSuffix` which causes the comments to be
  23682. // interleaved. See https://github.com/prettier/prettier/issues/4412
  23683. if (comment.trailing && !hasNewline$4(options.originalText, options.locStart(comment), {
  23684. backwards: true
  23685. })) {
  23686. return concat$d([hardline$9, printed]);
  23687. }
  23688. return printed;
  23689. }
  23690. var isInsideFlowComment = options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  23691. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  23692. }
  23693. case "CommentLine":
  23694. case "Line":
  23695. // Print shebangs with the proper comment characters
  23696. if (options.originalText.slice(options.locStart(comment)).startsWith("#!")) {
  23697. return "#!" + comment.value.trimRight();
  23698. }
  23699. return "//" + comment.value.trimRight();
  23700. default:
  23701. throw new Error("Not a comment: " + JSON.stringify(comment));
  23702. }
  23703. }
  23704. function isIndentableBlockComment(comment) {
  23705. // If the comment has multiple lines and every line starts with a star
  23706. // we can fix the indentation of each line. The stars in the `/*` and
  23707. // `*/` delimiters are not included in the comment value, so add them
  23708. // back first.
  23709. var lines = "*".concat(comment.value, "*").split("\n");
  23710. return lines.length > 1 && lines.every(function (line) {
  23711. return line.trim()[0] === "*";
  23712. });
  23713. }
  23714. function printIndentableBlockComment(comment) {
  23715. var lines = comment.value.split("\n");
  23716. return concat$d(["/*", join$9(hardline$9, lines.map(function (line, index) {
  23717. return index === 0 ? line.trimRight() : " " + (index < lines.length - 1 ? line.trim() : line.trimLeft());
  23718. })), "*/"]);
  23719. }
  23720. var printerEstree = {
  23721. preprocess: preprocess_1$1,
  23722. print: genericPrint$3,
  23723. embed: embed_1$1,
  23724. insertPragma: insertPragma$7,
  23725. massageAstNode: clean_1$1,
  23726. hasPrettierIgnore: hasPrettierIgnore$3,
  23727. willPrintOwnComments: willPrintOwnComments,
  23728. canAttachComment: canAttachComment$1,
  23729. printComment: printComment$2,
  23730. isBlockComment: comments$1.isBlockComment,
  23731. handleComments: {
  23732. ownLine: comments$1.handleOwnLineComment,
  23733. endOfLine: comments$1.handleEndOfLineComment,
  23734. remaining: comments$1.handleRemainingComment
  23735. }
  23736. };
  23737. var _require$$0$builders$7 = doc.builders,
  23738. concat$e = _require$$0$builders$7.concat,
  23739. hardline$a = _require$$0$builders$7.hardline,
  23740. indent$8 = _require$$0$builders$7.indent,
  23741. join$a = _require$$0$builders$7.join;
  23742. function genericPrint$4(path, options, print) {
  23743. var node = path.getValue();
  23744. switch (node.type) {
  23745. case "JsonRoot":
  23746. return concat$e([path.call(print, "node"), hardline$a]);
  23747. case "ArrayExpression":
  23748. return node.elements.length === 0 ? "[]" : concat$e(["[", indent$8(concat$e([hardline$a, join$a(concat$e([",", hardline$a]), path.map(print, "elements"))])), hardline$a, "]"]);
  23749. case "ObjectExpression":
  23750. return node.properties.length === 0 ? "{}" : concat$e(["{", indent$8(concat$e([hardline$a, join$a(concat$e([",", hardline$a]), path.map(print, "properties"))])), hardline$a, "}"]);
  23751. case "ObjectProperty":
  23752. return concat$e([path.call(print, "key"), ": ", path.call(print, "value")]);
  23753. case "UnaryExpression":
  23754. return concat$e([node.operator === "+" ? "" : node.operator, path.call(print, "argument")]);
  23755. case "NullLiteral":
  23756. return "null";
  23757. case "BooleanLiteral":
  23758. return node.value ? "true" : "false";
  23759. case "StringLiteral":
  23760. case "NumericLiteral":
  23761. return JSON.stringify(node.value);
  23762. case "Identifier":
  23763. return JSON.stringify(node.name);
  23764. default:
  23765. /* istanbul ignore next */
  23766. throw new Error("unknown type: " + JSON.stringify(node.type));
  23767. }
  23768. }
  23769. function clean$5(node, newNode
  23770. /*, parent*/
  23771. ) {
  23772. delete newNode.start;
  23773. delete newNode.end;
  23774. delete newNode.extra;
  23775. delete newNode.loc;
  23776. delete newNode.comments;
  23777. delete newNode.errors;
  23778. if (node.type === "Identifier") {
  23779. return {
  23780. type: "StringLiteral",
  23781. value: node.name
  23782. };
  23783. }
  23784. if (node.type === "UnaryExpression" && node.operator === "+") {
  23785. return newNode.argument;
  23786. }
  23787. }
  23788. var printerEstreeJson = {
  23789. preprocess: preprocess_1$1,
  23790. print: genericPrint$4,
  23791. massageAstNode: clean$5
  23792. };
  23793. var CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  23794. var options$5 = {
  23795. arrowParens: {
  23796. since: "1.9.0",
  23797. category: CATEGORY_JAVASCRIPT,
  23798. type: "choice",
  23799. default: "avoid",
  23800. description: "Include parentheses around a sole arrow function parameter.",
  23801. choices: [{
  23802. value: "avoid",
  23803. description: "Omit parens when possible. Example: `x => x`"
  23804. }, {
  23805. value: "always",
  23806. description: "Always include parens. Example: `(x) => x`"
  23807. }]
  23808. },
  23809. bracketSpacing: commonOptions.bracketSpacing,
  23810. jsxBracketSameLine: {
  23811. since: "0.17.0",
  23812. category: CATEGORY_JAVASCRIPT,
  23813. type: "boolean",
  23814. default: false,
  23815. description: "Put > on the last line instead of at a new line."
  23816. },
  23817. semi: {
  23818. since: "1.0.0",
  23819. category: CATEGORY_JAVASCRIPT,
  23820. type: "boolean",
  23821. default: true,
  23822. description: "Print semicolons.",
  23823. oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
  23824. },
  23825. singleQuote: commonOptions.singleQuote,
  23826. jsxSingleQuote: {
  23827. since: "1.15.0",
  23828. category: CATEGORY_JAVASCRIPT,
  23829. type: "boolean",
  23830. default: false,
  23831. description: "Use single quotes in JSX."
  23832. },
  23833. quoteProps: {
  23834. since: "1.17.0",
  23835. category: CATEGORY_JAVASCRIPT,
  23836. type: "choice",
  23837. default: "as-needed",
  23838. description: "Change when properties in objects are quoted.",
  23839. choices: [{
  23840. value: "as-needed",
  23841. description: "Only add quotes around object properties where required."
  23842. }, {
  23843. value: "consistent",
  23844. description: "If at least one property in an object requires quotes, quote all properties."
  23845. }, {
  23846. value: "preserve",
  23847. description: "Respect the input use of quotes in object properties."
  23848. }]
  23849. },
  23850. trailingComma: {
  23851. since: "0.0.0",
  23852. category: CATEGORY_JAVASCRIPT,
  23853. type: "choice",
  23854. default: [{
  23855. since: "0.0.0",
  23856. value: false
  23857. }, {
  23858. since: "0.19.0",
  23859. value: "none"
  23860. }],
  23861. description: "Print trailing commas wherever possible when multi-line.",
  23862. choices: [{
  23863. value: "none",
  23864. description: "No trailing commas."
  23865. }, {
  23866. value: "es5",
  23867. description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  23868. }, {
  23869. value: "all",
  23870. description: "Trailing commas wherever possible (including function arguments)."
  23871. }, {
  23872. value: true,
  23873. deprecated: "0.19.0",
  23874. redirect: "es5"
  23875. }, {
  23876. value: false,
  23877. deprecated: "0.19.0",
  23878. redirect: "none"
  23879. }]
  23880. }
  23881. };
  23882. var name$9 = "JavaScript";
  23883. var type$8 = "programming";
  23884. var tmScope$8 = "source.js";
  23885. var aceMode$8 = "javascript";
  23886. var codemirrorMode$4 = "javascript";
  23887. var codemirrorMimeType$4 = "text/javascript";
  23888. var color$3 = "#f1e05a";
  23889. var aliases$2 = [
  23890. "js",
  23891. "node"
  23892. ];
  23893. var extensions$8 = [
  23894. ".js",
  23895. "._js",
  23896. ".bones",
  23897. ".es",
  23898. ".es6",
  23899. ".frag",
  23900. ".gs",
  23901. ".jake",
  23902. ".jsb",
  23903. ".jscad",
  23904. ".jsfl",
  23905. ".jsm",
  23906. ".jss",
  23907. ".mjs",
  23908. ".njs",
  23909. ".pac",
  23910. ".sjs",
  23911. ".ssjs",
  23912. ".xsjs",
  23913. ".xsjslib"
  23914. ];
  23915. var filenames = [
  23916. "Jakefile"
  23917. ];
  23918. var interpreters = [
  23919. "chakra",
  23920. "d8",
  23921. "js",
  23922. "node",
  23923. "rhino",
  23924. "v8",
  23925. "v8-shell"
  23926. ];
  23927. var languageId$8 = 183;
  23928. var JavaScript = {
  23929. name: name$9,
  23930. type: type$8,
  23931. tmScope: tmScope$8,
  23932. aceMode: aceMode$8,
  23933. codemirrorMode: codemirrorMode$4,
  23934. codemirrorMimeType: codemirrorMimeType$4,
  23935. color: color$3,
  23936. aliases: aliases$2,
  23937. extensions: extensions$8,
  23938. filenames: filenames,
  23939. interpreters: interpreters,
  23940. languageId: languageId$8
  23941. };
  23942. var JavaScript$1 = /*#__PURE__*/Object.freeze({
  23943. __proto__: null,
  23944. name: name$9,
  23945. type: type$8,
  23946. tmScope: tmScope$8,
  23947. aceMode: aceMode$8,
  23948. codemirrorMode: codemirrorMode$4,
  23949. codemirrorMimeType: codemirrorMimeType$4,
  23950. color: color$3,
  23951. aliases: aliases$2,
  23952. extensions: extensions$8,
  23953. filenames: filenames,
  23954. interpreters: interpreters,
  23955. languageId: languageId$8,
  23956. 'default': JavaScript
  23957. });
  23958. var name$a = "JSX";
  23959. var type$9 = "programming";
  23960. var group$c = "JavaScript";
  23961. var extensions$9 = [
  23962. ".jsx"
  23963. ];
  23964. var tmScope$9 = "source.js.jsx";
  23965. var aceMode$9 = "javascript";
  23966. var codemirrorMode$5 = "jsx";
  23967. var codemirrorMimeType$5 = "text/jsx";
  23968. var languageId$9 = 178;
  23969. var JSX = {
  23970. name: name$a,
  23971. type: type$9,
  23972. group: group$c,
  23973. extensions: extensions$9,
  23974. tmScope: tmScope$9,
  23975. aceMode: aceMode$9,
  23976. codemirrorMode: codemirrorMode$5,
  23977. codemirrorMimeType: codemirrorMimeType$5,
  23978. languageId: languageId$9
  23979. };
  23980. var JSX$1 = /*#__PURE__*/Object.freeze({
  23981. __proto__: null,
  23982. name: name$a,
  23983. type: type$9,
  23984. group: group$c,
  23985. extensions: extensions$9,
  23986. tmScope: tmScope$9,
  23987. aceMode: aceMode$9,
  23988. codemirrorMode: codemirrorMode$5,
  23989. codemirrorMimeType: codemirrorMimeType$5,
  23990. languageId: languageId$9,
  23991. 'default': JSX
  23992. });
  23993. var name$b = "TypeScript";
  23994. var type$a = "programming";
  23995. var color$4 = "#2b7489";
  23996. var aliases$3 = [
  23997. "ts"
  23998. ];
  23999. var interpreters$1 = [
  24000. "deno",
  24001. "ts-node"
  24002. ];
  24003. var extensions$a = [
  24004. ".ts"
  24005. ];
  24006. var tmScope$a = "source.ts";
  24007. var aceMode$a = "typescript";
  24008. var codemirrorMode$6 = "javascript";
  24009. var codemirrorMimeType$6 = "application/typescript";
  24010. var languageId$a = 378;
  24011. var TypeScript = {
  24012. name: name$b,
  24013. type: type$a,
  24014. color: color$4,
  24015. aliases: aliases$3,
  24016. interpreters: interpreters$1,
  24017. extensions: extensions$a,
  24018. tmScope: tmScope$a,
  24019. aceMode: aceMode$a,
  24020. codemirrorMode: codemirrorMode$6,
  24021. codemirrorMimeType: codemirrorMimeType$6,
  24022. languageId: languageId$a
  24023. };
  24024. var TypeScript$1 = /*#__PURE__*/Object.freeze({
  24025. __proto__: null,
  24026. name: name$b,
  24027. type: type$a,
  24028. color: color$4,
  24029. aliases: aliases$3,
  24030. interpreters: interpreters$1,
  24031. extensions: extensions$a,
  24032. tmScope: tmScope$a,
  24033. aceMode: aceMode$a,
  24034. codemirrorMode: codemirrorMode$6,
  24035. codemirrorMimeType: codemirrorMimeType$6,
  24036. languageId: languageId$a,
  24037. 'default': TypeScript
  24038. });
  24039. var name$c = "TSX";
  24040. var type$b = "programming";
  24041. var group$d = "TypeScript";
  24042. var extensions$b = [
  24043. ".tsx"
  24044. ];
  24045. var tmScope$b = "source.tsx";
  24046. var aceMode$b = "javascript";
  24047. var codemirrorMode$7 = "jsx";
  24048. var codemirrorMimeType$7 = "text/jsx";
  24049. var languageId$b = 94901924;
  24050. var TSX = {
  24051. name: name$c,
  24052. type: type$b,
  24053. group: group$d,
  24054. extensions: extensions$b,
  24055. tmScope: tmScope$b,
  24056. aceMode: aceMode$b,
  24057. codemirrorMode: codemirrorMode$7,
  24058. codemirrorMimeType: codemirrorMimeType$7,
  24059. languageId: languageId$b
  24060. };
  24061. var TSX$1 = /*#__PURE__*/Object.freeze({
  24062. __proto__: null,
  24063. name: name$c,
  24064. type: type$b,
  24065. group: group$d,
  24066. extensions: extensions$b,
  24067. tmScope: tmScope$b,
  24068. aceMode: aceMode$b,
  24069. codemirrorMode: codemirrorMode$7,
  24070. codemirrorMimeType: codemirrorMimeType$7,
  24071. languageId: languageId$b,
  24072. 'default': TSX
  24073. });
  24074. var name$d = "JSON";
  24075. var type$c = "data";
  24076. var tmScope$c = "source.json";
  24077. var aceMode$c = "json";
  24078. var codemirrorMode$8 = "javascript";
  24079. var codemirrorMimeType$8 = "application/json";
  24080. var searchable = false;
  24081. var extensions$c = [
  24082. ".json",
  24083. ".avsc",
  24084. ".geojson",
  24085. ".gltf",
  24086. ".har",
  24087. ".ice",
  24088. ".JSON-tmLanguage",
  24089. ".jsonl",
  24090. ".mcmeta",
  24091. ".tfstate",
  24092. ".tfstate.backup",
  24093. ".topojson",
  24094. ".webapp",
  24095. ".webmanifest",
  24096. ".yy",
  24097. ".yyp"
  24098. ];
  24099. var filenames$1 = [
  24100. ".arcconfig",
  24101. ".htmlhintrc",
  24102. ".tern-config",
  24103. ".tern-project",
  24104. ".watchmanconfig",
  24105. "composer.lock",
  24106. "mcmod.info"
  24107. ];
  24108. var languageId$c = 174;
  24109. var _JSON = {
  24110. name: name$d,
  24111. type: type$c,
  24112. tmScope: tmScope$c,
  24113. aceMode: aceMode$c,
  24114. codemirrorMode: codemirrorMode$8,
  24115. codemirrorMimeType: codemirrorMimeType$8,
  24116. searchable: searchable,
  24117. extensions: extensions$c,
  24118. filenames: filenames$1,
  24119. languageId: languageId$c
  24120. };
  24121. var _JSON$1 = /*#__PURE__*/Object.freeze({
  24122. __proto__: null,
  24123. name: name$d,
  24124. type: type$c,
  24125. tmScope: tmScope$c,
  24126. aceMode: aceMode$c,
  24127. codemirrorMode: codemirrorMode$8,
  24128. codemirrorMimeType: codemirrorMimeType$8,
  24129. searchable: searchable,
  24130. extensions: extensions$c,
  24131. filenames: filenames$1,
  24132. languageId: languageId$c,
  24133. 'default': _JSON
  24134. });
  24135. var name$e = "JSON with Comments";
  24136. var type$d = "data";
  24137. var group$e = "JSON";
  24138. var tmScope$d = "source.js";
  24139. var aceMode$d = "javascript";
  24140. var codemirrorMode$9 = "javascript";
  24141. var codemirrorMimeType$9 = "text/javascript";
  24142. var aliases$4 = [
  24143. "jsonc"
  24144. ];
  24145. var extensions$d = [
  24146. ".sublime-build",
  24147. ".sublime-commands",
  24148. ".sublime-completions",
  24149. ".sublime-keymap",
  24150. ".sublime-macro",
  24151. ".sublime-menu",
  24152. ".sublime-mousemap",
  24153. ".sublime-project",
  24154. ".sublime-settings",
  24155. ".sublime-theme",
  24156. ".sublime-workspace",
  24157. ".sublime_metrics",
  24158. ".sublime_session"
  24159. ];
  24160. var filenames$2 = [
  24161. ".babelrc",
  24162. ".eslintrc.json",
  24163. ".jscsrc",
  24164. ".jshintrc",
  24165. ".jslintrc",
  24166. "jsconfig.json",
  24167. "language-configuration.json",
  24168. "tsconfig.json"
  24169. ];
  24170. var languageId$d = 423;
  24171. var JSON_with_Comments = {
  24172. name: name$e,
  24173. type: type$d,
  24174. group: group$e,
  24175. tmScope: tmScope$d,
  24176. aceMode: aceMode$d,
  24177. codemirrorMode: codemirrorMode$9,
  24178. codemirrorMimeType: codemirrorMimeType$9,
  24179. aliases: aliases$4,
  24180. extensions: extensions$d,
  24181. filenames: filenames$2,
  24182. languageId: languageId$d
  24183. };
  24184. var JSON_with_Comments$1 = /*#__PURE__*/Object.freeze({
  24185. __proto__: null,
  24186. name: name$e,
  24187. type: type$d,
  24188. group: group$e,
  24189. tmScope: tmScope$d,
  24190. aceMode: aceMode$d,
  24191. codemirrorMode: codemirrorMode$9,
  24192. codemirrorMimeType: codemirrorMimeType$9,
  24193. aliases: aliases$4,
  24194. extensions: extensions$d,
  24195. filenames: filenames$2,
  24196. languageId: languageId$d,
  24197. 'default': JSON_with_Comments
  24198. });
  24199. var name$f = "JSON5";
  24200. var type$e = "data";
  24201. var extensions$e = [
  24202. ".json5"
  24203. ];
  24204. var tmScope$e = "source.js";
  24205. var aceMode$e = "javascript";
  24206. var codemirrorMode$a = "javascript";
  24207. var codemirrorMimeType$a = "application/json";
  24208. var languageId$e = 175;
  24209. var JSON5 = {
  24210. name: name$f,
  24211. type: type$e,
  24212. extensions: extensions$e,
  24213. tmScope: tmScope$e,
  24214. aceMode: aceMode$e,
  24215. codemirrorMode: codemirrorMode$a,
  24216. codemirrorMimeType: codemirrorMimeType$a,
  24217. languageId: languageId$e
  24218. };
  24219. var JSON5$1 = /*#__PURE__*/Object.freeze({
  24220. __proto__: null,
  24221. name: name$f,
  24222. type: type$e,
  24223. extensions: extensions$e,
  24224. tmScope: tmScope$e,
  24225. aceMode: aceMode$e,
  24226. codemirrorMode: codemirrorMode$a,
  24227. codemirrorMimeType: codemirrorMimeType$a,
  24228. languageId: languageId$e,
  24229. 'default': JSON5
  24230. });
  24231. var require$$0$6 = getCjsExportFromNamespace(JavaScript$1);
  24232. var require$$1$2 = getCjsExportFromNamespace(JSX$1);
  24233. var require$$2$1 = getCjsExportFromNamespace(TypeScript$1);
  24234. var require$$3$1 = getCjsExportFromNamespace(TSX$1);
  24235. var require$$4 = getCjsExportFromNamespace(_JSON$1);
  24236. var require$$5 = getCjsExportFromNamespace(JSON_with_Comments$1);
  24237. var require$$6 = getCjsExportFromNamespace(JSON5$1);
  24238. var languages$4 = [createLanguage(require$$0$6, function (data) {
  24239. return Object.assign(data, {
  24240. since: "0.0.0",
  24241. parsers: ["babel", "flow"],
  24242. vscodeLanguageIds: ["javascript", "mongo"],
  24243. interpreters: data.interpreters.concat(["nodejs"])
  24244. });
  24245. }), createLanguage(require$$0$6, function (data) {
  24246. return Object.assign(data, {
  24247. name: "Flow",
  24248. since: "0.0.0",
  24249. parsers: ["babel", "flow"],
  24250. vscodeLanguageIds: ["javascript"],
  24251. aliases: [],
  24252. filenames: [],
  24253. extensions: [".js.flow"]
  24254. });
  24255. }), createLanguage(require$$1$2, function (data) {
  24256. return Object.assign(data, {
  24257. since: "0.0.0",
  24258. parsers: ["babel", "flow"],
  24259. vscodeLanguageIds: ["javascriptreact"]
  24260. });
  24261. }), createLanguage(require$$2$1, function (data) {
  24262. return Object.assign(data, {
  24263. since: "1.4.0",
  24264. parsers: ["typescript"],
  24265. vscodeLanguageIds: ["typescript"]
  24266. });
  24267. }), createLanguage(require$$3$1, function (data) {
  24268. return Object.assign(data, {
  24269. since: "1.4.0",
  24270. parsers: ["typescript"],
  24271. vscodeLanguageIds: ["typescriptreact"]
  24272. });
  24273. }), createLanguage(require$$4, function (data) {
  24274. return Object.assign(data, {
  24275. name: "JSON.stringify",
  24276. since: "1.13.0",
  24277. parsers: ["json-stringify"],
  24278. vscodeLanguageIds: ["json"],
  24279. extensions: [],
  24280. // .json file defaults to json instead of json-stringify
  24281. filenames: ["package.json", "package-lock.json", "composer.json"]
  24282. });
  24283. }), createLanguage(require$$4, function (data) {
  24284. return Object.assign(data, {
  24285. since: "1.5.0",
  24286. parsers: ["json"],
  24287. vscodeLanguageIds: ["json"],
  24288. filenames: data.filenames.concat([".prettierrc"])
  24289. });
  24290. }), createLanguage(require$$5, function (data) {
  24291. return Object.assign(data, {
  24292. since: "1.5.0",
  24293. parsers: ["json"],
  24294. vscodeLanguageIds: ["jsonc"],
  24295. filenames: data.filenames.concat([".eslintrc"])
  24296. });
  24297. }), createLanguage(require$$6, function (data) {
  24298. return Object.assign(data, {
  24299. since: "1.13.0",
  24300. parsers: ["json5"],
  24301. vscodeLanguageIds: ["json5"]
  24302. });
  24303. })];
  24304. var printers$4 = {
  24305. estree: printerEstree,
  24306. "estree-json": printerEstreeJson
  24307. };
  24308. var languageJs = {
  24309. languages: languages$4,
  24310. options: options$5,
  24311. printers: printers$4
  24312. };
  24313. var json$1 = {
  24314. "cjkPattern": "[\\u02ea-\\u02eb\\u1100-\\u11ff\\u2e80-\\u2e99\\u2e9b-\\u2ef3\\u2f00-\\u2fd5\\u3000-\\u303f\\u3041-\\u3096\\u3099-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312f\\u3131-\\u318e\\u3190-\\u3191\\u3196-\\u31ba\\u31c0-\\u31e3\\u31f0-\\u321e\\u322a-\\u3247\\u3260-\\u327e\\u328a-\\u32b0\\u32c0-\\u32cb\\u32d0-\\u3370\\u337b-\\u337f\\u33e0-\\u33fe\\u3400-\\u4db5\\u4e00-\\u9fef\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufe10-\\ufe1f\\ufe30-\\ufe6f\\uff00-\\uffef]|[\\ud840-\\ud868\\ud86a-\\ud86c\\ud86f-\\ud872\\ud874-\\ud879][\\udc00-\\udfff]|\\ud82c[\\udc00-\\udd1e\\udd50-\\udd52\\udd64-\\udd67]|\\ud83c[\\ude00\\ude50-\\ude51]|\\ud869[\\udc00-\\uded6\\udf00-\\udfff]|\\ud86d[\\udc00-\\udf34\\udf40-\\udfff]|\\ud86e[\\udc00-\\udc1d\\udc20-\\udfff]|\\ud873[\\udc00-\\udea1\\udeb0-\\udfff]|\\ud87a[\\udc00-\\udfe0]|\\ud87e[\\udc00-\\ude1d]",
  24315. "kPattern": "[\\u1100-\\u11ff\\u3001-\\u3003\\u3008-\\u3011\\u3013-\\u301f\\u302e-\\u3030\\u3037\\u30fb\\u3131-\\u318e\\u3200-\\u321e\\u3260-\\u327e\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\ufe45-\\ufe46\\uff61-\\uff65\\uffa0-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc]",
  24316. "punctuationPattern": "[\\u0021-\\u002f\\u003a-\\u0040\\u005b-\\u0060\\u007b-\\u007e\\u00a1\\u00a7\\u00ab\\u00b6-\\u00b7\\u00bb\\u00bf\\u037e\\u0387\\u055a-\\u055f\\u0589-\\u058a\\u05be\\u05c0\\u05c3\\u05c6\\u05f3-\\u05f4\\u0609-\\u060a\\u060c-\\u060d\\u061b\\u061e-\\u061f\\u066a-\\u066d\\u06d4\\u0700-\\u070d\\u07f7-\\u07f9\\u0830-\\u083e\\u085e\\u0964-\\u0965\\u0970\\u09fd\\u0a76\\u0af0\\u0c77\\u0c84\\u0df4\\u0e4f\\u0e5a-\\u0e5b\\u0f04-\\u0f12\\u0f14\\u0f3a-\\u0f3d\\u0f85\\u0fd0-\\u0fd4\\u0fd9-\\u0fda\\u104a-\\u104f\\u10fb\\u1360-\\u1368\\u1400\\u166e\\u169b-\\u169c\\u16eb-\\u16ed\\u1735-\\u1736\\u17d4-\\u17d6\\u17d8-\\u17da\\u1800-\\u180a\\u1944-\\u1945\\u1a1e-\\u1a1f\\u1aa0-\\u1aa6\\u1aa8-\\u1aad\\u1b5a-\\u1b60\\u1bfc-\\u1bff\\u1c3b-\\u1c3f\\u1c7e-\\u1c7f\\u1cc0-\\u1cc7\\u1cd3\\u2010-\\u2027\\u2030-\\u2043\\u2045-\\u2051\\u2053-\\u205e\\u207d-\\u207e\\u208d-\\u208e\\u2308-\\u230b\\u2329-\\u232a\\u2768-\\u2775\\u27c5-\\u27c6\\u27e6-\\u27ef\\u2983-\\u2998\\u29d8-\\u29db\\u29fc-\\u29fd\\u2cf9-\\u2cfc\\u2cfe-\\u2cff\\u2d70\\u2e00-\\u2e2e\\u2e30-\\u2e4f\\u3001-\\u3003\\u3008-\\u3011\\u3014-\\u301f\\u3030\\u303d\\u30a0\\u30fb\\ua4fe-\\ua4ff\\ua60d-\\ua60f\\ua673\\ua67e\\ua6f2-\\ua6f7\\ua874-\\ua877\\ua8ce-\\ua8cf\\ua8f8-\\ua8fa\\ua8fc\\ua92e-\\ua92f\\ua95f\\ua9c1-\\ua9cd\\ua9de-\\ua9df\\uaa5c-\\uaa5f\\uaade-\\uaadf\\uaaf0-\\uaaf1\\uabeb\\ufd3e-\\ufd3f\\ufe10-\\ufe19\\ufe30-\\ufe52\\ufe54-\\ufe61\\ufe63\\ufe68\\ufe6a-\\ufe6b\\uff01-\\uff03\\uff05-\\uff0a\\uff0c-\\uff0f\\uff1a-\\uff1b\\uff1f-\\uff20\\uff3b-\\uff3d\\uff3f\\uff5b\\uff5d\\uff5f-\\uff65]|\\ud800[\\udd00-\\udd02\\udf9f\\udfd0]|\\ud801[\\udd6f]|\\ud802[\\udc57\\udd1f\\udd3f\\ude50-\\ude58\\ude7f\\udef0-\\udef6\\udf39-\\udf3f\\udf99-\\udf9c]|\\ud803[\\udf55-\\udf59]|\\ud804[\\udc47-\\udc4d\\udcbb-\\udcbc\\udcbe-\\udcc1\\udd40-\\udd43\\udd74-\\udd75\\uddc5-\\uddc8\\uddcd\\udddb\\udddd-\\udddf\\ude38-\\ude3d\\udea9]|\\ud805[\\udc4b-\\udc4f\\udc5b\\udc5d\\udcc6\\uddc1-\\uddd7\\ude41-\\ude43\\ude60-\\ude6c\\udf3c-\\udf3e]|\\ud806[\\udc3b\\udde2\\ude3f-\\ude46\\ude9a-\\ude9c\\ude9e-\\udea2]|\\ud807[\\udc41-\\udc45\\udc70-\\udc71\\udef7-\\udef8\\udfff]|\\ud809[\\udc70-\\udc74]|\\ud81a[\\ude6e-\\ude6f\\udef5\\udf37-\\udf3b\\udf44]|\\ud81b[\\ude97-\\ude9a\\udfe2]|\\ud82f[\\udc9f]|\\ud836[\\ude87-\\ude8b]|\\ud83a[\\udd5e-\\udd5f]"
  24317. };
  24318. var cjkPattern = json$1.cjkPattern,
  24319. kPattern = json$1.kPattern,
  24320. punctuationPattern = json$1.punctuationPattern;
  24321. var getLast$3 = util.getLast;
  24322. var INLINE_NODE_TYPES = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
  24323. var INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat(["tableCell", "paragraph", "heading"]);
  24324. var kRegex = new RegExp(kPattern);
  24325. var punctuationRegex = new RegExp(punctuationPattern);
  24326. /**
  24327. * split text into whitespaces and words
  24328. * @param {string} text
  24329. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  24330. */
  24331. function splitText(text, options) {
  24332. var KIND_NON_CJK = "non-cjk";
  24333. var KIND_CJ_LETTER = "cj-letter";
  24334. var KIND_K_LETTER = "k-letter";
  24335. var KIND_CJK_PUNCTUATION = "cjk-punctuation";
  24336. var nodes = [];
  24337. (options.proseWrap === "preserve" ? text : text.replace(new RegExp("(".concat(cjkPattern, ")\n(").concat(cjkPattern, ")"), "g"), "$1$2")).split(/([ \t\n]+)/).forEach(function (token, index, tokens) {
  24338. // whitespace
  24339. if (index % 2 === 1) {
  24340. nodes.push({
  24341. type: "whitespace",
  24342. value: /\n/.test(token) ? "\n" : " "
  24343. });
  24344. return;
  24345. } // word separated by whitespace
  24346. if ((index === 0 || index === tokens.length - 1) && token === "") {
  24347. return;
  24348. }
  24349. token.split(new RegExp("(".concat(cjkPattern, ")"))).forEach(function (innerToken, innerIndex, innerTokens) {
  24350. if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
  24351. return;
  24352. } // non-CJK word
  24353. if (innerIndex % 2 === 0) {
  24354. if (innerToken !== "") {
  24355. appendNode({
  24356. type: "word",
  24357. value: innerToken,
  24358. kind: KIND_NON_CJK,
  24359. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  24360. hasTrailingPunctuation: punctuationRegex.test(getLast$3(innerToken))
  24361. });
  24362. }
  24363. return;
  24364. } // CJK character
  24365. appendNode(punctuationRegex.test(innerToken) ? {
  24366. type: "word",
  24367. value: innerToken,
  24368. kind: KIND_CJK_PUNCTUATION,
  24369. hasLeadingPunctuation: true,
  24370. hasTrailingPunctuation: true
  24371. } : {
  24372. type: "word",
  24373. value: innerToken,
  24374. kind: kRegex.test(innerToken) ? KIND_K_LETTER : KIND_CJ_LETTER,
  24375. hasLeadingPunctuation: false,
  24376. hasTrailingPunctuation: false
  24377. });
  24378. });
  24379. });
  24380. return nodes;
  24381. function appendNode(node) {
  24382. var lastNode = getLast$3(nodes);
  24383. if (lastNode && lastNode.type === "word") {
  24384. if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJ_LETTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJ_LETTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) {
  24385. nodes.push({
  24386. type: "whitespace",
  24387. value: " "
  24388. });
  24389. } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
  24390. ![lastNode.value, node.value].some(function (value) {
  24391. return /\u3000/.test(value);
  24392. })) {
  24393. nodes.push({
  24394. type: "whitespace",
  24395. value: ""
  24396. });
  24397. }
  24398. }
  24399. nodes.push(node);
  24400. function isBetween(kind1, kind2) {
  24401. return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
  24402. }
  24403. }
  24404. }
  24405. function getOrderedListItemInfo(orderListItem, originalText) {
  24406. var _originalText$slice$m = originalText.slice(orderListItem.position.start.offset, orderListItem.position.end.offset).match(/^\s*(\d+)(\.|\))(\s*)/),
  24407. _originalText$slice$m2 = _slicedToArray(_originalText$slice$m, 4),
  24408. numberText = _originalText$slice$m2[1],
  24409. marker = _originalText$slice$m2[2],
  24410. leadingSpaces = _originalText$slice$m2[3];
  24411. return {
  24412. numberText: numberText,
  24413. marker: marker,
  24414. leadingSpaces: leadingSpaces
  24415. };
  24416. } // workaround for https://github.com/remarkjs/remark/issues/351
  24417. // leading and trailing newlines are stripped by remark
  24418. function getFencedCodeBlockValue(node, originalText) {
  24419. var text = originalText.slice(node.position.start.offset, node.position.end.offset);
  24420. var leadingSpaceCount = text.match(/^\s*/)[0].length;
  24421. var replaceRegex = new RegExp("^\\s{0,".concat(leadingSpaceCount, "}"));
  24422. var lineContents = text.split("\n");
  24423. var markerStyle = text[leadingSpaceCount]; // ` or ~
  24424. var marker = text.slice(leadingSpaceCount).match(new RegExp("^[".concat(markerStyle, "]+")))[0]; // https://spec.commonmark.org/0.28/#example-104: Closing fences may be indented by 0-3 spaces
  24425. // https://spec.commonmark.org/0.28/#example-93: The closing code fence must be at least as long as the opening fence
  24426. var hasEndMarker = new RegExp("^\\s{0,3}".concat(marker)).test(lineContents[lineContents.length - 1].slice(getIndent(lineContents.length - 1)));
  24427. return lineContents.slice(1, hasEndMarker ? -1 : undefined).map(function (x, i) {
  24428. return x.slice(getIndent(i + 1)).replace(replaceRegex, "");
  24429. }).join("\n");
  24430. function getIndent(lineIndex) {
  24431. return node.position.indent[lineIndex - 1] - 1;
  24432. }
  24433. }
  24434. function mapAst(ast, handler) {
  24435. return function preorder(node, index, parentStack) {
  24436. parentStack = parentStack || [];
  24437. var newNode = handler(node, index, parentStack);
  24438. if (Array.isArray(newNode)) {
  24439. return newNode;
  24440. }
  24441. newNode = Object.assign({}, newNode);
  24442. if (newNode.children) {
  24443. newNode.children = newNode.children.reduce(function (nodes, child, index) {
  24444. var newNodes = preorder(child, index, [newNode].concat(parentStack));
  24445. if (!Array.isArray(newNodes)) {
  24446. newNodes = [newNodes];
  24447. }
  24448. nodes.push.apply(nodes, newNodes);
  24449. return nodes;
  24450. }, []);
  24451. }
  24452. return newNode;
  24453. }(ast, null, null);
  24454. }
  24455. var utils$5 = {
  24456. mapAst: mapAst,
  24457. splitText: splitText,
  24458. punctuationPattern: punctuationPattern,
  24459. getFencedCodeBlockValue: getFencedCodeBlockValue,
  24460. getOrderedListItemInfo: getOrderedListItemInfo,
  24461. INLINE_NODE_TYPES: INLINE_NODE_TYPES,
  24462. INLINE_NODE_WRAPPER_TYPES: INLINE_NODE_WRAPPER_TYPES
  24463. };
  24464. var _require$$0$builders$8 = doc.builders,
  24465. hardline$b = _require$$0$builders$8.hardline,
  24466. literalline$5 = _require$$0$builders$8.literalline,
  24467. concat$f = _require$$0$builders$8.concat,
  24468. markAsRoot$3 = _require$$0$builders$8.markAsRoot,
  24469. mapDoc$6 = doc.utils.mapDoc;
  24470. var getFencedCodeBlockValue$1 = utils$5.getFencedCodeBlockValue;
  24471. function embed$4(path, print, textToDoc, options) {
  24472. var node = path.getValue();
  24473. if (node.type === "code" && node.lang !== null) {
  24474. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  24475. var langMatch = node.lang.match(/^[A-Za-z0-9_-]+/);
  24476. var lang = langMatch ? langMatch[0] : "";
  24477. var parser = getParserName(lang);
  24478. if (parser) {
  24479. var styleUnit = options.__inJsTemplate ? "~" : "`";
  24480. var style = styleUnit.repeat(Math.max(3, util.getMaxContinuousCount(node.value, styleUnit) + 1));
  24481. var doc = textToDoc(getFencedCodeBlockValue$1(node, options.originalText), {
  24482. parser: parser
  24483. });
  24484. return markAsRoot$3(concat$f([style, node.lang, hardline$b, replaceNewlinesWithLiterallines(doc), style]));
  24485. }
  24486. }
  24487. if (node.type === "yaml") {
  24488. return markAsRoot$3(concat$f(["---", hardline$b, node.value && node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  24489. parser: "yaml"
  24490. })) : "", "---"]));
  24491. } // MDX
  24492. switch (node.type) {
  24493. case "importExport":
  24494. return textToDoc(node.value, {
  24495. parser: "babel"
  24496. });
  24497. case "jsx":
  24498. return textToDoc(node.value, {
  24499. parser: "__js_expression"
  24500. });
  24501. }
  24502. return null;
  24503. function getParserName(lang) {
  24504. var supportInfo = support.getSupportInfo(null, {
  24505. plugins: options.plugins
  24506. });
  24507. var language = supportInfo.languages.find(function (language) {
  24508. return language.name.toLowerCase() === lang || language.aliases && language.aliases.indexOf(lang) !== -1 || language.extensions && language.extensions.find(function (ext) {
  24509. return ext.substring(1) === lang;
  24510. });
  24511. });
  24512. if (language) {
  24513. return language.parsers[0];
  24514. }
  24515. return null;
  24516. }
  24517. function replaceNewlinesWithLiterallines(doc) {
  24518. return mapDoc$6(doc, function (currentDoc) {
  24519. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$f(currentDoc.split(/(\n)/g).map(function (v, i) {
  24520. return i % 2 === 0 ? v : literalline$5;
  24521. })) : currentDoc;
  24522. });
  24523. }
  24524. }
  24525. var embed_1$2 = embed$4;
  24526. var pragmas = ["format", "prettier"];
  24527. function startWithPragma(text) {
  24528. var pragma = "@(".concat(pragmas.join("|"), ")");
  24529. var regex = new RegExp(["<!--\\s*".concat(pragma, "\\s*-->"), "<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*".concat(pragma, "[^\\S\n]*($|\n)[\\s\\S]*\n.*-->")].join("|"), "m");
  24530. var matched = text.match(regex);
  24531. return matched && matched.index === 0;
  24532. }
  24533. var pragma$4 = {
  24534. startWithPragma: startWithPragma,
  24535. hasPragma: function hasPragma(text) {
  24536. return startWithPragma(frontMatter(text).content.trimLeft());
  24537. },
  24538. insertPragma: function insertPragma(text) {
  24539. var extracted = frontMatter(text);
  24540. var pragma = "<!-- @".concat(pragmas[0], " -->");
  24541. return extracted.frontMatter ? "".concat(extracted.frontMatter.raw, "\n\n").concat(pragma, "\n\n").concat(extracted.content) : "".concat(pragma, "\n\n").concat(extracted.content);
  24542. }
  24543. };
  24544. var getOrderedListItemInfo$1 = utils$5.getOrderedListItemInfo,
  24545. mapAst$1 = utils$5.mapAst,
  24546. splitText$1 = utils$5.splitText; // 0x0 ~ 0x10ffff
  24547. // eslint-disable-next-line no-control-regex
  24548. var isSingleCharRegex = /^([\u0000-\uffff]|[\ud800-\udbff][\udc00-\udfff])$/;
  24549. function preprocess$2(ast, options) {
  24550. ast = restoreUnescapedCharacter(ast, options);
  24551. ast = mergeContinuousTexts(ast);
  24552. ast = transformInlineCode(ast);
  24553. ast = transformIndentedCodeblockAndMarkItsParentList(ast, options);
  24554. ast = markAlignedList(ast, options);
  24555. ast = splitTextIntoSentences(ast, options);
  24556. ast = transformImportExport(ast);
  24557. ast = mergeContinuousImportExport(ast);
  24558. return ast;
  24559. }
  24560. function transformImportExport(ast) {
  24561. return mapAst$1(ast, function (node) {
  24562. if (node.type !== "import" && node.type !== "export") {
  24563. return node;
  24564. }
  24565. return Object.assign({}, node, {
  24566. type: "importExport"
  24567. });
  24568. });
  24569. }
  24570. function transformInlineCode(ast) {
  24571. return mapAst$1(ast, function (node) {
  24572. if (node.type !== "inlineCode") {
  24573. return node;
  24574. }
  24575. return Object.assign({}, node, {
  24576. value: node.value.replace(/\s+/g, " ")
  24577. });
  24578. });
  24579. }
  24580. function restoreUnescapedCharacter(ast, options) {
  24581. return mapAst$1(ast, function (node) {
  24582. return node.type !== "text" ? node : Object.assign({}, node, {
  24583. value: node.value !== "*" && node.value !== "_" && node.value !== "$" && // handle these cases in printer
  24584. isSingleCharRegex.test(node.value) && node.position.end.offset - node.position.start.offset !== node.value.length ? options.originalText.slice(node.position.start.offset, node.position.end.offset) : node.value
  24585. });
  24586. });
  24587. }
  24588. function mergeContinuousImportExport(ast) {
  24589. return mergeChildren(ast, function (prevNode, node) {
  24590. return prevNode.type === "importExport" && node.type === "importExport";
  24591. }, function (prevNode, node) {
  24592. return {
  24593. type: "importExport",
  24594. value: prevNode.value + "\n\n" + node.value,
  24595. position: {
  24596. start: prevNode.position.start,
  24597. end: node.position.end
  24598. }
  24599. };
  24600. });
  24601. }
  24602. function mergeChildren(ast, shouldMerge, mergeNode) {
  24603. return mapAst$1(ast, function (node) {
  24604. if (!node.children) {
  24605. return node;
  24606. }
  24607. var children = node.children.reduce(function (current, child) {
  24608. var lastChild = current[current.length - 1];
  24609. if (lastChild && shouldMerge(lastChild, child)) {
  24610. current.splice(-1, 1, mergeNode(lastChild, child));
  24611. } else {
  24612. current.push(child);
  24613. }
  24614. return current;
  24615. }, []);
  24616. return Object.assign({}, node, {
  24617. children: children
  24618. });
  24619. });
  24620. }
  24621. function mergeContinuousTexts(ast) {
  24622. return mergeChildren(ast, function (prevNode, node) {
  24623. return prevNode.type === "text" && node.type === "text";
  24624. }, function (prevNode, node) {
  24625. return {
  24626. type: "text",
  24627. value: prevNode.value + node.value,
  24628. position: {
  24629. start: prevNode.position.start,
  24630. end: node.position.end
  24631. }
  24632. };
  24633. });
  24634. }
  24635. function splitTextIntoSentences(ast, options) {
  24636. return mapAst$1(ast, function (node, index, _ref) {
  24637. var _ref2 = _slicedToArray(_ref, 1),
  24638. parentNode = _ref2[0];
  24639. if (node.type !== "text") {
  24640. return node;
  24641. }
  24642. var value = node.value;
  24643. if (parentNode.type === "paragraph") {
  24644. if (index === 0) {
  24645. value = value.trimLeft();
  24646. }
  24647. if (index === parentNode.children.length - 1) {
  24648. value = value.trimRight();
  24649. }
  24650. }
  24651. return {
  24652. type: "sentence",
  24653. position: node.position,
  24654. children: splitText$1(value, options)
  24655. };
  24656. });
  24657. }
  24658. function transformIndentedCodeblockAndMarkItsParentList(ast, options) {
  24659. return mapAst$1(ast, function (node, index, parentStack) {
  24660. if (node.type === "code") {
  24661. // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  24662. var isIndented = /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset));
  24663. node.isIndented = isIndented;
  24664. if (isIndented) {
  24665. for (var i = 0; i < parentStack.length; i++) {
  24666. var parent = parentStack[i]; // no need to check checked items
  24667. if (parent.hasIndentedCodeblock) {
  24668. break;
  24669. }
  24670. if (parent.type === "list") {
  24671. parent.hasIndentedCodeblock = true;
  24672. }
  24673. }
  24674. }
  24675. }
  24676. return node;
  24677. });
  24678. }
  24679. function markAlignedList(ast, options) {
  24680. return mapAst$1(ast, function (node, index, parentStack) {
  24681. if (node.type === "list" && node.children.length !== 0) {
  24682. // if one of its parents is not aligned, it's not possible to be aligned in sub-lists
  24683. for (var i = 0; i < parentStack.length; i++) {
  24684. var parent = parentStack[i];
  24685. if (parent.type === "list" && !parent.isAligned) {
  24686. node.isAligned = false;
  24687. return node;
  24688. }
  24689. }
  24690. node.isAligned = isAligned(node);
  24691. }
  24692. return node;
  24693. });
  24694. function getListItemStart(listItem) {
  24695. return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1;
  24696. }
  24697. function isAligned(list) {
  24698. if (!list.ordered) {
  24699. /**
  24700. * - 123
  24701. * - 123
  24702. */
  24703. return true;
  24704. }
  24705. var _list$children = _slicedToArray(list.children, 2),
  24706. firstItem = _list$children[0],
  24707. secondItem = _list$children[1];
  24708. var firstInfo = getOrderedListItemInfo$1(firstItem, options.originalText);
  24709. if (firstInfo.leadingSpaces.length > 1) {
  24710. /**
  24711. * 1. 123
  24712. *
  24713. * 1. 123
  24714. * 1. 123
  24715. */
  24716. return true;
  24717. }
  24718. var firstStart = getListItemStart(firstItem);
  24719. if (firstStart === -1) {
  24720. /**
  24721. * 1.
  24722. *
  24723. * 1.
  24724. * 1.
  24725. */
  24726. return false;
  24727. }
  24728. if (list.children.length === 1) {
  24729. /**
  24730. * aligned:
  24731. *
  24732. * 11. 123
  24733. *
  24734. * not aligned:
  24735. *
  24736. * 1. 123
  24737. */
  24738. return firstStart % options.tabWidth === 0;
  24739. }
  24740. var secondStart = getListItemStart(secondItem);
  24741. if (firstStart !== secondStart) {
  24742. /**
  24743. * 11. 123
  24744. * 1. 123
  24745. *
  24746. * 1. 123
  24747. * 11. 123
  24748. */
  24749. return false;
  24750. }
  24751. if (firstStart % options.tabWidth === 0) {
  24752. /**
  24753. * 11. 123
  24754. * 12. 123
  24755. */
  24756. return true;
  24757. }
  24758. /**
  24759. * aligned:
  24760. *
  24761. * 11. 123
  24762. * 1. 123
  24763. *
  24764. * not aligned:
  24765. *
  24766. * 1. 123
  24767. * 2. 123
  24768. */
  24769. var secondInfo = getOrderedListItemInfo$1(secondItem, options.originalText);
  24770. return secondInfo.leadingSpaces.length > 1;
  24771. }
  24772. }
  24773. var preprocess_1$2 = preprocess$2;
  24774. var _require$$0$builders$9 = doc.builders,
  24775. breakParent$4 = _require$$0$builders$9.breakParent,
  24776. concat$g = _require$$0$builders$9.concat,
  24777. join$b = _require$$0$builders$9.join,
  24778. line$8 = _require$$0$builders$9.line,
  24779. literalline$6 = _require$$0$builders$9.literalline,
  24780. markAsRoot$4 = _require$$0$builders$9.markAsRoot,
  24781. hardline$c = _require$$0$builders$9.hardline,
  24782. softline$7 = _require$$0$builders$9.softline,
  24783. ifBreak$7 = _require$$0$builders$9.ifBreak,
  24784. fill$5 = _require$$0$builders$9.fill,
  24785. align$2 = _require$$0$builders$9.align,
  24786. indent$9 = _require$$0$builders$9.indent,
  24787. group$f = _require$$0$builders$9.group,
  24788. mapDoc$7 = doc.utils.mapDoc,
  24789. printDocToString$2 = doc.printer.printDocToString;
  24790. var getFencedCodeBlockValue$2 = utils$5.getFencedCodeBlockValue,
  24791. getOrderedListItemInfo$2 = utils$5.getOrderedListItemInfo,
  24792. splitText$2 = utils$5.splitText,
  24793. punctuationPattern$1 = utils$5.punctuationPattern,
  24794. INLINE_NODE_TYPES$1 = utils$5.INLINE_NODE_TYPES,
  24795. INLINE_NODE_WRAPPER_TYPES$1 = utils$5.INLINE_NODE_WRAPPER_TYPES;
  24796. var replaceEndOfLineWith$2 = util.replaceEndOfLineWith;
  24797. var TRAILING_HARDLINE_NODES = ["importExport"];
  24798. var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  24799. var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition", "jsx"];
  24800. function genericPrint$5(path, options, print) {
  24801. var node = path.getValue();
  24802. if (shouldRemainTheSameContent(path)) {
  24803. return concat$g(splitText$2(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(function (node) {
  24804. return node.type === "word" ? node.value : node.value === "" ? "" : printLine(path, node.value, options);
  24805. }));
  24806. }
  24807. switch (node.type) {
  24808. case "root":
  24809. if (node.children.length === 0) {
  24810. return "";
  24811. }
  24812. return concat$g([normalizeDoc(printRoot(path, options, print)), TRAILING_HARDLINE_NODES.indexOf(getLastDescendantNode(node).type) === -1 ? hardline$c : ""]);
  24813. case "paragraph":
  24814. return printChildren$2(path, options, print, {
  24815. postprocessor: fill$5
  24816. });
  24817. case "sentence":
  24818. return printChildren$2(path, options, print);
  24819. case "word":
  24820. return node.value.replace(/[*$]/g, "\\$&") // escape all `*` and `$` (math)
  24821. .replace(new RegExp(["(^|".concat(punctuationPattern$1, ")(_+)"), "(_+)(".concat(punctuationPattern$1, "|$)")].join("|"), "g"), function (_, text1, underscore1, underscore2, text2) {
  24822. return (underscore1 ? "".concat(text1).concat(underscore1) : "".concat(underscore2).concat(text2)).replace(/_/g, "\\_");
  24823. });
  24824. // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  24825. case "whitespace":
  24826. {
  24827. var parentNode = path.getParentNode();
  24828. var index = parentNode.children.indexOf(node);
  24829. var nextNode = parentNode.children[index + 1];
  24830. var proseWrap = // leading char that may cause different syntax
  24831. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value) ? "never" : options.proseWrap;
  24832. return printLine(path, node.value, {
  24833. proseWrap: proseWrap
  24834. });
  24835. }
  24836. case "emphasis":
  24837. {
  24838. var _parentNode = path.getParentNode();
  24839. var _index = _parentNode.children.indexOf(node);
  24840. var prevNode = _parentNode.children[_index - 1];
  24841. var _nextNode = _parentNode.children[_index + 1];
  24842. var hasPrevOrNextWord = // `1*2*3` is considered emphasis but `1_2_3` is not
  24843. prevNode && prevNode.type === "sentence" && prevNode.children.length > 0 && util.getLast(prevNode.children).type === "word" && !util.getLast(prevNode.children).hasTrailingPunctuation || _nextNode && _nextNode.type === "sentence" && _nextNode.children.length > 0 && _nextNode.children[0].type === "word" && !_nextNode.children[0].hasLeadingPunctuation;
  24844. var style = hasPrevOrNextWord || getAncestorNode$2(path, "emphasis") ? "*" : "_";
  24845. return concat$g([style, printChildren$2(path, options, print), style]);
  24846. }
  24847. case "strong":
  24848. return concat$g(["**", printChildren$2(path, options, print), "**"]);
  24849. case "delete":
  24850. return concat$g(["~~", printChildren$2(path, options, print), "~~"]);
  24851. case "inlineCode":
  24852. {
  24853. var backtickCount = util.getMinNotPresentContinuousCount(node.value, "`");
  24854. var _style = "`".repeat(backtickCount || 1);
  24855. var gap = backtickCount ? " " : "";
  24856. return concat$g([_style, gap, node.value, gap, _style]);
  24857. }
  24858. case "link":
  24859. switch (options.originalText[node.position.start.offset]) {
  24860. case "<":
  24861. {
  24862. var mailto = "mailto:";
  24863. var url = // <hello@example.com> is parsed as { url: "mailto:hello@example.com" }
  24864. node.url.startsWith(mailto) && options.originalText.slice(node.position.start.offset + 1, node.position.start.offset + 1 + mailto.length) !== mailto ? node.url.slice(mailto.length) : node.url;
  24865. return concat$g(["<", url, ">"]);
  24866. }
  24867. case "[":
  24868. return concat$g(["[", printChildren$2(path, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  24869. default:
  24870. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  24871. }
  24872. case "image":
  24873. return concat$g(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  24874. case "blockquote":
  24875. return concat$g(["> ", align$2("> ", printChildren$2(path, options, print))]);
  24876. case "heading":
  24877. return concat$g(["#".repeat(node.depth) + " ", printChildren$2(path, options, print)]);
  24878. case "code":
  24879. {
  24880. if (node.isIndented) {
  24881. // indented code block
  24882. var alignment = " ".repeat(4);
  24883. return align$2(alignment, concat$g([alignment, concat$g(replaceEndOfLineWith$2(node.value, hardline$c))]));
  24884. } // fenced code block
  24885. var styleUnit = options.__inJsTemplate ? "~" : "`";
  24886. var _style2 = styleUnit.repeat(Math.max(3, util.getMaxContinuousCount(node.value, styleUnit) + 1));
  24887. return concat$g([_style2, node.lang || "", hardline$c, concat$g(replaceEndOfLineWith$2(getFencedCodeBlockValue$2(node, options.originalText), hardline$c)), hardline$c, _style2]);
  24888. }
  24889. case "yaml":
  24890. case "toml":
  24891. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  24892. case "html":
  24893. {
  24894. var _parentNode2 = path.getParentNode();
  24895. var value = _parentNode2.type === "root" && util.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
  24896. var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
  24897. return concat$g(replaceEndOfLineWith$2(value, isHtmlComment ? hardline$c : markAsRoot$4(literalline$6)));
  24898. }
  24899. case "list":
  24900. {
  24901. var nthSiblingIndex = getNthListSiblingIndex(node, path.getParentNode());
  24902. var isGitDiffFriendlyOrderedList = node.ordered && node.children.length > 1 && +getOrderedListItemInfo$2(node.children[1], options.originalText).numberText === 1;
  24903. return printChildren$2(path, options, print, {
  24904. processor: function processor(childPath, index) {
  24905. var prefix = getPrefix();
  24906. return concat$g([prefix, align$2(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
  24907. function getPrefix() {
  24908. var rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* ";
  24909. return node.isAligned ||
  24910. /* workaround for https://github.com/remarkjs/remark/issues/315 */
  24911. node.hasIndentedCodeblock ? alignListPrefix(rawPrefix, options) : rawPrefix;
  24912. }
  24913. }
  24914. });
  24915. }
  24916. case "thematicBreak":
  24917. {
  24918. var counter = getAncestorCounter$1(path, "list");
  24919. if (counter === -1) {
  24920. return "---";
  24921. }
  24922. var _nthSiblingIndex = getNthListSiblingIndex(path.getParentNode(counter), path.getParentNode(counter + 1));
  24923. return _nthSiblingIndex % 2 === 0 ? "***" : "---";
  24924. }
  24925. case "linkReference":
  24926. return concat$g(["[", printChildren$2(path, options, print), "]", node.referenceType === "full" ? concat$g(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
  24927. case "imageReference":
  24928. switch (node.referenceType) {
  24929. case "full":
  24930. return concat$g(["![", node.alt || "", "][", node.identifier, "]"]);
  24931. default:
  24932. return concat$g(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
  24933. }
  24934. case "definition":
  24935. {
  24936. var lineOrSpace = options.proseWrap === "always" ? line$8 : " ";
  24937. return group$f(concat$g([concat$g(["[", node.identifier, "]:"]), indent$9(concat$g([lineOrSpace, printUrl(node.url), node.title === null ? "" : concat$g([lineOrSpace, printTitle(node.title, options, false)])]))]));
  24938. }
  24939. case "footnote":
  24940. return concat$g(["[^", printChildren$2(path, options, print), "]"]);
  24941. case "footnoteReference":
  24942. return concat$g(["[^", node.identifier, "]"]);
  24943. case "footnoteDefinition":
  24944. {
  24945. var _nextNode2 = path.getParentNode().children[path.getName() + 1];
  24946. var shouldInlineFootnote = node.children.length === 1 && node.children[0].type === "paragraph" && (options.proseWrap === "never" || options.proseWrap === "preserve" && node.children[0].position.start.line === node.children[0].position.end.line);
  24947. return concat$g(["[^", node.identifier, "]: ", shouldInlineFootnote ? printChildren$2(path, options, print) : group$f(concat$g([align$2(" ".repeat(options.tabWidth), printChildren$2(path, options, print, {
  24948. processor: function processor(childPath, index) {
  24949. return index === 0 ? group$f(concat$g([softline$7, softline$7, childPath.call(print)])) : childPath.call(print);
  24950. }
  24951. })), _nextNode2 && _nextNode2.type === "footnoteDefinition" ? softline$7 : ""]))]);
  24952. }
  24953. case "table":
  24954. return printTable(path, options, print);
  24955. case "tableCell":
  24956. return printChildren$2(path, options, print);
  24957. case "break":
  24958. return /\s/.test(options.originalText[node.position.start.offset]) ? concat$g([" ", markAsRoot$4(literalline$6)]) : concat$g(["\\", hardline$c]);
  24959. case "liquidNode":
  24960. return concat$g(replaceEndOfLineWith$2(node.value, hardline$c));
  24961. // MDX
  24962. case "importExport":
  24963. case "jsx":
  24964. return node.value;
  24965. // fallback to the original text if multiparser failed
  24966. case "math":
  24967. return concat$g(["$$", hardline$c, node.value ? concat$g([concat$g(replaceEndOfLineWith$2(node.value, hardline$c)), hardline$c]) : "", "$$"]);
  24968. case "inlineMath":
  24969. {
  24970. // remark-math trims content but we don't want to remove whitespaces
  24971. // since it's very possible that it's recognized as math accidentally
  24972. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  24973. }
  24974. case "tableRow": // handled in "table"
  24975. case "listItem": // handled in "list"
  24976. default:
  24977. throw new Error("Unknown markdown type ".concat(JSON.stringify(node.type)));
  24978. }
  24979. }
  24980. function printListItem(path, options, print, listPrefix) {
  24981. var node = path.getValue();
  24982. var prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  24983. return concat$g([prefix, printChildren$2(path, options, print, {
  24984. processor: function processor(childPath, index) {
  24985. if (index === 0 && childPath.getValue().type !== "list") {
  24986. return align$2(" ".repeat(prefix.length), childPath.call(print));
  24987. }
  24988. var alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  24989. );
  24990. return concat$g([alignment, align$2(alignment, childPath.call(print))]);
  24991. }
  24992. })]);
  24993. }
  24994. function alignListPrefix(prefix, options) {
  24995. var additionalSpaces = getAdditionalSpaces();
  24996. return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  24997. );
  24998. function getAdditionalSpaces() {
  24999. var restSpaces = prefix.length % options.tabWidth;
  25000. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  25001. }
  25002. }
  25003. function getNthListSiblingIndex(node, parentNode) {
  25004. return getNthSiblingIndex(node, parentNode, function (siblingNode) {
  25005. return siblingNode.ordered === node.ordered;
  25006. });
  25007. }
  25008. function getNthSiblingIndex(node, parentNode, condition) {
  25009. condition = condition || function () {
  25010. return true;
  25011. };
  25012. var index = -1;
  25013. var _iteratorNormalCompletion = true;
  25014. var _didIteratorError = false;
  25015. var _iteratorError = undefined;
  25016. try {
  25017. for (var _iterator = parentNode.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  25018. var childNode = _step.value;
  25019. if (childNode.type === node.type && condition(childNode)) {
  25020. index++;
  25021. } else {
  25022. index = -1;
  25023. }
  25024. if (childNode === node) {
  25025. return index;
  25026. }
  25027. }
  25028. } catch (err) {
  25029. _didIteratorError = true;
  25030. _iteratorError = err;
  25031. } finally {
  25032. try {
  25033. if (!_iteratorNormalCompletion && _iterator.return != null) {
  25034. _iterator.return();
  25035. }
  25036. } finally {
  25037. if (_didIteratorError) {
  25038. throw _iteratorError;
  25039. }
  25040. }
  25041. }
  25042. }
  25043. function getAncestorCounter$1(path, typeOrTypes) {
  25044. var types = [].concat(typeOrTypes);
  25045. var counter = -1;
  25046. var ancestorNode;
  25047. while (ancestorNode = path.getParentNode(++counter)) {
  25048. if (types.indexOf(ancestorNode.type) !== -1) {
  25049. return counter;
  25050. }
  25051. }
  25052. return -1;
  25053. }
  25054. function getAncestorNode$2(path, typeOrTypes) {
  25055. var counter = getAncestorCounter$1(path, typeOrTypes);
  25056. return counter === -1 ? null : path.getParentNode(counter);
  25057. }
  25058. function printLine(path, value, options) {
  25059. if (options.proseWrap === "preserve" && value === "\n") {
  25060. return hardline$c;
  25061. }
  25062. var isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path, SINGLE_LINE_NODE_TYPES);
  25063. return value !== "" ? isBreakable ? line$8 : " " : isBreakable ? softline$7 : "";
  25064. }
  25065. function printTable(path, options, print) {
  25066. var hardlineWithoutBreakParent = hardline$c.parts[0];
  25067. var node = path.getValue();
  25068. var contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  25069. path.map(function (rowPath) {
  25070. var rowContents = [];
  25071. rowPath.map(function (cellPath) {
  25072. rowContents.push(printDocToString$2(cellPath.call(print), options).formatted);
  25073. }, "children");
  25074. contents.push(rowContents);
  25075. }, "children"); // Get the width of each column
  25076. var columnMaxWidths = contents.reduce(function (currentWidths, rowContents) {
  25077. return currentWidths.map(function (width, columnIndex) {
  25078. return Math.max(width, util.getStringWidth(rowContents[columnIndex]));
  25079. });
  25080. }, contents[0].map(function () {
  25081. return 3;
  25082. }) // minimum width = 3 (---, :--, :-:, --:)
  25083. );
  25084. var alignedTable = join$b(hardlineWithoutBreakParent, [printRow(contents[0]), printSeparator(), join$b(hardlineWithoutBreakParent, contents.slice(1).map(function (rowContents) {
  25085. return printRow(rowContents);
  25086. }))]);
  25087. if (options.proseWrap !== "never") {
  25088. return concat$g([breakParent$4, alignedTable]);
  25089. } // Only if the --prose-wrap never is set and it exceeds the print width.
  25090. var compactTable = join$b(hardlineWithoutBreakParent, [printRow(contents[0],
  25091. /* isCompact */
  25092. true), printSeparator(
  25093. /* isCompact */
  25094. true), join$b(hardlineWithoutBreakParent, contents.slice(1).map(function (rowContents) {
  25095. return printRow(rowContents,
  25096. /* isCompact */
  25097. true);
  25098. }))]);
  25099. return concat$g([breakParent$4, group$f(ifBreak$7(compactTable, alignedTable))]);
  25100. function printSeparator(isCompact) {
  25101. return concat$g(["| ", join$b(" | ", columnMaxWidths.map(function (width, index) {
  25102. var spaces = isCompact ? 3 : width;
  25103. switch (node.align[index]) {
  25104. case "left":
  25105. return ":" + "-".repeat(spaces - 1);
  25106. case "right":
  25107. return "-".repeat(spaces - 1) + ":";
  25108. case "center":
  25109. return ":" + "-".repeat(spaces - 2) + ":";
  25110. default:
  25111. return "-".repeat(spaces);
  25112. }
  25113. })), " |"]);
  25114. }
  25115. function printRow(rowContents, isCompact) {
  25116. return concat$g(["| ", join$b(" | ", isCompact ? rowContents : rowContents.map(function (rowContent, columnIndex) {
  25117. switch (node.align[columnIndex]) {
  25118. case "right":
  25119. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  25120. case "center":
  25121. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  25122. default:
  25123. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  25124. }
  25125. })), " |"]);
  25126. }
  25127. function alignLeft(text, width) {
  25128. var spaces = width - util.getStringWidth(text);
  25129. return concat$g([text, " ".repeat(spaces)]);
  25130. }
  25131. function alignRight(text, width) {
  25132. var spaces = width - util.getStringWidth(text);
  25133. return concat$g([" ".repeat(spaces), text]);
  25134. }
  25135. function alignCenter(text, width) {
  25136. var spaces = width - util.getStringWidth(text);
  25137. var left = Math.floor(spaces / 2);
  25138. var right = spaces - left;
  25139. return concat$g([" ".repeat(left), text, " ".repeat(right)]);
  25140. }
  25141. }
  25142. function printRoot(path, options, print) {
  25143. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  25144. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  25145. var ignoreRanges = [];
  25146. /** @type {IgnorePosition | null} */
  25147. var ignoreStart = null;
  25148. var children = path.getValue().children;
  25149. children.forEach(function (childNode, index) {
  25150. switch (isPrettierIgnore$1(childNode)) {
  25151. case "start":
  25152. if (ignoreStart === null) {
  25153. ignoreStart = {
  25154. index: index,
  25155. offset: childNode.position.end.offset
  25156. };
  25157. }
  25158. break;
  25159. case "end":
  25160. if (ignoreStart !== null) {
  25161. ignoreRanges.push({
  25162. start: ignoreStart,
  25163. end: {
  25164. index: index,
  25165. offset: childNode.position.start.offset
  25166. }
  25167. });
  25168. ignoreStart = null;
  25169. }
  25170. break;
  25171. }
  25172. });
  25173. return printChildren$2(path, options, print, {
  25174. processor: function processor(childPath, index) {
  25175. if (ignoreRanges.length !== 0) {
  25176. var ignoreRange = ignoreRanges[0];
  25177. if (index === ignoreRange.start.index) {
  25178. return concat$g([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
  25179. }
  25180. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  25181. return false;
  25182. }
  25183. if (index === ignoreRange.end.index) {
  25184. ignoreRanges.shift();
  25185. return false;
  25186. }
  25187. }
  25188. return childPath.call(print);
  25189. }
  25190. });
  25191. }
  25192. function printChildren$2(path, options, print, events) {
  25193. events = events || {};
  25194. var postprocessor = events.postprocessor || concat$g;
  25195. var processor = events.processor || function (childPath) {
  25196. return childPath.call(print);
  25197. };
  25198. var node = path.getValue();
  25199. var parts = [];
  25200. var lastChildNode;
  25201. path.map(function (childPath, index) {
  25202. var childNode = childPath.getValue();
  25203. var result = processor(childPath, index);
  25204. if (result !== false) {
  25205. var data = {
  25206. parts: parts,
  25207. prevNode: lastChildNode,
  25208. parentNode: node,
  25209. options: options
  25210. };
  25211. if (!shouldNotPrePrintHardline(childNode, data)) {
  25212. parts.push(hardline$c);
  25213. if (lastChildNode && TRAILING_HARDLINE_NODES.indexOf(lastChildNode.type) !== -1) {
  25214. if (shouldPrePrintTripleHardline(childNode, data)) {
  25215. parts.push(hardline$c);
  25216. }
  25217. } else {
  25218. if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
  25219. parts.push(hardline$c);
  25220. }
  25221. if (shouldPrePrintTripleHardline(childNode, data)) {
  25222. parts.push(hardline$c);
  25223. }
  25224. }
  25225. }
  25226. parts.push(result);
  25227. lastChildNode = childNode;
  25228. }
  25229. }, "children");
  25230. return postprocessor(parts);
  25231. }
  25232. function getLastDescendantNode(node) {
  25233. var current = node;
  25234. while (current.children && current.children.length !== 0) {
  25235. current = current.children[current.children.length - 1];
  25236. }
  25237. return current;
  25238. }
  25239. /** @return {false | 'next' | 'start' | 'end'} */
  25240. function isPrettierIgnore$1(node) {
  25241. if (node.type !== "html") {
  25242. return false;
  25243. }
  25244. var match = node.value.match(/^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/);
  25245. return match === null ? false : match[1] ? match[1] : "next";
  25246. }
  25247. function isInlineNode(node) {
  25248. return node && INLINE_NODE_TYPES$1.indexOf(node.type) !== -1;
  25249. }
  25250. function isEndsWithHardLine(node) {
  25251. return node && /\n+$/.test(node.value);
  25252. }
  25253. function last(nodes) {
  25254. return nodes && nodes[nodes.length - 1];
  25255. }
  25256. function shouldNotPrePrintHardline(node, _ref) {
  25257. var parentNode = _ref.parentNode,
  25258. parts = _ref.parts,
  25259. prevNode = _ref.prevNode;
  25260. var isFirstNode = parts.length === 0;
  25261. var isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES$1.indexOf(parentNode.type) !== -1;
  25262. var isAfterHardlineNode = prevNode && (isEndsWithHardLine(prevNode) || isEndsWithHardLine(last(prevNode.children)));
  25263. return isFirstNode || isInlineNode(node) || isInlineHTML || isAfterHardlineNode;
  25264. }
  25265. function shouldPrePrintDoubleHardline(node, _ref2) {
  25266. var parentNode = _ref2.parentNode,
  25267. prevNode = _ref2.prevNode;
  25268. var prevNodeType = prevNode && prevNode.type;
  25269. var nodeType = node.type;
  25270. var isSequence = prevNodeType === nodeType;
  25271. var isSiblingNode = isSequence && SIBLING_NODE_TYPES.indexOf(nodeType) !== -1;
  25272. var isInTightListItem = parentNode.type === "listItem" && !parentNode.loose;
  25273. var isPrevNodeLooseListItem = prevNodeType === "listItem" && prevNode.loose;
  25274. var isPrevNodePrettierIgnore = isPrettierIgnore$1(prevNode) === "next";
  25275. var isBlockHtmlWithoutBlankLineBetweenPrevHtml = nodeType === "html" && prevNodeType === "html" && prevNode.position.end.line + 1 === node.position.start.line;
  25276. var isJsxInlineSibling = prevNodeType === "jsx" && isInlineNode(node) || nodeType === "jsx" && isInlineNode(prevNode);
  25277. return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml || isJsxInlineSibling);
  25278. }
  25279. function shouldPrePrintTripleHardline(node, data) {
  25280. var isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  25281. var isIndentedCode = node.type === "code" && node.isIndented;
  25282. return isPrevNodeList && isIndentedCode;
  25283. }
  25284. function shouldRemainTheSameContent(path) {
  25285. var ancestorNode = getAncestorNode$2(path, ["linkReference", "imageReference"]);
  25286. return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
  25287. }
  25288. function normalizeDoc(doc) {
  25289. return mapDoc$7(doc, function (currentDoc) {
  25290. if (!currentDoc.parts) {
  25291. return currentDoc;
  25292. }
  25293. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  25294. return currentDoc.parts[0];
  25295. }
  25296. var parts = [];
  25297. currentDoc.parts.forEach(function (part) {
  25298. if (part.type === "concat") {
  25299. parts.push.apply(parts, part.parts);
  25300. } else if (part !== "") {
  25301. parts.push(part);
  25302. }
  25303. });
  25304. return Object.assign({}, currentDoc, {
  25305. parts: normalizeParts$2(parts)
  25306. });
  25307. });
  25308. }
  25309. function printUrl(url, dangerousCharOrChars) {
  25310. var dangerousChars = [" "].concat(dangerousCharOrChars || []);
  25311. return new RegExp(dangerousChars.map(function (x) {
  25312. return "\\".concat(x);
  25313. }).join("|")).test(url) ? "<".concat(url, ">") : url;
  25314. }
  25315. function printTitle(title, options, printSpace) {
  25316. if (printSpace == null) {
  25317. printSpace = true;
  25318. }
  25319. if (!title) {
  25320. return "";
  25321. }
  25322. if (printSpace) {
  25323. return " " + printTitle(title, options, false);
  25324. }
  25325. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  25326. return "(".concat(title, ")"); // avoid escaped quotes
  25327. } // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  25328. var singleCount = title.split("'").length - 1;
  25329. var doubleCount = title.split('"').length - 1;
  25330. var quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
  25331. title = title.replace(new RegExp("(".concat(quote, ")"), "g"), "\\$1");
  25332. return "".concat(quote).concat(title).concat(quote);
  25333. }
  25334. function normalizeParts$2(parts) {
  25335. return parts.reduce(function (current, part) {
  25336. var lastPart = util.getLast(current);
  25337. if (typeof lastPart === "string" && typeof part === "string") {
  25338. current.splice(-1, 1, lastPart + part);
  25339. } else {
  25340. current.push(part);
  25341. }
  25342. return current;
  25343. }, []);
  25344. }
  25345. function clamp(value, min, max) {
  25346. return value < min ? min : value > max ? max : value;
  25347. }
  25348. function clean$6(ast, newObj, parent) {
  25349. delete newObj.position;
  25350. delete newObj.raw; // front-matter
  25351. // for codeblock
  25352. if (ast.type === "code" || ast.type === "yaml" || ast.type === "import" || ast.type === "export" || ast.type === "jsx") {
  25353. delete newObj.value;
  25354. }
  25355. if (ast.type === "list") {
  25356. delete newObj.isAligned;
  25357. } // texts can be splitted or merged
  25358. if (ast.type === "text") {
  25359. return null;
  25360. }
  25361. if (ast.type === "inlineCode") {
  25362. newObj.value = ast.value.replace(/[ \t\n]+/g, " ");
  25363. } // for insert pragma
  25364. if (parent && parent.type === "root" && parent.children.length > 0 && (parent.children[0] === ast || (parent.children[0].type === "yaml" || parent.children[0].type === "toml") && parent.children[1] === ast) && ast.type === "html" && pragma$4.startWithPragma(ast.value)) {
  25365. return null;
  25366. }
  25367. }
  25368. function hasPrettierIgnore$4(path) {
  25369. var index = +path.getName();
  25370. if (index === 0) {
  25371. return false;
  25372. }
  25373. var prevNode = path.getParentNode().children[index - 1];
  25374. return isPrettierIgnore$1(prevNode) === "next";
  25375. }
  25376. var printerMarkdown = {
  25377. preprocess: preprocess_1$2,
  25378. print: genericPrint$5,
  25379. embed: embed_1$2,
  25380. massageAstNode: clean$6,
  25381. hasPrettierIgnore: hasPrettierIgnore$4,
  25382. insertPragma: pragma$4.insertPragma
  25383. };
  25384. var options$6 = {
  25385. proseWrap: commonOptions.proseWrap,
  25386. singleQuote: commonOptions.singleQuote
  25387. };
  25388. var name$g = "Markdown";
  25389. var type$f = "prose";
  25390. var aliases$5 = [
  25391. "pandoc"
  25392. ];
  25393. var aceMode$f = "markdown";
  25394. var codemirrorMode$b = "gfm";
  25395. var codemirrorMimeType$b = "text/x-gfm";
  25396. var wrap = true;
  25397. var extensions$f = [
  25398. ".md",
  25399. ".markdown",
  25400. ".mdown",
  25401. ".mdwn",
  25402. ".mdx",
  25403. ".mkd",
  25404. ".mkdn",
  25405. ".mkdown",
  25406. ".ronn",
  25407. ".workbook"
  25408. ];
  25409. var filenames$3 = [
  25410. "contents.lr"
  25411. ];
  25412. var tmScope$f = "source.gfm";
  25413. var languageId$f = 222;
  25414. var Markdown = {
  25415. name: name$g,
  25416. type: type$f,
  25417. aliases: aliases$5,
  25418. aceMode: aceMode$f,
  25419. codemirrorMode: codemirrorMode$b,
  25420. codemirrorMimeType: codemirrorMimeType$b,
  25421. wrap: wrap,
  25422. extensions: extensions$f,
  25423. filenames: filenames$3,
  25424. tmScope: tmScope$f,
  25425. languageId: languageId$f
  25426. };
  25427. var Markdown$1 = /*#__PURE__*/Object.freeze({
  25428. __proto__: null,
  25429. name: name$g,
  25430. type: type$f,
  25431. aliases: aliases$5,
  25432. aceMode: aceMode$f,
  25433. codemirrorMode: codemirrorMode$b,
  25434. codemirrorMimeType: codemirrorMimeType$b,
  25435. wrap: wrap,
  25436. extensions: extensions$f,
  25437. filenames: filenames$3,
  25438. tmScope: tmScope$f,
  25439. languageId: languageId$f,
  25440. 'default': Markdown
  25441. });
  25442. var require$$0$7 = getCjsExportFromNamespace(Markdown$1);
  25443. var languages$5 = [createLanguage(require$$0$7, function (data) {
  25444. return Object.assign(data, {
  25445. since: "1.8.0",
  25446. parsers: ["remark"],
  25447. vscodeLanguageIds: ["markdown"],
  25448. filenames: data.filenames.concat(["README"]),
  25449. extensions: data.extensions.filter(function (extension) {
  25450. return extension !== ".mdx";
  25451. })
  25452. });
  25453. }), createLanguage(require$$0$7, function (data) {
  25454. return Object.assign(data, {
  25455. name: "MDX",
  25456. since: "1.15.0",
  25457. parsers: ["mdx"],
  25458. vscodeLanguageIds: ["mdx"],
  25459. filenames: [],
  25460. extensions: [".mdx"]
  25461. });
  25462. })];
  25463. var printers$5 = {
  25464. mdast: printerMarkdown
  25465. };
  25466. var languageMarkdown = {
  25467. languages: languages$5,
  25468. options: options$6,
  25469. printers: printers$5
  25470. };
  25471. function isPragma(text) {
  25472. return /^\s*@(prettier|format)\s*$/.test(text);
  25473. }
  25474. function hasPragma$4(text) {
  25475. return /^\s*#[^\n\S]*@(prettier|format)\s*?(\n|$)/.test(text);
  25476. }
  25477. function insertPragma$8(text) {
  25478. return "# @format\n\n".concat(text);
  25479. }
  25480. var pragma$5 = {
  25481. isPragma: isPragma,
  25482. hasPragma: hasPragma$4,
  25483. insertPragma: insertPragma$8
  25484. };
  25485. var getLast$4 = util.getLast;
  25486. function getAncestorCount(path, filter) {
  25487. var counter = 0;
  25488. var pathStackLength = path.stack.length - 1;
  25489. for (var i = 0; i < pathStackLength; i++) {
  25490. var value = path.stack[i];
  25491. if (isNode(value) && filter(value)) {
  25492. counter++;
  25493. }
  25494. }
  25495. return counter;
  25496. }
  25497. /**
  25498. * @param {any} value
  25499. * @param {string[]=} types
  25500. */
  25501. function isNode(value, types) {
  25502. return value && typeof value.type === "string" && (!types || types.indexOf(value.type) !== -1);
  25503. }
  25504. function mapNode(node, callback, parent) {
  25505. return callback("children" in node ? Object.assign({}, node, {
  25506. children: node.children.map(function (childNode) {
  25507. return mapNode(childNode, callback, node);
  25508. })
  25509. }) : node, parent);
  25510. }
  25511. function defineShortcut(x, key, getter) {
  25512. Object.defineProperty(x, key, {
  25513. get: getter,
  25514. enumerable: false
  25515. });
  25516. }
  25517. function isNextLineEmpty$5(node, text) {
  25518. var newlineCount = 0;
  25519. var textLength = text.length;
  25520. for (var i = node.position.end.offset - 1; i < textLength; i++) {
  25521. var char = text[i];
  25522. if (char === "\n") {
  25523. newlineCount++;
  25524. }
  25525. if (newlineCount === 1 && /\S/.test(char)) {
  25526. return false;
  25527. }
  25528. if (newlineCount === 2) {
  25529. return true;
  25530. }
  25531. }
  25532. return false;
  25533. }
  25534. function isLastDescendantNode(path) {
  25535. var node = path.getValue();
  25536. switch (node.type) {
  25537. case "tag":
  25538. case "anchor":
  25539. case "comment":
  25540. return false;
  25541. }
  25542. var pathStackLength = path.stack.length;
  25543. for (var i = 1; i < pathStackLength; i++) {
  25544. var item = path.stack[i];
  25545. var parentItem = path.stack[i - 1];
  25546. if (Array.isArray(parentItem) && typeof item === "number" && item !== parentItem.length - 1) {
  25547. return false;
  25548. }
  25549. }
  25550. return true;
  25551. }
  25552. function getLastDescendantNode$1(node) {
  25553. return "children" in node && node.children.length !== 0 ? getLastDescendantNode$1(getLast$4(node.children)) : node;
  25554. }
  25555. function isPrettierIgnore$2(comment) {
  25556. return comment.value.trim() === "prettier-ignore";
  25557. }
  25558. function hasPrettierIgnore$5(path) {
  25559. var node = path.getValue();
  25560. if (node.type === "documentBody") {
  25561. var document = path.getParentNode();
  25562. return hasEndComments(document.head) && isPrettierIgnore$2(getLast$4(document.head.endComments));
  25563. }
  25564. return hasLeadingComments(node) && isPrettierIgnore$2(getLast$4(node.leadingComments));
  25565. }
  25566. function isEmptyNode(node) {
  25567. return (!node.children || node.children.length === 0) && !hasComments(node);
  25568. }
  25569. function hasComments(node) {
  25570. return hasLeadingComments(node) || hasMiddleComments(node) || hasIndicatorComment(node) || hasTrailingComment$2(node) || hasEndComments(node);
  25571. }
  25572. function hasLeadingComments(node) {
  25573. return node && node.leadingComments && node.leadingComments.length !== 0;
  25574. }
  25575. function hasMiddleComments(node) {
  25576. return node && node.middleComments && node.middleComments.length !== 0;
  25577. }
  25578. function hasIndicatorComment(node) {
  25579. return node && node.indicatorComment;
  25580. }
  25581. function hasTrailingComment$2(node) {
  25582. return node && node.trailingComment;
  25583. }
  25584. function hasEndComments(node) {
  25585. return node && node.endComments && node.endComments.length !== 0;
  25586. }
  25587. /**
  25588. * " a b c d e f " -> [" a b", "c d", "e f "]
  25589. */
  25590. function splitWithSingleSpace(text) {
  25591. var parts = [];
  25592. var lastPart = undefined;
  25593. var _iteratorNormalCompletion = true;
  25594. var _didIteratorError = false;
  25595. var _iteratorError = undefined;
  25596. try {
  25597. for (var _iterator = text.split(/( +)/g)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  25598. var part = _step.value;
  25599. if (part !== " ") {
  25600. if (lastPart === " ") {
  25601. parts.push(part);
  25602. } else {
  25603. parts.push((parts.pop() || "") + part);
  25604. }
  25605. } else if (lastPart === undefined) {
  25606. parts.unshift("");
  25607. }
  25608. lastPart = part;
  25609. }
  25610. } catch (err) {
  25611. _didIteratorError = true;
  25612. _iteratorError = err;
  25613. } finally {
  25614. try {
  25615. if (!_iteratorNormalCompletion && _iterator.return != null) {
  25616. _iterator.return();
  25617. }
  25618. } finally {
  25619. if (_didIteratorError) {
  25620. throw _iteratorError;
  25621. }
  25622. }
  25623. }
  25624. if (lastPart === " ") {
  25625. parts.push((parts.pop() || "") + " ");
  25626. }
  25627. if (parts[0] === "") {
  25628. parts.shift();
  25629. parts.unshift(" " + (parts.shift() || ""));
  25630. }
  25631. return parts;
  25632. }
  25633. function getFlowScalarLineContents(nodeType, content, options) {
  25634. var rawLineContents = content.split("\n").map(function (lineContent, index, lineContents) {
  25635. return index === 0 && index === lineContents.length - 1 ? lineContent : index !== 0 && index !== lineContents.length - 1 ? lineContent.trim() : index === 0 ? lineContent.trimRight() : lineContent.trimLeft();
  25636. });
  25637. if (options.proseWrap === "preserve") {
  25638. return rawLineContents.map(function (lineContent) {
  25639. return lineContent.length === 0 ? [] : [lineContent];
  25640. });
  25641. }
  25642. return rawLineContents.map(function (lineContent) {
  25643. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  25644. }).reduce(function (reduced, lineContentWords, index) {
  25645. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !( // trailing backslash in quoteDouble should be preserved
  25646. nodeType === "quoteDouble" && getLast$4(getLast$4(reduced)).endsWith("\\")) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  25647. }, []).map(function (lineContentWords) {
  25648. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  25649. });
  25650. }
  25651. function getBlockValueLineContents(node, _ref) {
  25652. var parentIndent = _ref.parentIndent,
  25653. isLastDescendant = _ref.isLastDescendant,
  25654. options = _ref.options;
  25655. var content = node.position.start.line === node.position.end.line ? "" : options.originalText.slice(node.position.start.offset, node.position.end.offset) // exclude open line `>` or `|`
  25656. .match(/^[^\n]*?\n([\s\S]*)$/)[1];
  25657. var leadingSpaceCount = node.indent === null ? function (match) {
  25658. return match ? match[1].length : Infinity;
  25659. }(content.match(/^( *)\S/m)) : node.indent - 1 + parentIndent;
  25660. var rawLineContents = content.split("\n").map(function (lineContent) {
  25661. return lineContent.slice(leadingSpaceCount);
  25662. });
  25663. if (options.proseWrap === "preserve" || node.type === "blockLiteral") {
  25664. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  25665. return lineContent.length === 0 ? [] : [lineContent];
  25666. }));
  25667. }
  25668. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  25669. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  25670. }).reduce(function (reduced, lineContentWords, index) {
  25671. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !/^\s/.test(lineContentWords[0]) && !/^\s|\s$/.test(getLast$4(reduced)) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  25672. }, []).map(function (lineContentWords) {
  25673. return lineContentWords.reduce(function (reduced, word) {
  25674. return (// disallow trailing spaces
  25675. reduced.length !== 0 && /\s$/.test(getLast$4(reduced)) ? reduced.concat(reduced.pop() + " " + word) : reduced.concat(word)
  25676. );
  25677. }, []);
  25678. }).map(function (lineContentWords) {
  25679. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  25680. }));
  25681. function removeUnnecessaryTrailingNewlines(lineContents) {
  25682. if (node.chomping === "keep") {
  25683. return getLast$4(lineContents).length === 0 ? lineContents.slice(0, -1) : lineContents;
  25684. }
  25685. var trailingNewlineCount = 0;
  25686. for (var i = lineContents.length - 1; i >= 0; i--) {
  25687. if (lineContents[i].length === 0) {
  25688. trailingNewlineCount++;
  25689. } else {
  25690. break;
  25691. }
  25692. }
  25693. return trailingNewlineCount === 0 ? lineContents : trailingNewlineCount >= 2 && !isLastDescendant ? // next empty line
  25694. lineContents.slice(0, -(trailingNewlineCount - 1)) : lineContents.slice(0, -trailingNewlineCount);
  25695. }
  25696. }
  25697. var utils$6 = {
  25698. getLast: getLast$4,
  25699. getAncestorCount: getAncestorCount,
  25700. isNode: isNode,
  25701. isEmptyNode: isEmptyNode,
  25702. mapNode: mapNode,
  25703. defineShortcut: defineShortcut,
  25704. isNextLineEmpty: isNextLineEmpty$5,
  25705. isLastDescendantNode: isLastDescendantNode,
  25706. getBlockValueLineContents: getBlockValueLineContents,
  25707. getFlowScalarLineContents: getFlowScalarLineContents,
  25708. getLastDescendantNode: getLastDescendantNode$1,
  25709. hasPrettierIgnore: hasPrettierIgnore$5,
  25710. hasLeadingComments: hasLeadingComments,
  25711. hasMiddleComments: hasMiddleComments,
  25712. hasIndicatorComment: hasIndicatorComment,
  25713. hasTrailingComment: hasTrailingComment$2,
  25714. hasEndComments: hasEndComments
  25715. };
  25716. var insertPragma$9 = pragma$5.insertPragma,
  25717. isPragma$1 = pragma$5.isPragma;
  25718. var getAncestorCount$1 = utils$6.getAncestorCount,
  25719. getBlockValueLineContents$1 = utils$6.getBlockValueLineContents,
  25720. getFlowScalarLineContents$1 = utils$6.getFlowScalarLineContents,
  25721. getLast$5 = utils$6.getLast,
  25722. getLastDescendantNode$2 = utils$6.getLastDescendantNode,
  25723. hasLeadingComments$1 = utils$6.hasLeadingComments,
  25724. hasMiddleComments$1 = utils$6.hasMiddleComments,
  25725. hasIndicatorComment$1 = utils$6.hasIndicatorComment,
  25726. hasTrailingComment$3 = utils$6.hasTrailingComment,
  25727. hasEndComments$1 = utils$6.hasEndComments,
  25728. hasPrettierIgnore$6 = utils$6.hasPrettierIgnore,
  25729. isLastDescendantNode$1 = utils$6.isLastDescendantNode,
  25730. isNextLineEmpty$6 = utils$6.isNextLineEmpty,
  25731. isNode$1 = utils$6.isNode,
  25732. isEmptyNode$1 = utils$6.isEmptyNode,
  25733. defineShortcut$1 = utils$6.defineShortcut,
  25734. mapNode$1 = utils$6.mapNode;
  25735. var docBuilders$2 = doc.builders;
  25736. var conditionalGroup$2 = docBuilders$2.conditionalGroup,
  25737. breakParent$5 = docBuilders$2.breakParent,
  25738. concat$h = docBuilders$2.concat,
  25739. dedent$3 = docBuilders$2.dedent,
  25740. dedentToRoot$3 = docBuilders$2.dedentToRoot,
  25741. fill$6 = docBuilders$2.fill,
  25742. group$g = docBuilders$2.group,
  25743. hardline$d = docBuilders$2.hardline,
  25744. ifBreak$8 = docBuilders$2.ifBreak,
  25745. join$c = docBuilders$2.join,
  25746. line$9 = docBuilders$2.line,
  25747. lineSuffix$2 = docBuilders$2.lineSuffix,
  25748. literalline$7 = docBuilders$2.literalline,
  25749. markAsRoot$5 = docBuilders$2.markAsRoot,
  25750. softline$8 = docBuilders$2.softline;
  25751. var replaceEndOfLineWith$3 = util.replaceEndOfLineWith;
  25752. function preprocess$3(ast) {
  25753. return mapNode$1(ast, defineShortcuts);
  25754. }
  25755. function defineShortcuts(node) {
  25756. switch (node.type) {
  25757. case "document":
  25758. defineShortcut$1(node, "head", function () {
  25759. return node.children[0];
  25760. });
  25761. defineShortcut$1(node, "body", function () {
  25762. return node.children[1];
  25763. });
  25764. break;
  25765. case "documentBody":
  25766. case "sequenceItem":
  25767. case "flowSequenceItem":
  25768. case "mappingKey":
  25769. case "mappingValue":
  25770. defineShortcut$1(node, "content", function () {
  25771. return node.children[0];
  25772. });
  25773. break;
  25774. case "mappingItem":
  25775. case "flowMappingItem":
  25776. defineShortcut$1(node, "key", function () {
  25777. return node.children[0];
  25778. });
  25779. defineShortcut$1(node, "value", function () {
  25780. return node.children[1];
  25781. });
  25782. break;
  25783. }
  25784. return node;
  25785. }
  25786. function genericPrint$6(path, options, print) {
  25787. var node = path.getValue();
  25788. var parentNode = path.getParentNode();
  25789. var tag = !node.tag ? "" : path.call(print, "tag");
  25790. var anchor = !node.anchor ? "" : path.call(print, "anchor");
  25791. var nextEmptyLine = isNode$1(node, ["mapping", "sequence", "comment", "directive", "mappingItem", "sequenceItem"]) && !isLastDescendantNode$1(path) ? printNextEmptyLine(path, options.originalText) : "";
  25792. return concat$h([node.type !== "mappingValue" && hasLeadingComments$1(node) ? concat$h([join$c(hardline$d, path.map(print, "leadingComments")), hardline$d]) : "", tag, tag && anchor ? " " : "", anchor, tag || anchor ? isNode$1(node, ["sequence", "mapping"]) && !hasMiddleComments$1(node) ? hardline$d : " " : "", hasMiddleComments$1(node) ? concat$h([node.middleComments.length === 1 ? "" : hardline$d, join$c(hardline$d, path.map(print, "middleComments")), hardline$d]) : "", hasPrettierIgnore$6(path) ? concat$h(replaceEndOfLineWith$3(options.originalText.slice(node.position.start.offset, node.position.end.offset), literalline$7)) : group$g(_print(node, parentNode, path, options, print)), hasTrailingComment$3(node) && !isNode$1(node, ["document", "documentHead"]) ? lineSuffix$2(concat$h([node.type === "mappingValue" && !node.content ? "" : " ", parentNode.type === "mappingKey" && path.getParentNode(2).type === "mapping" && isInlineNode$1(node) ? "" : breakParent$5, path.call(print, "trailingComment")])) : "", nextEmptyLine, hasEndComments$1(node) && !isNode$1(node, ["documentHead", "documentBody"]) ? align$3(node.type === "sequenceItem" ? 2 : 0, concat$h([hardline$d, join$c(hardline$d, path.map(print, "endComments"))])) : ""]);
  25793. }
  25794. function _print(node, parentNode, path, options, print) {
  25795. switch (node.type) {
  25796. case "root":
  25797. return concat$h([join$c(hardline$d, path.map(function (childPath, index) {
  25798. var document = node.children[index];
  25799. var nextDocument = node.children[index + 1];
  25800. return concat$h([print(childPath), shouldPrintDocumentEndMarker(document, nextDocument) ? concat$h([hardline$d, "...", hasTrailingComment$3(document) ? concat$h([" ", path.call(print, "trailingComment")]) : ""]) : !nextDocument || hasTrailingComment$3(nextDocument.head) ? "" : concat$h([hardline$d, "---"])]);
  25801. }, "children")), node.children.length === 0 || function (lastDescendantNode) {
  25802. return isNode$1(lastDescendantNode, ["blockLiteral", "blockFolded"]) && lastDescendantNode.chomping === "keep";
  25803. }(getLastDescendantNode$2(node)) ? "" : hardline$d]);
  25804. case "document":
  25805. {
  25806. var nextDocument = parentNode.children[path.getName() + 1];
  25807. return join$c(hardline$d, [shouldPrintDocumentHeadEndMarker(node, nextDocument, parentNode, options) === "head" ? join$c(hardline$d, [node.head.children.length === 0 && node.head.endComments.length === 0 ? "" : path.call(print, "head"), concat$h(["---", hasTrailingComment$3(node.head) ? concat$h([" ", path.call(print, "head", "trailingComment")]) : ""])].filter(Boolean)) : "", shouldPrintDocumentBody(node) ? path.call(print, "body") : ""].filter(Boolean));
  25808. }
  25809. case "documentHead":
  25810. return join$c(hardline$d, [].concat(path.map(print, "children"), path.map(print, "endComments")));
  25811. case "documentBody":
  25812. {
  25813. var children = join$c(hardline$d, path.map(print, "children")).parts;
  25814. var endComments = join$c(hardline$d, path.map(print, "endComments")).parts;
  25815. var separator = children.length === 0 || endComments.length === 0 ? "" : function (lastDescendantNode) {
  25816. return isNode$1(lastDescendantNode, ["blockFolded", "blockLiteral"]) ? lastDescendantNode.chomping === "keep" ? // there's already a newline printed at the end of blockValue (chomping=keep, lastDescendant=true)
  25817. "" : // an extra newline for better readability
  25818. concat$h([hardline$d, hardline$d]) : hardline$d;
  25819. }(getLastDescendantNode$2(node));
  25820. return concat$h([].concat(children, separator, endComments));
  25821. }
  25822. case "directive":
  25823. return concat$h(["%", join$c(" ", [node.name].concat(node.parameters))]);
  25824. case "comment":
  25825. return concat$h(["#", node.value]);
  25826. case "alias":
  25827. return concat$h(["*", node.value]);
  25828. case "tag":
  25829. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  25830. case "anchor":
  25831. return concat$h(["&", node.value]);
  25832. case "plain":
  25833. return printFlowScalarContent(node.type, options.originalText.slice(node.position.start.offset, node.position.end.offset), options);
  25834. case "quoteDouble":
  25835. case "quoteSingle":
  25836. {
  25837. var singleQuote = "'";
  25838. var doubleQuote = '"';
  25839. var raw = options.originalText.slice(node.position.start.offset + 1, node.position.end.offset - 1);
  25840. if (node.type === "quoteSingle" && raw.includes("\\") || node.type === "quoteDouble" && /\\[^"]/.test(raw)) {
  25841. // only quoteDouble can use escape chars
  25842. // and quoteSingle do not need to escape backslashes
  25843. var originalQuote = node.type === "quoteDouble" ? doubleQuote : singleQuote;
  25844. return concat$h([originalQuote, printFlowScalarContent(node.type, raw, options), originalQuote]);
  25845. } else if (raw.includes(doubleQuote)) {
  25846. return concat$h([singleQuote, printFlowScalarContent(node.type, node.type === "quoteDouble" ? raw // double quote needs to be escaped by backslash in quoteDouble
  25847. .replace(/\\"/g, doubleQuote).replace(/'/g, singleQuote.repeat(2)) : raw, options), singleQuote]);
  25848. }
  25849. if (raw.includes(singleQuote)) {
  25850. return concat$h([doubleQuote, printFlowScalarContent(node.type, node.type === "quoteSingle" ? // single quote needs to be escaped by 2 single quotes in quoteSingle
  25851. raw.replace(/''/g, singleQuote) : raw, options), doubleQuote]);
  25852. }
  25853. var quote = options.singleQuote ? singleQuote : doubleQuote;
  25854. return concat$h([quote, printFlowScalarContent(node.type, raw, options), quote]);
  25855. }
  25856. case "blockFolded":
  25857. case "blockLiteral":
  25858. {
  25859. var parentIndent = getAncestorCount$1(path, function (ancestorNode) {
  25860. return isNode$1(ancestorNode, ["sequence", "mapping"]);
  25861. });
  25862. var isLastDescendant = isLastDescendantNode$1(path);
  25863. return concat$h([node.type === "blockFolded" ? ">" : "|", node.indent === null ? "" : node.indent.toString(), node.chomping === "clip" ? "" : node.chomping === "keep" ? "+" : "-", hasIndicatorComment$1(node) ? concat$h([" ", path.call(print, "indicatorComment")]) : "", (node.indent === null ? dedent$3 : dedentToRoot$3)(align$3(node.indent === null ? options.tabWidth : node.indent - 1 + parentIndent, concat$h(getBlockValueLineContents$1(node, {
  25864. parentIndent: parentIndent,
  25865. isLastDescendant: isLastDescendant,
  25866. options: options
  25867. }).reduce(function (reduced, lineWords, index, lineContents) {
  25868. return reduced.concat(index === 0 ? hardline$d : "", fill$6(join$c(line$9, lineWords).parts), index !== lineContents.length - 1 ? lineWords.length === 0 ? hardline$d : markAsRoot$5(literalline$7) : node.chomping === "keep" && isLastDescendant ? lineWords.length === 0 ? dedentToRoot$3(hardline$d) : dedentToRoot$3(literalline$7) : "");
  25869. }, []))))]);
  25870. }
  25871. case "sequence":
  25872. return join$c(hardline$d, path.map(print, "children"));
  25873. case "sequenceItem":
  25874. return concat$h(["- ", align$3(2, !node.content ? "" : path.call(print, "content"))]);
  25875. case "mappingKey":
  25876. return !node.content ? "" : path.call(print, "content");
  25877. case "mappingValue":
  25878. return !node.content ? "" : path.call(print, "content");
  25879. case "mapping":
  25880. return join$c(hardline$d, path.map(print, "children"));
  25881. case "mappingItem":
  25882. case "flowMappingItem":
  25883. {
  25884. var isEmptyMappingKey = isEmptyNode$1(node.key);
  25885. var isEmptyMappingValue = isEmptyNode$1(node.value);
  25886. if (isEmptyMappingKey && isEmptyMappingValue) {
  25887. return concat$h([": "]);
  25888. }
  25889. var key = path.call(print, "key");
  25890. var value = path.call(print, "value");
  25891. if (isEmptyMappingValue) {
  25892. return node.type === "flowMappingItem" && parentNode.type === "flowMapping" ? key : node.type === "mappingItem" && isAbsolutelyPrintedAsSingleLineNode(node.key.content, options) && !hasTrailingComment$3(node.key.content) && (!parentNode.tag || parentNode.tag.value !== "tag:yaml.org,2002:set") ? concat$h([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ":"]) : concat$h(["? ", align$3(2, key)]);
  25893. }
  25894. if (isEmptyMappingKey) {
  25895. return concat$h([": ", align$3(2, value)]);
  25896. }
  25897. var groupId = Symbol("mappingKey");
  25898. var forceExplicitKey = hasLeadingComments$1(node.value) || !isInlineNode$1(node.key.content);
  25899. return forceExplicitKey ? concat$h(["? ", align$3(2, key), hardline$d, join$c("", path.map(print, "value", "leadingComments").map(function (comment) {
  25900. return concat$h([comment, hardline$d]);
  25901. })), ": ", align$3(2, value)]) : // force singleline
  25902. isSingleLineNode(node.key.content) && !hasLeadingComments$1(node.key.content) && !hasMiddleComments$1(node.key.content) && !hasTrailingComment$3(node.key.content) && !hasEndComments$1(node.key) && !hasLeadingComments$1(node.value.content) && !hasMiddleComments$1(node.value.content) && !hasEndComments$1(node.value) && isAbsolutelyPrintedAsSingleLineNode(node.value.content, options) ? concat$h([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ": ", value]) : conditionalGroup$2([concat$h([group$g(concat$h([ifBreak$8("? "), group$g(align$3(2, key), {
  25903. id: groupId
  25904. })])), ifBreak$8(concat$h([hardline$d, ": ", align$3(2, value)]), indent(concat$h([needsSpaceInFrontOfMappingValue(node) ? " " : "", ":", hasLeadingComments$1(node.value.content) || hasEndComments$1(node.value) && node.value.content && !isNode$1(node.value.content, ["mapping", "sequence"]) || parentNode.type === "mapping" && hasTrailingComment$3(node.key.content) && isInlineNode$1(node.value.content) || isNode$1(node.value.content, ["mapping", "sequence"]) && node.value.content.tag === null && node.value.content.anchor === null ? hardline$d : !node.value.content ? "" : line$9, value])), {
  25905. groupId: groupId
  25906. })])]);
  25907. }
  25908. case "flowMapping":
  25909. case "flowSequence":
  25910. {
  25911. var openMarker = node.type === "flowMapping" ? "{" : "[";
  25912. var closeMarker = node.type === "flowMapping" ? "}" : "]";
  25913. var bracketSpacing = node.type === "flowMapping" && node.children.length !== 0 && options.bracketSpacing ? line$9 : softline$8;
  25914. var isLastItemEmptyMappingItem = node.children.length !== 0 && function (lastItem) {
  25915. return lastItem.type === "flowMappingItem" && isEmptyNode$1(lastItem.key) && isEmptyNode$1(lastItem.value);
  25916. }(getLast$5(node.children));
  25917. return concat$h([openMarker, indent(concat$h([bracketSpacing, concat$h(path.map(function (childPath, index) {
  25918. return concat$h([print(childPath), index === node.children.length - 1 ? "" : concat$h([",", line$9, node.children[index].position.start.line !== node.children[index + 1].position.start.line ? printNextEmptyLine(childPath, options.originalText) : ""])]);
  25919. }, "children")), ifBreak$8(",", "")])), isLastItemEmptyMappingItem ? "" : bracketSpacing, closeMarker]);
  25920. }
  25921. case "flowSequenceItem":
  25922. return path.call(print, "content");
  25923. // istanbul ignore next
  25924. default:
  25925. throw new Error("Unexpected node type ".concat(node.type));
  25926. }
  25927. function indent(doc) {
  25928. return docBuilders$2.align(" ".repeat(options.tabWidth), doc);
  25929. }
  25930. }
  25931. function align$3(n, doc) {
  25932. return typeof n === "number" && n > 0 ? docBuilders$2.align(" ".repeat(n), doc) : docBuilders$2.align(n, doc);
  25933. }
  25934. function isInlineNode$1(node) {
  25935. if (!node) {
  25936. return true;
  25937. }
  25938. switch (node.type) {
  25939. case "plain":
  25940. case "quoteDouble":
  25941. case "quoteSingle":
  25942. case "alias":
  25943. case "flowMapping":
  25944. case "flowSequence":
  25945. return true;
  25946. default:
  25947. return false;
  25948. }
  25949. }
  25950. function isSingleLineNode(node) {
  25951. if (!node) {
  25952. return true;
  25953. }
  25954. switch (node.type) {
  25955. case "plain":
  25956. case "quoteDouble":
  25957. case "quoteSingle":
  25958. return node.position.start.line === node.position.end.line;
  25959. case "alias":
  25960. return true;
  25961. default:
  25962. return false;
  25963. }
  25964. }
  25965. function shouldPrintDocumentBody(document) {
  25966. return document.body.children.length !== 0 || hasEndComments$1(document.body);
  25967. }
  25968. function shouldPrintDocumentEndMarker(document, nextDocument) {
  25969. return (
  25970. /**
  25971. *... # trailingComment
  25972. */
  25973. hasTrailingComment$3(document) || nextDocument && (
  25974. /**
  25975. * ...
  25976. * %DIRECTIVE
  25977. * ---
  25978. */
  25979. nextDocument.head.children.length !== 0 ||
  25980. /**
  25981. * ...
  25982. * # endComment
  25983. * ---
  25984. */
  25985. hasEndComments$1(nextDocument.head))
  25986. );
  25987. }
  25988. function shouldPrintDocumentHeadEndMarker(document, nextDocument, root, options) {
  25989. if (
  25990. /**
  25991. * ---
  25992. * preserve the first document head end marker
  25993. */
  25994. root.children[0] === document && /---(\s|$)/.test(options.originalText.slice(options.locStart(document), options.locStart(document) + 4)) ||
  25995. /**
  25996. * %DIRECTIVE
  25997. * ---
  25998. */
  25999. document.head.children.length !== 0 ||
  26000. /**
  26001. * # end comment
  26002. * ---
  26003. */
  26004. hasEndComments$1(document.head) ||
  26005. /**
  26006. * --- # trailing comment
  26007. */
  26008. hasTrailingComment$3(document.head)) {
  26009. return "head";
  26010. }
  26011. if (shouldPrintDocumentEndMarker(document, nextDocument)) {
  26012. return false;
  26013. }
  26014. return nextDocument ? "root" : false;
  26015. }
  26016. function isAbsolutelyPrintedAsSingleLineNode(node, options) {
  26017. if (!node) {
  26018. return true;
  26019. }
  26020. switch (node.type) {
  26021. case "plain":
  26022. case "quoteSingle":
  26023. case "quoteDouble":
  26024. break;
  26025. case "alias":
  26026. return true;
  26027. default:
  26028. return false;
  26029. }
  26030. if (options.proseWrap === "preserve") {
  26031. return node.position.start.line === node.position.end.line;
  26032. }
  26033. if ( // backslash-newline
  26034. /\\$/m.test(options.originalText.slice(node.position.start.offset, node.position.end.offset))) {
  26035. return false;
  26036. }
  26037. switch (options.proseWrap) {
  26038. case "never":
  26039. return node.value.indexOf("\n") === -1;
  26040. case "always":
  26041. return !/[\n ]/.test(node.value);
  26042. // istanbul ignore next
  26043. default:
  26044. return false;
  26045. }
  26046. }
  26047. function needsSpaceInFrontOfMappingValue(node) {
  26048. return node.key.content && node.key.content.type === "alias";
  26049. }
  26050. function printNextEmptyLine(path, originalText) {
  26051. var node = path.getValue();
  26052. var root = path.stack[0];
  26053. root.isNextEmptyLinePrintedChecklist = root.isNextEmptyLinePrintedChecklist || [];
  26054. if (!root.isNextEmptyLinePrintedChecklist[node.position.end.line]) {
  26055. if (isNextLineEmpty$6(node, originalText)) {
  26056. root.isNextEmptyLinePrintedChecklist[node.position.end.line] = true;
  26057. return softline$8;
  26058. }
  26059. }
  26060. return "";
  26061. }
  26062. function printFlowScalarContent(nodeType, content, options) {
  26063. var lineContents = getFlowScalarLineContents$1(nodeType, content, options);
  26064. return join$c(hardline$d, lineContents.map(function (lineContentWords) {
  26065. return fill$6(join$c(line$9, lineContentWords).parts);
  26066. }));
  26067. }
  26068. function clean$7(node, newNode
  26069. /*, parent */
  26070. ) {
  26071. if (isNode$1(newNode)) {
  26072. delete newNode.position;
  26073. switch (newNode.type) {
  26074. case "comment":
  26075. // insert pragma
  26076. if (isPragma$1(newNode.value)) {
  26077. return null;
  26078. }
  26079. break;
  26080. case "quoteDouble":
  26081. case "quoteSingle":
  26082. newNode.type = "quote";
  26083. break;
  26084. }
  26085. }
  26086. }
  26087. var printerYaml = {
  26088. preprocess: preprocess$3,
  26089. print: genericPrint$6,
  26090. massageAstNode: clean$7,
  26091. insertPragma: insertPragma$9
  26092. };
  26093. var options$7 = {
  26094. bracketSpacing: commonOptions.bracketSpacing,
  26095. singleQuote: commonOptions.singleQuote,
  26096. proseWrap: commonOptions.proseWrap
  26097. };
  26098. var name$h = "YAML";
  26099. var type$g = "data";
  26100. var tmScope$g = "source.yaml";
  26101. var aliases$6 = [
  26102. "yml"
  26103. ];
  26104. var extensions$g = [
  26105. ".yml",
  26106. ".mir",
  26107. ".reek",
  26108. ".rviz",
  26109. ".sublime-syntax",
  26110. ".syntax",
  26111. ".yaml",
  26112. ".yaml-tmlanguage",
  26113. ".yml.mysql"
  26114. ];
  26115. var filenames$4 = [
  26116. ".clang-format",
  26117. ".clang-tidy",
  26118. ".gemrc",
  26119. "glide.lock"
  26120. ];
  26121. var aceMode$g = "yaml";
  26122. var codemirrorMode$c = "yaml";
  26123. var codemirrorMimeType$c = "text/x-yaml";
  26124. var languageId$g = 407;
  26125. var YAML = {
  26126. name: name$h,
  26127. type: type$g,
  26128. tmScope: tmScope$g,
  26129. aliases: aliases$6,
  26130. extensions: extensions$g,
  26131. filenames: filenames$4,
  26132. aceMode: aceMode$g,
  26133. codemirrorMode: codemirrorMode$c,
  26134. codemirrorMimeType: codemirrorMimeType$c,
  26135. languageId: languageId$g
  26136. };
  26137. var YAML$1 = /*#__PURE__*/Object.freeze({
  26138. __proto__: null,
  26139. name: name$h,
  26140. type: type$g,
  26141. tmScope: tmScope$g,
  26142. aliases: aliases$6,
  26143. extensions: extensions$g,
  26144. filenames: filenames$4,
  26145. aceMode: aceMode$g,
  26146. codemirrorMode: codemirrorMode$c,
  26147. codemirrorMimeType: codemirrorMimeType$c,
  26148. languageId: languageId$g,
  26149. 'default': YAML
  26150. });
  26151. var require$$0$8 = getCjsExportFromNamespace(YAML$1);
  26152. var languages$6 = [createLanguage(require$$0$8, function (data) {
  26153. return Object.assign(data, {
  26154. since: "1.14.0",
  26155. parsers: ["yaml"],
  26156. vscodeLanguageIds: ["yaml"]
  26157. });
  26158. })];
  26159. var languageYaml = {
  26160. languages: languages$6,
  26161. printers: {
  26162. yaml: printerYaml
  26163. },
  26164. options: options$7
  26165. };
  26166. var version$2 = require$$0.version;
  26167. var getSupportInfo$2 = support.getSupportInfo;
  26168. var internalPlugins = [languageCss, languageGraphql, languageHandlebars, languageHtml, languageJs, languageMarkdown, languageYaml];
  26169. var isArray$1 = Array.isArray || function (arr) {
  26170. return Object.prototype.toString.call(arr) === "[object Array]";
  26171. }; // Luckily `opts` is always the 2nd argument
  26172. function withPlugins(fn) {
  26173. return function () {
  26174. var args = Array.from(arguments);
  26175. var plugins = args[1] && args[1].plugins || [];
  26176. if (!isArray$1(plugins)) {
  26177. plugins = Object.values(plugins);
  26178. }
  26179. args[1] = Object.assign({}, args[1], {
  26180. plugins: internalPlugins.concat(plugins)
  26181. });
  26182. return fn.apply(null, args);
  26183. };
  26184. }
  26185. var formatWithCursor = withPlugins(core.formatWithCursor);
  26186. var standalone = {
  26187. formatWithCursor: formatWithCursor,
  26188. format: function format(text, opts) {
  26189. return formatWithCursor(text, opts).formatted;
  26190. },
  26191. check: function check(text, opts) {
  26192. var formatted = formatWithCursor(text, opts).formatted;
  26193. return formatted === text;
  26194. },
  26195. doc: doc,
  26196. getSupportInfo: withPlugins(getSupportInfo$2),
  26197. version: version$2,
  26198. util: utilShared,
  26199. __debug: {
  26200. parse: withPlugins(core.parse),
  26201. formatAST: withPlugins(core.formatAST),
  26202. formatDoc: withPlugins(core.formatDoc),
  26203. printToDoc: withPlugins(core.printToDoc),
  26204. printDocToString: withPlugins(core.printDocToString)
  26205. }
  26206. };
  26207. var standalone$1 = standalone;
  26208. return standalone$1;
  26209. })));