@putout/printer 8.48.0 → 9.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,13 @@
1
+ 2024.06.07, v9.0.0
2
+
3
+ feature:
4
+ - d4510ed @putout/printer: semantics: roundBraces: add support of SequenceExpressions
5
+
6
+ 2024.06.07, v8.48.1
7
+
8
+ feature:
9
+ - 5fe30fd @putout/printer: move out SequenceExpression
10
+
1
11
  2024.06.07, v8.48.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -174,7 +174,9 @@ Options used to configure logic of output, similar to ESLint rules:
174
174
  - ✅ `maxVariablesInOneLine` - count of `VariableDeclarators` in one line.
175
175
  - ✅ `maxPropertiesInOneLine` - count of `ObjectProperties` in one line.
176
176
  - ✅ `maxPropertiesLengthInOneLine` - maximum length of `Object Property`, when violated splits event if `maxPropertiesInOneLine` satisfies;
177
- - ✅ `roundBraces` - to output braces in a single argument arrow function expressions: `(a) => {}` or not `a => {}`.
177
+ - ✅ `roundBraces` to output braces or not
178
+ - In a single argument arrow function expressions `(a) => {}` or not `a => {}`;
179
+ - In sequence expressions: `for(let e of l) (a(), b())` or not `for(let e of l) a(), b()`;
178
180
 
179
181
  ## Visitors API
180
182
 
@@ -33,7 +33,7 @@ const {ArrayPattern} = require('./array-pattern/array-pattern');
33
33
  const {AssignmentPattern} = require('./assignment-pattern');
34
34
  const {RestElement} = require('./rest-element');
35
35
  const {SpreadElement} = require('./spread-element');
36
- const {SequenceExpression} = require('./sequence-expression');
36
+ const {SequenceExpression} = require('./sequence-expression/sequence-expression');
37
37
  const {TaggedTemplateExpression} = require('./tagged-template-expression');
38
38
 
39
39
  const {
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ module.exports.SequenceExpression = (path, printer, semantics) => {
4
+ const {maybe, traverse} = printer;
5
+
6
+ const expressions = path.get('expressions');
7
+ const n = expressions.length - 1;
8
+
9
+ maybeWriteBrace(path, printer, semantics, {
10
+ brace: '(',
11
+ });
12
+
13
+ for (const [index, expression] of expressions.entries()) {
14
+ traverse(expression);
15
+ maybe.write(index < n, ',');
16
+ maybe.write.space(index < n);
17
+ }
18
+
19
+ maybeWriteBrace(path, printer, semantics, {
20
+ brace: ')',
21
+ });
22
+ };
23
+
24
+ function maybeWriteBrace(path, printer, semantics, {brace}) {
25
+ const {roundBraces} = semantics;
26
+ const {write} = printer;
27
+
28
+ if (path.parentPath.isArrowFunctionExpression()) {
29
+ write(brace);
30
+ return;
31
+ }
32
+
33
+ if (!roundBraces)
34
+ return;
35
+
36
+ write(brace);
37
+ }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isNext, isParentLast} = require('../../is');
3
+ const {isNext} = require('../../is');
4
4
 
5
5
  module.exports.TryStatement = {
6
6
  print(path, {print}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.48.0",
3
+ "version": "9.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",
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports.SequenceExpression = (path, {maybe, write, traverse}) => {
4
- const expressions = path.get('expressions');
5
- const n = expressions.length - 1;
6
-
7
- write('(');
8
-
9
- for (const [index, expression] of expressions.entries()) {
10
- traverse(expression);
11
- maybe.write(index < n, ',');
12
- maybe.write.space(index < n);
13
- }
14
-
15
- write(')');
16
- };