prettier 3.2.5 → 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/LICENSE +56 -535
- package/bin/prettier.cjs +4 -8
- package/doc.js +20 -29
- package/doc.mjs +20 -29
- package/index.cjs +1 -1
- package/index.d.ts +4 -2
- package/index.mjs +3109 -4509
- package/internal/cli.mjs +339 -3544
- package/package.json +1 -1
- package/plugins/acorn.js +11 -11
- package/plugins/acorn.mjs +11 -11
- package/plugins/angular.js +1 -1
- package/plugins/angular.mjs +1 -1
- package/plugins/babel.js +11 -11
- package/plugins/babel.mjs +11 -11
- package/plugins/estree.js +28 -28
- package/plugins/estree.mjs +28 -28
- package/plugins/flow.js +16 -17
- package/plugins/flow.mjs +16 -17
- package/plugins/glimmer.js +22 -22
- package/plugins/glimmer.mjs +22 -22
- package/plugins/graphql.js +4 -4
- package/plugins/graphql.mjs +4 -4
- package/plugins/html.js +15 -15
- package/plugins/html.mjs +15 -15
- package/plugins/markdown.js +42 -42
- package/plugins/markdown.mjs +42 -42
- package/plugins/meriyah.js +5 -5
- package/plugins/meriyah.mjs +5 -5
- package/plugins/postcss.js +26 -26
- package/plugins/postcss.mjs +26 -26
- package/plugins/typescript.js +20 -20
- package/plugins/typescript.mjs +20 -20
- package/plugins/yaml.js +32 -32
- package/plugins/yaml.mjs +32 -32
- package/standalone.js +26 -26
- package/standalone.mjs +26 -26
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
|
-
|
|
21
|
-
if (nb
|
|
22
|
-
|
|
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
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
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
|
-
|
|
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 =
|
|
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
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
|
|
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?:
|
|
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;
|