prettier 3.0.0-alpha.3 → 3.0.0-alpha.4

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/doc.mjs CHANGED
@@ -161,7 +161,7 @@ function fill(parts) {
161
161
  }
162
162
  return { type: DOC_TYPE_FILL, parts };
163
163
  }
164
- function ifBreak(breakContents, flatContents, opts = {}) {
164
+ function ifBreak(breakContents, flatContents = "", opts = {}) {
165
165
  if (false) {
166
166
  if (breakContents) {
167
167
  assertDoc(breakContents);
@@ -436,12 +436,7 @@ function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
436
436
  break;
437
437
  }
438
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
- }
439
+ docsStack.push(doc2.flatContents, doc2.breakContents);
445
440
  break;
446
441
  case DOC_TYPE_GROUP:
447
442
  if (shouldTraverseConditionalGroups && doc2.expandedStates) {
@@ -506,19 +501,12 @@ function mapDoc(doc, cb) {
506
501
  ...doc2,
507
502
  parts: doc2.parts.map(rec)
508
503
  });
509
- case DOC_TYPE_IF_BREAK: {
510
- let {
511
- breakContents,
512
- flatContents
513
- } = doc2;
514
- breakContents && (breakContents = rec(breakContents));
515
- flatContents && (flatContents = rec(flatContents));
504
+ case DOC_TYPE_IF_BREAK:
516
505
  return cb({
517
506
  ...doc2,
518
- breakContents,
519
- flatContents
507
+ breakContents: rec(doc2.breakContents),
508
+ flatContents: rec(doc2.flatContents)
520
509
  });
521
- }
522
510
  case DOC_TYPE_GROUP: {
523
511
  let {
524
512
  expandedStates,
@@ -626,62 +614,66 @@ function removeLinesFn(doc) {
626
614
  return doc.soft ? "" : " ";
627
615
  }
628
616
  if (doc.type === DOC_TYPE_IF_BREAK) {
629
- return doc.flatContents || "";
617
+ return doc.flatContents;
630
618
  }
631
619
  return doc;
632
620
  }
633
621
  function removeLines(doc) {
634
622
  return mapDoc(doc, removeLinesFn);
635
623
  }
636
- var isHardline = (doc, nextDoc) => doc && doc.type === DOC_TYPE_LINE && doc.hard && nextDoc && nextDoc.type === DOC_TYPE_BREAK_PARENT;
637
- function stripDocTrailingHardlineFromDoc(doc) {
638
- if (!doc) {
639
- return doc;
624
+ function stripTrailingHardlineFromParts(parts) {
625
+ parts = [...parts];
626
+ while (parts.length >= 2 && at_default(false, parts, -2).type === DOC_TYPE_LINE && at_default(false, parts, -1).type === DOC_TYPE_BREAK_PARENT) {
627
+ parts.length -= 2;
640
628
  }
641
- if (Array.isArray(doc) || doc.type === DOC_TYPE_FILL) {
642
- const parts = getDocParts(doc);
643
- while (parts.length > 1 && isHardline(...parts.slice(-2))) {
644
- parts.length -= 2;
645
- }
646
- if (parts.length > 0) {
647
- const lastPart = stripDocTrailingHardlineFromDoc(at_default(false, parts, -1));
648
- parts[parts.length - 1] = lastPart;
649
- }
650
- return Array.isArray(doc) ? parts : {
651
- ...doc,
652
- parts
653
- };
629
+ if (parts.length > 0) {
630
+ const lastPart = stripTrailingHardlineFromDoc(at_default(false, parts, -1));
631
+ parts[parts.length - 1] = lastPart;
654
632
  }
655
- switch (doc.type) {
633
+ return parts;
634
+ }
635
+ function stripTrailingHardlineFromDoc(doc) {
636
+ switch (get_doc_type_default(doc)) {
656
637
  case DOC_TYPE_ALIGN:
657
638
  case DOC_TYPE_INDENT:
658
639
  case DOC_TYPE_INDENT_IF_BREAK:
659
640
  case DOC_TYPE_GROUP:
660
641
  case DOC_TYPE_LINE_SUFFIX:
661
642
  case DOC_TYPE_LABEL: {
662
- const contents = stripDocTrailingHardlineFromDoc(doc.contents);
643
+ const contents = stripTrailingHardlineFromDoc(doc.contents);
663
644
  return {
664
645
  ...doc,
665
646
  contents
666
647
  };
667
648
  }
668
- case DOC_TYPE_IF_BREAK: {
669
- const breakContents = stripDocTrailingHardlineFromDoc(doc.breakContents);
670
- const flatContents = stripDocTrailingHardlineFromDoc(doc.flatContents);
649
+ case DOC_TYPE_IF_BREAK:
671
650
  return {
672
651
  ...doc,
673
- breakContents,
674
- flatContents
652
+ breakContents: stripTrailingHardlineFromDoc(doc.breakContents),
653
+ flatContents: stripTrailingHardlineFromDoc(doc.flatContents)
675
654
  };
676
- }
655
+ case DOC_TYPE_FILL:
656
+ return {
657
+ ...doc,
658
+ parts: stripTrailingHardlineFromParts(doc.parts)
659
+ };
660
+ case DOC_TYPE_ARRAY:
661
+ return stripTrailingHardlineFromParts(doc);
662
+ case DOC_TYPE_STRING:
663
+ return doc.replace(/[\n\r]*$/, "");
664
+ case DOC_TYPE_CURSOR:
665
+ case DOC_TYPE_TRIM:
666
+ case DOC_TYPE_LINE_SUFFIX_BOUNDARY:
667
+ case DOC_TYPE_LINE:
668
+ case DOC_TYPE_BREAK_PARENT:
669
+ break;
670
+ default:
671
+ throw new invalid_doc_error_default(doc);
677
672
  }
678
673
  return doc;
679
674
  }
680
675
  function stripTrailingHardline(doc) {
681
- if (typeof doc === "string") {
682
- return doc.replace(/(?:\r?\n)*$/, "");
683
- }
684
- return stripDocTrailingHardlineFromDoc(cleanDoc(doc));
676
+ return stripTrailingHardlineFromDoc(cleanDoc(doc));
685
677
  }
686
678
  function cleanDocFn(doc) {
687
679
  switch (get_doc_type_default(doc)) {
@@ -1341,6 +1333,7 @@ __export(debug_exports, {
1341
1333
  });
1342
1334
  init_define_process();
1343
1335
  function flattenDoc(doc) {
1336
+ var _a;
1344
1337
  if (!doc) {
1345
1338
  return "";
1346
1339
  }
@@ -1369,7 +1362,7 @@ function flattenDoc(doc) {
1369
1362
  return {
1370
1363
  ...doc,
1371
1364
  contents: flattenDoc(doc.contents),
1372
- expandedStates: doc.expandedStates && doc.expandedStates.map(flattenDoc)
1365
+ expandedStates: (_a = doc.expandedStates) == null ? void 0 : _a.map(flattenDoc)
1373
1366
  };
1374
1367
  }
1375
1368
  if (doc.type === DOC_TYPE_FILL) {
package/index.cjs CHANGED
@@ -280,31 +280,6 @@ var init_get_string_width = __esm({
280
280
  });
281
281
 
282
282
  // src/common/util.js
283
- function skip2(chars) {
284
- return (text, index, opts) => {
285
- const backwards = opts && opts.backwards;
286
- if (index === false) {
287
- return false;
288
- }
289
- const { length } = text;
290
- let cursor = index;
291
- while (cursor >= 0 && cursor < length) {
292
- const c = text.charAt(cursor);
293
- if (chars instanceof RegExp) {
294
- if (!chars.test(c)) {
295
- return cursor;
296
- }
297
- } else if (!chars.includes(c)) {
298
- return cursor;
299
- }
300
- backwards ? cursor-- : cursor++;
301
- }
302
- if (cursor === -1 || cursor === length) {
303
- return cursor;
304
- }
305
- return false;
306
- };
307
- }
308
283
  function hasNewline(text, index, opts = {}) {
309
284
  const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
310
285
  const idx2 = skip_newline_default(text, idx, opts);
@@ -467,7 +442,7 @@ __export(util_shared_exports, {
467
442
  isNextLineEmptyAfterIndex: () => isNextLineEmptyAfterIndex,
468
443
  isPreviousLineEmpty: () => isPreviousLineEmpty,
469
444
  makeString: () => makeString,
470
- skip: () => skip2,
445
+ skip: () => skip,
471
446
  skipEverythingButNewLine: () => skipEverythingButNewLine,
472
447
  skipInlineComment: () => skip_inline_comment_default,
473
448
  skipNewline: () => skip_newline_default,
@@ -485,7 +460,7 @@ var init_util_shared = __esm({
485
460
  // src/main/version.evaluate.cjs
486
461
  var require_version_evaluate = __commonJS({
487
462
  "src/main/version.evaluate.cjs"(exports2, module2) {
488
- module2.exports = "3.0.0-alpha.3";
463
+ module2.exports = "3.0.0-alpha.4";
489
464
  }
490
465
  });
491
466
 
@@ -503,10 +478,26 @@ var functionNames = [
503
478
  ];
504
479
  var prettier = /* @__PURE__ */ Object.create(null);
505
480
  for (const name of functionNames) {
506
- prettier[name] = function(...args) {
507
- return prettierPromise.then((prettier2) => prettier2[name](...args));
481
+ prettier[name] = async (...args) => {
482
+ const prettier2 = await prettierPromise;
483
+ return prettier2[name](...args);
484
+ };
485
+ }
486
+ var debugApiFunctionNames = [
487
+ "parse",
488
+ "formatAST",
489
+ "formatDoc",
490
+ "printToDoc",
491
+ "printDocToString"
492
+ ];
493
+ var debugApis = /* @__PURE__ */ Object.create(null);
494
+ for (const name of debugApiFunctionNames) {
495
+ debugApis[name] = async (...args) => {
496
+ const prettier2 = await prettierPromise;
497
+ return prettier2.__debug[name](...args);
508
498
  };
509
499
  }
500
+ prettier.__debug = debugApis;
510
501
  if (true) {
511
502
  prettier.util = (init_util_shared(), __toCommonJS(util_shared_exports));
512
503
  prettier.doc = require("./doc.js");