@prettier/plugin-php 0.19.3 → 0.19.5
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/package.json +8 -7
- package/src/clean.js +20 -20
- package/src/comments.js +12 -24
- package/src/index.js +1 -1
- package/src/options.js +1 -0
- package/src/parser.js +1 -5
- package/src/pragma.js +3 -13
- package/src/printer.js +619 -801
- package/src/util.js +2 -1
- package/standalone.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prettier/plugin-php",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.5",
|
|
4
4
|
"description": "Prettier PHP Plugin",
|
|
5
5
|
"repository": "prettier/prettier-php",
|
|
6
6
|
"author": "Lucas Azzola <@azz>",
|
|
@@ -19,16 +19,17 @@
|
|
|
19
19
|
"@babel/preset-env": "^7.19.4",
|
|
20
20
|
"codecov": "3.8.3",
|
|
21
21
|
"cross-env": "^7.0.2",
|
|
22
|
-
"eslint": "8.
|
|
23
|
-
"eslint-config-prettier": "8.
|
|
22
|
+
"eslint": "8.36.0",
|
|
23
|
+
"eslint-config-prettier": "8.7.0",
|
|
24
24
|
"eslint-plugin-import": "2.27.5",
|
|
25
25
|
"eslint-plugin-jest": "27.2.1",
|
|
26
26
|
"eslint-plugin-prettier": "4.2.1",
|
|
27
|
-
"
|
|
28
|
-
"jest
|
|
29
|
-
"jest-
|
|
27
|
+
"eslint-plugin-prettier-doc": "^1.1.0",
|
|
28
|
+
"jest": "29.5.0",
|
|
29
|
+
"jest-environment-jsdom": "29.5.0",
|
|
30
|
+
"jest-runner-eslint": "2.0.0",
|
|
30
31
|
"jest-snapshot-serializer-raw": "^1.1.0",
|
|
31
|
-
"prettier": "2.
|
|
32
|
+
"prettier": "^2.8.4",
|
|
32
33
|
"rollup": "^2.75.7",
|
|
33
34
|
"rollup-plugin-alias": "^2.0.0",
|
|
34
35
|
"rollup-plugin-babel": "^4.3.2",
|
package/src/clean.js
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
const util = require("./util");
|
|
4
4
|
|
|
5
|
+
const ignoredProperties = new Set([
|
|
6
|
+
"loc",
|
|
7
|
+
"range",
|
|
8
|
+
"raw",
|
|
9
|
+
"comments",
|
|
10
|
+
"leadingComments",
|
|
11
|
+
"trailingComments",
|
|
12
|
+
"parenthesizedExpression",
|
|
13
|
+
"parent",
|
|
14
|
+
"prev",
|
|
15
|
+
"start",
|
|
16
|
+
"end",
|
|
17
|
+
"tokens",
|
|
18
|
+
"errors",
|
|
19
|
+
"extra",
|
|
20
|
+
]);
|
|
21
|
+
|
|
5
22
|
/**
|
|
6
23
|
* This function takes the existing ast node and a copy, by reference
|
|
7
24
|
* We use it for testing, so that we can compare pre-post versions of the AST,
|
|
@@ -9,25 +26,6 @@ const util = require("./util");
|
|
|
9
26
|
* changed by the printer, etc.)
|
|
10
27
|
*/
|
|
11
28
|
function clean(node, newObj) {
|
|
12
|
-
[
|
|
13
|
-
"loc",
|
|
14
|
-
"range",
|
|
15
|
-
"raw",
|
|
16
|
-
"comments",
|
|
17
|
-
"leadingComments",
|
|
18
|
-
"trailingComments",
|
|
19
|
-
"parenthesizedExpression",
|
|
20
|
-
"parent",
|
|
21
|
-
"prev",
|
|
22
|
-
"start",
|
|
23
|
-
"end",
|
|
24
|
-
"tokens",
|
|
25
|
-
"errors",
|
|
26
|
-
"extra",
|
|
27
|
-
].forEach((name) => {
|
|
28
|
-
delete newObj[name];
|
|
29
|
-
});
|
|
30
|
-
|
|
31
29
|
if (node.kind === "string") {
|
|
32
30
|
// TODO if options are available in this method, replace with
|
|
33
31
|
// newObj.isDoubleQuote = !util.useSingleQuote(node, options);
|
|
@@ -44,7 +42,7 @@ function clean(node, newObj) {
|
|
|
44
42
|
return null;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
newObj.value = newObj.value.replace(/\
|
|
45
|
+
newObj.value = newObj.value.replace(/\n/g, "");
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
// continue ((2)); -> continue 2;
|
|
@@ -110,4 +108,6 @@ function clean(node, newObj) {
|
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
110
|
|
|
111
|
+
clean.ignoredProperties = ignoredProperties;
|
|
112
|
+
|
|
113
113
|
module.exports = clean;
|
package/src/comments.js
CHANGED
|
@@ -8,15 +8,8 @@ const {
|
|
|
8
8
|
hasNewline,
|
|
9
9
|
hasNewlineInRange,
|
|
10
10
|
} = require("prettier").util;
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
join,
|
|
14
|
-
indent,
|
|
15
|
-
hardline,
|
|
16
|
-
cursor,
|
|
17
|
-
lineSuffix,
|
|
18
|
-
breakParent,
|
|
19
|
-
} = require("prettier").doc.builders;
|
|
11
|
+
const { join, indent, hardline, cursor, lineSuffix, breakParent } =
|
|
12
|
+
require("prettier").doc.builders;
|
|
20
13
|
const {
|
|
21
14
|
getNextNonSpaceNonCommentCharacterIndex,
|
|
22
15
|
isNextLineEmpty,
|
|
@@ -860,7 +853,7 @@ function printDanglingComments(path, options, sameIndent, filter) {
|
|
|
860
853
|
if (sameIndent) {
|
|
861
854
|
return join(hardline, parts);
|
|
862
855
|
}
|
|
863
|
-
return indent(
|
|
856
|
+
return indent([hardline, join(hardline, parts)]);
|
|
864
857
|
}
|
|
865
858
|
|
|
866
859
|
function hasLeadingComment(node) {
|
|
@@ -896,7 +889,7 @@ function printComments(comments, options) {
|
|
|
896
889
|
parts.push(hardline);
|
|
897
890
|
}
|
|
898
891
|
});
|
|
899
|
-
return
|
|
892
|
+
return parts;
|
|
900
893
|
}
|
|
901
894
|
|
|
902
895
|
function isBlockComment(comment) {
|
|
@@ -937,7 +930,7 @@ function canAttachComment(node) {
|
|
|
937
930
|
// TODO remove after https://github.com/prettier/prettier/issues/5087
|
|
938
931
|
function prependCursorPlaceholder(path, options, printed) {
|
|
939
932
|
if (path.getNode() === options.cursorNode && path.getValue()) {
|
|
940
|
-
return
|
|
933
|
+
return [cursor, printed, cursor];
|
|
941
934
|
}
|
|
942
935
|
|
|
943
936
|
return printed;
|
|
@@ -957,15 +950,15 @@ function printLeadingComment(commentPath, print, options) {
|
|
|
957
950
|
// Leading block comments should see if they need to stay on the
|
|
958
951
|
// same line or not.
|
|
959
952
|
if (isBlock) {
|
|
960
|
-
return
|
|
953
|
+
return [
|
|
961
954
|
contents,
|
|
962
955
|
hasNewline(options.originalText, options.locEnd(comment))
|
|
963
956
|
? hardline
|
|
964
957
|
: " ",
|
|
965
|
-
]
|
|
958
|
+
];
|
|
966
959
|
}
|
|
967
960
|
|
|
968
|
-
return
|
|
961
|
+
return [contents, hardline];
|
|
969
962
|
}
|
|
970
963
|
|
|
971
964
|
function printTrailingComment(commentPath, print, options) {
|
|
@@ -1000,18 +993,13 @@ function printTrailingComment(commentPath, print, options) {
|
|
|
1000
993
|
options
|
|
1001
994
|
);
|
|
1002
995
|
|
|
1003
|
-
return lineSuffix(
|
|
1004
|
-
concat([hardline, isLineBeforeEmpty ? hardline : "", contents])
|
|
1005
|
-
);
|
|
996
|
+
return lineSuffix([hardline, isLineBeforeEmpty ? hardline : "", contents]);
|
|
1006
997
|
} else if (isBlock) {
|
|
1007
998
|
// Trailing block comments never need a newline
|
|
1008
|
-
return
|
|
999
|
+
return [" ", contents];
|
|
1009
1000
|
}
|
|
1010
1001
|
|
|
1011
|
-
return
|
|
1012
|
-
lineSuffix(concat([" ", contents])),
|
|
1013
|
-
!isBlock ? breakParent : "",
|
|
1014
|
-
]);
|
|
1002
|
+
return [lineSuffix([" ", contents]), !isBlock ? breakParent : ""];
|
|
1015
1003
|
}
|
|
1016
1004
|
|
|
1017
1005
|
function printAllComments(path, print, options, needsSemi) {
|
|
@@ -1049,7 +1037,7 @@ function printAllComments(path, print, options, needsSemi) {
|
|
|
1049
1037
|
return prependCursorPlaceholder(
|
|
1050
1038
|
path,
|
|
1051
1039
|
options,
|
|
1052
|
-
|
|
1040
|
+
leadingParts.concat(trailingParts)
|
|
1053
1041
|
);
|
|
1054
1042
|
}
|
|
1055
1043
|
|
package/src/index.js
CHANGED
package/src/options.js
CHANGED
package/src/parser.js
CHANGED
|
@@ -9,7 +9,7 @@ function parse(text, parsers, opts) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// Todo https://github.com/glayzzle/php-parser/issues/170
|
|
12
|
-
text = text.replace(/\?>\
|
|
12
|
+
text = text.replace(/\?>\n<\?/g, "?>\n___PSEUDO_INLINE_PLACEHOLDER___<?");
|
|
13
13
|
|
|
14
14
|
// initialize a new parser instance
|
|
15
15
|
const parser = new engine({
|
|
@@ -52,10 +52,6 @@ function parse(text, parsers, opts) {
|
|
|
52
52
|
// currently inline comments include the line break at the end, we need to
|
|
53
53
|
// strip those out and update the end location for each comment manually
|
|
54
54
|
ast.comments.forEach((comment) => {
|
|
55
|
-
if (comment.value[comment.value.length - 1] === "\r") {
|
|
56
|
-
comment.value = comment.value.slice(0, -1);
|
|
57
|
-
comment.loc.end.offset = comment.loc.end.offset - 1;
|
|
58
|
-
}
|
|
59
55
|
if (comment.value[comment.value.length - 1] === "\n") {
|
|
60
56
|
comment.value = comment.value.slice(0, -1);
|
|
61
57
|
comment.loc.end.offset = comment.loc.end.offset - 1;
|
package/src/pragma.js
CHANGED
|
@@ -22,16 +22,6 @@ const getPageLevelDocBlock = memoize((text) => {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
function guessLineEnding(text) {
|
|
26
|
-
const index = text.indexOf("\n");
|
|
27
|
-
|
|
28
|
-
if (index >= 0 && text.charAt(index - 1) === "\r") {
|
|
29
|
-
return "\r\n";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return "\n";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
25
|
function hasPragma(text) {
|
|
36
26
|
// fast path optimization - check if the pragma shows up in the file at all
|
|
37
27
|
if (!reHasPragma.test(text)) {
|
|
@@ -49,8 +39,8 @@ function hasPragma(text) {
|
|
|
49
39
|
return false;
|
|
50
40
|
}
|
|
51
41
|
|
|
52
|
-
function injectPragma(docblock
|
|
53
|
-
let lines = docblock.split(
|
|
42
|
+
function injectPragma(docblock) {
|
|
43
|
+
let lines = docblock.split("\n");
|
|
54
44
|
|
|
55
45
|
if (lines.length === 1) {
|
|
56
46
|
// normalize to multiline for simplicity
|
|
@@ -66,7 +56,7 @@ function injectPragma(docblock, text) {
|
|
|
66
56
|
// not found => index == -1, which conveniently will splice 1 from the end.
|
|
67
57
|
lines.splice(pragmaIndex, 0, " * @format");
|
|
68
58
|
|
|
69
|
-
return lines.join(
|
|
59
|
+
return lines.join("\n");
|
|
70
60
|
}
|
|
71
61
|
|
|
72
62
|
function insertPragma(text) {
|