@putout/printer 2.41.0 → 2.42.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/class.js +10 -3
- package/lib/tokenize/expressions/functions/class-method.js +0 -1
- package/lib/tokenize/expressions/functions/function-declaration.js +0 -1
- package/lib/tokenize/expressions/functions/object-method.js +0 -1
- package/lib/tokenize/expressions/functions/params.js +0 -1
- package/lib/tokenize/expressions/new-expression.js +47 -16
- package/lib/tokenize/literals/index.js +3 -8
- package/lib/tokenize/maybe-get.js +8 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {isNext} = require('../is');
|
|
4
4
|
const {markAfter} = require('../mark');
|
|
5
|
+
const {maybeDecorators} = require('../maybe-get');
|
|
5
6
|
|
|
6
7
|
module.exports.ClassExpression = classVisitor;
|
|
7
8
|
module.exports.ClassDeclaration = classVisitor;
|
|
@@ -20,13 +21,14 @@ module.exports.StaticBlock = (path, {print, traverse}) => {
|
|
|
20
21
|
print.newline();
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
|
|
24
|
+
module.exports.ClassDeclaration = (path, {print, indent, maybe, write, traverse}) => {
|
|
24
25
|
indent();
|
|
25
26
|
|
|
26
27
|
classVisitor(path, {
|
|
27
28
|
print,
|
|
28
29
|
indent,
|
|
29
30
|
maybe,
|
|
31
|
+
traverse,
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
if (!path.parentPath.isExportDeclaration() && isNext(path)) {
|
|
@@ -36,7 +38,12 @@ module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
|
|
|
36
38
|
}
|
|
37
39
|
};
|
|
38
40
|
|
|
39
|
-
function classVisitor(path, {print, indent, maybe}) {
|
|
41
|
+
function classVisitor(path, {print, indent, maybe, traverse}) {
|
|
42
|
+
for (const decorator of maybeDecorators(path)) {
|
|
43
|
+
traverse(decorator);
|
|
44
|
+
print.breakline();
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
print('class ');
|
|
41
48
|
print('__id');
|
|
42
49
|
print('__typeParameters');
|
|
@@ -64,7 +71,7 @@ function classVisitor(path, {print, indent, maybe}) {
|
|
|
64
71
|
|
|
65
72
|
for (const item of body) {
|
|
66
73
|
indent();
|
|
67
|
-
|
|
74
|
+
traverse(item);
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
indent.dec();
|
|
@@ -1,19 +1,50 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
const {exists} = require('../is');
|
|
4
|
+
const isInsideExpressionStatement = ({parentPath}) => parentPath.isExpressionStatement();
|
|
5
|
+
const notFirst = ({parentPath}) => exists(parentPath.getPrevSibling());
|
|
6
|
+
|
|
7
|
+
const getPrev = ({parentPath}) => {
|
|
8
|
+
const prev = parentPath.getPrevSibling();
|
|
9
|
+
return [
|
|
10
|
+
prev.node,
|
|
11
|
+
prev,
|
|
12
|
+
];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports.NewExpression = {
|
|
16
|
+
beforeIf(path) {
|
|
17
|
+
if (!isInsideExpressionStatement(path))
|
|
18
|
+
return false;
|
|
19
|
+
|
|
20
|
+
const [exists, prev] = getPrev(path);
|
|
21
|
+
|
|
22
|
+
if (!exists)
|
|
23
|
+
return false;
|
|
24
|
+
|
|
25
|
+
if (prev.isExpressionStatement())
|
|
26
|
+
return false;
|
|
27
|
+
|
|
28
|
+
return notFirst(path);
|
|
29
|
+
},
|
|
30
|
+
before(path, {print}) {
|
|
31
|
+
print.breakline();
|
|
32
|
+
},
|
|
33
|
+
print(path, {print, maybe}) {
|
|
34
|
+
print('new ');
|
|
35
|
+
print('__callee');
|
|
36
|
+
print('__typeParameters');
|
|
37
|
+
|
|
38
|
+
const args = path.get('arguments');
|
|
39
|
+
print('(');
|
|
40
|
+
|
|
41
|
+
const n = args.length - 1;
|
|
42
|
+
|
|
43
|
+
for (const [i, arg] of args.entries()) {
|
|
44
|
+
print(arg);
|
|
45
|
+
maybe.print(i < n, ', ');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
print(')');
|
|
49
|
+
},
|
|
19
50
|
};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {TemplateLiteral} = require('./template-literal');
|
|
4
|
-
const maybeDecorators = (
|
|
5
|
-
if (!path.node.decorators)
|
|
6
|
-
return [];
|
|
7
|
-
|
|
8
|
-
return path.get('decorators');
|
|
9
|
-
};
|
|
4
|
+
const {maybeDecorators} = require('../maybe-get');
|
|
10
5
|
|
|
11
6
|
module.exports = {
|
|
12
7
|
TemplateLiteral,
|
|
@@ -16,7 +11,6 @@ module.exports = {
|
|
|
16
11
|
Decorator(path, {print}) {
|
|
17
12
|
print('@');
|
|
18
13
|
print('__expression');
|
|
19
|
-
print(' ');
|
|
20
14
|
},
|
|
21
15
|
NumericLiteral(path, {write}) {
|
|
22
16
|
const {
|
|
@@ -35,7 +29,7 @@ module.exports = {
|
|
|
35
29
|
|
|
36
30
|
write(raw || `'${value}'`);
|
|
37
31
|
},
|
|
38
|
-
Identifier(path, {write, maybe, traverse}) {
|
|
32
|
+
Identifier(path, {write, maybe, traverse, print}) {
|
|
39
33
|
const {node} = path;
|
|
40
34
|
const {name, optional} = node;
|
|
41
35
|
const parenthesized = node.extra?.parenthesized;
|
|
@@ -44,6 +38,7 @@ module.exports = {
|
|
|
44
38
|
maybe.write(parenthesized, '(');
|
|
45
39
|
for (const decorator of maybeDecorators(path)) {
|
|
46
40
|
traverse(decorator);
|
|
41
|
+
print(' ');
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
write(name);
|
package/package.json
CHANGED