@putout/printer 8.25.0 → 8.27.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/ChangeLog +10 -0
- package/README.md +1 -1
- package/lib/tokenize/expressions/array-expression/array-expression.js +15 -1
- package/lib/tokenize/expressions/array-expression/newline.js +4 -0
- package/lib/tokenize/expressions/object-expression/object-expression.js +3 -2
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +1 -0
- package/lib/tokenize/is.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -296,7 +296,7 @@ This is the same as `print('__left')` but more low-level, and supports only obje
|
|
|
296
296
|
About speed, for file `speed.js`:
|
|
297
297
|
|
|
298
298
|
```js
|
|
299
|
-
const {readFileSync} = require('fs');
|
|
299
|
+
const {readFileSync} = require('node:fs');
|
|
300
300
|
|
|
301
301
|
const putout = require('putout');
|
|
302
302
|
const parser = require('@babel/parser');
|
|
@@ -26,6 +26,7 @@ const {
|
|
|
26
26
|
isSpreadElement,
|
|
27
27
|
isStringLiteral,
|
|
28
28
|
isIdentifier,
|
|
29
|
+
isArrayExpression,
|
|
29
30
|
} = types;
|
|
30
31
|
|
|
31
32
|
const isNextString = (path) => isStringLiteral(path.getNextSibling());
|
|
@@ -35,7 +36,20 @@ const isNextObject = (a) => a.getNextSibling().isObjectExpression();
|
|
|
35
36
|
const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
|
|
36
37
|
const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
|
|
37
38
|
const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
|
|
38
|
-
|
|
39
|
+
|
|
40
|
+
const isObjectAfterArray = (a) => {
|
|
41
|
+
if (!isArrayExpression(a))
|
|
42
|
+
return false;
|
|
43
|
+
|
|
44
|
+
return isNextObject(a);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const isObjectAfterSimple = (a) => {
|
|
48
|
+
if (isObjectAfterArray(a))
|
|
49
|
+
return true;
|
|
50
|
+
|
|
51
|
+
return isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
|
|
52
|
+
};
|
|
39
53
|
|
|
40
54
|
const isSpreadBeforeObject = (a) => {
|
|
41
55
|
if (!a.isObjectExpression())
|
|
@@ -43,6 +43,7 @@ const isSimpleAndCall = ([a, b]) => {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
|
|
46
|
+
const isBooleanAndObject = ([a, b]) => isBooleanLiteral(a) && isObjectExpression(b);
|
|
46
47
|
const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
|
|
47
48
|
const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
|
|
48
49
|
const ONE_LINE = false;
|
|
@@ -258,6 +259,9 @@ function isIncreaseIndent(path) {
|
|
|
258
259
|
if (!elements.length)
|
|
259
260
|
return false;
|
|
260
261
|
|
|
262
|
+
if (isBooleanAndObject(elements))
|
|
263
|
+
return true;
|
|
264
|
+
|
|
261
265
|
if (isInsideCallLoop(path))
|
|
262
266
|
return false;
|
|
263
267
|
|
|
@@ -53,7 +53,8 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
53
53
|
|
|
54
54
|
const n = properties.length - 1;
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
const memberCallee = isMemberExpressionCallee(path);
|
|
57
|
+
maybe.indent.inc(memberCallee);
|
|
57
58
|
|
|
58
59
|
for (const [index, property] of properties.entries()) {
|
|
59
60
|
if (property.isSpreadElement()) {
|
|
@@ -94,7 +95,7 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
94
95
|
print('}');
|
|
95
96
|
maybe.print(parens, ')');
|
|
96
97
|
|
|
97
|
-
maybe.indent.dec(
|
|
98
|
+
maybe.indent.dec(memberCallee);
|
|
98
99
|
};
|
|
99
100
|
|
|
100
101
|
const hasNextLeadingComment = (path) => {
|
|
@@ -168,6 +168,7 @@ function shouldAddNewline(path, semantics) {
|
|
|
168
168
|
const moreLength = moreThenMaxPropertiesLengthInOneLine(path, {
|
|
169
169
|
maxPropertiesLengthInOneLine,
|
|
170
170
|
});
|
|
171
|
+
|
|
171
172
|
const moreCount = moreThenMaxPropertiesInOneLine(path, {
|
|
172
173
|
maxPropertiesInOneLine,
|
|
173
174
|
});
|
package/lib/tokenize/is.js
CHANGED
|
@@ -64,7 +64,7 @@ function isStringAndIdentifier([a, b]) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
module.exports.isSimpleAndEmptyObject = ([a, b]) => {
|
|
67
|
-
if (!isIdentifier(a) && !isSpreadElement(a))
|
|
67
|
+
if (!isIdentifier(a) && !isSpreadElement(a) && !isArrayExpression(a))
|
|
68
68
|
return false;
|
|
69
69
|
|
|
70
70
|
if (!isObjectExpression(b))
|
package/package.json
CHANGED