prettier 1.16.4 → 1.17.0

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