prettier 3.8.4 → 3.9.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
@@ -5,8 +5,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err = [e], e;
14
+ }
10
15
  };
11
16
  var __export = (target, all) => {
12
17
  for (var name in all)
@@ -56,7 +61,7 @@ var init_method_replace_all = __esm({
56
61
  }
57
62
  return this.split(pattern).join(replacement);
58
63
  };
59
- replaceAll = createMethodShim("replaceAll", function() {
64
+ replaceAll = /* @__PURE__ */ createMethodShim("replaceAll", function() {
60
65
  if (typeof this === "string") {
61
66
  return stringReplaceAll;
62
67
  }
@@ -68,10 +73,10 @@ var init_method_replace_all = __esm({
68
73
  // src/utilities/skip.js
69
74
  function skip(characters) {
70
75
  return (text, startIndex, options) => {
71
- const backwards = Boolean(options?.backwards);
72
76
  if (startIndex === false) {
73
77
  return false;
74
78
  }
79
+ const backwards = Boolean(options?.backwards);
75
80
  const { length } = text;
76
81
  let cursor = startIndex;
77
82
  while (cursor >= 0 && cursor < length) {
@@ -94,10 +99,10 @@ function skip(characters) {
94
99
  var skipWhitespace, skipSpaces, skipToLineEnd, skipEverythingButNewLine;
95
100
  var init_skip = __esm({
96
101
  "src/utilities/skip.js"() {
97
- skipWhitespace = skip(/\s/u);
102
+ skipWhitespace = skip(/\s/);
98
103
  skipSpaces = skip(" ");
99
104
  skipToLineEnd = skip(",; ");
100
- skipEverythingButNewLine = skip(/[^\n\r]/u);
105
+ skipEverythingButNewLine = skip(/[^\n\r]/);
101
106
  }
102
107
  });
103
108
 
@@ -124,10 +129,10 @@ var init_skip_inline_comment = __esm({
124
129
 
125
130
  // src/utilities/skip-newline.js
126
131
  function skipNewline(text, startIndex, options) {
127
- const backwards = Boolean(options?.backwards);
128
132
  if (startIndex === false) {
129
133
  return false;
130
134
  }
135
+ const backwards = Boolean(options?.backwards);
131
136
  const character = text.charAt(startIndex);
132
137
  if (backwards) {
133
138
  if (text.charAt(startIndex - 1) === "\r" && character === "\n") {
@@ -326,7 +331,7 @@ function getIndentSize(value, tabWidth) {
326
331
  }
327
332
  return get_alignment_size_default(
328
333
  // All the leading whitespaces
329
- value.slice(lastNewlineIndex + 1).match(/^[\t ]*/u)[0],
334
+ value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0],
330
335
  tabWidth
331
336
  );
332
337
  }
@@ -353,7 +358,7 @@ var init_escape_string_regexp = __esm({
353
358
  // src/utilities/get-max-continuous-count.js
354
359
  function getMaxContinuousCount(text, searchString) {
355
360
  let results = text.matchAll(
356
- new RegExp(`(?:${escapeStringRegexp(searchString)})+`, "gu")
361
+ new RegExp(`(?:${escapeStringRegexp(searchString)})+`, "g")
357
362
  );
358
363
  if (!results.reduce) {
359
364
  results = [...results];
@@ -400,7 +405,7 @@ function getPreferredQuote(text, preferredQuoteOrPreferSingleQuote) {
400
405
  }
401
406
  return (preferredQuoteCount > alternateQuoteCount ? alternate : preferred).character;
402
407
  }
403
- var SINGLE_QUOTE, DOUBLE_QUOTE, SINGLE_QUOTE_DATA, DOUBLE_QUOTE_DATA, SINGLE_QUOTE_SETTINGS, DOUBLE_QUOTE_SETTINGS, get_preferred_quote_default;
408
+ var SINGLE_QUOTE, DOUBLE_QUOTE, SINGLE_QUOTE_DATA, DOUBLE_QUOTE_DATA, SINGLE_QUOTE_SETTINGS, DOUBLE_QUOTE_SETTINGS;
404
409
  var init_get_preferred_quote = __esm({
405
410
  "src/utilities/get-preferred-quote.js"() {
406
411
  SINGLE_QUOTE = "'";
@@ -421,7 +426,6 @@ var init_get_preferred_quote = __esm({
421
426
  preferred: DOUBLE_QUOTE_DATA,
422
427
  alternate: SINGLE_QUOTE_DATA
423
428
  });
424
- get_preferred_quote_default = getPreferredQuote;
425
429
  }
426
430
  });
427
431
 
@@ -435,15 +439,81 @@ var init_emoji_regex = __esm({
435
439
  }
436
440
  });
437
441
 
442
+ // node_modules/get-east-asian-width/lookup-data.js
443
+ var fullwidthMinimalCodePoint, fullwidthMaximumCodePoint, fullwidthRanges, wideMinimalCodePoint, wideMaximumCodePoint, wideRanges;
444
+ var init_lookup_data = __esm({
445
+ "node_modules/get-east-asian-width/lookup-data.js"() {
446
+ fullwidthMinimalCodePoint = 12288;
447
+ fullwidthMaximumCodePoint = 65510;
448
+ fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
449
+ wideMinimalCodePoint = 4352;
450
+ wideMaximumCodePoint = 262141;
451
+ wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
452
+ }
453
+ });
454
+
455
+ // node_modules/get-east-asian-width/utilities.js
456
+ var isInRange;
457
+ var init_utilities2 = __esm({
458
+ "node_modules/get-east-asian-width/utilities.js"() {
459
+ isInRange = (ranges, codePoint) => {
460
+ let low = 0;
461
+ let high = Math.floor(ranges.length / 2) - 1;
462
+ while (low <= high) {
463
+ const mid = Math.floor((low + high) / 2);
464
+ const i = mid * 2;
465
+ if (codePoint < ranges[i]) {
466
+ high = mid - 1;
467
+ } else if (codePoint > ranges[i + 1]) {
468
+ low = mid + 1;
469
+ } else {
470
+ return true;
471
+ }
472
+ }
473
+ return false;
474
+ };
475
+ }
476
+ });
477
+
438
478
  // node_modules/get-east-asian-width/lookup.js
439
- function isFullWidth(x) {
440
- return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
441
- }
442
- function isWide(x) {
443
- return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x >= 94192 && x <= 94198 || x >= 94208 && x <= 101589 || x >= 101631 && x <= 101662 || x >= 101760 && x <= 101874 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128728 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129674 || x >= 129678 && x <= 129734 || x === 129736 || x >= 129741 && x <= 129756 || x >= 129759 && x <= 129770 || x >= 129775 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
479
+ function findWideFastPathRange(ranges) {
480
+ let fastPathStart = ranges[0];
481
+ let fastPathEnd = ranges[1];
482
+ for (let index = 0; index < ranges.length; index += 2) {
483
+ const start = ranges[index];
484
+ const end = ranges[index + 1];
485
+ if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) {
486
+ return [start, end];
487
+ }
488
+ if (end - start > fastPathEnd - fastPathStart) {
489
+ fastPathStart = start;
490
+ fastPathEnd = end;
491
+ }
492
+ }
493
+ return [fastPathStart, fastPathEnd];
444
494
  }
495
+ var commonCjkCodePoint, wideFastPathStart, wideFastPathEnd, isFullWidth, isWide;
445
496
  var init_lookup = __esm({
446
497
  "node_modules/get-east-asian-width/lookup.js"() {
498
+ init_lookup_data();
499
+ init_utilities2();
500
+ commonCjkCodePoint = 19968;
501
+ [wideFastPathStart, wideFastPathEnd] = /* @__PURE__ */ findWideFastPathRange(wideRanges);
502
+ isFullWidth = (codePoint) => {
503
+ if (codePoint < fullwidthMinimalCodePoint || codePoint > fullwidthMaximumCodePoint) {
504
+ return false;
505
+ }
506
+ return isInRange(fullwidthRanges, codePoint);
507
+ };
508
+ isWide = (codePoint) => {
509
+ if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
510
+ return true;
511
+ }
512
+ if (codePoint < wideMinimalCodePoint || codePoint > wideMaximumCodePoint) {
513
+ return false;
514
+ }
515
+ return isInRange(wideRanges, codePoint);
516
+ };
447
517
  }
448
518
  });
449
519
 
@@ -454,11 +524,12 @@ var init_get_east_asian_width = __esm({
454
524
  }
455
525
  });
456
526
 
457
- // src/utilities/narrow-emojis.evaluate.js
458
- var narrow_emojis_evaluate_default;
459
- var init_narrow_emojis_evaluate = __esm({
460
- "src/utilities/narrow-emojis.evaluate.js"() {
461
- narrow_emojis_evaluate_default = "\xA9\xAE\u203C\u2049\u2122\u2139\u2194\u2195\u2196\u2197\u2198\u2199\u21A9\u21AA\u2328\u23CF\u23F1\u23F2\u23F8\u23F9\u23FA\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600\u2601\u2602\u2603\u2604\u260E\u2611\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638\u2639\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694\u2695\u2696\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F1\u26F7\u26F8\u26F9\u2702\u2708\u2709\u270C\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u2764\u27A1\u2934\u2935\u2B05\u2B06\u2B07";
527
+ // node_modules/narrow-emojis/index.js
528
+ var narrowEmojiRegexp, isNarrowEmojiCharacter;
529
+ var init_narrow_emojis = __esm({
530
+ "node_modules/narrow-emojis/index.js"() {
531
+ narrowEmojiRegexp = /^(?:[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u2764\u27A1\u2934\u2935\u2B05-\u2B07]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF3\uDFF5\uDFF7]|\uD83D[\uDC3F\uDC41\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])$/;
532
+ isNarrowEmojiCharacter = (character) => narrowEmojiRegexp.test(character);
462
533
  }
463
534
  });
464
535
 
@@ -470,11 +541,11 @@ function getStringWidth(text) {
470
541
  if (!notAsciiRegex.test(text)) {
471
542
  return text.length;
472
543
  }
473
- text = text.replace(
474
- emoji_regex_default(),
475
- (match) => narrowEmojisSet.has(match) ? " " : " "
476
- );
477
544
  let width = 0;
545
+ text = text.replace(emoji_regex_default(), (character) => {
546
+ width += isNarrowEmojiCharacter(character) ? 1 : 2;
547
+ return "";
548
+ });
478
549
  for (const character of text) {
479
550
  const codePoint = character.codePointAt(0);
480
551
  if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
@@ -490,14 +561,13 @@ function getStringWidth(text) {
490
561
  }
491
562
  return width;
492
563
  }
493
- var notAsciiRegex, narrowEmojisSet, get_string_width_default;
564
+ var notAsciiRegex, get_string_width_default;
494
565
  var init_get_string_width = __esm({
495
566
  "src/utilities/get-string-width.js"() {
496
567
  init_emoji_regex();
497
568
  init_get_east_asian_width();
498
- init_narrow_emojis_evaluate();
499
- notAsciiRegex = /[^\x20-\x7F]/u;
500
- narrowEmojisSet = new Set(narrow_emojis_evaluate_default);
569
+ init_narrow_emojis();
570
+ notAsciiRegex = /[^\x20-\x7F]/;
501
571
  get_string_width_default = getStringWidth;
502
572
  }
503
573
  });
@@ -546,7 +616,7 @@ __export(public_exports, {
546
616
  getMaxContinuousCount: () => get_max_continuous_count_default,
547
617
  getNextNonSpaceNonCommentCharacter: () => get_next_non_space_non_comment_character_default,
548
618
  getNextNonSpaceNonCommentCharacterIndex: () => getNextNonSpaceNonCommentCharacterIndex2,
549
- getPreferredQuote: () => get_preferred_quote_default,
619
+ getPreferredQuote: () => getPreferredQuote,
550
620
  getStringWidth: () => get_string_width_default,
551
621
  hasNewline: () => has_newline_default,
552
622
  hasNewlineInRange: () => has_newline_in_range_default,
@@ -589,7 +659,7 @@ function legacyIsNextLineEmpty(text, node, locEnd) {
589
659
  }
590
660
  function makeString(rawText, enclosingQuote, unescapeUnnecessaryEscapes) {
591
661
  const otherQuote = enclosingQuote === '"' ? "'" : '"';
592
- const regex = /\\(.)|(["'])/gsu;
662
+ const regex = /\\(.)|(["'])/gs;
593
663
  const raw = method_replace_all_default(
594
664
  /* OPTIONAL_OBJECT: false */
595
665
  0,
@@ -605,7 +675,7 @@ function makeString(rawText, enclosingQuote, unescapeUnnecessaryEscapes) {
605
675
  if (quote) {
606
676
  return quote;
607
677
  }
608
- return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/u.test(escaped) ? escaped : "\\" + escaped;
678
+ return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/.test(escaped) ? escaped : "\\" + escaped;
609
679
  }
610
680
  );
611
681
  return enclosingQuote + raw + enclosingQuote;
@@ -648,7 +718,7 @@ __export(version_evaluate_exports, {
648
718
  var version_evaluate_default;
649
719
  var init_version_evaluate = __esm({
650
720
  "src/main/version.evaluate.js"() {
651
- version_evaluate_default = "3.8.4";
721
+ version_evaluate_default = "3.9.0";
652
722
  }
653
723
  });
654
724
 
package/index.d.ts CHANGED
@@ -488,13 +488,19 @@ export interface Printer<T = any> {
488
488
  print(
489
489
  path: AstPath<T>,
490
490
  options: ParserOptions<T>,
491
- print: (path: AstPath<T>) => Doc,
491
+ print: (
492
+ selector?: string | number | Array<string | number> | AstPath<T>,
493
+ args?: unknown,
494
+ ) => Doc,
492
495
  args?: unknown,
493
496
  ): Doc;
494
497
  printPrettierIgnored?(
495
498
  path: AstPath<T>,
496
499
  options: ParserOptions<T>,
497
- print: (path: AstPath<T>) => Doc,
500
+ print: (
501
+ selector?: string | number | Array<string | number> | AstPath<T>,
502
+ args?: unknown,
503
+ ) => Doc,
498
504
  args?: unknown,
499
505
  ): Doc;
500
506
  embed?:
@@ -506,6 +512,7 @@ export interface Printer<T = any> {
506
512
  textToDoc: (text: string, options: Options) => Promise<Doc>,
507
513
  print: (
508
514
  selector?: string | number | Array<string | number> | AstPath,
515
+ args?: unknown,
509
516
  ) => Doc,
510
517
  path: AstPath,
511
518
  options: Options,