prettier 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -33,6 +33,42 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
33
  ));
34
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
35
 
36
+ // src/utils/skip.js
37
+ function skip(characters) {
38
+ return (text, startIndex, options) => {
39
+ const backwards = Boolean(options == null ? void 0 : options.backwards);
40
+ if (startIndex === false) {
41
+ return false;
42
+ }
43
+ const { length } = text;
44
+ let cursor = startIndex;
45
+ while (cursor >= 0 && cursor < length) {
46
+ const character = text.charAt(cursor);
47
+ if (characters instanceof RegExp) {
48
+ if (!characters.test(character)) {
49
+ return cursor;
50
+ }
51
+ } else if (!characters.includes(character)) {
52
+ return cursor;
53
+ }
54
+ backwards ? cursor-- : cursor++;
55
+ }
56
+ if (cursor === -1 || cursor === length) {
57
+ return cursor;
58
+ }
59
+ return false;
60
+ };
61
+ }
62
+ var skipWhitespace, skipSpaces, skipToLineEnd, skipEverythingButNewLine;
63
+ var init_skip = __esm({
64
+ "src/utils/skip.js"() {
65
+ skipWhitespace = skip(/\s/);
66
+ skipSpaces = skip(" ");
67
+ skipToLineEnd = skip(",; ");
68
+ skipEverythingButNewLine = skip(/[^\n\r]/);
69
+ }
70
+ });
71
+
36
72
  // src/utils/skip-inline-comment.js
37
73
  function skipInlineComment(text, startIndex) {
38
74
  if (startIndex === false) {
@@ -85,42 +121,6 @@ var init_skip_newline = __esm({
85
121
  }
86
122
  });
87
123
 
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) {
93
- return false;
94
- }
95
- const { length } = text;
96
- let cursor = startIndex;
97
- while (cursor >= 0 && cursor < length) {
98
- const character = text.charAt(cursor);
99
- if (characters instanceof RegExp) {
100
- if (!characters.test(character)) {
101
- return cursor;
102
- }
103
- } else if (!characters.includes(character)) {
104
- return cursor;
105
- }
106
- backwards ? cursor-- : cursor++;
107
- }
108
- if (cursor === -1 || cursor === length) {
109
- return cursor;
110
- }
111
- return false;
112
- };
113
- }
114
- var skipWhitespace, skipSpaces, skipToLineEnd, skipEverythingButNewLine;
115
- var init_skip = __esm({
116
- "src/utils/skip.js"() {
117
- skipWhitespace = skip(/\s/);
118
- skipSpaces = skip(" ");
119
- skipToLineEnd = skip(",; ");
120
- skipEverythingButNewLine = skip(/[^\n\r]/);
121
- }
122
- });
123
-
124
124
  // src/utils/skip-trailing-comment.js
