prettier 3.2.4 → 3.3.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/bin/prettier.cjs CHANGED
@@ -16,14 +16,10 @@ var require_semver_compare = __commonJS({
16
16
  for (var i = 0; i < 3; i++) {
17
17
  var na = Number(pa[i]);
18
18
  var nb = Number(pb[i]);
19
- if (na > nb)
20
- return 1;
21
- if (nb > na)
22
- return -1;
23
- if (!isNaN(na) && isNaN(nb))
24
- return 1;
25
- if (isNaN(na) && !isNaN(nb))
26
- return -1;
19
+ if (na > nb) return 1;
20
+ if (nb > na) return -1;
21
+ if (!isNaN(na) && isNaN(nb)) return 1;
22
+ if (isNaN(na) && !isNaN(nb)) return -1;
27
23
  }
28
24
  return 0;
29
25
  };
package/doc.js CHANGED
@@ -403,15 +403,6 @@ Expected it to be ${EXPECTED_TYPE_VALUES}.`;
403
403
  var get_string_width_default = getStringWidth;
404
404
 
405
405
  // src/document/utils.js
406
- var getDocParts = (doc) => {
407
- if (Array.isArray(doc)) {
408
- return doc;
409
- }
410
- if (doc.type !== DOC_TYPE_FILL) {
411
- throw new Error(`Expect doc to be 'array' or '${DOC_TYPE_FILL}'.`);
412
- }
413
- return doc.parts;
414
- };
415
406
  function mapDoc(doc, cb) {
416
407
  if (typeof doc === "string") {
417
408
  return cb(doc);
@@ -830,26 +821,25 @@ Expected it to be ${EXPECTED_TYPE_VALUES}.`;
830
821
  let trimCount = 0;
831
822
  let cursorCount = 0;
832
823
  let outIndex = out.length;
833
- outer:
834
- while (outIndex--) {
835
- const last = out[outIndex];
836
- if (last === CURSOR_PLACEHOLDER) {
837
- cursorCount++;
838
- continue;
839
- }
840
- if (false) {
841
- throw new Error(`Unexpected value in trim: '${typeof last}'`);
842
- }
843
- for (let charIndex = last.length - 1; charIndex >= 0; charIndex--) {
844
- const char = last[charIndex];
845
- if (char === " " || char === " ") {
846
- trimCount++;
847
- } else {
848
- out[outIndex] = last.slice(0, charIndex + 1);
849
- break outer;
850
- }
824
+ outer: while (outIndex--) {
825
+ const last = out[outIndex];
826
+ if (last === CURSOR_PLACEHOLDER) {
827
+ cursorCount++;
828
+ continue;
829
+ }
830
+ if (false) {
831
+ throw new Error(`Unexpected value in trim: '${typeof last}'`);
832
+ }
833
+ for (let charIndex = last.length - 1; charIndex >= 0; charIndex--) {
834
+ const char = last[charIndex];
835
+ if (char === " " || char === " ") {
836
+ trimCount++;
837
+ } else {
838
+ out[outIndex] = last.slice(0, charIndex + 1);
839
+ break outer;
851
840
  }
852
841
  }
842
+ }
853
843
  if (trimCount > 0 || cursorCount > 0) {
854
844
  out.length = outIndex + 1;
855
845
  while (cursorCount-- > 0) {
@@ -877,14 +867,15 @@ Expected it to be ${EXPECTED_TYPE_VALUES}.`;
877
867
  mode,
878
868
  doc
879
869
  } = cmds.pop();
880
- switch (get_doc_type_default(doc)) {
870
+ const docType = get_doc_type_default(doc);
871
+ switch (docType) {
881
872
  case DOC_TYPE_STRING:
882
873
  out.push(doc);
883
874
  width -= get_string_width_default(doc);
884
875
  break;
885
876
  case DOC_TYPE_ARRAY:
886
877
  case DOC_TYPE_FILL: {
887
- const parts = getDocParts(doc);
878
+ const parts = docType === DOC_TYPE_ARRAY ? doc : doc.parts;
888
879
  for (let i = parts.length - 1; i >= 0; i--) {
889
880
  cmds.push({
890
881
  mode,
package/doc.mjs CHANGED
@@ -368,15 +368,6 @@ function getStringWidth(text) {
368
368
  var get_string_width_default = getStringWidth;
369
369
 
370
370
  // src/document/utils.js
371
- var getDocParts = (doc) => {
372
- if (Array.isArray(doc)) {
373
- return doc;
374
- }
375
- if (doc.type !== DOC_TYPE_FILL) {
376
- throw new Error(`Expect doc to be 'array' or '${DOC_TYPE_FILL}'.`);
377
- }
378
- return doc.parts;
379
- };
380
371
  function mapDoc(doc, cb) {
381
372
  if (typeof doc === "string") {
382
373
  return cb(doc);
@@ -795,26 +786,25 @@ function trim2(out) {
795
786
  let trimCount = 0;
796
787
  let cursorCount = 0;
797
788
  let outIndex = out.length;
798
- outer:
799
- while (outIndex--) {
800
- const last = out[outIndex];
801
- if (last === CURSOR_PLACEHOLDER) {
802
- cursorCount++;
803
- continue;
804
- }
805
- if (false) {
806
- throw new Error(`Unexpected value in trim: '${typeof last}'`);
807
- }
808
- for (let charIndex = last.length - 1; charIndex >= 0; charIndex--) {
809
- const char = last[charIndex];
810
- if (char === " " || char === " ") {
811
- trimCount++;
812
- } else {
813
- out[outIndex] = last.slice(0, charIndex + 1);
814
- break outer;
815
- }
789
+ outer: while (outIndex--) {
790
+ const last = out[outIndex];
791
+ if (last === CURSOR_PLACEHOLDER) {
792
+ cursorCount++;
793
+ continue;
794
+ }
795
+ if (false) {
796
+ throw new Error(`Unexpected value in trim: '${typeof last}'`);
797
+ }
798
+ for (let charIndex = last.length - 1; charIndex >= 0; charIndex--) {
799
+ const char = last[charIndex];
800
+ if (char === " " || char === " ") {
801
+ trimCount++;
802
+ } else {
803
+ out[outIndex] = last.slice(0, charIndex + 1);
804
+ break outer;
816
805
  }
817
806
  }
807
+ }
818
808
  if (trimCount > 0 || cursorCount > 0) {
819
809
  out.length = outIndex + 1;
820
810
  while (cursorCount-- > 0) {
@@ -842,14 +832,15 @@ function fits(next, restCommands, width, hasLineSuffix, groupModeMap, mustBeFlat
842
832
  mode,
843
833
  doc
844
834
  } = cmds.pop();
845
- switch (get_doc_type_default(doc)) {
835
+ const docType = get_doc_type_default(doc);
836
+ switch (docType) {
846
837
  case DOC_TYPE_STRING:
847
838
  out.push(doc);
848
839
  width -= get_string_width_default(doc);
849
840
  break;
850
841
  case DOC_TYPE_ARRAY:
851
842
  case DOC_TYPE_FILL: {
852
- const parts = getDocParts(doc);
843
+ const parts = docType === DOC_TYPE_ARRAY ? doc : doc.parts;
853
844
  for (let i = parts.length - 1; i >= 0; i--) {
854
845
  cmds.push({
855
846
  mode,
package/index.cjs CHANGED
@@ -585,7 +585,7 @@ var init_public = __esm({
585
585
  // src/main/version.evaluate.cjs
586
586
  var require_version_evaluate = __commonJS({
587
587
  "src/main/version.evaluate.cjs"(exports2, module2) {
588
- module2.exports = "3.2.4";
588
+ module2.exports = "3.3.0";
589
589
  }
590
590
  });
591
591
 
package/index.d.ts CHANGED
@@ -496,10 +496,12 @@ export interface Printer<T = any> {
496
496
  insertPragma?: (text: string) => string;
497
497
  /**
498
498
  * @returns `null` if you want to remove this node
499
- * @returns `void` if you want to use modified newNode
499
+ * @returns `void` if you want to use modified `cloned`
500
500
  * @returns anything if you want to replace the node with it
501
501
  */
502
- massageAstNode?: ((node: any, newNode: any, parent: any) => any) | undefined;
502
+ massageAstNode?:
503
+ | ((original: any, cloned: any, parent: any) => any)
504
+ | undefined;
503
505
  hasPrettierIgnore?: ((path: AstPath<T>) => boolean) | undefined;
504
506
  canAttachComment?: ((node: T) => boolean) | undefined;
505
507
  isBlockComment?: ((node: T) => boolean) | undefined;