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