prettier 3.0.0-alpha.6 → 3.0.0-alpha.8-for-vscode

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.
Files changed (55) hide show
  1. package/LICENSE +17 -17
  2. package/bin/prettier.cjs +0 -0
  3. package/doc.d.ts +2 -10
  4. package/doc.js +55 -246
  5. package/doc.mjs +51 -246
  6. package/index.cjs +1 -1
  7. package/index.d.ts +26 -8
  8. package/index.mjs +5920 -20834
  9. package/internal/cli.mjs +486 -478
  10. package/internal/{third-party.mjs → internal.mjs} +19 -14
  11. package/package.json +39 -28
  12. package/plugins/acorn.d.ts +6 -0
  13. package/plugins/acorn.js +13 -0
  14. package/plugins/acorn.mjs +13 -0
  15. package/plugins/angular.d.ts +5 -9
  16. package/plugins/angular.js +2 -2
  17. package/plugins/angular.mjs +2 -2
  18. package/plugins/babel.d.ts +14 -14
  19. package/plugins/babel.js +11 -11
  20. package/plugins/babel.mjs +11 -11
  21. package/plugins/estree.d.ts +0 -0
  22. package/plugins/estree.js +35 -0
  23. package/plugins/estree.mjs +35 -0
  24. package/plugins/flow.d.ts +2 -6
  25. package/plugins/flow.js +20 -20
  26. package/plugins/flow.mjs +20 -20
  27. package/plugins/glimmer.d.ts +2 -6
  28. package/plugins/glimmer.js +22 -17
  29. package/plugins/glimmer.mjs +22 -17
  30. package/plugins/graphql.d.ts +2 -6
  31. package/plugins/graphql.js +16 -7
  32. package/plugins/graphql.mjs +16 -7
  33. package/plugins/html.d.ts +5 -9
  34. package/plugins/html.js +19 -17
  35. package/plugins/html.mjs +19 -17
  36. package/plugins/markdown.d.ts +4 -8
  37. package/plugins/markdown.js +54 -33
  38. package/plugins/markdown.mjs +54 -33
  39. package/plugins/meriyah.d.ts +2 -6
  40. package/plugins/meriyah.js +5 -5
  41. package/plugins/meriyah.mjs +5 -5
  42. package/plugins/postcss.d.ts +4 -8
  43. package/plugins/postcss.js +45 -32
  44. package/plugins/postcss.mjs +45 -32
  45. package/plugins/typescript.d.ts +2 -6
  46. package/plugins/typescript.js +24 -20
  47. package/plugins/typescript.mjs +24 -20
  48. package/plugins/yaml.d.ts +2 -6
  49. package/plugins/yaml.js +130 -117
  50. package/plugins/yaml.mjs +130 -117
  51. package/standalone.js +27 -90
  52. package/standalone.mjs +27 -90
  53. package/plugins/acorn-and-espree.d.ts +0 -10
  54. package/plugins/acorn-and-espree.js +0 -13
  55. package/plugins/acorn-and-espree.mjs +0 -13
package/doc.mjs CHANGED
@@ -7,10 +7,6 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __commonJS = (cb, mod) => function __require() {
8
8
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
9
  };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
