@putout/printer 7.4.0 → 8.0.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,9 @@
1
+ 2024.01.09, v8.0.0
2
+
3
+ feature:
4
+ - 7bfc136 @putout/printer: format.roundBraceOpen/roundBraceClose -> semantics.roundBraces (#4)
5
+ - d235aee @putout/printer: @putout/plugin-react-hooks v6.0.0
6
+
1
7
  2023.12.18, v7.4.0
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -89,8 +89,6 @@ print(ast, {
89
89
  newline: '\n',
90
90
  space: ' ',
91
91
  splitter: '\n',
92
- roundBraceOpen: '(',
93
- roundBraceClose: ')',
94
92
  quote: `'`,
95
93
  endOfFile: '\n',
96
94
  },
@@ -103,6 +101,7 @@ print(ast, {
103
101
  trailingComma: true,
104
102
  encodeSingleQuote: true,
105
103
  encodeDoubleQuote: false,
104
+ roundBraces: true,
106
105
  },
107
106
  visitors: {
108
107
  AssignmentPattern(path, {print}) {
@@ -128,8 +127,6 @@ const overrides = {
128
127
  newline: '\n',
129
128
  space: ' ',
130
129
  splitter: '\n',
131
- roundBraceOpen: '(',
132
- roundBraceClose: ')',
133
130
  endOfFile: '\n',
134
131
  },
135
132
  };
@@ -139,7 +136,6 @@ const overrides = {
139
136
  - `newline` - symbol used for line separation;
140
137
  - `space` - default symbol used for space character;
141
138
  - `splitter` - mandatory symbol that used inside of statements like this:
142
- - `roundBraceOpen` and `roundBraceClose` symbols to output braces in a single argument arrow function expressions: `(a) => {}`.
143
139
 
144
140
  Default options produce:
145
141
 
@@ -176,6 +172,7 @@ Options used to configure logic of output, similar to ESLint rules:
176
172
  - ✅ `maxElementsInOneLine` - count of `ArrayExpression` and `ArrayPattern` elements placed in one line.
177
173
  - ✅ `maxVariablesInOneLine` - count of `VariableDeclarators` in one line.
178
174
  - ✅ `maxPropertiesInOneLine` - count of `ObjectProperties` in one line.
175
+ - ✅ `roundBraces` - to output braces in a single argument arrow function expressions: `(a) => {}` or not `a => {}`.
179
176
 
180
177
  ## Visitors API
181
178
 
package/lib/printer.d.ts CHANGED
@@ -5,12 +5,11 @@ interface Format {
5
5
  newline: string;
6
6
  space: string;
7
7
  splitter: string;
8
- roundBraceOpen: string;
9
- roundBraceClose: string;
10
8
  quote: string;
11
9
  }
12
10
 
13
11
  interface Semantics {
12
+ roundBraces: boolean;
14
13
  comments: boolean;
15
14
  maxPropertiesInOneLine: number;
16
15
  maxSpecifiersInOneLine: number;
@@ -21,7 +21,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
21
21
  printBraceOpen(path, {
22
22
  print,
23
23
  braceOpen,
24
- });
24
+ }, semantics);
25
25
 
26
26
  parseComments(path, printer, semantics);
27
27
 
@@ -41,19 +41,19 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
41
41
  printBraceClose(path, {
42
42
  print,
43
43
  braceClose,
44
- });
44
+ }, semantics);
45
45
  };
46
46
 
47
- function printBraceOpen(path, {print, braceOpen}) {
48
- if (isOneArgArrow(path))
49
- return print.roundBraceOpen();
47
+ function printBraceOpen(path, {print, braceOpen}, semantics) {
48
+ if (isOneArgArrow(path) && !semantics.roundBraces)
49
+ return;
50
50
 
51
51
  return print(braceOpen);
52
52
  }
53
53
 
54
- function printBraceClose(path, {print, braceClose}) {
55
- if (isOneArgArrow(path))
56
- return print.roundBraceClose();
54
+ function printBraceClose(path, {print, braceClose}, semantics) {
55
+ if (isOneArgArrow(path) && !semantics.roundBraces)
56
+ return;
57
57
 
58
58
  print(braceClose);
59
59
  }
@@ -20,8 +20,6 @@ function initFormat(format) {
20
20
  newline: '\n',
21
21
  space: ' ',
22
22
  splitter: '\n',
23
- roundBraceOpen: '(',
24
- roundBraceClose: ')',
25
23
  quote: `'`,
26
24
  endOfFile: '\n',
27
25
  ...format,
@@ -38,6 +36,7 @@ function initSemantics(semantics = {}) {
38
36
  trailingComma: true,
39
37
  encodeSingleQuote: true,
40
38
  encodeDoubleQuote: false,
39
+ roundBraces: true,
41
40
  ...semantics,
42
41
  };
43
42
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- module.exports.maybeSpaceAfterKeyword = (path, {print}) => {
3
+ module.exports.maybeSpaceAfterKeyword = (path, {print}, semantics) => {
4
4
  const {argument} = path.node;
5
5
 
6
6
  if (!argument)
@@ -17,7 +17,7 @@ module.exports.maybeSpaceAfterKeyword = (path, {print}) => {
17
17
  if (type === 'UnaryExpression' && argument.operator === '!')
18
18
  return print.space();
19
19
 
20
- if (type === 'ArrowFunctionExpression')
20
+ if (type === 'ArrowFunctionExpression' && semantics.roundBraces)
21
21
  return print.space();
22
22
 
23
23
  print(' ');
@@ -20,12 +20,12 @@ module.exports.ReturnStatement = {
20
20
  before(path, {print}) {
21
21
  print.linebreak();
22
22
  },
23
- print(path, {indent, print}) {
23
+ print(path, printer, semantics) {
24
+ const {indent, print} = printer;
25
+
24
26
  indent();
25
27
  print('return');
26
- maybeSpaceAfterKeyword(path, {
27
- print,
28
- });
28
+ maybeSpaceAfterKeyword(path, printer, semantics);
29
29
 
30
30
  if (isJSXWithComment(path)) {
31
31
  print('(');
@@ -25,7 +25,6 @@ const {parseOverrides} = require('./overrides');
25
25
 
26
26
  const isString = (a) => typeof a === 'string';
27
27
  const {assign, freeze} = Object;
28
- const callWith = (fn, a) => () => fn(a);
29
28
 
30
29
  const GET = '__';
31
30
  const get = (path, command) => path.get(command.replace(GET, ''));
@@ -88,16 +87,6 @@ module.exports.tokenize = (ast, overrides) => {
88
87
  });
89
88
  };
90
89
 
91
- const roundBraceOpen = callWith(addToken, {
92
- type: TYPES.ROUND_BRACE_OPEN,
93
- value: format.roundBraceOpen,
94
- });
95
-
96
- const roundBraceClose = callWith(addToken, {
97
- type: TYPES.ROUND_BRACE_Close,
98
- value: format.roundBraceClose,
99
- });
100
-
101
90
  const linebreak = () => {
102
91
  indent();
103
92
  newline();
@@ -207,8 +196,6 @@ module.exports.tokenize = (ast, overrides) => {
207
196
  assign(print, write, {
208
197
  space,
209
198
  round,
210
- roundBraceOpen,
211
- roundBraceClose,
212
199
  });
213
200
 
214
201
  const printer = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "7.4.0",
3
+ "version": "8.0.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",
@@ -50,7 +50,7 @@
50
50
  "@putout/plugin-printer": "^3.0.0",
51
51
  "@putout/plugin-promises": "^14.0.0",
52
52
  "@putout/plugin-react-hook-form": "^4.0.0",
53
- "@putout/plugin-react-hooks": "^5.0.0",
53
+ "@putout/plugin-react-hooks": "^6.0.0",
54
54
  "acorn": "^8.8.2",
55
55
  "c8": "^8.0.0",
56
56
  "check-dts": "^0.7.2",