@putout/printer 1.54.1 → 1.54.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.04.18, v1.54.2
2
+
3
+ feature:
4
+ - a9c17af @putout/printer: improve support of ArrowFunctionExpression used inside LogicalExpression
5
+
1
6
  2023.04.18, v1.54.1
2
7
 
3
8
  feature:
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ const {exists} = require('../../is');
4
+
5
+ module.exports.ArrowFunctionExpression = {
6
+ condition({parentPath}) {
7
+ return parentPath.isLogicalExpression();
8
+ },
9
+ before(path, {write}) {
10
+ write('(');
11
+ },
12
+ print(path, {print, maybe, write, traverse}) {
13
+ const {async} = path.node;
14
+
15
+ maybe.print(async, 'async ');
16
+ print('(');
17
+
18
+ const params = path.get('params');
19
+ const n = params.length;
20
+
21
+ for (let i = 0; i < n; i++) {
22
+ print(params[i]);
23
+
24
+ if (i < n - 1)
25
+ print(', ');
26
+ }
27
+
28
+ print(')');
29
+
30
+ const returnType = path.get('returnType');
31
+
32
+ if (exists(returnType)) {
33
+ write(':');
34
+ write.space();
35
+ traverse(returnType);
36
+ }
37
+
38
+ print.space();
39
+ print('=>');
40
+ print.space();
41
+ print('__body');
42
+ },
43
+ after(path, {write}) {
44
+ write(')');
45
+ },
46
+ };
@@ -1,8 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const {hasPrevNewline} = require('../mark');
4
- const {exists} = require('../is');
3
+ const {hasPrevNewline} = require('../../mark');
5
4
  const isFirst = (path) => !path.getPrevSibling().node;
5
+ const {ArrowFunctionExpression} = require('./arrow-function-expression');
6
+
7
+ module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
6
8
 
7
9
  module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
8
10
  const {node} = path;
@@ -39,38 +41,6 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
39
41
  print('__body');
40
42
  };
41
43
 
42
- module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
43
-
44
- function ArrowFunctionExpression(path, {print, maybe, write, traverse}) {
45
- const {async} = path.node;
46
- maybe.print(async, 'async ');
47
- print('(');
48
-
49
- const params = path.get('params');
50
- const n = params.length;
51
-
52
- for (let i = 0; i < n; i++) {
53
- print(params[i]);
54
-
55
- if (i < n - 1)
56
- print(', ');
57
- }
58
-
59
- print(')');
60
-
61
- const returnType = path.get('returnType');
62
-
63
- if (exists(returnType)) {
64
- write(':');
65
- write.space();
66
- traverse(returnType);
67
- }
68
-
69
- print.space();
70
- print('=>');
71
- print.space();
72
- print('__body');
73
- }
74
44
  module.exports.ObjectMethod = (path, {print}) => {
75
45
  const {kind} = path.node;
76
46
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const functions = require('./functions');
3
+ const functions = require('./functions/functions');
4
4
  const unaryExpressions = require('./unary-expressions');
5
5
  const memberExpressions = require('./member-expressions');
6
6
 
@@ -114,4 +114,3 @@ function isLooksLikeChain(path) {
114
114
 
115
115
  return !compare(parentPath, '__a.__b(__args)') || itMember || itExpression;
116
116
  }
117
-
@@ -126,5 +126,6 @@ const isNextAssign = (path) => {
126
126
  if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
127
127
  return false;
128
128
 
129
- return nextPath.get('expression').isAssignmentExpression();
129
+ return nextPath
130
+ .get('expression').isAssignmentExpression();
130
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.54.1",
3
+ "version": "1.54.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",