@putout/printer 5.20.0 → 5.21.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 CHANGED
@@ -1,3 +1,8 @@
1
+ 2023.10.03, v5.21.0
2
+
3
+ feature:
4
+ - 3c291c6 @putout/printer: export visitors
5
+
1
6
  2023.10.02, v5.20.0
2
7
 
3
8
  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:
package/lib/printer.js CHANGED
@@ -10,3 +10,5 @@ module.exports.print = (ast, overrides = {}) => {
10
10
 
11
11
  return printTokens(tokens);
12
12
  };
13
+
14
+ module.exports.visitors = require('./tokenize/visitors');
@@ -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
- ...traversers,
173
+ ...baseVisitors,
187
174
  ...visitors,
188
175
  };
189
176
 
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.20.0",
3
+ "version": "5.21.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",