@putout/printer 5.20.0 → 5.22.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/README.md +25 -1
- package/lib/printer.js +2 -0
- package/lib/tokenize/tokenize.js +2 -15
- package/lib/tokenize/typescript/index.js +1 -1
- package/lib/tokenize/typescript/type/ts-type-parameter.js +1 -1
- package/lib/tokenize/visitors.js +15 -0
- package/package.json +1 -1
- /package/lib/tokenize/typescript/{ts-mapped-type.js → mapped-type/ts-mapped-type.js} +0 -0
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2023.10.05, v5.22.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 8a98fa5 @putout/printer: TSTypeParameter inside TSMappedType: extends -> in (coderaiser/putout#185)
|
|
5
|
+
|
|
6
|
+
2023.10.03, v5.21.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 3c291c6 @putout/printer: export visitors
|
|
10
|
+
|
|
1
11
|
2023.10.02, v5.20.0
|
|
2
12
|
|
|
3
13
|
feature:
|
package/README.md
CHANGED
|
@@ -174,6 +174,30 @@ Options used to configure logic of output, similar to ESLint rules:
|
|
|
174
174
|
|
|
175
175
|
When you want to improve support of existing visitor or extend **Printer** with a new ones, you need next base operations:
|
|
176
176
|
|
|
177
|
+
### override
|
|
178
|
+
|
|
179
|
+
When you need to override behavior of existing visitor use:
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
import {
|
|
183
|
+
print,
|
|
184
|
+
visitors as v,
|
|
185
|
+
} from '@putout/printer';
|
|
186
|
+
|
|
187
|
+
print(ast, {
|
|
188
|
+
visitors: {
|
|
189
|
+
CallExpression(path, printer, semantics) {
|
|
190
|
+
const {print} = printer;
|
|
191
|
+
|
|
192
|
+
if (!path.node.goldstein)
|
|
193
|
+
return v.CallExpression(path, printer, semantics);
|
|
194
|
+
|
|
195
|
+
print('__goldstein');
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
177
201
|
### `print`
|
|
178
202
|
|
|
179
203
|
Used in previous example `print` can be used for a couple purposes:
|
|
@@ -259,7 +283,7 @@ print(ast, {
|
|
|
259
283
|
});
|
|
260
284
|
```
|
|
261
285
|
|
|
262
|
-
This is the same as `
|
|
286
|
+
This is the same as `print('__left')` but more low-level, and supports only objects.
|
|
263
287
|
|
|
264
288
|
## Speed Comparison
|
|
265
289
|
|
package/lib/printer.js
CHANGED
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -4,12 +4,8 @@ const {round} = Math;
|
|
|
4
4
|
const fullstore = require('fullstore');
|
|
5
5
|
const isObject = (a) => a && typeof a === 'object';
|
|
6
6
|
const babelTraverse = require('@putout/babel').traverse;
|
|
7
|
-
const expressions = require('./expressions');
|
|
8
|
-
const statements = require('./statements');
|
|
9
|
-
const literals = require('./literals');
|
|
10
|
-
const typescript = require('./typescript');
|
|
11
|
-
const jsx = require('./jsx');
|
|
12
7
|
const {TYPES} = require('../types');
|
|
8
|
+
const baseVisitors = require('./visitors');
|
|
13
9
|
|
|
14
10
|
const {
|
|
15
11
|
maybeFile,
|
|
@@ -18,7 +14,6 @@ const {
|
|
|
18
14
|
} = require('./maybe');
|
|
19
15
|
|
|
20
16
|
const {createDebug, createLog} = require('./debug');
|
|
21
|
-
|
|
22
17
|
const {maybeMarkAfter} = require('./mark');
|
|
23
18
|
|
|
24
19
|
const {
|
|
@@ -32,14 +27,6 @@ const isString = (a) => typeof a === 'string';
|
|
|
32
27
|
const {assign, freeze} = Object;
|
|
33
28
|
const callWith = (fn, a) => () => fn(a);
|
|
34
29
|
|
|
35
|
-
const traversers = {
|
|
36
|
-
...expressions,
|
|
37
|
-
...statements,
|
|
38
|
-
...literals,
|
|
39
|
-
...typescript,
|
|
40
|
-
...jsx,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
30
|
const GET = '__';
|
|
44
31
|
const get = (path, command) => path.get(command.replace(GET, ''));
|
|
45
32
|
|
|
@@ -183,7 +170,7 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
183
170
|
});
|
|
184
171
|
|
|
185
172
|
const currentTraversers = {
|
|
186
|
-
...
|
|
173
|
+
...baseVisitors,
|
|
187
174
|
...visitors,
|
|
188
175
|
};
|
|
189
176
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const {isNext} = require('../is');
|
|
4
4
|
const {TSTypeLiteral} = require('./type/ts-type-literal');
|
|
5
5
|
const {TSTypeAliasDeclaration} = require('./type/ts-type-alias-declaration');
|
|
6
|
-
const {TSMappedType} = require('./ts-mapped-type');
|
|
6
|
+
const {TSMappedType} = require('./mapped-type/ts-mapped-type');
|
|
7
7
|
const {TSConditionalType} = require('./ts-conditional-type');
|
|
8
8
|
const {TSTypeParameter} = require('./type/ts-type-parameter');
|
|
9
9
|
const {TSDeclareFunction} = require('./function/ts-declare-function');
|
|
@@ -17,7 +17,7 @@ module.exports.TSTypeParameter = (path, {write, traverse}) => {
|
|
|
17
17
|
if (!exists(constraint))
|
|
18
18
|
return;
|
|
19
19
|
|
|
20
|
-
if (constraint.isTSTypeOperator()) {
|
|
20
|
+
if (constraint.isTSTypeOperator() || path.parentPath.isTSMappedType()) {
|
|
21
21
|
write(' in ');
|
|
22
22
|
} else {
|
|
23
23
|
write(' extends ');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const expressions = require('./expressions');
|
|
4
|
+
const statements = require('./statements');
|
|
5
|
+
const literals = require('./literals');
|
|
6
|
+
const typescript = require('./typescript');
|
|
7
|
+
const jsx = require('./jsx');
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
...expressions,
|
|
11
|
+
...statements,
|
|
12
|
+
...literals,
|
|
13
|
+
...typescript,
|
|
14
|
+
...jsx,
|
|
15
|
+
};
|
package/package.json
CHANGED
|
File without changes
|