doc.js 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.doc = factory());
  5. }(this, (function () { 'use strict';
  6. /**
  7. * @param {Doc[]} parts
  8. * @returns Doc
  9. */
  10. function concat(parts) {
  11. // access the internals of a document directly.
  12. // if(parts.length === 1) {
  13. // // If it's a single document, no need to concat it.
  14. // return parts[0];
  15. // }
  16. return {
  17. type: "concat",
  18. parts
  19. };
  20. }
  21. /**
  22. * @param {Doc} contents
  23. * @returns Doc
  24. */
  25. function indent(contents) {
  26. return {
  27. type: "indent",
  28. contents
  29. };
  30. }
  31. /**
  32. * @param {number | string} n
  33. * @param {Doc} contents
  34. * @returns Doc
  35. */
  36. function align(n, contents) {
  37. return {
  38. type: "align",
  39. contents,
  40. n
  41. };
  42. }
  43. /**
  44. * @param {Doc} contents
  45. * @param {object} [opts] - TBD ???
  46. * @returns Doc
  47. */
  48. function group(contents, opts) {
  49. opts = opts || {};
  50. return {
  51. type: "group",
  52. id: opts.id,
  53. contents,
  54. break: !!opts.shouldBreak,
  55. expandedStates: opts.expandedStates
  56. };
  57. }
  58. /**
  59. * @param {Doc} contents
  60. * @returns Doc
  61. */
  62. function dedentToRoot(contents) {
  63. return align(-Infinity, contents);
  64. }
  65. /**
  66. * @param {Doc} contents
  67. * @returns Doc
  68. */
  69. function markAsRoot(contents) {
  70. // @ts-ignore - TBD ???:
  71. return align({
  72. type: "root"
  73. }, contents);
  74. }
  75. /**
  76. * @param {Doc} contents
  77. * @returns Doc
  78. */
  79. function dedent(contents) {
  80. return align(-1, contents);
  81. }
  82. /**
  83. * @param {Doc[]} states
  84. * @param {object} [opts] - TBD ???
  85. * @returns Doc
  86. */
  87. function conditionalGroup(states, opts) {
  88. return group(states[0], Object.assign({}, opts, {
  89. expandedStates: states
  90. }));
  91. }
  92. /**
  93. * @param {Doc[]} parts
  94. * @returns Doc
  95. */
  96. function fill(parts) {
  97. return {
  98. type: "fill",
  99. parts
  100. };
  101. }
  102. /**
  103. * @param {Doc} [breakContents]
  104. * @param {Doc} [flatContents]
  105. * @param {object} [opts] - TBD ???
  106. * @returns Doc
  107. */
  108. function ifBreak(breakContents, flatContents, opts) {
  109. opts = opts || {};
  110. return {
  111. type: "if-break",
  112. breakContents,
  113. flatContents,
  114. groupId: opts.groupId
  115. };
  116. }
  117. /**
  118. * @param {Doc} contents
  119. * @returns Doc
  120. */
  121. function lineSuffix(contents) {
  122. return {
  123. type: "line-suffix",
  124. contents
  125. };
  126. }
  127. const lineSuffixBoundary = {
  128. type: "line-suffix-boundary"
  129. };
  130. const breakParent = {
  131. type: "break-parent"
  132. };
  133. const trim = {
  134. type: "trim"
  135. };
  136. const line = {
  137. type: "line"
  138. };
  139. const softline = {
  140. type: "line",
  141. soft: true
  142. };
  143. const hardline = concat([{
  144. type: "line",
  145. hard: true
  146. }, breakParent]);
  147. const literalline = concat([{
  148. type: "line",
  149. hard: true,
  150. literal: true
  151. }, breakParent]);
  152. const cursor = {
  153. type: "cursor",
  154. placeholder: Symbol("cursor")
  155. };
  156. /**
  157. * @param {Doc} sep
  158. * @param {Doc[]} arr
  159. * @returns Doc
  160. */
  161. function join(sep, arr) {
  162. const res = [];
  163. for (let i = 0; i < arr.length; i++) {
  164. if (i !== 0) {
  165. res.push(sep);
  166. }
  167. res.push(arr[i]);
  168. }
  169. return concat(res);
  170. }
  171. /**
  172. * @param {Doc} doc
  173. * @param {number} size
  174. * @param {number} tabWidth
  175. */
  176. function addAlignmentToDoc(doc, size, tabWidth) {
  177. let aligned = doc;
  178. if (size > 0) {
  179. // Use indent to add tabs for all the levels of tabs we need
  180. for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
  181. aligned = indent(aligned);
  182. } // Use align for all the spaces that are needed
  183. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  184. // indentation, so we use -Infinity to reset the indentation to 0
  185. aligned = align(-Infinity, aligned);
  186. }
  187. return aligned;
  188. }
  189. var docBuilders = {
  190. concat,
  191. join,
  192. line,
  193. softline,
  194. hardline,
  195. literalline,
  196. group,
  197. conditionalGroup,
  198. fill,
  199. lineSuffix,
  200. lineSuffixBoundary,
  201. cursor,
  202. breakParent,
  203. ifBreak,
  204. trim,
  205. indent,
  206. align,
  207. addAlignmentToDoc,
  208. markAsRoot,
  209. dedentToRoot,
  210. dedent
  211. };
  212. var ansiRegex = ({
  213. onlyFirst = false
  214. } = {}) => {
  215. const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  216. return new RegExp(pattern, onlyFirst ? undefined : 'g');
  217. };
  218. var stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
  219. /* eslint-disable yoda */
  220. const isFullwidthCodePoint = codePoint => {
  221. if (Number.isNaN(codePoint)) {
  222. return false;
  223. } // Code points are derived from:
  224. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  225. if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo
  226. codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  227. codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
  228. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  229. 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  230. 0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals
  231. 0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A
  232. 0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables
  233. 0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs
  234. 0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms
  235. 0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants
  236. 0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms
  237. 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement
  238. 0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement
  239. 0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  240. 0x20000 <= codePoint && codePoint <= 0x3FFFD)) {
  241. return true;
  242. }
  243. return false;
  244. };
  245. var isFullwidthCodePoint_1 = isFullwidthCodePoint;
  246. var _default = isFullwidthCodePoint;
  247. isFullwidthCodePoint_1.default = _default;
  248. var emojiRegex = function () {
  249. // https://mths.be/emoji
  250. 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;
  251. };
  252. const stringWidth = string => {
  253. string = string.replace(emojiRegex(), ' ');
  254. if (typeof string !== 'string' || string.length === 0) {
  255. return 0;
  256. }
  257. string = stripAnsi(string);
  258. let width = 0;
  259. for (let i = 0; i < string.length; i++) {
  260. const code = string.codePointAt(i); // Ignore control characters
  261. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  262. continue;
  263. } // Ignore combining characters
  264. if (code >= 0x300 && code <= 0x36F) {
  265. continue;
  266. } // Surrogates
  267. if (code > 0xFFFF) {
  268. i++;
  269. }
  270. width += isFullwidthCodePoint_1(code) ? 2 : 1;
  271. }
  272. return width;
  273. };
  274. var stringWidth_1 = stringWidth; // TODO: remove this in the next major version
  275. var _default$1 = stringWidth;
  276. stringWidth_1.default = _default$1;
  277. var escapeStringRegexp = string => {
  278. if (typeof string !== 'string') {
  279. throw new TypeError('Expected a string');
  280. } // Escape characters with special meaning either inside or outside character sets.
  281. // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
  282. return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
  283. };
  284. var getLast = arr => arr[arr.length - 1];
  285. function _objectWithoutPropertiesLoose(source, excluded) {
  286. if (source == null) return {};
  287. var target = {};
  288. var sourceKeys = Object.keys(source);
  289. var key, i;
  290. for (i = 0; i < sourceKeys.length; i++) {
  291. key = sourceKeys[i];
  292. if (excluded.indexOf(key) >= 0) continue;
  293. target[key] = source[key];
  294. }
  295. return target;
  296. }
  297. function _taggedTemplateLiteral(strings, raw) {
  298. if (!raw) {
  299. raw = strings.slice(0);
  300. }
  301. return Object.freeze(Object.defineProperties(strings, {
  302. raw: {
  303. value: Object.freeze(raw)
  304. }
  305. }));
  306. }
  307. var global$1 = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};
  308. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  309. function defaultSetTimout() {
  310. throw new Error('setTimeout has not been defined');
  311. }
  312. function defaultClearTimeout() {
  313. throw new Error('clearTimeout has not been defined');
  314. }
  315. var cachedSetTimeout = defaultSetTimout;
  316. var cachedClearTimeout = defaultClearTimeout;
  317. if (typeof global$1.setTimeout === 'function') {
  318. cachedSetTimeout = setTimeout;
  319. }
  320. if (typeof global$1.clearTimeout === 'function') {
  321. cachedClearTimeout = clearTimeout;
  322. }
  323. function runTimeout(fun) {
  324. if (cachedSetTimeout === setTimeout) {
  325. //normal enviroments in sane situations
  326. return setTimeout(fun, 0);
  327. } // if setTimeout wasn't available but was latter defined
  328. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  329. cachedSetTimeout = setTimeout;
  330. return setTimeout(fun, 0);
  331. }
  332. try {
  333. // when when somebody has screwed with setTimeout but no I.E. maddness
  334. return cachedSetTimeout(fun, 0);
  335. } catch (e) {
  336. try {
  337. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  338. return cachedSetTimeout.call(null, fun, 0);
  339. } catch (e) {
  340. // 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
  341. return cachedSetTimeout.call(this, fun, 0);
  342. }
  343. }
  344. }
  345. function runClearTimeout(marker) {
  346. if (cachedClearTimeout === clearTimeout) {
  347. //normal enviroments in sane situations
  348. return clearTimeout(marker);
  349. } // if clearTimeout wasn't available but was latter defined
  350. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  351. cachedClearTimeout = clearTimeout;
  352. return clearTimeout(marker);
  353. }
  354. try {
  355. // when when somebody has screwed with setTimeout but no I.E. maddness
  356. return cachedClearTimeout(marker);
  357. } catch (e) {
  358. try {
  359. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  360. return cachedClearTimeout.call(null, marker);
  361. } catch (e) {
  362. // 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.
  363. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  364. return cachedClearTimeout.call(this, marker);
  365. }
  366. }
  367. }
  368. var queue = [];
  369. var draining = false;
  370. var currentQueue;
  371. var queueIndex = -1;
  372. function cleanUpNextTick() {
  373. if (!draining || !currentQueue) {
  374. return;
  375. }
  376. draining = false;
  377. if (currentQueue.length) {
  378. queue = currentQueue.concat(queue);
  379. } else {
  380. queueIndex = -1;
  381. }
  382. if (queue.length) {
  383. drainQueue();
  384. }
  385. }
  386. function drainQueue() {
  387. if (draining) {
  388. return;
  389. }
  390. var timeout = runTimeout(cleanUpNextTick);
  391. draining = true;
  392. var len = queue.length;
  393. while (len) {
  394. currentQueue = queue;
  395. queue = [];
  396. while (++queueIndex < len) {
  397. if (currentQueue) {
  398. currentQueue[queueIndex].run();
  399. }
  400. }
  401. queueIndex = -1;
  402. len = queue.length;
  403. }
  404. currentQueue = null;
  405. draining = false;
  406. runClearTimeout(timeout);
  407. }
  408. function nextTick(fun) {
  409. var args = new Array(arguments.length - 1);
  410. if (arguments.length > 1) {
  411. for (var i = 1; i < arguments.length; i++) {
  412. args[i - 1] = arguments[i];
  413. }
  414. }
  415. queue.push(new Item(fun, args));
  416. if (queue.length === 1 && !draining) {
  417. runTimeout(drainQueue);
  418. }
  419. } // v8 likes predictible objects
  420. function Item(fun, array) {
  421. this.fun = fun;
  422. this.array = array;
  423. }
  424. Item.prototype.run = function () {
  425. this.fun.apply(null, this.array);
  426. };
  427. var title = 'browser';
  428. var platform = 'browser';
  429. var browser = true;
  430. var env = {};
  431. var argv = [];
  432. var version = ''; // empty string to avoid regexp issues
  433. var versions = {};
  434. var release = {};
  435. var config = {};
  436. function noop() {}
  437. var on = noop;
  438. var addListener = noop;
  439. var once = noop;
  440. var off = noop;
  441. var removeListener = noop;
  442. var removeAllListeners = noop;
  443. var emit = noop;
  444. function binding(name) {
  445. throw new Error('process.binding is not supported');
  446. }
  447. function cwd() {
  448. return '/';
  449. }
  450. function chdir(dir) {
  451. throw new Error('process.chdir is not supported');
  452. }
  453. function umask() {
  454. return 0;
  455. } // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  456. var performance = global$1.performance || {};
  457. var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function () {
  458. return new Date().getTime();
  459. }; // generate timestamp or delta
  460. // see http://nodejs.org/api/process.html#process_process_hrtime
  461. function hrtime(previousTimestamp) {
  462. var clocktime = performanceNow.call(performance) * 1e-3;
  463. var seconds = Math.floor(clocktime);
  464. var nanoseconds = Math.floor(clocktime % 1 * 1e9);
  465. if (previousTimestamp) {
  466. seconds = seconds - previousTimestamp[0];
  467. nanoseconds = nanoseconds - previousTimestamp[1];
  468. if (nanoseconds < 0) {
  469. seconds--;
  470. nanoseconds += 1e9;
  471. }
  472. }
  473. return [seconds, nanoseconds];
  474. }
  475. var startTime = new Date();
  476. function uptime() {
  477. var currentTime = new Date();
  478. var dif = currentTime - startTime;
  479. return dif / 1000;
  480. }
  481. var process = {
  482. nextTick: nextTick,
  483. title: title,
  484. browser: browser,
  485. env: env,
  486. argv: argv,
  487. version: version,
  488. versions: versions,
  489. on: on,
  490. addListener: addListener,
  491. once: once,
  492. off: off,
  493. removeListener: removeListener,
  494. removeAllListeners: removeAllListeners,
  495. emit: emit,
  496. binding: binding,
  497. cwd: cwd,
  498. chdir: chdir,
  499. umask: umask,
  500. hrtime: hrtime,
  501. platform: platform,
  502. release: release,
  503. config: config,
  504. uptime: uptime
  505. };
  506. const debug = typeof process === 'object' && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error('SEMVER', ...args) : () => {};
  507. var debug_1 = debug;
  508. // Note: this is the semver.org version of the spec that it implements
  509. // Not necessarily the package version of this code.
  510. const SEMVER_SPEC_VERSION = '2.0.0';
  511. const MAX_LENGTH = 256;
  512. const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
  513. /* istanbul ignore next */
  514. 9007199254740991; // Max safe segment length for coercion.
  515. const MAX_SAFE_COMPONENT_LENGTH = 16;
  516. var constants = {
  517. SEMVER_SPEC_VERSION,
  518. MAX_LENGTH,
  519. MAX_SAFE_INTEGER,
  520. MAX_SAFE_COMPONENT_LENGTH
  521. };
  522. function createCommonjsModule(fn, basedir, module) {
  523. return module = {
  524. path: basedir,
  525. exports: {},
  526. require: function (path, base) {
  527. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  528. }
  529. }, fn(module, module.exports), module.exports;
  530. }
  531. function commonjsRequire () {
  532. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  533. }
  534. var re_1 = createCommonjsModule(function (module, exports) {
  535. const {
  536. MAX_SAFE_COMPONENT_LENGTH
  537. } = constants;
  538. exports = module.exports = {}; // The actual regexps go on exports.re
  539. const re = exports.re = [];
  540. const src = exports.src = [];
  541. const t = exports.t = {};
  542. let R = 0;
  543. const createToken = (name, value, isGlobal) => {
  544. const index = R++;
  545. debug_1(index, value);
  546. t[name] = index;
  547. src[index] = value;
  548. re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
  549. }; // The following Regular Expressions can be used for tokenizing,
  550. // validating, and parsing SemVer version strings.
  551. // ## Numeric Identifier
  552. // A single `0`, or a non-zero digit followed by zero or more digits.
  553. createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
  554. createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+'); // ## Non-numeric Identifier
  555. // Zero or more digits, followed by a letter or hyphen, and then zero or
  556. // more letters, digits, or hyphens.
  557. createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*'); // ## Main Version
  558. // Three dot-separated numeric identifiers.
  559. createToken('MAINVERSION', "(".concat(src[t.NUMERICIDENTIFIER], ")\\.") + "(".concat(src[t.NUMERICIDENTIFIER], ")\\.") + "(".concat(src[t.NUMERICIDENTIFIER], ")"));
  560. createToken('MAINVERSIONLOOSE', "(".concat(src[t.NUMERICIDENTIFIERLOOSE], ")\\.") + "(".concat(src[t.NUMERICIDENTIFIERLOOSE], ")\\.") + "(".concat(src[t.NUMERICIDENTIFIERLOOSE], ")")); // ## Pre-release Version Identifier
  561. // A numeric identifier, or a non-numeric identifier.
  562. createToken('PRERELEASEIDENTIFIER', "(?:".concat(src[t.NUMERICIDENTIFIER], "|").concat(src[t.NONNUMERICIDENTIFIER], ")"));
  563. createToken('PRERELEASEIDENTIFIERLOOSE', "(?:".concat(src[t.NUMERICIDENTIFIERLOOSE], "|").concat(src[t.NONNUMERICIDENTIFIER], ")")); // ## Pre-release Version
  564. // Hyphen, followed by one or more dot-separated pre-release version
  565. // identifiers.
  566. createToken('PRERELEASE', "(?:-(".concat(src[t.PRERELEASEIDENTIFIER], "(?:\\.").concat(src[t.PRERELEASEIDENTIFIER], ")*))"));
  567. createToken('PRERELEASELOOSE', "(?:-?(".concat(src[t.PRERELEASEIDENTIFIERLOOSE], "(?:\\.").concat(src[t.PRERELEASEIDENTIFIERLOOSE], ")*))")); // ## Build Metadata Identifier
  568. // Any combination of digits, letters, or hyphens.
  569. createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+'); // ## Build Metadata
  570. // Plus sign, followed by one or more period-separated build metadata
  571. // identifiers.
  572. createToken('BUILD', "(?:\\+(".concat(src[t.BUILDIDENTIFIER], "(?:\\.").concat(src[t.BUILDIDENTIFIER], ")*))")); // ## Full Version String
  573. // A main version, followed optionally by a pre-release version and
  574. // build metadata.
  575. // Note that the only major, minor, patch, and pre-release sections of
  576. // the version string are capturing groups. The build metadata is not a
  577. // capturing group, because it should not ever be used in version
  578. // comparison.
  579. createToken('FULLPLAIN', "v?".concat(src[t.MAINVERSION]).concat(src[t.PRERELEASE], "?").concat(src[t.BUILD], "?"));
  580. createToken('FULL', "^".concat(src[t.FULLPLAIN], "$")); // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  581. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  582. // common in the npm registry.
  583. createToken('LOOSEPLAIN', "[v=\\s]*".concat(src[t.MAINVERSIONLOOSE]).concat(src[t.PRERELEASELOOSE], "?").concat(src[t.BUILD], "?"));
  584. createToken('LOOSE', "^".concat(src[t.LOOSEPLAIN], "$"));
  585. createToken('GTLT', '((?:<|>)?=?)'); // Something like "2.*" or "1.2.x".
  586. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  587. // Only the first item is strictly required.
  588. createToken('XRANGEIDENTIFIERLOOSE', "".concat(src[t.NUMERICIDENTIFIERLOOSE], "|x|X|\\*"));
  589. createToken('XRANGEIDENTIFIER', "".concat(src[t.NUMERICIDENTIFIER], "|x|X|\\*"));
  590. createToken('XRANGEPLAIN', "[v=\\s]*(".concat(src[t.XRANGEIDENTIFIER], ")") + "(?:\\.(".concat(src[t.XRANGEIDENTIFIER], ")") + "(?:\\.(".concat(src[t.XRANGEIDENTIFIER], ")") + "(?:".concat(src[t.PRERELEASE], ")?").concat(src[t.BUILD], "?") + ")?)?");
  591. createToken('XRANGEPLAINLOOSE', "[v=\\s]*(".concat(src[t.XRANGEIDENTIFIERLOOSE], ")") + "(?:\\.(".concat(src[t.XRANGEIDENTIFIERLOOSE], ")") + "(?:\\.(".concat(src[t.XRANGEIDENTIFIERLOOSE], ")") + "(?:".concat(src[t.PRERELEASELOOSE], ")?").concat(src[t.BUILD], "?") + ")?)?");
  592. createToken('XRANGE', "^".concat(src[t.GTLT], "\\s*").concat(src[t.XRANGEPLAIN], "$"));
  593. createToken('XRANGELOOSE', "^".concat(src[t.GTLT], "\\s*").concat(src[t.XRANGEPLAINLOOSE], "$")); // Coercion.
  594. // Extract anything that could conceivably be a part of a valid semver
  595. createToken('COERCE', "".concat('(^|[^\\d])' + '(\\d{1,').concat(MAX_SAFE_COMPONENT_LENGTH, "})") + "(?:\\.(\\d{1,".concat(MAX_SAFE_COMPONENT_LENGTH, "}))?") + "(?:\\.(\\d{1,".concat(MAX_SAFE_COMPONENT_LENGTH, "}))?") + "(?:$|[^\\d])");
  596. createToken('COERCERTL', src[t.COERCE], true); // Tilde ranges.
  597. // Meaning is "reasonably at or greater than"
  598. createToken('LONETILDE', '(?:~>?)');
  599. createToken('TILDETRIM', "(\\s*)".concat(src[t.LONETILDE], "\\s+"), true);
  600. exports.tildeTrimReplace = '$1~';
  601. createToken('TILDE', "^".concat(src[t.LONETILDE]).concat(src[t.XRANGEPLAIN], "$"));
  602. createToken('TILDELOOSE', "^".concat(src[t.LONETILDE]).concat(src[t.XRANGEPLAINLOOSE], "$")); // Caret ranges.
  603. // Meaning is "at least and backwards compatible with"
  604. createToken('LONECARET', '(?:\\^)');
  605. createToken('CARETTRIM', "(\\s*)".concat(src[t.LONECARET], "\\s+"), true);
  606. exports.caretTrimReplace = '$1^';
  607. createToken('CARET', "^".concat(src[t.LONECARET]).concat(src[t.XRANGEPLAIN], "$"));
  608. createToken('CARETLOOSE', "^".concat(src[t.LONECARET]).concat(src[t.XRANGEPLAINLOOSE], "$")); // A simple gt/lt/eq thing, or just "" to indicate "any version"
  609. createToken('COMPARATORLOOSE', "^".concat(src[t.GTLT], "\\s*(").concat(src[t.LOOSEPLAIN], ")$|^$"));
  610. createToken('COMPARATOR', "^".concat(src[t.GTLT], "\\s*(").concat(src[t.FULLPLAIN], ")$|^$")); // An expression to strip any whitespace between the gtlt and the thing
  611. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  612. createToken('COMPARATORTRIM', "(\\s*)".concat(src[t.GTLT], "\\s*(").concat(src[t.LOOSEPLAIN], "|").concat(src[t.XRANGEPLAIN], ")"), true);
  613. exports.comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  614. // Note that these all use the loose form, because they'll be
  615. // checked against either the strict or loose comparator form
  616. // later.
  617. createToken('HYPHENRANGE', "^\\s*(".concat(src[t.XRANGEPLAIN], ")") + "\\s+-\\s+" + "(".concat(src[t.XRANGEPLAIN], ")") + "\\s*$");
  618. createToken('HYPHENRANGELOOSE', "^\\s*(".concat(src[t.XRANGEPLAINLOOSE], ")") + "\\s+-\\s+" + "(".concat(src[t.XRANGEPLAINLOOSE], ")") + "\\s*$"); // Star ranges basically just allow anything at all.
  619. createToken('STAR', '(<|>)?=?\\s*\\*'); // >=0.0.0 is like a star
  620. createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$');
  621. createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$');
  622. });
  623. const numeric = /^[0-9]+$/;
  624. const compareIdentifiers = (a, b) => {
  625. const anum = numeric.test(a);
  626. const bnum = numeric.test(b);
  627. if (anum && bnum) {
  628. a = +a;
  629. b = +b;
  630. }
  631. return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
  632. };
  633. const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
  634. var identifiers = {
  635. compareIdentifiers,
  636. rcompareIdentifiers
  637. };
  638. const {
  639. MAX_LENGTH: MAX_LENGTH$1,
  640. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1
  641. } = constants;
  642. const {
  643. re,
  644. t
  645. } = re_1;
  646. const {
  647. compareIdentifiers: compareIdentifiers$1
  648. } = identifiers;
  649. class SemVer {
  650. constructor(version, options) {
  651. if (!options || typeof options !== 'object') {
  652. options = {
  653. loose: !!options,
  654. includePrerelease: false
  655. };
  656. }
  657. if (version instanceof SemVer) {
  658. if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
  659. return version;
  660. } else {
  661. version = version.version;
  662. }
  663. } else if (typeof version !== 'string') {
  664. throw new TypeError("Invalid Version: ".concat(version));
  665. }
  666. if (version.length > MAX_LENGTH$1) {
  667. throw new TypeError("version is longer than ".concat(MAX_LENGTH$1, " characters"));
  668. }
  669. debug_1('SemVer', version, options);
  670. this.options = options;
  671. this.loose = !!options.loose; // this isn't actually relevant for versions, but keep it so that we
  672. // don't run into trouble passing this.options around.
  673. this.includePrerelease = !!options.includePrerelease;
  674. const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
  675. if (!m) {
  676. throw new TypeError("Invalid Version: ".concat(version));
  677. }
  678. this.raw = version; // these are actually numbers
  679. this.major = +m[1];
  680. this.minor = +m[2];
  681. this.patch = +m[3];
  682. if (this.major > MAX_SAFE_INTEGER$1 || this.major < 0) {
  683. throw new TypeError('Invalid major version');
  684. }
  685. if (this.minor > MAX_SAFE_INTEGER$1 || this.minor < 0) {
  686. throw new TypeError('Invalid minor version');
  687. }
  688. if (this.patch > MAX_SAFE_INTEGER$1 || this.patch < 0) {
  689. throw new TypeError('Invalid patch version');
  690. } // numberify any prerelease numeric ids
  691. if (!m[4]) {
  692. this.prerelease = [];
  693. } else {
  694. this.prerelease = m[4].split('.').map(id => {
  695. if (/^[0-9]+$/.test(id)) {
  696. const num = +id;
  697. if (num >= 0 && num < MAX_SAFE_INTEGER$1) {
  698. return num;
  699. }
  700. }
  701. return id;
  702. });
  703. }
  704. this.build = m[5] ? m[5].split('.') : [];
  705. this.format();
  706. }
  707. format() {
  708. this.version = "".concat(this.major, ".").concat(this.minor, ".").concat(this.patch);
  709. if (this.prerelease.length) {
  710. this.version += "-".concat(this.prerelease.join('.'));
  711. }
  712. return this.version;
  713. }
  714. toString() {
  715. return this.version;
  716. }
  717. compare(other) {
  718. debug_1('SemVer.compare', this.version, this.options, other);
  719. if (!(other instanceof SemVer)) {
  720. if (typeof other === 'string' && other === this.version) {
  721. return 0;
  722. }
  723. other = new SemVer(other, this.options);
  724. }
  725. if (other.version === this.version) {
  726. return 0;
  727. }
  728. return this.compareMain(other) || this.comparePre(other);
  729. }
  730. compareMain(other) {
  731. if (!(other instanceof SemVer)) {
  732. other = new SemVer(other, this.options);
  733. }
  734. return compareIdentifiers$1(this.major, other.major) || compareIdentifiers$1(this.minor, other.minor) || compareIdentifiers$1(this.patch, other.patch);
  735. }
  736. comparePre(other) {
  737. if (!(other instanceof SemVer)) {
  738. other = new SemVer(other, this.options);
  739. } // NOT having a prerelease is > having one
  740. if (this.prerelease.length && !other.prerelease.length) {
  741. return -1;
  742. } else if (!this.prerelease.length && other.prerelease.length) {
  743. return 1;
  744. } else if (!this.prerelease.length && !other.prerelease.length) {
  745. return 0;
  746. }
  747. let i = 0;
  748. do {
  749. const a = this.prerelease[i];
  750. const b = other.prerelease[i];
  751. debug_1('prerelease compare', i, a, b);
  752. if (a === undefined && b === undefined) {
  753. return 0;
  754. } else if (b === undefined) {
  755. return 1;
  756. } else if (a === undefined) {
  757. return -1;
  758. } else if (a === b) {
  759. continue;
  760. } else {
  761. return compareIdentifiers$1(a, b);
  762. }
  763. } while (++i);
  764. }
  765. compareBuild(other) {
  766. if (!(other instanceof SemVer)) {
  767. other = new SemVer(other, this.options);
  768. }
  769. let i = 0;
  770. do {
  771. const a = this.build[i];
  772. const b = other.build[i];
  773. debug_1('prerelease compare', i, a, b);
  774. if (a === undefined && b === undefined) {
  775. return 0;
  776. } else if (b === undefined) {
  777. return 1;
  778. } else if (a === undefined) {
  779. return -1;
  780. } else if (a === b) {
  781. continue;
  782. } else {
  783. return compareIdentifiers$1(a, b);
  784. }
  785. } while (++i);
  786. } // preminor will bump the version up to the next minor release, and immediately
  787. // down to pre-release. premajor and prepatch work the same way.
  788. inc(release, identifier) {
  789. switch (release) {
  790. case 'premajor':
  791. this.prerelease.length = 0;
  792. this.patch = 0;
  793. this.minor = 0;
  794. this.major++;
  795. this.inc('pre', identifier);
  796. break;
  797. case 'preminor':
  798. this.prerelease.length = 0;
  799. this.patch = 0;
  800. this.minor++;
  801. this.inc('pre', identifier);
  802. break;
  803. case 'prepatch':
  804. // If this is already a prerelease, it will bump to the next version
  805. // drop any prereleases that might already exist, since they are not
  806. // relevant at this point.
  807. this.prerelease.length = 0;
  808. this.inc('patch', identifier);
  809. this.inc('pre', identifier);
  810. break;
  811. // If the input is a non-prerelease version, this acts the same as
  812. // prepatch.
  813. case 'prerelease':
  814. if (this.prerelease.length === 0) {
  815. this.inc('patch', identifier);
  816. }
  817. this.inc('pre', identifier);
  818. break;
  819. case 'major':
  820. // If this is a pre-major version, bump up to the same major version.
  821. // Otherwise increment major.
  822. // 1.0.0-5 bumps to 1.0.0
  823. // 1.1.0 bumps to 2.0.0
  824. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
  825. this.major++;
  826. }
  827. this.minor = 0;
  828. this.patch = 0;
  829. this.prerelease = [];
  830. break;
  831. case 'minor':
  832. // If this is a pre-minor version, bump up to the same minor version.
  833. // Otherwise increment minor.
  834. // 1.2.0-5 bumps to 1.2.0
  835. // 1.2.1 bumps to 1.3.0
  836. if (this.patch !== 0 || this.prerelease.length === 0) {
  837. this.minor++;
  838. }
  839. this.patch = 0;
  840. this.prerelease = [];
  841. break;
  842. case 'patch':
  843. // If this is not a pre-release version, it will increment the patch.
  844. // If it is a pre-release it will bump up to the same patch version.
  845. // 1.2.0-5 patches to 1.2.0
  846. // 1.2.0 patches to 1.2.1
  847. if (this.prerelease.length === 0) {
  848. this.patch++;
  849. }
  850. this.prerelease = [];
  851. break;
  852. // This probably shouldn't be used publicly.
  853. // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
  854. case 'pre':
  855. if (this.prerelease.length === 0) {
  856. this.prerelease = [0];
  857. } else {
  858. let i = this.prerelease.length;
  859. while (--i >= 0) {
  860. if (typeof this.prerelease[i] === 'number') {
  861. this.prerelease[i]++;
  862. i = -2;
  863. }
  864. }
  865. if (i === -1) {
  866. // didn't increment anything
  867. this.prerelease.push(0);
  868. }
  869. }
  870. if (identifier) {
  871. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  872. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  873. if (this.prerelease[0] === identifier) {
  874. if (isNaN(this.prerelease[1])) {
  875. this.prerelease = [identifier, 0];
  876. }
  877. } else {
  878. this.prerelease = [identifier, 0];
  879. }
  880. }
  881. break;
  882. default:
  883. throw new Error("invalid increment argument: ".concat(release));
  884. }
  885. this.format();
  886. this.raw = this.version;
  887. return this;
  888. }
  889. }
  890. var semver = SemVer;
  891. const compare = (a, b, loose) => new semver(a, loose).compare(new semver(b, loose));
  892. var compare_1 = compare;
  893. const lt = (a, b, loose) => compare_1(a, b, loose) < 0;
  894. var lt_1 = lt;
  895. const gte = (a, b, loose) => compare_1(a, b, loose) >= 0;
  896. var gte_1 = gte;
  897. var arrayify = (object, keyName) => Object.entries(object).map(([key, value]) => Object.assign({
  898. [keyName]: key
  899. }, value));
  900. var name = "prettier";
  901. var version$1 = "2.2.1";
  902. var description = "Prettier is an opinionated code formatter";
  903. var bin = "./bin/prettier.js";
  904. var repository = "prettier/prettier";
  905. var homepage = "https://prettier.io";
  906. var author = "James Long";
  907. var license = "MIT";
  908. var main = "./index.js";
  909. var browser$1 = "./standalone.js";
  910. var unpkg = "./standalone.js";
  911. var engines = {
  912. node: ">=10.13.0"
  913. };
  914. var files = [
  915. "index.js",
  916. "standalone.js",
  917. "src",
  918. "bin"
  919. ];
  920. var dependencies = {
  921. "@angular/compiler": "10.2.3",
  922. "@babel/code-frame": "7.10.4",
  923. "@babel/parser": "7.12.5",
  924. "@glimmer/syntax": "0.66.0",
  925. "@iarna/toml": "2.2.5",
  926. "@typescript-eslint/typescript-estree": "4.8.1",
  927. "angular-estree-parser": "2.2.1",
  928. "angular-html-parser": "1.7.1",
  929. camelcase: "6.2.0",
  930. chalk: "4.1.0",
  931. "ci-info": "watson/ci-info#f43f6a1cefff47fb361c88cf4b943fdbcaafe540",
  932. "cjk-regex": "2.0.0",
  933. cosmiconfig: "7.0.0",
  934. dashify: "2.0.0",
  935. diff: "5.0.0",
  936. editorconfig: "0.15.3",
  937. "editorconfig-to-prettier": "0.2.0",
  938. "escape-string-regexp": "4.0.0",
  939. espree: "7.3.0",
  940. esutils: "2.0.3",
  941. "fast-glob": "3.2.4",
  942. "fast-json-stable-stringify": "2.1.0",
  943. "find-parent-dir": "0.3.0",
  944. "flow-parser": "0.138.0",
  945. "get-stdin": "8.0.0",
  946. globby: "11.0.1",
  947. graphql: "15.4.0",
  948. "html-element-attributes": "2.3.0",
  949. "html-styles": "1.0.0",
  950. "html-tag-names": "1.1.5",
  951. "html-void-elements": "1.0.5",
  952. ignore: "4.0.6",
  953. "jest-docblock": "26.0.0",
  954. json5: "2.1.3",
  955. leven: "3.1.0",
  956. "lines-and-columns": "1.1.6",
  957. "linguist-languages": "7.12.1",
  958. lodash: "4.17.20",
  959. mem: "8.0.0",
  960. meriyah: "3.1.6",
  961. minimatch: "3.0.4",
  962. minimist: "1.2.5",
  963. "n-readlines": "1.0.1",
  964. outdent: "0.7.1",
  965. "parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
  966. "please-upgrade-node": "3.2.0",
  967. "postcss-less": "3.1.4",
  968. "postcss-media-query-parser": "0.2.3",
  969. "postcss-scss": "2.1.1",
  970. "postcss-selector-parser": "2.2.3",
  971. "postcss-values-parser": "2.0.1",
  972. "regexp-util": "1.2.2",
  973. "remark-footnotes": "2.0.0",
  974. "remark-math": "3.0.1",
  975. "remark-parse": "8.0.3",
  976. resolve: "1.19.0",
  977. semver: "7.3.2",
  978. "string-width": "4.2.0",
  979. typescript: "4.1.2",
  980. "unicode-regex": "3.0.0",
  981. unified: "9.2.0",
  982. vnopts: "1.0.2",
  983. "yaml-unist-parser": "1.3.1"
  984. };
  985. var devDependencies = {
  986. "@babel/core": "7.12.3",
  987. "@babel/preset-env": "7.12.1",
  988. "@babel/types": "7.12.6",
  989. "@glimmer/reference": "0.66.0",
  990. "@rollup/plugin-alias": "3.1.1",
  991. "@rollup/plugin-babel": "5.2.1",
  992. "@rollup/plugin-commonjs": "16.0.0",
  993. "@rollup/plugin-json": "4.1.0",
  994. "@rollup/plugin-node-resolve": "10.0.0",
  995. "@rollup/plugin-replace": "2.3.4",
  996. "@types/estree": "0.0.45",
  997. "@types/node": "14.14.0",
  998. "@typescript-eslint/types": "4.8.1",
  999. "babel-jest": "26.6.3",
  1000. "babel-loader": "8.2.1",
  1001. benchmark: "2.1.4",
  1002. "builtin-modules": "3.1.0",
  1003. "cross-env": "7.0.2",
  1004. cspell: "4.2.2",
  1005. eslint: "7.13.0",
  1006. "eslint-config-prettier": "6.15.0",
  1007. "eslint-formatter-friendly": "7.0.0",
  1008. "eslint-plugin-import": "2.22.1",
  1009. "eslint-plugin-jest": "24.1.3",
  1010. "eslint-plugin-prettier-internal-rules": "file:scripts/tools/eslint-plugin-prettier-internal-rules",
  1011. "eslint-plugin-react": "7.21.5",
  1012. "eslint-plugin-unicorn": "23.0.0",
  1013. execa: "4.1.0",
  1014. jest: "26.6.3",
  1015. "jest-snapshot-serializer-ansi": "1.0.0",
  1016. "jest-snapshot-serializer-raw": "1.1.0",
  1017. "jest-watch-typeahead": "0.6.1",
  1018. "npm-run-all": "4.1.5",
  1019. "path-browserify": "1.0.1",
  1020. prettier: "2.2.0",
  1021. rimraf: "3.0.2",
  1022. rollup: "2.33.3",
  1023. "rollup-plugin-node-globals": "1.4.0",
  1024. "rollup-plugin-terser": "7.0.2",
  1025. shelljs: "0.8.4",
  1026. "snapshot-diff": "0.8.1",
  1027. "strip-ansi": "6.0.0",
  1028. "synchronous-promise": "2.0.15",
  1029. tempy: "1.0.0",
  1030. "terser-webpack-plugin": "5.0.3",
  1031. webpack: "5.5.1"
  1032. };
  1033. var scripts = {
  1034. prepublishOnly: "echo \"Error: must publish from dist/\" && exit 1",
  1035. "prepare-release": "yarn && yarn build && yarn test:dist",
  1036. test: "jest",
  1037. "test:dev-package": "cross-env INSTALL_PACKAGE=1 jest",
  1038. "test:dist": "cross-env NODE_ENV=production jest",
  1039. "test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 jest",
  1040. "test:integration": "jest tests_integration",
  1041. "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",
  1042. "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",
  1043. "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",
  1044. lint: "run-p lint:*",
  1045. "lint:typecheck": "tsc",
  1046. "lint:eslint": "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly",
  1047. "lint:changelog": "node ./scripts/lint-changelog.js",
  1048. "lint:prettier": "prettier . \"!test*\" --check",
  1049. "lint:dist": "eslint --no-eslintrc --no-ignore --env=es6,browser --parser-options=ecmaVersion:2018 \"dist/!(bin-prettier|index|third-party).js\"",
  1050. "lint:spellcheck": "cspell \"**/*\" \".github/**/*\"",
  1051. "lint:deps": "node ./scripts/check-deps.js",
  1052. fix: "run-s fix:eslint fix:prettier",
  1053. "fix:eslint": "yarn lint:eslint --fix",
  1054. "fix:prettier": "yarn lint:prettier --write",
  1055. build: "node --max-old-space-size=3072 ./scripts/build/build.js",
  1056. "build-docs": "node ./scripts/build-docs.js"
  1057. };
  1058. var require$$3 = {
  1059. name: name,
  1060. version: version$1,
  1061. description: description,
  1062. bin: bin,
  1063. repository: repository,
  1064. homepage: homepage,
  1065. author: author,
  1066. license: license,
  1067. main: main,
  1068. browser: browser$1,
  1069. unpkg: unpkg,
  1070. engines: engines,
  1071. files: files,
  1072. dependencies: dependencies,
  1073. devDependencies: devDependencies,
  1074. scripts: scripts
  1075. };
  1076. var lib = createCommonjsModule(function (module, exports) {
  1077. Object.defineProperty(exports, "__esModule", {
  1078. value: true
  1079. }); // In the absence of a WeakSet or WeakMap implementation, don't break, but don't cache either.
  1080. function noop() {
  1081. var args = [];
  1082. for (var _i = 0; _i < arguments.length; _i++) {
  1083. args[_i] = arguments[_i];
  1084. }
  1085. }
  1086. function createWeakMap() {
  1087. if (typeof WeakMap !== 'undefined') {
  1088. return new WeakMap();
  1089. } else {
  1090. return fakeSetOrMap();
  1091. }
  1092. }
  1093. /**
  1094. * Creates and returns a no-op implementation of a WeakMap / WeakSet that never stores anything.
  1095. */
  1096. function fakeSetOrMap() {
  1097. return {
  1098. add: noop,
  1099. delete: noop,
  1100. get: noop,
  1101. set: noop,
  1102. has: function (k) {
  1103. return false;
  1104. }
  1105. };
  1106. } // Safe hasOwnProperty
  1107. var hop = Object.prototype.hasOwnProperty;
  1108. var has = function (obj, prop) {
  1109. return hop.call(obj, prop);
  1110. }; // Copy all own enumerable properties from source to target
  1111. function extend(target, source) {
  1112. for (var prop in source) {
  1113. if (has(source, prop)) {
  1114. target[prop] = source[prop];
  1115. }
  1116. }
  1117. return target;
  1118. }
  1119. var reLeadingNewline = /^[ \t]*(?:\r\n|\r|\n)/;
  1120. var reTrailingNewline = /(?:\r\n|\r|\n)[ \t]*$/;
  1121. var reStartsWithNewlineOrIsEmpty = /^(?:[\r\n]|$)/;
  1122. var reDetectIndentation = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
  1123. var reOnlyWhitespaceWithAtLeastOneNewline = /^[ \t]*[\r\n][ \t\r\n]*$/;
  1124. function _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options) {
  1125. // If first interpolated value is a reference to outdent,
  1126. // determine indentation level from the indentation of the interpolated value.
  1127. var indentationLevel = 0;
  1128. var match = strings[0].match(reDetectIndentation);
  1129. if (match) {
  1130. indentationLevel = match[1].length;
  1131. }
  1132. var reSource = "(\\r\\n|\\r|\\n).{0," + indentationLevel + "}";
  1133. var reMatchIndent = new RegExp(reSource, 'g');
  1134. if (firstInterpolatedValueSetsIndentationLevel) {
  1135. strings = strings.slice(1);
  1136. }
  1137. var newline = options.newline,
  1138. trimLeadingNewline = options.trimLeadingNewline,
  1139. trimTrailingNewline = options.trimTrailingNewline;
  1140. var normalizeNewlines = typeof newline === 'string';
  1141. var l = strings.length;
  1142. var outdentedStrings = strings.map(function (v, i) {
  1143. // Remove leading indentation from all lines
  1144. v = v.replace(reMatchIndent, '$1'); // Trim a leading newline from the first string
  1145. if (i === 0 && trimLeadingNewline) {
  1146. v = v.replace(reLeadingNewline, '');
  1147. } // Trim a trailing newline from the last string
  1148. if (i === l - 1 && trimTrailingNewline) {
  1149. v = v.replace(reTrailingNewline, '');
  1150. } // Normalize newlines
  1151. if (normalizeNewlines) {
  1152. v = v.replace(/\r\n|\n|\r/g, function (_) {
  1153. return newline;
  1154. });
  1155. }
  1156. return v;
  1157. });
  1158. return outdentedStrings;
  1159. }
  1160. function concatStringsAndValues(strings, values) {
  1161. var ret = '';
  1162. for (var i = 0, l = strings.length; i < l; i++) {
  1163. ret += strings[i];
  1164. if (i < l - 1) {
  1165. ret += values[i];
  1166. }
  1167. }
  1168. return ret;
  1169. }
  1170. function isTemplateStringsArray(v) {
  1171. return has(v, 'raw') && has(v, 'length');
  1172. }
  1173. /**
  1174. * It is assumed that opts will not change. If this is a problem, clone your options object and pass the clone to
  1175. * makeInstance
  1176. * @param options
  1177. * @return {outdent}
  1178. */
  1179. function createInstance(options) {
  1180. /** Cache of pre-processed template literal arrays */
  1181. var arrayAutoIndentCache = createWeakMap();
  1182. /**
  1183. * Cache of pre-processed template literal arrays, where first interpolated value is a reference to outdent,
  1184. * before interpolated values are injected.
  1185. */
  1186. var arrayFirstInterpSetsIndentCache = createWeakMap();
  1187. function outdent(stringsOrOptions) {
  1188. var values = [];
  1189. for (var _i = 1; _i < arguments.length; _i++) {
  1190. values[_i - 1] = arguments[_i];
  1191. }
  1192. /* tslint:enable:no-shadowed-variable */
  1193. if (isTemplateStringsArray(stringsOrOptions)) {
  1194. var strings = stringsOrOptions; // Is first interpolated value a reference to outdent, alone on its own line, without any preceding non-whitespace?
  1195. var firstInterpolatedValueSetsIndentationLevel = (values[0] === outdent || values[0] === defaultOutdent) && reOnlyWhitespaceWithAtLeastOneNewline.test(strings[0]) && reStartsWithNewlineOrIsEmpty.test(strings[1]); // Perform outdentation
  1196. var cache = firstInterpolatedValueSetsIndentationLevel ? arrayFirstInterpSetsIndentCache : arrayAutoIndentCache;
  1197. var renderedArray = cache.get(strings);
  1198. if (!renderedArray) {
  1199. renderedArray = _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
  1200. cache.set(strings, renderedArray);
  1201. }
  1202. /** If no interpolated values, skip concatenation step */
  1203. if (values.length === 0) {
  1204. return renderedArray[0];
  1205. }
  1206. /** Concatenate string literals with interpolated values */
  1207. var rendered = concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
  1208. return rendered;
  1209. } else {
  1210. // Create and return a new instance of outdent with the given options
  1211. return createInstance(extend(extend({}, options), stringsOrOptions || {}));
  1212. }
  1213. }
  1214. var fullOutdent = extend(outdent, {
  1215. string: function (str) {
  1216. return _outdentArray([str], false, options)[0];
  1217. }
  1218. });
  1219. return fullOutdent;
  1220. }
  1221. var defaultOutdent = createInstance({
  1222. trimLeadingNewline: true,
  1223. trimTrailingNewline: true
  1224. });
  1225. exports.outdent = defaultOutdent; // Named exports. Simple and preferred.
  1226. // import outdent from 'outdent';
  1227. exports.default = defaultOutdent;
  1228. {
  1229. // In webpack harmony-modules environments, module.exports is read-only,
  1230. // so we fail gracefully.
  1231. try {
  1232. module.exports = defaultOutdent;
  1233. Object.defineProperty(defaultOutdent, '__esModule', {
  1234. value: true
  1235. });
  1236. defaultOutdent.default = defaultOutdent;
  1237. defaultOutdent.outdent = defaultOutdent;
  1238. } catch (e) {}
  1239. }
  1240. });
  1241. function _templateObject6() {
  1242. const 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 "]);
  1243. _templateObject6 = function () {
  1244. return data;
  1245. };
  1246. return data;
  1247. }
  1248. function _templateObject5() {
  1249. const 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 "]);
  1250. _templateObject5 = function () {
  1251. return data;
  1252. };
  1253. return data;
  1254. }
  1255. function _templateObject4() {
  1256. const 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 "]);
  1257. _templateObject4 = function () {
  1258. return data;
  1259. };
  1260. return data;
  1261. }
  1262. function _templateObject3() {
  1263. const 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 "]);
  1264. _templateObject3 = function () {
  1265. return data;
  1266. };
  1267. return data;
  1268. }
  1269. function _templateObject2() {
  1270. const data = _taggedTemplateLiteral(["\n Maintain existing\n (mixed values within one file are normalised by looking at what's used after the first line)\n "]);
  1271. _templateObject2 = function () {
  1272. return data;
  1273. };
  1274. return data;
  1275. }
  1276. function _templateObject() {
  1277. const 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 "]);
  1278. _templateObject = function () {
  1279. return data;
  1280. };
  1281. return data;
  1282. }
  1283. const {
  1284. outdent
  1285. } = lib;
  1286. const CATEGORY_CONFIG = "Config";
  1287. const CATEGORY_EDITOR = "Editor";
  1288. const CATEGORY_FORMAT = "Format";
  1289. const CATEGORY_OTHER = "Other";
  1290. const CATEGORY_OUTPUT = "Output";
  1291. const CATEGORY_GLOBAL = "Global";
  1292. const CATEGORY_SPECIAL = "Special";
  1293. /**
  1294. * @typedef {Object} OptionInfo
  1295. * @property {string} [since] - available since version
  1296. * @property {string} category
  1297. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  1298. * @property {boolean} [array] - indicate it's an array of the specified type
  1299. * @property {OptionValueInfo} [default]
  1300. * @property {OptionRangeInfo} [range] - for type int
  1301. * @property {string} description
  1302. * @property {string} [deprecated] - deprecated since version
  1303. * @property {OptionRedirectInfo} [redirect] - redirect deprecated option
  1304. * @property {(value: any) => boolean} [exception]
  1305. * @property {OptionChoiceInfo[]} [choices] - for type choice
  1306. * @property {string} [cliName]
  1307. * @property {string} [cliCategory]
  1308. * @property {string} [cliDescription]
  1309. *
  1310. * @typedef {number | boolean | string} OptionValue
  1311. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  1312. *
  1313. * @typedef {Object} OptionRedirectInfo
  1314. * @property {string} option
  1315. * @property {OptionValue} value
  1316. *
  1317. * @typedef {Object} OptionRangeInfo
  1318. * @property {number} start - recommended range start
  1319. * @property {number} end - recommended range end
  1320. * @property {number} step - recommended range step
  1321. *
  1322. * @typedef {Object} OptionChoiceInfo
  1323. * @property {boolean | string} value - boolean for the option that is originally boolean type
  1324. * @property {string} description
  1325. * @property {string} [since] - undefined if available since the first version of the option
  1326. * @property {string} [deprecated] - deprecated since version
  1327. * @property {OptionValueInfo} [redirect] - redirect deprecated value
  1328. */
  1329. /** @type {{ [name: string]: OptionInfo }} */
  1330. const options = {
  1331. cursorOffset: {
  1332. since: "1.4.0",
  1333. category: CATEGORY_SPECIAL,
  1334. type: "int",
  1335. default: -1,
  1336. range: {
  1337. start: -1,
  1338. end: Infinity,
  1339. step: 1
  1340. },
  1341. description: outdent(_templateObject()),
  1342. cliCategory: CATEGORY_EDITOR
  1343. },
  1344. endOfLine: {
  1345. since: "1.15.0",
  1346. category: CATEGORY_GLOBAL,
  1347. type: "choice",
  1348. default: [{
  1349. since: "1.15.0",
  1350. value: "auto"
  1351. }, {
  1352. since: "2.0.0",
  1353. value: "lf"
  1354. }],
  1355. description: "Which end of line characters to apply.",
  1356. choices: [{
  1357. value: "lf",
  1358. description: "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
  1359. }, {
  1360. value: "crlf",
  1361. description: "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
  1362. }, {
  1363. value: "cr",
  1364. description: "Carriage Return character only (\\r), used very rarely"
  1365. }, {
  1366. value: "auto",
  1367. description: outdent(_templateObject2())
  1368. }]
  1369. },
  1370. filepath: {
  1371. since: "1.4.0",
  1372. category: CATEGORY_SPECIAL,
  1373. type: "path",
  1374. description: "Specify the input filepath. This will be used to do parser inference.",
  1375. cliName: "stdin-filepath",
  1376. cliCategory: CATEGORY_OTHER,
  1377. cliDescription: "Path to the file to pretend that stdin comes from."
  1378. },
  1379. insertPragma: {
  1380. since: "1.8.0",
  1381. category: CATEGORY_SPECIAL,
  1382. type: "boolean",
  1383. default: false,
  1384. description: "Insert @format pragma into file's first docblock comment.",
  1385. cliCategory: CATEGORY_OTHER
  1386. },
  1387. parser: {
  1388. since: "0.0.10",
  1389. category: CATEGORY_GLOBAL,
  1390. type: "choice",
  1391. default: [{
  1392. since: "0.0.10",
  1393. value: "babylon"
  1394. }, {
  1395. since: "1.13.0",
  1396. value: undefined
  1397. }],
  1398. description: "Which parser to use.",
  1399. exception: value => typeof value === "string" || typeof value === "function",
  1400. choices: [{
  1401. value: "flow",
  1402. description: "Flow"
  1403. }, {
  1404. value: "babel",
  1405. since: "1.16.0",
  1406. description: "JavaScript"
  1407. }, {
  1408. value: "babel-flow",
  1409. since: "1.16.0",
  1410. description: "Flow"
  1411. }, {
  1412. value: "babel-ts",
  1413. since: "2.0.0",
  1414. description: "TypeScript"
  1415. }, {
  1416. value: "typescript",
  1417. since: "1.4.0",
  1418. description: "TypeScript"
  1419. }, {
  1420. value: "espree",
  1421. since: "2.2.0",
  1422. description: "JavaScript"
  1423. }, {
  1424. value: "meriyah",
  1425. since: "2.2.0",
  1426. description: "JavaScript"
  1427. }, {
  1428. value: "css",
  1429. since: "1.7.1",
  1430. description: "CSS"
  1431. }, {
  1432. value: "less",
  1433. since: "1.7.1",
  1434. description: "Less"
  1435. }, {
  1436. value: "scss",
  1437. since: "1.7.1",
  1438. description: "SCSS"
  1439. }, {
  1440. value: "json",
  1441. since: "1.5.0",
  1442. description: "JSON"
  1443. }, {
  1444. value: "json5",
  1445. since: "1.13.0",
  1446. description: "JSON5"
  1447. }, {
  1448. value: "json-stringify",
  1449. since: "1.13.0",
  1450. description: "JSON.stringify"
  1451. }, {
  1452. value: "graphql",
  1453. since: "1.5.0",
  1454. description: "GraphQL"
  1455. }, {
  1456. value: "markdown",
  1457. since: "1.8.0",
  1458. description: "Markdown"
  1459. }, {
  1460. value: "mdx",
  1461. since: "1.15.0",
  1462. description: "MDX"
  1463. }, {
  1464. value: "vue",
  1465. since: "1.10.0",
  1466. description: "Vue"
  1467. }, {
  1468. value: "yaml",
  1469. since: "1.14.0",
  1470. description: "YAML"
  1471. }, {
  1472. value: "glimmer",
  1473. since: null,
  1474. description: "Handlebars"
  1475. }, {
  1476. value: "html",
  1477. since: "1.15.0",
  1478. description: "HTML"
  1479. }, {
  1480. value: "angular",
  1481. since: "1.15.0",
  1482. description: "Angular"
  1483. }, {
  1484. value: "lwc",
  1485. since: "1.17.0",
  1486. description: "Lightning Web Components"
  1487. }]
  1488. },
  1489. plugins: {
  1490. since: "1.10.0",
  1491. type: "path",
  1492. array: true,
  1493. default: [{
  1494. value: []
  1495. }],
  1496. category: CATEGORY_GLOBAL,
  1497. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  1498. exception: value => typeof value === "string" || typeof value === "object",
  1499. cliName: "plugin",
  1500. cliCategory: CATEGORY_CONFIG
  1501. },
  1502. pluginSearchDirs: {
  1503. since: "1.13.0",
  1504. type: "path",
  1505. array: true,
  1506. default: [{
  1507. value: []
  1508. }],
  1509. category: CATEGORY_GLOBAL,
  1510. description: outdent(_templateObject3()),
  1511. exception: value => typeof value === "string" || typeof value === "object",
  1512. cliName: "plugin-search-dir",
  1513. cliCategory: CATEGORY_CONFIG
  1514. },
  1515. printWidth: {
  1516. since: "0.0.0",
  1517. category: CATEGORY_GLOBAL,
  1518. type: "int",
  1519. default: 80,
  1520. description: "The line length where Prettier will try wrap.",
  1521. range: {
  1522. start: 0,
  1523. end: Infinity,
  1524. step: 1
  1525. }
  1526. },
  1527. rangeEnd: {
  1528. since: "1.4.0",
  1529. category: CATEGORY_SPECIAL,
  1530. type: "int",
  1531. default: Infinity,
  1532. range: {
  1533. start: 0,
  1534. end: Infinity,
  1535. step: 1
  1536. },
  1537. description: outdent(_templateObject4()),
  1538. cliCategory: CATEGORY_EDITOR
  1539. },
  1540. rangeStart: {
  1541. since: "1.4.0",
  1542. category: CATEGORY_SPECIAL,
  1543. type: "int",
  1544. default: 0,
  1545. range: {
  1546. start: 0,
  1547. end: Infinity,
  1548. step: 1
  1549. },
  1550. description: outdent(_templateObject5()),
  1551. cliCategory: CATEGORY_EDITOR
  1552. },
  1553. requirePragma: {
  1554. since: "1.7.0",
  1555. category: CATEGORY_SPECIAL,
  1556. type: "boolean",
  1557. default: false,
  1558. description: outdent(_templateObject6()),
  1559. cliCategory: CATEGORY_OTHER
  1560. },
  1561. tabWidth: {
  1562. type: "int",
  1563. category: CATEGORY_GLOBAL,
  1564. default: 2,
  1565. description: "Number of spaces per indentation level.",
  1566. range: {
  1567. start: 0,
  1568. end: Infinity,
  1569. step: 1
  1570. }
  1571. },
  1572. useTabs: {
  1573. since: "1.0.0",
  1574. category: CATEGORY_GLOBAL,
  1575. type: "boolean",
  1576. default: false,
  1577. description: "Indent with tabs instead of spaces."
  1578. },
  1579. embeddedLanguageFormatting: {
  1580. since: "2.1.0",
  1581. category: CATEGORY_GLOBAL,
  1582. type: "choice",
  1583. default: [{
  1584. since: "2.1.0",
  1585. value: "auto"
  1586. }],
  1587. description: "Control how Prettier formats quoted code embedded in the file.",
  1588. choices: [{
  1589. value: "auto",
  1590. description: "Format embedded code if Prettier can automatically identify it."
  1591. }, {
  1592. value: "off",
  1593. description: "Never automatically format embedded code."
  1594. }]
  1595. }
  1596. };
  1597. var coreOptions = {
  1598. CATEGORY_CONFIG,
  1599. CATEGORY_EDITOR,
  1600. CATEGORY_FORMAT,
  1601. CATEGORY_OTHER,
  1602. CATEGORY_OUTPUT,
  1603. CATEGORY_GLOBAL,
  1604. CATEGORY_SPECIAL,
  1605. options
  1606. };
  1607. const semver$1 = {
  1608. compare: compare_1,
  1609. lt: lt_1,
  1610. gte: gte_1
  1611. };
  1612. const currentVersion = require$$3.version;
  1613. const coreOptions$1 = coreOptions.options;
  1614. /**
  1615. * Strings in `plugins` and `pluginSearchDirs` are handled by a wrapped version
  1616. * of this function created by `withPlugins`. Don't pass them here directly.
  1617. * @param {object} param0
  1618. * @param {(string | object)[]=} param0.plugins Strings are resolved by `withPlugins`.
  1619. * @param {string[]=} param0.pluginSearchDirs Added by `withPlugins`.
  1620. * @param {boolean=} param0.showUnreleased
  1621. * @param {boolean=} param0.showDeprecated
  1622. * @param {boolean=} param0.showInternal
  1623. */
  1624. function getSupportInfo({
  1625. plugins = [],
  1626. showUnreleased = false,
  1627. showDeprecated = false,
  1628. showInternal = false
  1629. } = {}) {
  1630. // pre-release version is smaller than the normal version in semver,
  1631. // we need to treat it as the normal one so as to test new features.
  1632. const version = currentVersion.split("-", 1)[0];
  1633. const languages = plugins.reduce((all, plugin) => all.concat(plugin.languages || []), []).filter(filterSince);
  1634. const options = arrayify(Object.assign({}, ...plugins.map(({
  1635. options
  1636. }) => options), coreOptions$1), "name").filter(option => filterSince(option) && filterDeprecated(option)).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1).map(mapInternal).map(option => {
  1637. option = Object.assign({}, option);
  1638. if (Array.isArray(option.default)) {
  1639. option.default = option.default.length === 1 ? option.default[0].value : option.default.filter(filterSince).sort((info1, info2) => semver$1.compare(info2.since, info1.since))[0].value;
  1640. }
  1641. if (Array.isArray(option.choices)) {
  1642. option.choices = option.choices.filter(option => filterSince(option) && filterDeprecated(option));
  1643. if (option.name === "parser") {
  1644. collectParsersFromLanguages(option, languages, plugins);
  1645. }
  1646. }
  1647. const pluginDefaults = plugins.filter(plugin => plugin.defaultOptions && plugin.defaultOptions[option.name] !== undefined).reduce((reduced, plugin) => {
  1648. reduced[plugin.name] = plugin.defaultOptions[option.name];
  1649. return reduced;
  1650. }, {});
  1651. return Object.assign({}, option, {
  1652. pluginDefaults
  1653. });
  1654. });
  1655. return {
  1656. languages,
  1657. options
  1658. };
  1659. function filterSince(object) {
  1660. return showUnreleased || !("since" in object) || object.since && semver$1.gte(version, object.since);
  1661. }
  1662. function filterDeprecated(object) {
  1663. return showDeprecated || !("deprecated" in object) || object.deprecated && semver$1.lt(version, object.deprecated);
  1664. }
  1665. function mapInternal(object) {
  1666. if (showInternal) {
  1667. return object;
  1668. }
  1669. const newObject = _objectWithoutPropertiesLoose(object, ["cliName", "cliCategory", "cliDescription"]);
  1670. return newObject;
  1671. }
  1672. }
  1673. function collectParsersFromLanguages(option, languages, plugins) {
  1674. const existingValues = new Set(option.choices.map(choice => choice.value));
  1675. for (const language of languages) {
  1676. if (language.parsers) {
  1677. for (const value of language.parsers) {
  1678. if (!existingValues.has(value)) {
  1679. existingValues.add(value);
  1680. const plugin = plugins.find(plugin => plugin.parsers && plugin.parsers[value]);
  1681. let description = language.name;
  1682. if (plugin && plugin.name) {
  1683. description += " (plugin: ".concat(plugin.name, ")");
  1684. }
  1685. option.choices.push({
  1686. value,
  1687. description
  1688. });
  1689. }
  1690. }
  1691. }
  1692. }
  1693. }
  1694. var support = {
  1695. getSupportInfo
  1696. };
  1697. const {
  1698. getSupportInfo: getSupportInfo$1
  1699. } = support;
  1700. const notAsciiRegex = /[^\x20-\x7F]/;
  1701. const getPenultimate = arr => arr[arr.length - 2];
  1702. /**
  1703. * @typedef {{backwards?: boolean}} SkipOptions
  1704. */
  1705. /**
  1706. * @param {string | RegExp} chars
  1707. * @returns {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  1708. */
  1709. function skip(chars) {
  1710. return (text, index, opts) => {
  1711. const backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  1712. // to check for failures (did someone say monads?).
  1713. /* istanbul ignore next */
  1714. if (index === false) {
  1715. return false;
  1716. }
  1717. const {
  1718. length
  1719. } = text;
  1720. let cursor = index;
  1721. while (cursor >= 0 && cursor < length) {
  1722. const c = text.charAt(cursor);
  1723. if (chars instanceof RegExp) {
  1724. if (!chars.test(c)) {
  1725. return cursor;
  1726. }
  1727. } else if (!chars.includes(c)) {
  1728. return cursor;
  1729. }
  1730. backwards ? cursor-- : cursor++;
  1731. }
  1732. if (cursor === -1 || cursor === length) {
  1733. // If we reached the beginning or end of the file, return the
  1734. // out-of-bounds cursor. It's up to the caller to handle this
  1735. // correctly. We don't want to indicate `false` though if it
  1736. // actually skipped valid characters.
  1737. return cursor;
  1738. }
  1739. return false;
  1740. };
  1741. }
  1742. /**
  1743. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  1744. */
  1745. const skipWhitespace = skip(/\s/);
  1746. /**
  1747. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  1748. */
  1749. const skipSpaces = skip(" \t");
  1750. /**
  1751. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  1752. */
  1753. const skipToLineEnd = skip(",; \t");
  1754. /**
  1755. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  1756. */
  1757. const skipEverythingButNewLine = skip(/[^\n\r]/);
  1758. /**
  1759. * @param {string} text
  1760. * @param {number | false} index
  1761. * @returns {number | false}
  1762. */
  1763. function skipInlineComment(text, index) {
  1764. /* istanbul ignore next */
  1765. if (index === false) {
  1766. return false;
  1767. }
  1768. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  1769. for (let i = index + 2; i < text.length; ++i) {
  1770. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  1771. return i + 2;
  1772. }
  1773. }
  1774. }
  1775. return index;
  1776. }
  1777. /**
  1778. * @param {string} text
  1779. * @param {number | false} index
  1780. * @returns {number | false}
  1781. */
  1782. function skipTrailingComment(text, index) {
  1783. /* istanbul ignore next */
  1784. if (index === false) {
  1785. return false;
  1786. }
  1787. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  1788. return skipEverythingButNewLine(text, index);
  1789. }
  1790. return index;
  1791. } // This one doesn't use the above helper function because it wants to
  1792. // test \r\n in order and `skip` doesn't support ordering and we only
  1793. // want to skip one newline. It's simple to implement.
  1794. /**
  1795. * @param {string} text
  1796. * @param {number | false} index
  1797. * @param {SkipOptions=} opts
  1798. * @returns {number | false}
  1799. */
  1800. function skipNewline(text, index, opts) {
  1801. const backwards = opts && opts.backwards;
  1802. if (index === false) {
  1803. return false;
  1804. }
  1805. const atIndex = text.charAt(index);
  1806. if (backwards) {
  1807. // We already replace `\r\n` with `\n` before parsing
  1808. /* istanbul ignore next */
  1809. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  1810. return index - 2;
  1811. }
  1812. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  1813. return index - 1;
  1814. }
  1815. } else {
  1816. // We already replace `\r\n` with `\n` before parsing
  1817. /* istanbul ignore next */
  1818. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  1819. return index + 2;
  1820. }
  1821. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  1822. return index + 1;
  1823. }
  1824. }
  1825. return index;
  1826. }
  1827. /**
  1828. * @param {string} text
  1829. * @param {number} index
  1830. * @param {SkipOptions=} opts
  1831. * @returns {boolean}
  1832. */
  1833. function hasNewline(text, index, opts) {
  1834. opts = opts || {};
  1835. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  1836. const idx2 = skipNewline(text, idx, opts);
  1837. return idx !== idx2;
  1838. }
  1839. /**
  1840. * @param {string} text
  1841. * @param {number} start
  1842. * @param {number} end
  1843. * @returns {boolean}
  1844. */
  1845. function hasNewlineInRange(text, start, end) {
  1846. for (let i = start; i < end; ++i) {
  1847. if (text.charAt(i) === "\n") {
  1848. return true;
  1849. }
  1850. }
  1851. return false;
  1852. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  1853. /**
  1854. * @template N
  1855. * @param {string} text
  1856. * @param {N} node
  1857. * @param {(node: N) => number} locStart
  1858. */
  1859. function isPreviousLineEmpty(text, node, locStart) {
  1860. /** @type {number | false} */
  1861. let idx = locStart(node) - 1;
  1862. idx = skipSpaces(text, idx, {
  1863. backwards: true
  1864. });
  1865. idx = skipNewline(text, idx, {
  1866. backwards: true
  1867. });
  1868. idx = skipSpaces(text, idx, {
  1869. backwards: true
  1870. });
  1871. const idx2 = skipNewline(text, idx, {
  1872. backwards: true
  1873. });
  1874. return idx !== idx2;
  1875. }
  1876. /**
  1877. * @param {string} text
  1878. * @param {number} index
  1879. * @returns {boolean}
  1880. */
  1881. function isNextLineEmptyAfterIndex(text, index) {
  1882. /** @type {number | false} */
  1883. let oldIdx = null;
  1884. /** @type {number | false} */
  1885. let idx = index;
  1886. while (idx !== oldIdx) {
  1887. // We need to skip all the potential trailing inline comments
  1888. oldIdx = idx;
  1889. idx = skipToLineEnd(text, idx);
  1890. idx = skipInlineComment(text, idx);
  1891. idx = skipSpaces(text, idx);
  1892. }
  1893. idx = skipTrailingComment(text, idx);
  1894. idx = skipNewline(text, idx);
  1895. return idx !== false && hasNewline(text, idx);
  1896. }
  1897. /**
  1898. * @template N
  1899. * @param {string} text
  1900. * @param {N} node
  1901. * @param {(node: N) => number} locEnd
  1902. * @returns {boolean}
  1903. */
  1904. function isNextLineEmpty(text, node, locEnd) {
  1905. return isNextLineEmptyAfterIndex(text, locEnd(node));
  1906. }
  1907. /**
  1908. * @param {string} text
  1909. * @param {number} idx
  1910. * @returns {number | false}
  1911. */
  1912. function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
  1913. /** @type {number | false} */
  1914. let oldIdx = null;
  1915. /** @type {number | false} */
  1916. let nextIdx = idx;
  1917. while (nextIdx !== oldIdx) {
  1918. oldIdx = nextIdx;
  1919. nextIdx = skipSpaces(text, nextIdx);
  1920. nextIdx = skipInlineComment(text, nextIdx);
  1921. nextIdx = skipTrailingComment(text, nextIdx);
  1922. nextIdx = skipNewline(text, nextIdx);
  1923. }
  1924. return nextIdx;
  1925. }
  1926. /**
  1927. * @template N
  1928. * @param {string} text
  1929. * @param {N} node
  1930. * @param {(node: N) => number} locEnd
  1931. * @returns {number | false}
  1932. */
  1933. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  1934. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
  1935. }
  1936. /**
  1937. * @template N
  1938. * @param {string} text
  1939. * @param {N} node
  1940. * @param {(node: N) => number} locEnd
  1941. * @returns {string}
  1942. */
  1943. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  1944. return text.charAt( // @ts-ignore => TBD: can return false, should we define a fallback?
  1945. getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  1946. } // Not using, but it's public utils
  1947. /* istanbul ignore next */
  1948. /**
  1949. * @param {string} text
  1950. * @param {number} index
  1951. * @param {SkipOptions=} opts
  1952. * @returns {boolean}
  1953. */
  1954. function hasSpaces(text, index, opts) {
  1955. opts = opts || {};
  1956. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  1957. return idx !== index;
  1958. }
  1959. /**
  1960. * @param {string} value
  1961. * @param {number} tabWidth
  1962. * @param {number=} startIndex
  1963. * @returns {number}
  1964. */
  1965. function getAlignmentSize(value, tabWidth, startIndex) {
  1966. startIndex = startIndex || 0;
  1967. let size = 0;
  1968. for (let i = startIndex; i < value.length; ++i) {
  1969. if (value[i] === "\t") {
  1970. // Tabs behave in a way that they are aligned to the nearest
  1971. // multiple of tabWidth:
  1972. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  1973. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  1974. size = size + tabWidth - size % tabWidth;
  1975. } else {
  1976. size++;
  1977. }
  1978. }
  1979. return size;
  1980. }
  1981. /**
  1982. * @param {string} value
  1983. * @param {number} tabWidth
  1984. * @returns {number}
  1985. */
  1986. function getIndentSize(value, tabWidth) {
  1987. const lastNewlineIndex = value.lastIndexOf("\n");
  1988. if (lastNewlineIndex === -1) {
  1989. return 0;
  1990. }
  1991. return getAlignmentSize( // All the leading whitespaces
  1992. value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0], tabWidth);
  1993. }
  1994. /**
  1995. * @typedef {'"' | "'"} Quote
  1996. */
  1997. /**
  1998. *
  1999. * @param {string} raw
  2000. * @param {Quote} preferredQuote
  2001. * @returns {Quote}
  2002. */
  2003. function getPreferredQuote(raw, preferredQuote) {
  2004. // `rawContent` is the string exactly like it appeared in the input source
  2005. // code, without its enclosing quotes.
  2006. const rawContent = raw.slice(1, -1);
  2007. /** @type {{ quote: '"', regex: RegExp }} */
  2008. const double = {
  2009. quote: '"',
  2010. regex: /"/g
  2011. };
  2012. /** @type {{ quote: "'", regex: RegExp }} */
  2013. const single = {
  2014. quote: "'",
  2015. regex: /'/g
  2016. };
  2017. const preferred = preferredQuote === "'" ? single : double;
  2018. const alternate = preferred === single ? double : single;
  2019. let result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
  2020. // the string, we might want to enclose with the alternate quote instead, to
  2021. // minimize the number of escaped quotes.
  2022. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  2023. const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  2024. const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  2025. result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
  2026. }
  2027. return result;
  2028. }
  2029. function printString(raw, options, isDirectiveLiteral) {
  2030. // `rawContent` is the string exactly like it appeared in the input source
  2031. // code, without its enclosing quotes.
  2032. const rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
  2033. // the quotes on a DirectiveLiteral.
  2034. const canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
  2035. /** @type {Quote} */
  2036. const enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
  2037. // change the escape sequences they use.
  2038. // See https://github.com/prettier/prettier/issues/1555
  2039. // and https://tc39.github.io/ecma262/#directive-prologue
  2040. if (isDirectiveLiteral) {
  2041. if (canChangeDirectiveQuotes) {
  2042. return enclosingQuote + rawContent + enclosingQuote;
  2043. }
  2044. return raw;
  2045. } // It might sound unnecessary to use `makeString` even if the string already
  2046. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  2047. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  2048. // sure that we consistently output the minimum amount of escaped quotes.
  2049. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.embeddedInHtml));
  2050. }
  2051. /**
  2052. * @param {string} rawContent
  2053. * @param {Quote} enclosingQuote
  2054. * @param {boolean=} unescapeUnnecessaryEscapes
  2055. * @returns {string}
  2056. */
  2057. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  2058. const otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  2059. const regex = /\\([\S\s])|(["'])/g; // Escape and unescape single and double quotes as needed to be able to
  2060. // enclose `rawContent` with `enclosingQuote`.
  2061. const newContent = rawContent.replace(regex, (match, escaped, quote) => {
  2062. // If we matched an escape, and the escaped character is a quote of the
  2063. // other type than we intend to enclose the string with, there's no need for
  2064. // it to be escaped, so return it _without_ the backslash.
  2065. if (escaped === otherQuote) {
  2066. return escaped;
  2067. } // If we matched an unescaped quote and it is of the _same_ type as we
  2068. // intend to enclose the string with, it must be escaped, so return it with
  2069. // a backslash.
  2070. if (quote === enclosingQuote) {
  2071. return "\\" + quote;
  2072. }
  2073. if (quote) {
  2074. return quote;
  2075. } // Unescape any unnecessarily escaped character.
  2076. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  2077. return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/.test(escaped) ? escaped : "\\" + escaped;
  2078. });
  2079. return enclosingQuote + newContent + enclosingQuote;
  2080. }
  2081. function printNumber(rawNumber) {
  2082. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  2083. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  2084. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  2085. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  2086. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  2087. .replace(/\.(?=e|$)/, "");
  2088. }
  2089. /**
  2090. * @param {string} str
  2091. * @param {string} target
  2092. * @returns {number}
  2093. */
  2094. function getMaxContinuousCount(str, target) {
  2095. const results = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
  2096. if (results === null) {
  2097. return 0;
  2098. }
  2099. return results.reduce((maxCount, result) => Math.max(maxCount, result.length / target.length), 0);
  2100. }
  2101. function getMinNotPresentContinuousCount(str, target) {
  2102. const matches = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
  2103. if (matches === null) {
  2104. return 0;
  2105. }
  2106. const countPresent = new Map();
  2107. let max = 0;
  2108. for (const match of matches) {
  2109. const count = match.length / target.length;
  2110. countPresent.set(count, true);
  2111. if (count > max) {
  2112. max = count;
  2113. }
  2114. }
  2115. for (let i = 1; i < max; i++) {
  2116. if (!countPresent.get(i)) {
  2117. return i;
  2118. }
  2119. }
  2120. return max + 1;
  2121. }
  2122. /**
  2123. * @param {string} text
  2124. * @returns {number}
  2125. */
  2126. function getStringWidth(text) {
  2127. if (!text) {
  2128. return 0;
  2129. } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
  2130. if (!notAsciiRegex.test(text)) {
  2131. return text.length;
  2132. }
  2133. return stringWidth_1(text);
  2134. }
  2135. function isNodeIgnoreComment(comment) {
  2136. return comment.value.trim() === "prettier-ignore";
  2137. }
  2138. function addCommentHelper(node, comment) {
  2139. const comments = node.comments || (node.comments = []);
  2140. comments.push(comment);
  2141. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  2142. // We already "print" it via the raw text, we don't need to re-print it as a
  2143. // comment
  2144. /* istanbul ignore next */
  2145. if (node.type === "JSXText") {
  2146. comment.printed = true;
  2147. }
  2148. }
  2149. function addLeadingComment(node, comment) {
  2150. comment.leading = true;
  2151. comment.trailing = false;
  2152. addCommentHelper(node, comment);
  2153. }
  2154. function addDanglingComment(node, comment, marker) {
  2155. comment.leading = false;
  2156. comment.trailing = false;
  2157. if (marker) {
  2158. comment.marker = marker;
  2159. }
  2160. addCommentHelper(node, comment);
  2161. }
  2162. function addTrailingComment(node, comment) {
  2163. comment.leading = false;
  2164. comment.trailing = true;
  2165. addCommentHelper(node, comment);
  2166. }
  2167. function replaceEndOfLineWith(text, replacement) {
  2168. const parts = [];
  2169. for (const part of text.split("\n")) {
  2170. if (parts.length !== 0) {
  2171. parts.push(replacement);
  2172. }
  2173. parts.push(part);
  2174. }
  2175. return parts;
  2176. }
  2177. function inferParserByLanguage(language, options) {
  2178. const {
  2179. languages
  2180. } = getSupportInfo$1({
  2181. plugins: options.plugins
  2182. });
  2183. const matched = languages.find(({
  2184. name
  2185. }) => name.toLowerCase() === language) || languages.find(({
  2186. aliases
  2187. }) => Array.isArray(aliases) && aliases.includes(language)) || languages.find(({
  2188. extensions
  2189. }) => Array.isArray(extensions) && extensions.includes(".".concat(language)));
  2190. return matched && matched.parsers[0];
  2191. }
  2192. function isFrontMatterNode(node) {
  2193. return node && node.type === "front-matter";
  2194. }
  2195. function getShebang(text) {
  2196. if (!text.startsWith("#!")) {
  2197. return "";
  2198. }
  2199. const index = text.indexOf("\n");
  2200. if (index === -1) {
  2201. return text;
  2202. }
  2203. return text.slice(0, index);
  2204. }
  2205. var util = {
  2206. inferParserByLanguage,
  2207. replaceEndOfLineWith,
  2208. getStringWidth,
  2209. getMaxContinuousCount,
  2210. getMinNotPresentContinuousCount,
  2211. getPenultimate,
  2212. getLast,
  2213. getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
  2214. getNextNonSpaceNonCommentCharacterIndex,
  2215. getNextNonSpaceNonCommentCharacter,
  2216. skip,
  2217. skipWhitespace,
  2218. skipSpaces,
  2219. skipToLineEnd,
  2220. skipEverythingButNewLine,
  2221. skipInlineComment,
  2222. skipTrailingComment,
  2223. skipNewline,
  2224. isNextLineEmptyAfterIndex,
  2225. isNextLineEmpty,
  2226. isPreviousLineEmpty,
  2227. hasNewline,
  2228. hasNewlineInRange,
  2229. hasSpaces,
  2230. getAlignmentSize,
  2231. getIndentSize,
  2232. getPreferredQuote,
  2233. printString,
  2234. printNumber,
  2235. isNodeIgnoreComment,
  2236. makeString,
  2237. addLeadingComment,
  2238. addDanglingComment,
  2239. addTrailingComment,
  2240. isFrontMatterNode,
  2241. getShebang
  2242. };
  2243. function guessEndOfLine(text) {
  2244. const index = text.indexOf("\r");
  2245. if (index >= 0) {
  2246. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  2247. }
  2248. return "lf";
  2249. }
  2250. function convertEndOfLineToChars(value) {
  2251. switch (value) {
  2252. case "cr":
  2253. return "\r";
  2254. case "crlf":
  2255. return "\r\n";
  2256. default:
  2257. return "\n";
  2258. }
  2259. }
  2260. function countEndOfLineChars(text, eol) {
  2261. let regex;
  2262. /* istanbul ignore else */
  2263. if (eol === "\n") {
  2264. regex = /\n/g;
  2265. } else if (eol === "\r") {
  2266. regex = /\r/g;
  2267. } else if (eol === "\r\n") {
  2268. regex = /\r\n/g;
  2269. } else {
  2270. throw new Error("Unexpected \"eol\" ".concat(JSON.stringify(eol), "."));
  2271. }
  2272. const endOfLines = text.match(regex);
  2273. return endOfLines ? endOfLines.length : 0;
  2274. }
  2275. function normalizeEndOfLine(text) {
  2276. return text.replace(/\r\n?/g, "\n");
  2277. }
  2278. var endOfLine = {
  2279. guessEndOfLine,
  2280. convertEndOfLineToChars,
  2281. countEndOfLineChars,
  2282. normalizeEndOfLine
  2283. };
  2284. const {
  2285. getStringWidth: getStringWidth$1
  2286. } = util;
  2287. const {
  2288. convertEndOfLineToChars: convertEndOfLineToChars$1
  2289. } = endOfLine;
  2290. const {
  2291. concat: concat$1,
  2292. fill: fill$1,
  2293. cursor: cursor$1
  2294. } = docBuilders;
  2295. /** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
  2296. let groupModeMap;
  2297. const MODE_BREAK = 1;
  2298. const MODE_FLAT = 2;
  2299. function rootIndent() {
  2300. return {
  2301. value: "",
  2302. length: 0,
  2303. queue: []
  2304. };
  2305. }
  2306. function makeIndent(ind, options) {
  2307. return generateInd(ind, {
  2308. type: "indent"
  2309. }, options);
  2310. }
  2311. function makeAlign(indent, n, options) {
  2312. if (n === -Infinity) {
  2313. return indent.root || rootIndent();
  2314. }
  2315. if (n < 0) {
  2316. return generateInd(indent, {
  2317. type: "dedent"
  2318. }, options);
  2319. }
  2320. if (!n) {
  2321. return indent;
  2322. }
  2323. if (n.type === "root") {
  2324. return Object.assign({}, indent, {
  2325. root: indent
  2326. });
  2327. }
  2328. const alignType = typeof n === "string" ? "stringAlign" : "numberAlign";
  2329. return generateInd(indent, {
  2330. type: alignType,
  2331. n
  2332. }, options);
  2333. }
  2334. function generateInd(ind, newPart, options) {
  2335. const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  2336. let value = "";
  2337. let length = 0;
  2338. let lastTabs = 0;
  2339. let lastSpaces = 0;
  2340. for (const part of queue) {
  2341. switch (part.type) {
  2342. case "indent":
  2343. flush();
  2344. if (options.useTabs) {
  2345. addTabs(1);
  2346. } else {
  2347. addSpaces(options.tabWidth);
  2348. }
  2349. break;
  2350. case "stringAlign":
  2351. flush();
  2352. value += part.n;
  2353. length += part.n.length;
  2354. break;
  2355. case "numberAlign":
  2356. lastTabs += 1;
  2357. lastSpaces += part.n;
  2358. break;
  2359. /* istanbul ignore next */
  2360. default:
  2361. throw new Error("Unexpected type '".concat(part.type, "'"));
  2362. }
  2363. }
  2364. flushSpaces();
  2365. return Object.assign({}, ind, {
  2366. value,
  2367. length,
  2368. queue
  2369. });
  2370. function addTabs(count) {
  2371. value += "\t".repeat(count);
  2372. length += options.tabWidth * count;
  2373. }
  2374. function addSpaces(count) {
  2375. value += " ".repeat(count);
  2376. length += count;
  2377. }
  2378. function flush() {
  2379. if (options.useTabs) {
  2380. flushTabs();
  2381. } else {
  2382. flushSpaces();
  2383. }
  2384. }
  2385. function flushTabs() {
  2386. if (lastTabs > 0) {
  2387. addTabs(lastTabs);
  2388. }
  2389. resetLast();
  2390. }
  2391. function flushSpaces() {
  2392. if (lastSpaces > 0) {
  2393. addSpaces(lastSpaces);
  2394. }
  2395. resetLast();
  2396. }
  2397. function resetLast() {
  2398. lastTabs = 0;
  2399. lastSpaces = 0;
  2400. }
  2401. }
  2402. function trim$1(out) {
  2403. if (out.length === 0) {
  2404. return 0;
  2405. }
  2406. let trimCount = 0; // Trim whitespace at the end of line
  2407. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[\t ]*$/)) {
  2408. trimCount += out.pop().length;
  2409. }
  2410. if (out.length && typeof out[out.length - 1] === "string") {
  2411. const trimmed = out[out.length - 1].replace(/[\t ]*$/, "");
  2412. trimCount += out[out.length - 1].length - trimmed.length;
  2413. out[out.length - 1] = trimmed;
  2414. }
  2415. return trimCount;
  2416. }
  2417. function fits(next, restCommands, width, options, mustBeFlat) {
  2418. let restIdx = restCommands.length;
  2419. const cmds = [next]; // `out` is only used for width counting because `trim` requires to look
  2420. // backwards for space characters.
  2421. const out = [];
  2422. while (width >= 0) {
  2423. if (cmds.length === 0) {
  2424. if (restIdx === 0) {
  2425. return true;
  2426. }
  2427. cmds.push(restCommands[restIdx - 1]);
  2428. restIdx--;
  2429. continue;
  2430. }
  2431. const [ind, mode, doc] = cmds.pop();
  2432. if (typeof doc === "string") {
  2433. out.push(doc);
  2434. width -= getStringWidth$1(doc);
  2435. } else {
  2436. switch (doc.type) {
  2437. case "concat":
  2438. for (let i = doc.parts.length - 1; i >= 0; i--) {
  2439. cmds.push([ind, mode, doc.parts[i]]);
  2440. }
  2441. break;
  2442. case "indent":
  2443. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  2444. break;
  2445. case "align":
  2446. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  2447. break;
  2448. case "trim":
  2449. width += trim$1(out);
  2450. break;
  2451. case "group":
  2452. if (mustBeFlat && doc.break) {
  2453. return false;
  2454. }
  2455. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  2456. if (doc.id) {
  2457. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  2458. }
  2459. break;
  2460. case "fill":
  2461. for (let i = doc.parts.length - 1; i >= 0; i--) {
  2462. cmds.push([ind, mode, doc.parts[i]]);
  2463. }
  2464. break;
  2465. case "if-break":
  2466. {
  2467. const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  2468. if (groupMode === MODE_BREAK) {
  2469. if (doc.breakContents) {
  2470. cmds.push([ind, mode, doc.breakContents]);
  2471. }
  2472. }
  2473. if (groupMode === MODE_FLAT) {
  2474. if (doc.flatContents) {
  2475. cmds.push([ind, mode, doc.flatContents]);
  2476. }
  2477. }
  2478. break;
  2479. }
  2480. case "line":
  2481. switch (mode) {
  2482. // fallthrough
  2483. case MODE_FLAT:
  2484. if (!doc.hard) {
  2485. if (!doc.soft) {
  2486. out.push(" ");
  2487. width -= 1;
  2488. }
  2489. break;
  2490. }
  2491. return true;
  2492. case MODE_BREAK:
  2493. return true;
  2494. }
  2495. break;
  2496. }
  2497. }
  2498. }
  2499. return false;
  2500. }
  2501. function printDocToString(doc, options) {
  2502. groupModeMap = {};
  2503. const width = options.printWidth;
  2504. const newLine = convertEndOfLineToChars$1(options.endOfLine);
  2505. let pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  2506. // while loop which is much faster. The while loop below adds new
  2507. // cmds to the array instead of recursively calling `print`.
  2508. const cmds = [[rootIndent(), MODE_BREAK, doc]];
  2509. const out = [];
  2510. let shouldRemeasure = false;
  2511. let lineSuffix = [];
  2512. while (cmds.length !== 0) {
  2513. const [ind, mode, doc] = cmds.pop();
  2514. if (typeof doc === "string") {
  2515. const formatted = newLine !== "\n" && doc.includes("\n") ? doc.replace(/\n/g, newLine) : doc;
  2516. out.push(formatted);
  2517. pos += getStringWidth$1(formatted);
  2518. } else {
  2519. switch (doc.type) {
  2520. case "cursor":
  2521. out.push(cursor$1.placeholder);
  2522. break;
  2523. case "concat":
  2524. for (let i = doc.parts.length - 1; i >= 0; i--) {
  2525. cmds.push([ind, mode, doc.parts[i]]);
  2526. }
  2527. break;
  2528. case "indent":
  2529. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  2530. break;
  2531. case "align":
  2532. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  2533. break;
  2534. case "trim":
  2535. pos -= trim$1(out);
  2536. break;
  2537. case "group":
  2538. switch (mode) {
  2539. case MODE_FLAT:
  2540. if (!shouldRemeasure) {
  2541. cmds.push([ind, doc.break ? MODE_BREAK : MODE_FLAT, doc.contents]);
  2542. break;
  2543. }
  2544. // fallthrough
  2545. case MODE_BREAK:
  2546. {
  2547. shouldRemeasure = false;
  2548. const next = [ind, MODE_FLAT, doc.contents];
  2549. const rem = width - pos;
  2550. if (!doc.break && fits(next, cmds, rem, options)) {
  2551. cmds.push(next);
  2552. } else {
  2553. // Expanded states are a rare case where a document
  2554. // can manually provide multiple representations of
  2555. // itself. It provides an array of documents
  2556. // going from the least expanded (most flattened)
  2557. // representation first to the most expanded. If a
  2558. // group has these, we need to manually go through
  2559. // these states and find the first one that fits.
  2560. if (doc.expandedStates) {
  2561. const mostExpanded = doc.expandedStates[doc.expandedStates.length - 1];
  2562. if (doc.break) {
  2563. cmds.push([ind, MODE_BREAK, mostExpanded]);
  2564. break;
  2565. } else {
  2566. for (let i = 1; i < doc.expandedStates.length + 1; i++) {
  2567. if (i >= doc.expandedStates.length) {
  2568. cmds.push([ind, MODE_BREAK, mostExpanded]);
  2569. break;
  2570. } else {
  2571. const state = doc.expandedStates[i];
  2572. const cmd = [ind, MODE_FLAT, state];
  2573. if (fits(cmd, cmds, rem, options)) {
  2574. cmds.push(cmd);
  2575. break;
  2576. }
  2577. }
  2578. }
  2579. }
  2580. } else {
  2581. cmds.push([ind, MODE_BREAK, doc.contents]);
  2582. }
  2583. }
  2584. break;
  2585. }
  2586. }
  2587. if (doc.id) {
  2588. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  2589. }
  2590. break;
  2591. // Fills each line with as much code as possible before moving to a new
  2592. // line with the same indentation.
  2593. //
  2594. // Expects doc.parts to be an array of alternating content and
  2595. // whitespace. The whitespace contains the linebreaks.
  2596. //
  2597. // For example:
  2598. // ["I", line, "love", line, "monkeys"]
  2599. // or
  2600. // [{ type: group, ... }, softline, { type: group, ... }]
  2601. //
  2602. // It uses this parts structure to handle three main layout cases:
  2603. // * The first two content items fit on the same line without
  2604. // breaking
  2605. // -> output the first content item and the whitespace "flat".
  2606. // * Only the first content item fits on the line without breaking
  2607. // -> output the first content item "flat" and the whitespace with
  2608. // "break".
  2609. // * Neither content item fits on the line without breaking
  2610. // -> output the first content item and the whitespace with "break".
  2611. case "fill":
  2612. {
  2613. const rem = width - pos;
  2614. const {
  2615. parts
  2616. } = doc;
  2617. if (parts.length === 0) {
  2618. break;
  2619. }
  2620. const [content, whitespace] = parts;
  2621. const contentFlatCmd = [ind, MODE_FLAT, content];
  2622. const contentBreakCmd = [ind, MODE_BREAK, content];
  2623. const contentFits = fits(contentFlatCmd, [], rem, options, true);
  2624. if (parts.length === 1) {
  2625. if (contentFits) {
  2626. cmds.push(contentFlatCmd);
  2627. } else {
  2628. cmds.push(contentBreakCmd);
  2629. }
  2630. break;
  2631. }
  2632. const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  2633. const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  2634. if (parts.length === 2) {
  2635. if (contentFits) {
  2636. cmds.push(whitespaceFlatCmd);
  2637. cmds.push(contentFlatCmd);
  2638. } else {
  2639. cmds.push(whitespaceBreakCmd);
  2640. cmds.push(contentBreakCmd);
  2641. }
  2642. break;
  2643. } // At this point we've handled the first pair (context, separator)
  2644. // and will create a new fill doc for the rest of the content.
  2645. // Ideally we wouldn't mutate the array here but copying all the
  2646. // elements to a new array would make this algorithm quadratic,
  2647. // which is unusable for large arrays (e.g. large texts in JSX).
  2648. parts.splice(0, 2);
  2649. const remainingCmd = [ind, mode, fill$1(parts)];
  2650. const secondContent = parts[0];
  2651. const firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$1([content, whitespace, secondContent])];
  2652. const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, options, true);
  2653. if (firstAndSecondContentFits) {
  2654. cmds.push(remainingCmd);
  2655. cmds.push(whitespaceFlatCmd);
  2656. cmds.push(contentFlatCmd);
  2657. } else if (contentFits) {
  2658. cmds.push(remainingCmd);
  2659. cmds.push(whitespaceBreakCmd);
  2660. cmds.push(contentFlatCmd);
  2661. } else {
  2662. cmds.push(remainingCmd);
  2663. cmds.push(whitespaceBreakCmd);
  2664. cmds.push(contentBreakCmd);
  2665. }
  2666. break;
  2667. }
  2668. case "if-break":
  2669. {
  2670. const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  2671. if (groupMode === MODE_BREAK) {
  2672. if (doc.breakContents) {
  2673. cmds.push([ind, mode, doc.breakContents]);
  2674. }
  2675. }
  2676. if (groupMode === MODE_FLAT) {
  2677. if (doc.flatContents) {
  2678. cmds.push([ind, mode, doc.flatContents]);
  2679. }
  2680. }
  2681. break;
  2682. }
  2683. case "line-suffix":
  2684. lineSuffix.push([ind, mode, doc.contents]);
  2685. break;
  2686. case "line-suffix-boundary":
  2687. if (lineSuffix.length > 0) {
  2688. cmds.push([ind, mode, {
  2689. type: "line",
  2690. hard: true
  2691. }]);
  2692. }
  2693. break;
  2694. case "line":
  2695. switch (mode) {
  2696. case MODE_FLAT:
  2697. if (!doc.hard) {
  2698. if (!doc.soft) {
  2699. out.push(" ");
  2700. pos += 1;
  2701. }
  2702. break;
  2703. } else {
  2704. // This line was forced into the output even if we
  2705. // were in flattened mode, so we need to tell the next
  2706. // group that no matter what, it needs to remeasure
  2707. // because the previous measurement didn't accurately
  2708. // capture the entire expression (this is necessary
  2709. // for nested groups)
  2710. shouldRemeasure = true;
  2711. }
  2712. // fallthrough
  2713. case MODE_BREAK:
  2714. if (lineSuffix.length) {
  2715. cmds.push([ind, mode, doc]);
  2716. cmds.push(...lineSuffix.reverse());
  2717. lineSuffix = [];
  2718. break;
  2719. }
  2720. if (doc.literal) {
  2721. if (ind.root) {
  2722. out.push(newLine, ind.root.value);
  2723. pos = ind.root.length;
  2724. } else {
  2725. out.push(newLine);
  2726. pos = 0;
  2727. }
  2728. } else {
  2729. pos -= trim$1(out);
  2730. out.push(newLine + ind.value);
  2731. pos = ind.length;
  2732. }
  2733. break;
  2734. }
  2735. break;
  2736. }
  2737. } // Flush remaining line-suffix contents at the end of the document, in case
  2738. // there is no new line after the line-suffix.
  2739. if (cmds.length === 0 && lineSuffix.length) {
  2740. cmds.push(...lineSuffix.reverse());
  2741. lineSuffix = [];
  2742. }
  2743. }
  2744. const cursorPlaceholderIndex = out.indexOf(cursor$1.placeholder);
  2745. if (cursorPlaceholderIndex !== -1) {
  2746. const otherCursorPlaceholderIndex = out.indexOf(cursor$1.placeholder, cursorPlaceholderIndex + 1);
  2747. const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  2748. const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  2749. const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  2750. return {
  2751. formatted: beforeCursor + aroundCursor + afterCursor,
  2752. cursorNodeStart: beforeCursor.length,
  2753. cursorNodeText: aroundCursor
  2754. };
  2755. }
  2756. return {
  2757. formatted: out.join("")
  2758. };
  2759. }
  2760. var docPrinter = {
  2761. printDocToString
  2762. };
  2763. const {
  2764. literalline: literalline$1,
  2765. concat: concat$2
  2766. } = docBuilders; // Using a unique object to compare by reference.
  2767. const traverseDocOnExitStackMarker = {};
  2768. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  2769. const docsStack = [doc];
  2770. while (docsStack.length !== 0) {
  2771. const doc = docsStack.pop();
  2772. if (doc === traverseDocOnExitStackMarker) {
  2773. onExit(docsStack.pop());
  2774. continue;
  2775. }
  2776. if (onExit) {
  2777. docsStack.push(doc, traverseDocOnExitStackMarker);
  2778. }
  2779. if ( // Should Recurse
  2780. !onEnter || onEnter(doc) !== false) {
  2781. // When there are multiple parts to process,
  2782. // the parts need to be pushed onto the stack in reverse order,
  2783. // so that they are processed in the original order
  2784. // when the stack is popped.
  2785. if (doc.type === "concat" || doc.type === "fill") {
  2786. for (let ic = doc.parts.length, i = ic - 1; i >= 0; --i) {
  2787. docsStack.push(doc.parts[i]);
  2788. }
  2789. } else if (doc.type === "if-break") {
  2790. if (doc.flatContents) {
  2791. docsStack.push(doc.flatContents);
  2792. }
  2793. if (doc.breakContents) {
  2794. docsStack.push(doc.breakContents);
  2795. }
  2796. } else if (doc.type === "group" && doc.expandedStates) {
  2797. if (shouldTraverseConditionalGroups) {
  2798. for (let ic = doc.expandedStates.length, i = ic - 1; i >= 0; --i) {
  2799. docsStack.push(doc.expandedStates[i]);
  2800. }
  2801. } else {
  2802. docsStack.push(doc.contents);
  2803. }
  2804. } else if (doc.contents) {
  2805. docsStack.push(doc.contents);
  2806. }
  2807. }
  2808. }
  2809. }
  2810. function mapDoc(doc, cb) {
  2811. if (doc.type === "concat" || doc.type === "fill") {
  2812. const parts = doc.parts.map(part => mapDoc(part, cb));
  2813. return cb(Object.assign({}, doc, {
  2814. parts
  2815. }));
  2816. } else if (doc.type === "if-break") {
  2817. const breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  2818. const flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  2819. return cb(Object.assign({}, doc, {
  2820. breakContents,
  2821. flatContents
  2822. }));
  2823. } else if (doc.contents) {
  2824. const contents = mapDoc(doc.contents, cb);
  2825. return cb(Object.assign({}, doc, {
  2826. contents
  2827. }));
  2828. }
  2829. return cb(doc);
  2830. }
  2831. function findInDoc(doc, fn, defaultValue) {
  2832. let result = defaultValue;
  2833. let hasStopped = false;
  2834. function findInDocOnEnterFn(doc) {
  2835. const maybeResult = fn(doc);
  2836. if (maybeResult !== undefined) {
  2837. hasStopped = true;
  2838. result = maybeResult;
  2839. }
  2840. if (hasStopped) {
  2841. return false;
  2842. }
  2843. }
  2844. traverseDoc(doc, findInDocOnEnterFn);
  2845. return result;
  2846. }
  2847. function isEmpty(n) {
  2848. return typeof n === "string" && n.length === 0;
  2849. }
  2850. function isLineNextFn(doc) {
  2851. if (typeof doc === "string") {
  2852. return false;
  2853. }
  2854. if (doc.type === "line") {
  2855. return true;
  2856. }
  2857. }
  2858. function isLineNext(doc) {
  2859. return findInDoc(doc, isLineNextFn, false);
  2860. }
  2861. function willBreakFn(doc) {
  2862. if (doc.type === "group" && doc.break) {
  2863. return true;
  2864. }
  2865. if (doc.type === "line" && doc.hard) {
  2866. return true;
  2867. }
  2868. if (doc.type === "break-parent") {
  2869. return true;
  2870. }
  2871. }
  2872. function willBreak(doc) {
  2873. return findInDoc(doc, willBreakFn, false);
  2874. }
  2875. function breakParentGroup(groupStack) {
  2876. if (groupStack.length > 0) {
  2877. const parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  2878. // the user is expected to manually handle what breaks.
  2879. if (!parentGroup.expandedStates) {
  2880. parentGroup.break = true;
  2881. }
  2882. }
  2883. return null;
  2884. }
  2885. function propagateBreaks(doc) {
  2886. const alreadyVisitedSet = new Set();
  2887. const groupStack = [];
  2888. function propagateBreaksOnEnterFn(doc) {
  2889. if (doc.type === "break-parent") {
  2890. breakParentGroup(groupStack);
  2891. }
  2892. if (doc.type === "group") {
  2893. groupStack.push(doc);
  2894. if (alreadyVisitedSet.has(doc)) {
  2895. return false;
  2896. }
  2897. alreadyVisitedSet.add(doc);
  2898. }
  2899. }
  2900. function propagateBreaksOnExitFn(doc) {
  2901. if (doc.type === "group") {
  2902. const group = groupStack.pop();
  2903. if (group.break) {
  2904. breakParentGroup(groupStack);
  2905. }
  2906. }
  2907. }
  2908. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
  2909. /* shouldTraverseConditionalGroups */
  2910. true);
  2911. }
  2912. function removeLinesFn(doc) {
  2913. // Force this doc into flat mode by statically converting all
  2914. // lines into spaces (or soft lines into nothing). Hard lines
  2915. // should still output because there's too great of a chance
  2916. // of breaking existing assumptions otherwise.
  2917. if (doc.type === "line" && !doc.hard) {
  2918. return doc.soft ? "" : " ";
  2919. } else if (doc.type === "if-break") {
  2920. return doc.flatContents || "";
  2921. }
  2922. return doc;
  2923. }
  2924. function removeLines(doc) {
  2925. return mapDoc(doc, removeLinesFn);
  2926. }
  2927. function getInnerParts(doc) {
  2928. let {
  2929. parts
  2930. } = doc;
  2931. let lastPart; // Avoid a falsy element like ""
  2932. for (let i = doc.parts.length; i > 0 && !lastPart; i--) {
  2933. lastPart = parts[i - 1];
  2934. }
  2935. if (lastPart.type === "group") {
  2936. parts = lastPart.contents.parts;
  2937. }
  2938. return parts;
  2939. }
  2940. function stripTrailingHardline(doc, withInnerParts = false) {
  2941. // HACK remove ending hardline, original PR: #1984
  2942. if (doc.type === "concat" && doc.parts.length !== 0) {
  2943. const parts = withInnerParts ? getInnerParts(doc) : doc.parts;
  2944. const lastPart = parts[parts.length - 1];
  2945. if (lastPart.type === "concat") {
  2946. if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
  2947. return {
  2948. type: "concat",
  2949. parts: parts.slice(0, -1)
  2950. };
  2951. }
  2952. return {
  2953. type: "concat",
  2954. parts: doc.parts.slice(0, -1).concat(stripTrailingHardline(lastPart))
  2955. };
  2956. }
  2957. }
  2958. return doc;
  2959. }
  2960. function normalizeParts(parts) {
  2961. const newParts = [];
  2962. const restParts = parts.filter(Boolean);
  2963. while (restParts.length !== 0) {
  2964. const part = restParts.shift();
  2965. if (!part) {
  2966. continue;
  2967. }
  2968. if (part.type === "concat") {
  2969. restParts.unshift(...part.parts);
  2970. continue;
  2971. }
  2972. if (newParts.length !== 0 && typeof newParts[newParts.length - 1] === "string" && typeof part === "string") {
  2973. newParts[newParts.length - 1] += part;
  2974. continue;
  2975. }
  2976. newParts.push(part);
  2977. }
  2978. return newParts;
  2979. }
  2980. function normalizeDoc(doc) {
  2981. return mapDoc(doc, currentDoc => {
  2982. if (!currentDoc.parts) {
  2983. return currentDoc;
  2984. }
  2985. return Object.assign({}, currentDoc, {
  2986. parts: normalizeParts(currentDoc.parts)
  2987. });
  2988. });
  2989. }
  2990. function replaceNewlinesWithLiterallines(doc) {
  2991. return mapDoc(doc, currentDoc => typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$2(currentDoc.split(/(\n)/g).map((v, i) => i % 2 === 0 ? v : literalline$1)) : currentDoc);
  2992. }
  2993. var docUtils = {
  2994. isEmpty,
  2995. willBreak,
  2996. isLineNext,
  2997. traverseDoc,
  2998. findInDoc,
  2999. mapDoc,
  3000. propagateBreaks,
  3001. removeLines,
  3002. stripTrailingHardline,
  3003. normalizeParts,
  3004. normalizeDoc,
  3005. replaceNewlinesWithLiterallines
  3006. };
  3007. function flattenDoc(doc) {
  3008. if (doc.type === "concat") {
  3009. const res = [];
  3010. for (let i = 0; i < doc.parts.length; ++i) {
  3011. const doc2 = doc.parts[i];
  3012. if (typeof doc2 !== "string" && doc2.type === "concat") {
  3013. res.push(...flattenDoc(doc2).parts);
  3014. } else {
  3015. const flattened = flattenDoc(doc2);
  3016. if (flattened !== "") {
  3017. res.push(flattened);
  3018. }
  3019. }
  3020. }
  3021. return Object.assign({}, doc, {
  3022. parts: res
  3023. });
  3024. } else if (doc.type === "if-break") {
  3025. return Object.assign({}, doc, {
  3026. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  3027. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  3028. });
  3029. } else if (doc.type === "group") {
  3030. return Object.assign({}, doc, {
  3031. contents: flattenDoc(doc.contents),
  3032. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  3033. });
  3034. } else if (doc.contents) {
  3035. return Object.assign({}, doc, {
  3036. contents: flattenDoc(doc.contents)
  3037. });
  3038. }
  3039. return doc;
  3040. }
  3041. function printDoc(doc) {
  3042. if (typeof doc === "string") {
  3043. return JSON.stringify(doc);
  3044. }
  3045. if (doc.type === "line") {
  3046. if (doc.literal) {
  3047. return "literalline";
  3048. }
  3049. if (doc.hard) {
  3050. return "hardline";
  3051. }
  3052. if (doc.soft) {
  3053. return "softline";
  3054. }
  3055. return "line";
  3056. }
  3057. if (doc.type === "break-parent") {
  3058. return "breakParent";
  3059. }
  3060. if (doc.type === "trim") {
  3061. return "trim";
  3062. }
  3063. if (doc.type === "concat") {
  3064. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  3065. }
  3066. if (doc.type === "indent") {
  3067. return "indent(" + printDoc(doc.contents) + ")";
  3068. }
  3069. if (doc.type === "align") {
  3070. 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) + ")";
  3071. }
  3072. if (doc.type === "if-break") {
  3073. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  3074. }
  3075. if (doc.type === "group") {
  3076. if (doc.expandedStates) {
  3077. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  3078. }
  3079. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  3080. }
  3081. if (doc.type === "fill") {
  3082. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  3083. }
  3084. if (doc.type === "line-suffix") {
  3085. return "lineSuffix(" + printDoc(doc.contents) + ")";
  3086. }
  3087. if (doc.type === "line-suffix-boundary") {
  3088. return "lineSuffixBoundary";
  3089. }
  3090. throw new Error("Unknown doc type " + doc.type);
  3091. }
  3092. var docDebug = {
  3093. printDocToDebug(doc) {
  3094. return printDoc(flattenDoc(doc));
  3095. }
  3096. };
  3097. /**
  3098. * @typedef {import("./doc-builders").Doc} Doc
  3099. */
  3100. var document = {
  3101. builders: docBuilders,
  3102. printer: docPrinter,
  3103. utils: docUtils,
  3104. debug: docDebug
  3105. };
  3106. return document;
  3107. })));