@putout/printer 8.2.0 → 8.4.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/lib/tokenize/comment/parse-leading-comments.js +2 -3
- package/lib/tokenize/expressions/array-expression/array-expression.js +6 -3
- package/lib/tokenize/expressions/array-expression/indent.js +13 -3
- package/lib/tokenize/expressions/array-expression/newline.js +1 -1
- package/lib/tokenize/is.js +1 -6
- package/lib/tokenize/statements/switch-statement.js +0 -1
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +3 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -88,9 +88,8 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
88
88
|
|
|
89
89
|
print(`//${value}`);
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
maybe.print.
|
|
93
|
-
maybe.print.newline(!propIs && !isParentSwitch);
|
|
91
|
+
maybe.print.breakline(propIs);
|
|
92
|
+
maybe.print.newline(!propIs);
|
|
94
93
|
continue;
|
|
95
94
|
}
|
|
96
95
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
3
4
|
const {
|
|
4
5
|
isCoupleLines,
|
|
5
6
|
isStringAndIdentifier,
|
|
@@ -19,12 +20,13 @@ const {
|
|
|
19
20
|
isArrayIndented,
|
|
20
21
|
} = require('./indent');
|
|
21
22
|
|
|
22
|
-
const {types} = require('@putout/babel');
|
|
23
23
|
const {
|
|
24
24
|
isObjectExpression,
|
|
25
25
|
isSpreadElement,
|
|
26
|
+
isStringLiteral,
|
|
26
27
|
} = types;
|
|
27
28
|
|
|
29
|
+
const isNextString = (path) => isStringLiteral(path.getNextSibling());
|
|
28
30
|
const isNextObject = (a) => a.getNextSibling().isObjectExpression();
|
|
29
31
|
const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
|
|
30
32
|
const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
|
|
@@ -98,9 +100,9 @@ module.exports.ArrayExpression = {
|
|
|
98
100
|
const parentElements = path.parentPath.get('elements');
|
|
99
101
|
|
|
100
102
|
if (isInsideArray(path) && isStringAndArray(parentElements)) {
|
|
101
|
-
indent.dec();
|
|
103
|
+
maybe.indent.dec(!isNextString(path));
|
|
102
104
|
maybe.indent(elements.length && isNewLine);
|
|
103
|
-
indent.inc();
|
|
105
|
+
maybe.indent.inc(!isNextString(path));
|
|
104
106
|
} else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
|
|
105
107
|
maybe.indent(elements.length && isNewLine);
|
|
106
108
|
}
|
|
@@ -128,3 +130,4 @@ module.exports.ArrayExpression = {
|
|
|
128
130
|
indent.inc();
|
|
129
131
|
},
|
|
130
132
|
};
|
|
133
|
+
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
|
-
const {isStringLiteral} = types;
|
|
5
|
-
|
|
6
4
|
const {isIndented} = require('../../is');
|
|
7
5
|
|
|
6
|
+
const {
|
|
7
|
+
isStringLiteral,
|
|
8
|
+
isArrayExpression,
|
|
9
|
+
} = types;
|
|
10
|
+
|
|
8
11
|
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
9
12
|
|
|
10
13
|
module.exports.isInsideArray = isInsideArray;
|
|
@@ -26,7 +29,14 @@ function isArrayInsideArray(path) {
|
|
|
26
29
|
if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
|
|
27
30
|
return false;
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
const parentElements = path.parentPath.node.elements;
|
|
33
|
+
const parentHasArrays = parentElements.filter(isArrayExpression).length;
|
|
34
|
+
const lastIsArray = !isArrayExpression(parentElements.at(-1));
|
|
35
|
+
|
|
36
|
+
if (parentHasArrays && lastIsArray)
|
|
37
|
+
return false;
|
|
38
|
+
|
|
39
|
+
return parentElements.length <= 3;
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
const isTwoLongStrings = ([a, b]) => {
|
|
@@ -96,7 +96,7 @@ module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
|
|
|
96
96
|
if (isTwoSimplesInsideObjectProperty(path))
|
|
97
97
|
return ONE_LINE;
|
|
98
98
|
|
|
99
|
-
if (isStringAndArray(elements))
|
|
99
|
+
if (isStringAndArray(elements) && elements.length < 3)
|
|
100
100
|
return ONE_LINE;
|
|
101
101
|
|
|
102
102
|
if (isStringAndMember(elements))
|
package/lib/tokenize/is.js
CHANGED
|
@@ -65,12 +65,7 @@ module.exports.isIdentifierAndIdentifier = ([a, b]) => {
|
|
|
65
65
|
};
|
|
66
66
|
module.exports.isStringAndMember = ([a, b]) => isStringLiteral(a) && isMemberExpression(b);
|
|
67
67
|
module.exports.isIdentifierAndString = ([a, b]) => isIdentifier(a) && isStringLiteral(b);
|
|
68
|
-
module.exports.isStringAndArray = (
|
|
69
|
-
if (array.length > 2)
|
|
70
|
-
return false;
|
|
71
|
-
|
|
72
|
-
const [a, b] = array;
|
|
73
|
-
|
|
68
|
+
module.exports.isStringAndArray = ([a, b]) => {
|
|
74
69
|
if (!isStringLiteral(a))
|
|
75
70
|
return false;
|
|
76
71
|
|
|
@@ -18,7 +18,7 @@ const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
|
18
18
|
|
|
19
19
|
const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
|
|
20
20
|
const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
|
|
21
|
-
const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock)$/.test(path.parentPath.type);
|
|
21
|
+
const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock|SwitchCase)$/.test(path.parentPath.type);
|
|
22
22
|
const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
|
|
23
23
|
const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
|
|
24
24
|
const isParentIf = (path) => path.parentPath.isIfStatement();
|
|
@@ -83,7 +83,8 @@ module.exports.VariableDeclaration = {
|
|
|
83
83
|
write.newline();
|
|
84
84
|
wasNewline = true;
|
|
85
85
|
} else if (isParentSwitchCase(path)) {
|
|
86
|
-
write.breakline();
|
|
86
|
+
//write.breakline();
|
|
87
|
+
write.newline();
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
if (isParentBlock(path) && isNext(path) && (noTrailingComment(path) || isNewlineBetweenSiblings(path))) {
|
package/package.json
CHANGED