@putout/printer 6.4.0 → 6.5.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
CHANGED
|
@@ -10,6 +10,8 @@ const {
|
|
|
10
10
|
const {markBefore} = require('../mark');
|
|
11
11
|
const {maybeInsideFn} = require('./maybe-inside-fn');
|
|
12
12
|
|
|
13
|
+
const deduplicate = (a) => Array.from(new Set(a));
|
|
14
|
+
|
|
13
15
|
const {
|
|
14
16
|
isObjectProperty,
|
|
15
17
|
isVariableDeclarator,
|
|
@@ -43,7 +45,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
43
45
|
const propIs = isProperty(path);
|
|
44
46
|
const isIndent = !looksLikeSwitchCase && !path.isClassMethod() && !insideFn && !propIs;
|
|
45
47
|
|
|
46
|
-
for (const {type, value} of leadingComments) {
|
|
48
|
+
for (const {type, value} of deduplicate(leadingComments)) {
|
|
47
49
|
maybe.indent(isIndent);
|
|
48
50
|
|
|
49
51
|
if (type === 'CommentLine') {
|
|
@@ -14,12 +14,14 @@ const {
|
|
|
14
14
|
isCurrentNewLine,
|
|
15
15
|
} = require('./new-line');
|
|
16
16
|
|
|
17
|
+
const {types} = require('@putout/babel');
|
|
17
18
|
const {
|
|
18
19
|
isObjectExpression,
|
|
19
20
|
isStringLiteral,
|
|
20
|
-
} =
|
|
21
|
+
} = types;
|
|
21
22
|
|
|
22
23
|
const isNextObject = (a) => a.getNextSibling().isObjectExpression();
|
|
24
|
+
const isArrayInsideArray = (path) => path.isArrayExpression() && path.parentPath.isArrayExpression();
|
|
23
25
|
|
|
24
26
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
25
27
|
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
@@ -63,7 +65,7 @@ module.exports.ArrayExpression = {
|
|
|
63
65
|
|
|
64
66
|
print('[');
|
|
65
67
|
|
|
66
|
-
const indented = !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(elements[0]);
|
|
68
|
+
const indented = !isArrayInsideArray(path) && (!isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(elements[0]));
|
|
67
69
|
|
|
68
70
|
if (indented)
|
|
69
71
|
maybe.indent.inc(shouldIncreaseIndent);
|
|
@@ -103,7 +105,7 @@ module.exports.ArrayExpression = {
|
|
|
103
105
|
indent.dec();
|
|
104
106
|
maybe.indent(elements.length && isNewLine);
|
|
105
107
|
indent.inc();
|
|
106
|
-
} else if (!isObjectExpression(elements.at(-1))) {
|
|
108
|
+
} else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
|
|
107
109
|
maybe.indent(elements.length && isNewLine);
|
|
108
110
|
}
|
|
109
111
|
|
package/package.json
CHANGED