@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.
@@ -1,18 +1,14 @@
1
- "use strict";
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.getParentNode();
5
+ const { parent } = path;
9
6
 
10
7
  if (!parent) {
11
8
  return false;
12
9
  }
13
10
 
14
- const name = path.getName();
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 name === "what" && parent.what === node;
55
+ return key === "what";
60
56
  case "bin":
61
- return parent.type === "**" && name === "left";
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 name === "what" && parent.what === node;
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 && name === "right") {
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 name === "what" && parent.what === node;
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 name === "what" && parent.what === node;
152
+ return key === "what";
161
153
 
162
154
  case "retif":
163
- return parent.test === node;
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 (name === "test" && !parent.trueExpr) {
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 name === "what" && parent.what === node;
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 name === "what" && parent.what === node;
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 name === "what" && parent.what === node;
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
- module.exports = needsParens;
250
+ export default needsParens;
package/src/options.js CHANGED
@@ -1,8 +1,6 @@
1
- "use strict";
2
-
3
1
  const CATEGORY_PHP = "PHP";
4
2
 
5
- module.exports = {
3
+ export default {
6
4
  phpVersion: {
7
5
  since: "0.13.0",
8
6
  category: CATEGORY_PHP,
package/src/parser.js CHANGED
@@ -1,7 +1,6 @@
1
- "use strict";
2
- const engine = require("php-parser");
1
+ import engine from "php-parser";
3
2
 
4
- function parse(text, parsers, opts) {
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
- module.exports = parse;
63
+ export default parse;
package/src/pragma.js CHANGED
@@ -1,7 +1,5 @@
1
- "use strict";
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
- module.exports = {
95
- hasPragma,
96
- insertPragma,
97
- };
92
+ export { hasPragma, insertPragma };