10
  var __copyProps = (to, from, except, desc) => {
15
11
  if (from && typeof from === "object" || typeof from === "function") {
16
12
  for (let key of __getOwnPropNames(from))
@@ -38,36 +34,6 @@ var require_emoji_regex = __commonJS({
38
34
  }
39
35
  });
40
36
 
41
- // src/document/builders.js
42
- var builders_exports = {};
43
- __export(builders_exports, {
44
- addAlignmentToDoc: () => addAlignmentToDoc,
45
- align: () => align,
46
- breakParent: () => breakParent,
47
- concat: () => concat,
48
- conditionalGroup: () => conditionalGroup,
49
- cursor: () => cursor,
50
- dedent: () => dedent,
51
- dedentToRoot: () => dedentToRoot,
52
- fill: () => fill,
53
- group: () => group,
54
- hardline: () => hardline,
55
- hardlineWithoutBreakParent: () => hardlineWithoutBreakParent,
56
- ifBreak: () => ifBreak,
57
- indent: () => indent,
58
- indentIfBreak: () => indentIfBreak,
59
- join: () => join,
60
- label: () => label,
61
- line: () => line,
62
- lineSuffix: () => lineSuffix,
63
- lineSuffixBoundary: () => lineSuffixBoundary,
64
- literalline: () => literalline,
65
- literallineWithoutBreakParent: () => literallineWithoutBreakParent,
66
- markAsRoot: () => markAsRoot,
67
- softline: () => softline,
68
- trim: () => trim
69
- });
70
-
71
37
  // src/document/constants.js
72
38
  var DOC_TYPE_STRING = "string";
73
39
  var DOC_TYPE_ARRAY = "array";
@@ -342,20 +308,16 @@ function label(label2, contents) {
342
308
  assertDoc(contents);
343
309
  return label2 ? { type: DOC_TYPE_LABEL, label: label2, contents } : contents;
344
310
  }
345
- var concat = (parts) => parts;
346
-
347
- // src/document/printer.js
348
- var printer_exports = {};
349
- __export(printer_exports, {
350
- printDocToString: () => printDocToString
351
- });
352
311
 
353
312
  // scripts/build/shims/at.js
354
313
  var at = (isOptionalObject, object, index) => {
355
314
  if (isOptionalObject && (object === void 0 || object === null)) {
356
315
  return;
357
316
  }
358
- return object.at ? object.at(index) : object[index < 0 ? object.length + index : index];
317
+ if (Array.isArray(object) || typeof object === "string") {
318
+ return object[index < 0 ? object.length + index : index];
319
+ }
320
+ return object.at(index);
359
321
  };
360
322
  var at_default = at;
361
323
 
@@ -468,23 +430,6 @@ function getStringWidth(text) {
468
430
  var get_string_width_default = getStringWidth;
469
431
 
470
432
  // src/document/utils.js
471
- var utils_exports = {};
472
- __export(utils_exports, {
473
- canBreak: () => canBreak,
474
- cleanDoc: () => cleanDoc,
475
- findInDoc: () => findInDoc,
476
- getDocParts: () => getDocParts,
477
- getDocType: () => get_doc_type_default,
478
- mapDoc: () => mapDoc,
479
- normalizeDoc: () => normalizeDoc,
480
- normalizeParts: () => normalizeParts,
481
- propagateBreaks: () => propagateBreaks,
482
- removeLines: () => removeLines,
483
- replaceEndOfLine: () => replaceEndOfLine,
484
- stripTrailingHardline: () => stripTrailingHardline,
485
- traverseDoc: () => traverse_doc_default,
486
- willBreak: () => willBreak
487
- });
488
433
  var getDocParts = (doc) => {
489
434
  if (Array.isArray(doc)) {
490
435
  return doc;
@@ -788,45 +733,6 @@ function cleanDocFn(doc) {
788
733
  function cleanDoc(doc) {
789
734
  return mapDoc(doc, (currentDoc) => cleanDocFn(currentDoc));
790
735
  }
791
- function normalizeParts(parts) {
792
- const newParts = [];
793
- const restParts = parts.filter(Boolean);
794
- while (restParts.length > 0) {
795
- const part = restParts.shift();
796
- if (!part) {
797
- continue;
798
- }
799
- if (Array.isArray(part)) {
800
- restParts.unshift(...part);
801
- continue;
802
- }
803
- if (newParts.length > 0 && typeof at_default(
804
- /* isOptionalObject*/
805
- false,
806
- newParts,
807
- -1
808
- ) === "string" && typeof part === "string") {
809
- newParts[newParts.length - 1] += part;
810
- continue;
811
- }
812
- newParts.push(part);
813
- }
814
- return newParts;
815
- }
816
- function normalizeDoc(doc) {
817
- return mapDoc(doc, (currentDoc) => {
818
- if (Array.isArray(currentDoc)) {
819
- return normalizeParts(currentDoc);
820
- }
821
- if (!currentDoc.parts) {
822
- return currentDoc;
823
- }
824
- return {
825
- ...currentDoc,
826
- parts: normalizeParts(currentDoc.parts)
827
- };
828
- });
829
- }
830
736
  function replaceEndOfLine(doc, replacement = literalline) {
831
737
  return mapDoc(doc, (currentDoc) => typeof currentDoc === "string" ? join(replacement, currentDoc.split("\n")) : currentDoc);
832
738
  }
@@ -980,6 +886,9 @@ function trim2(out) {
980
886
  return trimCount;
981
887
  }
982
888
  function fits(next, restCommands, width, hasLineSuffix, groupModeMap, mustBeFlat) {
889
+ if (width === Number.POSITIVE_INFINITY) {
890
+ return true;
891
+ }
983
892
  let restIdx = restCommands.length;
984
893
  const cmds = [next];
985
894
  const out = [];
@@ -1086,6 +995,7 @@ function printDocToString(doc, options) {
1086
995
  let shouldRemeasure = false;
1087
996
  const lineSuffix2 = [];
1088
997
  let printedCursorCount = 0;
998
+ propagateBreaks(doc);
1089
999
  while (cmds.length > 0) {
1090
1000
  const {
1091
1001
  ind,
@@ -1401,153 +1311,48 @@ function printDocToString(doc, options) {
1401
1311
  };
1402
1312
  }
1403
1313
 
1404
- // src/document/debug.js
1405
- var debug_exports = {};
1406
- __export(debug_exports, {
1407
- printDocToDebug: () => printDocToDebug
1408
- });
1409
- function flattenDoc(doc) {
1410
- var _a;
1411
- if (!doc) {
1412
- return "";
1413
- }
1414
- if (Array.isArray(doc)) {
1415
- const res = [];
1416
- for (const part of doc) {
1417
- if (Array.isArray(part)) {
1418
- res.push(...flattenDoc(part));
1419
- } else {
1420
- const flattened = flattenDoc(part);
1421
- if (flattened !== "") {
1422
- res.push(flattened);
1423
- }
1424
- }
1425
- }
1426
- return res;
1427
- }
1428
- if (doc.type === DOC_TYPE_IF_BREAK) {
1429
- return {
1430
- ...doc,
1431
- breakContents: flattenDoc(doc.breakContents),
1432
- flatContents: flattenDoc(doc.flatContents)
1433
- };
1434
- }
1435
- if (doc.type === DOC_TYPE_GROUP) {
1436
- return {
1437
- ...doc,
1438
- contents: flattenDoc(doc.contents),
1439
- expandedStates: (_a = doc.expandedStates) == null ? void 0 : _a.map(flattenDoc)
1440
- };
1441
- }
1442
- if (doc.type === DOC_TYPE_FILL) {
1443
- return { type: "fill", parts: doc.parts.map(flattenDoc) };
1444
- }
1445
- if (doc.contents) {
1446
- return { ...doc, contents: flattenDoc(doc.contents) };
1447
- }
1448
- return doc;
1449
- }
1450
- function printDocToDebug(doc) {
1451
- const printedSymbols = /* @__PURE__ */ Object.create(null);
1452
- const usedKeysForSymbols = /* @__PURE__ */ new Set();
1453
- return printDoc(flattenDoc(doc));
1454
- function printDoc(doc2, index, parentParts) {
1455
- var _a, _b;
1456
- if (typeof doc2 === "string") {
1457
- return JSON.stringify(doc2);
1458
- }
1459
- if (Array.isArray(doc2)) {
1460
- const printed = doc2.map(printDoc).filter(Boolean);
1461
- return printed.length === 1 ? printed[0] : `[${printed.join(", ")}]`;
1462
- }
1463
- if (doc2.type === DOC_TYPE_LINE) {
1464
- const withBreakParent = ((_a = parentParts == null ? void 0 : parentParts[index + 1]) == null ? void 0 : _a.type) === DOC_TYPE_BREAK_PARENT;
1465
- if (doc2.literal) {
1466
- return withBreakParent ? "literalline" : "literallineWithoutBreakParent";
1467
- }
1468
- if (doc2.hard) {
1469
- return withBreakParent ? "hardline" : "hardlineWithoutBreakParent";
1470
- }
1471
- if (doc2.soft) {
1472
- return "softline";
1473
- }
1474
- return "line";
1475
- }
1476
- if (doc2.type === DOC_TYPE_BREAK_PARENT) {
1477
- const afterHardline = ((_b = parentParts == null ? void 0 : parentParts[index - 1]) == null ? void 0 : _b.type) === DOC_TYPE_LINE && parentParts[index - 1].hard;
1478
- return afterHardline ? void 0 : "breakParent";
1479
- }
1480
- if (doc2.type === DOC_TYPE_TRIM) {
1481
- return "trim";
1482
- }
1483
- if (doc2.type === DOC_TYPE_INDENT) {
1484
- return "indent(" + printDoc(doc2.contents) + ")";
1485
- }
1486
- if (doc2.type === DOC_TYPE_ALIGN) {
1487
- return doc2.n === Number.NEGATIVE_INFINITY ? "dedentToRoot(" + printDoc(doc2.contents) + ")" : doc2.n < 0 ? "dedent(" + printDoc(doc2.contents) + ")" : doc2.n.type === "root" ? "markAsRoot(" + printDoc(doc2.contents) + ")" : "align(" + JSON.stringify(doc2.n) + ", " + printDoc(doc2.contents) + ")";
1488
- }
1489
- if (doc2.type === DOC_TYPE_IF_BREAK) {
1490
- return "ifBreak(" + printDoc(doc2.breakContents) + (doc2.flatContents ? ", " + printDoc(doc2.flatContents) : "") + (doc2.groupId ? (!doc2.flatContents ? ', ""' : "") + `, { groupId: ${printGroupId(doc2.groupId)} }` : "") + ")";
1491
- }
1492
- if (doc2.type === DOC_TYPE_INDENT_IF_BREAK) {
1493
- const optionsParts = [];
1494
- if (doc2.negate) {
1495
- optionsParts.push("negate: true");
1496
- }
1497
- if (doc2.groupId) {
1498
- optionsParts.push(`groupId: ${printGroupId(doc2.groupId)}`);
1499
- }
1500
- const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
1501
- return `indentIfBreak(${printDoc(doc2.contents)}${options})`;
1502
- }
1503
- if (doc2.type === DOC_TYPE_GROUP) {
1504
- const optionsParts = [];
1505
- if (doc2.break && doc2.break !== "propagated") {
1506
- optionsParts.push("shouldBreak: true");
1507
- }
1508
- if (doc2.id) {
1509
- optionsParts.push(`id: ${printGroupId(doc2.id)}`);
1510
- }
1511
- const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
1512
- if (doc2.expandedStates) {
1513
- return `conditionalGroup([${doc2.expandedStates.map((part) => printDoc(part)).join(",")}]${options})`;
1514
- }
1515
- return `group(${printDoc(doc2.contents)}${options})`;
1516
- }
1517
- if (doc2.type === DOC_TYPE_FILL) {
1518
- return `fill([${doc2.parts.map((part) => printDoc(part)).join(", ")}])`;
1519
- }
1520
- if (doc2.type === DOC_TYPE_LINE_SUFFIX) {
1521
- return "lineSuffix(" + printDoc(doc2.contents) + ")";
1522
- }
1523
- if (doc2.type === DOC_TYPE_LINE_SUFFIX_BOUNDARY) {
1524
- return "lineSuffixBoundary";
1525
- }
1526
- if (doc2.type === DOC_TYPE_LABEL) {
1527
- return `label(${JSON.stringify(doc2.label)}, ${printDoc(doc2.contents)})`;
1528
- }
1529
- throw new Error("Unknown doc type " + doc2.type);
1530
- }
1531
- function printGroupId(id) {
1532
- if (typeof id !== "symbol") {
1533
- return JSON.stringify(String(id));
1534
- }
1535
- if (id in printedSymbols) {
1536
- return printedSymbols[id];
1537
- }
1538
- const prefix = id.description || "symbol";
1539
- for (let counter = 0; ; counter++) {
1540
- const key = prefix + (counter > 0 ? ` #${counter}` : "");
1541
- if (!usedKeysForSymbols.has(key)) {
1542
- usedKeysForSymbols.add(key);
1543
- return printedSymbols[id] = `Symbol.for(${JSON.stringify(key)})`;
1544
- }
1545
- }
1546
- }
1547
- }
1314
+ // src/document/public.js
1315
+ var builders = {
1316
+ join,
1317
+ line,
1318
+ softline,
1319
+ hardline,
1320
+ literalline,
1321
+ group,
1322
+ conditionalGroup,
1323
+ fill,
1324
+ lineSuffix,
1325
+ lineSuffixBoundary,
1326
+ cursor,
1327
+ breakParent,
1328
+ ifBreak,
1329
+ trim,
1330
+ indent,
1331
+ indentIfBreak,
1332
+ align,
1333
+ addAlignmentToDoc,
1334
+ markAsRoot,
1335
+ dedentToRoot,
1336
+ dedent,
1337
+ hardlineWithoutBreakParent,
1338
+ literallineWithoutBreakParent,
1339
+ label,
1340
+ // TODO: Remove this in v4
1341
+ concat: (parts) => parts
1342
+ };
1343
+ var printer = { printDocToString };
1344
+ var utils = {
1345
+ willBreak,
1346
+ traverseDoc: traverse_doc_default,
1347
+ findInDoc,
1348
+ mapDoc,
1349
+ removeLines,
1350
+ stripTrailingHardline,
1351
+ replaceEndOfLine,
1352
+ canBreak
1353
+ };
1548
1354
  export {
1549
- builders_exports as builders,
1550
- debug_exports as debug,
1551
- printer_exports as printer,
1552
- utils_exports as utils
1355
+ builders,
1356
+ printer,
1357
+ utils
1553
1358
  };
package/index.cjs CHANGED
@@ -639,7 +639,7 @@ var init_public = __esm({
639
639
  // src/main/version.evaluate.cjs
640
640
  var require_version_evaluate = __commonJS({
641
641
  "src/main/version.evaluate.cjs"(exports2, module2) {
642
- module2.exports = "3.0.0-alpha.6";
642
+ module2.exports = "3.0.0-alpha.8-for-vscode";
643
643
  }
644
644
  });
645
645
 
package/index.d.ts CHANGED
@@ -8,10 +8,10 @@
8
8
  // exported module.
9
9
  export {};
10
10
 
11
- import { builders, debug, printer, utils } from "./doc.js";
11
+ import { builders, printer, utils } from "./doc.js";
12
12
 
13
13
  export namespace doc {
14
- export { builders, debug, printer, utils };
14
+ export { builders, printer, utils };
15
15
  }
16
16
 
17
17
  // This utility is here to handle the case where you have an explicit union
@@ -477,11 +477,19 @@ export interface Printer<T = any> {
477
477
  ): Doc;
478
478
  embed?:
479
479
  | ((
480
- path: AstPath<T>,
481
- print: (path: AstPath<T>) => Doc,
482
- textToDoc: (text: string, options: Options) => Doc,
483
- options: ParserOptions<T>
484
- ) => Doc | null)
480
+ path: AstPath,
481
+ options: Options
482
+ ) =>
483
+ | ((
484
+ textToDoc: (text: string, options: Options) => Promise<Doc>,
485
+ print: (
486
+ selector?: string | number | Array<string | number> | AstPath
487
+ ) => Doc,
488
+ path: AstPath,
489
+ options: Options
490
+ ) => Promise<Doc | undefined> | Doc | undefined)
491
+ | Doc
492
+ | null)
485
493
  | undefined;
486
494
  insertPragma?: (text: string) => string;
487
495
  /**
@@ -497,6 +505,16 @@ export interface Printer<T = any> {
497
505
  printComment?:
498
506
  | ((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc)
499
507
  | undefined;
508
+ /**
509
+ * By default, Prettier searches all object properties (except for a few predefined ones) of each node recursively.
510
+ * This function can be provided to override that behavior.
511
+ * @param node The node whose children should be returned.
512
+ * @param options Current options.
513
+ * @returns `[]` if the node has no children or `undefined` to fall back on the default behavior.
514
+ */
515
+ getCommentChildNodes?:
516
+ | ((node: T, options: ParserOptions<T>) => T[] | undefined)
517
+ | undefined;
500
518
  handleComments?:
501
519
  | {
502
520
  ownLine?:
@@ -767,7 +785,7 @@ export interface SupportInfo {
767
785
  }
768
786
 
769
787
  export interface FileInfoOptions {
770
- ignorePath?: string | undefined;
788
+ ignorePath?: string | string[] | undefined;
771
789
  withNodeModules?: boolean | undefined;
772
790
  plugins?: string[] | undefined;
773
791
  resolveConfig?: boolean | undefined;