@putout/printer 1.6.1 → 1.6.2

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.03.20, v1.6.2
2
+
3
+ feature:
4
+ - eb7ba9c @putout/printer: add format
5
+
1
6
  2023.03.20, v1.6.1
2
7
 
3
8
  fix:
package/README.md CHANGED
@@ -48,7 +48,9 @@ Here is how you can override `AssignmentPattern`:
48
48
  const ast = parse('const {a = 5} = b');
49
49
 
50
50
  print(ast, {
51
- indent: ' ',
51
+ format: {
52
+ indent: ' ',
53
+ },
52
54
  visitors: {
53
55
  AssignmentPattern(path, {print}) {
54
56
  print(' /* [hello world] */= ');
@@ -25,7 +25,15 @@ const traversers = {
25
25
  const GET = '__';
26
26
  const get = (path, command) => path.get(command.replace(GET, ''));
27
27
 
28
+ function initFormat(format) {
29
+ return {
30
+ ...format,
31
+ indent: ' ',
32
+ };
33
+ }
34
+
28
35
  module.exports.tokenize = (ast, overrides = {}) => {
36
+ const format = initFormat(overrides.format);
29
37
  const tokens = [];
30
38
  const debug = createDebug(tokens);
31
39
  const write = (value) => {
@@ -48,7 +56,7 @@ module.exports.tokenize = (ast, overrides = {}) => {
48
56
  const indent = () => {
49
57
  tokens.push({
50
58
  type: TYPES.INDENT,
51
- value: printIndent(i),
59
+ value: printIndent(i, format.indent),
52
60
  });
53
61
  };
54
62
 
@@ -60,14 +68,14 @@ module.exports.tokenize = (ast, overrides = {}) => {
60
68
  const linebreak = () => {
61
69
  tokens.push({
62
70
  type: TYPES.NEWLINE,
63
- value: `${printIndent(i)}\n`,
71
+ value: `${printIndent(i, format.indent)}\n`,
64
72
  });
65
73
  };
66
74
 
67
75
  const breakline = () => {
68
76
  tokens.push({
69
77
  type: TYPES.NEWLINE,
70
- value: `\n${printIndent(i)}`,
78
+ value: `\n${printIndent(i, format.indent)}`,
71
79
  });
72
80
  };
73
81
 
@@ -155,12 +163,12 @@ module.exports.tokenize = (ast, overrides = {}) => {
155
163
  return tokens;
156
164
  };
157
165
 
158
- function printIndent(i) {
166
+ function printIndent(i, indent) {
159
167
  let result = '';
160
168
  ++i;
161
169
 
162
170
  while (--i) {
163
- result += ' ';
171
+ result += indent;
164
172
  }
165
173
 
166
174
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
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",