@prettier/plugin-php 0.19.7 → 0.20.1
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/README.md +38 -19
- package/package.json +32 -20
- package/src/clean.js +5 -7
- package/src/comments.js +39 -50
- package/src/index.js +54 -30
- package/src/linguist-languages.cjs +4 -0
- package/src/needs-parens.js +17 -25
- package/src/options.js +1 -3
- package/src/parser.js +3 -4
- package/src/pragma.js +3 -8
- package/src/printer.js +236 -324
- package/src/util.js +13 -26
- package/standalone.js +3 -1
- package/src/module.js +0 -2
package/src/needs-parens.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const assert = require("assert");
|
|
4
|
-
|
|
5
|
-
const { getPrecedence, shouldFlatten, isBitwiseOperator } = require("./util");
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { getPrecedence, shouldFlatten, isBitwiseOperator } from "./util.js";
|
|
6
3
|
|
|
7
4
|
function needsParens(path) {
|
|
8
|
-
const parent = path
|
|
5
|
+
const { parent } = path;
|
|
9
6
|
|
|
10
7
|
if (!parent) {
|
|
11
8
|
return false;
|
|
12
9
|
}
|
|
13
10
|
|
|
14
|
-
const
|
|
15
|
-
const node = path.getNode();
|
|
11
|
+
const { key, node } = path;
|
|
16
12
|
|
|
17
13
|
if (
|
|
18
14
|
[
|
|
@@ -56,9 +52,9 @@ function needsParens(path) {
|
|
|
56
52
|
case "staticlookup":
|
|
57
53
|
case "offsetlookup":
|
|
58
54
|
case "call":
|
|
59
|
-
return
|
|
55
|
+
return key === "what";
|
|
60
56
|
case "bin":
|
|
61
|
-
return parent.type === "**" &&
|
|
57
|
+
return parent.type === "**" && key === "left";
|
|
62
58
|
default:
|
|
63
59
|
return false;
|
|
64
60
|
}
|
|
@@ -80,7 +76,7 @@ function needsParens(path) {
|
|
|
80
76
|
case "nullsafepropertylookup":
|
|
81
77
|
case "staticlookup":
|
|
82
78
|
case "offsetlookup":
|
|
83
|
-
return
|
|
79
|
+
return key === "what";
|
|
84
80
|
case "bin": {
|
|
85
81
|
const po = parent.type;
|
|
86
82
|
const pp = getPrecedence(po);
|
|
@@ -95,7 +91,7 @@ function needsParens(path) {
|
|
|
95
91
|
return true;
|
|
96
92
|
}
|
|
97
93
|
|
|
98
|
-
if (pp === np &&
|
|
94
|
+
if (pp === np && key === "right") {
|
|
99
95
|
assert.strictEqual(parent.right, node);
|
|
100
96
|
|
|
101
97
|
return true;
|
|
@@ -127,11 +123,7 @@ function needsParens(path) {
|
|
|
127
123
|
case "staticlookup": {
|
|
128
124
|
switch (parent.kind) {
|
|
129
125
|
case "call":
|
|
130
|
-
return
|
|
131
|
-
name === "what" &&
|
|
132
|
-
parent.what === node &&
|
|
133
|
-
node.parenthesizedExpression
|
|
134
|
-
);
|
|
126
|
+
return key === "what" && node.parenthesizedExpression;
|
|
135
127
|
|
|
136
128
|
default:
|
|
137
129
|
return false;
|
|
@@ -145,7 +137,7 @@ function needsParens(path) {
|
|
|
145
137
|
case "staticlookup":
|
|
146
138
|
case "offsetlookup":
|
|
147
139
|
case "call":
|
|
148
|
-
return
|
|
140
|
+
return key === "what";
|
|
149
141
|
default:
|
|
150
142
|
return false;
|
|
151
143
|
}
|
|
@@ -157,10 +149,10 @@ function needsParens(path) {
|
|
|
157
149
|
case "staticlookup":
|
|
158
150
|
case "offsetlookup":
|
|
159
151
|
case "call":
|
|
160
|
-
return
|
|
152
|
+
return key === "what";
|
|
161
153
|
|
|
162
154
|
case "retif":
|
|
163
|
-
return
|
|
155
|
+
return key === "test";
|
|
164
156
|
|
|
165
157
|
default:
|
|
166
158
|
return !!(node.key || node.value);
|
|
@@ -195,7 +187,7 @@ function needsParens(path) {
|
|
|
195
187
|
case "unary":
|
|
196
188
|
case "bin":
|
|
197
189
|
case "retif":
|
|
198
|
-
if (
|
|
190
|
+
if (key === "test" && !parent.trueExpr) {
|
|
199
191
|
return false;
|
|
200
192
|
}
|
|
201
193
|
|
|
@@ -205,7 +197,7 @@ function needsParens(path) {
|
|
|
205
197
|
case "staticlookup":
|
|
206
198
|
case "offsetlookup":
|
|
207
199
|
case "call":
|
|
208
|
-
return
|
|
200
|
+
return key === "what";
|
|
209
201
|
|
|
210
202
|
default:
|
|
211
203
|
return false;
|
|
@@ -213,7 +205,7 @@ function needsParens(path) {
|
|
|
213
205
|
case "closure":
|
|
214
206
|
switch (parent.kind) {
|
|
215
207
|
case "call":
|
|
216
|
-
return
|
|
208
|
+
return key === "what";
|
|
217
209
|
|
|
218
210
|
// https://github.com/prettier/plugin-php/issues/1675
|
|
219
211
|
case "propertylookup":
|
|
@@ -243,7 +235,7 @@ function needsParens(path) {
|
|
|
243
235
|
return false;
|
|
244
236
|
}
|
|
245
237
|
|
|
246
|
-
return
|
|
238
|
+
return key === "what";
|
|
247
239
|
default:
|
|
248
240
|
return false;
|
|
249
241
|
}
|
|
@@ -255,4 +247,4 @@ function needsParens(path) {
|
|
|
255
247
|
return false;
|
|
256
248
|
}
|
|
257
249
|
|
|
258
|
-
|
|
250
|
+
export default needsParens;
|
package/src/options.js
CHANGED
package/src/parser.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const engine = require("php-parser");
|
|
1
|
+
import engine from "php-parser";
|
|
3
2
|
|
|
4
|
-
function parse(text,
|
|
3
|
+
function parse(text, opts) {
|
|
5
4
|
const inMarkdown = opts && opts.parentParser === "markdown";
|
|
6
5
|
|
|
7
6
|
if (!text && inMarkdown) {
|
|
@@ -61,4 +60,4 @@ function parse(text, parsers, opts) {
|
|
|
61
60
|
return ast;
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
export default parse;
|
package/src/pragma.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const parse = require("./parser");
|
|
4
|
-
const memoize = require("mem");
|
|
1
|
+
import memoize from "mem";
|
|
2
|
+
import parse from "./parser.js";
|
|
5
3
|
|
|
6
4
|
const reHasPragma = /@prettier|@format/;
|
|
7
5
|
|
|
@@ -91,7 +89,4 @@ function insertPragma(text) {
|
|
|
91
89
|
${after}`;
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
|
|
95
|
-
hasPragma,
|
|
96
|
-
insertPragma,
|
|
97
|
-
};
|
|
92
|
+
export { hasPragma, insertPragma };
|