prettier 3.0.0-alpha.1 → 3.0.0-alpha.10

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 (57) hide show
  1. package/LICENSE +910 -759
  2. package/README.md +3 -3
  3. package/bin/prettier.cjs +0 -0
  4. package/doc.d.ts +240 -0
  5. package/doc.js +351 -479
  6. package/doc.mjs +342 -474
  7. package/index.cjs +400 -230
  8. package/index.d.ts +921 -0
  9. package/index.mjs +17218 -32209
  10. package/internal/cli.mjs +4374 -10823
  11. package/internal/internal.mjs +6437 -0
  12. package/package.json +55 -13
  13. package/plugins/acorn.d.ts +6 -0
  14. package/plugins/acorn.js +13 -0
  15. package/plugins/acorn.mjs +13 -0
  16. package/plugins/angular.d.ts +8 -0
  17. package/plugins/angular.js +2 -2
  18. package/plugins/angular.mjs +2 -2
  19. package/plugins/babel.d.ts +17 -0
  20. package/plugins/babel.js +12 -12
  21. package/plugins/babel.mjs +12 -12
  22. package/plugins/estree.d.ts +0 -0
  23. package/plugins/estree.js +35 -0
  24. package/plugins/estree.mjs +35 -0
  25. package/plugins/flow.d.ts +5 -0
  26. package/plugins/flow.js +20 -20
  27. package/plugins/flow.mjs +20 -20
  28. package/plugins/glimmer.d.ts +5 -0
  29. package/plugins/glimmer.js +22 -17
  30. package/plugins/glimmer.mjs +22 -17
  31. package/plugins/graphql.d.ts +5 -0
  32. package/plugins/graphql.js +16 -7
  33. package/plugins/graphql.mjs +16 -7
  34. package/plugins/html.d.ts +8 -0
  35. package/plugins/html.js +19 -29
  36. package/plugins/html.mjs +19 -29
  37. package/plugins/markdown.d.ts +7 -0
  38. package/plugins/markdown.js +54 -34
  39. package/plugins/markdown.mjs +54 -34
  40. package/plugins/meriyah.d.ts +5 -0
  41. package/plugins/meriyah.js +5 -6
  42. package/plugins/meriyah.mjs +5 -6
  43. package/plugins/postcss.d.ts +7 -0
  44. package/plugins/postcss.js +45 -43
  45. package/plugins/postcss.mjs +45 -43
  46. package/plugins/typescript.d.ts +5 -0
  47. package/plugins/typescript.js +24 -239
  48. package/plugins/typescript.mjs +24 -239
  49. package/plugins/yaml.d.ts +5 -0
  50. package/plugins/yaml.js +148 -135
  51. package/plugins/yaml.mjs +148 -135
  52. package/standalone.d.ts +33 -0
  53. package/standalone.js +35 -105
  54. package/standalone.mjs +35 -105
  55. package/internal/third-party.mjs +0 -9071
  56. package/plugins/acorn-and-espree.js +0 -13
  57. package/plugins/acorn-and-espree.mjs +0 -13
package/doc.mjs CHANGED
@@ -4,17 +4,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
7
  var __commonJS = (cb, mod) => function __require() {
12
8
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
9
  };
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
10
  var __copyProps = (to, from, except, desc) => {
19
11
  if (from && typeof from === "object" || typeof from === "function") {
20
12
  for (let key of __getOwnPropNames(from))
@@ -24,67 +16,25 @@ var __copyProps = (to, from, except, desc) => {
24
16
  return to;
25
17
  };
26
18
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
23
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
24
  mod
29
25
  ));
30
- var __publicField = (obj, key, value) => {
31
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
- return value;
33
- };
34
-
35
- // <define:process>
36
- var init_define_process = __esm({
37
- "<define:process>"() {
38
- }
39
- });
40
26
 
41
27
  // node_modules/string-width/node_modules/emoji-regex/index.js
42
28
  var require_emoji_regex = __commonJS({
43
29
  "node_modules/string-width/node_modules/emoji-regex/index.js"(exports, module) {
44
30
  "use strict";
45
- init_define_process();
46
31
  module.exports = function() {
47
32
  return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\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])|\uD83C[\uDF3E\uDF73\uDF7C\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\uDF7C\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\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\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\uDF7C\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\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCB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\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\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\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83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DC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\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\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\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-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*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\u26A7\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-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\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[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
48
33
  };
49
34
  }
50
35
  });
51
36
 
52
- // src/document/index.js
53
- init_define_process();
54
-
55
- // src/document/builders.js
56
- var builders_exports = {};
57
- __export(builders_exports, {
58
- addAlignmentToDoc: () => addAlignmentToDoc,
59
- align: () => align,
60
- breakParent: () => breakParent,
61
- concat: () => concat,
62
- conditionalGroup: () => conditionalGroup,
63
- cursor: () => cursor,
64
- dedent: () => dedent,
65
- dedentToRoot: () => dedentToRoot,
66
- fill: () => fill,
67
- group: () => group,
68
- hardline: () => hardline,
69
- hardlineWithoutBreakParent: () => hardlineWithoutBreakParent,
70
- ifBreak: () => ifBreak,
71
- indent: () => indent,
72
- indentIfBreak: () => indentIfBreak,
73
- join: () => join,
74
- label: () => label,
75
- line: () => line,
76
- lineSuffix: () => lineSuffix,
77
- lineSuffixBoundary: () => lineSuffixBoundary,
78
- literalline: () => literalline,
79
- literallineWithoutBreakParent: () => literallineWithoutBreakParent,
80
- markAsRoot: () => markAsRoot,
81
- softline: () => softline,
82
- trim: () => trim
83
- });
84
- init_define_process();
85
-
86
37
  // src/document/constants.js
