doc.js 115 KB

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