@putout/printer 2.5.0 → 2.7.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 +11 -0
- package/lib/tokenize/expressions/index.js +1 -1
- package/lib/tokenize/expressions/object-expression/object-expression.js +9 -3
- package/lib/tokenize/expressions/{object-pattern.js → object-pattern/object-pattern.js} +12 -11
- package/lib/tokenize/expressions/object-pattern/wrong-shortand.js +6 -0
- package/lib/tokenize/statements/block-statement.js +1 -3
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -5
- package/lib/tokenize/statements/while-statement.js +0 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.06.13, v2.7.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 7f3fd61 @putout/printer: ObjectPattern: couple levels deep
|
|
5
|
+
- 7922ba6 @putout/printer: ObjectPattern: move out
|
|
6
|
+
|
|
7
|
+
2023.06.13, v2.6.0
|
|
8
|
+
|
|
9
|
+
fix:
|
|
10
|
+
- 30e2aa1 @putout/printer: ObjectExpression: used as argument call
|
|
11
|
+
|
|
1
12
|
2023.06.12, v2.5.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -19,7 +19,7 @@ const {NewExpression} = require('./new-expression');
|
|
|
19
19
|
|
|
20
20
|
const {ObjectExpression} = require('./object-expression/object-expression');
|
|
21
21
|
const {ObjectProperty} = require('./object-expression/object-property');
|
|
22
|
-
const {ObjectPattern} = require('./object-pattern');
|
|
22
|
+
const {ObjectPattern} = require('./object-pattern/object-pattern');
|
|
23
23
|
|
|
24
24
|
const {
|
|
25
25
|
ClassProperty,
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
} = require('../../is');
|
|
13
13
|
|
|
14
14
|
const {parseComments} = require('../../comments');
|
|
15
|
+
const {isObjectExpression} = require('@babel/types');
|
|
15
16
|
|
|
16
17
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
17
18
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
@@ -28,9 +29,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantic
|
|
|
28
29
|
|
|
29
30
|
maybe.print(parens, '(');
|
|
30
31
|
print('{');
|
|
31
|
-
parseComments(path, {
|
|
32
|
-
write,
|
|
33
|
-
}, semantics);
|
|
32
|
+
parseComments(path, {write}, semantics);
|
|
34
33
|
maybe.print.newline(manyLines);
|
|
35
34
|
|
|
36
35
|
for (const property of properties) {
|
|
@@ -85,6 +84,13 @@ const notLastArgInsideCall = (path) => {
|
|
|
85
84
|
if (!parentPath.isCallExpression())
|
|
86
85
|
return false;
|
|
87
86
|
|
|
87
|
+
const {properties} = path.node;
|
|
88
|
+
|
|
89
|
+
for (const property of properties) {
|
|
90
|
+
if (isObjectExpression(property.value))
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
88
94
|
return path !== parentPath
|
|
89
95
|
.get('arguments')
|
|
90
96
|
.at(-1);
|
|
@@ -5,17 +5,17 @@ const {
|
|
|
5
5
|
isObjectPattern,
|
|
6
6
|
} = require('@babel/types');
|
|
7
7
|
|
|
8
|
+
const {wrongShorthand} = require('./wrong-shortand');
|
|
9
|
+
|
|
8
10
|
const {
|
|
9
11
|
isForOf,
|
|
10
12
|
isCoupleLines,
|
|
11
13
|
exists,
|
|
12
|
-
} = require('
|
|
14
|
+
} = require('../../is');
|
|
13
15
|
|
|
14
|
-
const
|
|
15
|
-
return !computed && !isAssign && keyPath.node.name !== valuePath.node.name;
|
|
16
|
-
};
|
|
16
|
+
const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
|
|
17
17
|
|
|
18
|
-
const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties
|
|
18
|
+
const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties?.length === 1;
|
|
19
19
|
|
|
20
20
|
module.exports.ObjectPattern = {
|
|
21
21
|
print(path, {indent, print, maybe}) {
|
|
@@ -27,7 +27,7 @@ module.exports.ObjectPattern = {
|
|
|
27
27
|
const is = shouldAddNewline(path);
|
|
28
28
|
const hasObject = n && hasObjectPattern(properties);
|
|
29
29
|
|
|
30
|
-
maybe.print(is
|
|
30
|
+
maybe.print.newline(is);
|
|
31
31
|
|
|
32
32
|
for (const [i, property] of properties.entries()) {
|
|
33
33
|
if (property.isRestElement()) {
|
|
@@ -46,7 +46,7 @@ module.exports.ObjectPattern = {
|
|
|
46
46
|
computed,
|
|
47
47
|
} = property.node;
|
|
48
48
|
|
|
49
|
-
const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling());
|
|
49
|
+
const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling()) && !path.parentPath.isObjectProperty();
|
|
50
50
|
|
|
51
51
|
maybe.indent(is);
|
|
52
52
|
maybe.print.breakline(couple);
|
|
@@ -87,10 +87,10 @@ module.exports.ObjectPattern = {
|
|
|
87
87
|
if (!path.parentPath.isObjectProperty())
|
|
88
88
|
return false;
|
|
89
89
|
|
|
90
|
-
if (
|
|
91
|
-
return
|
|
90
|
+
if (isTwoLevelsDeep(path))
|
|
91
|
+
return false;
|
|
92
92
|
|
|
93
|
-
return
|
|
93
|
+
return isOneParentProperty(path);
|
|
94
94
|
},
|
|
95
95
|
after(path, {print}) {
|
|
96
96
|
print.newline();
|
|
@@ -121,13 +121,14 @@ function hasObjectPattern(properties) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
function shouldAddNewline(path) {
|
|
124
|
+
const {parentPath} = path;
|
|
124
125
|
const properties = path.get('properties');
|
|
125
126
|
const n = properties.length - 1;
|
|
126
127
|
|
|
127
128
|
if (!isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties))
|
|
128
129
|
return true;
|
|
129
130
|
|
|
130
|
-
if (
|
|
131
|
+
if (parentPath.isObjectProperty())
|
|
131
132
|
return true;
|
|
132
133
|
|
|
133
134
|
return false;
|
package/package.json
CHANGED