@putout/printer 5.8.0 → 5.9.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 +6 -0
- package/lib/tokenize/expressions/class/class-property.js +17 -18
- package/lib/tokenize/expressions/class/maybe-decorators.js +22 -0
- package/lib/tokenize/expressions/function/class-method.js +3 -5
- package/lib/tokenize/tokenize.js +7 -10
- package/package.json +1 -1
- package/lib/tokenize/expressions/class/maybe-print-decorators.js +0 -16
package/ChangeLog
CHANGED
|
@@ -2,23 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const {exists} = require('../../is');
|
|
4
4
|
const {maybePrintTypeAnnotation} = require('../../literals/maybe-type-annotation');
|
|
5
|
-
const {
|
|
5
|
+
const {maybeDecorators} = require('./maybe-decorators');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
module.exports.ClassPrivateProperty = processClassProperty;
|
|
9
|
-
|
|
10
|
-
module.exports.PrivateName = (path, {print}) => {
|
|
11
|
-
print('#');
|
|
12
|
-
print('__id');
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
module.exports.ClassAccessorProperty = (path, printer, semantics) => {
|
|
16
|
-
processClassProperty(path, printer, semantics, {
|
|
17
|
-
accessor: true,
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function processClassProperty(path, printer, semantics, {accessor} = {}) {
|
|
7
|
+
const processClassProperty = maybeDecorators((path, printer, semantics, {accessor} = {}) => {
|
|
22
8
|
const {print, maybe} = printer;
|
|
23
9
|
const {node} = path;
|
|
24
10
|
const {
|
|
@@ -27,7 +13,6 @@ function processClassProperty(path, printer, semantics, {accessor} = {}) {
|
|
|
27
13
|
optional,
|
|
28
14
|
} = node;
|
|
29
15
|
|
|
30
|
-
maybePrintDecorators(path, printer);
|
|
31
16
|
maybe.print(accessor, 'accessor ');
|
|
32
17
|
|
|
33
18
|
const value = path.get('value');
|
|
@@ -50,4 +35,18 @@ function processClassProperty(path, printer, semantics, {accessor} = {}) {
|
|
|
50
35
|
|
|
51
36
|
print(';');
|
|
52
37
|
print.newline();
|
|
53
|
-
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
module.exports.ClassProperty = processClassProperty;
|
|
41
|
+
module.exports.ClassPrivateProperty = processClassProperty;
|
|
42
|
+
|
|
43
|
+
module.exports.PrivateName = (path, {print}) => {
|
|
44
|
+
print('#');
|
|
45
|
+
print('__id');
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports.ClassAccessorProperty = (path, printer, semantics) => {
|
|
49
|
+
processClassProperty(path, printer, semantics, {
|
|
50
|
+
accessor: true,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isPrev} = require('../../is');
|
|
4
|
+
|
|
5
|
+
module.exports.maybeDecorators = (visitor) => (path, printer, semantics, options) => {
|
|
6
|
+
const {
|
|
7
|
+
write,
|
|
8
|
+
traverse,
|
|
9
|
+
maybe,
|
|
10
|
+
} = printer;
|
|
11
|
+
const {decorators} = path.node;
|
|
12
|
+
|
|
13
|
+
if (decorators) {
|
|
14
|
+
for (const decorator of path.get('decorators')) {
|
|
15
|
+
maybe.write.breakline(isPrev(path));
|
|
16
|
+
traverse(decorator);
|
|
17
|
+
write.breakline();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
visitor(path, printer, semantics, options);
|
|
22
|
+
};
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const {isNext} = require('../../is');
|
|
4
4
|
const {printParams} = require('./params');
|
|
5
|
-
const {
|
|
5
|
+
const {maybeDecorators} = require('../class/maybe-decorators');
|
|
6
6
|
|
|
7
7
|
const ClassMethod = {
|
|
8
|
-
print(path, printer, semantics) {
|
|
8
|
+
print: maybeDecorators((path, printer, semantics) => {
|
|
9
9
|
const {print, maybe} = printer;
|
|
10
10
|
const {node} = path;
|
|
11
11
|
const {
|
|
@@ -20,8 +20,6 @@ const ClassMethod = {
|
|
|
20
20
|
const isMethod = kind === 'method';
|
|
21
21
|
const isGetter = /get|set/.test(kind);
|
|
22
22
|
|
|
23
|
-
maybePrintDecorators(path, printer);
|
|
24
|
-
|
|
25
23
|
if (accessibility) {
|
|
26
24
|
print(accessibility);
|
|
27
25
|
print(' ');
|
|
@@ -62,7 +60,7 @@ const ClassMethod = {
|
|
|
62
60
|
|
|
63
61
|
print.space();
|
|
64
62
|
print('__body');
|
|
65
|
-
},
|
|
63
|
+
}),
|
|
66
64
|
afterSatisfy: () => [isNext],
|
|
67
65
|
after(path, {print}) {
|
|
68
66
|
print.linebreak();
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -19,10 +19,7 @@ const {
|
|
|
19
19
|
|
|
20
20
|
const {createDebug, createLog} = require('./debug');
|
|
21
21
|
|
|
22
|
-
const {
|
|
23
|
-
maybeMarkAfter,
|
|
24
|
-
maybeMarkBefore,
|
|
25
|
-
} = require('./mark');
|
|
22
|
+
const {maybeMarkAfter} = require('./mark');
|
|
26
23
|
|
|
27
24
|
const {
|
|
28
25
|
parseLeadingComments,
|
|
@@ -32,7 +29,7 @@ const {
|
|
|
32
29
|
const {parseOverrides} = require('./overrides');
|
|
33
30
|
|
|
34
31
|
const isString = (a) => typeof a === 'string';
|
|
35
|
-
const {assign} = Object;
|
|
32
|
+
const {assign, freeze} = Object;
|
|
36
33
|
const callWith = (fn, a) => () => fn(a);
|
|
37
34
|
|
|
38
35
|
const traversers = {
|
|
@@ -164,7 +161,6 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
164
161
|
|
|
165
162
|
const maybe = {
|
|
166
163
|
indent: maybeIndent,
|
|
167
|
-
markBefore: maybeMarkBefore,
|
|
168
164
|
markAfter: maybeMarkAfter,
|
|
169
165
|
write: maybeWrite,
|
|
170
166
|
space: maybeSpace,
|
|
@@ -175,7 +171,7 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
175
171
|
dec: maybeIndentDec,
|
|
176
172
|
});
|
|
177
173
|
|
|
178
|
-
const
|
|
174
|
+
const mainPrinter = freeze({
|
|
179
175
|
indent,
|
|
180
176
|
write,
|
|
181
177
|
debug,
|
|
@@ -183,7 +179,7 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
183
179
|
maybe,
|
|
184
180
|
quote,
|
|
185
181
|
store: fullstore(),
|
|
186
|
-
};
|
|
182
|
+
});
|
|
187
183
|
|
|
188
184
|
const currentTraversers = {
|
|
189
185
|
...traversers,
|
|
@@ -219,9 +215,10 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
219
215
|
roundBraceClose,
|
|
220
216
|
});
|
|
221
217
|
|
|
222
|
-
|
|
218
|
+
const printer = {
|
|
219
|
+
...mainPrinter,
|
|
223
220
|
print,
|
|
224
|
-
}
|
|
221
|
+
};
|
|
225
222
|
|
|
226
223
|
const maybePrint = (a, b) => a && print(b);
|
|
227
224
|
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {isPrev} = require('../../is');
|
|
4
|
-
|
|
5
|
-
module.exports.maybePrintDecorators = (path, printer) => {
|
|
6
|
-
const {print, maybe} = printer;
|
|
7
|
-
const {decorators} = path.node;
|
|
8
|
-
|
|
9
|
-
if (decorators) {
|
|
10
|
-
for (const decorator of path.get('decorators')) {
|
|
11
|
-
maybe.print.breakline(isPrev(path));
|
|
12
|
-
print(decorator);
|
|
13
|
-
print.breakline();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|