125
125
  function skipTrailingComment(text, startIndex) {
126
126
  if (startIndex === false) {
@@ -155,32 +155,14 @@ function getNextNonSpaceNonCommentCharacterIndex(text, startIndex) {
155
155
  var get_next_non_space_non_comment_character_index_default;
156
156
  var init_get_next_non_space_non_comment_character_index = __esm({
157
157
  "src/utils/get-next-non-space-non-comment-character-index.js"() {
158
+ init_skip();
158
159
  init_skip_inline_comment();
159
160
  init_skip_newline();
160
161
  init_skip_trailing_comment();
161
- init_skip();
162
162
  get_next_non_space_non_comment_character_index_default = getNextNonSpaceNonCommentCharacterIndex;
163
163
  }
164
164
  });
165
165
 
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
166
  // src/utils/has-newline.js
185
167
  function hasNewline(text, startIndex, options = {}) {
186
168
  const idx = skipSpaces(
@@ -217,15 +199,112 @@ function isNextLineEmpty(text, startIndex) {
217
199
  var is_next_line_empty_default;
218
200
  var init_is_next_line_empty = __esm({
219
201
  "src/utils/is-next-line-empty.js"() {
220
- init_skip_newline();
202
+ init_has_newline();
221
203
  init_skip();
222
204
  init_skip_inline_comment();
205
+ init_skip_newline();
223
206
  init_skip_trailing_comment();
224
- init_has_newline();
225
207
  is_next_line_empty_default = isNextLineEmpty;
226
208
  }
227
209
  });
228
210
 
211
+ // src/utils/is-previous-line-empty.js
212
+ function isPreviousLineEmpty(text, startIndex) {
213
+ let idx = startIndex - 1;
214
+ idx = skipSpaces(text, idx, { backwards: true });
215
+ idx = skip_newline_default(text, idx, { backwards: true });
216
+ idx = skipSpaces(text, idx, { backwards: true });
217
+ const idx2 = skip_newline_default(text, idx, { backwards: true });
218
+ return idx !== idx2;
219
+ }
220
+ var is_previous_line_empty_default;
221
+ var init_is_previous_line_empty = __esm({
222
+ "src/utils/is-previous-line-empty.js"() {
223
+ init_skip();
224
+ init_skip_newline();
225
+ is_previous_line_empty_default = isPreviousLineEmpty;
226
+ }
227
+ });
228
+
229
+ // src/main/comments/utils.js
230
+ function describeNodeForDebugging(node) {
231
+ const nodeType = node.type || node.kind || "(unknown type)";
232
+ let nodeName = String(
233
+ 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 || ""
234
+ );
235
+ if (nodeName.length > 20) {
236
+ nodeName = nodeName.slice(0, 19) + "\u2026";
237
+ }
238
+ return nodeType + (nodeName ? " " + nodeName : "");
239
+ }
240
+ function addCommentHelper(node, comment) {
241
+ const comments = node.comments ?? (node.comments = []);
242
+ comments.push(comment);
243
+ comment.printed = false;
244
+ comment.nodeDescription = describeNodeForDebugging(node);
245
+ }
246
+ function addLeadingComment(node, comment) {
247
+ comment.leading = true;
248
+ comment.trailing = false;
249
+ addCommentHelper(node, comment);
250
+ }
251
+ function addDanglingComment(node, comment, marker) {
252
+ comment.leading = false;
253
+ comment.trailing = false;
254
+ if (marker) {
255
+ comment.marker = marker;
256
+ }
257
+ addCommentHelper(node, comment);
258
+ }
259
+ function addTrailingComment(node, comment) {
260
+ comment.leading = false;
261
+ comment.trailing = true;
262
+ addCommentHelper(node, comment);
263
+ }
264
+ var init_utils = __esm({
265
+ "src/main/comments/utils.js"() {
266
+ }
267
+ });
268
+
269
+ // src/utils/get-alignment-size.js
270
+ function getAlignmentSize(text, tabWidth, startIndex = 0) {
271
+ let size = 0;
272
+ for (let i = startIndex; i < text.length; ++i) {
273
+ if (text[i] === " ") {
274
+ size = size + tabWidth - size % tabWidth;
275
+ } else {
276
+ size++;
277
+ }
278
+ }
279
+ return size;
280
+ }
281
+ var get_alignment_size_default;
282
+ var init_get_alignment_size = __esm({
283
+ "src/utils/get-alignment-size.js"() {
284
+ get_alignment_size_default = getAlignmentSize;
285
+ }
286
+ });
287
+
288
+ // src/utils/get-indent-size.js
289
+ function getIndentSize(value, tabWidth) {
290
+ const lastNewlineIndex = value.lastIndexOf("\n");
291
+ if (lastNewlineIndex === -1) {
292
+ return 0;
293
+ }
294
+ return get_alignment_size_default(
295
+ // All the leading whitespaces
296
+ value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0],
297
+ tabWidth
298
+ );
299
+ }
300
+ var get_indent_size_default;
301
+ var init_get_indent_size = __esm({
302
+ "src/utils/get-indent-size.js"() {
303
+ init_get_alignment_size();
304
+ get_indent_size_default = getIndentSize;
305
+ }
306
+ });
307
+
229
308
  // node_modules/escape-string-regexp/index.js
230
309
  function escapeStringRegexp(string) {
231
310
  if (typeof string !== "string") {
@@ -259,6 +338,19 @@ var init_get_max_continuous_count = __esm({
259
338
  }
260
339
  });
261
340
 
341
+ // src/utils/get-next-non-space-non-comment-character.js
342
+ function getNextNonSpaceNonCommentCharacter(text, startIndex) {
343
+ const index = get_next_non_space_non_comment_character_index_default(text, startIndex);
344
+ return index === false ? "" : text.charAt(index);
345
+ }
346
+ var get_next_non_space_non_comment_character_default;
347
+ var init_get_next_non_space_non_comment_character = __esm({
348
+ "src/utils/get-next-non-space-non-comment-character.js"() {
349
+ init_get_next_non_space_non_comment_character_index();
350
+ get_next_non_space_non_comment_character_default = getNextNonSpaceNonCommentCharacter;
351
+ }
352
+ });
353
+
262
354
  // node_modules/emoji-regex/index.mjs
263
355
  var emoji_regex_default;
264
356
  var init_emoji_regex = __esm({
@@ -322,45 +414,6 @@ var init_get_string_width = __esm({
322
414
  }
323
415
  });
324
416
 
325
- // src/utils/get-alignment-size.js
326
- function getAlignmentSize(text, tabWidth, startIndex = 0) {
327
- let size = 0;
328
- for (let i = startIndex; i < text.length; ++i) {
329
- if (text[i] === " ") {
330
- size = size + tabWidth - size % tabWidth;
331
- } else {
332
- size++;
333
- }
334
- }
335
- return size;
336
- }
337
- var get_alignment_size_default;
338
- var init_get_alignment_size = __esm({
339
- "src/utils/get-alignment-size.js"() {
340
- get_alignment_size_default = getAlignmentSize;
341
- }
342
- });
343
-
344
- // src/utils/get-indent-size.js
345
- function getIndentSize(value, tabWidth) {
346
- const lastNewlineIndex = value.lastIndexOf("\n");
347
- if (lastNewlineIndex === -1) {
348
- return 0;
349
- }
350
- return get_alignment_size_default(
351
- // All the leading whitespaces
352
- value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0],
353
- tabWidth
354
- );
355
- }
356
- var get_indent_size_default;
357
- var init_get_indent_size = __esm({
358
- "src/utils/get-indent-size.js"() {
359
- init_get_alignment_size();
360
- get_indent_size_default = getIndentSize;
361
- }
362
- });
363
-
364
417
  // src/utils/has-newline-in-range.js
365
418
  function hasNewlineInRange(text, startIndex, endIndex) {
366
419
  for (let i = startIndex; i < endIndex; ++i) {
@@ -394,19 +447,6 @@ var init_has_spaces = __esm({
394
447
  }
395
448
  });
396
449
 
397
- // src/utils/get-next-non-space-non-comment-character.js
398
- function getNextNonSpaceNonCommentCharacter(text, startIndex) {
399
- const index = get_next_non_space_non_comment_character_index_default(text, startIndex);
400
- return index === false ? "" : text.charAt(index);
401
- }
402
- var get_next_non_space_non_comment_character_default;
403
- var init_get_next_non_space_non_comment_character = __esm({
404
- "src/utils/get-next-non-space-non-comment-character.js"() {
405
- init_get_next_non_space_non_comment_character_index();
406
- get_next_non_space_non_comment_character_default = getNextNonSpaceNonCommentCharacter;
407
- }
408
- });
409
-
410
450
  // scripts/build/shims/string-replace-all.js
411
451
  var stringReplaceAll, string_replace_all_default;
412
452
  var init_string_replace_all = __esm({
@@ -459,46 +499,6 @@ var init_make_string = __esm({
459
499
  }
460
500
  });
461
501
 
462
- // src/main/comments/utils.js
463
- function describeNodeForDebugging(node) {
464
- const nodeType = node.type || node.kind || "(unknown type)";
465
- let nodeName = String(
466
- 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 || ""
467
- );
468
- if (nodeName.length > 20) {
469
- nodeName = nodeName.slice(0, 19) + "\u2026";
470
- }
471
- return nodeType + (nodeName ? " " + nodeName : "");
472
- }
473
- function addCommentHelper(node, comment) {
474
- const comments = node.comments ?? (node.comments = []);
475
- comments.push(comment);
476
- comment.printed = false;
477
- comment.nodeDescription = describeNodeForDebugging(node);
478
- }
479
- function addLeadingComment(node, comment) {
480
- comment.leading = true;
481
- comment.trailing = false;
482
- addCommentHelper(node, comment);
483
- }
484
- function addDanglingComment(node, comment, marker) {
485
- comment.leading = false;
486
- comment.trailing = false;
487
- if (marker) {
488
- comment.marker = marker;
489
- }
490
- addCommentHelper(node, comment);
491
- }
492
- function addTrailingComment(node, comment) {
493
- comment.leading = false;
494
- comment.trailing = true;
495
- addCommentHelper(node, comment);
496
- }
497
- var init_utils = __esm({
498
- "src/main/comments/utils.js"() {
499
- }
500
- });
501
-
502
502
  // src/utils/public.js
503
503
  var public_exports = {};
504
504
  __export(public_exports, {
@@ -563,29 +563,29 @@ function isNextLineEmpty2(text, startIndex) {
563
563
  var init_public = __esm({
564
564
  "src/utils/public.js"() {
565
565
  init_get_next_non_space_non_comment_character_index();
566
- init_is_previous_line_empty();
567
566
  init_is_next_line_empty();
568
- init_get_max_continuous_count();
569
- init_get_string_width();
567
+ init_is_previous_line_empty();
568
+ init_utils();
570
569
  init_get_alignment_size();
571
570
  init_get_indent_size();
572
- init_skip_newline();
573
- init_skip_inline_comment();
574
- init_skip_trailing_comment();
571
+ init_get_max_continuous_count();
572
+ init_get_next_non_space_non_comment_character();
573
+ init_get_string_width();
575
574
  init_has_newline();
576
575
  init_has_newline_in_range();
577
576
  init_has_spaces();
578
- init_get_next_non_space_non_comment_character();
579
577
  init_make_string();
580
578
  init_skip();
581
- init_utils();
579
+ init_skip_inline_comment();
580
+ init_skip_newline();
581
+ init_skip_trailing_comment();
582
582
  }
583
583
  });
584
584
 
585
585
  // src/main/version.evaluate.cjs
586
586
  var require_version_evaluate = __commonJS({
587
587
  "src/main/version.evaluate.cjs"(exports2, module2) {
588
- module2.exports = "3.1.0";
588
+ module2.exports = "3.2.0";
589
589
  }
590
590
  });
591
591
 
package/index.d.ts CHANGED
@@ -50,8 +50,8 @@ type IndexValue<T, P> = T extends any[]
50
50
  ? T[P]
51
51
  : never
52
52
  : P extends keyof T
53
- ? T[P]
54
- : never;
53
+ ? T[P]
54
+ : never;
55
55
 
56
56
  // Determines if an object T is an array like string[] (in which case this
57
57
  // evaluates to false) or a tuple like [string] (in which case this evaluates to
@@ -60,8 +60,8 @@ type IndexValue<T, P> = T extends any[]
60
60
  type IsTuple<T> = T extends []
61
61
  ? true
62
62
  : T extends [infer First, ...infer Remain]
63
- ? IsTuple<Remain>
64
- : false;
63
+ ? IsTuple<Remain>
64
+ : false;
65
65
 
66
66
  type CallProperties<T> = T extends any[] ? IndexProperties<T> : keyof T;
67
67
  type IterProperties<T> = T extends any[]
@@ -291,6 +291,7 @@ export type BuiltInParserName =
291
291
  | "json-stringify"
292
292
  | "json"
293
293
  | "json5"
294
+ | "jsonc"
294
295
  | "less"
295
296
  | "lwc"
296
297
  | "markdown"
@@ -347,12 +348,6 @@ export interface RequiredOptions extends doc.printer.Options {
347
348
  * @default false
348
349
  */
349
350
  bracketSameLine: boolean;
350
- /**
351
- * Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line.
352
- * @default false
353
- * @deprecated use bracketSameLine instead
354
- */
355
- jsxBracketSameLine: boolean;
356
351
  /**
357
352
  * Format only a segment of a file.
358
353
  * @default 0
@@ -430,6 +425,22 @@ export interface RequiredOptions extends doc.printer.Options {
430
425
  * @default false
431
426
  */
432
427
  singleAttributePerLine: boolean;
428
+ /**
429
+ * Use curious ternaries, with the question mark after the condition, instead
430
+ * of on the same line as the consequent.
431
+ * @default false
432
+ */
433
+ experimentalTernaries: boolean;
434
+ /**
435
+ * Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line.
436
+ * @default false
437
+ * @deprecated use bracketSameLine instead
438
+ */
439
+ jsxBracketSameLine?: boolean;
440
+ /**
441
+ * Arbitrary additional values on an options object are always allowed.
442
+ */
443
+ [_: string]: unknown;
433
444
  }
434
445
 
435
446
  export interface ParserOptions<T = any> extends RequiredOptions {
@@ -548,8 +559,6 @@ export interface CursorOptions extends Options {
548
559
  * Specify where the cursor is.
549
560
  */
550
561
  cursorOffset: number;
551
- rangeStart?: never;
552
- rangeEnd?: never;
553
562
  }
554
563
 
555
564
  export interface CursorResult {
@@ -572,7 +581,7 @@ export function check(source: string, options?: Options): Promise<boolean>;
572
581
  * `formatWithCursor` both formats the code, and translates a cursor position from unformatted code to formatted code.
573
582
  * This is useful for editor integrations, to prevent the cursor from moving when code is formatted.
574
583
  *
575
- * The `cursorOffset` option should be provided, to specify where the cursor is. This option cannot be used with `rangeStart` and `rangeEnd`.
584
+ * The `cursorOffset` option should be provided, to specify where the cursor is.
576
585
  */
577
586
  export function formatWithCursor(
578
587
  source: string,
@@ -782,7 +791,7 @@ export interface SupportInfo {
782
791
  export interface FileInfoOptions {
783
792
  ignorePath?: string | URL | (string | URL)[] | undefined;
784
793
  withNodeModules?: boolean | undefined;
785
- plugins?: string[] | undefined;
794
+ plugins?: Array<string | Plugin> | undefined;
786
795
  resolveConfig?: boolean | undefined;
787
796
  }
788
797
 
@@ -796,10 +805,17 @@ export function getFileInfo(
796
805
  options?: FileInfoOptions,
797
806
  ): Promise<FileInfoResult>;
798
807
 
808
+ export interface SupportInfoOptions {
809
+ plugins?: Array<string | Plugin> | undefined;
810
+ showDeprecated?: boolean | undefined;
811
+ }
812
+
799
813
  /**
800
814
  * Returns an object representing the parsers, languages and file types Prettier supports for the current version.
801
815
  */
802
- export function getSupportInfo(): Promise<SupportInfo>;
816
+ export function getSupportInfo(
817
+ options?: SupportInfoOptions,
818
+ ): Promise<SupportInfo>;
803
819
 
804
820
  /**
805
821
  * `version` field in `package.json`