prettier 3.0.0-alpha.3 → 3.0.0-alpha.5
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 +875 -677
- package/README.md +3 -3
- package/doc.d.ts +248 -0
- package/doc.js +314 -246
- package/doc.mjs +309 -241
- package/index.cjs +399 -229
- package/index.d.ts +903 -0
- package/index.mjs +18131 -16873
- package/internal/cli.mjs +3958 -10433
- package/internal/third-party.mjs +2948 -5593
- package/package.json +32 -1
- package/plugins/acorn-and-espree.d.ts +10 -0
- package/plugins/acorn-and-espree.js +12 -12
- package/plugins/acorn-and-espree.mjs +12 -12
- package/plugins/angular.d.ts +11 -0
- package/plugins/angular.js +2 -2
- package/plugins/angular.mjs +2 -2
- package/plugins/babel.d.ts +16 -0
- package/plugins/babel.js +12 -12
- package/plugins/babel.mjs +12 -12
- package/plugins/flow.d.ts +8 -0
- package/plugins/flow.js +20 -20
- package/plugins/flow.mjs +20 -20
- package/plugins/glimmer.d.ts +8 -0
- package/plugins/glimmer.js +18 -18
- package/plugins/glimmer.mjs +18 -18
- package/plugins/graphql.d.ts +8 -0
- package/plugins/graphql.js +7 -7
- package/plugins/graphql.mjs +7 -7
- package/plugins/html.d.ts +11 -0
- package/plugins/html.js +17 -28
- package/plugins/html.mjs +17 -28
- package/plugins/markdown.d.ts +10 -0
- package/plugins/markdown.js +28 -29
- package/plugins/markdown.mjs +28 -29
- package/plugins/meriyah.d.ts +8 -0
- package/plugins/meriyah.js +5 -6
- package/plugins/meriyah.mjs +5 -6
- package/plugins/postcss.d.ts +10 -0
- package/plugins/postcss.js +32 -43
- package/plugins/postcss.mjs +32 -43
- package/plugins/typescript.d.ts +8 -0
- package/plugins/typescript.js +18 -231
- package/plugins/typescript.mjs +18 -231
- package/plugins/yaml.d.ts +8 -0
- package/plugins/yaml.js +108 -108
- package/plugins/yaml.mjs +108 -108
- package/standalone.d.ts +33 -0
- package/standalone.js +77 -83
- package/standalone.mjs +77 -83
package/index.cjs
CHANGED
|
@@ -24,39 +24,83 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
26
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
31
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
32
|
mod
|
|
29
33
|
));
|
|
30
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
35
|
|
|
32
|
-
//
|
|
33
|
-
function
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
+
// src/utils/skip-inline-comment.js
|
|
37
|
+
function skipInlineComment(text, startIndex) {
|
|
38
|
+
if (startIndex === false) {
|
|
39
|
+
return false;
|
|
36
40
|
}
|
|
37
|
-
|
|
41
|
+
if (text.charAt(startIndex) === "/" && text.charAt(startIndex + 1) === "*") {
|
|
42
|
+
for (let i = startIndex + 2; i < text.length; ++i) {
|
|
43
|
+
if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
|
|
44
|
+
return i + 2;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return startIndex;
|
|
38
49
|
}
|
|
39
|
-
var
|
|
40
|
-
|
|
50
|
+
var skip_inline_comment_default;
|
|
51
|
+
var init_skip_inline_comment = __esm({
|
|
52
|
+
"src/utils/skip-inline-comment.js"() {
|
|
53
|
+
skip_inline_comment_default = skipInlineComment;
|
|
41
54
|
}
|
|
42
55
|
});
|
|
43
56
|
|
|
44
|
-
// src/utils/
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
// src/utils/skip-newline.js
|
|
58
|
+
function skipNewline(text, startIndex, options) {
|
|
59
|
+
const backwards = Boolean(options == null ? void 0 : options.backwards);
|
|
60
|
+
if (startIndex === false) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const character = text.charAt(startIndex);
|
|
64
|
+
if (backwards) {
|
|
65
|
+
if (text.charAt(startIndex - 1) === "\r" && character === "\n") {
|
|
66
|
+
return startIndex - 2;
|
|
67
|
+
}
|
|
68
|
+
if (character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029") {
|
|
69
|
+
return startIndex - 1;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (character === "\r" && text.charAt(startIndex + 1) === "\n") {
|
|
73
|
+
return startIndex + 2;
|
|
74
|
+
}
|
|
75
|
+
if (character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029") {
|
|
76
|
+
return startIndex + 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return startIndex;
|
|
80
|
+
}
|
|
81
|
+
var skip_newline_default;
|
|
82
|
+
var init_skip_newline = __esm({
|
|
83
|
+
"src/utils/skip-newline.js"() {
|
|
84
|
+
skip_newline_default = skipNewline;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// src/utils/skip.js
|
|
89
|
+
function skip(characters) {
|
|
90
|
+
return (text, startIndex, options) => {
|
|
91
|
+
const backwards = Boolean(options == null ? void 0 : options.backwards);
|
|
92
|
+
if (startIndex === false) {
|
|
49
93
|
return false;
|
|
50
94
|
}
|
|
51
95
|
const { length } = text;
|
|
52
|
-
let cursor =
|
|
96
|
+
let cursor = startIndex;
|
|
53
97
|
while (cursor >= 0 && cursor < length) {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
if (!
|
|
98
|
+
const character = text.charAt(cursor);
|
|
99
|
+
if (characters instanceof RegExp) {
|
|
100
|
+
if (!characters.test(character)) {
|
|
57
101
|
return cursor;
|
|
58
102
|
}
|
|
59
|
-
} else if (!
|
|
103
|
+
} else if (!characters.includes(character)) {
|
|
60
104
|
return cursor;
|
|
61
105
|
}
|
|
62
106
|
backwards ? cursor-- : cursor++;
|
|
@@ -69,7 +113,7 @@ function skip(chars) {
|
|
|
69
113
|
}
|
|
70
114
|
var skipWhitespace, skipSpaces, skipToLineEnd, skipEverythingButNewLine;
|
|
71
115
|
var init_skip = __esm({
|
|
72
|
-
"src/utils/
|
|
116
|
+
"src/utils/skip.js"() {
|
|
73
117
|
skipWhitespace = skip(/\s/);
|
|
74
118
|
skipSpaces = skip(" ");
|
|
75
119
|
skipToLineEnd = skip(",; ");
|
|
@@ -77,80 +121,28 @@ var init_skip = __esm({
|
|
|
77
121
|
}
|
|
78
122
|
});
|
|
79
123
|
|
|
80
|
-
// src/utils/
|
|
81
|
-
function
|
|
82
|
-
if (
|
|
124
|
+
// src/utils/skip-trailing-comment.js
|
|
125
|
+
function skipTrailingComment(text, startIndex) {
|
|
126
|
+
if (startIndex === false) {
|
|
83
127
|
return false;
|
|
84
128
|
}
|
|
85
|
-
if (text.charAt(
|
|
86
|
-
|
|
87
|
-
if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
|
|
88
|
-
return i + 2;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return index;
|
|
93
|
-
}
|
|
94
|
-
var skip_inline_comment_default;
|
|
95
|
-
var init_skip_inline_comment = __esm({
|
|
96
|
-
"src/utils/text/skip-inline-comment.js"() {
|
|
97
|
-
skip_inline_comment_default = skipInlineComment;
|
|
129
|
+
if (text.charAt(startIndex) === "/" && text.charAt(startIndex + 1) === "/") {
|
|
130
|
+
return skipEverythingButNewLine(text, startIndex);
|
|
98
131
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// src/utils/text/skip-trailing-comment.js
|
|
102
|
-
function skipTrailingComment(text, index) {
|
|
103
|
-
if (index === false) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
|
|
107
|
-
return skipEverythingButNewLine(text, index);
|
|
108
|
-
}
|
|
109
|
-
return index;
|
|
132
|
+
return startIndex;
|
|
110
133
|
}
|
|
111
134
|
var skip_trailing_comment_default;
|
|
112
135
|
var init_skip_trailing_comment = __esm({
|
|
113
|
-
"src/utils/
|
|
136
|
+
"src/utils/skip-trailing-comment.js"() {
|
|
114
137
|
init_skip();
|
|
115
138
|
skip_trailing_comment_default = skipTrailingComment;
|
|
116
139
|
}
|
|
117
140
|
});
|
|
118
141
|
|
|
119
|
-
// src/utils/
|
|
120
|
-
function
|
|
121
|
-
const backwards = opts && opts.backwards;
|
|
122
|
-
if (index === false) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
const atIndex = text.charAt(index);
|
|
126
|
-
if (backwards) {
|
|
127
|
-
if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
|
|
128
|
-
return index - 2;
|
|
129
|
-
}
|
|
130
|
-
if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
|
|
131
|
-
return index - 1;
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
|
|
135
|
-
return index + 2;
|
|
136
|
-
}
|
|
137
|
-
if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
|
|
138
|
-
return index + 1;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return index;
|
|
142
|
-
}
|
|
143
|
-
var skip_newline_default;
|
|
144
|
-
var init_skip_newline = __esm({
|
|
145
|
-
"src/utils/text/skip-newline.js"() {
|
|
146
|
-
skip_newline_default = skipNewline;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// src/utils/text/get-next-non-space-non-comment-character-index-with-start-index.js
|
|
151
|
-
function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
|
|
142
|
+
// src/utils/get-next-non-space-non-comment-character-index.js
|
|
143
|
+
function getNextNonSpaceNonCommentCharacterIndex(text, startIndex) {
|
|
152
144
|
let oldIdx = null;
|
|
153
|
-
let nextIdx =
|
|
145
|
+
let nextIdx = startIndex;
|
|
154
146
|
while (nextIdx !== oldIdx) {
|
|
155
147
|
oldIdx = nextIdx;
|
|
156
148
|
nextIdx = skipSpaces(text, nextIdx);
|
|
@@ -160,20 +152,110 @@ function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
|
|
|
160
152
|
}
|
|
161
153
|
return nextIdx;
|
|
162
154
|
}
|
|
163
|
-
var
|
|
164
|
-
var
|
|
165
|
-
"src/utils/
|
|
155
|
+
var get_next_non_space_non_comment_character_index_default;
|
|
156
|
+
var init_get_next_non_space_non_comment_character_index = __esm({
|
|
157
|
+
"src/utils/get-next-non-space-non-comment-character-index.js"() {
|
|
166
158
|
init_skip_inline_comment();
|
|
167
159
|
init_skip_newline();
|
|
168
160
|
init_skip_trailing_comment();
|
|
169
161
|
init_skip();
|
|
170
|
-
|
|
162
|
+
get_next_non_space_non_comment_character_index_default = getNextNonSpaceNonCommentCharacterIndex;
|
|
171
163
|
}
|
|
172
164
|
});
|
|
173
165
|
|
|
174
|
-
// src/utils/is-
|
|
175
|
-
|
|
176
|
-
|
|
166
|
+
// src/utils/is-previous-line-empty.js
|
|
167
|
+
function isPreviousLineEmpty(text, startIndex) {
|
|
168
|
+
let idx = startIndex - 1;
|
|
169
|
+
idx = skipSpaces(text, idx, { backwards: true });
|
|
170
|
+
idx = skip_newline_default(text, idx, { backwards: true });
|
|
171
|
+
idx = skipSpaces(text, idx, { backwards: true });
|
|
172
|
+
const idx2 = skip_newline_default(text, idx, { backwards: true });
|
|
173
|
+
return idx !== idx2;
|
|
174
|
+
}
|
|
175
|
+
var is_previous_line_empty_default;
|
|
176
|
+
var init_is_previous_line_empty = __esm({
|
|
177
|
+
"src/utils/is-previous-line-empty.js"() {
|
|
178
|
+
init_skip_newline();
|
|
179
|
+
init_skip();
|
|
180
|
+
is_previous_line_empty_default = isPreviousLineEmpty;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// src/utils/has-newline.js
|
|
185
|
+
function hasNewline(text, startIndex, options = {}) {
|
|
186
|
+
const idx = skipSpaces(
|
|
187
|
+
text,
|
|
188
|
+
options.backwards ? startIndex - 1 : startIndex,
|
|
189
|
+
options
|
|
190
|
+
);
|
|
191
|
+
const idx2 = skip_newline_default(text, idx, options);
|
|
192
|
+
return idx !== idx2;
|
|
193
|
+
}
|
|
194
|
+
var has_newline_default;
|
|
195
|
+
var init_has_newline = __esm({
|
|
196
|
+
"src/utils/has-newline.js"() {
|
|
197
|
+
init_skip();
|
|
198
|
+
init_skip_newline();
|
|
199
|
+
has_newline_default = hasNewline;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// src/utils/is-next-line-empty.js
|
|
204
|
+
function isNextLineEmpty(text, startIndex) {
|
|
205
|
+
let oldIdx = null;
|
|
206
|
+
let idx = startIndex;
|
|
207
|
+
while (idx !== oldIdx) {
|
|
208
|
+
oldIdx = idx;
|
|
209
|
+
idx = skipToLineEnd(text, idx);
|
|
210
|
+
idx = skip_inline_comment_default(text, idx);
|
|
211
|
+
idx = skipSpaces(text, idx);
|
|
212
|
+
}
|
|
213
|
+
idx = skip_trailing_comment_default(text, idx);
|
|
214
|
+
idx = skip_newline_default(text, idx);
|
|
215
|
+
return idx !== false && has_newline_default(text, idx);
|
|
216
|
+
}
|
|
217
|
+
var is_next_line_empty_default;
|
|
218
|
+
var init_is_next_line_empty = __esm({
|
|
219
|
+
"src/utils/is-next-line-empty.js"() {
|
|
220
|
+
init_skip_newline();
|
|
221
|
+
init_skip();
|
|
222
|
+
init_skip_inline_comment();
|
|
223
|
+
init_skip_trailing_comment();
|
|
224
|
+
init_has_newline();
|
|
225
|
+
is_next_line_empty_default = isNextLineEmpty;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// node_modules/escape-string-regexp/index.js
|
|
230
|
+
function escapeStringRegexp(string) {
|
|
231
|
+
if (typeof string !== "string") {
|
|
232
|
+
throw new TypeError("Expected a string");
|
|
233
|
+
}
|
|
234
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
235
|
+
}
|
|
236
|
+
var init_escape_string_regexp = __esm({
|
|
237
|
+
"node_modules/escape-string-regexp/index.js"() {
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// src/utils/get-max-continuous-count.js
|
|
242
|
+
function getMaxContinuousCount(text, searchString) {
|
|
243
|
+
const results = text.match(
|
|
244
|
+
new RegExp(`(${escapeStringRegexp(searchString)})+`, "g")
|
|
245
|
+
);
|
|
246
|
+
if (results === null) {
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
return results.reduce(
|
|
250
|
+
(maxCount, result) => Math.max(maxCount, result.length / searchString.length),
|
|
251
|
+
0
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
var get_max_continuous_count_default;
|
|
255
|
+
var init_get_max_continuous_count = __esm({
|
|
256
|
+
"src/utils/get-max-continuous-count.js"() {
|
|
257
|
+
init_escape_string_regexp();
|
|
258
|
+
get_max_continuous_count_default = getMaxContinuousCount;
|
|
177
259
|
}
|
|
178
260
|
});
|
|
179
261
|
|
|
@@ -208,7 +290,22 @@ function isFullwidthCodePoint(codePoint) {
|
|
|
208
290
|
if (!Number.isInteger(codePoint)) {
|
|
209
291
|
return false;
|
|
210
292
|
}
|
|
211
|
-
return codePoint >= 4352 && (codePoint <= 4447 ||
|
|
293
|
+
return codePoint >= 4352 && (codePoint <= 4447 || // Hangul Jamo
|
|
294
|
+
codePoint === 9001 || // LEFT-POINTING ANGLE BRACKET
|
|
295
|
+
codePoint === 9002 || // RIGHT-POINTING ANGLE BRACKET
|
|
296
|
+
// CJK Radicals Supplement .. Enclosed CJK Letters and Months
|
|
297
|
+
11904 <= codePoint && codePoint <= 12871 && codePoint !== 12351 || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
|
|
298
|
+
12880 <= codePoint && codePoint <= 19903 || // CJK Unified Ideographs .. Yi Radicals
|
|
299
|
+
19968 <= codePoint && codePoint <= 42182 || // Hangul Jamo Extended-A
|
|
300
|
+
43360 <= codePoint && codePoint <= 43388 || // Hangul Syllables
|
|
301
|
+
44032 <= codePoint && codePoint <= 55203 || // CJK Compatibility Ideographs
|
|
302
|
+
63744 <= codePoint && codePoint <= 64255 || // Vertical Forms
|
|
303
|
+
65040 <= codePoint && codePoint <= 65049 || // CJK Compatibility Forms .. Small Form Variants
|
|
304
|
+
65072 <= codePoint && codePoint <= 65131 || // Halfwidth and Fullwidth Forms
|
|
305
|
+
65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 || // Kana Supplement
|
|
306
|
+
110592 <= codePoint && codePoint <= 110593 || // Enclosed Ideographic Supplement
|
|
307
|
+
127488 <= codePoint && codePoint <= 127569 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
|
|
308
|
+
131072 <= codePoint && codePoint <= 262141);
|
|
212
309
|
}
|
|
213
310
|
var init_is_fullwidth_code_point = __esm({
|
|
214
311
|
"node_modules/string-width/node_modules/is-fullwidth-code-point/index.js"() {
|
|
@@ -279,83 +376,11 @@ var init_get_string_width = __esm({
|
|
|
279
376
|
}
|
|
280
377
|
});
|
|
281
378
|
|
|
282
|
-
// src/
|
|
283
|
-
function
|
|
284
|
-
return (text, index, opts) => {
|
|
285
|
-
const backwards = opts && opts.backwards;
|
|
286
|
-
if (index === false) {
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
289
|
-
const { length } = text;
|
|
290
|
-
let cursor = index;
|
|
291
|
-
while (cursor >= 0 && cursor < length) {
|
|
292
|
-
const c = text.charAt(cursor);
|
|
293
|
-
if (chars instanceof RegExp) {
|
|
294
|
-
if (!chars.test(c)) {
|
|
295
|
-
return cursor;
|
|
296
|
-
}
|
|
297
|
-
} else if (!chars.includes(c)) {
|
|
298
|
-
return cursor;
|
|
299
|
-
}
|
|
300
|
-
backwards ? cursor-- : cursor++;
|
|
301
|
-
}
|
|
302
|
-
if (cursor === -1 || cursor === length) {
|
|
303
|
-
return cursor;
|
|
304
|
-
}
|
|
305
|
-
return false;
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
function hasNewline(text, index, opts = {}) {
|
|
309
|
-
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
310
|
-
const idx2 = skip_newline_default(text, idx, opts);
|
|
311
|
-
return idx !== idx2;
|
|
312
|
-
}
|
|
313
|
-
function hasNewlineInRange(text, start, end) {
|
|
314
|
-
for (let i = start; i < end; ++i) {
|
|
315
|
-
if (text.charAt(i) === "\n") {
|
|
316
|
-
return true;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
function isPreviousLineEmpty(text, node, locStart) {
|
|
322
|
-
let idx = locStart(node) - 1;
|
|
323
|
-
idx = skipSpaces(text, idx, { backwards: true });
|
|
324
|
-
idx = skip_newline_default(text, idx, { backwards: true });
|
|
325
|
-
idx = skipSpaces(text, idx, { backwards: true });
|
|
326
|
-
const idx2 = skip_newline_default(text, idx, { backwards: true });
|
|
327
|
-
return idx !== idx2;
|
|
328
|
-
}
|
|
329
|
-
function isNextLineEmptyAfterIndex(text, index) {
|
|
330
|
-
let oldIdx = null;
|
|
331
|
-
let idx = index;
|
|
332
|
-
while (idx !== oldIdx) {
|
|
333
|
-
oldIdx = idx;
|
|
334
|
-
idx = skipToLineEnd(text, idx);
|
|
335
|
-
idx = skip_inline_comment_default(text, idx);
|
|
336
|
-
idx = skipSpaces(text, idx);
|
|
337
|
-
}
|
|
338
|
-
idx = skip_trailing_comment_default(text, idx);
|
|
339
|
-
idx = skip_newline_default(text, idx);
|
|
340
|
-
return idx !== false && hasNewline(text, idx);
|
|
341
|
-
}
|
|
342
|
-
function isNextLineEmpty(text, node, locEnd) {
|
|
343
|
-
return isNextLineEmptyAfterIndex(text, locEnd(node));
|
|
344
|
-
}
|
|
345
|
-
function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
|
|
346
|
-
return get_next_non_space_non_comment_character_index_with_start_index_default(
|
|
347
|
-
text,
|
|
348
|
-
locEnd(node)
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
function hasSpaces(text, index, opts = {}) {
|
|
352
|
-
const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
|
|
353
|
-
return idx !== index;
|
|
354
|
-
}
|
|
355
|
-
function getAlignmentSize(value, tabWidth, startIndex = 0) {
|
|
379
|
+
// src/utils/get-alignment-size.js
|
|
380
|
+
function getAlignmentSize(text, tabWidth, startIndex = 0) {
|
|
356
381
|
let size = 0;
|
|
357
|
-
for (let i = startIndex; i <
|
|
358
|
-
if (
|
|
382
|
+
for (let i = startIndex; i < text.length; ++i) {
|
|
383
|
+
if (text[i] === " ") {
|
|
359
384
|
size = size + tabWidth - size % tabWidth;
|
|
360
385
|
} else {
|
|
361
386
|
size++;
|
|
@@ -363,44 +388,141 @@ function getAlignmentSize(value, tabWidth, startIndex = 0) {
|
|
|
363
388
|
}
|
|
364
389
|
return size;
|
|
365
390
|
}
|
|
391
|
+
var get_alignment_size_default;
|
|
392
|
+
var init_get_alignment_size = __esm({
|
|
393
|
+
"src/utils/get-alignment-size.js"() {
|
|
394
|
+
get_alignment_size_default = getAlignmentSize;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// src/utils/get-indent-size.js
|
|
366
399
|
function getIndentSize(value, tabWidth) {
|
|
367
400
|
const lastNewlineIndex = value.lastIndexOf("\n");
|
|
368
401
|
if (lastNewlineIndex === -1) {
|
|
369
402
|
return 0;
|
|
370
403
|
}
|
|
371
|
-
return
|
|
404
|
+
return get_alignment_size_default(
|
|
405
|
+
// All the leading whitespaces
|
|
372
406
|
value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0],
|
|
373
407
|
tabWidth
|
|
374
408
|
);
|
|
375
409
|
}
|
|
376
|
-
|
|
410
|
+
var get_indent_size_default;
|
|
411
|
+
var init_get_indent_size = __esm({
|
|
412
|
+
"src/utils/get-indent-size.js"() {
|
|
413
|
+
init_get_alignment_size();
|
|
414
|
+
get_indent_size_default = getIndentSize;
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// src/utils/has-newline-in-range.js
|
|
419
|
+
function hasNewlineInRange(text, startIndex, endIndex) {
|
|
420
|
+
for (let i = startIndex; i < endIndex; ++i) {
|
|
421
|
+
if (text.charAt(i) === "\n") {
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
var has_newline_in_range_default;
|
|
428
|
+
var init_has_newline_in_range = __esm({
|
|
429
|
+
"src/utils/has-newline-in-range.js"() {
|
|
430
|
+
has_newline_in_range_default = hasNewlineInRange;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// src/utils/has-spaces.js
|
|
435
|
+
function hasSpaces(text, startIndex, options = {}) {
|
|
436
|
+
const idx = skipSpaces(
|
|
437
|
+
text,
|
|
438
|
+
options.backwards ? startIndex - 1 : startIndex,
|
|
439
|
+
options
|
|
440
|
+
);
|
|
441
|
+
return idx !== startIndex;
|
|
442
|
+
}
|
|
443
|
+
var has_spaces_default;
|
|
444
|
+
var init_has_spaces = __esm({
|
|
445
|
+
"src/utils/has-spaces.js"() {
|
|
446
|
+
init_skip();
|
|
447
|
+
has_spaces_default = hasSpaces;
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// src/utils/get-next-non-space-non-comment-character.js
|
|
452
|
+
function getNextNonSpaceNonCommentCharacter(text, startIndex) {
|
|
453
|
+
const index = get_next_non_space_non_comment_character_index_default(text, startIndex);
|
|
454
|
+
return index === false ? "" : text.charAt(index);
|
|
455
|
+
}
|
|
456
|
+
var get_next_non_space_non_comment_character_default;
|
|
457
|
+
var init_get_next_non_space_non_comment_character = __esm({
|
|
458
|
+
"src/utils/get-next-non-space-non-comment-character.js"() {
|
|
459
|
+
init_get_next_non_space_non_comment_character_index();
|
|
460
|
+
get_next_non_space_non_comment_character_default = getNextNonSpaceNonCommentCharacter;
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// scripts/build/shims/string-replace-all.js
|
|
465
|
+
var stringReplaceAll, string_replace_all_default;
|
|
466
|
+
var init_string_replace_all = __esm({
|
|
467
|
+
"scripts/build/shims/string-replace-all.js"() {
|
|
468
|
+
stringReplaceAll = (isOptionalObject, original, pattern, replacement) => {
|
|
469
|
+
if (isOptionalObject && (original === void 0 || original === null)) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (original.replaceAll) {
|
|
473
|
+
return original.replaceAll(pattern, replacement);
|
|
474
|
+
}
|
|
475
|
+
if (pattern.global) {
|
|
476
|
+
return original.replace(pattern, replacement);
|
|
477
|
+
}
|
|
478
|
+
return original.split(pattern).join(replacement);
|
|
479
|
+
};
|
|
480
|
+
string_replace_all_default = stringReplaceAll;
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
// src/utils/make-string.js
|
|
485
|
+
function makeString(rawText, enclosingQuote, unescapeUnnecessaryEscapes) {
|
|
377
486
|
const otherQuote = enclosingQuote === '"' ? "'" : '"';
|
|
378
487
|
const regex = /\\(.)|(["'])/gs;
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
488
|
+
const raw = string_replace_all_default(
|
|
489
|
+
/* isOptionalObject*/
|
|
490
|
+
false,
|
|
491
|
+
rawText,
|
|
492
|
+
regex,
|
|
493
|
+
(match, escaped, quote) => {
|
|
494
|
+
if (escaped === otherQuote) {
|
|
495
|
+
return escaped;
|
|
496
|
+
}
|
|
497
|
+
if (quote === enclosingQuote) {
|
|
498
|
+
return "\\" + quote;
|
|
499
|
+
}
|
|
500
|
+
if (quote) {
|
|
501
|
+
return quote;
|
|
502
|
+
}
|
|
503
|
+
return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/.test(escaped) ? escaped : "\\" + escaped;
|
|
388
504
|
}
|
|
389
|
-
return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/.test(escaped) ? escaped : "\\" + escaped;
|
|
390
|
-
});
|
|
391
|
-
return enclosingQuote + newContent + enclosingQuote;
|
|
392
|
-
}
|
|
393
|
-
function getMaxContinuousCount(str, target) {
|
|
394
|
-
const results = str.match(
|
|
395
|
-
new RegExp(`(${escapeStringRegexp(target)})+`, "g")
|
|
396
505
|
);
|
|
397
|
-
|
|
398
|
-
|
|
506
|
+
return enclosingQuote + raw + enclosingQuote;
|
|
507
|
+
}
|
|
508
|
+
var make_string_default;
|
|
509
|
+
var init_make_string = __esm({
|
|
510
|
+
"src/utils/make-string.js"() {
|
|
511
|
+
init_string_replace_all();
|
|
512
|
+
make_string_default = makeString;
|
|
399
513
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// src/main/comments/utils.js
|
|
517
|
+
function describeNodeForDebugging(node) {
|
|
518
|
+
const nodeType = node.type || node.kind || "(unknown type)";
|
|
519
|
+
let nodeName = String(
|
|
520
|
+
node.name || node.id && (typeof node.id === "object" ? node.id.name : node.id) || node.key && (typeof node.key === "object" ? node.key.name : node.key) || node.value && (typeof node.value === "object" ? "" : String(node.value)) || node.operator || ""
|
|
403
521
|
);
|
|
522
|
+
if (nodeName.length > 20) {
|
|
523
|
+
nodeName = nodeName.slice(0, 19) + "\u2026";
|
|
524
|
+
}
|
|
525
|
+
return nodeType + (nodeName ? " " + nodeName : "");
|
|
404
526
|
}
|
|
405
527
|
function addCommentHelper(node, comment) {
|
|
406
528
|
const comments = node.comments ?? (node.comments = []);
|
|
@@ -426,48 +548,31 @@ function addTrailingComment(node, comment) {
|
|
|
426
548
|
comment.trailing = true;
|
|
427
549
|
addCommentHelper(node, comment);
|
|
428
550
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
let nodeName = String(
|
|
432
|
-
node.name || node.id && (typeof node.id === "object" ? node.id.name : node.id) || node.key && (typeof node.key === "object" ? node.key.name : node.key) || node.value && (typeof node.value === "object" ? "" : String(node.value)) || node.operator || ""
|
|
433
|
-
);
|
|
434
|
-
if (nodeName.length > 20) {
|
|
435
|
-
nodeName = nodeName.slice(0, 19) + "\u2026";
|
|
436
|
-
}
|
|
437
|
-
return nodeType + (nodeName ? " " + nodeName : "");
|
|
438
|
-
}
|
|
439
|
-
var init_util = __esm({
|
|
440
|
-
"src/common/util.js"() {
|
|
441
|
-
init_escape_string_regexp();
|
|
442
|
-
init_skip();
|
|
443
|
-
init_skip_inline_comment();
|
|
444
|
-
init_skip_trailing_comment();
|
|
445
|
-
init_skip_newline();
|
|
446
|
-
init_get_next_non_space_non_comment_character_index_with_start_index();
|
|
447
|
-
init_is_non_empty_array();
|
|
448
|
-
init_get_string_width();
|
|
551
|
+
var init_utils = __esm({
|
|
552
|
+
"src/main/comments/utils.js"() {
|
|
449
553
|
}
|
|
450
554
|
});
|
|
451
555
|
|
|
452
|
-
// src/
|
|
453
|
-
var
|
|
454
|
-
__export(
|
|
556
|
+
// src/utils/public.js
|
|
557
|
+
var public_exports = {};
|
|
558
|
+
__export(public_exports, {
|
|
455
559
|
addDanglingComment: () => addDanglingComment,
|
|
456
560
|
addLeadingComment: () => addLeadingComment,
|
|
457
561
|
addTrailingComment: () => addTrailingComment,
|
|
458
|
-
getAlignmentSize: () =>
|
|
459
|
-
getIndentSize: () =>
|
|
460
|
-
getMaxContinuousCount: () =>
|
|
461
|
-
|
|
562
|
+
getAlignmentSize: () => get_alignment_size_default,
|
|
563
|
+
getIndentSize: () => get_indent_size_default,
|
|
564
|
+
getMaxContinuousCount: () => get_max_continuous_count_default,
|
|
565
|
+
getNextNonSpaceNonCommentCharacter: () => get_next_non_space_non_comment_character_default,
|
|
566
|
+
getNextNonSpaceNonCommentCharacterIndex: () => getNextNonSpaceNonCommentCharacterIndex2,
|
|
462
567
|
getStringWidth: () => get_string_width_default,
|
|
463
|
-
hasNewline: () =>
|
|
464
|
-
hasNewlineInRange: () =>
|
|
465
|
-
hasSpaces: () =>
|
|
466
|
-
isNextLineEmpty: () =>
|
|
467
|
-
isNextLineEmptyAfterIndex: () =>
|
|
468
|
-
isPreviousLineEmpty: () =>
|
|
469
|
-
makeString: () =>
|
|
470
|
-
skip: () =>
|
|
568
|
+
hasNewline: () => has_newline_default,
|
|
569
|
+
hasNewlineInRange: () => has_newline_in_range_default,
|
|
570
|
+
hasSpaces: () => has_spaces_default,
|
|
571
|
+
isNextLineEmpty: () => isNextLineEmpty2,
|
|
572
|
+
isNextLineEmptyAfterIndex: () => is_next_line_empty_default,
|
|
573
|
+
isPreviousLineEmpty: () => isPreviousLineEmpty2,
|
|
574
|
+
makeString: () => make_string_default,
|
|
575
|
+
skip: () => skip,
|
|
471
576
|
skipEverythingButNewLine: () => skipEverythingButNewLine,
|
|
472
577
|
skipInlineComment: () => skip_inline_comment_default,
|
|
473
578
|
skipNewline: () => skip_newline_default,
|
|
@@ -476,16 +581,65 @@ __export(util_shared_exports, {
|
|
|
476
581
|
skipTrailingComment: () => skip_trailing_comment_default,
|
|
477
582
|
skipWhitespace: () => skipWhitespace
|
|
478
583
|
});
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
584
|
+
function legacyGetNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
|
|
585
|
+
return get_next_non_space_non_comment_character_index_default(
|
|
586
|
+
text,
|
|
587
|
+
locEnd(node)
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
function getNextNonSpaceNonCommentCharacterIndex2(text, startIndex) {
|
|
591
|
+
return arguments.length === 2 || typeof startIndex === "number" ? get_next_non_space_non_comment_character_index_default(text, startIndex) : (
|
|
592
|
+
// @ts-expect-error -- expected
|
|
593
|
+
// eslint-disable-next-line prefer-rest-params
|
|
594
|
+
legacyGetNextNonSpaceNonCommentCharacterIndex(...arguments)
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
function legacyIsPreviousLineEmpty(text, node, locStart) {
|
|
598
|
+
return is_previous_line_empty_default(text, locStart(node));
|
|
599
|
+
}
|
|
600
|
+
function isPreviousLineEmpty2(text, startIndex) {
|
|
601
|
+
return arguments.length === 2 || typeof startIndex === "number" ? is_previous_line_empty_default(text, startIndex) : (
|
|
602
|
+
// @ts-expect-error -- expected
|
|
603
|
+
// eslint-disable-next-line prefer-rest-params
|
|
604
|
+
legacyIsPreviousLineEmpty(...arguments)
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
function legacyIsNextLineEmpty(text, node, locEnd) {
|
|
608
|
+
return is_next_line_empty_default(text, locEnd(node));
|
|
609
|
+
}
|
|
610
|
+
function isNextLineEmpty2(text, startIndex) {
|
|
611
|
+
return arguments.length === 2 || typeof startIndex === "number" ? is_next_line_empty_default(text, startIndex) : (
|
|
612
|
+
// @ts-expect-error -- expected
|
|
613
|
+
// eslint-disable-next-line prefer-rest-params
|
|
614
|
+
legacyIsNextLineEmpty(...arguments)
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
var init_public = __esm({
|
|
618
|
+
"src/utils/public.js"() {
|
|
619
|
+
init_get_next_non_space_non_comment_character_index();
|
|
620
|
+
init_is_previous_line_empty();
|
|
621
|
+
init_is_next_line_empty();
|
|
622
|
+
init_get_max_continuous_count();
|
|
623
|
+
init_get_string_width();
|
|
624
|
+
init_get_alignment_size();
|
|
625
|
+
init_get_indent_size();
|
|
626
|
+
init_skip_newline();
|
|
627
|
+
init_skip_inline_comment();
|
|
628
|
+
init_skip_trailing_comment();
|
|
629
|
+
init_has_newline();
|
|
630
|
+
init_has_newline_in_range();
|
|
631
|
+
init_has_spaces();
|
|
632
|
+
init_get_next_non_space_non_comment_character();
|
|
633
|
+
init_make_string();
|
|
634
|
+
init_skip();
|
|
635
|
+
init_utils();
|
|
482
636
|
}
|
|
483
637
|
});
|
|
484
638
|
|
|
485
639
|
// src/main/version.evaluate.cjs
|
|
486
640
|
var require_version_evaluate = __commonJS({
|
|
487
641
|
"src/main/version.evaluate.cjs"(exports2, module2) {
|
|
488
|
-
module2.exports = "3.0.0-alpha.
|
|
642
|
+
module2.exports = "3.0.0-alpha.5";
|
|
489
643
|
}
|
|
490
644
|
});
|
|
491
645
|
|
|
@@ -503,12 +657,28 @@ var functionNames = [
|
|
|
503
657
|
];
|
|
504
658
|
var prettier = /* @__PURE__ */ Object.create(null);
|
|
505
659
|
for (const name of functionNames) {
|
|
506
|
-
prettier[name] =
|
|
507
|
-
|
|
660
|
+
prettier[name] = async (...args) => {
|
|
661
|
+
const prettier2 = await prettierPromise;
|
|
662
|
+
return prettier2[name](...args);
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
var debugApiFunctionNames = [
|
|
666
|
+
"parse",
|
|
667
|
+
"formatAST",
|
|
668
|
+
"formatDoc",
|
|
669
|
+
"printToDoc",
|
|
670
|
+
"printDocToString"
|
|
671
|
+
];
|
|
672
|
+
var debugApis = /* @__PURE__ */ Object.create(null);
|
|
673
|
+
for (const name of debugApiFunctionNames) {
|
|
674
|
+
debugApis[name] = async (...args) => {
|
|
675
|
+
const prettier2 = await prettierPromise;
|
|
676
|
+
return prettier2.__debug[name](...args);
|
|
508
677
|
};
|
|
509
678
|
}
|
|
679
|
+
prettier.__debug = debugApis;
|
|
510
680
|
if (true) {
|
|
511
|
-
prettier.util = (
|
|
681
|
+
prettier.util = (init_public(), __toCommonJS(public_exports));
|
|
512
682
|
prettier.doc = require("./doc.js");
|
|
513
683
|
} else {
|
|
514
684
|
Object.defineProperties(prettier, {
|