87
- init_define_process();
88
38
  var DOC_TYPE_STRING = "string";
89
39
  var DOC_TYPE_ARRAY = "array";
90
40
  var DOC_TYPE_CURSOR = "cursor";
@@ -116,23 +66,157 @@ var VALID_OBJECT_DOC_TYPES = /* @__PURE__ */ new Set([
116
66
  DOC_TYPE_BREAK_PARENT
117
67
  ]);
118
68
 
69
+ // src/document/utils/get-doc-type.js
70
+ function getDocType(doc) {
71
+ if (typeof doc === "string") {
72
+ return DOC_TYPE_STRING;
73
+ }
74
+ if (Array.isArray(doc)) {
75
+ return DOC_TYPE_ARRAY;
76
+ }
77
+ if (!doc) {
78
+ return;
79
+ }
80
+ const { type } = doc;
81
+ if (VALID_OBJECT_DOC_TYPES.has(type)) {
82
+ return type;
83
+ }
84
+ }
85
+ var get_doc_type_default = getDocType;
86
+
87
+ // src/document/invalid-doc-error.js
88
+ var disjunctionListFormat = (list) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(list);
89
+ function getDocErrorMessage(doc) {
90
+ const type = doc === null ? "null" : typeof doc;
91
+ if (type !== "string" && type !== "object") {
92
+ return `Unexpected doc '${type}',
93
+ Expected it to be 'string' or 'object'.`;
94
+ }
95
+ if (get_doc_type_default(doc)) {
96
+ throw new Error("doc is valid.");
97
+ }
98
+ const objectType = Object.prototype.toString.call(doc);
99
+ if (objectType !== "[object Object]") {
100
+ return `Unexpected doc '${objectType}'.`;
101
+ }
102
+ const EXPECTED_TYPE_VALUES = disjunctionListFormat(
103
+ [...VALID_OBJECT_DOC_TYPES].map((type2) => `'${type2}'`)
104
+ );
105
+ return `Unexpected doc.type '${doc.type}'.
106
+ Expected it to be ${EXPECTED_TYPE_VALUES}.`;
107
+ }
108
+ var InvalidDocError = class extends Error {
109
+ name = "InvalidDocError";
110
+ constructor(doc) {
111
+ super(getDocErrorMessage(doc));
112
+ this.doc = doc;
113
+ }
114
+ };
115
+ var invalid_doc_error_default = InvalidDocError;
116
+
117
+ // src/document/utils/traverse-doc.js
118
+ var traverseDocOnExitStackMarker = {};
119
+ function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
120
+ const docsStack = [doc];
121
+ while (docsStack.length > 0) {
122
+ const doc2 = docsStack.pop();
123
+ if (doc2 === traverseDocOnExitStackMarker) {
124
+ onExit(docsStack.pop());
125
+ continue;
126
+ }
127
+ if (onExit) {
128
+ docsStack.push(doc2, traverseDocOnExitStackMarker);
129
+ }
130
+ const docType = get_doc_type_default(doc2);
131
+ if (!docType) {
132
+ throw new invalid_doc_error_default(doc2);
133
+ }
134
+ if ((onEnter == null ? void 0 : onEnter(doc2)) === false) {
135
+ continue;
136
+ }
137
+ switch (docType) {
138
+ case DOC_TYPE_ARRAY:
139
+ case DOC_TYPE_FILL: {
140
+ const parts = docType === DOC_TYPE_ARRAY ? doc2 : doc2.parts;
141
+ for (let ic = parts.length, i = ic - 1; i >= 0; --i) {
142
+ docsStack.push(parts[i]);
143
+ }
144
+ break;
145
+ }
146
+ case DOC_TYPE_IF_BREAK:
147
+ docsStack.push(doc2.flatContents, doc2.breakContents);
148
+ break;
149
+ case DOC_TYPE_GROUP:
150
+ if (shouldTraverseConditionalGroups && doc2.expandedStates) {
151
+ for (let ic = doc2.expandedStates.length, i = ic - 1; i >= 0; --i) {
152
+ docsStack.push(doc2.expandedStates[i]);
153
+ }
154
+ } else {
155
+ docsStack.push(doc2.contents);
156
+ }
157
+ break;
158
+ case DOC_TYPE_ALIGN:
159
+ case DOC_TYPE_INDENT:
160
+ case DOC_TYPE_INDENT_IF_BREAK:
161
+ case DOC_TYPE_LABEL:
162
+ case DOC_TYPE_LINE_SUFFIX:
163
+ docsStack.push(doc2.contents);
164
+ break;
165
+ case DOC_TYPE_STRING:
166
+ case DOC_TYPE_CURSOR:
167
+ case DOC_TYPE_TRIM:
168
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
169
+ case DOC_TYPE_LINE:
170
+ case DOC_TYPE_BREAK_PARENT:
171
+ break;
172
+ default:
173
+ throw new invalid_doc_error_default(doc2);
174
+ }
175
+ }
176
+ }
177
+ var traverse_doc_default = traverseDoc;
178
+
179
+ // src/document/utils/assert-doc.js
180
+ var noop = () => {
181
+ };
182
+ var assertDoc = true ? noop : function(doc) {
183
+ traverse_doc_default(doc, (doc2) => {
184
+ if (checked.has(doc2)) {
185
+ return false;
186
+ }
187
+ if (typeof doc2 !== "string") {
188
+ checked.add(doc2);
189
+ }
190
+ });
191
+ };
192
+ var assertDocArray = true ? noop : function(docs, optional = false) {
193
+ if (optional && !docs) {
194
+ return;
195
+ }
196
+ if (!Array.isArray(docs)) {
197
+ throw new TypeError("Unexpected doc array.");
198
+ }
199
+ for (const doc of docs) {
200
+ assertDoc(doc);
201
+ }
202
+ };
203
+
119
204
  // src/document/builders.js
