.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / prettier-stylelint / node_modules / prettier / doc.js
1 (function (global, factory) {
2   typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3   typeof define === 'function' && define.amd ? define(['exports'], factory) :
4   (global = global || self, factory(global.doc = {}));
5 }(this, (function (exports) { 'use strict';
6
7   /**
8    * @param {Doc[]} parts
9    * @returns Doc
10    */
11
12
13   function concat(parts) {
14     // access the internals of a document directly.
15     // if(parts.length === 1) {
16     //   // If it's a single document, no need to concat it.
17     //   return parts[0];
18     // }
19
20
21     return {
22       type: "concat",
23       parts: parts
24     };
25   }
26   /**
27    * @param {Doc} contents
28    * @returns Doc
29    */
30
31
32   function indent(contents) {
33
34     return {
35       type: "indent",
36       contents: contents
37     };
38   }
39   /**
40    * @param {number} n
41    * @param {Doc} contents
42    * @returns Doc
43    */
44
45
46   function align(n, contents) {
47
48     return {
49       type: "align",
50       contents: contents,
51       n: n
52     };
53   }
54   /**
55    * @param {Doc} contents
56    * @param {object} [opts] - TBD ???
57    * @returns Doc
58    */
59
60
61   function group(contents, opts) {
62     opts = opts || {};
63
64     return {
65       type: "group",
66       id: opts.id,
67       contents: contents,
68       break: !!opts.shouldBreak,
69       expandedStates: opts.expandedStates
70     };
71   }
72   /**
73    * @param {Doc} contents
74    * @returns Doc
75    */
76
77
78   function dedentToRoot(contents) {
79     return align(-Infinity, contents);
80   }
81   /**
82    * @param {Doc} contents
83    * @returns Doc
84    */
85
86
87   function markAsRoot(contents) {
88     // @ts-ignore - TBD ???:
89     return align({
90       type: "root"
91     }, contents);
92   }
93   /**
94    * @param {Doc} contents
95    * @returns Doc
96    */
97
98
99   function dedent(contents) {
100     return align(-1, contents);
101   }
102   /**
103    * @param {Doc[]} states
104    * @param {object} [opts] - TBD ???
105    * @returns Doc
106    */
107
108
109   function conditionalGroup(states, opts) {
110     return group(states[0], Object.assign(opts || {}, {
111       expandedStates: states
112     }));
113   }
114   /**
115    * @param {Doc[]} parts
116    * @returns Doc
117    */
118
119
120   function fill(parts) {
121
122     return {
123       type: "fill",
124       parts: parts
125     };
126   }
127   /**
128    * @param {Doc} [breakContents]
129    * @param {Doc} [flatContents]
130    * @param {object} [opts] - TBD ???
131    * @returns Doc
132    */
133
134
135   function ifBreak(breakContents, flatContents, opts) {
136     opts = opts || {};
137
138     return {
139       type: "if-break",
140       breakContents: breakContents,
141       flatContents: flatContents,
142       groupId: opts.groupId
143     };
144   }
145   /**
146    * @param {Doc} contents
147    * @returns Doc
148    */
149
150
151   function lineSuffix(contents) {
152
153     return {
154       type: "line-suffix",
155       contents: contents
156     };
157   }
158
159   var lineSuffixBoundary = {
160     type: "line-suffix-boundary"
161   };
162   var breakParent = {
163     type: "break-parent"
164   };
165   var trim = {
166     type: "trim"
167   };
168   var line = {
169     type: "line"
170   };
171   var softline = {
172     type: "line",
173     soft: true
174   };
175   var hardline = concat([{
176     type: "line",
177     hard: true
178   }, breakParent]);
179   var literalline = concat([{
180     type: "line",
181     hard: true,
182     literal: true
183   }, breakParent]);
184   var cursor = {
185     type: "cursor",
186     placeholder: Symbol("cursor")
187   };
188   /**
189    * @param {Doc} sep
190    * @param {Doc[]} arr
191    * @returns Doc
192    */
193
194   function join(sep, arr) {
195     var res = [];
196
197     for (var i = 0; i < arr.length; i++) {
198       if (i !== 0) {
199         res.push(sep);
200       }
201
202       res.push(arr[i]);
203     }
204
205     return concat(res);
206   }
207   /**
208    * @param {Doc} doc
209    * @param {number} size
210    * @param {number} tabWidth
211    */
212
213
214   function addAlignmentToDoc(doc, size, tabWidth) {
215     var aligned = doc;
216
217     if (size > 0) {
218       // Use indent to add tabs for all the levels of tabs we need
219       for (var i = 0; i < Math.floor(size / tabWidth); ++i) {
220         aligned = indent(aligned);
221       } // Use align for all the spaces that are needed
222
223
224       aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
225       // indentation, so we use -Infinity to reset the indentation to 0
226
227       aligned = align(-Infinity, aligned);
228     }
229
230     return aligned;
231   }
232
233   var docBuilders = {
234     concat: concat,
235     join: join,
236     line: line,
237     softline: softline,
238     hardline: hardline,
239     literalline: literalline,
240     group: group,
241     conditionalGroup: conditionalGroup,
242     fill: fill,
243     lineSuffix: lineSuffix,
244     lineSuffixBoundary: lineSuffixBoundary,
245     cursor: cursor,
246     breakParent: breakParent,
247     ifBreak: ifBreak,
248     trim: trim,
249     indent: indent,
250     align: align,
251     addAlignmentToDoc: addAlignmentToDoc,
252     markAsRoot: markAsRoot,
253     dedentToRoot: dedentToRoot,
254     dedent: dedent
255   };
256
257   var ansiRegex = function ansiRegex(options) {
258     options = Object.assign({
259       onlyFirst: false
260     }, options);
261     var pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
262     return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
263   };
264
265   var stripAnsi = function stripAnsi(string) {
266     return typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
267   };
268
269   var stripAnsi_1 = stripAnsi;
270   var default_1 = stripAnsi;
271   stripAnsi_1.default = default_1;
272
273   /* eslint-disable yoda */
274
275   var isFullwidthCodePoint = function isFullwidthCodePoint(codePoint) {
276     if (Number.isNaN(codePoint)) {
277       return false;
278     } // Code points are derived from:
279     // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
280
281
282     if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo
283     codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
284     codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
285     // CJK Radicals Supplement .. Enclosed CJK Letters and Months
286     0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
287     0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals
288     0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A
289     0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables
290     0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs
291     0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms
292     0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants
293     0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms
294     0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement
295     0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement
296     0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
297     0x20000 <= codePoint && codePoint <= 0x3FFFD)) {
298       return true;
299     }
300
301     return false;
302   };
303
304   var isFullwidthCodePoint_1 = isFullwidthCodePoint;
305   var default_1$1 = isFullwidthCodePoint;
306   isFullwidthCodePoint_1.default = default_1$1;
307
308   var emojiRegex = function emojiRegex() {
309     // https://mths.be/emoji
310     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;
311   };
312
313   var stringWidth = function stringWidth(string) {
314     string = string.replace(emojiRegex(), '  ');
315
316     if (typeof string !== 'string' || string.length === 0) {
317       return 0;
318     }
319
320     string = stripAnsi_1(string);
321     var width = 0;
322
323     for (var i = 0; i < string.length; i++) {
324       var code = string.codePointAt(i); // Ignore control characters
325
326       if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
327         continue;
328       } // Ignore combining characters
329
330
331       if (code >= 0x300 && code <= 0x36F) {
332         continue;
333       } // Surrogates
334
335
336       if (code > 0xFFFF) {
337         i++;
338       }
339
340       width += isFullwidthCodePoint_1(code) ? 2 : 1;
341     }
342
343     return width;
344   };
345
346   var stringWidth_1 = stringWidth; // TODO: remove this in the next major version
347
348   var default_1$2 = stringWidth;
349   stringWidth_1.default = default_1$2;
350
351   var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
352
353   var escapeStringRegexp = function escapeStringRegexp(str) {
354     if (typeof str !== 'string') {
355       throw new TypeError('Expected a string');
356     }
357
358     return str.replace(matchOperatorsRe, '\\$&');
359   };
360
361   var getLast = function getLast(arr) {
362     return arr.length > 0 ? arr[arr.length - 1] : null;
363   };
364
365   var notAsciiRegex = /[^\x20-\x7F]/;
366
367   function isExportDeclaration(node) {
368     if (node) {
369       switch (node.type) {
370         case "ExportDefaultDeclaration":
371         case "ExportDefaultSpecifier":
372         case "DeclareExportDeclaration":
373         case "ExportNamedDeclaration":
374         case "ExportAllDeclaration":
375           return true;
376       }
377     }
378
379     return false;
380   }
381
382   function getParentExportDeclaration(path) {
383     var parentNode = path.getParentNode();
384
385     if (path.getName() === "declaration" && isExportDeclaration(parentNode)) {
386       return parentNode;
387     }
388
389     return null;
390   }
391
392   function getPenultimate(arr) {
393     if (arr.length > 1) {
394       return arr[arr.length - 2];
395     }
396
397     return null;
398   }
399   /**
400    * @typedef {{backwards?: boolean}} SkipOptions
401    */
402
403   /**
404    * @param {string | RegExp} chars
405    * @returns {(text: string, index: number | false, opts?: SkipOptions) => number | false}
406    */
407
408
409   function skip(chars) {
410     return function (text, index, opts) {
411       var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
412       // to check for failures (did someone say monads?).
413
414       if (index === false) {
415         return false;
416       }
417
418       var length = text.length;
419       var cursor = index;
420
421       while (cursor >= 0 && cursor < length) {
422         var c = text.charAt(cursor);
423
424         if (chars instanceof RegExp) {
425           if (!chars.test(c)) {
426             return cursor;
427           }
428         } else if (chars.indexOf(c) === -1) {
429           return cursor;
430         }
431
432         backwards ? cursor-- : cursor++;
433       }
434
435       if (cursor === -1 || cursor === length) {
436         // If we reached the beginning or end of the file, return the
437         // out-of-bounds cursor. It's up to the caller to handle this
438         // correctly. We don't want to indicate `false` though if it
439         // actually skipped valid characters.
440         return cursor;
441       }
442
443       return false;
444     };
445   }
446   /**
447    * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
448    */
449
450
451   var skipWhitespace = skip(/\s/);
452   /**
453    * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
454    */
455
456   var skipSpaces = skip(" \t");
457   /**
458    * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
459    */
460
461   var skipToLineEnd = skip(",; \t");
462   /**
463    * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
464    */
465
466   var skipEverythingButNewLine = skip(/[^\r\n]/);
467   /**
468    * @param {string} text
469    * @param {number | false} index
470    * @returns {number | false}
471    */
472
473   function skipInlineComment(text, index) {
474     if (index === false) {
475       return false;
476     }
477
478     if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
479       for (var i = index + 2; i < text.length; ++i) {
480         if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
481           return i + 2;
482         }
483       }
484     }
485
486     return index;
487   }
488   /**
489    * @param {string} text
490    * @param {number | false} index
491    * @returns {number | false}
492    */
493
494
495   function skipTrailingComment(text, index) {
496     if (index === false) {
497       return false;
498     }
499
500     if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
501       return skipEverythingButNewLine(text, index);
502     }
503
504     return index;
505   } // This one doesn't use the above helper function because it wants to
506   // test \r\n in order and `skip` doesn't support ordering and we only
507   // want to skip one newline. It's simple to implement.
508
509   /**
510    * @param {string} text
511    * @param {number | false} index
512    * @param {SkipOptions=} opts
513    * @returns {number | false}
514    */
515
516
517   function skipNewline(text, index, opts) {
518     var backwards = opts && opts.backwards;
519
520     if (index === false) {
521       return false;
522     }
523
524     var atIndex = text.charAt(index);
525
526     if (backwards) {
527       if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
528         return index - 2;
529       }
530
531       if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
532         return index - 1;
533       }
534     } else {
535       if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
536         return index + 2;
537       }
538
539       if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
540         return index + 1;
541       }
542     }
543
544     return index;
545   }
546   /**
547    * @param {string} text
548    * @param {number} index
549    * @param {SkipOptions=} opts
550    * @returns {boolean}
551    */
552
553
554   function hasNewline(text, index, opts) {
555     opts = opts || {};
556     var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
557     var idx2 = skipNewline(text, idx, opts);
558     return idx !== idx2;
559   }
560   /**
561    * @param {string} text
562    * @param {number} start
563    * @param {number} end
564    * @returns {boolean}
565    */
566
567
568   function hasNewlineInRange(text, start, end) {
569     for (var i = start; i < end; ++i) {
570       if (text.charAt(i) === "\n") {
571         return true;
572       }
573     }
574
575     return false;
576   } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
577
578   /**
579    * @template N
580    * @param {string} text
581    * @param {N} node
582    * @param {(node: N) => number} locStart
583    */
584
585
586   function isPreviousLineEmpty(text, node, locStart) {
587     /** @type {number | false} */
588     var idx = locStart(node) - 1;
589     idx = skipSpaces(text, idx, {
590       backwards: true
591     });
592     idx = skipNewline(text, idx, {
593       backwards: true
594     });
595     idx = skipSpaces(text, idx, {
596       backwards: true
597     });
598     var idx2 = skipNewline(text, idx, {
599       backwards: true
600     });
601     return idx !== idx2;
602   }
603   /**
604    * @param {string} text
605    * @param {number} index
606    * @returns {boolean}
607    */
608
609
610   function isNextLineEmptyAfterIndex(text, index) {
611     /** @type {number | false} */
612     var oldIdx = null;
613     /** @type {number | false} */
614
615     var idx = index;
616
617     while (idx !== oldIdx) {
618       // We need to skip all the potential trailing inline comments
619       oldIdx = idx;
620       idx = skipToLineEnd(text, idx);
621       idx = skipInlineComment(text, idx);
622       idx = skipSpaces(text, idx);
623     }
624
625     idx = skipTrailingComment(text, idx);
626     idx = skipNewline(text, idx);
627     return idx !== false && hasNewline(text, idx);
628   }
629   /**
630    * @template N
631    * @param {string} text
632    * @param {N} node
633    * @param {(node: N) => number} locEnd
634    * @returns {boolean}
635    */
636
637
638   function isNextLineEmpty(text, node, locEnd) {
639     return isNextLineEmptyAfterIndex(text, locEnd(node));
640   }
641   /**
642    * @param {string} text
643    * @param {number} idx
644    * @returns {number | false}
645    */
646
647
648   function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
649     /** @type {number | false} */
650     var oldIdx = null;
651     /** @type {number | false} */
652
653     var nextIdx = idx;
654
655     while (nextIdx !== oldIdx) {
656       oldIdx = nextIdx;
657       nextIdx = skipSpaces(text, nextIdx);
658       nextIdx = skipInlineComment(text, nextIdx);
659       nextIdx = skipTrailingComment(text, nextIdx);
660       nextIdx = skipNewline(text, nextIdx);
661     }
662
663     return nextIdx;
664   }
665   /**
666    * @template N
667    * @param {string} text
668    * @param {N} node
669    * @param {(node: N) => number} locEnd
670    * @returns {number | false}
671    */
672
673
674   function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
675     return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
676   }
677   /**
678    * @template N
679    * @param {string} text
680    * @param {N} node
681    * @param {(node: N) => number} locEnd
682    * @returns {string}
683    */
684
685
686   function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
687     return text.charAt( // @ts-ignore => TBD: can return false, should we define a fallback?
688     getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
689   }
690   /**
691    * @param {string} text
692    * @param {number} index
693    * @param {SkipOptions=} opts
694    * @returns {boolean}
695    */
696
697
698   function hasSpaces(text, index, opts) {
699     opts = opts || {};
700     var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
701     return idx !== index;
702   }
703   /**
704    * @param {{range?: [number, number], start?: number}} node
705    * @param {number} index
706    */
707
708
709   function setLocStart(node, index) {
710     if (node.range) {
711       node.range[0] = index;
712     } else {
713       node.start = index;
714     }
715   }
716   /**
717    * @param {{range?: [number, number], end?: number}} node
718    * @param {number} index
719    */
720
721
722   function setLocEnd(node, index) {
723     if (node.range) {
724       node.range[1] = index;
725     } else {
726       node.end = index;
727     }
728   }
729
730   var PRECEDENCE = {};
731   [["|>"], ["??"], ["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(function (tier, i) {
732     tier.forEach(function (op) {
733       PRECEDENCE[op] = i;
734     });
735   });
736
737   function getPrecedence(op) {
738     return PRECEDENCE[op];
739   }
740
741   var equalityOperators = {
742     "==": true,
743     "!=": true,
744     "===": true,
745     "!==": true
746   };
747   var multiplicativeOperators = {
748     "*": true,
749     "/": true,
750     "%": true
751   };
752   var bitshiftOperators = {
753     ">>": true,
754     ">>>": true,
755     "<<": true
756   };
757
758   function shouldFlatten(parentOp, nodeOp) {
759     if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
760       return false;
761     } // ** is right-associative
762     // x ** y ** z --> x ** (y ** z)
763
764
765     if (parentOp === "**") {
766       return false;
767     } // x == y == z --> (x == y) == z
768
769
770     if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
771       return false;
772     } // x * y % z --> (x * y) % z
773
774
775     if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
776       return false;
777     } // x * y / z --> (x * y) / z
778     // x / y * z --> (x / y) * z
779
780
781     if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
782       return false;
783     } // x << y << z --> (x << y) << z
784
785
786     if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
787       return false;
788     }
789
790     return true;
791   }
792
793   function isBitwiseOperator(operator) {
794     return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
795   } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
796   // holds) `function`, `class`, or `do {}`. Will be overzealous if there's
797   // already necessary grouping parentheses.
798
799
800   function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
801     node = getLeftMost(node);
802
803     switch (node.type) {
804       case "FunctionExpression":
805       case "ClassExpression":
806       case "DoExpression":
807         return forbidFunctionClassAndDoExpr;
808
809       case "ObjectExpression":
810         return true;
811
812       case "MemberExpression":
813       case "OptionalMemberExpression":
814         return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
815
816       case "TaggedTemplateExpression":
817         if (node.tag.type === "FunctionExpression") {
818           // IIFEs are always already parenthesized
819           return false;
820         }
821
822         return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
823
824       case "CallExpression":
825       case "OptionalCallExpression":
826         if (node.callee.type === "FunctionExpression") {
827           // IIFEs are always already parenthesized
828           return false;
829         }
830
831         return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
832
833       case "ConditionalExpression":
834         return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
835
836       case "UpdateExpression":
837         return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
838
839       case "BindExpression":
840         return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
841
842       case "SequenceExpression":
843         return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
844
845       case "TSAsExpression":
846         return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
847
848       default:
849         return false;
850     }
851   }
852
853   function getLeftMost(node) {
854     if (node.left) {
855       return getLeftMost(node.left);
856     }
857
858     return node;
859   }
860   /**
861    * @param {string} value
862    * @param {number} tabWidth
863    * @param {number=} startIndex
864    * @returns {number}
865    */
866
867
868   function getAlignmentSize(value, tabWidth, startIndex) {
869     startIndex = startIndex || 0;
870     var size = 0;
871
872     for (var i = startIndex; i < value.length; ++i) {
873       if (value[i] === "\t") {
874         // Tabs behave in a way that they are aligned to the nearest
875         // multiple of tabWidth:
876         // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
877         // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
878         size = size + tabWidth - size % tabWidth;
879       } else {
880         size++;
881       }
882     }
883
884     return size;
885   }
886   /**
887    * @param {string} value
888    * @param {number} tabWidth
889    * @returns {number}
890    */
891
892
893   function getIndentSize(value, tabWidth) {
894     var lastNewlineIndex = value.lastIndexOf("\n");
895
896     if (lastNewlineIndex === -1) {
897       return 0;
898     }
899
900     return getAlignmentSize( // All the leading whitespaces
901     value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0], tabWidth);
902   }
903   /**
904    * @typedef {'"' | "'"} Quote
905    */
906
907   /**
908    *
909    * @param {string} raw
910    * @param {Quote} preferredQuote
911    * @returns {Quote}
912    */
913
914
915   function getPreferredQuote(raw, preferredQuote) {
916     // `rawContent` is the string exactly like it appeared in the input source
917     // code, without its enclosing quotes.
918     var rawContent = raw.slice(1, -1);
919     /** @type {{ quote: '"', regex: RegExp }} */
920
921     var double = {
922       quote: '"',
923       regex: /"/g
924     };
925     /** @type {{ quote: "'", regex: RegExp }} */
926
927     var single = {
928       quote: "'",
929       regex: /'/g
930     };
931     var preferred = preferredQuote === "'" ? single : double;
932     var alternate = preferred === single ? double : single;
933     var result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
934     // the string, we might want to enclose with the alternate quote instead, to
935     // minimize the number of escaped quotes.
936
937     if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
938       var numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
939       var numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
940       result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
941     }
942
943     return result;
944   }
945
946   function printString(raw, options, isDirectiveLiteral) {
947     // `rawContent` is the string exactly like it appeared in the input source
948     // code, without its enclosing quotes.
949     var rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
950     // the quotes on a DirectiveLiteral.
951
952     var canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
953     /** @type {Quote} */
954
955     var enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
956     // change the escape sequences they use.
957     // See https://github.com/prettier/prettier/issues/1555
958     // and https://tc39.github.io/ecma262/#directive-prologue
959
960     if (isDirectiveLiteral) {
961       if (canChangeDirectiveQuotes) {
962         return enclosingQuote + rawContent + enclosingQuote;
963       }
964
965       return raw;
966     } // It might sound unnecessary to use `makeString` even if the string already
967     // is enclosed with `enclosingQuote`, but it isn't. The string could contain
968     // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
969     // sure that we consistently output the minimum amount of escaped quotes.
970
971
972     return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.embeddedInHtml));
973   }
974   /**
975    * @param {string} rawContent
976    * @param {Quote} enclosingQuote
977    * @param {boolean=} unescapeUnnecessaryEscapes
978    * @returns {string}
979    */
980
981
982   function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
983     var otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
984
985     var regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
986     // enclose `rawContent` with `enclosingQuote`.
987
988     var newContent = rawContent.replace(regex, function (match, escaped, quote) {
989       // If we matched an escape, and the escaped character is a quote of the
990       // other type than we intend to enclose the string with, there's no need for
991       // it to be escaped, so return it _without_ the backslash.
992       if (escaped === otherQuote) {
993         return escaped;
994       } // If we matched an unescaped quote and it is of the _same_ type as we
995       // intend to enclose the string with, it must be escaped, so return it with
996       // a backslash.
997
998
999       if (quote === enclosingQuote) {
1000         return "\\" + quote;
1001       }
1002
1003       if (quote) {
1004         return quote;
1005       } // Unescape any unnecessarily escaped character.
1006       // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
1007
1008
1009       return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) ? escaped : "\\" + escaped;
1010     });
1011     return enclosingQuote + newContent + enclosingQuote;
1012   }
1013
1014   function printNumber(rawNumber) {
1015     return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
1016     .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
1017     .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
1018     .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
1019     .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
1020     .replace(/\.(?=e|$)/, "");
1021   }
1022   /**
1023    * @param {string} str
1024    * @param {string} target
1025    * @returns {number}
1026    */
1027
1028
1029   function getMaxContinuousCount(str, target) {
1030     var results = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
1031
1032     if (results === null) {
1033       return 0;
1034     }
1035
1036     return results.reduce(function (maxCount, result) {
1037       return Math.max(maxCount, result.length / target.length);
1038     }, 0);
1039   }
1040
1041   function getMinNotPresentContinuousCount(str, target) {
1042     var matches = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
1043
1044     if (matches === null) {
1045       return 0;
1046     }
1047
1048     var countPresent = new Map();
1049     var max = 0;
1050     var _iteratorNormalCompletion = true;
1051     var _didIteratorError = false;
1052     var _iteratorError = undefined;
1053
1054     try {
1055       for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
1056         var match = _step.value;
1057         var count = match.length / target.length;
1058         countPresent.set(count, true);
1059
1060         if (count > max) {
1061           max = count;
1062         }
1063       }
1064     } catch (err) {
1065       _didIteratorError = true;
1066       _iteratorError = err;
1067     } finally {
1068       try {
1069         if (!_iteratorNormalCompletion && _iterator.return != null) {
1070           _iterator.return();
1071         }
1072       } finally {
1073         if (_didIteratorError) {
1074           throw _iteratorError;
1075         }
1076       }
1077     }
1078
1079     for (var i = 1; i < max; i++) {
1080       if (!countPresent.get(i)) {
1081         return i;
1082       }
1083     }
1084
1085     return max + 1;
1086   }
1087   /**
1088    * @param {string} text
1089    * @returns {number}
1090    */
1091
1092
1093   function getStringWidth(text) {
1094     if (!text) {
1095       return 0;
1096     } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
1097
1098
1099     if (!notAsciiRegex.test(text)) {
1100       return text.length;
1101     }
1102
1103     return stringWidth_1(text);
1104   }
1105
1106   function hasIgnoreComment(path) {
1107     var node = path.getValue();
1108     return hasNodeIgnoreComment(node);
1109   }
1110
1111   function hasNodeIgnoreComment(node) {
1112     return node && node.comments && node.comments.length > 0 && node.comments.some(function (comment) {
1113       return comment.value.trim() === "prettier-ignore";
1114     });
1115   }
1116
1117   function matchAncestorTypes(path, types, index) {
1118     index = index || 0;
1119     types = types.slice();
1120
1121     while (types.length) {
1122       var parent = path.getParentNode(index);
1123       var type = types.shift();
1124
1125       if (!parent || parent.type !== type) {
1126         return false;
1127       }
1128
1129       index++;
1130     }
1131
1132     return true;
1133   }
1134
1135   function addCommentHelper(node, comment) {
1136     var comments = node.comments || (node.comments = []);
1137     comments.push(comment);
1138     comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
1139     // We already "print" it via the raw text, we don't need to re-print it as a
1140     // comment
1141
1142     if (node.type === "JSXText") {
1143       comment.printed = true;
1144     }
1145   }
1146
1147   function addLeadingComment(node, comment) {
1148     comment.leading = true;
1149     comment.trailing = false;
1150     addCommentHelper(node, comment);
1151   }
1152
1153   function addDanglingComment(node, comment) {
1154     comment.leading = false;
1155     comment.trailing = false;
1156     addCommentHelper(node, comment);
1157   }
1158
1159   function addTrailingComment(node, comment) {
1160     comment.leading = false;
1161     comment.trailing = true;
1162     addCommentHelper(node, comment);
1163   }
1164
1165   function isWithinParentArrayProperty(path, propertyName) {
1166     var node = path.getValue();
1167     var parent = path.getParentNode();
1168
1169     if (parent == null) {
1170       return false;
1171     }
1172
1173     if (!Array.isArray(parent[propertyName])) {
1174       return false;
1175     }
1176
1177     var key = path.getName();
1178     return parent[propertyName][key] === node;
1179   }
1180
1181   function replaceEndOfLineWith(text, replacement) {
1182     var parts = [];
1183     var _iteratorNormalCompletion2 = true;
1184     var _didIteratorError2 = false;
1185     var _iteratorError2 = undefined;
1186
1187     try {
1188       for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
1189         var part = _step2.value;
1190
1191         if (parts.length !== 0) {
1192           parts.push(replacement);
1193         }
1194
1195         parts.push(part);
1196       }
1197     } catch (err) {
1198       _didIteratorError2 = true;
1199       _iteratorError2 = err;
1200     } finally {
1201       try {
1202         if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
1203           _iterator2.return();
1204         }
1205       } finally {
1206         if (_didIteratorError2) {
1207           throw _iteratorError2;
1208         }
1209       }
1210     }
1211
1212     return parts;
1213   }
1214
1215   var util = {
1216     replaceEndOfLineWith: replaceEndOfLineWith,
1217     getStringWidth: getStringWidth,
1218     getMaxContinuousCount: getMaxContinuousCount,
1219     getMinNotPresentContinuousCount: getMinNotPresentContinuousCount,
1220     getPrecedence: getPrecedence,
1221     shouldFlatten: shouldFlatten,
1222     isBitwiseOperator: isBitwiseOperator,
1223     isExportDeclaration: isExportDeclaration,
1224     getParentExportDeclaration: getParentExportDeclaration,
1225     getPenultimate: getPenultimate,
1226     getLast: getLast,
1227     getNextNonSpaceNonCommentCharacterIndexWithStartIndex: getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
1228     getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex,
1229     getNextNonSpaceNonCommentCharacter: getNextNonSpaceNonCommentCharacter,
1230     skip: skip,
1231     skipWhitespace: skipWhitespace,
1232     skipSpaces: skipSpaces,
1233     skipToLineEnd: skipToLineEnd,
1234     skipEverythingButNewLine: skipEverythingButNewLine,
1235     skipInlineComment: skipInlineComment,
1236     skipTrailingComment: skipTrailingComment,
1237     skipNewline: skipNewline,
1238     isNextLineEmptyAfterIndex: isNextLineEmptyAfterIndex,
1239     isNextLineEmpty: isNextLineEmpty,
1240     isPreviousLineEmpty: isPreviousLineEmpty,
1241     hasNewline: hasNewline,
1242     hasNewlineInRange: hasNewlineInRange,
1243     hasSpaces: hasSpaces,
1244     setLocStart: setLocStart,
1245     setLocEnd: setLocEnd,
1246     startsWithNoLookaheadToken: startsWithNoLookaheadToken,
1247     getAlignmentSize: getAlignmentSize,
1248     getIndentSize: getIndentSize,
1249     getPreferredQuote: getPreferredQuote,
1250     printString: printString,
1251     printNumber: printNumber,
1252     hasIgnoreComment: hasIgnoreComment,
1253     hasNodeIgnoreComment: hasNodeIgnoreComment,
1254     makeString: makeString,
1255     matchAncestorTypes: matchAncestorTypes,
1256     addLeadingComment: addLeadingComment,
1257     addDanglingComment: addDanglingComment,
1258     addTrailingComment: addTrailingComment,
1259     isWithinParentArrayProperty: isWithinParentArrayProperty
1260   };
1261
1262   function guessEndOfLine(text) {
1263     var index = text.indexOf("\r");
1264
1265     if (index >= 0) {
1266       return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
1267     }
1268
1269     return "lf";
1270   }
1271
1272   function convertEndOfLineToChars(value) {
1273     switch (value) {
1274       case "cr":
1275         return "\r";
1276
1277       case "crlf":
1278         return "\r\n";
1279
1280       default:
1281         return "\n";
1282     }
1283   }
1284
1285   var endOfLine = {
1286     guessEndOfLine: guessEndOfLine,
1287     convertEndOfLineToChars: convertEndOfLineToChars
1288   };
1289
1290   var getStringWidth$1 = util.getStringWidth;
1291   var convertEndOfLineToChars$1 = endOfLine.convertEndOfLineToChars;
1292   var concat$1 = docBuilders.concat,
1293       fill$1 = docBuilders.fill,
1294       cursor$1 = docBuilders.cursor;
1295   /** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
1296
1297   var groupModeMap;
1298   var MODE_BREAK = 1;
1299   var MODE_FLAT = 2;
1300
1301   function rootIndent() {
1302     return {
1303       value: "",
1304       length: 0,
1305       queue: []
1306     };
1307   }
1308
1309   function makeIndent(ind, options) {
1310     return generateInd(ind, {
1311       type: "indent"
1312     }, options);
1313   }
1314
1315   function makeAlign(ind, n, options) {
1316     return n === -Infinity ? ind.root || rootIndent() : n < 0 ? generateInd(ind, {
1317       type: "dedent"
1318     }, options) : !n ? ind : n.type === "root" ? Object.assign({}, ind, {
1319       root: ind
1320     }) : typeof n === "string" ? generateInd(ind, {
1321       type: "stringAlign",
1322       n: n
1323     }, options) : generateInd(ind, {
1324       type: "numberAlign",
1325       n: n
1326     }, options);
1327   }
1328
1329   function generateInd(ind, newPart, options) {
1330     var queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
1331     var value = "";
1332     var length = 0;
1333     var lastTabs = 0;
1334     var lastSpaces = 0;
1335     var _iteratorNormalCompletion = true;
1336     var _didIteratorError = false;
1337     var _iteratorError = undefined;
1338
1339     try {
1340       for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
1341         var part = _step.value;
1342
1343         switch (part.type) {
1344           case "indent":
1345             flush();
1346
1347             if (options.useTabs) {
1348               addTabs(1);
1349             } else {
1350               addSpaces(options.tabWidth);
1351             }
1352
1353             break;
1354
1355           case "stringAlign":
1356             flush();
1357             value += part.n;
1358             length += part.n.length;
1359             break;
1360
1361           case "numberAlign":
1362             lastTabs += 1;
1363             lastSpaces += part.n;
1364             break;
1365
1366           /* istanbul ignore next */
1367
1368           default:
1369             throw new Error("Unexpected type '".concat(part.type, "'"));
1370         }
1371       }
1372     } catch (err) {
1373       _didIteratorError = true;
1374       _iteratorError = err;
1375     } finally {
1376       try {
1377         if (!_iteratorNormalCompletion && _iterator.return != null) {
1378           _iterator.return();
1379         }
1380       } finally {
1381         if (_didIteratorError) {
1382           throw _iteratorError;
1383         }
1384       }
1385     }
1386
1387     flushSpaces();
1388     return Object.assign({}, ind, {
1389       value: value,
1390       length: length,
1391       queue: queue
1392     });
1393
1394     function addTabs(count) {
1395       value += "\t".repeat(count);
1396       length += options.tabWidth * count;
1397     }
1398
1399     function addSpaces(count) {
1400       value += " ".repeat(count);
1401       length += count;
1402     }
1403
1404     function flush() {
1405       if (options.useTabs) {
1406         flushTabs();
1407       } else {
1408         flushSpaces();
1409       }
1410     }
1411
1412     function flushTabs() {
1413       if (lastTabs > 0) {
1414         addTabs(lastTabs);
1415       }
1416
1417       resetLast();
1418     }
1419
1420     function flushSpaces() {
1421       if (lastSpaces > 0) {
1422         addSpaces(lastSpaces);
1423       }
1424
1425       resetLast();
1426     }
1427
1428     function resetLast() {
1429       lastTabs = 0;
1430       lastSpaces = 0;
1431     }
1432   }
1433
1434   function trim$1(out) {
1435     if (out.length === 0) {
1436       return 0;
1437     }
1438
1439     var trimCount = 0; // Trim whitespace at the end of line
1440
1441     while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[ \t]*$/)) {
1442       trimCount += out.pop().length;
1443     }
1444
1445     if (out.length && typeof out[out.length - 1] === "string") {
1446       var trimmed = out[out.length - 1].replace(/[ \t]*$/, "");
1447       trimCount += out[out.length - 1].length - trimmed.length;
1448       out[out.length - 1] = trimmed;
1449     }
1450
1451     return trimCount;
1452   }
1453
1454   function fits(next, restCommands, width, options, mustBeFlat) {
1455     var restIdx = restCommands.length;
1456     var cmds = [next]; // `out` is only used for width counting because `trim` requires to look
1457     // backwards for space characters.
1458
1459     var out = [];
1460
1461     while (width >= 0) {
1462       if (cmds.length === 0) {
1463         if (restIdx === 0) {
1464           return true;
1465         }
1466
1467         cmds.push(restCommands[restIdx - 1]);
1468         restIdx--;
1469         continue;
1470       }
1471
1472       var x = cmds.pop();
1473       var ind = x[0];
1474       var mode = x[1];
1475       var doc = x[2];
1476
1477       if (typeof doc === "string") {
1478         out.push(doc);
1479         width -= getStringWidth$1(doc);
1480       } else {
1481         switch (doc.type) {
1482           case "concat":
1483             for (var i = doc.parts.length - 1; i >= 0; i--) {
1484               cmds.push([ind, mode, doc.parts[i]]);
1485             }
1486
1487             break;
1488
1489           case "indent":
1490             cmds.push([makeIndent(ind, options), mode, doc.contents]);
1491             break;
1492
1493           case "align":
1494             cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
1495             break;
1496
1497           case "trim":
1498             width += trim$1(out);
1499             break;
1500
1501           case "group":
1502             if (mustBeFlat && doc.break) {
1503               return false;
1504             }
1505
1506             cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
1507
1508             if (doc.id) {
1509               groupModeMap[doc.id] = cmds[cmds.length - 1][1];
1510             }
1511
1512             break;
1513
1514           case "fill":
1515             for (var _i = doc.parts.length - 1; _i >= 0; _i--) {
1516               cmds.push([ind, mode, doc.parts[_i]]);
1517             }
1518
1519             break;
1520
1521           case "if-break":
1522             {
1523               var groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
1524
1525               if (groupMode === MODE_BREAK) {
1526                 if (doc.breakContents) {
1527                   cmds.push([ind, mode, doc.breakContents]);
1528                 }
1529               }
1530
1531               if (groupMode === MODE_FLAT) {
1532                 if (doc.flatContents) {
1533                   cmds.push([ind, mode, doc.flatContents]);
1534                 }
1535               }
1536
1537               break;
1538             }
1539
1540           case "line":
1541             switch (mode) {
1542               // fallthrough
1543               case MODE_FLAT:
1544                 if (!doc.hard) {
1545                   if (!doc.soft) {
1546                     out.push(" ");
1547                     width -= 1;
1548                   }
1549
1550                   break;
1551                 }
1552
1553                 return true;
1554
1555               case MODE_BREAK:
1556                 return true;
1557             }
1558
1559             break;
1560         }
1561       }
1562     }
1563
1564     return false;
1565   }
1566
1567   function printDocToString(doc, options) {
1568     groupModeMap = {};
1569     var width = options.printWidth;
1570     var newLine = convertEndOfLineToChars$1(options.endOfLine);
1571     var pos = 0; // cmds is basically a stack. We've turned a recursive call into a
1572     // while loop which is much faster. The while loop below adds new
1573     // cmds to the array instead of recursively calling `print`.
1574
1575     var cmds = [[rootIndent(), MODE_BREAK, doc]];
1576     var out = [];
1577     var shouldRemeasure = false;
1578     var lineSuffix = [];
1579
1580     while (cmds.length !== 0) {
1581       var x = cmds.pop();
1582       var ind = x[0];
1583       var mode = x[1];
1584       var _doc = x[2];
1585
1586       if (typeof _doc === "string") {
1587         out.push(_doc);
1588         pos += getStringWidth$1(_doc);
1589       } else {
1590         switch (_doc.type) {
1591           case "cursor":
1592             out.push(cursor$1.placeholder);
1593             break;
1594
1595           case "concat":
1596             for (var i = _doc.parts.length - 1; i >= 0; i--) {
1597               cmds.push([ind, mode, _doc.parts[i]]);
1598             }
1599
1600             break;
1601
1602           case "indent":
1603             cmds.push([makeIndent(ind, options), mode, _doc.contents]);
1604             break;
1605
1606           case "align":
1607             cmds.push([makeAlign(ind, _doc.n, options), mode, _doc.contents]);
1608             break;
1609
1610           case "trim":
1611             pos -= trim$1(out);
1612             break;
1613
1614           case "group":
1615             switch (mode) {
1616               case MODE_FLAT:
1617                 if (!shouldRemeasure) {
1618                   cmds.push([ind, _doc.break ? MODE_BREAK : MODE_FLAT, _doc.contents]);
1619                   break;
1620                 }
1621
1622               // fallthrough
1623
1624               case MODE_BREAK:
1625                 {
1626                   shouldRemeasure = false;
1627                   var next = [ind, MODE_FLAT, _doc.contents];
1628                   var rem = width - pos;
1629
1630                   if (!_doc.break && fits(next, cmds, rem, options)) {
1631                     cmds.push(next);
1632                   } else {
1633                     // Expanded states are a rare case where a document
1634                     // can manually provide multiple representations of
1635                     // itself. It provides an array of documents
1636                     // going from the least expanded (most flattened)
1637                     // representation first to the most expanded. If a
1638                     // group has these, we need to manually go through
1639                     // these states and find the first one that fits.
1640                     if (_doc.expandedStates) {
1641                       var mostExpanded = _doc.expandedStates[_doc.expandedStates.length - 1];
1642
1643                       if (_doc.break) {
1644                         cmds.push([ind, MODE_BREAK, mostExpanded]);
1645                         break;
1646                       } else {
1647                         for (var _i2 = 1; _i2 < _doc.expandedStates.length + 1; _i2++) {
1648                           if (_i2 >= _doc.expandedStates.length) {
1649                             cmds.push([ind, MODE_BREAK, mostExpanded]);
1650                             break;
1651                           } else {
1652                             var state = _doc.expandedStates[_i2];
1653                             var cmd = [ind, MODE_FLAT, state];
1654
1655                             if (fits(cmd, cmds, rem, options)) {
1656                               cmds.push(cmd);
1657                               break;
1658                             }
1659                           }
1660                         }
1661                       }
1662                     } else {
1663                       cmds.push([ind, MODE_BREAK, _doc.contents]);
1664                     }
1665                   }
1666
1667                   break;
1668                 }
1669             }
1670
1671             if (_doc.id) {
1672               groupModeMap[_doc.id] = cmds[cmds.length - 1][1];
1673             }
1674
1675             break;
1676           // Fills each line with as much code as possible before moving to a new
1677           // line with the same indentation.
1678           //
1679           // Expects doc.parts to be an array of alternating content and
1680           // whitespace. The whitespace contains the linebreaks.
1681           //
1682           // For example:
1683           //   ["I", line, "love", line, "monkeys"]
1684           // or
1685           //   [{ type: group, ... }, softline, { type: group, ... }]
1686           //
1687           // It uses this parts structure to handle three main layout cases:
1688           // * The first two content items fit on the same line without
1689           //   breaking
1690           //   -> output the first content item and the whitespace "flat".
1691           // * Only the first content item fits on the line without breaking
1692           //   -> output the first content item "flat" and the whitespace with
1693           //   "break".
1694           // * Neither content item fits on the line without breaking
1695           //   -> output the first content item and the whitespace with "break".
1696
1697           case "fill":
1698             {
1699               var _rem = width - pos;
1700
1701               var parts = _doc.parts;
1702
1703               if (parts.length === 0) {
1704                 break;
1705               }
1706
1707               var content = parts[0];
1708               var contentFlatCmd = [ind, MODE_FLAT, content];
1709               var contentBreakCmd = [ind, MODE_BREAK, content];
1710               var contentFits = fits(contentFlatCmd, [], _rem, options, true);
1711
1712               if (parts.length === 1) {
1713                 if (contentFits) {
1714                   cmds.push(contentFlatCmd);
1715                 } else {
1716                   cmds.push(contentBreakCmd);
1717                 }
1718
1719                 break;
1720               }
1721
1722               var whitespace = parts[1];
1723               var whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
1724               var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
1725
1726               if (parts.length === 2) {
1727                 if (contentFits) {
1728                   cmds.push(whitespaceFlatCmd);
1729                   cmds.push(contentFlatCmd);
1730                 } else {
1731                   cmds.push(whitespaceBreakCmd);
1732                   cmds.push(contentBreakCmd);
1733                 }
1734
1735                 break;
1736               } // At this point we've handled the first pair (context, separator)
1737               // and will create a new fill doc for the rest of the content.
1738               // Ideally we wouldn't mutate the array here but coping all the
1739               // elements to a new array would make this algorithm quadratic,
1740               // which is unusable for large arrays (e.g. large texts in JSX).
1741
1742
1743               parts.splice(0, 2);
1744               var remainingCmd = [ind, mode, fill$1(parts)];
1745               var secondContent = parts[0];
1746               var firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$1([content, whitespace, secondContent])];
1747               var firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], _rem, options, true);
1748
1749               if (firstAndSecondContentFits) {
1750                 cmds.push(remainingCmd);
1751                 cmds.push(whitespaceFlatCmd);
1752                 cmds.push(contentFlatCmd);
1753               } else if (contentFits) {
1754                 cmds.push(remainingCmd);
1755                 cmds.push(whitespaceBreakCmd);
1756                 cmds.push(contentFlatCmd);
1757               } else {
1758                 cmds.push(remainingCmd);
1759                 cmds.push(whitespaceBreakCmd);
1760                 cmds.push(contentBreakCmd);
1761               }
1762
1763               break;
1764             }
1765
1766           case "if-break":
1767             {
1768               var groupMode = _doc.groupId ? groupModeMap[_doc.groupId] : mode;
1769
1770               if (groupMode === MODE_BREAK) {
1771                 if (_doc.breakContents) {
1772                   cmds.push([ind, mode, _doc.breakContents]);
1773                 }
1774               }
1775
1776               if (groupMode === MODE_FLAT) {
1777                 if (_doc.flatContents) {
1778                   cmds.push([ind, mode, _doc.flatContents]);
1779                 }
1780               }
1781
1782               break;
1783             }
1784
1785           case "line-suffix":
1786             lineSuffix.push([ind, mode, _doc.contents]);
1787             break;
1788
1789           case "line-suffix-boundary":
1790             if (lineSuffix.length > 0) {
1791               cmds.push([ind, mode, {
1792                 type: "line",
1793                 hard: true
1794               }]);
1795             }
1796
1797             break;
1798
1799           case "line":
1800             switch (mode) {
1801               case MODE_FLAT:
1802                 if (!_doc.hard) {
1803                   if (!_doc.soft) {
1804                     out.push(" ");
1805                     pos += 1;
1806                   }
1807
1808                   break;
1809                 } else {
1810                   // This line was forced into the output even if we
1811                   // were in flattened mode, so we need to tell the next
1812                   // group that no matter what, it needs to remeasure
1813                   // because the previous measurement didn't accurately
1814                   // capture the entire expression (this is necessary
1815                   // for nested groups)
1816                   shouldRemeasure = true;
1817                 }
1818
1819               // fallthrough
1820
1821               case MODE_BREAK:
1822                 if (lineSuffix.length) {
1823                   cmds.push([ind, mode, _doc]);
1824                   [].push.apply(cmds, lineSuffix.reverse());
1825                   lineSuffix = [];
1826                   break;
1827                 }
1828
1829                 if (_doc.literal) {
1830                   if (ind.root) {
1831                     out.push(newLine, ind.root.value);
1832                     pos = ind.root.length;
1833                   } else {
1834                     out.push(newLine);
1835                     pos = 0;
1836                   }
1837                 } else {
1838                   pos -= trim$1(out);
1839                   out.push(newLine + ind.value);
1840                   pos = ind.length;
1841                 }
1842
1843                 break;
1844             }
1845
1846             break;
1847         }
1848       }
1849     }
1850
1851     var cursorPlaceholderIndex = out.indexOf(cursor$1.placeholder);
1852
1853     if (cursorPlaceholderIndex !== -1) {
1854       var otherCursorPlaceholderIndex = out.indexOf(cursor$1.placeholder, cursorPlaceholderIndex + 1);
1855       var beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
1856       var aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
1857       var afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
1858       return {
1859         formatted: beforeCursor + aroundCursor + afterCursor,
1860         cursorNodeStart: beforeCursor.length,
1861         cursorNodeText: aroundCursor
1862       };
1863     }
1864
1865     return {
1866       formatted: out.join("")
1867     };
1868   }
1869
1870   var docPrinter = {
1871     printDocToString: printDocToString
1872   };
1873
1874   var traverseDocOnExitStackMarker = {};
1875
1876   function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
1877     var docsStack = [doc];
1878
1879     while (docsStack.length !== 0) {
1880       var _doc = docsStack.pop();
1881
1882       if (_doc === traverseDocOnExitStackMarker) {
1883         onExit(docsStack.pop());
1884         continue;
1885       }
1886
1887       var shouldRecurse = true;
1888
1889       if (onEnter) {
1890         if (onEnter(_doc) === false) {
1891           shouldRecurse = false;
1892         }
1893       }
1894
1895       if (onExit) {
1896         docsStack.push(_doc);
1897         docsStack.push(traverseDocOnExitStackMarker);
1898       }
1899
1900       if (shouldRecurse) {
1901         // When there are multiple parts to process,
1902         // the parts need to be pushed onto the stack in reverse order,
1903         // so that they are processed in the original order
1904         // when the stack is popped.
1905         if (_doc.type === "concat" || _doc.type === "fill") {
1906           for (var ic = _doc.parts.length, i = ic - 1; i >= 0; --i) {
1907             docsStack.push(_doc.parts[i]);
1908           }
1909         } else if (_doc.type === "if-break") {
1910           if (_doc.flatContents) {
1911             docsStack.push(_doc.flatContents);
1912           }
1913
1914           if (_doc.breakContents) {
1915             docsStack.push(_doc.breakContents);
1916           }
1917         } else if (_doc.type === "group" && _doc.expandedStates) {
1918           if (shouldTraverseConditionalGroups) {
1919             for (var _ic = _doc.expandedStates.length, _i = _ic - 1; _i >= 0; --_i) {
1920               docsStack.push(_doc.expandedStates[_i]);
1921             }
1922           } else {
1923             docsStack.push(_doc.contents);
1924           }
1925         } else if (_doc.contents) {
1926           docsStack.push(_doc.contents);
1927         }
1928       }
1929     }
1930   }
1931
1932   function mapDoc(doc, cb) {
1933     if (doc.type === "concat" || doc.type === "fill") {
1934       var parts = doc.parts.map(function (part) {
1935         return mapDoc(part, cb);
1936       });
1937       return cb(Object.assign({}, doc, {
1938         parts: parts
1939       }));
1940     } else if (doc.type === "if-break") {
1941       var breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
1942       var flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
1943       return cb(Object.assign({}, doc, {
1944         breakContents: breakContents,
1945         flatContents: flatContents
1946       }));
1947     } else if (doc.contents) {
1948       var contents = mapDoc(doc.contents, cb);
1949       return cb(Object.assign({}, doc, {
1950         contents: contents
1951       }));
1952     }
1953
1954     return cb(doc);
1955   }
1956
1957   function findInDoc(doc, fn, defaultValue) {
1958     var result = defaultValue;
1959     var hasStopped = false;
1960
1961     function findInDocOnEnterFn(doc) {
1962       var maybeResult = fn(doc);
1963
1964       if (maybeResult !== undefined) {
1965         hasStopped = true;
1966         result = maybeResult;
1967       }
1968
1969       if (hasStopped) {
1970         return false;
1971       }
1972     }
1973
1974     traverseDoc(doc, findInDocOnEnterFn);
1975     return result;
1976   }
1977
1978   function isEmpty(n) {
1979     return typeof n === "string" && n.length === 0;
1980   }
1981
1982   function isLineNextFn(doc) {
1983     if (typeof doc === "string") {
1984       return false;
1985     }
1986
1987     if (doc.type === "line") {
1988       return true;
1989     }
1990   }
1991
1992   function isLineNext(doc) {
1993     return findInDoc(doc, isLineNextFn, false);
1994   }
1995
1996   function willBreakFn(doc) {
1997     if (doc.type === "group" && doc.break) {
1998       return true;
1999     }
2000
2001     if (doc.type === "line" && doc.hard) {
2002       return true;
2003     }
2004
2005     if (doc.type === "break-parent") {
2006       return true;
2007     }
2008   }
2009
2010   function willBreak(doc) {
2011     return findInDoc(doc, willBreakFn, false);
2012   }
2013
2014   function breakParentGroup(groupStack) {
2015     if (groupStack.length > 0) {
2016       var parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
2017       // the user is expected to manually handle what breaks.
2018
2019       if (!parentGroup.expandedStates) {
2020         parentGroup.break = true;
2021       }
2022     }
2023
2024     return null;
2025   }
2026
2027   function propagateBreaks(doc) {
2028     var alreadyVisitedSet = new Set();
2029     var groupStack = [];
2030
2031     function propagateBreaksOnEnterFn(doc) {
2032       if (doc.type === "break-parent") {
2033         breakParentGroup(groupStack);
2034       }
2035
2036       if (doc.type === "group") {
2037         groupStack.push(doc);
2038
2039         if (alreadyVisitedSet.has(doc)) {
2040           return false;
2041         }
2042
2043         alreadyVisitedSet.add(doc);
2044       }
2045     }
2046
2047     function propagateBreaksOnExitFn(doc) {
2048       if (doc.type === "group") {
2049         var group = groupStack.pop();
2050
2051         if (group.break) {
2052           breakParentGroup(groupStack);
2053         }
2054       }
2055     }
2056
2057     traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
2058     /* shouldTraverseConditionalGroups */
2059     true);
2060   }
2061
2062   function removeLinesFn(doc) {
2063     // Force this doc into flat mode by statically converting all
2064     // lines into spaces (or soft lines into nothing). Hard lines
2065     // should still output because there's too great of a chance
2066     // of breaking existing assumptions otherwise.
2067     if (doc.type === "line" && !doc.hard) {
2068       return doc.soft ? "" : " ";
2069     } else if (doc.type === "if-break") {
2070       return doc.flatContents || "";
2071     }
2072
2073     return doc;
2074   }
2075
2076   function removeLines(doc) {
2077     return mapDoc(doc, removeLinesFn);
2078   }
2079
2080   function stripTrailingHardline(doc) {
2081     // HACK remove ending hardline, original PR: #1984
2082     if (doc.type === "concat" && doc.parts.length !== 0) {
2083       var lastPart = doc.parts[doc.parts.length - 1];
2084
2085       if (lastPart.type === "concat") {
2086         if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
2087           return {
2088             type: "concat",
2089             parts: doc.parts.slice(0, -1)
2090           };
2091         }
2092
2093         return {
2094           type: "concat",
2095           parts: doc.parts.slice(0, -1).concat(stripTrailingHardline(lastPart))
2096         };
2097       }
2098     }
2099
2100     return doc;
2101   }
2102
2103   var docUtils = {
2104     isEmpty: isEmpty,
2105     willBreak: willBreak,
2106     isLineNext: isLineNext,
2107     traverseDoc: traverseDoc,
2108     findInDoc: findInDoc,
2109     mapDoc: mapDoc,
2110     propagateBreaks: propagateBreaks,
2111     removeLines: removeLines,
2112     stripTrailingHardline: stripTrailingHardline
2113   };
2114
2115   function flattenDoc(doc) {
2116     if (doc.type === "concat") {
2117       var res = [];
2118
2119       for (var i = 0; i < doc.parts.length; ++i) {
2120         var doc2 = doc.parts[i];
2121
2122         if (typeof doc2 !== "string" && doc2.type === "concat") {
2123           [].push.apply(res, flattenDoc(doc2).parts);
2124         } else {
2125           var flattened = flattenDoc(doc2);
2126
2127           if (flattened !== "") {
2128             res.push(flattened);
2129           }
2130         }
2131       }
2132
2133       return Object.assign({}, doc, {
2134         parts: res
2135       });
2136     } else if (doc.type === "if-break") {
2137       return Object.assign({}, doc, {
2138         breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
2139         flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
2140       });
2141     } else if (doc.type === "group") {
2142       return Object.assign({}, doc, {
2143         contents: flattenDoc(doc.contents),
2144         expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
2145       });
2146     } else if (doc.contents) {
2147       return Object.assign({}, doc, {
2148         contents: flattenDoc(doc.contents)
2149       });
2150     }
2151
2152     return doc;
2153   }
2154
2155   function printDoc(doc) {
2156     if (typeof doc === "string") {
2157       return JSON.stringify(doc);
2158     }
2159
2160     if (doc.type === "line") {
2161       if (doc.literal) {
2162         return "literalline";
2163       }
2164
2165       if (doc.hard) {
2166         return "hardline";
2167       }
2168
2169       if (doc.soft) {
2170         return "softline";
2171       }
2172
2173       return "line";
2174     }
2175
2176     if (doc.type === "break-parent") {
2177       return "breakParent";
2178     }
2179
2180     if (doc.type === "trim") {
2181       return "trim";
2182     }
2183
2184     if (doc.type === "concat") {
2185       return "[" + doc.parts.map(printDoc).join(", ") + "]";
2186     }
2187
2188     if (doc.type === "indent") {
2189       return "indent(" + printDoc(doc.contents) + ")";
2190     }
2191
2192     if (doc.type === "align") {
2193       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) + ")";
2194     }
2195
2196     if (doc.type === "if-break") {
2197       return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
2198     }
2199
2200     if (doc.type === "group") {
2201       if (doc.expandedStates) {
2202         return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
2203       }
2204
2205       return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
2206     }
2207
2208     if (doc.type === "fill") {
2209       return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
2210     }
2211
2212     if (doc.type === "line-suffix") {
2213       return "lineSuffix(" + printDoc(doc.contents) + ")";
2214     }
2215
2216     if (doc.type === "line-suffix-boundary") {
2217       return "lineSuffixBoundary";
2218     }
2219
2220     throw new Error("Unknown doc type " + doc.type);
2221   }
2222
2223   var docDebug = {
2224     printDocToDebug: function printDocToDebug(doc) {
2225       return printDoc(flattenDoc(doc));
2226     }
2227   };
2228
2229   var doc = {
2230     builders: docBuilders,
2231     printer: docPrinter,
2232     utils: docUtils,
2233     debug: docDebug
2234   };
2235   var doc_1 = doc.builders;
2236   var doc_2 = doc.printer;
2237   var doc_3 = doc.utils;
2238   var doc_4 = doc.debug;
2239
2240   exports.builders = doc_1;
2241   exports.debug = doc_4;
2242   exports.default = doc;
2243   exports.printer = doc_2;
2244   exports.utils = doc_3;
2245
2246   Object.defineProperty(exports, '__esModule', { value: true });
2247
2248 })));