@putout/printer 15.20.1 → 15.20.3
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/comments-printer/comments-printer.js +1 -2
- package/lib/tokenize/expressions/function/params.js +1 -2
- package/lib/tokenize/expressions/object-pattern/calculate-long-assign-pattern.js +38 -0
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +12 -2
- package/package.json +2 -1
package/ChangeLog
CHANGED
|
@@ -61,8 +61,7 @@ module.exports.printLeadingComments = (path, printer, semantics, {currentTravers
|
|
|
61
61
|
module.exports.printTrailingComments = (path, printer, semantics, {currentTraverse}) => {
|
|
62
62
|
const {print} = printer;
|
|
63
63
|
const {
|
|
64
|
-
trailingComments = []
|
|
65
|
-
} = path.node;
|
|
64
|
+
trailingComments = []} = path.node;
|
|
66
65
|
|
|
67
66
|
const {
|
|
68
67
|
printTrailingCommentLine,
|
|
@@ -19,8 +19,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
19
19
|
braceClose = ')',
|
|
20
20
|
printSpace = print.space,
|
|
21
21
|
printAfterOpen = noop,
|
|
22
|
-
printBeforeClose = noop
|
|
23
|
-
} = customization;
|
|
22
|
+
printBeforeClose = noop} = customization;
|
|
24
23
|
|
|
25
24
|
if (typeParameters)
|
|
26
25
|
traverse(path.get('typeParameters'));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {isAssignmentPattern} = types;
|
|
5
|
+
|
|
6
|
+
module.exports.calculateAssigns = (property, semantics) => {
|
|
7
|
+
const prev = property.getPrevSibling();
|
|
8
|
+
const next = property.getNextSibling();
|
|
9
|
+
|
|
10
|
+
const currentAssign = isLongAssignPattern(property, semantics);
|
|
11
|
+
const prevAssign = isLongAssignPattern(prev, semantics);
|
|
12
|
+
const nextAssign = isLongAssignPattern(next, semantics);
|
|
13
|
+
const bothLongAssigns = currentAssign && (nextAssign || prevAssign);
|
|
14
|
+
|
|
15
|
+
const oneLongAssign = currentAssign
|
|
16
|
+
&& (!next.node
|
|
17
|
+
|| nextAssign
|
|
18
|
+
|| !isAssignmentPattern(next.node?.value));
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
bothLongAssigns,
|
|
22
|
+
oneLongAssign,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports.isLongAssignPattern = isLongAssignPattern;
|
|
27
|
+
|
|
28
|
+
function isLongAssignPattern(path, semantics) {
|
|
29
|
+
if (!path.node)
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
if (!isAssignmentPattern(path.node.value))
|
|
33
|
+
return false;
|
|
34
|
+
|
|
35
|
+
const {maxPropertiesLengthInOneLine} = semantics;
|
|
36
|
+
|
|
37
|
+
return path.node.key.name.length > maxPropertiesLengthInOneLine;
|
|
38
|
+
}
|
|
@@ -15,6 +15,11 @@ const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
|
|
|
15
15
|
const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
|
|
16
16
|
const {printKey} = require('../object-expression/print-key');
|
|
17
17
|
|
|
18
|
+
const {
|
|
19
|
+
calculateAssigns,
|
|
20
|
+
isLongAssignPattern,
|
|
21
|
+
} = require('./calculate-long-assign-pattern');
|
|
22
|
+
|
|
18
23
|
const {
|
|
19
24
|
isObjectExpression,
|
|
20
25
|
isIdentifier,
|
|
@@ -142,7 +147,7 @@ module.exports.ObjectPattern = {
|
|
|
142
147
|
});
|
|
143
148
|
|
|
144
149
|
maybe.indent((prevAssignObject || is) && notInsideFn);
|
|
145
|
-
maybe.print.breakline(couple);
|
|
150
|
+
maybe.print.breakline(couple && !isLongAssignPattern(property, semantics));
|
|
146
151
|
|
|
147
152
|
if (!isAssign && nextAssignObject)
|
|
148
153
|
print.breakline();
|
|
@@ -174,7 +179,12 @@ module.exports.ObjectPattern = {
|
|
|
174
179
|
continue;
|
|
175
180
|
}
|
|
176
181
|
|
|
177
|
-
|
|
182
|
+
const {
|
|
183
|
+
oneLongAssign,
|
|
184
|
+
bothLongAssigns,
|
|
185
|
+
} = calculateAssigns(property, semantics);
|
|
186
|
+
|
|
187
|
+
if ((!oneLongAssign || bothLongAssigns) && (is || hasObject || prevAssignObject && notInsideFn)) {
|
|
178
188
|
print(',');
|
|
179
189
|
print.newline();
|
|
180
190
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "15.20.
|
|
3
|
+
"version": "15.20.3",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
+
"@babel/parser": "8.0.0-beta.2",
|
|
72
73
|
"@putout/eslint": "^4.1.0",
|
|
73
74
|
"@putout/plugin-minify": "^11.2.1",
|
|
74
75
|
"@putout/plugin-printer": "^6.0.0",
|