@putout/printer 1.58.0 → 1.60.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 +10 -0
- package/lib/tokenize/debug.js +5 -0
- package/lib/tokenize/expressions/functions/class-method.js +42 -0
- package/lib/tokenize/expressions/functions/functions.js +2 -23
- package/lib/tokenize/jsx/index.js +2 -1
- package/lib/tokenize/literals/index.js +3 -0
- package/lib/tokenize/tokenize.js +7 -13
- package/lib/types.js +1 -0
- package/package.json +2 -1
package/ChangeLog
CHANGED
package/lib/tokenize/debug.js
CHANGED
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
LOG,
|
|
9
9
|
LOG_ALL,
|
|
10
10
|
LOG_TOKENS,
|
|
11
|
+
LOG_TERM,
|
|
11
12
|
DEBUG,
|
|
12
13
|
} = process.env;
|
|
13
14
|
|
|
@@ -54,6 +55,10 @@ module.exports.createLog = ({newline = '\n', store = createStore()} = {}) => ({t
|
|
|
54
55
|
|
|
55
56
|
store(value);
|
|
56
57
|
}
|
|
58
|
+
|
|
59
|
+
if (LOG_TERM) {
|
|
60
|
+
process.stdout.write(value);
|
|
61
|
+
}
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
function createStore() {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isNext} = require('../../is');
|
|
4
|
+
|
|
5
|
+
module.exports.ClassMethod = {
|
|
6
|
+
print(path, {print, maybe}) {
|
|
7
|
+
const {kind} = path.node;
|
|
8
|
+
const isConstructor = kind === 'constructor';
|
|
9
|
+
const isMethod = kind === 'method';
|
|
10
|
+
const isGetter = /get|set/.test(kind);
|
|
11
|
+
|
|
12
|
+
maybe.print(isConstructor, kind);
|
|
13
|
+
maybe.print(isMethod, '__key');
|
|
14
|
+
|
|
15
|
+
if (isGetter) {
|
|
16
|
+
print(kind);
|
|
17
|
+
print(' ');
|
|
18
|
+
print('__key');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
print('(');
|
|
22
|
+
|
|
23
|
+
const params = path.get('params');
|
|
24
|
+
const n = params.length;
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < n; i++) {
|
|
27
|
+
print(params[i]);
|
|
28
|
+
|
|
29
|
+
if (i < n - 1)
|
|
30
|
+
print(', ');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
print(') ');
|
|
34
|
+
print('__body');
|
|
35
|
+
},
|
|
36
|
+
afterSatisfy: () => [
|
|
37
|
+
isNext,
|
|
38
|
+
],
|
|
39
|
+
after(path, {print}) {
|
|
40
|
+
print.linebreak();
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const {ArrowFunctionExpression} = require('./arrow-function-expression');
|
|
4
4
|
const {FunctionDeclaration} = require('./function-declaration');
|
|
5
|
+
const {ClassMethod} = require('./class-method');
|
|
5
6
|
|
|
6
7
|
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
7
8
|
module.exports.FunctionDeclaration = FunctionDeclaration;
|
|
9
|
+
module.exports.ClassMethod = ClassMethod;
|
|
8
10
|
|
|
9
11
|
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
10
12
|
const {node} = path;
|
|
@@ -63,26 +65,3 @@ module.exports.ObjectMethod = (path, {print}) => {
|
|
|
63
65
|
print(') ');
|
|
64
66
|
print('__body');
|
|
65
67
|
};
|
|
66
|
-
|
|
67
|
-
module.exports.ClassMethod = (path, {print, maybe}) => {
|
|
68
|
-
const {kind} = path.node;
|
|
69
|
-
const notMethod = kind !== 'method';
|
|
70
|
-
const notConstructor = kind !== 'constructor';
|
|
71
|
-
|
|
72
|
-
maybe.print(notMethod, `${kind} `);
|
|
73
|
-
maybe.print(notConstructor, '__key');
|
|
74
|
-
print('(');
|
|
75
|
-
|
|
76
|
-
const params = path.get('params');
|
|
77
|
-
const n = params.length;
|
|
78
|
-
|
|
79
|
-
for (let i = 0; i < n; i++) {
|
|
80
|
-
print(params[i]);
|
|
81
|
-
|
|
82
|
-
if (i < n - 1)
|
|
83
|
-
print(', ');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
print(') ');
|
|
87
|
-
print('__body');
|
|
88
|
-
};
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -100,10 +100,8 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
const linebreak = () => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
value: `${printIndent(i, format.indent)}\n`,
|
|
106
|
-
});
|
|
103
|
+
indent();
|
|
104
|
+
newline();
|
|
107
105
|
};
|
|
108
106
|
|
|
109
107
|
const space = () => {
|
|
@@ -114,15 +112,8 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
114
112
|
};
|
|
115
113
|
|
|
116
114
|
const breakline = () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
value: '\n',
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
addToken({
|
|
123
|
-
type: TYPES.SPACE,
|
|
124
|
-
value: printIndent(i, format.indent),
|
|
125
|
-
});
|
|
115
|
+
newline();
|
|
116
|
+
indent();
|
|
126
117
|
};
|
|
127
118
|
|
|
128
119
|
const newline = () => {
|
|
@@ -219,7 +210,10 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
219
210
|
|
|
220
211
|
const currentIndent = i;
|
|
221
212
|
parseLeadingComments(path, printer);
|
|
213
|
+
|
|
214
|
+
// this is main thing
|
|
222
215
|
maybePlugin(currentTraverse, path, printer);
|
|
216
|
+
|
|
223
217
|
parseTrailingComments(path, printer);
|
|
224
218
|
maybeThrow(i !== currentIndent, path, `☝️Looks like indent level changed after token visitor: '{{ type }}', for code: '{{ path }}'`);
|
|
225
219
|
debug(path.type);
|
package/lib/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.60.0",
|
|
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",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"generate"
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"@putout/plugin-react-hooks": "^5.0.0",
|
|
48
49
|
"@putout/test": "^6.0.1",
|
|
49
50
|
"acorn": "^8.8.2",
|
|
50
51
|
"c8": "^7.5.0",
|