@putout/printer 1.53.0 → 1.54.1
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/assignment-expression.js +18 -7
- package/lib/tokenize/expressions/member-expressions.js +8 -2
- package/lib/tokenize/is.js +1 -2
- package/lib/tokenize/literals/index.js +3 -0
- package/lib/tokenize/statements/expression-statement.js +2 -2
- package/lib/tokenize/statements/variable-declaration.js +14 -5
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.04.18, v1.54.1
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 7f6d7d4 @putout/printer: add support of Import used as object of MemberExpression
|
|
5
|
+
- c2b2e4b @putout/printer: VariableDeclaration: drop useless newline
|
|
6
|
+
|
|
7
|
+
2023.04.18, v1.54.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 6c8bac0 @putout/printer add support of Import
|
|
11
|
+
|
|
1
12
|
2023.04.17, v1.53.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
const {isObjectPattern} = require('@babel/types');
|
|
4
|
+
|
|
5
|
+
module.exports.AssignmentExpression = {
|
|
6
|
+
condition: (path) => isObjectPattern(path.node.left),
|
|
7
|
+
before(path, {write}) {
|
|
8
|
+
write('(');
|
|
9
|
+
},
|
|
10
|
+
print(path, {print}) {
|
|
11
|
+
const {operator} = path.node;
|
|
12
|
+
print('__left');
|
|
13
|
+
print(' ');
|
|
14
|
+
print(operator);
|
|
15
|
+
print(' ');
|
|
16
|
+
print('__right');
|
|
17
|
+
},
|
|
18
|
+
after(path, {write}) {
|
|
19
|
+
write(')');
|
|
20
|
+
},
|
|
10
21
|
};
|
|
@@ -12,9 +12,14 @@ const {
|
|
|
12
12
|
getTemplateValues,
|
|
13
13
|
} = require('@putout/compare');
|
|
14
14
|
|
|
15
|
-
module.exports.MemberExpression = (path, {print, indent, maybe}) => {
|
|
15
|
+
module.exports.MemberExpression = (path, {print, indent, maybe, traverse}) => {
|
|
16
16
|
const {computed} = path.node;
|
|
17
|
-
|
|
17
|
+
const object = path.get('object');
|
|
18
|
+
const isObjectAwait = object.isAwaitExpression();
|
|
19
|
+
|
|
20
|
+
maybe.print(isObjectAwait, '(');
|
|
21
|
+
traverse(object);
|
|
22
|
+
maybe.print(isObjectAwait, ')');
|
|
18
23
|
|
|
19
24
|
if (computed) {
|
|
20
25
|
print('[');
|
|
@@ -109,3 +114,4 @@ function isLooksLikeChain(path) {
|
|
|
109
114
|
|
|
110
115
|
return !compare(parentPath, '__a.__b(__args)') || itMember || itExpression;
|
|
111
116
|
}
|
|
117
|
+
|
package/lib/tokenize/is.js
CHANGED
|
@@ -78,10 +78,9 @@ module.exports.isNewlineBetweenStatements = (path) => {
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
module.exports.satisfy = (conditions) => (path) => {
|
|
81
|
-
for (const condition of conditions)
|
|
81
|
+
for (const condition of conditions)
|
|
82
82
|
if (condition(path))
|
|
83
83
|
return true;
|
|
84
|
-
}
|
|
85
84
|
|
|
86
85
|
return false;
|
|
87
86
|
};
|
|
@@ -28,7 +28,7 @@ module.exports.ExpressionStatement = {
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
afterSatisfy: () => [
|
|
31
|
-
|
|
31
|
+
isParentBlockOrNotLastOrParentLast,
|
|
32
32
|
isParentBlock,
|
|
33
33
|
isNext,
|
|
34
34
|
isNextUp,
|
|
@@ -49,7 +49,7 @@ function isNotLastBody(path) {
|
|
|
49
49
|
return path.parentPath.get('body') === path;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function
|
|
52
|
+
function isParentBlockOrNotLastOrParentLast(path) {
|
|
53
53
|
return isParentBlock(path) || !(isLast(path) || isParentLast(path));
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -57,7 +57,10 @@ module.exports.VariableDeclaration = {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
function noNextParentBlock(path) {
|
|
60
|
-
|
|
60
|
+
if (isNext(path))
|
|
61
|
+
return false;
|
|
62
|
+
|
|
63
|
+
return path.parentPath.isBlockStatement();
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
function notLastParentExport(path) {
|
|
@@ -68,7 +71,10 @@ function notLastParentExport(path) {
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
function notLastCoupleLines(path) {
|
|
71
|
-
|
|
74
|
+
if (isLast(path))
|
|
75
|
+
return false;
|
|
76
|
+
|
|
77
|
+
return isCoupleLines(path);
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
function notLastPrevVarNotNextVar(path) {
|
|
@@ -83,7 +89,6 @@ function isNextCoupleLines(path) {
|
|
|
83
89
|
|
|
84
90
|
return isCoupleLines(next);
|
|
85
91
|
}
|
|
86
|
-
|
|
87
92
|
const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
|
|
88
93
|
|
|
89
94
|
function shouldAddNewlineBefore(path) {
|
|
@@ -116,6 +121,10 @@ const isNextAssign = (path) => {
|
|
|
116
121
|
if (!nextPath.isExpressionStatement())
|
|
117
122
|
return false;
|
|
118
123
|
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
const {parentPath} = path;
|
|
125
|
+
|
|
126
|
+
if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
|
|
127
|
+
return false;
|
|
128
|
+
|
|
129
|
+
return nextPath.get('expression').isAssignmentExpression();
|
|
121
130
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.54.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|