120
205
  function indent(contents) {
121
- if (false) {
122
- assertDoc(contents);
123
- }
206
+ assertDoc(contents);
124
207
  return { type: DOC_TYPE_INDENT, contents };
125
208
  }
126
209
  function align(widthOrString, contents) {
127
- if (false) {
128
- assertDoc(contents);
129
- }
210
+ assertDoc(contents);
130
211
  return { type: DOC_TYPE_ALIGN, contents, n: widthOrString };
131
212
  }
132
213
  function group(contents, opts = {}) {
133
- if (false) {
134
- assertDoc(contents);
135
- }
214
+ assertDoc(contents);
215
+ assertDocArray(
216
+ opts.expandedStates,
217
+ /* optional */
218
+ true
219
+ );
136
220
  return {
137
221
  type: DOC_TYPE_GROUP,
138
222
  id: opts.id,
@@ -154,21 +238,13 @@ function conditionalGroup(states, opts) {
154
238
  return group(states[0], { ...opts, expandedStates: states });
155
239
  }
156
240
  function fill(parts) {
157
- if (false) {
158
- for (const part of parts) {
159
- assertDoc(part);
160
- }
161
- }
241
+ assertDocArray(parts);
162
242
  return { type: DOC_TYPE_FILL, parts };
163
243
  }
164
- function ifBreak(breakContents, flatContents, opts = {}) {
165
- if (false) {
166
- if (breakContents) {
167
- assertDoc(breakContents);
168
- }
169
- if (flatContents) {
170
- assertDoc(flatContents);
171
- }
244
+ function ifBreak(breakContents, flatContents = "", opts = {}) {
245
+ assertDoc(breakContents);
246
+ if (flatContents !== "") {
247
+ assertDoc(flatContents);
172
248
  }
173
249
  return {
174
250
  type: DOC_TYPE_IF_BREAK,
@@ -178,6 +254,7 @@ function ifBreak(breakContents, flatContents, opts = {}) {
178
254
  };
179
255
  }
180
256
  function indentIfBreak(contents, opts) {
257
+ assertDoc(contents);
181
258
  return {
182
259
  type: DOC_TYPE_INDENT_IF_BREAK,
183
260
  contents,
@@ -186,9 +263,7 @@ function indentIfBreak(contents, opts) {
186
263
  };
187
264
  }
188
265
  function lineSuffix(contents) {
189
- if (false) {
190
- assertDoc(contents);
191
- }
266
+ assertDoc(contents);
192
267
  return { type: DOC_TYPE_LINE_SUFFIX, contents };
193
268
  }
194
269
  var lineSuffixBoundary = { type: DOC_TYPE_LINE_SUFFIX_BOUNDARY };
@@ -205,17 +280,20 @@ var softline = { type: DOC_TYPE_LINE, soft: true };
205
280
  var hardline = [hardlineWithoutBreakParent, breakParent];
206
281
  var literalline = [literallineWithoutBreakParent, breakParent];
207
282
  var cursor = { type: DOC_TYPE_CURSOR };
208
- function join(sep, arr) {
209
- const res = [];
210
- for (let i = 0; i < arr.length; i++) {
283
+ function join(separator, docs) {
284
+ assertDoc(separator);
285
+ assertDocArray(docs);
286
+ const parts = [];
287
+ for (let i = 0; i < docs.length; i++) {
211
288
  if (i !== 0) {
212
- res.push(sep);
289
+ parts.push(separator);
213
290
  }
214
- res.push(arr[i]);
291
+ parts.push(docs[i]);
215
292
  }
216
- return res;
293
+ return parts;
217
294
  }
218
295
  function addAlignmentToDoc(doc, size, tabWidth) {
296
+ assertDoc(doc);
219
297
  let aligned = doc;
220
298
  if (size > 0) {
221
299
  for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
@@ -227,29 +305,38 @@ function addAlignmentToDoc(doc, size, tabWidth) {
227
305
  return aligned;
228
306
  }
229
307
  function label(label2, contents) {
308
+ assertDoc(contents);
230
309
  return label2 ? { type: DOC_TYPE_LABEL, label: label2, contents } : contents;
231
310
  }
232
- var concat = (parts) => parts;
233
-
234
- // src/document/printer.js
235
- var printer_exports = {};
236
- __export(printer_exports, {
237
- printDocToString: () => printDocToString
238
- });
239
- init_define_process();
240
311
 
241
312
  // scripts/build/shims/at.js
242
- init_define_process();
243
- var at = (isOptionalObject, object, index, ...args) => {
313
+ var at = (isOptionalObject, object, index) => {
244
314
  if (isOptionalObject && (object === void 0 || object === null)) {
245
315
  return;
246
316
  }
247
- return object.at ? object.at(index, ...args) : 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);
248
321
  };
249
322
  var at_default = at;
250
323
 
324
+ // scripts/build/shims/string-replace-all.js
325
+ var stringReplaceAll = (isOptionalObject, original, pattern, replacement) => {
326
+ if (isOptionalObject && (original === void 0 || original === null)) {
327
+ return;
328
+ }
329
+ if (original.replaceAll) {
330
+ return original.replaceAll(pattern, replacement);
331
+ }
332
+ if (pattern.global) {
333
+ return original.replace(pattern, replacement);
334
+ }
335
+ return original.split(pattern).join(replacement);
336
+ };
337
+ var string_replace_all_default = stringReplaceAll;
338
+
251
339
  // src/common/end-of-line.js
252
- init_define_process();
253
340
  function convertEndOfLineToChars(value) {
254
341
  switch (value) {
255
342
  case "cr":
@@ -261,17 +348,7 @@ function convertEndOfLineToChars(value) {
261
348
  }
262
349
  }
263
350
 
264
- // src/utils/get-string-width.js
265
- init_define_process();
266
-
267
- // node_modules/string-width/index.js
268
- init_define_process();
269
-
270
- // node_modules/strip-ansi/index.js
271
- init_define_process();
272
-
273
351
  // node_modules/strip-ansi/node_modules/ansi-regex/index.js
274
- init_define_process();
275
352
  function ansiRegex({ onlyFirst = false } = {}) {
276
353
  const pattern = [
277
354
  "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
@@ -289,12 +366,26 @@ function stripAnsi(string) {
289
366
  }
290
367
 
291
368
  // node_modules/string-width/node_modules/is-fullwidth-code-point/index.js
292
- init_define_process();
293
369
  function isFullwidthCodePoint(codePoint) {
294
370
  if (!Number.isInteger(codePoint)) {
295
371
  return false;
296
372
  }
297
- return codePoint >= 4352 && (codePoint <= 4447 || codePoint === 9001 || codePoint === 9002 || 11904 <= codePoint && codePoint <= 12871 && codePoint !== 12351 || 12880 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65131 || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 262141);
373
+ return codePoint >= 4352 && (codePoint <= 4447 || // Hangul Jamo
374
+ codePoint === 9001 || // LEFT-POINTING ANGLE BRACKET
375
+ codePoint === 9002 || // RIGHT-POINTING ANGLE BRACKET
376
+ // CJK Radicals Supplement .. Enclosed CJK Letters and Months
377
+ 11904 <= codePoint && codePoint <= 12871 && codePoint !== 12351 || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
378
+ 12880 <= codePoint && codePoint <= 19903 || // CJK Unified Ideographs .. Yi Radicals
379
+ 19968 <= codePoint && codePoint <= 42182 || // Hangul Jamo Extended-A
380
+ 43360 <= codePoint && codePoint <= 43388 || // Hangul Syllables
381
+ 44032 <= codePoint && codePoint <= 55203 || // CJK Compatibility Ideographs
382
+ 63744 <= codePoint && codePoint <= 64255 || // Vertical Forms
383
+ 65040 <= codePoint && codePoint <= 65049 || // CJK Compatibility Forms .. Small Form Variants
384
+ 65072 <= codePoint && codePoint <= 65131 || // Halfwidth and Fullwidth Forms
385
+ 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 || // Kana Supplement
386
+ 110592 <= codePoint && codePoint <= 110593 || // Enclosed Ideographic Supplement
387
+ 127488 <= codePoint && codePoint <= 127569 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
388
+ 131072 <= codePoint && codePoint <= 262141);
298
389
  }
299
390
 
300
391
  // node_modules/string-width/index.js
@@ -338,141 +429,6 @@ function getStringWidth(text) {
338
429
  }
339
430
  var get_string_width_default = getStringWidth;
340
431
 
341
- // src/document/utils.js
342
- var utils_exports = {};
343
- __export(utils_exports, {
344
- canBreak: () => canBreak,
345
- cleanDoc: () => cleanDoc,
346
- findInDoc: () => findInDoc,
347
- getDocParts: () => getDocParts,
348
- getDocType: () => get_doc_type_default,
349
- mapDoc: () => mapDoc,
350
- normalizeDoc: () => normalizeDoc,
351
- normalizeParts: () => normalizeParts,
352
- propagateBreaks: () => propagateBreaks,
353
- removeLines: () => removeLines,
354
- replaceEndOfLine: () => replaceEndOfLine,
355
- stripTrailingHardline: () => stripTrailingHardline,
356
- traverseDoc: () => traverse_doc_default,
357
- willBreak: () => willBreak
358
- });
359
- init_define_process();
360
-
361
- // src/document/utils/get-doc-type.js
362
- init_define_process();
363
- function getDocType(doc) {
364
- if (typeof doc === "string") {
365
- return DOC_TYPE_STRING;
366
- }
367
- if (Array.isArray(doc)) {
368
- return DOC_TYPE_ARRAY;
369
- }
370
- if (!doc) {
371
- return;
372
- }
373
- const { type } = doc;
374
- if (VALID_OBJECT_DOC_TYPES.has(type)) {
375
- return type;
376
- }
377
- }
378
- var get_doc_type_default = getDocType;
379
-
380
- // src/document/utils/traverse-doc.js
381
- init_define_process();
382
-
383
- // src/document/invalid-doc-error.js
384
- init_define_process();
385
- var disjunctionListFormat = (list) => [...list.slice(0, -1), `or ${at_default(false, list, -1)}`].join(", ");
386
- function getDocErrorMessage(doc) {
387
- const type = doc === null ? null : typeof doc;
388
- if (type !== "string" && type !== "object") {
389
- return `Unexpected doc '${type}',
390
- Expected it to be 'string' or 'object'.`;
391
- }
392
- if (get_doc_type_default(doc)) {
393
- throw new Error("doc is valid.");
394
- }
395
- const objectType = Object.prototype.toString.call(doc);
396
- if (objectType !== "[object Object]") {
397
- return `Unexpected doc '${objectType}'.`;
398
- }
399
- const EXPECTED_TYPE_VALUES = disjunctionListFormat([...VALID_OBJECT_DOC_TYPES].map((type2) => `'${type2}'`));
400
- return `Unexpected doc.type '${doc.type}'.
401
- Expected it to be ${EXPECTED_TYPE_VALUES}.`;
402
- }
403
- var InvalidDocError = class extends Error {
404
- constructor(doc) {
405
- super(getDocErrorMessage(doc));
406
- __publicField(this, "name", "InvalidDocError");
407
- this.doc = doc;
408
- }
409
- };
410
- var invalid_doc_error_default = InvalidDocError;
411
-
412
- // src/document/utils/traverse-doc.js
413
- var traverseDocOnExitStackMarker = {};
414
- function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
415
- const docsStack = [doc];
416
- while (docsStack.length > 0) {
417
- const doc2 = docsStack.pop();
418
- if (doc2 === traverseDocOnExitStackMarker) {
419
- onExit(docsStack.pop());
420
- continue;
421
- }
422
- if (onExit) {
423
- docsStack.push(doc2, traverseDocOnExitStackMarker);
424
- }
425
- if ((onEnter == null ? void 0 : onEnter(doc2)) === false) {
426
- continue;
427
- }
428
- const docType = get_doc_type_default(doc2);
429
- switch (docType) {
430
- case DOC_TYPE_ARRAY:
431
- case DOC_TYPE_FILL: {
432
- const parts = docType === DOC_TYPE_ARRAY ? doc2 : doc2.parts;
433
- for (let ic = parts.length, i = ic - 1; i >= 0; --i) {
434
- docsStack.push(parts[i]);
435
- }
436
- break;
437
- }
438
- case DOC_TYPE_IF_BREAK:
439
- if (doc2.flatContents) {
440
- docsStack.push(doc2.flatContents);
441
- }
442
- if (doc2.breakContents) {
443
- docsStack.push(doc2.breakContents);
444
- }
445
- break;
446
- case DOC_TYPE_GROUP:
447
- if (shouldTraverseConditionalGroups && doc2.expandedStates) {
448
- for (let ic = doc2.expandedStates.length, i = ic - 1; i >= 0; --i) {
449
- docsStack.push(doc2.expandedStates[i]);
450
- }
451
- } else {
452
- docsStack.push(doc2.contents);
453
- }
454
- break;
455
- case DOC_TYPE_ALIGN:
456
- case DOC_TYPE_INDENT:
457
- case DOC_TYPE_INDENT_IF_BREAK:
458
- case DOC_TYPE_LABEL:
459
- case DOC_TYPE_LINE_SUFFIX:
460
- docsStack.push(doc2.contents);
461
- break;
462
- case DOC_TYPE_STRING:
463
- case DOC_TYPE_CURSOR:
464
- case DOC_TYPE_TRIM:
465
- case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
466
- case DOC_TYPE_LINE:
467
- case DOC_TYPE_BREAK_PARENT:
468
- break;
469
- default:
470
- throw new invalid_doc_error_default(doc2);
471
- }
472
- }
473
- }
474
- var traverse_doc_default = traverseDoc;
475
-
476
432
  // src/document/utils.js
477
433
  var getDocParts = (doc) => {
478
434
  if (Array.isArray(doc)) {
@@ -506,19 +462,12 @@ function mapDoc(doc, cb) {
506
462
  ...doc2,
507
463
  parts: doc2.parts.map(rec)
508
464
  });
509
- case DOC_TYPE_IF_BREAK: {
510
- let {
511
- breakContents,
512
- flatContents
513
- } = doc2;
514
- breakContents && (breakContents = rec(breakContents));
515
- flatContents && (flatContents = rec(flatContents));
465
+ case DOC_TYPE_IF_BREAK:
516
466
  return cb({
517
467
  ...doc2,
518
- breakContents,
519
- flatContents
468
+ breakContents: rec(doc2.breakContents),
469
+ flatContents: rec(doc2.flatContents)
520
470
  });
521
- }
522
471
  case DOC_TYPE_GROUP: {
523
472
  let {
524
473
  expandedStates,
@@ -589,7 +538,12 @@ function willBreak(doc) {
589
538
  }
590
539
  function breakParentGroup(groupStack) {
591
540
  if (groupStack.length > 0) {
592
- const parentGroup = at_default(false, groupStack, -1);
541
+ const parentGroup = at_default(
542
+ /* isOptionalObject*/
543
+ false,
544
+ groupStack,
545
+ -1
546
+ );
593
547
  if (!parentGroup.expandedStates && !parentGroup.break) {
594
548
  parentGroup.break = "propagated";
595
549
  }
@@ -623,6 +577,7 @@ function propagateBreaks(doc) {
623
577
  doc,
624
578
  propagateBreaksOnEnterFn,
625
579
  propagateBreaksOnExitFn,
580
+ /* shouldTraverseConditionalGroups */
626
581
  true
627
582
  );
628
583
  }
@@ -631,62 +586,81 @@ function removeLinesFn(doc) {
631
586
  return doc.soft ? "" : " ";
632
587
  }
633
588
  if (doc.type === DOC_TYPE_IF_BREAK) {
634
- return doc.flatContents || "";
589
+ return doc.flatContents;
635
590
  }
636
591
  return doc;
637
592
  }
638
593
  function removeLines(doc) {
639
594
  return mapDoc(doc, removeLinesFn);
640
595
  }
641
- var isHardline = (doc, nextDoc) => doc && doc.type === DOC_TYPE_LINE && doc.hard && nextDoc && nextDoc.type === DOC_TYPE_BREAK_PARENT;
642
- function stripDocTrailingHardlineFromDoc(doc) {
643
- if (!doc) {
644
- return doc;
645
- }
646
- if (Array.isArray(doc) || doc.type === DOC_TYPE_FILL) {
647
- const parts = getDocParts(doc);
648
- while (parts.length > 1 && isHardline(...parts.slice(-2))) {
649
- parts.length -= 2;
650
- }
651
- if (parts.length > 0) {
652
- const lastPart = stripDocTrailingHardlineFromDoc(at_default(false, parts, -1));
653
- parts[parts.length - 1] = lastPart;
654
- }
655
- return Array.isArray(doc) ? parts : {
656
- ...doc,
657
- parts
658
- };
659
- }
660
- switch (doc.type) {
596
+ function stripTrailingHardlineFromParts(parts) {
597
+ parts = [...parts];
598
+ while (parts.length >= 2 && at_default(
599
+ /* isOptionalObject*/
600
+ false,
601
+ parts,
602
+ -2
603
+ ).type === DOC_TYPE_LINE && at_default(
604
+ /* isOptionalObject*/
605
+ false,
606
+ parts,
607
+ -1
608
+ ).type === DOC_TYPE_BREAK_PARENT) {
609
+ parts.length -= 2;
610
+ }
611
+ if (parts.length > 0) {
612
+ const lastPart = stripTrailingHardlineFromDoc(at_default(
613
+ /* isOptionalObject*/
614
+ false,
615
+ parts,
616
+ -1
617
+ ));
618
+ parts[parts.length - 1] = lastPart;
619
+ }
620
+ return parts;
621
+ }
622
+ function stripTrailingHardlineFromDoc(doc) {
623
+ switch (get_doc_type_default(doc)) {
661
624
  case DOC_TYPE_ALIGN:
662
625
  case DOC_TYPE_INDENT:
663
626
  case DOC_TYPE_INDENT_IF_BREAK:
664
627
  case DOC_TYPE_GROUP:
665
628
  case DOC_TYPE_LINE_SUFFIX:
666
629
  case DOC_TYPE_LABEL: {
667
- const contents = stripDocTrailingHardlineFromDoc(doc.contents);
630
+ const contents = stripTrailingHardlineFromDoc(doc.contents);
668
631
  return {
669
632
  ...doc,
670
633
  contents
671
634
  };
672
635
  }
673
- case DOC_TYPE_IF_BREAK: {
674
- const breakContents = stripDocTrailingHardlineFromDoc(doc.breakContents);
675
- const flatContents = stripDocTrailingHardlineFromDoc(doc.flatContents);
636
+ case DOC_TYPE_IF_BREAK:
676
637
  return {
677
638
  ...doc,
678
- breakContents,
679
- flatContents
639
+ breakContents: stripTrailingHardlineFromDoc(doc.breakContents),
640
+ flatContents: stripTrailingHardlineFromDoc(doc.flatContents)
680
641
  };
681
- }
642
+ case DOC_TYPE_FILL:
643
+ return {
644
+ ...doc,
645
+ parts: stripTrailingHardlineFromParts(doc.parts)
646
+ };
647
+ case DOC_TYPE_ARRAY:
648
+ return stripTrailingHardlineFromParts(doc);
649
+ case DOC_TYPE_STRING:
650
+ return doc.replace(/[\n\r]*$/, "");
651
+ case DOC_TYPE_CURSOR:
652
+ case DOC_TYPE_TRIM:
653
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
654
+ case DOC_TYPE_LINE:
655
+ case DOC_TYPE_BREAK_PARENT:
656
+ break;
657
+ default:
658
+ throw new invalid_doc_error_default(doc);
682
659
  }
683
660
  return doc;
684
661
  }
685
662
  function stripTrailingHardline(doc) {
686
- if (typeof doc === "string") {
687
- return doc.replace(/(?:\r?\n)*$/, "");
688
- }
689
- return stripDocTrailingHardlineFromDoc(cleanDoc(doc));
663
+ return stripTrailingHardlineFromDoc(cleanDoc(doc));
690
664
  }
691
665
  function cleanDocFn(doc) {
692
666
  switch (get_doc_type_default(doc)) {
@@ -723,7 +697,12 @@ function cleanDocFn(doc) {
723
697
  continue;
724
698
  }
725
699
  const [currentPart, ...restParts] = Array.isArray(part) ? part : [part];
726
- if (typeof currentPart === "string" && typeof at_default(false, parts, -1) === "string") {
700
+ if (typeof currentPart === "string" && typeof at_default(
701
+ /* isOptionalObject*/
702
+ false,
703
+ parts,
704
+ -1
705
+ ) === "string") {
727
706
  parts[parts.length - 1] += currentPart;
728
707
  } else {
729
708
  parts.push(currentPart);
@@ -754,40 +733,6 @@ function cleanDocFn(doc) {
754
733
  function cleanDoc(doc) {
755
734
  return mapDoc(doc, (currentDoc) => cleanDocFn(currentDoc));
756
735
  }
757
- function normalizeParts(parts) {
758
- const newParts = [];
759
- const restParts = parts.filter(Boolean);
760
- while (restParts.length > 0) {
761
- const part = restParts.shift();
762
- if (!part) {
763
- continue;
764
- }
765
- if (Array.isArray(part)) {
766
- restParts.unshift(...part);
767
- continue;
768
- }
769
- if (newParts.length > 0 && typeof at_default(false, newParts, -1) === "string" && typeof part === "string") {
770
- newParts[newParts.length - 1] += part;
771
- continue;
772
- }
773
- newParts.push(part);
774
- }
775
- return newParts;
776
- }
777
- function normalizeDoc(doc) {
778
- return mapDoc(doc, (currentDoc) => {
779
- if (Array.isArray(currentDoc)) {
780
- return normalizeParts(currentDoc);
781
- }
782
- if (!currentDoc.parts) {
783
- return currentDoc;
784
- }
785
- return {
786
- ...currentDoc,
787
- parts: normalizeParts(currentDoc.parts)
788
- };
789
- });
790
- }
791
736
  function replaceEndOfLine(doc, replacement = literalline) {
792
737
  return mapDoc(doc, (currentDoc) => typeof currentDoc === "string" ? join(replacement, currentDoc.split("\n")) : currentDoc);
793
738
  }
@@ -941,6 +886,9 @@ function trim2(out) {
941
886
  return trimCount;
942
887
  }
943
888
  function fits(next, restCommands, width, hasLineSuffix, groupModeMap, mustBeFlat) {
889
+ if (width === Number.POSITIVE_INFINITY) {
890
+ return true;
891
+ }
944
892
  let restIdx = restCommands.length;
945
893
  const cmds = [next];
946
894
  const out = [];
@@ -989,7 +937,12 @@ function fits(next, restCommands, width, hasLineSuffix, groupModeMap, mustBeFlat
989
937
  return false;
990
938
  }
991
939
  const groupMode = doc.break ? MODE_BREAK : mode;
992
- const contents = doc.expandedStates && groupMode === MODE_BREAK ? at_default(false, doc.expandedStates, -1) : doc.contents;
940
+ const contents = doc.expandedStates && groupMode === MODE_BREAK ? at_default(
941
+ /* isOptionalObject*/
942
+ false,
943
+ doc.expandedStates,
944
+ -1
945
+ ) : doc.contents;
993
946
  cmds.push({
994
947
  mode: groupMode,
995
948
  doc: contents
@@ -1042,6 +995,7 @@ function printDocToString(doc, options) {
1042
995
  let shouldRemeasure = false;
1043
996
  const lineSuffix2 = [];
1044
997
  let printedCursorCount = 0;
998
+ propagateBreaks(doc);
1045
999
  while (cmds.length > 0) {
1046
1000
  const {
1047
1001
  ind,
@@ -1050,9 +1004,17 @@ function printDocToString(doc, options) {
1050
1004
  } = cmds.pop();
1051
1005
  switch (get_doc_type_default(doc2)) {
1052
1006
  case DOC_TYPE_STRING: {
1053
- const formatted = newLine !== "\n" ? doc2.replace(/\n/g, newLine) : doc2;
1007
+ const formatted = newLine !== "\n" ? string_replace_all_default(
1008
+ /* isOptionalObject*/
1009
+ false,
1010
+ doc2,
1011
+ "\n",
1012
+ newLine
1013
+ ) : doc2;
1054
1014
  out.push(formatted);
1055
- pos += get_string_width_default(formatted);
1015
+ if (cmds.length > 0) {
1016
+ pos += get_string_width_default(formatted);
1017
+ }
1056
1018
  break;
1057
1019
  }
1058
1020
  case DOC_TYPE_ARRAY:
@@ -1112,7 +1074,12 @@ function printDocToString(doc, options) {
1112
1074
  cmds.push(next);
1113
1075
  } else {
1114
1076
  if (doc2.expandedStates) {
1115
- const mostExpanded = at_default(false, doc2.expandedStates, -1);
1077
+ const mostExpanded = at_default(
1078
+ /* isOptionalObject*/
1079
+ false,
1080
+ doc2.expandedStates,
1081
+ -1
1082
+ );
1116
1083
  if (doc2.break) {
1117
1084
  cmds.push({
1118
1085
  ind,
@@ -1155,7 +1122,12 @@ function printDocToString(doc, options) {
1155
1122
  }
1156
1123
  }
1157
1124
  if (doc2.id) {
1158
- groupModeMap[doc2.id] = at_default(false, cmds, -1).mode;
1125
+ groupModeMap[doc2.id] = at_default(
1126
+ /* isOptionalObject*/
1127
+ false,
1128
+ cmds,
1129
+ -1
1130
+ ).mode;
1159
1131
  }
1160
1132
  break;
1161
1133
  case DOC_TYPE_FILL: {
@@ -1339,152 +1311,48 @@ function printDocToString(doc, options) {
1339
1311
  };
1340
1312
  }
1341
1313
 
1342
- // src/document/debug.js
1343
- var debug_exports = {};
1344
- __export(debug_exports, {
1345
- printDocToDebug: () => printDocToDebug
1346
- });
1347
- init_define_process();
1348
- function flattenDoc(doc) {
1349
- if (!doc) {
1350
- return "";
1351
- }
1352
- if (Array.isArray(doc)) {
1353
- const res = [];
1354
- for (const part of doc) {
1355
- if (Array.isArray(part)) {
1356
- res.push(...flattenDoc(part));
1357
- } else {
1358
- const flattened = flattenDoc(part);
1359
- if (flattened !== "") {
1360
- res.push(flattened);
1361
- }
1362
- }
1363
- }
1364
- return res;
1365
- }
1366
- if (doc.type === DOC_TYPE_IF_BREAK) {
1367
- return {
1368
- ...doc,
1369
- breakContents: flattenDoc(doc.breakContents),
1370
- flatContents: flattenDoc(doc.flatContents)
1371
- };
1372
- }
1373
- if (doc.type === DOC_TYPE_GROUP) {
1374
- return {
1375
- ...doc,
1376
- contents: flattenDoc(doc.contents),
1377
- expandedStates: doc.expandedStates && doc.expandedStates.map(flattenDoc)
1378
- };
1379
- }
1380
- if (doc.type === DOC_TYPE_FILL) {
1381
- return { type: "fill", parts: doc.parts.map(flattenDoc) };
1382
- }
1383
- if (doc.contents) {
1384
- return { ...doc, contents: flattenDoc(doc.contents) };
1385
- }
1386
- return doc;
1387
- }
1388
- function printDocToDebug(doc) {
1389
- const printedSymbols = /* @__PURE__ */ Object.create(null);
1390
- const usedKeysForSymbols = /* @__PURE__ */ new Set();
1391
- return printDoc(flattenDoc(doc));
1392
- function printDoc(doc2, index, parentParts) {
1393
- if (typeof doc2 === "string") {
1394
- return JSON.stringify(doc2);
1395
- }
1396
- if (Array.isArray(doc2)) {
1397
- const printed = doc2.map(printDoc).filter(Boolean);
1398
- return printed.length === 1 ? printed[0] : `[${printed.join(", ")}]`;
1399
- }
1400
- if (doc2.type === DOC_TYPE_LINE) {
1401
- const withBreakParent = Array.isArray(parentParts) && parentParts[index + 1] && parentParts[index + 1].type === DOC_TYPE_BREAK_PARENT;
1402
- if (doc2.literal) {
1403
- return withBreakParent ? "literalline" : "literallineWithoutBreakParent";
1404
- }
1405
- if (doc2.hard) {
1406
- return withBreakParent ? "hardline" : "hardlineWithoutBreakParent";
1407
- }
1408
- if (doc2.soft) {
1409
- return "softline";
1410
- }
1411
- return "line";
1412
- }
1413
- if (doc2.type === DOC_TYPE_BREAK_PARENT) {
1414
- const afterHardline = Array.isArray(parentParts) && parentParts[index - 1] && parentParts[index - 1].type === DOC_TYPE_LINE && parentParts[index - 1].hard;
1415
- return afterHardline ? void 0 : "breakParent";
1416
- }
1417
- if (doc2.type === DOC_TYPE_TRIM) {
1418
- return "trim";
1419
- }
1420
- if (doc2.type === DOC_TYPE_INDENT) {
1421
- return "indent(" + printDoc(doc2.contents) + ")";
1422
- }
1423
- if (doc2.type === DOC_TYPE_ALIGN) {
1424
- 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) + ")";
1425
- }
1426
- if (doc2.type === DOC_TYPE_IF_BREAK) {
1427
- return "ifBreak(" + printDoc(doc2.breakContents) + (doc2.flatContents ? ", " + printDoc(doc2.flatContents) : "") + (doc2.groupId ? (!doc2.flatContents ? ', ""' : "") + `, { groupId: ${printGroupId(doc2.groupId)} }` : "") + ")";
1428
- }
1429
- if (doc2.type === DOC_TYPE_INDENT_IF_BREAK) {
1430
- const optionsParts = [];
1431
- if (doc2.negate) {
1432
- optionsParts.push("negate: true");
1433
- }
1434
- if (doc2.groupId) {
1435
- optionsParts.push(`groupId: ${printGroupId(doc2.groupId)}`);
1436
- }
1437
- const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
1438
- return `indentIfBreak(${printDoc(doc2.contents)}${options})`;
1439
- }
1440
- if (doc2.type === DOC_TYPE_GROUP) {
1441
- const optionsParts = [];
1442
- if (doc2.break && doc2.break !== "propagated") {
1443
- optionsParts.push("shouldBreak: true");
1444
- }
1445
- if (doc2.id) {
1446
- optionsParts.push(`id: ${printGroupId(doc2.id)}`);
1447
- }
1448
- const options = optionsParts.length > 0 ? `, { ${optionsParts.join(", ")} }` : "";
1449
- if (doc2.expandedStates) {
1450
- return `conditionalGroup([${doc2.expandedStates.map((part) => printDoc(part)).join(",")}]${options})`;
1451
- }
1452
- return `group(${printDoc(doc2.contents)}${options})`;
1453
- }
1454
- if (doc2.type === DOC_TYPE_FILL) {
1455
- return `fill([${doc2.parts.map((part) => printDoc(part)).join(", ")}])`;
1456
- }
1457
- if (doc2.type === DOC_TYPE_LINE_SUFFIX) {
1458
- return "lineSuffix(" + printDoc(doc2.contents) + ")";
1459
- }
1460
- if (doc2.type === DOC_TYPE_LINE_SUFFIX_BOUNDARY) {
1461
- return "lineSuffixBoundary";
1462
- }
1463
- if (doc2.type === DOC_TYPE_LABEL) {
1464
- return `label(${JSON.stringify(doc2.label)}, ${printDoc(doc2.contents)})`;
1465
- }
1466
- throw new Error("Unknown doc type " + doc2.type);
1467
- }
1468
- function printGroupId(id) {
1469
- if (typeof id !== "symbol") {
1470
- return JSON.stringify(String(id));
1471
- }
1472
- if (id in printedSymbols) {
1473
- return printedSymbols[id];
1474
- }
1475
- const prefix = id.description || "symbol";
1476
- for (let counter = 0; ; counter++) {
1477
- const key = prefix + (counter > 0 ? ` #${counter}` : "");
1478
- if (!usedKeysForSymbols.has(key)) {
1479
- usedKeysForSymbols.add(key);
1480
- return printedSymbols[id] = `Symbol.for(${JSON.stringify(key)})`;
1481
- }
1482
- }
1483
- }
1484
- }
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
+ };
1485
1354
  export {
1486
- builders_exports as builders,
1487
- debug_exports as debug,
1488
- printer_exports as printer,
1489
- utils_exports as utils
1355
+ builders,
1356
+ printer,
1357
+ utils
1490
1358
  };