@putout/printer 1.113.1 → 1.114.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.05.24, v1.114.0
2
+
3
+ feature:
4
+ - d23bd5b @putout/printer: functions: move out pararms
5
+
1
6
  2023.05.24, v1.113.1
2
7
 
3
8
  feature:
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {exists} = require('../../is');
4
+ const {printParams} = require('./params');
4
5
 
5
6
  module.exports.ArrowFunctionExpression = {
6
7
  condition({parentPath}) {
@@ -13,21 +14,10 @@ module.exports.ArrowFunctionExpression = {
13
14
  const {async} = path.node;
14
15
 
15
16
  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
- print.space();
27
- }
28
- }
29
17
 
30
- print(')');
18
+ printParams(path, {
19
+ print,
20
+ });
31
21
 
32
22
  const returnType = path.get('returnType');
33
23
 
@@ -53,4 +43,3 @@ module.exports.ArrowFunctionExpression = {
53
43
  write(')');
54
44
  },
55
45
  };
56
-
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isNext} = require('../../is');
4
+ const {printParams} = require('./params');
4
5
 
5
6
  const ClassMethod = {
6
7
  print(path, {print, maybe}) {
@@ -18,19 +19,11 @@ const ClassMethod = {
18
19
  print('__key');
19
20
  }
20
21
 
21
- print('(');
22
+ printParams(path, {
23
+ print,
24
+ });
22
25
 
23
- const params = path.get('params');
24
- const n = params.length;
25
-
26
- for (let i = 0; i < n; i++) {
27
- print(params[i]);
28
-
29
- if (i < n - 1)
30
- print(', ');
31
- }
32
-
33
- print(') ');
26
+ print.space();
34
27
  print('__body');
35
28
  },
36
29
  afterSatisfy: () => [
@@ -6,6 +6,7 @@ const {
6
6
  isNext,
7
7
  isNextParent,
8
8
  } = require('../../is');
9
+ const {printParams} = require('./params');
9
10
 
10
11
  module.exports.FunctionDeclaration = {
11
12
  print(path, {print, maybe}) {
@@ -16,19 +17,11 @@ module.exports.FunctionDeclaration = {
16
17
  print('function ');
17
18
  print('__id');
18
19
  print('__typeParameters');
19
- print('(');
20
20
 
21
- const params = path.get('params');
22
- const n = params.length - 1;
21
+ printParams(path, {
22
+ print,
23
+ });
23
24
 
24
- for (let i = 0; i <= n; i++) {
25
- print(params[i]);
26
-
27
- if (i < n)
28
- print(', ');
29
- }
30
-
31
- print(')');
32
25
  print.space();
33
26
  print('__body');
34
27
  },
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {exists} = require('../../is');
4
+ const {printParams} = require('./params');
4
5
 
5
6
  module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
6
7
  const {node} = path;
@@ -21,19 +22,10 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
21
22
  traverse(id);
22
23
  }
23
24
 
24
- print('(');
25
+ printParams(path, {
26
+ print,
27
+ });
25
28
 
26
- const params = path.get('params');
27
- const n = params.length;
28
-
29
- for (let i = 0; i < n; i++) {
30
- print(params[i]);
31
-
32
- if (i < n - 1)
33
- print(', ');
34
- }
35
-
36
- print(')');
37
29
  print.space();
38
30
  print('__body');
39
31
  };
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isNewlineBetweenSiblings} = require('../../is');
4
+ const {printParams} = require('./params');
4
5
 
5
6
  module.exports.ObjectMethod = {
6
7
  beforeIf(path) {
@@ -16,21 +17,11 @@ module.exports.ObjectMethod = {
16
17
  print(`${kind} `);
17
18
 
18
19
  print('__key');
19
- print('(');
20
20
 
21
- const params = path.get('params');
22
- const n = params.length - 1;
21
+ printParams(path, {
22
+ print,
23
+ });
23
24
 
24
- for (let i = 0; i <= n; i++) {
25
- print(params[i]);
26
-
27
- if (i < n) {
28
- print(',');
29
- print.space();
30
- }
31
- }
32
-
33
- print(')');
34
25
  print.space();
35
26
  print('__body');
36
27
  },
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ module.exports.printParams = (path, {print}) => {
4
+ print('(');
5
+
6
+ const params = path.get('params');
7
+ const n = params.length;
8
+
9
+ for (let i = 0; i < n; i++) {
10
+ print(params[i]);
11
+
12
+ if (i < n - 1) {
13
+ print(',');
14
+ print.space();
15
+ }
16
+ }
17
+
18
+ print(')');
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.113.1",
3
+ "version": "1.114.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",