@putout/printer 2.95.0 → 2.96.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 +5 -0
- package/lib/tokenize/expressions/assignment-expression.js +3 -2
- package/lib/tokenize/expressions/binary-expression/binary-expression.js +2 -3
- package/lib/tokenize/expressions/conditional-expression.js +1 -1
- package/lib/tokenize/expressions/index.js +1 -1
- package/lib/tokenize/expressions/unary-expression/parens.js +13 -0
- package/lib/tokenize/expressions/{unary-expressions.js → unary-expression/unary-expressions.js} +11 -4
- package/lib/tokenize/literals/identifier.js +35 -0
- package/lib/tokenize/literals/index.js +3 -18
- package/lib/tokenize/typescript/index.js +10 -3
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isObjectPattern} = require('@babel/types');
|
|
4
|
+
const {isParens} = require('./unary-expression/parens');
|
|
4
5
|
|
|
5
6
|
module.exports.AssignmentExpression = {
|
|
6
7
|
condition: (path) => {
|
|
7
|
-
const {left
|
|
8
|
+
const {left} = path.node;
|
|
8
9
|
|
|
9
10
|
if (isObjectPattern(left))
|
|
10
11
|
return true;
|
|
11
12
|
|
|
12
|
-
if (
|
|
13
|
+
if (isParens(path))
|
|
13
14
|
return true;
|
|
14
15
|
|
|
15
16
|
return path.parentPath.isLogicalExpression();
|
|
@@ -6,12 +6,11 @@ const {
|
|
|
6
6
|
} = require('./concatanate');
|
|
7
7
|
|
|
8
8
|
const {maybeSpace} = require('./maybe-space');
|
|
9
|
+
const {isParens} = require('../unary-expression/parens');
|
|
9
10
|
|
|
10
11
|
const BinaryExpression = {
|
|
11
12
|
condition(path) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (parens)
|
|
13
|
+
if (isParens(path))
|
|
15
14
|
return true;
|
|
16
15
|
|
|
17
16
|
return path.parentPath.isAwaitExpression();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const functions = require('./function/functions');
|
|
4
|
-
const unaryExpressions = require('./unary-expressions');
|
|
4
|
+
const unaryExpressions = require('./unary-expression/unary-expressions');
|
|
5
5
|
const memberExpressions = require('./member-expression/member-expressions');
|
|
6
6
|
|
|
7
7
|
const {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isParens = (path) => path.node.extra?.parenthesized;
|
|
4
|
+
|
|
5
|
+
module.exports.isParens = isParens;
|
|
6
|
+
|
|
7
|
+
module.exports.maybeParenOpen = (path, {maybe}) => {
|
|
8
|
+
maybe.write(isParens(path), '(');
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports.maybeParenClose = (path, {maybe}) => {
|
|
12
|
+
maybe.write(isParens(path), ')');
|
|
13
|
+
};
|
package/lib/tokenize/expressions/{unary-expressions.js → unary-expression/unary-expressions.js}
RENAMED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isLast, isNext} = require('
|
|
3
|
+
const {isLast, isNext} = require('../../is');
|
|
4
|
+
const {
|
|
5
|
+
maybeParenOpen,
|
|
6
|
+
maybeParenClose,
|
|
7
|
+
} = require('./parens');
|
|
4
8
|
|
|
5
9
|
module.exports.UnaryExpression = unaryExpression;
|
|
6
10
|
module.exports.UpdateExpression = unaryExpression;
|
|
@@ -39,14 +43,17 @@ function printUnary(path, name, {print}) {
|
|
|
39
43
|
|
|
40
44
|
const isWord = (a) => /^(delete|typeof|void|throw)$/.test(a);
|
|
41
45
|
|
|
42
|
-
function unaryExpression(path,
|
|
46
|
+
function unaryExpression(path, printer) {
|
|
47
|
+
const {maybe, traverse} = printer;
|
|
43
48
|
const {prefix, operator} = path.node;
|
|
44
|
-
|
|
45
49
|
const argPath = path.get('argument');
|
|
46
50
|
|
|
51
|
+
maybeParenOpen(path, printer);
|
|
52
|
+
|
|
47
53
|
maybe.print(prefix, operator);
|
|
48
54
|
maybe.print(isWord(operator), ' ');
|
|
49
|
-
|
|
50
55
|
traverse(argPath);
|
|
51
56
|
maybe.print(!prefix, operator);
|
|
57
|
+
|
|
58
|
+
maybeParenClose(path, printer);
|
|
52
59
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
maybeParenOpen,
|
|
5
|
+
maybeParenClose,
|
|
6
|
+
} = require('../expressions/unary-expression/parens');
|
|
7
|
+
|
|
8
|
+
const {maybeDecorators} = require('../maybe-get');
|
|
9
|
+
|
|
10
|
+
module.exports.Identifier = (path, printer) => {
|
|
11
|
+
const {
|
|
12
|
+
write,
|
|
13
|
+
maybe,
|
|
14
|
+
traverse,
|
|
15
|
+
print,
|
|
16
|
+
} = printer;
|
|
17
|
+
|
|
18
|
+
const {node} = path;
|
|
19
|
+
const {name, optional} = node;
|
|
20
|
+
|
|
21
|
+
const typeAnnotation = path.get('typeAnnotation');
|
|
22
|
+
|
|
23
|
+
maybeParenOpen(path, printer);
|
|
24
|
+
|
|
25
|
+
for (const decorator of maybeDecorators(path)) {
|
|
26
|
+
traverse(decorator);
|
|
27
|
+
print(' ');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
write(name);
|
|
31
|
+
maybe.write(optional, '?');
|
|
32
|
+
traverse(typeAnnotation);
|
|
33
|
+
|
|
34
|
+
maybeParenClose(path, printer);
|
|
35
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {TemplateLiteral} = require('./template-literal');
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
const {Identifier} = require('./identifier');
|
|
5
6
|
|
|
6
7
|
module.exports = {
|
|
8
|
+
Identifier,
|
|
7
9
|
TemplateLiteral,
|
|
8
10
|
BigIntLiteral(path, {write}) {
|
|
9
11
|
write(path.node.raw);
|
|
@@ -39,23 +41,6 @@ module.exports = {
|
|
|
39
41
|
|
|
40
42
|
write(raw || `'${value}'`);
|
|
41
43
|
},
|
|
42
|
-
Identifier(path, {write, maybe, traverse, print}) {
|
|
43
|
-
const {node} = path;
|
|
44
|
-
const {name, optional} = node;
|
|
45
|
-
const parenthesized = node.extra?.parenthesized;
|
|
46
|
-
const typeAnnotation = path.get('typeAnnotation');
|
|
47
|
-
|
|
48
|
-
maybe.write(parenthesized, '(');
|
|
49
|
-
for (const decorator of maybeDecorators(path)) {
|
|
50
|
-
traverse(decorator);
|
|
51
|
-
print(' ');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
write(name);
|
|
55
|
-
maybe.write(optional, '?');
|
|
56
|
-
traverse(typeAnnotation);
|
|
57
|
-
maybe.write(parenthesized, ')');
|
|
58
|
-
},
|
|
59
44
|
RegExpLiteral(path, {print}) {
|
|
60
45
|
print(path.node.raw);
|
|
61
46
|
},
|
|
@@ -30,6 +30,11 @@ const {TSCallSignatureDeclaration} = require('./function/ts-call-signature-decla
|
|
|
30
30
|
const {TSConstructSignatureDeclaration} = require('./function/ts-construct-signature-declaration');
|
|
31
31
|
const {TSMethodSignature} = require('./function/ts-method-signature');
|
|
32
32
|
|
|
33
|
+
const {
|
|
34
|
+
maybeParenOpen,
|
|
35
|
+
maybeParenClose,
|
|
36
|
+
} = require('../expressions/unary-expression/parens');
|
|
37
|
+
|
|
33
38
|
module.exports = {
|
|
34
39
|
TSAsExpression,
|
|
35
40
|
TSTypeLiteral,
|
|
@@ -119,11 +124,13 @@ module.exports = {
|
|
|
119
124
|
TSBooleanKeyword(path, {write}) {
|
|
120
125
|
write('boolean');
|
|
121
126
|
},
|
|
122
|
-
TSUnionType(path,
|
|
127
|
+
TSUnionType(path, printer) {
|
|
128
|
+
const {traverse, write} = printer;
|
|
129
|
+
|
|
123
130
|
const types = path.get('types');
|
|
124
131
|
const n = types.length - 1;
|
|
125
132
|
|
|
126
|
-
|
|
133
|
+
maybeParenOpen(path, printer);
|
|
127
134
|
|
|
128
135
|
for (const [i, type] of types.entries()) {
|
|
129
136
|
traverse(type);
|
|
@@ -135,7 +142,7 @@ module.exports = {
|
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
maybeParenClose(path, printer);
|
|
139
146
|
},
|
|
140
147
|
TSNumberKeyword(path, {write}) {
|
|
141
148
|
write('number');
|
package/package.json
CHANGED