prettier 1.19.0 → 2.0.2
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/LICENSE +0 -0
- package/README.md +6 -0
- package/bin-prettier.js +33129 -26030
- package/doc.js +368 -480
- package/index.js +31778 -25276
- package/package.json +2 -2
- package/parser-angular.js +638 -3
- package/parser-babel.js +1 -0
- package/parser-flow.js +1 -1
- package/parser-glimmer.js +1 -1
- package/parser-graphql.js +1 -1
- package/parser-html.js +99 -99
- package/parser-markdown.js +10 -129
- package/parser-postcss.js +3 -3
- package/parser-typescript.js +3 -3
- package/parser-yaml.js +3 -2
- package/standalone.js +12685 -11556
- package/third-party.js +10741 -3926
- package/parser-babylon.js +0 -1
package/doc.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
return {
|
|
22
22
|
type: "concat",
|
|
23
|
-
parts
|
|
23
|
+
parts
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
return {
|
|
35
35
|
type: "indent",
|
|
36
|
-
contents
|
|
36
|
+
contents
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
|
|
48
48
|
return {
|
|
49
49
|
type: "align",
|
|
50
|
-
contents
|
|
51
|
-
n
|
|
50
|
+
contents,
|
|
51
|
+
n
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
return {
|
|
65
65
|
type: "group",
|
|
66
66
|
id: opts.id,
|
|
67
|
-
contents
|
|
67
|
+
contents,
|
|
68
68
|
break: !!opts.shouldBreak,
|
|
69
69
|
expandedStates: opts.expandedStates
|
|
70
70
|
};
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
function conditionalGroup(states, opts) {
|
|
110
|
-
return group(states[0], Object.assign(
|
|
110
|
+
return group(states[0], Object.assign({}, opts, {
|
|
111
111
|
expandedStates: states
|
|
112
112
|
}));
|
|
113
113
|
}
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
|
|
122
122
|
return {
|
|
123
123
|
type: "fill",
|
|
124
|
-
parts
|
|
124
|
+
parts
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
@@ -137,8 +137,8 @@
|
|
|
137
137
|
|
|
138
138
|
return {
|
|
139
139
|
type: "if-break",
|
|
140
|
-
breakContents
|
|
141
|
-
flatContents
|
|
140
|
+
breakContents,
|
|
141
|
+
flatContents,
|
|
142
142
|
groupId: opts.groupId
|
|
143
143
|
};
|
|
144
144
|
}
|
|
@@ -152,36 +152,36 @@
|
|
|
152
152
|
|
|
153
153
|
return {
|
|
154
154
|
type: "line-suffix",
|
|
155
|
-
contents
|
|
155
|
+
contents
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
const lineSuffixBoundary = {
|
|
160
160
|
type: "line-suffix-boundary"
|
|
161
161
|
};
|
|
162
|
-
|
|
162
|
+
const breakParent = {
|
|
163
163
|
type: "break-parent"
|
|
164
164
|
};
|
|
165
|
-
|
|
165
|
+
const trim = {
|
|
166
166
|
type: "trim"
|
|
167
167
|
};
|
|
168
|
-
|
|
168
|
+
const line = {
|
|
169
169
|
type: "line"
|
|
170
170
|
};
|
|
171
|
-
|
|
171
|
+
const softline = {
|
|
172
172
|
type: "line",
|
|
173
173
|
soft: true
|
|
174
174
|
};
|
|
175
|
-
|
|
175
|
+
const hardline = concat([{
|
|
176
176
|
type: "line",
|
|
177
177
|
hard: true
|
|
178
178
|
}, breakParent]);
|
|
179
|
-
|
|
179
|
+
const literalline = concat([{
|
|
180
180
|
type: "line",
|
|
181
181
|
hard: true,
|
|
182
182
|
literal: true
|
|
183
183
|
}, breakParent]);
|
|
184
|
-
|
|
184
|
+
const cursor = {
|
|
185
185
|
type: "cursor",
|
|
186
186
|
placeholder: Symbol("cursor")
|
|
187
187
|
};
|
|
@@ -192,9 +192,9 @@
|
|
|
192
192
|
*/
|
|
193
193
|
|
|
194
194
|
function join(sep, arr) {
|
|
195
|
-
|
|
195
|
+
const res = [];
|
|
196
196
|
|
|
197
|
-
for (
|
|
197
|
+
for (let i = 0; i < arr.length; i++) {
|
|
198
198
|
if (i !== 0) {
|
|
199
199
|
res.push(sep);
|
|
200
200
|
}
|
|
@@ -212,11 +212,11 @@
|
|
|
212
212
|
|
|
213
213
|
|
|
214
214
|
function addAlignmentToDoc(doc, size, tabWidth) {
|
|
215
|
-
|
|
215
|
+
let aligned = doc;
|
|
216
216
|
|
|
217
217
|
if (size > 0) {
|
|
218
218
|
// Use indent to add tabs for all the levels of tabs we need
|
|
219
|
-
for (
|
|
219
|
+
for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
|
|
220
220
|
aligned = indent(aligned);
|
|
221
221
|
} // Use align for all the spaces that are needed
|
|
222
222
|
|
|
@@ -231,48 +231,41 @@
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
var docBuilders = {
|
|
234
|
-
concat
|
|
235
|
-
join
|
|
236
|
-
line
|
|
237
|
-
softline
|
|
238
|
-
hardline
|
|
239
|
-
literalline
|
|
240
|
-
group
|
|
241
|
-
conditionalGroup
|
|
242
|
-
fill
|
|
243
|
-
lineSuffix
|
|
244
|
-
lineSuffixBoundary
|
|
245
|
-
cursor
|
|
246
|
-
breakParent
|
|
247
|
-
ifBreak
|
|
248
|
-
trim
|
|
249
|
-
indent
|
|
250
|
-
align
|
|
251
|
-
addAlignmentToDoc
|
|
252
|
-
markAsRoot
|
|
253
|
-
dedentToRoot
|
|
254
|
-
dedent
|
|
234
|
+
concat,
|
|
235
|
+
join,
|
|
236
|
+
line,
|
|
237
|
+
softline,
|
|
238
|
+
hardline,
|
|
239
|
+
literalline,
|
|
240
|
+
group,
|
|
241
|
+
conditionalGroup,
|
|
242
|
+
fill,
|
|
243
|
+
lineSuffix,
|
|
244
|
+
lineSuffixBoundary,
|
|
245
|
+
cursor,
|
|
246
|
+
breakParent,
|
|
247
|
+
ifBreak,
|
|
248
|
+
trim,
|
|
249
|
+
indent,
|
|
250
|
+
align,
|
|
251
|
+
addAlignmentToDoc,
|
|
252
|
+
markAsRoot,
|
|
253
|
+
dedentToRoot,
|
|
254
|
+
dedent
|
|
255
255
|
};
|
|
256
256
|
|
|
257
|
-
var ansiRegex =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
var stripAnsi = function stripAnsi(string) {
|
|
266
|
-
return typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
|
|
257
|
+
var ansiRegex = ({
|
|
258
|
+
onlyFirst = false
|
|
259
|
+
} = {}) => {
|
|
260
|
+
const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
|
|
261
|
+
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
267
262
|
};
|
|
268
263
|
|
|
269
|
-
var
|
|
270
|
-
var default_1 = stripAnsi;
|
|
271
|
-
stripAnsi_1.default = default_1;
|
|
264
|
+
var stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
|
|
272
265
|
|
|
273
266
|
/* eslint-disable yoda */
|
|
274
267
|
|
|
275
|
-
|
|
268
|
+
const isFullwidthCodePoint = codePoint => {
|
|
276
269
|
if (Number.isNaN(codePoint)) {
|
|
277
270
|
return false;
|
|
278
271
|
} // Code points are derived from:
|
|
@@ -302,26 +295,26 @@
|
|
|
302
295
|
};
|
|
303
296
|
|
|
304
297
|
var isFullwidthCodePoint_1 = isFullwidthCodePoint;
|
|
305
|
-
var default_1
|
|
306
|
-
isFullwidthCodePoint_1.default = default_1
|
|
298
|
+
var default_1 = isFullwidthCodePoint;
|
|
299
|
+
isFullwidthCodePoint_1.default = default_1;
|
|
307
300
|
|
|
308
301
|
var emojiRegex = function emojiRegex() {
|
|
309
302
|
// https://mths.be/emoji
|
|
310
303
|
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
304
|
};
|
|
312
305
|
|
|
313
|
-
|
|
306
|
+
const stringWidth = string => {
|
|
314
307
|
string = string.replace(emojiRegex(), ' ');
|
|
315
308
|
|
|
316
309
|
if (typeof string !== 'string' || string.length === 0) {
|
|
317
310
|
return 0;
|
|
318
311
|
}
|
|
319
312
|
|
|
320
|
-
string =
|
|
321
|
-
|
|
313
|
+
string = stripAnsi(string);
|
|
314
|
+
let width = 0;
|
|
322
315
|
|
|
323
|
-
for (
|
|
324
|
-
|
|
316
|
+
for (let i = 0; i < string.length; i++) {
|
|
317
|
+
const code = string.codePointAt(i); // Ignore control characters
|
|
325
318
|
|
|
326
319
|
if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
|
|
327
320
|
continue;
|
|
@@ -345,49 +338,22 @@
|
|
|
345
338
|
|
|
346
339
|
var stringWidth_1 = stringWidth; // TODO: remove this in the next major version
|
|
347
340
|
|
|
348
|
-
var default_1$
|
|
349
|
-
stringWidth_1.default = default_1$
|
|
341
|
+
var default_1$1 = stringWidth;
|
|
342
|
+
stringWidth_1.default = default_1$1;
|
|
350
343
|
|
|
351
|
-
|
|
344
|
+
const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
|
|
352
345
|
|
|
353
|
-
var escapeStringRegexp =
|
|
354
|
-
if (typeof
|
|
346
|
+
var escapeStringRegexp = string => {
|
|
347
|
+
if (typeof string !== 'string') {
|
|
355
348
|
throw new TypeError('Expected a string');
|
|
356
349
|
}
|
|
357
350
|
|
|
358
|
-
return
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
var getLast = function getLast(arr) {
|
|
362
|
-
return arr.length > 0 ? arr[arr.length - 1] : null;
|
|
351
|
+
return string.replace(matchOperatorsRegex, '\\$&');
|
|
363
352
|
};
|
|
364
353
|
|
|
365
|
-
var
|
|
366
|
-
|
|
367
|
-
function isExportDeclaration(node) {
|
|
368
|
-
if (node) {
|
|
369
|
-
switch (node.type) {
|
|
370
|
-
case "ExportDefaultDeclaration":
|
|
371
|
-
case "ExportDefaultSpecifier":
|
|
372
|
-
case "DeclareExportDeclaration":
|
|
373
|
-
case "ExportNamedDeclaration":
|
|
374
|
-
case "ExportAllDeclaration":
|
|
375
|
-
return true;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
354
|
+
var getLast = arr => arr[arr.length - 1];
|
|
378
355
|
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function getParentExportDeclaration(path) {
|
|
383
|
-
var parentNode = path.getParentNode();
|
|
384
|
-
|
|
385
|
-
if (path.getName() === "declaration" && isExportDeclaration(parentNode)) {
|
|
386
|
-
return parentNode;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
356
|
+
const notAsciiRegex = /[^\x20-\x7F]/;
|
|
391
357
|
|
|
392
358
|
function getPenultimate(arr) {
|
|
393
359
|
if (arr.length > 1) {
|
|
@@ -407,25 +373,27 @@
|
|
|
407
373
|
|
|
408
374
|
|
|
409
375
|
function skip(chars) {
|
|
410
|
-
return
|
|
411
|
-
|
|
376
|
+
return (text, index, opts) => {
|
|
377
|
+
const backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
|
|
412
378
|
// to check for failures (did someone say monads?).
|
|
413
379
|
|
|
414
380
|
if (index === false) {
|
|
415
381
|
return false;
|
|
416
382
|
}
|
|
417
383
|
|
|
418
|
-
|
|
419
|
-
|
|
384
|
+
const {
|
|
385
|
+
length
|
|
386
|
+
} = text;
|
|
387
|
+
let cursor = index;
|
|
420
388
|
|
|
421
389
|
while (cursor >= 0 && cursor < length) {
|
|
422
|
-
|
|
390
|
+
const c = text.charAt(cursor);
|
|
423
391
|
|
|
424
392
|
if (chars instanceof RegExp) {
|
|
425
393
|
if (!chars.test(c)) {
|
|
426
394
|
return cursor;
|
|
427
395
|
}
|
|
428
|
-
} else if (chars.
|
|
396
|
+
} else if (!chars.includes(c)) {
|
|
429
397
|
return cursor;
|
|
430
398
|
}
|
|
431
399
|
|
|
@@ -448,22 +416,22 @@
|
|
|
448
416
|
*/
|
|
449
417
|
|
|
450
418
|
|
|
451
|
-
|
|
419
|
+
const skipWhitespace = skip(/\s/);
|
|
452
420
|
/**
|
|
453
421
|
* @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
|
|
454
422
|
*/
|
|
455
423
|
|
|
456
|
-
|
|
424
|
+
const skipSpaces = skip(" \t");
|
|
457
425
|
/**
|
|
458
426
|
* @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
|
|
459
427
|
*/
|
|
460
428
|
|
|
461
|
-
|
|
429
|
+
const skipToLineEnd = skip(",; \t");
|
|
462
430
|
/**
|
|
463
431
|
* @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
|
|
464
432
|
*/
|
|
465
433
|
|
|
466
|
-
|
|
434
|
+
const skipEverythingButNewLine = skip(/[^\r\n]/);
|
|
467
435
|
/**
|
|
468
436
|
* @param {string} text
|
|
469
437
|
* @param {number | false} index
|
|
@@ -476,7 +444,7 @@
|
|
|
476
444
|
}
|
|
477
445
|
|
|
478
446
|
if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
|
|
479
|
-
for (
|
|
447
|
+
for (let i = index + 2; i < text.length; ++i) {
|
|
480
448
|
if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
|
|
481
449
|
return i + 2;
|
|
482
450
|
}
|
|
@@ -515,13 +483,13 @@
|
|
|
515
483
|
|
|
516
484
|
|
|
517
485
|
function skipNewline(text, index, opts) {
|
|
518
|
-
|
|
486
|
+
const backwards = opts && opts.backwards;
|
|
519
487
|
|
|
520
488
|
if (index === false) {
|
|
521
489
|
return false;
|
|
522
490
|
}
|
|
523
491
|
|
|
524
|
-
|
|
492
|
+
const atIndex = text.charAt(index);
|
|
525
493
|
|
|
526
494
|
if (backwards) {
|
|
527
495
|
if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
|
|
@@ -553,8 +521,8 @@
|
|
|
553
521
|
|
|
554
522
|
function hasNewline(text, index, opts) {
|
|
555
523
|
opts = opts || {};
|
|
556
|
-
|
|
557
|
-
|
|
524
|
+
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
525
|
+
const idx2 = skipNewline(text, idx, opts);
|
|
558
526
|
return idx !== idx2;
|
|
559
527
|
}
|
|
560
528
|
/**
|
|
@@ -566,7 +534,7 @@
|
|
|
566
534
|
|
|
567
535
|
|
|
568
536
|
function hasNewlineInRange(text, start, end) {
|
|
569
|
-
for (
|
|
537
|
+
for (let i = start; i < end; ++i) {
|
|
570
538
|
if (text.charAt(i) === "\n") {
|
|
571
539
|
return true;
|
|
572
540
|
}
|
|
@@ -585,7 +553,7 @@
|
|
|
585
553
|
|
|
586
554
|
function isPreviousLineEmpty(text, node, locStart) {
|
|
587
555
|
/** @type {number | false} */
|
|
588
|
-
|
|
556
|
+
let idx = locStart(node) - 1;
|
|
589
557
|
idx = skipSpaces(text, idx, {
|
|
590
558
|
backwards: true
|
|
591
559
|
});
|
|
@@ -595,7 +563,7 @@
|
|
|
595
563
|
idx = skipSpaces(text, idx, {
|
|
596
564
|
backwards: true
|
|
597
565
|
});
|
|
598
|
-
|
|
566
|
+
const idx2 = skipNewline(text, idx, {
|
|
599
567
|
backwards: true
|
|
600
568
|
});
|
|
601
569
|
return idx !== idx2;
|
|
@@ -609,10 +577,10 @@
|
|
|
609
577
|
|
|
610
578
|
function isNextLineEmptyAfterIndex(text, index) {
|
|
611
579
|
/** @type {number | false} */
|
|
612
|
-
|
|
580
|
+
let oldIdx = null;
|
|
613
581
|
/** @type {number | false} */
|
|
614
582
|
|
|
615
|
-
|
|
583
|
+
let idx = index;
|
|
616
584
|
|
|
617
585
|
while (idx !== oldIdx) {
|
|
618
586
|
// We need to skip all the potential trailing inline comments
|
|
@@ -647,10 +615,10 @@
|
|
|
647
615
|
|
|
648
616
|
function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
|
|
649
617
|
/** @type {number | false} */
|
|
650
|
-
|
|
618
|
+
let oldIdx = null;
|
|
651
619
|
/** @type {number | false} */
|
|
652
620
|
|
|
653
|
-
|
|
621
|
+
let nextIdx = idx;
|
|
654
622
|
|
|
655
623
|
while (nextIdx !== oldIdx) {
|
|
656
624
|
oldIdx = nextIdx;
|
|
@@ -697,7 +665,7 @@
|
|
|
697
665
|
|
|
698
666
|
function hasSpaces(text, index, opts) {
|
|
699
667
|
opts = opts || {};
|
|
700
|
-
|
|
668
|
+
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
701
669
|
return idx !== index;
|
|
702
670
|
}
|
|
703
671
|
/**
|
|
@@ -727,9 +695,9 @@
|
|
|
727
695
|
}
|
|
728
696
|
}
|
|
729
697
|
|
|
730
|
-
|
|
731
|
-
[["|>"], ["??"], ["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(
|
|
732
|
-
tier.forEach(
|
|
698
|
+
const PRECEDENCE = {};
|
|
699
|
+
[["|>"], ["??"], ["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach((tier, i) => {
|
|
700
|
+
tier.forEach(op => {
|
|
733
701
|
PRECEDENCE[op] = i;
|
|
734
702
|
});
|
|
735
703
|
});
|
|
@@ -738,18 +706,18 @@
|
|
|
738
706
|
return PRECEDENCE[op];
|
|
739
707
|
}
|
|
740
708
|
|
|
741
|
-
|
|
709
|
+
const equalityOperators = {
|
|
742
710
|
"==": true,
|
|
743
711
|
"!=": true,
|
|
744
712
|
"===": true,
|
|
745
713
|
"!==": true
|
|
746
714
|
};
|
|
747
|
-
|
|
715
|
+
const multiplicativeOperators = {
|
|
748
716
|
"*": true,
|
|
749
717
|
"/": true,
|
|
750
718
|
"%": true
|
|
751
719
|
};
|
|
752
|
-
|
|
720
|
+
const bitshiftOperators = {
|
|
753
721
|
">>": true,
|
|
754
722
|
">>>": true,
|
|
755
723
|
"<<": true
|
|
@@ -867,9 +835,9 @@
|
|
|
867
835
|
|
|
868
836
|
function getAlignmentSize(value, tabWidth, startIndex) {
|
|
869
837
|
startIndex = startIndex || 0;
|
|
870
|
-
|
|
838
|
+
let size = 0;
|
|
871
839
|
|
|
872
|
-
for (
|
|
840
|
+
for (let i = startIndex; i < value.length; ++i) {
|
|
873
841
|
if (value[i] === "\t") {
|
|
874
842
|
// Tabs behave in a way that they are aligned to the nearest
|
|
875
843
|
// multiple of tabWidth:
|
|
@@ -891,7 +859,7 @@
|
|
|
891
859
|
|
|
892
860
|
|
|
893
861
|
function getIndentSize(value, tabWidth) {
|
|
894
|
-
|
|
862
|
+
const lastNewlineIndex = value.lastIndexOf("\n");
|
|
895
863
|
|
|
896
864
|
if (lastNewlineIndex === -1) {
|
|
897
865
|
return 0;
|
|
@@ -915,28 +883,28 @@
|
|
|
915
883
|
function getPreferredQuote(raw, preferredQuote) {
|
|
916
884
|
// `rawContent` is the string exactly like it appeared in the input source
|
|
917
885
|
// code, without its enclosing quotes.
|
|
918
|
-
|
|
886
|
+
const rawContent = raw.slice(1, -1);
|
|
919
887
|
/** @type {{ quote: '"', regex: RegExp }} */
|
|
920
888
|
|
|
921
|
-
|
|
889
|
+
const double = {
|
|
922
890
|
quote: '"',
|
|
923
891
|
regex: /"/g
|
|
924
892
|
};
|
|
925
893
|
/** @type {{ quote: "'", regex: RegExp }} */
|
|
926
894
|
|
|
927
|
-
|
|
895
|
+
const single = {
|
|
928
896
|
quote: "'",
|
|
929
897
|
regex: /'/g
|
|
930
898
|
};
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
899
|
+
const preferred = preferredQuote === "'" ? single : double;
|
|
900
|
+
const alternate = preferred === single ? double : single;
|
|
901
|
+
let result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
|
|
934
902
|
// the string, we might want to enclose with the alternate quote instead, to
|
|
935
903
|
// minimize the number of escaped quotes.
|
|
936
904
|
|
|
937
905
|
if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
|
|
938
|
-
|
|
939
|
-
|
|
906
|
+
const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
|
|
907
|
+
const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
|
|
940
908
|
result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
|
|
941
909
|
}
|
|
942
910
|
|
|
@@ -946,13 +914,13 @@
|
|
|
946
914
|
function printString(raw, options, isDirectiveLiteral) {
|
|
947
915
|
// `rawContent` is the string exactly like it appeared in the input source
|
|
948
916
|
// code, without its enclosing quotes.
|
|
949
|
-
|
|
917
|
+
const rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
|
|
950
918
|
// the quotes on a DirectiveLiteral.
|
|
951
919
|
|
|
952
|
-
|
|
920
|
+
const canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
|
|
953
921
|
/** @type {Quote} */
|
|
954
922
|
|
|
955
|
-
|
|
923
|
+
const enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
|
|
956
924
|
// change the escape sequences they use.
|
|
957
925
|
// See https://github.com/prettier/prettier/issues/1555
|
|
958
926
|
// and https://tc39.github.io/ecma262/#directive-prologue
|
|
@@ -980,12 +948,12 @@
|
|
|
980
948
|
|
|
981
949
|
|
|
982
950
|
function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
|
|
983
|
-
|
|
951
|
+
const otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
|
|
984
952
|
|
|
985
|
-
|
|
953
|
+
const regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
|
|
986
954
|
// enclose `rawContent` with `enclosingQuote`.
|
|
987
955
|
|
|
988
|
-
|
|
956
|
+
const newContent = rawContent.replace(regex, (match, escaped, quote) => {
|
|
989
957
|
// If we matched an escape, and the escaped character is a quote of the
|
|
990
958
|
// other type than we intend to enclose the string with, there's no need for
|
|
991
959
|
// it to be escaped, so return it _without_ the backslash.
|
|
@@ -1027,56 +995,35 @@
|
|
|
1027
995
|
|
|
1028
996
|
|
|
1029
997
|
function getMaxContinuousCount(str, target) {
|
|
1030
|
-
|
|
998
|
+
const results = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
|
|
1031
999
|
|
|
1032
1000
|
if (results === null) {
|
|
1033
1001
|
return 0;
|
|
1034
1002
|
}
|
|
1035
1003
|
|
|
1036
|
-
return results.reduce(
|
|
1037
|
-
return Math.max(maxCount, result.length / target.length);
|
|
1038
|
-
}, 0);
|
|
1004
|
+
return results.reduce((maxCount, result) => Math.max(maxCount, result.length / target.length), 0);
|
|
1039
1005
|
}
|
|
1040
1006
|
|
|
1041
1007
|
function getMinNotPresentContinuousCount(str, target) {
|
|
1042
|
-
|
|
1008
|
+
const matches = str.match(new RegExp("(".concat(escapeStringRegexp(target), ")+"), "g"));
|
|
1043
1009
|
|
|
1044
1010
|
if (matches === null) {
|
|
1045
1011
|
return 0;
|
|
1046
1012
|
}
|
|
1047
1013
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
var _iteratorNormalCompletion = true;
|
|
1051
|
-
var _didIteratorError = false;
|
|
1052
|
-
var _iteratorError = undefined;
|
|
1014
|
+
const countPresent = new Map();
|
|
1015
|
+
let max = 0;
|
|
1053
1016
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
var count = match.length / target.length;
|
|
1058
|
-
countPresent.set(count, true);
|
|
1017
|
+
for (const match of matches) {
|
|
1018
|
+
const count = match.length / target.length;
|
|
1019
|
+
countPresent.set(count, true);
|
|
1059
1020
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
} catch (err) {
|
|
1065
|
-
_didIteratorError = true;
|
|
1066
|
-
_iteratorError = err;
|
|
1067
|
-
} finally {
|
|
1068
|
-
try {
|
|
1069
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1070
|
-
_iterator.return();
|
|
1071
|
-
}
|
|
1072
|
-
} finally {
|
|
1073
|
-
if (_didIteratorError) {
|
|
1074
|
-
throw _iteratorError;
|
|
1075
|
-
}
|
|
1021
|
+
if (count > max) {
|
|
1022
|
+
max = count;
|
|
1076
1023
|
}
|
|
1077
1024
|
}
|
|
1078
1025
|
|
|
1079
|
-
for (
|
|
1026
|
+
for (let i = 1; i < max; i++) {
|
|
1080
1027
|
if (!countPresent.get(i)) {
|
|
1081
1028
|
return i;
|
|
1082
1029
|
}
|
|
@@ -1104,36 +1051,20 @@
|
|
|
1104
1051
|
}
|
|
1105
1052
|
|
|
1106
1053
|
function hasIgnoreComment(path) {
|
|
1107
|
-
|
|
1054
|
+
const node = path.getValue();
|
|
1108
1055
|
return hasNodeIgnoreComment(node);
|
|
1109
1056
|
}
|
|
1110
1057
|
|
|
1111
1058
|
function hasNodeIgnoreComment(node) {
|
|
1112
|
-
return node && node.comments && node.comments.length > 0 && node.comments.some(
|
|
1113
|
-
return comment.value.trim() === "prettier-ignore";
|
|
1114
|
-
});
|
|
1059
|
+
return node && (node.comments && node.comments.length > 0 && node.comments.some(comment => isNodeIgnoreComment(comment) && !comment.unignore) || node.prettierIgnore);
|
|
1115
1060
|
}
|
|
1116
1061
|
|
|
1117
|
-
function
|
|
1118
|
-
|
|
1119
|
-
types = types.slice();
|
|
1120
|
-
|
|
1121
|
-
while (types.length) {
|
|
1122
|
-
var parent = path.getParentNode(index);
|
|
1123
|
-
var type = types.shift();
|
|
1124
|
-
|
|
1125
|
-
if (!parent || parent.type !== type) {
|
|
1126
|
-
return false;
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
index++;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
return true;
|
|
1062
|
+
function isNodeIgnoreComment(comment) {
|
|
1063
|
+
return comment.value.trim() === "prettier-ignore";
|
|
1133
1064
|
}
|
|
1134
1065
|
|
|
1135
1066
|
function addCommentHelper(node, comment) {
|
|
1136
|
-
|
|
1067
|
+
const comments = node.comments || (node.comments = []);
|
|
1137
1068
|
comments.push(comment);
|
|
1138
1069
|
comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
|
|
1139
1070
|
// We already "print" it via the raw text, we don't need to re-print it as a
|
|
@@ -1163,8 +1094,8 @@
|
|
|
1163
1094
|
}
|
|
1164
1095
|
|
|
1165
1096
|
function isWithinParentArrayProperty(path, propertyName) {
|
|
1166
|
-
|
|
1167
|
-
|
|
1097
|
+
const node = path.getValue();
|
|
1098
|
+
const parent = path.getParentNode();
|
|
1168
1099
|
|
|
1169
1100
|
if (parent == null) {
|
|
1170
1101
|
return false;
|
|
@@ -1174,93 +1105,71 @@
|
|
|
1174
1105
|
return false;
|
|
1175
1106
|
}
|
|
1176
1107
|
|
|
1177
|
-
|
|
1108
|
+
const key = path.getName();
|
|
1178
1109
|
return parent[propertyName][key] === node;
|
|
1179
1110
|
}
|
|
1180
1111
|
|
|
1181
1112
|
function replaceEndOfLineWith(text, replacement) {
|
|
1182
|
-
|
|
1183
|
-
var _iteratorNormalCompletion2 = true;
|
|
1184
|
-
var _didIteratorError2 = false;
|
|
1185
|
-
var _iteratorError2 = undefined;
|
|
1113
|
+
const parts = [];
|
|
1186
1114
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
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
|
-
}
|
|
1115
|
+
for (const part of text.split("\n")) {
|
|
1116
|
+
if (parts.length !== 0) {
|
|
1117
|
+
parts.push(replacement);
|
|
1209
1118
|
}
|
|
1119
|
+
|
|
1120
|
+
parts.push(part);
|
|
1210
1121
|
}
|
|
1211
1122
|
|
|
1212
1123
|
return parts;
|
|
1213
1124
|
}
|
|
1214
1125
|
|
|
1215
1126
|
var util = {
|
|
1216
|
-
replaceEndOfLineWith
|
|
1217
|
-
getStringWidth
|
|
1218
|
-
getMaxContinuousCount
|
|
1219
|
-
getMinNotPresentContinuousCount
|
|
1220
|
-
getPrecedence
|
|
1221
|
-
shouldFlatten
|
|
1222
|
-
isBitwiseOperator
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
addTrailingComment: addTrailingComment,
|
|
1259
|
-
isWithinParentArrayProperty: isWithinParentArrayProperty
|
|
1127
|
+
replaceEndOfLineWith,
|
|
1128
|
+
getStringWidth,
|
|
1129
|
+
getMaxContinuousCount,
|
|
1130
|
+
getMinNotPresentContinuousCount,
|
|
1131
|
+
getPrecedence,
|
|
1132
|
+
shouldFlatten,
|
|
1133
|
+
isBitwiseOperator,
|
|
1134
|
+
getPenultimate,
|
|
1135
|
+
getLast,
|
|
1136
|
+
getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
|
|
1137
|
+
getNextNonSpaceNonCommentCharacterIndex,
|
|
1138
|
+
getNextNonSpaceNonCommentCharacter,
|
|
1139
|
+
skip,
|
|
1140
|
+
skipWhitespace,
|
|
1141
|
+
skipSpaces,
|
|
1142
|
+
skipToLineEnd,
|
|
1143
|
+
skipEverythingButNewLine,
|
|
1144
|
+
skipInlineComment,
|
|
1145
|
+
skipTrailingComment,
|
|
1146
|
+
skipNewline,
|
|
1147
|
+
isNextLineEmptyAfterIndex,
|
|
1148
|
+
isNextLineEmpty,
|
|
1149
|
+
isPreviousLineEmpty,
|
|
1150
|
+
hasNewline,
|
|
1151
|
+
hasNewlineInRange,
|
|
1152
|
+
hasSpaces,
|
|
1153
|
+
setLocStart,
|
|
1154
|
+
setLocEnd,
|
|
1155
|
+
startsWithNoLookaheadToken,
|
|
1156
|
+
getAlignmentSize,
|
|
1157
|
+
getIndentSize,
|
|
1158
|
+
getPreferredQuote,
|
|
1159
|
+
printString,
|
|
1160
|
+
printNumber,
|
|
1161
|
+
hasIgnoreComment,
|
|
1162
|
+
hasNodeIgnoreComment,
|
|
1163
|
+
isNodeIgnoreComment,
|
|
1164
|
+
makeString,
|
|
1165
|
+
addLeadingComment,
|
|
1166
|
+
addDanglingComment,
|
|
1167
|
+
addTrailingComment,
|
|
1168
|
+
isWithinParentArrayProperty
|
|
1260
1169
|
};
|
|
1261
1170
|
|
|
1262
1171
|
function guessEndOfLine(text) {
|
|
1263
|
-
|
|
1172
|
+
const index = text.indexOf("\r");
|
|
1264
1173
|
|
|
1265
1174
|
if (index >= 0) {
|
|
1266
1175
|
return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
|
|
@@ -1283,20 +1192,26 @@
|
|
|
1283
1192
|
}
|
|
1284
1193
|
|
|
1285
1194
|
var endOfLine = {
|
|
1286
|
-
guessEndOfLine
|
|
1287
|
-
convertEndOfLineToChars
|
|
1195
|
+
guessEndOfLine,
|
|
1196
|
+
convertEndOfLineToChars
|
|
1288
1197
|
};
|
|
1289
1198
|
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1199
|
+
const {
|
|
1200
|
+
getStringWidth: getStringWidth$1
|
|
1201
|
+
} = util;
|
|
1202
|
+
const {
|
|
1203
|
+
convertEndOfLineToChars: convertEndOfLineToChars$1
|
|
1204
|
+
} = endOfLine;
|
|
1205
|
+
const {
|
|
1206
|
+
concat: concat$1,
|
|
1207
|
+
fill: fill$1,
|
|
1208
|
+
cursor: cursor$1
|
|
1209
|
+
} = docBuilders;
|
|
1295
1210
|
/** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
|
|
1296
1211
|
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1212
|
+
let groupModeMap;
|
|
1213
|
+
const MODE_BREAK = 1;
|
|
1214
|
+
const MODE_FLAT = 2;
|
|
1300
1215
|
|
|
1301
1216
|
function rootIndent() {
|
|
1302
1217
|
return {
|
|
@@ -1319,76 +1234,56 @@
|
|
|
1319
1234
|
root: ind
|
|
1320
1235
|
}) : typeof n === "string" ? generateInd(ind, {
|
|
1321
1236
|
type: "stringAlign",
|
|
1322
|
-
n
|
|
1237
|
+
n
|
|
1323
1238
|
}, options) : generateInd(ind, {
|
|
1324
1239
|
type: "numberAlign",
|
|
1325
|
-
n
|
|
1240
|
+
n
|
|
1326
1241
|
}, options);
|
|
1327
1242
|
}
|
|
1328
1243
|
|
|
1329
1244
|
function generateInd(ind, newPart, options) {
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1245
|
+
const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
|
|
1246
|
+
let value = "";
|
|
1247
|
+
let length = 0;
|
|
1248
|
+
let lastTabs = 0;
|
|
1249
|
+
let lastSpaces = 0;
|
|
1250
|
+
|
|
1251
|
+
for (const part of queue) {
|
|
1252
|
+
switch (part.type) {
|
|
1253
|
+
case "indent":
|
|
1254
|
+
flush();
|
|
1255
|
+
|
|
1256
|
+
if (options.useTabs) {
|
|
1257
|
+
addTabs(1);
|
|
1258
|
+
} else {
|
|
1259
|
+
addSpaces(options.tabWidth);
|
|
1260
|
+
}
|
|
1346
1261
|
|
|
1347
|
-
|
|
1348
|
-
addTabs(1);
|
|
1349
|
-
} else {
|
|
1350
|
-
addSpaces(options.tabWidth);
|
|
1351
|
-
}
|
|
1262
|
+
break;
|
|
1352
1263
|
|
|
1353
|
-
|
|
1264
|
+
case "stringAlign":
|
|
1265
|
+
flush();
|
|
1266
|
+
value += part.n;
|
|
1267
|
+
length += part.n.length;
|
|
1268
|
+
break;
|
|
1354
1269
|
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
break;
|
|
1270
|
+
case "numberAlign":
|
|
1271
|
+
lastTabs += 1;
|
|
1272
|
+
lastSpaces += part.n;
|
|
1273
|
+
break;
|
|
1360
1274
|
|
|
1361
|
-
|
|
1362
|
-
lastTabs += 1;
|
|
1363
|
-
lastSpaces += part.n;
|
|
1364
|
-
break;
|
|
1365
|
-
|
|
1366
|
-
/* istanbul ignore next */
|
|
1275
|
+
/* istanbul ignore next */
|
|
1367
1276
|
|
|
1368
|
-
|
|
1369
|
-
|
|
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
|
-
}
|
|
1277
|
+
default:
|
|
1278
|
+
throw new Error("Unexpected type '".concat(part.type, "'"));
|
|
1384
1279
|
}
|
|
1385
1280
|
}
|
|
1386
1281
|
|
|
1387
1282
|
flushSpaces();
|
|
1388
1283
|
return Object.assign({}, ind, {
|
|
1389
|
-
value
|
|
1390
|
-
length
|
|
1391
|
-
queue
|
|
1284
|
+
value,
|
|
1285
|
+
length,
|
|
1286
|
+
queue
|
|
1392
1287
|
});
|
|
1393
1288
|
|
|
1394
1289
|
function addTabs(count) {
|
|
@@ -1436,14 +1331,14 @@
|
|
|
1436
1331
|
return 0;
|
|
1437
1332
|
}
|
|
1438
1333
|
|
|
1439
|
-
|
|
1334
|
+
let trimCount = 0; // Trim whitespace at the end of line
|
|
1440
1335
|
|
|
1441
1336
|
while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[ \t]*$/)) {
|
|
1442
1337
|
trimCount += out.pop().length;
|
|
1443
1338
|
}
|
|
1444
1339
|
|
|
1445
1340
|
if (out.length && typeof out[out.length - 1] === "string") {
|
|
1446
|
-
|
|
1341
|
+
const trimmed = out[out.length - 1].replace(/[ \t]*$/, "");
|
|
1447
1342
|
trimCount += out[out.length - 1].length - trimmed.length;
|
|
1448
1343
|
out[out.length - 1] = trimmed;
|
|
1449
1344
|
}
|
|
@@ -1452,11 +1347,11 @@
|
|
|
1452
1347
|
}
|
|
1453
1348
|
|
|
1454
1349
|
function fits(next, restCommands, width, options, mustBeFlat) {
|
|
1455
|
-
|
|
1456
|
-
|
|
1350
|
+
let restIdx = restCommands.length;
|
|
1351
|
+
const cmds = [next]; // `out` is only used for width counting because `trim` requires to look
|
|
1457
1352
|
// backwards for space characters.
|
|
1458
1353
|
|
|
1459
|
-
|
|
1354
|
+
const out = [];
|
|
1460
1355
|
|
|
1461
1356
|
while (width >= 0) {
|
|
1462
1357
|
if (cmds.length === 0) {
|
|
@@ -1469,10 +1364,7 @@
|
|
|
1469
1364
|
continue;
|
|
1470
1365
|
}
|
|
1471
1366
|
|
|
1472
|
-
|
|
1473
|
-
var ind = x[0];
|
|
1474
|
-
var mode = x[1];
|
|
1475
|
-
var doc = x[2];
|
|
1367
|
+
const [ind, mode, doc] = cmds.pop();
|
|
1476
1368
|
|
|
1477
1369
|
if (typeof doc === "string") {
|
|
1478
1370
|
out.push(doc);
|
|
@@ -1480,7 +1372,7 @@
|
|
|
1480
1372
|
} else {
|
|
1481
1373
|
switch (doc.type) {
|
|
1482
1374
|
case "concat":
|
|
1483
|
-
for (
|
|
1375
|
+
for (let i = doc.parts.length - 1; i >= 0; i--) {
|
|
1484
1376
|
cmds.push([ind, mode, doc.parts[i]]);
|
|
1485
1377
|
}
|
|
1486
1378
|
|
|
@@ -1512,15 +1404,15 @@
|
|
|
1512
1404
|
break;
|
|
1513
1405
|
|
|
1514
1406
|
case "fill":
|
|
1515
|
-
for (
|
|
1516
|
-
cmds.push([ind, mode, doc.parts[
|
|
1407
|
+
for (let i = doc.parts.length - 1; i >= 0; i--) {
|
|
1408
|
+
cmds.push([ind, mode, doc.parts[i]]);
|
|
1517
1409
|
}
|
|
1518
1410
|
|
|
1519
1411
|
break;
|
|
1520
1412
|
|
|
1521
1413
|
case "if-break":
|
|
1522
1414
|
{
|
|
1523
|
-
|
|
1415
|
+
const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
|
|
1524
1416
|
|
|
1525
1417
|
if (groupMode === MODE_BREAK) {
|
|
1526
1418
|
if (doc.breakContents) {
|
|
@@ -1566,45 +1458,42 @@
|
|
|
1566
1458
|
|
|
1567
1459
|
function printDocToString(doc, options) {
|
|
1568
1460
|
groupModeMap = {};
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1461
|
+
const width = options.printWidth;
|
|
1462
|
+
const newLine = convertEndOfLineToChars$1(options.endOfLine);
|
|
1463
|
+
let pos = 0; // cmds is basically a stack. We've turned a recursive call into a
|
|
1572
1464
|
// while loop which is much faster. The while loop below adds new
|
|
1573
1465
|
// cmds to the array instead of recursively calling `print`.
|
|
1574
1466
|
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1467
|
+
const cmds = [[rootIndent(), MODE_BREAK, doc]];
|
|
1468
|
+
const out = [];
|
|
1469
|
+
let shouldRemeasure = false;
|
|
1470
|
+
let lineSuffix = [];
|
|
1579
1471
|
|
|
1580
1472
|
while (cmds.length !== 0) {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
if (typeof _doc === "string") {
|
|
1587
|
-
out.push(_doc);
|
|
1588
|
-
pos += getStringWidth$1(_doc);
|
|
1473
|
+
const [ind, mode, doc] = cmds.pop();
|
|
1474
|
+
|
|
1475
|
+
if (typeof doc === "string") {
|
|
1476
|
+
out.push(doc);
|
|
1477
|
+
pos += getStringWidth$1(doc);
|
|
1589
1478
|
} else {
|
|
1590
|
-
switch (
|
|
1479
|
+
switch (doc.type) {
|
|
1591
1480
|
case "cursor":
|
|
1592
1481
|
out.push(cursor$1.placeholder);
|
|
1593
1482
|
break;
|
|
1594
1483
|
|
|
1595
1484
|
case "concat":
|
|
1596
|
-
for (
|
|
1597
|
-
cmds.push([ind, mode,
|
|
1485
|
+
for (let i = doc.parts.length - 1; i >= 0; i--) {
|
|
1486
|
+
cmds.push([ind, mode, doc.parts[i]]);
|
|
1598
1487
|
}
|
|
1599
1488
|
|
|
1600
1489
|
break;
|
|
1601
1490
|
|
|
1602
1491
|
case "indent":
|
|
1603
|
-
cmds.push([makeIndent(ind, options), mode,
|
|
1492
|
+
cmds.push([makeIndent(ind, options), mode, doc.contents]);
|
|
1604
1493
|
break;
|
|
1605
1494
|
|
|
1606
1495
|
case "align":
|
|
1607
|
-
cmds.push([makeAlign(ind,
|
|
1496
|
+
cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
|
|
1608
1497
|
break;
|
|
1609
1498
|
|
|
1610
1499
|
case "trim":
|
|
@@ -1615,7 +1504,7 @@
|
|
|
1615
1504
|
switch (mode) {
|
|
1616
1505
|
case MODE_FLAT:
|
|
1617
1506
|
if (!shouldRemeasure) {
|
|
1618
|
-
cmds.push([ind,
|
|
1507
|
+
cmds.push([ind, doc.break ? MODE_BREAK : MODE_FLAT, doc.contents]);
|
|
1619
1508
|
break;
|
|
1620
1509
|
}
|
|
1621
1510
|
|
|
@@ -1624,10 +1513,10 @@
|
|
|
1624
1513
|
case MODE_BREAK:
|
|
1625
1514
|
{
|
|
1626
1515
|
shouldRemeasure = false;
|
|
1627
|
-
|
|
1628
|
-
|
|
1516
|
+
const next = [ind, MODE_FLAT, doc.contents];
|
|
1517
|
+
const rem = width - pos;
|
|
1629
1518
|
|
|
1630
|
-
if (!
|
|
1519
|
+
if (!doc.break && fits(next, cmds, rem, options)) {
|
|
1631
1520
|
cmds.push(next);
|
|
1632
1521
|
} else {
|
|
1633
1522
|
// Expanded states are a rare case where a document
|
|
@@ -1637,20 +1526,20 @@
|
|
|
1637
1526
|
// representation first to the most expanded. If a
|
|
1638
1527
|
// group has these, we need to manually go through
|
|
1639
1528
|
// these states and find the first one that fits.
|
|
1640
|
-
if (
|
|
1641
|
-
|
|
1529
|
+
if (doc.expandedStates) {
|
|
1530
|
+
const mostExpanded = doc.expandedStates[doc.expandedStates.length - 1];
|
|
1642
1531
|
|
|
1643
|
-
if (
|
|
1532
|
+
if (doc.break) {
|
|
1644
1533
|
cmds.push([ind, MODE_BREAK, mostExpanded]);
|
|
1645
1534
|
break;
|
|
1646
1535
|
} else {
|
|
1647
|
-
for (
|
|
1648
|
-
if (
|
|
1536
|
+
for (let i = 1; i < doc.expandedStates.length + 1; i++) {
|
|
1537
|
+
if (i >= doc.expandedStates.length) {
|
|
1649
1538
|
cmds.push([ind, MODE_BREAK, mostExpanded]);
|
|
1650
1539
|
break;
|
|
1651
1540
|
} else {
|
|
1652
|
-
|
|
1653
|
-
|
|
1541
|
+
const state = doc.expandedStates[i];
|
|
1542
|
+
const cmd = [ind, MODE_FLAT, state];
|
|
1654
1543
|
|
|
1655
1544
|
if (fits(cmd, cmds, rem, options)) {
|
|
1656
1545
|
cmds.push(cmd);
|
|
@@ -1660,7 +1549,7 @@
|
|
|
1660
1549
|
}
|
|
1661
1550
|
}
|
|
1662
1551
|
} else {
|
|
1663
|
-
cmds.push([ind, MODE_BREAK,
|
|
1552
|
+
cmds.push([ind, MODE_BREAK, doc.contents]);
|
|
1664
1553
|
}
|
|
1665
1554
|
}
|
|
1666
1555
|
|
|
@@ -1668,8 +1557,8 @@
|
|
|
1668
1557
|
}
|
|
1669
1558
|
}
|
|
1670
1559
|
|
|
1671
|
-
if (
|
|
1672
|
-
groupModeMap[
|
|
1560
|
+
if (doc.id) {
|
|
1561
|
+
groupModeMap[doc.id] = cmds[cmds.length - 1][1];
|
|
1673
1562
|
}
|
|
1674
1563
|
|
|
1675
1564
|
break;
|
|
@@ -1696,18 +1585,19 @@
|
|
|
1696
1585
|
|
|
1697
1586
|
case "fill":
|
|
1698
1587
|
{
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1588
|
+
const rem = width - pos;
|
|
1589
|
+
const {
|
|
1590
|
+
parts
|
|
1591
|
+
} = doc;
|
|
1702
1592
|
|
|
1703
1593
|
if (parts.length === 0) {
|
|
1704
1594
|
break;
|
|
1705
1595
|
}
|
|
1706
1596
|
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1597
|
+
const [content, whitespace] = parts;
|
|
1598
|
+
const contentFlatCmd = [ind, MODE_FLAT, content];
|
|
1599
|
+
const contentBreakCmd = [ind, MODE_BREAK, content];
|
|
1600
|
+
const contentFits = fits(contentFlatCmd, [], rem, options, true);
|
|
1711
1601
|
|
|
1712
1602
|
if (parts.length === 1) {
|
|
1713
1603
|
if (contentFits) {
|
|
@@ -1719,9 +1609,8 @@
|
|
|
1719
1609
|
break;
|
|
1720
1610
|
}
|
|
1721
1611
|
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
|
|
1612
|
+
const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
|
|
1613
|
+
const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
|
|
1725
1614
|
|
|
1726
1615
|
if (parts.length === 2) {
|
|
1727
1616
|
if (contentFits) {
|
|
@@ -1735,16 +1624,16 @@
|
|
|
1735
1624
|
break;
|
|
1736
1625
|
} // At this point we've handled the first pair (context, separator)
|
|
1737
1626
|
// and will create a new fill doc for the rest of the content.
|
|
1738
|
-
// Ideally we wouldn't mutate the array here but
|
|
1627
|
+
// Ideally we wouldn't mutate the array here but copying all the
|
|
1739
1628
|
// elements to a new array would make this algorithm quadratic,
|
|
1740
1629
|
// which is unusable for large arrays (e.g. large texts in JSX).
|
|
1741
1630
|
|
|
1742
1631
|
|
|
1743
1632
|
parts.splice(0, 2);
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1633
|
+
const remainingCmd = [ind, mode, fill$1(parts)];
|
|
1634
|
+
const secondContent = parts[0];
|
|
1635
|
+
const firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$1([content, whitespace, secondContent])];
|
|
1636
|
+
const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, options, true);
|
|
1748
1637
|
|
|
1749
1638
|
if (firstAndSecondContentFits) {
|
|
1750
1639
|
cmds.push(remainingCmd);
|
|
@@ -1765,17 +1654,17 @@
|
|
|
1765
1654
|
|
|
1766
1655
|
case "if-break":
|
|
1767
1656
|
{
|
|
1768
|
-
|
|
1657
|
+
const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
|
|
1769
1658
|
|
|
1770
1659
|
if (groupMode === MODE_BREAK) {
|
|
1771
|
-
if (
|
|
1772
|
-
cmds.push([ind, mode,
|
|
1660
|
+
if (doc.breakContents) {
|
|
1661
|
+
cmds.push([ind, mode, doc.breakContents]);
|
|
1773
1662
|
}
|
|
1774
1663
|
}
|
|
1775
1664
|
|
|
1776
1665
|
if (groupMode === MODE_FLAT) {
|
|
1777
|
-
if (
|
|
1778
|
-
cmds.push([ind, mode,
|
|
1666
|
+
if (doc.flatContents) {
|
|
1667
|
+
cmds.push([ind, mode, doc.flatContents]);
|
|
1779
1668
|
}
|
|
1780
1669
|
}
|
|
1781
1670
|
|
|
@@ -1783,7 +1672,7 @@
|
|
|
1783
1672
|
}
|
|
1784
1673
|
|
|
1785
1674
|
case "line-suffix":
|
|
1786
|
-
lineSuffix.push([ind, mode,
|
|
1675
|
+
lineSuffix.push([ind, mode, doc.contents]);
|
|
1787
1676
|
break;
|
|
1788
1677
|
|
|
1789
1678
|
case "line-suffix-boundary":
|
|
@@ -1799,8 +1688,8 @@
|
|
|
1799
1688
|
case "line":
|
|
1800
1689
|
switch (mode) {
|
|
1801
1690
|
case MODE_FLAT:
|
|
1802
|
-
if (!
|
|
1803
|
-
if (!
|
|
1691
|
+
if (!doc.hard) {
|
|
1692
|
+
if (!doc.soft) {
|
|
1804
1693
|
out.push(" ");
|
|
1805
1694
|
pos += 1;
|
|
1806
1695
|
}
|
|
@@ -1820,13 +1709,13 @@
|
|
|
1820
1709
|
|
|
1821
1710
|
case MODE_BREAK:
|
|
1822
1711
|
if (lineSuffix.length) {
|
|
1823
|
-
cmds.push([ind, mode,
|
|
1824
|
-
|
|
1712
|
+
cmds.push([ind, mode, doc]);
|
|
1713
|
+
cmds.push(...lineSuffix.reverse());
|
|
1825
1714
|
lineSuffix = [];
|
|
1826
1715
|
break;
|
|
1827
1716
|
}
|
|
1828
1717
|
|
|
1829
|
-
if (
|
|
1718
|
+
if (doc.literal) {
|
|
1830
1719
|
if (ind.root) {
|
|
1831
1720
|
out.push(newLine, ind.root.value);
|
|
1832
1721
|
pos = ind.root.length;
|
|
@@ -1848,13 +1737,13 @@
|
|
|
1848
1737
|
}
|
|
1849
1738
|
}
|
|
1850
1739
|
|
|
1851
|
-
|
|
1740
|
+
const cursorPlaceholderIndex = out.indexOf(cursor$1.placeholder);
|
|
1852
1741
|
|
|
1853
1742
|
if (cursorPlaceholderIndex !== -1) {
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1743
|
+
const otherCursorPlaceholderIndex = out.indexOf(cursor$1.placeholder, cursorPlaceholderIndex + 1);
|
|
1744
|
+
const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
|
|
1745
|
+
const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
|
|
1746
|
+
const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
|
|
1858
1747
|
return {
|
|
1859
1748
|
formatted: beforeCursor + aroundCursor + afterCursor,
|
|
1860
1749
|
cursorNodeStart: beforeCursor.length,
|
|
@@ -1868,32 +1757,32 @@
|
|
|
1868
1757
|
}
|
|
1869
1758
|
|
|
1870
1759
|
var docPrinter = {
|
|
1871
|
-
printDocToString
|
|
1760
|
+
printDocToString
|
|
1872
1761
|
};
|
|
1873
1762
|
|
|
1874
|
-
|
|
1763
|
+
const traverseDocOnExitStackMarker = {};
|
|
1875
1764
|
|
|
1876
1765
|
function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
|
|
1877
|
-
|
|
1766
|
+
const docsStack = [doc];
|
|
1878
1767
|
|
|
1879
1768
|
while (docsStack.length !== 0) {
|
|
1880
|
-
|
|
1769
|
+
const doc = docsStack.pop();
|
|
1881
1770
|
|
|
1882
|
-
if (
|
|
1771
|
+
if (doc === traverseDocOnExitStackMarker) {
|
|
1883
1772
|
onExit(docsStack.pop());
|
|
1884
1773
|
continue;
|
|
1885
1774
|
}
|
|
1886
1775
|
|
|
1887
|
-
|
|
1776
|
+
let shouldRecurse = true;
|
|
1888
1777
|
|
|
1889
1778
|
if (onEnter) {
|
|
1890
|
-
if (onEnter(
|
|
1779
|
+
if (onEnter(doc) === false) {
|
|
1891
1780
|
shouldRecurse = false;
|
|
1892
1781
|
}
|
|
1893
1782
|
}
|
|
1894
1783
|
|
|
1895
1784
|
if (onExit) {
|
|
1896
|
-
docsStack.push(
|
|
1785
|
+
docsStack.push(doc);
|
|
1897
1786
|
docsStack.push(traverseDocOnExitStackMarker);
|
|
1898
1787
|
}
|
|
1899
1788
|
|
|
@@ -1902,28 +1791,28 @@
|
|
|
1902
1791
|
// the parts need to be pushed onto the stack in reverse order,
|
|
1903
1792
|
// so that they are processed in the original order
|
|
1904
1793
|
// when the stack is popped.
|
|
1905
|
-
if (
|
|
1906
|
-
for (
|
|
1907
|
-
docsStack.push(
|
|
1794
|
+
if (doc.type === "concat" || doc.type === "fill") {
|
|
1795
|
+
for (let ic = doc.parts.length, i = ic - 1; i >= 0; --i) {
|
|
1796
|
+
docsStack.push(doc.parts[i]);
|
|
1908
1797
|
}
|
|
1909
|
-
} else if (
|
|
1910
|
-
if (
|
|
1911
|
-
docsStack.push(
|
|
1798
|
+
} else if (doc.type === "if-break") {
|
|
1799
|
+
if (doc.flatContents) {
|
|
1800
|
+
docsStack.push(doc.flatContents);
|
|
1912
1801
|
}
|
|
1913
1802
|
|
|
1914
|
-
if (
|
|
1915
|
-
docsStack.push(
|
|
1803
|
+
if (doc.breakContents) {
|
|
1804
|
+
docsStack.push(doc.breakContents);
|
|
1916
1805
|
}
|
|
1917
|
-
} else if (
|
|
1806
|
+
} else if (doc.type === "group" && doc.expandedStates) {
|
|
1918
1807
|
if (shouldTraverseConditionalGroups) {
|
|
1919
|
-
for (
|
|
1920
|
-
docsStack.push(
|
|
1808
|
+
for (let ic = doc.expandedStates.length, i = ic - 1; i >= 0; --i) {
|
|
1809
|
+
docsStack.push(doc.expandedStates[i]);
|
|
1921
1810
|
}
|
|
1922
1811
|
} else {
|
|
1923
|
-
docsStack.push(
|
|
1812
|
+
docsStack.push(doc.contents);
|
|
1924
1813
|
}
|
|
1925
|
-
} else if (
|
|
1926
|
-
docsStack.push(
|
|
1814
|
+
} else if (doc.contents) {
|
|
1815
|
+
docsStack.push(doc.contents);
|
|
1927
1816
|
}
|
|
1928
1817
|
}
|
|
1929
1818
|
}
|
|
@@ -1931,23 +1820,21 @@
|
|
|
1931
1820
|
|
|
1932
1821
|
function mapDoc(doc, cb) {
|
|
1933
1822
|
if (doc.type === "concat" || doc.type === "fill") {
|
|
1934
|
-
|
|
1935
|
-
return mapDoc(part, cb);
|
|
1936
|
-
});
|
|
1823
|
+
const parts = doc.parts.map(part => mapDoc(part, cb));
|
|
1937
1824
|
return cb(Object.assign({}, doc, {
|
|
1938
|
-
parts
|
|
1825
|
+
parts
|
|
1939
1826
|
}));
|
|
1940
1827
|
} else if (doc.type === "if-break") {
|
|
1941
|
-
|
|
1942
|
-
|
|
1828
|
+
const breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
|
|
1829
|
+
const flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
|
|
1943
1830
|
return cb(Object.assign({}, doc, {
|
|
1944
|
-
breakContents
|
|
1945
|
-
flatContents
|
|
1831
|
+
breakContents,
|
|
1832
|
+
flatContents
|
|
1946
1833
|
}));
|
|
1947
1834
|
} else if (doc.contents) {
|
|
1948
|
-
|
|
1835
|
+
const contents = mapDoc(doc.contents, cb);
|
|
1949
1836
|
return cb(Object.assign({}, doc, {
|
|
1950
|
-
contents
|
|
1837
|
+
contents
|
|
1951
1838
|
}));
|
|
1952
1839
|
}
|
|
1953
1840
|
|
|
@@ -1955,11 +1842,11 @@
|
|
|
1955
1842
|
}
|
|
1956
1843
|
|
|
1957
1844
|
function findInDoc(doc, fn, defaultValue) {
|
|
1958
|
-
|
|
1959
|
-
|
|
1845
|
+
let result = defaultValue;
|
|
1846
|
+
let hasStopped = false;
|
|
1960
1847
|
|
|
1961
1848
|
function findInDocOnEnterFn(doc) {
|
|
1962
|
-
|
|
1849
|
+
const maybeResult = fn(doc);
|
|
1963
1850
|
|
|
1964
1851
|
if (maybeResult !== undefined) {
|
|
1965
1852
|
hasStopped = true;
|
|
@@ -2013,7 +1900,7 @@
|
|
|
2013
1900
|
|
|
2014
1901
|
function breakParentGroup(groupStack) {
|
|
2015
1902
|
if (groupStack.length > 0) {
|
|
2016
|
-
|
|
1903
|
+
const parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
|
|
2017
1904
|
// the user is expected to manually handle what breaks.
|
|
2018
1905
|
|
|
2019
1906
|
if (!parentGroup.expandedStates) {
|
|
@@ -2025,8 +1912,8 @@
|
|
|
2025
1912
|
}
|
|
2026
1913
|
|
|
2027
1914
|
function propagateBreaks(doc) {
|
|
2028
|
-
|
|
2029
|
-
|
|
1915
|
+
const alreadyVisitedSet = new Set();
|
|
1916
|
+
const groupStack = [];
|
|
2030
1917
|
|
|
2031
1918
|
function propagateBreaksOnEnterFn(doc) {
|
|
2032
1919
|
if (doc.type === "break-parent") {
|
|
@@ -2046,7 +1933,7 @@
|
|
|
2046
1933
|
|
|
2047
1934
|
function propagateBreaksOnExitFn(doc) {
|
|
2048
1935
|
if (doc.type === "group") {
|
|
2049
|
-
|
|
1936
|
+
const group = groupStack.pop();
|
|
2050
1937
|
|
|
2051
1938
|
if (group.break) {
|
|
2052
1939
|
breakParentGroup(groupStack);
|
|
@@ -2080,7 +1967,7 @@
|
|
|
2080
1967
|
function stripTrailingHardline(doc) {
|
|
2081
1968
|
// HACK remove ending hardline, original PR: #1984
|
|
2082
1969
|
if (doc.type === "concat" && doc.parts.length !== 0) {
|
|
2083
|
-
|
|
1970
|
+
const lastPart = doc.parts[doc.parts.length - 1];
|
|
2084
1971
|
|
|
2085
1972
|
if (lastPart.type === "concat") {
|
|
2086
1973
|
if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
|
|
@@ -2101,28 +1988,28 @@
|
|
|
2101
1988
|
}
|
|
2102
1989
|
|
|
2103
1990
|
var docUtils = {
|
|
2104
|
-
isEmpty
|
|
2105
|
-
willBreak
|
|
2106
|
-
isLineNext
|
|
2107
|
-
traverseDoc
|
|
2108
|
-
findInDoc
|
|
2109
|
-
mapDoc
|
|
2110
|
-
propagateBreaks
|
|
2111
|
-
removeLines
|
|
2112
|
-
stripTrailingHardline
|
|
1991
|
+
isEmpty,
|
|
1992
|
+
willBreak,
|
|
1993
|
+
isLineNext,
|
|
1994
|
+
traverseDoc,
|
|
1995
|
+
findInDoc,
|
|
1996
|
+
mapDoc,
|
|
1997
|
+
propagateBreaks,
|
|
1998
|
+
removeLines,
|
|
1999
|
+
stripTrailingHardline
|
|
2113
2000
|
};
|
|
2114
2001
|
|
|
2115
2002
|
function flattenDoc(doc) {
|
|
2116
2003
|
if (doc.type === "concat") {
|
|
2117
|
-
|
|
2004
|
+
const res = [];
|
|
2118
2005
|
|
|
2119
|
-
for (
|
|
2120
|
-
|
|
2006
|
+
for (let i = 0; i < doc.parts.length; ++i) {
|
|
2007
|
+
const doc2 = doc.parts[i];
|
|
2121
2008
|
|
|
2122
2009
|
if (typeof doc2 !== "string" && doc2.type === "concat") {
|
|
2123
|
-
|
|
2010
|
+
res.push(...flattenDoc(doc2).parts);
|
|
2124
2011
|
} else {
|
|
2125
|
-
|
|
2012
|
+
const flattened = flattenDoc(doc2);
|
|
2126
2013
|
|
|
2127
2014
|
if (flattened !== "") {
|
|
2128
2015
|
res.push(flattened);
|
|
@@ -2221,27 +2108,28 @@
|
|
|
2221
2108
|
}
|
|
2222
2109
|
|
|
2223
2110
|
var docDebug = {
|
|
2224
|
-
printDocToDebug
|
|
2111
|
+
printDocToDebug(doc) {
|
|
2225
2112
|
return printDoc(flattenDoc(doc));
|
|
2226
2113
|
}
|
|
2114
|
+
|
|
2227
2115
|
};
|
|
2228
2116
|
|
|
2229
|
-
var
|
|
2117
|
+
var document = {
|
|
2230
2118
|
builders: docBuilders,
|
|
2231
2119
|
printer: docPrinter,
|
|
2232
2120
|
utils: docUtils,
|
|
2233
2121
|
debug: docDebug
|
|
2234
2122
|
};
|
|
2235
|
-
var
|
|
2236
|
-
var
|
|
2237
|
-
var
|
|
2238
|
-
var
|
|
2239
|
-
|
|
2240
|
-
exports.builders =
|
|
2241
|
-
exports.debug =
|
|
2242
|
-
exports.default =
|
|
2243
|
-
exports.printer =
|
|
2244
|
-
exports.utils =
|
|
2123
|
+
var document_1 = document.builders;
|
|
2124
|
+
var document_2 = document.printer;
|
|
2125
|
+
var document_3 = document.utils;
|
|
2126
|
+
var document_4 = document.debug;
|
|
2127
|
+
|
|
2128
|
+
exports.builders = document_1;
|
|
2129
|
+
exports.debug = document_4;
|
|
2130
|
+
exports.default = document;
|
|
2131
|
+
exports.printer = document_2;
|
|
2132
|
+
exports.utils = document_3;
|
|
2245
2133
|
|
|
2246
2134
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2247
2135
|
|